File indexing completed on 2023-11-26 08:17:49

0001 /*
0002    SPDX-FileCopyrightText: 2018-2023 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 "model/rocketchataccountfilterproxymodel.h"
0011 #include "model/rocketchataccountmodel.h"
0012 #include "rocketchataccount.h"
0013 
0014 #include <QObject>
0015 
0016 class LIBRUQOLACORE_EXPORT AccountManager : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     struct LIBRUQOLACORE_EXPORT AccountManagerInfo {
0021         QString displayName;
0022         QString accountName;
0023         QString userName;
0024         QString serverUrl;
0025         QString password;
0026         bool enabled = true;
0027     };
0028 
0029     explicit AccountManager(QObject *parent = nullptr);
0030     ~AccountManager() override;
0031 
0032     void removeAccount(const QString &accountName, bool removeLogFiles = false);
0033     void addAccount(const AccountManagerInfo &info);
0034 
0035     RocketChatAccount *account() const;
0036     RocketChatAccountModel *rocketChatAccountModel() const;
0037 
0038     RocketChatAccountFilterProxyModel *rocketChatAccountProxyModel() const;
0039 
0040     void addAccount(RocketChatAccount *account);
0041 
0042     void setCurrentAccount(const QString &accountName);
0043     [[nodiscard]] QString currentAccount() const;
0044     void selectAccount(const QString &accountName);
0045 
0046     void modifyAccount(const AccountManagerInfo &info);
0047     [[nodiscard]] QStringList accountsName() const;
0048 
0049     [[nodiscard]] int accountNumber() const;
0050     void openMessageUrl(const QString &messageUrl);
0051     [[nodiscard]] bool showMessage(const ParseMessageUrlUtils &parseUrl);
0052     [[nodiscard]] RocketChatAccount *accountFromName(const QString &accountName);
0053 
0054     [[nodiscard]] QStringList accountNamesSorted() const;
0055 
0056 Q_SIGNALS:
0057     void logoutAccountDone(const QString &accountName);
0058     void updateNotification(bool hasAlert, int nbUnread, const QString &accountName);
0059     void currentAccountChanged();
0060     void roomNeedAttention();
0061     void messageUrlNotFound(const QString &str);
0062 
0063 private:
0064     Q_DISABLE_COPY(AccountManager)
0065 
0066     LIBRUQOLACORE_NO_EXPORT void removeDatabaseAccount(const QString &accountName);
0067     LIBRUQOLACORE_NO_EXPORT void removeDirectory(const QString &directory);
0068     LIBRUQOLACORE_NO_EXPORT void removeLogs(const QString &accountName);
0069     LIBRUQOLACORE_NO_EXPORT void loadAccount();
0070     LIBRUQOLACORE_NO_EXPORT void connectToAccount(RocketChatAccount *account);
0071     LIBRUQOLACORE_NO_EXPORT void slotSwitchToAccountAndRoomName(const QString &accountName, const QString &roomName, const QString &channelType);
0072     RocketChatAccount *mCurrentAccount = nullptr;
0073     RocketChatAccountModel *const mRocketChatAccountModel;
0074     RocketChatAccountFilterProxyModel *const mRocketChatAccountProxyModel;
0075 };