File indexing completed on 2024-03-24 17:01:22

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 #include <QWindow>
0008 
0009 #include <KWallet>
0010 
0011 #include "drkonqi.h"
0012 
0013 class CredentialStore : public QObject
0014 {
0015     Q_OBJECT
0016 public:
0017     using QObject::QObject;
0018 
0019     Q_INVOKABLE void load();
0020     Q_INVOKABLE void store();
0021     Q_INVOKABLE void drop();
0022 
0023     Q_PROPERTY(bool canStore MEMBER m_canStore CONSTANT)
0024     const bool m_canStore = KWallet::Wallet::isEnabled();
0025 
0026     Q_PROPERTY(QString url MEMBER m_url NOTIFY urlChanged)
0027     QString m_url;
0028     Q_SIGNAL void urlChanged();
0029 
0030     Q_PROPERTY(QString email MEMBER m_email NOTIFY emailChanged)
0031     QString m_email;
0032     Q_SIGNAL void emailChanged();
0033 
0034     Q_PROPERTY(QString password MEMBER m_password NOTIFY passwordChanged)
0035     QString m_password;
0036     Q_SIGNAL void passwordChanged();
0037 
0038     Q_PROPERTY(QWindow *window MEMBER m_window NOTIFY windowChanged)
0039     QWindow *m_window = nullptr;
0040     Q_SIGNAL void windowChanged();
0041 
0042 private:
0043     void openWallet();
0044     static bool kWalletEntryExists(const QString &entryName);
0045 
0046     KWallet::Wallet *m_wallet = nullptr;
0047     const QString m_walletEntryName = DrKonqi::isTestingBugzilla() ? QStringLiteral("drkonqi_bugzilla_test_mode") : QStringLiteral("drkonqi_bugzilla");
0048     bool m_walletWasOpenedBefore = false;
0049 };