File indexing completed on 2025-01-19 04:46:53

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "gravatarconfiguresettingspluginwidget.h"
0008 #include <Gravatar/GravatarCache>
0009 #include <Gravatar/GravatarConfigureSettingsWidget>
0010 #include <PimCommon/ConfigureImmutableWidgetUtils>
0011 
0012 #include <KLocalizedString>
0013 
0014 #include <gravatar/gravatarsettings.h>
0015 
0016 #include <QCheckBox>
0017 #include <QVBoxLayout>
0018 
0019 using namespace PimCommon::ConfigureImmutableWidgetUtils;
0020 GravatarConfigureSettingsPluginWidget::GravatarConfigureSettingsPluginWidget(QWidget *parent)
0021     : MessageViewer::MessageViewerConfigureSettingsPluginWidget(parent)
0022     , mGravatarConfigWidget(new Gravatar::GravatarConfigureSettingsWidget(this))
0023     , mEnableGravatarSupport(new QCheckBox(i18n("Enable Gravatar Support"), this))
0024 {
0025     auto mainLayout = new QVBoxLayout(this);
0026     mainLayout->setObjectName(QLatin1StringView("mainlayout"));
0027     mainLayout->setContentsMargins({});
0028 
0029     mEnableGravatarSupport->setObjectName(QLatin1StringView("gravatarcheckbox"));
0030     mEnableGravatarSupport->setChecked(false);
0031     mainLayout->addWidget(mEnableGravatarSupport);
0032 
0033     mGravatarConfigWidget->setObjectName(QLatin1StringView("gravatarconfigwidget"));
0034     mainLayout->addWidget(mGravatarConfigWidget);
0035     connect(mEnableGravatarSupport, &QCheckBox::clicked, mGravatarConfigWidget, &Gravatar::GravatarConfigureSettingsWidget::setEnabled);
0036 }
0037 
0038 GravatarConfigureSettingsPluginWidget::~GravatarConfigureSettingsPluginWidget() = default;
0039 
0040 void GravatarConfigureSettingsPluginWidget::loadSettings()
0041 {
0042     loadWidget(mEnableGravatarSupport, Gravatar::GravatarSettings::self()->gravatarSupportEnabledItem());
0043     mGravatarConfigWidget->load();
0044 }
0045 
0046 void GravatarConfigureSettingsPluginWidget::saveSettings()
0047 {
0048     saveCheckBox(mEnableGravatarSupport, Gravatar::GravatarSettings::self()->gravatarSupportEnabledItem());
0049     if (!mEnableGravatarSupport->isChecked()) {
0050         Gravatar::GravatarCache::self()->clearAllCache();
0051     }
0052     mGravatarConfigWidget->save();
0053 }
0054 
0055 void GravatarConfigureSettingsPluginWidget::resetSettings()
0056 {
0057     const bool bUseDefaults = Gravatar::GravatarSettings::self()->useDefaults(true);
0058     loadSettings();
0059     Gravatar::GravatarSettings::self()->useDefaults(bUseDefaults);
0060     mGravatarConfigWidget->slotRestoreDefault();
0061 }
0062 
0063 #include "moc_gravatarconfiguresettingspluginwidget.cpp"