File indexing completed on 2024-04-14 04:54:50

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "authenticationinfo.h"
0010 #include "libruqolacore_export.h"
0011 #include "model/rocketchataccountfilterproxymodel.h"
0012 #include "model/rocketchataccountmodel.h"
0013 #include "parsemessageurlutils.h"
0014 
0015 #include <QObject>
0016 class RocketChatAccount;
0017 
0018 class LIBRUQOLACORE_EXPORT AccountManager : public QObject
0019 {
0020     Q_OBJECT
0021 public:
0022     struct LIBRUQOLACORE_EXPORT AccountManagerInfo {
0023         QVector<AuthenticationInfo> authenticationInfos;
0024         QString displayName;
0025         QString accountName;
0026         QString userName;
0027         QString serverUrl;
0028         QString password;
0029         bool canResetPassword = false;
0030         bool enabled = true;
0031         bool canRegisterAccount = false;
0032     };
0033 
0034     explicit AccountManager(QObject *parent = nullptr);
0035     ~AccountManager() override;
0036 
0037     void removeAccount(const QString &accountName, bool removeLogFiles = false);
0038     void addAccount(const AccountManagerInfo &info);
0039 
0040     RocketChatAccount *account() const;
0041     RocketChatAccountModel *rocketChatAccountModel() const;
0042 
0043     RocketChatAccountFilterProxyModel *rocketChatAccountProxyModel() const;
0044 
0045     void addAccount(RocketChatAccount *account);
0046 
0047     void setCurrentAccount(const QString &accountName);
0048     [[nodiscard]] QString currentAccount() const;
0049     void selectAccount(const QString &accountName);
0050 
0051     void modifyAccount(const AccountManagerInfo &info);
0052     [[nodiscard]] QStringList accountsName() const;
0053 
0054     [[nodiscard]] int accountNumber() const;
0055     void openMessageUrl(const QString &messageUrl);
0056     [[nodiscard]] bool showMessage(const ParseMessageUrlUtils &parseUrl);
0057     [[nodiscard]] RocketChatAccount *accountFromName(const QString &accountName);
0058 
0059     [[nodiscard]] QStringList accountNamesSorted() const;
0060 
0061 Q_SIGNALS:
0062     void logoutAccountDone(const QString &accountName);
0063     void updateNotification(bool hasAlert, int nbUnread, const QString &accountName);
0064     void currentAccountChanged();
0065     void roomNeedAttention();
0066     void messageUrlNotFound(const QString &str);
0067 
0068 private:
0069     LIBRUQOLACORE_NO_EXPORT void removeDatabaseAccount(const QString &accountName);
0070     LIBRUQOLACORE_NO_EXPORT void removeDirectory(const QString &directory);
0071     LIBRUQOLACORE_NO_EXPORT void removeLogs(const QString &accountName);
0072     LIBRUQOLACORE_NO_EXPORT void loadAccount();
0073     LIBRUQOLACORE_NO_EXPORT void connectToAccount(RocketChatAccount *account);
0074     LIBRUQOLACORE_NO_EXPORT void slotSwitchToAccountAndRoomName(const QString &accountName, const QString &roomName, const QString &channelType);
0075     LIBRUQOLACORE_NO_EXPORT void loadExcludeEmoticons();
0076     RocketChatAccount *mCurrentAccount = nullptr;
0077     RocketChatAccountModel *const mRocketChatAccountModel;
0078     RocketChatAccountFilterProxyModel *const mRocketChatAccountProxyModel;
0079 };
0080 Q_DECLARE_TYPEINFO(AccountManager::AccountManagerInfo, Q_RELOCATABLE_TYPE);