blob: 7ebc19a6c8f628e4b5cebb6ee3da00d0159731dd [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "qmladapterbase.h"
22
23#include <QObject>
24#include <QSettings>
25#include <QString>
26
27#include "lrcinstance.h"
28#include "utils.h"
29
30class AccountAdapter : public QmlAdapterBase
31{
32 Q_OBJECT
33
34public:
35 explicit AccountAdapter(QObject *parent = 0);
36 ~AccountAdapter();
37 //Singleton
38 static AccountAdapter &instance();
39
40 /*
41 * Change to account corresponding to combox box index.
42 */
43 Q_INVOKABLE void accountChanged(int index);
44 /*
45 * Create normal Jami account, SIP account and JAMS accounts.
46 */
47 Q_INVOKABLE void createJamiAccount(QString registeredName,
48 const QVariantMap &settings,
49 QString photoBoothImgBase64,
50 bool isCreating);
51 Q_INVOKABLE void createSIPAccount(const QVariantMap &settings, QString photoBoothImgBase64);
52 Q_INVOKABLE void createJAMSAccount(const QVariantMap &settings);
53 /*
54 * Delete current account
55 */
56 Q_INVOKABLE void deleteCurrentAccount();
57 /*
58 * Setting related
59 */
60 Q_INVOKABLE void settingsNeverShowAgain(bool checked);
61 Q_INVOKABLE void passwordSetStatusMessageBox(bool success, QString title, QString infoToDisplay);
62 /*
63 * conf property
64 */
65 Q_INVOKABLE bool hasPassword();
66 Q_INVOKABLE void setArchiveHasPassword(bool isHavePassword);
67 Q_INVOKABLE bool exportToFile(const QString &accountId,
68 const QString &path,
69 const QString &password = {}) const;
70 Q_INVOKABLE void setArchivePasswordAsync(const QString &accountID, const QString &password);
71 /*
72 * lrc instances functions wrappers
73 */
74 Q_INVOKABLE bool savePassword(QString accountId, QString oldPassword, QString newPassword);
75 Q_INVOKABLE void startAudioMeter(bool async);
76 Q_INVOKABLE void stopAudioMeter(bool async);
77 Q_INVOKABLE void startPreviewing(bool force);
78 Q_INVOKABLE void stopPreviewing();
79 Q_INVOKABLE bool hasVideoCall();
80 Q_INVOKABLE bool isPreviewing();
81 Q_INVOKABLE void setCurrAccDisplayName(QString text);
82 Q_INVOKABLE void setSelectedAccountId(QString accountId = {});
83 Q_INVOKABLE void setSelectedConvId(QString accountId = {});
84
85 /*
86 * lrc model instances getter
87 */
88 Q_INVOKABLE lrc::api::NewAccountModel *accoundModel();
89 Q_INVOKABLE lrc::api::AVModel *avModel();
90 Q_INVOKABLE lrc::api::DataTransferModel *dataTransferModel();
91
92 Q_INVOKABLE RenderManager *getRenderManager();
93signals:
94
95 /*
96 * Trigger other components to reconnect account related signals.
97 */
98 void accountSignalsReconnect(const QString &accountId);
99 void accountStatusChanged();
100 void updateConversationForAddedContact();
101 /*
102 * send report failure to QML to make it show the right UI state .
103 */
104 void reportFailure();
105 void accountAdded(bool showBackUp, int index);
106
107private:
108 void initQmlObject() override final;
109 void setSelectedAccount(const QString &accountId, int index);
110 void backToWelcomePage(int index);
111 void deselectConversation();
112
113 /*
114 * Make account signal connections.
115 */
116 void connectAccount(const QString &accountId);
117 /*
118 * Implement what to do when creat accout fails.
119 */
120 void connectFailure();
121
122 QMetaObject::Connection accountStatusChangedConnection_;
123 QMetaObject::Connection contactAddedConnection_;
124 QMetaObject::Connection addedToConferenceConnection_;
125};
126#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
127Q_DECLARE_METATYPE(AccountAdapter *)
128#endif