1 /*
2    SPDX-FileCopyrightText: 2018-2021 Laurent Montel <montel@kde.org>
3 
4    SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "libruqolacore_export.h"
10 #include "model/rocketchataccountfilterproxymodel.h"
11 #include "model/rocketchataccountmodel.h"
12 #include "rocketchataccount.h"
13 #include "utils.h"
14 
15 #include <QObject>
16 
17 class LIBRUQOLACORE_EXPORT AccountManager : public QObject
18 {
19     Q_OBJECT
20 public:
21     struct LIBRUQOLACORE_EXPORT AccountManagerInfo {
22         QString displayName;
23         QString accountName;
24         QString userName;
25         QString serverUrl;
26         QString password;
27         bool enabled = true;
28     };
29 
30     explicit AccountManager(QObject *parent = nullptr);
31     ~AccountManager() override;
32 
33     void removeAccount(const QString &accountName);
34     void addAccount(const AccountManagerInfo &info);
35 
36     RocketChatAccount *account() const;
37     RocketChatAccountModel *rocketChatAccountModel() const;
38 
39     RocketChatAccountFilterProxyModel *rocketChatAccountProxyModel() const;
40 
41     void addAccount(RocketChatAccount *account);
42 
43     void setCurrentAccount(const QString &accountName);
44     Q_REQUIRED_RESULT QString currentAccount() const;
45     void selectAccount(const QString &accountName);
46 
47     void modifyAccount(const AccountManagerInfo &info);
48     Q_REQUIRED_RESULT QStringList accountsName() const;
49 
50     Q_REQUIRED_RESULT int accountNumber() const;
51 Q_SIGNALS:
52     void logoutAccountDone(const QString &accountName);
53     void updateNotification(bool hasAlert, int nbUnread, const QString &accountName);
54     void currentAccountChanged();
55     void roomNeedAttention();
56 
57 private:
58     Q_DISABLE_COPY(AccountManager)
59 
60     void loadAccount();
61     void connectToAccount(RocketChatAccount *account);
62     void slotSwitchToAccountAndRoomName(const QString &accountName, const QString &roomName, const QString &channelType);
63     RocketChatAccount *mCurrentAccount = nullptr;
64     RocketChatAccountModel *const mRocketChatAccountModel;
65     RocketChatAccountFilterProxyModel *const mRocketChatAccountProxyModel;
66 };
67 
68