File indexing completed on 2025-02-16 04:50:13

0001 /*
0002    SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
0003    SPDX-FileCopyrightText: 2020 Igor Poboiko <igor.poboiko@gmail.com>
0004 
0005    SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "settingsbase.h"
0011 
0012 #include <QPointer>
0013 #include <qwindowdefs.h>
0014 
0015 #include <KGAPI/Types>
0016 
0017 namespace QKeychain
0018 {
0019 class ReadPasswordJob;
0020 class WritePasswordJob;
0021 }
0022 
0023 /**
0024  * @brief Settings object
0025  *
0026  * Provides read-only access to application clientId and
0027  * clientSecret and read-write access to accessToken and
0028  * refreshToken. Interacts with QtKeyChain.
0029  */
0030 class GoogleSettings : public SettingsBase
0031 {
0032     Q_OBJECT
0033     Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.Google.ExtendedSettings")
0034 
0035 public:
0036     enum class Option {
0037         NoOption = 0,
0038         ExportToDBus = 1,
0039     };
0040     Q_DECLARE_FLAGS(Options, Option)
0041 
0042     explicit GoogleSettings(const KSharedConfigPtr &config, Options options = Option::ExportToDBus);
0043 
0044     void init();
0045     void setWindowId(WId id);
0046     void setResourceId(const QString &resourceIdentifier);
0047 
0048     QString appId() const;
0049     QString clientId() const;
0050     QString clientSecret() const;
0051 
0052     void addCalendar(const QString &calendar);
0053     void addTaskList(const QString &taskList);
0054 
0055     KGAPI2::AccountPtr accountPtr();
0056     // Wallet
0057     bool isReady() const;
0058     QKeychain::WritePasswordJob *storeAccount(KGAPI2::AccountPtr account);
0059     void cleanup();
0060 
0061 Q_SIGNALS:
0062     void accountReady(bool ready);
0063     void accountChanged();
0064     void okEnabled(bool enabled);
0065 
0066 private:
0067     void slotWalletOpened(bool success);
0068     WId m_winId = 0;
0069     QString m_resourceId;
0070     bool m_isReady = false;
0071     KGAPI2::AccountPtr m_account;
0072     KGAPI2::AccountPtr fetchAccountFromKeychain(const QString &accountName, QKeychain::ReadPasswordJob *job);
0073 };