blob: d2e9844d7ffdf44a8aadcacefea337f579027fee [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 */
Sébastien Blin1f915762020-08-03 13:27:42 -040060 Q_INVOKABLE void passwordSetStatusMessageBox(bool success, QString title, QString infoToDisplay);
61 /*
62 * conf property
63 */
64 Q_INVOKABLE bool hasPassword();
65 Q_INVOKABLE void setArchiveHasPassword(bool isHavePassword);
66 Q_INVOKABLE bool exportToFile(const QString &accountId,
67 const QString &path,
68 const QString &password = {}) const;
69 Q_INVOKABLE void setArchivePasswordAsync(const QString &accountID, const QString &password);
70 /*
71 * lrc instances functions wrappers
72 */
73 Q_INVOKABLE bool savePassword(QString accountId, QString oldPassword, QString newPassword);
74 Q_INVOKABLE void startAudioMeter(bool async);
75 Q_INVOKABLE void stopAudioMeter(bool async);
Yang Wangc2ea0b12020-08-18 13:24:37 -040076 Q_INVOKABLE void startPreviewing(bool force = false, bool async = true);
77 Q_INVOKABLE void stopPreviewing(bool async = true);
Sébastien Blin1f915762020-08-03 13:27:42 -040078 Q_INVOKABLE bool hasVideoCall();
79 Q_INVOKABLE bool isPreviewing();
80 Q_INVOKABLE void setCurrAccDisplayName(QString text);
81 Q_INVOKABLE void setSelectedAccountId(QString accountId = {});
82 Q_INVOKABLE void setSelectedConvId(QString accountId = {});
83
Sébastien Blin1f915762020-08-03 13:27:42 -040084signals:
85
86 /*
87 * Trigger other components to reconnect account related signals.
88 */
89 void accountSignalsReconnect(const QString &accountId);
90 void accountStatusChanged();
91 void updateConversationForAddedContact();
92 /*
93 * send report failure to QML to make it show the right UI state .
94 */
95 void reportFailure();
96 void accountAdded(bool showBackUp, int index);
97
98private:
99 void initQmlObject() override final;
ababi69f5dfc2020-08-25 15:07:57 +0200100 void setSelectedAccount(const QString &accountId);
101 void backToWelcomePage();
Sébastien Blin1f915762020-08-03 13:27:42 -0400102 void deselectConversation();
103
104 /*
105 * Make account signal connections.
106 */
107 void connectAccount(const QString &accountId);
108 /*
109 * Implement what to do when creat accout fails.
110 */
111 void connectFailure();
112
113 QMetaObject::Connection accountStatusChangedConnection_;
114 QMetaObject::Connection contactAddedConnection_;
115 QMetaObject::Connection addedToConferenceConnection_;
Sébastien Blinacb1cf02020-08-17 22:38:19 -0400116 QMetaObject::Connection accountProfileChangedConnection_;
Sébastien Blin1f915762020-08-03 13:27:42 -0400117};
Sébastien Blin1f915762020-08-03 13:27:42 -0400118Q_DECLARE_METATYPE(AccountAdapter *)