diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index ebd946bf1..df66fbc91 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -482,8 +482,8 @@ void App::initCore() { mSettings = settings; mEngine->setObjectOwnership(mSettings.get(), QQmlEngine::CppOwnership); mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership); - mAccountList = AccountList::create(); - mCallList = CallList::create(); + setAccountList(AccountList::create()); + setCallList(CallList::create()); setAutoStart(mSettings->getAutoStart()); setQuitOnLastWindowClosed(mSettings->getExitOnClose()); connect(mSettings.get(), &SettingsCore::exitOnCloseChanged, this, &App::onExitOnCloseChanged, @@ -561,12 +561,6 @@ void App::initCppInterfaces() { qmlRegisterSingletonType( "SettingsCpp", 1, 0, "SettingsCpp", [this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mSettings.get(); }); - qmlRegisterSingletonType( - "LinphoneAccountsCpp", 1, 0, "LinphoneAccountsCpp", - [this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mAccountList.get(); }); - qmlRegisterSingletonType( - "LinphoneCallsCpp", 1, 0, "LinphoneCallsCpp", - [this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mCallList.get(); }); qmlRegisterType(Constants::MainQmlUri, 1, 0, "PhoneNumberProxy"); qmlRegisterType(Constants::MainQmlUri, 1, 0, "VariantObject"); @@ -799,10 +793,32 @@ QSharedPointer App::getAccountList() const { return mAccountList; } +void App::setAccountList(QSharedPointer data) { + if (mAccountList != data) { + mAccountList = data; + emit accountsChanged(); + } +} + +AccountList *App::getAccounts() const { + return mAccountList.get(); +} + QSharedPointer App::getCallList() const { return mCallList; } +void App::setCallList(QSharedPointer data) { + if (mCallList != data) { + mCallList = data; + emit callsChanged(); + } +} + +CallList *App::getCalls() const { + return mCallList.get(); +} + QSharedPointer App::getSettings() const { return mSettings; } diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index 0e2275720..0b96c51a5 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -39,6 +39,8 @@ class QSystemTrayIcon; class App : public SingleApplication, public AbstractObject { Q_OBJECT Q_PROPERTY(bool coreStarted READ getCoreStarted WRITE setCoreStarted NOTIFY coreStartedChanged) + Q_PROPERTY(AccountList *accounts READ getAccounts NOTIFY accountsChanged) + Q_PROPERTY(CallList *calls READ getCalls NOTIFY callsChanged) public: App(int &argc, char *argv[]); ~App(); @@ -124,7 +126,12 @@ public: QQuickWindow *getMainWindow() const; void setMainWindow(QQuickWindow *data); QSharedPointer getAccountList() const; + void setAccountList(QSharedPointer data); + Q_INVOKABLE AccountList *getAccounts() const; + QSharedPointer getCallList() const; + void setCallList(QSharedPointer data); + Q_INVOKABLE CallList *getCalls() const; QSharedPointer getSettings() const; void onExitOnCloseChanged(); // Can be used for UniqueConnection @@ -146,6 +153,8 @@ public: signals: void mainWindowChanged(); void coreStartedChanged(bool coreStarted); + void accountsChanged(); + void callsChanged(); // void executeCommand(QString command); private: diff --git a/Linphone/core/account/AccountProxy.cpp b/Linphone/core/account/AccountProxy.cpp index d9f4e27bf..388b7d4ed 100644 --- a/Linphone/core/account/AccountProxy.cpp +++ b/Linphone/core/account/AccountProxy.cpp @@ -24,17 +24,18 @@ #include "core/App.hpp" AccountProxy::AccountProxy(QObject *parent) : LimitProxy(parent) { - setSourceModel(App::getInstance()->getAccountList().get()); + connect(this, &AccountProxy::initializedChanged, this, &AccountProxy::resetDefaultAccount); + connect(this, &AccountProxy::initializedChanged, this, &AccountProxy::haveAccountChanged); } AccountProxy::~AccountProxy() { - setSourceModel(nullptr); } AccountGui *AccountProxy::getDefaultAccount() { - if (!mDefaultAccount) - mDefaultAccount = dynamic_cast(dynamic_cast(sourceModel())->sourceModel()) - ->getDefaultAccountCore(); + if (!mDefaultAccount) { + auto model = getListModel(); + if (model) mDefaultAccount = model->getDefaultAccountCore(); + } return new AccountGui(mDefaultAccount); } @@ -48,15 +49,21 @@ void AccountProxy::resetDefaultAccount() { } AccountGui *AccountProxy::findAccountByAddress(const QString &address) { - return getListModel()->findAccountByAddress(address); + auto model = getListModel(); + if (model) return model->findAccountByAddress(address); + else return nullptr; } AccountGui *AccountProxy::firstAccount() { - return getListModel()->firstAccount(); + auto model = getListModel(); + if (model) return model->firstAccount(); + else return nullptr; } bool AccountProxy::getHaveAccount() const { - return getListModel()->getHaveAccount(); + auto model = getListModel(); + if (model) return model->getHaveAccount(); + else return false; } bool AccountProxy::isInitialized() const { @@ -81,7 +88,6 @@ void AccountProxy::setSourceModel(QAbstractItemModel *model) { qDebug() << "AccountProxy initialized"; setInitialized(init); }); - setInitialized(newAccountList->isInitialized()); connect(newAccountList, &AccountList::countChanged, this, &AccountProxy::resetDefaultAccount, Qt::QueuedConnection); connect(newAccountList, &AccountList::defaultAccountChanged, this, &AccountProxy::resetDefaultAccount, @@ -90,6 +96,7 @@ void AccountProxy::setSourceModel(QAbstractItemModel *model) { Qt::QueuedConnection); } setSourceModels(new SortFilterList(model, Qt::AscendingOrder)); + if (newAccountList) setInitialized(newAccountList->isInitialized()); } //------------------------------------------------------------------------------------------ diff --git a/Linphone/core/call/CallProxy.cpp b/Linphone/core/call/CallProxy.cpp index 8d6d61574..6f9a5b238 100644 --- a/Linphone/core/call/CallProxy.cpp +++ b/Linphone/core/call/CallProxy.cpp @@ -26,7 +26,8 @@ DEFINE_ABSTRACT_OBJECT(CallProxy) CallProxy::CallProxy(QObject *parent) : LimitProxy(parent) { - setSourceModel(App::getInstance()->getCallList().get()); + connect(this, &CallProxy::sourceModelChanged, this, &CallProxy::resetCurrentCall); + connect(this, &CallProxy::sourceModelChanged, this, &CallProxy::haveCallChanged); } CallProxy::~CallProxy() { @@ -49,7 +50,8 @@ void CallProxy::resetCurrentCall() { } bool CallProxy::getHaveCall() const { - return getListModel()->getHaveCall(); + auto model = getListModel(); + return model ? model->getHaveCall() : false; } void CallProxy::setSourceModel(QAbstractItemModel *model) { diff --git a/Linphone/view/Control/Container/Call/ActiveSpeakerLayout.qml b/Linphone/view/Control/Container/Call/ActiveSpeakerLayout.qml index 87afc37a2..da7af20eb 100644 --- a/Linphone/view/Control/Container/Call/ActiveSpeakerLayout.qml +++ b/Linphone/view/Control/Container/Call/ActiveSpeakerLayout.qml @@ -4,10 +4,9 @@ import QtQuick.Effects import QtQml.Models import QtQuick.Controls.Basic as Control import Linphone -import EnumsToStringCpp 1.0 -import UtilsCpp 1.0 -import SettingsCpp 1.0 -import LinphoneAccountsCpp +import EnumsToStringCpp +import UtilsCpp +import SettingsCpp // ============================================================================= Item{ @@ -171,6 +170,7 @@ Item{ videoEnabled: preview.visible && mainItem.call && mainItem.call.core.localVideoEnabled onVideoEnabledChanged: console.log("P : " +videoEnabled + " / " +visible +" / " +mainItem.call) property AccountProxy accounts: AccountProxy {id: accountProxy + sourceModel: AppCpp.accounts } account: accountProxy.findAccountByAddress(mainItem.localAddress) call: mainItem.call diff --git a/Linphone/view/Control/Container/Call/GridLayout.qml b/Linphone/view/Control/Container/Call/GridLayout.qml index 30eace79e..646ec0f2b 100644 --- a/Linphone/view/Control/Container/Call/GridLayout.qml +++ b/Linphone/view/Control/Container/Call/GridLayout.qml @@ -3,7 +3,6 @@ import QtQuick.Layouts import QtQml.Models import Linphone -import LinphoneAccountsCpp // ============================================================================= @@ -23,7 +22,9 @@ Mosaic { qmlName: "G" Component.onCompleted: console.log("Loaded : " +allDevices + " = " +allDevices.count) } - property AccountProxy accounts: AccountProxy {id: accountProxy + property AccountProxy accounts: AccountProxy { + id: accountProxy + sourceModel: AppCpp.accounts } model: grid.call && grid.call.core.isConference ? participantDevices: [0,1] delegate: Item{ diff --git a/Linphone/view/Control/Display/Call/CallListView.qml b/Linphone/view/Control/Display/Call/CallListView.qml index 916a671be..f0c4dfd8a 100644 --- a/Linphone/view/Control/Display/Call/CallListView.qml +++ b/Linphone/view/Control/Display/Call/CallListView.qml @@ -10,6 +10,7 @@ ListView { id: mainItem model: CallProxy { id: callProxy + sourceModel: AppCpp.calls } implicitHeight: contentHeight spacing: 15 * DefaultStyle.dp diff --git a/Linphone/view/Control/Input/NumericPad.qml b/Linphone/view/Control/Input/NumericPad.qml index 14842391d..bf8b87aa8 100644 --- a/Linphone/view/Control/Input/NumericPad.qml +++ b/Linphone/view/Control/Input/NumericPad.qml @@ -4,7 +4,6 @@ import QtQuick.Layouts as Layout import QtQuick.Effects import Linphone import UtilsCpp -import LinphoneCallsCpp FocusScope{ id: mainItem diff --git a/Linphone/view/Control/Popup/NumericPadPopup.qml b/Linphone/view/Control/Popup/NumericPadPopup.qml index 689ac8d81..50ed7af59 100644 --- a/Linphone/view/Control/Popup/NumericPadPopup.qml +++ b/Linphone/view/Control/Popup/NumericPadPopup.qml @@ -4,7 +4,6 @@ import QtQuick.Layouts as Layout import QtQuick.Effects import Linphone import UtilsCpp -import LinphoneCallsCpp Control.Popup { id: mainItem diff --git a/Linphone/view/Control/Tool/Prototype/AccountsPrototype.qml b/Linphone/view/Control/Tool/Prototype/AccountsPrototype.qml index b6ce7e442..7bf2e69d6 100644 --- a/Linphone/view/Control/Tool/Prototype/AccountsPrototype.qml +++ b/Linphone/view/Control/Tool/Prototype/AccountsPrototype.qml @@ -3,7 +3,6 @@ import QtQuick.Layouts import QtQuick.Controls.Basic as Control import Linphone import UtilsCpp 1.0 -import LinphoneAccountsCpp // Snippet diff --git a/Linphone/view/Control/Tool/Prototype/CallPrototype.qml b/Linphone/view/Control/Tool/Prototype/CallPrototype.qml index 39a11b77f..fc0a12543 100644 --- a/Linphone/view/Control/Tool/Prototype/CallPrototype.qml +++ b/Linphone/view/Control/Tool/Prototype/CallPrototype.qml @@ -2,9 +2,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls.Basic as Control import Linphone -import UtilsCpp 1.0 -import LinphoneAccountsCpp -import LinphoneCallsCpp +import UtilsCpp // Snippet Window { diff --git a/Linphone/view/Page/Form/Settings/AccountSettingsPage.qml b/Linphone/view/Page/Form/Settings/AccountSettingsPage.qml index 20a8d50b1..964c3f487 100644 --- a/Linphone/view/Page/Form/Settings/AccountSettingsPage.qml +++ b/Linphone/view/Page/Form/Settings/AccountSettingsPage.qml @@ -3,14 +3,16 @@ import QtQuick.Effects import QtQuick.Layouts import QtQuick.Controls.Basic as Control import Linphone -import UtilsCpp 1.0 -import SettingsCpp 1.0 -import LinphoneAccountsCpp +import UtilsCpp +import SettingsCpp AbstractSettingsMenu { layoutsPath: "qrc:/qt/qml/Linphone/view/Page/Layout/Settings" titleText: qsTr("Mon compte") - property AccountProxy accounts: AccountProxy {id: accountProxy} + property AccountProxy accounts: AccountProxy { + id: accountProxy + sourceModel: AppCpp.accounts + } property AccountGui account: accountProxy.defaultAccount signal accountRemoved() families: [ diff --git a/Linphone/view/Page/Layout/Main/MainLayout.qml b/Linphone/view/Page/Layout/Main/MainLayout.qml index f0f1c5e34..d0ac94336 100644 --- a/Linphone/view/Page/Layout/Main/MainLayout.qml +++ b/Linphone/view/Page/Layout/Main/MainLayout.qml @@ -11,7 +11,6 @@ import QtQuick.Effects import Linphone import UtilsCpp import SettingsCpp -import LinphoneAccountsCpp Item { id: mainItem @@ -70,11 +69,13 @@ Item { AccountProxy { id: accountProxy + sourceModel: AppCpp.accounts onDefaultAccountChanged: if (tabbar.currentIndex === 0 && defaultAccount) defaultAccount.core?.lResetMissedCalls() } CallProxy { id: callsModel + sourceModel: AppCpp.calls } diff --git a/Linphone/view/Page/Main/Account/AccountListView.qml b/Linphone/view/Page/Main/Account/AccountListView.qml index b12af30ea..dd5013249 100644 --- a/Linphone/view/Page/Main/Account/AccountListView.qml +++ b/Linphone/view/Page/Main/Account/AccountListView.qml @@ -7,7 +7,6 @@ import QtQuick.Dialogs import Linphone import UtilsCpp import SettingsCpp -import LinphoneAccountsCpp Item { id: mainItem @@ -38,7 +37,7 @@ Item { Layout.preferredHeight: contentHeight Layout.fillWidth: true spacing: mainItem.spacing - model: LinphoneAccountsCpp + model: AppCpp.accounts delegate: Contact{ id: contactItem width: list.width diff --git a/Linphone/view/Page/Main/Call/CallPage.qml b/Linphone/view/Page/Main/Call/CallPage.qml index d3e3fae1a..3c0146978 100644 --- a/Linphone/view/Page/Main/Call/CallPage.qml +++ b/Linphone/view/Page/Main/Call/CallPage.qml @@ -5,7 +5,6 @@ import QtQuick.Controls.Basic as Control import Linphone import UtilsCpp import SettingsCpp -import LinphoneAccountsCpp AbstractMainPage { id: mainItem @@ -22,7 +21,10 @@ AbstractMainPage { //Group call properties property ConferenceInfoGui confInfoGui - property AccountProxy accounts: AccountProxy {id: accountProxy} + property AccountProxy accounts: AccountProxy { + id: accountProxy + sourceModel: AppCpp.accounts + } property AccountGui account: accountProxy.defaultAccount property var state: account && account.core?.registrationState || 0 property bool isRegistered: account ? account.core?.registrationState == LinphoneEnums.RegistrationState.Ok : false diff --git a/Linphone/view/Page/Main/Call/WaitingRoom.qml b/Linphone/view/Page/Main/Call/WaitingRoom.qml index 2156ee36b..0171bfb82 100644 --- a/Linphone/view/Page/Main/Call/WaitingRoom.qml +++ b/Linphone/view/Page/Main/Call/WaitingRoom.qml @@ -3,8 +3,7 @@ import QtQuick.Layouts import QtQuick.Effects import QtQuick.Controls.Basic as Control import Linphone -import UtilsCpp 1.0 -import LinphoneAccountsCpp +import UtilsCpp RowLayout { id: mainItem @@ -32,6 +31,7 @@ RowLayout { mutedStatus: microButton.checked AccountProxy { id: accounts + sourceModel: AppCpp.accounts } account: accounts.defaultAccount } diff --git a/Linphone/view/Page/Window/Call/CallsWindow.qml b/Linphone/view/Page/Window/Call/CallsWindow.qml index f50b3df03..696f8666f 100644 --- a/Linphone/view/Page/Window/Call/CallsWindow.qml +++ b/Linphone/view/Page/Window/Call/CallsWindow.qml @@ -3,11 +3,10 @@ import QtQuick.Layouts import QtQuick.Effects import QtQuick.Controls.Basic as Control import Linphone -import EnumsToStringCpp 1.0 -import UtilsCpp 1.0 -import SettingsCpp 1.0 -import DesktopToolsCpp 1.0 -import LinphoneCallsCpp +import EnumsToStringCpp +import UtilsCpp +import SettingsCpp +import DesktopToolsCpp AbstractWindow { id: mainWindow @@ -165,6 +164,7 @@ AbstractWindow { CallProxy{ id: callsModel + sourceModel: AppCpp.calls onCurrentCallChanged: { if(currentCall) { mainWindow.call = currentCall diff --git a/Linphone/view/Page/Window/Main/MainWindow.qml b/Linphone/view/Page/Window/Main/MainWindow.qml index b340a7355..50d50de47 100644 --- a/Linphone/view/Page/Window/Main/MainWindow.qml +++ b/Linphone/view/Page/Window/Main/MainWindow.qml @@ -3,9 +3,8 @@ import QtQuick.Layouts import QtQuick.Window import QtQuick.Controls.Basic import Linphone -import UtilsCpp 1.0 -import SettingsCpp 1.0 -import LinphoneAccountsCpp +import UtilsCpp +import SettingsCpp AbstractWindow { id: mainWindow @@ -17,7 +16,7 @@ AbstractWindow { color: DefaultStyle.grey_0 signal callCreated() - property var accountProxy: accountProxyLoader.item + property var accountProxy // TODO : use this to make the border transparent // flags: Qt.Window | Qt.FramelessWindowHint | Qt.WindowTitleHint @@ -98,11 +97,11 @@ AbstractWindow { id: accountProxyLoader active: AppCpp.coreStarted sourceComponent: AccountProxy { - Component.onCompleted: { + sourceModel: AppCpp.accounts + onInitializedChanged: { mainWindow.accountProxy = this mainWindow.initStackViewItem() } - onInitializedChanged: mainWindow.initStackViewItem() } }