File indexing completed on 2024-12-08 10:25:53

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqolacore_export.h"
0010 #include <QDate>
0011 #include <QObject>
0012 #include <QString>
0013 
0014 namespace QKeychain
0015 {
0016 class Job;
0017 }
0018 
0019 class QSettings;
0020 class LIBRUQOLACORE_EXPORT RocketChatAccountSettings : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     explicit RocketChatAccountSettings(const QString &accountFileName = QString(), QObject *parent = nullptr);
0025     ~RocketChatAccountSettings() override;
0026 
0027     [[nodiscard]] bool isValid() const;
0028 
0029     [[nodiscard]] QString userId() const;
0030     void setUserId(const QString &userId);
0031 
0032     [[nodiscard]] QString authToken() const;
0033     void setAuthToken(const QString &authToken);
0034 
0035     // account info
0036     [[nodiscard]] QString serverUrl() const;
0037     void setServerUrl(const QString &serverUrl);
0038 
0039     [[nodiscard]] QString accountName() const;
0040     void setAccountName(const QString &accountName);
0041 
0042     [[nodiscard]] QString userName() const;
0043     void setUserName(const QString &userName);
0044 
0045     [[nodiscard]] QString twoFactorAuthenticationCode() const;
0046     void setTwoFactorAuthenticationCode(const QString &twoFactorAuthenticationCode);
0047 
0048     void logout();
0049     [[nodiscard]] QString cacheBasePath();
0050 
0051     [[nodiscard]] QString password() const;
0052     void setPassword(const QString &password);
0053 
0054     void removeSettings();
0055 
0056     [[nodiscard]] qint64 expireToken() const;
0057     void setExpireToken(qint64 expireToken);
0058 
0059     [[nodiscard]] bool tokenExpired() const;
0060 
0061     [[nodiscard]] bool accountEnabled() const;
0062     void setAccountEnabled(bool accountEnabled);
0063 
0064     [[nodiscard]] QString lastSelectedRoom() const;
0065     void setLastSelectedRoom(const QString &roomId);
0066 
0067     [[nodiscard]] QString displayName() const;
0068     void setDisplayName(const QString &displayName);
0069 
0070     [[nodiscard]] QDate lastCheckedPreviewUrlCacheDate() const;
0071     void setLastCheckedPreviewUrlCacheDate(const QDate &newLastCheckedPreviewUrlCacheDate);
0072 
0073 Q_SIGNALS:
0074     void serverURLChanged();
0075     void userNameChanged();
0076     void userIdChanged();
0077     void accountNameChanged();
0078     void passwordChanged();
0079     void twoFactorAuthenticationCodeChanged();
0080     void enableAccountChanged();
0081     void displayNameChanged();
0082 
0083 private:
0084     Q_DISABLE_COPY(RocketChatAccountSettings)
0085     LIBRUQOLACORE_NO_EXPORT void initializeSettings(const QString &accountFileName);
0086     LIBRUQOLACORE_NO_EXPORT void slotPasswordRead(QKeychain::Job *job);
0087     LIBRUQOLACORE_NO_EXPORT void slotPasswordWritten(QKeychain::Job *job);
0088 
0089     QString mUserId;
0090     QString mAuthToken;
0091     QString mServerUrl;
0092     QString mAccountName;
0093     QString mDisplayName;
0094     QString mCachePath;
0095     QString mUserName;
0096     QString mPassword;
0097     QDate mLastCheckedPreviewUrlCacheDate;
0098     bool mUseLdap = false;
0099     QString mTwoFactorAuthenticationCode;
0100     qint64 mExpireToken = -1;
0101     QSettings *mSetting = nullptr;
0102     bool mAccountEnabled = true;
0103 };