File indexing completed on 2024-06-02 05:21:02

0001 /*
0002     SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <Akonadi/AgentConfigurationBase>
0008 
0009 #include "googleresource_debug.h"
0010 #include "googlesettings.h"
0011 #include "googlesettingswidget.h"
0012 
0013 class GoogleConfig : public Akonadi::AgentConfigurationBase
0014 {
0015     Q_OBJECT
0016 
0017 public:
0018     explicit GoogleConfig(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &list)
0019         : Akonadi::AgentConfigurationBase(config, parent, list)
0020         , mSettings(config, GoogleSettings::Option::NoOption)
0021         , mWidget(mSettings, identifier(), parent)
0022     {
0023         connect(&mWidget, &GoogleSettingsWidget::okEnabled, this, &Akonadi::AgentConfigurationBase::enableOkButton);
0024     }
0025 
0026     void load() override
0027     {
0028         Akonadi::AgentConfigurationBase::load();
0029         mSettings.init();
0030         connect(&mSettings, &GoogleSettings::accountReady, this, [this](bool ready) {
0031             if (ready) {
0032                 mWidget.loadSettings();
0033             }
0034         });
0035     }
0036 
0037     [[nodiscard]] bool save() const override
0038     {
0039         const_cast<GoogleConfig *>(this)->mWidget.saveSettings();
0040         return Akonadi::AgentConfigurationBase::save();
0041     }
0042 
0043     GoogleSettings mSettings;
0044     GoogleSettingsWidget mWidget;
0045 };
0046 
0047 AKONADI_AGENTCONFIG_FACTORY(GoogleConfigFactory, "googleconfig.json", GoogleConfig)
0048 
0049 #include "googleconfig.moc"