File indexing completed on 2024-12-22 05:02:29
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "gravatarconfiguresettingswidget.h" 0008 #include "gravatarsettings.h" 0009 #include <Gravatar/GravatarCache> 0010 #include <KConfigDialogManager> 0011 #include <KLocalizedString> 0012 #include <KPluralHandlingSpinBox> 0013 #include <KSeparator> 0014 #include <QCheckBox> 0015 #include <QHBoxLayout> 0016 #include <QLabel> 0017 #include <QPushButton> 0018 #include <QVBoxLayout> 0019 0020 using namespace Gravatar; 0021 0022 GravatarConfigureSettingsWidget::GravatarConfigureSettingsWidget(QWidget *parent) 0023 : QWidget(parent) 0024 { 0025 auto topLayout = new QVBoxLayout(this); 0026 topLayout->setObjectName(QLatin1StringView("mainlayout")); 0027 topLayout->setContentsMargins(0, 0, 0, 0); 0028 mUseDefaultPixmap = new QCheckBox(i18n("Use Default Image"), this); 0029 mUseDefaultPixmap->setObjectName(QLatin1StringView("kcfg_GravatarUseDefaultImage")); 0030 topLayout->addWidget(mUseDefaultPixmap); 0031 0032 mUseLibravatar = new QCheckBox(i18n("Use Libravatar"), this); 0033 mUseLibravatar->setObjectName(QLatin1StringView("kcfg_LibravatarSupportEnabled")); 0034 topLayout->addWidget(mUseLibravatar); 0035 0036 mFallbackGravatar = new QCheckBox(i18n("Fallback to Gravatar"), this); 0037 mFallbackGravatar->setObjectName(QLatin1StringView("kcfg_FallbackToGravatar")); 0038 topLayout->addWidget(mFallbackGravatar); 0039 connect(mUseLibravatar, &QCheckBox::toggled, mFallbackGravatar, &QCheckBox::setEnabled); 0040 mFallbackGravatar->setEnabled(false); 0041 0042 auto cacheSizeLayout = new QHBoxLayout; 0043 topLayout->addLayout(cacheSizeLayout); 0044 auto lab = new QLabel(i18n("Gravatar Cache Size:"), this); 0045 lab->setObjectName(QLatin1StringView("gravatarcachesizelabel")); 0046 cacheSizeLayout->addWidget(lab); 0047 0048 mGravatarCacheSize = new KPluralHandlingSpinBox(this); 0049 mGravatarCacheSize->setMinimum(1); 0050 mGravatarCacheSize->setMaximum(9999); 0051 mGravatarCacheSize->setSuffix(ki18ncp("add space before image", " image", " images")); 0052 mGravatarCacheSize->setObjectName(QLatin1StringView("kcfg_GravatarCacheSize")); 0053 cacheSizeLayout->addWidget(mGravatarCacheSize); 0054 cacheSizeLayout->addStretch(); 0055 0056 auto separator = new KSeparator(this); 0057 separator->setObjectName(QLatin1StringView("separator")); 0058 topLayout->addWidget(separator); 0059 0060 auto buttonLayout = new QHBoxLayout; 0061 topLayout->addLayout(buttonLayout); 0062 mClearGravatarCache = new QPushButton(i18n("Clear Gravatar Cache"), this); 0063 mClearGravatarCache->setObjectName(QLatin1StringView("cleargravatarcachebutton")); 0064 buttonLayout->addWidget(mClearGravatarCache); 0065 buttonLayout->addStretch(); 0066 0067 separator = new KSeparator(this); 0068 separator->setObjectName(QLatin1StringView("separator2")); 0069 topLayout->addWidget(separator); 0070 0071 connect(mClearGravatarCache, &QAbstractButton::clicked, this, &GravatarConfigureSettingsWidget::slotClearGravatarCache); 0072 0073 m_configDialogManager = new KConfigDialogManager(this, GravatarSettings::self()); 0074 } 0075 0076 GravatarConfigureSettingsWidget::~GravatarConfigureSettingsWidget() = default; 0077 0078 void GravatarConfigureSettingsWidget::slotClearGravatarCache() 0079 { 0080 Gravatar::GravatarCache::self()->clearAllCache(); 0081 } 0082 0083 void GravatarConfigureSettingsWidget::slotRestoreDefault() 0084 { 0085 m_configDialogManager->updateWidgetsDefault(); 0086 } 0087 0088 void GravatarConfigureSettingsWidget::save() 0089 { 0090 m_configDialogManager->updateSettings(); 0091 } 0092 0093 void GravatarConfigureSettingsWidget::load() 0094 { 0095 m_configDialogManager->updateWidgets(); 0096 } 0097 0098 #include "moc_gravatarconfiguresettingswidget.cpp"