Use sourceModel to set proxy models in order to avoid loading unused data.

This commit is contained in:
Julien Wadel 2024-10-23 16:12:03 +02:00
parent 075937aa00
commit 18fc4de29d
18 changed files with 87 additions and 53 deletions

View file

@ -482,8 +482,8 @@ void App::initCore() {
mSettings = settings; mSettings = settings;
mEngine->setObjectOwnership(mSettings.get(), QQmlEngine::CppOwnership); mEngine->setObjectOwnership(mSettings.get(), QQmlEngine::CppOwnership);
mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership); mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership);
mAccountList = AccountList::create(); setAccountList(AccountList::create());
mCallList = CallList::create(); setCallList(CallList::create());
setAutoStart(mSettings->getAutoStart()); setAutoStart(mSettings->getAutoStart());
setQuitOnLastWindowClosed(mSettings->getExitOnClose()); setQuitOnLastWindowClosed(mSettings->getExitOnClose());
connect(mSettings.get(), &SettingsCore::exitOnCloseChanged, this, &App::onExitOnCloseChanged, connect(mSettings.get(), &SettingsCore::exitOnCloseChanged, this, &App::onExitOnCloseChanged,
@ -561,12 +561,6 @@ void App::initCppInterfaces() {
qmlRegisterSingletonType<SettingsCore>( qmlRegisterSingletonType<SettingsCore>(
"SettingsCpp", 1, 0, "SettingsCpp", "SettingsCpp", 1, 0, "SettingsCpp",
[this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mSettings.get(); }); [this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mSettings.get(); });
qmlRegisterSingletonType<AccountList>(
"LinphoneAccountsCpp", 1, 0, "LinphoneAccountsCpp",
[this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mAccountList.get(); });
qmlRegisterSingletonType<CallList>(
"LinphoneCallsCpp", 1, 0, "LinphoneCallsCpp",
[this](QQmlEngine *engine, QJSEngine *) -> QObject * { return mCallList.get(); });
qmlRegisterType<PhoneNumberProxy>(Constants::MainQmlUri, 1, 0, "PhoneNumberProxy"); qmlRegisterType<PhoneNumberProxy>(Constants::MainQmlUri, 1, 0, "PhoneNumberProxy");
qmlRegisterType<VariantObject>(Constants::MainQmlUri, 1, 0, "VariantObject"); qmlRegisterType<VariantObject>(Constants::MainQmlUri, 1, 0, "VariantObject");
@ -799,10 +793,32 @@ QSharedPointer<AccountList> App::getAccountList() const {
return mAccountList; return mAccountList;
} }
void App::setAccountList(QSharedPointer<AccountList> data) {
if (mAccountList != data) {
mAccountList = data;
emit accountsChanged();
}
}
AccountList *App::getAccounts() const {
return mAccountList.get();
}
QSharedPointer<CallList> App::getCallList() const { QSharedPointer<CallList> App::getCallList() const {
return mCallList; return mCallList;
} }
void App::setCallList(QSharedPointer<CallList> data) {
if (mCallList != data) {
mCallList = data;
emit callsChanged();
}
}
CallList *App::getCalls() const {
return mCallList.get();
}
QSharedPointer<SettingsCore> App::getSettings() const { QSharedPointer<SettingsCore> App::getSettings() const {
return mSettings; return mSettings;
} }

View file

@ -39,6 +39,8 @@ class QSystemTrayIcon;
class App : public SingleApplication, public AbstractObject { class App : public SingleApplication, public AbstractObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool coreStarted READ getCoreStarted WRITE setCoreStarted NOTIFY coreStartedChanged) 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: public:
App(int &argc, char *argv[]); App(int &argc, char *argv[]);
~App(); ~App();
@ -124,7 +126,12 @@ public:
QQuickWindow *getMainWindow() const; QQuickWindow *getMainWindow() const;
void setMainWindow(QQuickWindow *data); void setMainWindow(QQuickWindow *data);
QSharedPointer<AccountList> getAccountList() const; QSharedPointer<AccountList> getAccountList() const;
void setAccountList(QSharedPointer<AccountList> data);
Q_INVOKABLE AccountList *getAccounts() const;
QSharedPointer<CallList> getCallList() const; QSharedPointer<CallList> getCallList() const;
void setCallList(QSharedPointer<CallList> data);
Q_INVOKABLE CallList *getCalls() const;
QSharedPointer<SettingsCore> getSettings() const; QSharedPointer<SettingsCore> getSettings() const;
void onExitOnCloseChanged(); // Can be used for UniqueConnection void onExitOnCloseChanged(); // Can be used for UniqueConnection
@ -146,6 +153,8 @@ public:
signals: signals:
void mainWindowChanged(); void mainWindowChanged();
void coreStartedChanged(bool coreStarted); void coreStartedChanged(bool coreStarted);
void accountsChanged();
void callsChanged();
// void executeCommand(QString command); // void executeCommand(QString command);
private: private:

View file

@ -24,17 +24,18 @@
#include "core/App.hpp" #include "core/App.hpp"
AccountProxy::AccountProxy(QObject *parent) : LimitProxy(parent) { 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() { AccountProxy::~AccountProxy() {
setSourceModel(nullptr);
} }
AccountGui *AccountProxy::getDefaultAccount() { AccountGui *AccountProxy::getDefaultAccount() {
if (!mDefaultAccount) if (!mDefaultAccount) {
mDefaultAccount = dynamic_cast<AccountList *>(dynamic_cast<SortFilterList *>(sourceModel())->sourceModel()) auto model = getListModel<AccountList>();
->getDefaultAccountCore(); if (model) mDefaultAccount = model->getDefaultAccountCore();
}
return new AccountGui(mDefaultAccount); return new AccountGui(mDefaultAccount);
} }
@ -48,15 +49,21 @@ void AccountProxy::resetDefaultAccount() {
} }
AccountGui *AccountProxy::findAccountByAddress(const QString &address) { AccountGui *AccountProxy::findAccountByAddress(const QString &address) {
return getListModel<AccountList>()->findAccountByAddress(address); auto model = getListModel<AccountList>();
if (model) return model->findAccountByAddress(address);
else return nullptr;
} }
AccountGui *AccountProxy::firstAccount() { AccountGui *AccountProxy::firstAccount() {
return getListModel<AccountList>()->firstAccount(); auto model = getListModel<AccountList>();
if (model) return model->firstAccount();
else return nullptr;
} }
bool AccountProxy::getHaveAccount() const { bool AccountProxy::getHaveAccount() const {
return getListModel<AccountList>()->getHaveAccount(); auto model = getListModel<AccountList>();
if (model) return model->getHaveAccount();
else return false;
} }
bool AccountProxy::isInitialized() const { bool AccountProxy::isInitialized() const {
@ -81,7 +88,6 @@ void AccountProxy::setSourceModel(QAbstractItemModel *model) {
qDebug() << "AccountProxy initialized"; qDebug() << "AccountProxy initialized";
setInitialized(init); setInitialized(init);
}); });
setInitialized(newAccountList->isInitialized());
connect(newAccountList, &AccountList::countChanged, this, &AccountProxy::resetDefaultAccount, connect(newAccountList, &AccountList::countChanged, this, &AccountProxy::resetDefaultAccount,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(newAccountList, &AccountList::defaultAccountChanged, this, &AccountProxy::resetDefaultAccount, connect(newAccountList, &AccountList::defaultAccountChanged, this, &AccountProxy::resetDefaultAccount,
@ -90,6 +96,7 @@ void AccountProxy::setSourceModel(QAbstractItemModel *model) {
Qt::QueuedConnection); Qt::QueuedConnection);
} }
setSourceModels(new SortFilterList(model, Qt::AscendingOrder)); setSourceModels(new SortFilterList(model, Qt::AscendingOrder));
if (newAccountList) setInitialized(newAccountList->isInitialized());
} }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------

View file

@ -26,7 +26,8 @@
DEFINE_ABSTRACT_OBJECT(CallProxy) DEFINE_ABSTRACT_OBJECT(CallProxy)
CallProxy::CallProxy(QObject *parent) : LimitProxy(parent) { 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() { CallProxy::~CallProxy() {
@ -49,7 +50,8 @@ void CallProxy::resetCurrentCall() {
} }
bool CallProxy::getHaveCall() const { bool CallProxy::getHaveCall() const {
return getListModel<CallList>()->getHaveCall(); auto model = getListModel<CallList>();
return model ? model->getHaveCall() : false;
} }
void CallProxy::setSourceModel(QAbstractItemModel *model) { void CallProxy::setSourceModel(QAbstractItemModel *model) {

View file

@ -4,10 +4,9 @@ import QtQuick.Effects
import QtQml.Models import QtQml.Models
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import EnumsToStringCpp 1.0 import EnumsToStringCpp
import UtilsCpp 1.0 import UtilsCpp
import SettingsCpp 1.0 import SettingsCpp
import LinphoneAccountsCpp
// ============================================================================= // =============================================================================
Item{ Item{
@ -171,6 +170,7 @@ Item{
videoEnabled: preview.visible && mainItem.call && mainItem.call.core.localVideoEnabled videoEnabled: preview.visible && mainItem.call && mainItem.call.core.localVideoEnabled
onVideoEnabledChanged: console.log("P : " +videoEnabled + " / " +visible +" / " +mainItem.call) onVideoEnabledChanged: console.log("P : " +videoEnabled + " / " +visible +" / " +mainItem.call)
property AccountProxy accounts: AccountProxy {id: accountProxy property AccountProxy accounts: AccountProxy {id: accountProxy
sourceModel: AppCpp.accounts
} }
account: accountProxy.findAccountByAddress(mainItem.localAddress) account: accountProxy.findAccountByAddress(mainItem.localAddress)
call: mainItem.call call: mainItem.call

View file

@ -3,7 +3,6 @@ import QtQuick.Layouts
import QtQml.Models import QtQml.Models
import Linphone import Linphone
import LinphoneAccountsCpp
// ============================================================================= // =============================================================================
@ -23,7 +22,9 @@ Mosaic {
qmlName: "G" qmlName: "G"
Component.onCompleted: console.log("Loaded : " +allDevices + " = " +allDevices.count) 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] model: grid.call && grid.call.core.isConference ? participantDevices: [0,1]
delegate: Item{ delegate: Item{

View file

@ -10,6 +10,7 @@ ListView {
id: mainItem id: mainItem
model: CallProxy { model: CallProxy {
id: callProxy id: callProxy
sourceModel: AppCpp.calls
} }
implicitHeight: contentHeight implicitHeight: contentHeight
spacing: 15 * DefaultStyle.dp spacing: 15 * DefaultStyle.dp

View file

@ -4,7 +4,6 @@ import QtQuick.Layouts as Layout
import QtQuick.Effects import QtQuick.Effects
import Linphone import Linphone
import UtilsCpp import UtilsCpp
import LinphoneCallsCpp
FocusScope{ FocusScope{
id: mainItem id: mainItem

View file

@ -4,7 +4,6 @@ import QtQuick.Layouts as Layout
import QtQuick.Effects import QtQuick.Effects
import Linphone import Linphone
import UtilsCpp import UtilsCpp
import LinphoneCallsCpp
Control.Popup { Control.Popup {
id: mainItem id: mainItem

View file

@ -3,7 +3,6 @@ import QtQuick.Layouts
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import UtilsCpp 1.0 import UtilsCpp 1.0
import LinphoneAccountsCpp
// Snippet // Snippet

View file

@ -2,9 +2,7 @@ import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import UtilsCpp 1.0 import UtilsCpp
import LinphoneAccountsCpp
import LinphoneCallsCpp
// Snippet // Snippet
Window { Window {

View file

@ -3,14 +3,16 @@ import QtQuick.Effects
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import UtilsCpp 1.0 import UtilsCpp
import SettingsCpp 1.0 import SettingsCpp
import LinphoneAccountsCpp
AbstractSettingsMenu { AbstractSettingsMenu {
layoutsPath: "qrc:/qt/qml/Linphone/view/Page/Layout/Settings" layoutsPath: "qrc:/qt/qml/Linphone/view/Page/Layout/Settings"
titleText: qsTr("Mon compte") titleText: qsTr("Mon compte")
property AccountProxy accounts: AccountProxy {id: accountProxy} property AccountProxy accounts: AccountProxy {
id: accountProxy
sourceModel: AppCpp.accounts
}
property AccountGui account: accountProxy.defaultAccount property AccountGui account: accountProxy.defaultAccount
signal accountRemoved() signal accountRemoved()
families: [ families: [

View file

@ -11,7 +11,6 @@ import QtQuick.Effects
import Linphone import Linphone
import UtilsCpp import UtilsCpp
import SettingsCpp import SettingsCpp
import LinphoneAccountsCpp
Item { Item {
id: mainItem id: mainItem
@ -70,11 +69,13 @@ Item {
AccountProxy { AccountProxy {
id: accountProxy id: accountProxy
sourceModel: AppCpp.accounts
onDefaultAccountChanged: if (tabbar.currentIndex === 0 && defaultAccount) defaultAccount.core?.lResetMissedCalls() onDefaultAccountChanged: if (tabbar.currentIndex === 0 && defaultAccount) defaultAccount.core?.lResetMissedCalls()
} }
CallProxy { CallProxy {
id: callsModel id: callsModel
sourceModel: AppCpp.calls
} }

View file

@ -7,7 +7,6 @@ import QtQuick.Dialogs
import Linphone import Linphone
import UtilsCpp import UtilsCpp
import SettingsCpp import SettingsCpp
import LinphoneAccountsCpp
Item { Item {
id: mainItem id: mainItem
@ -38,7 +37,7 @@ Item {
Layout.preferredHeight: contentHeight Layout.preferredHeight: contentHeight
Layout.fillWidth: true Layout.fillWidth: true
spacing: mainItem.spacing spacing: mainItem.spacing
model: LinphoneAccountsCpp model: AppCpp.accounts
delegate: Contact{ delegate: Contact{
id: contactItem id: contactItem
width: list.width width: list.width

View file

@ -5,7 +5,6 @@ import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import UtilsCpp import UtilsCpp
import SettingsCpp import SettingsCpp
import LinphoneAccountsCpp
AbstractMainPage { AbstractMainPage {
id: mainItem id: mainItem
@ -22,7 +21,10 @@ AbstractMainPage {
//Group call properties //Group call properties
property ConferenceInfoGui confInfoGui property ConferenceInfoGui confInfoGui
property AccountProxy accounts: AccountProxy {id: accountProxy} property AccountProxy accounts: AccountProxy {
id: accountProxy
sourceModel: AppCpp.accounts
}
property AccountGui account: accountProxy.defaultAccount property AccountGui account: accountProxy.defaultAccount
property var state: account && account.core?.registrationState || 0 property var state: account && account.core?.registrationState || 0
property bool isRegistered: account ? account.core?.registrationState == LinphoneEnums.RegistrationState.Ok : false property bool isRegistered: account ? account.core?.registrationState == LinphoneEnums.RegistrationState.Ok : false

View file

@ -3,8 +3,7 @@ import QtQuick.Layouts
import QtQuick.Effects import QtQuick.Effects
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import UtilsCpp 1.0 import UtilsCpp
import LinphoneAccountsCpp
RowLayout { RowLayout {
id: mainItem id: mainItem
@ -32,6 +31,7 @@ RowLayout {
mutedStatus: microButton.checked mutedStatus: microButton.checked
AccountProxy { AccountProxy {
id: accounts id: accounts
sourceModel: AppCpp.accounts
} }
account: accounts.defaultAccount account: accounts.defaultAccount
} }

View file

@ -3,11 +3,10 @@ import QtQuick.Layouts
import QtQuick.Effects import QtQuick.Effects
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import Linphone import Linphone
import EnumsToStringCpp 1.0 import EnumsToStringCpp
import UtilsCpp 1.0 import UtilsCpp
import SettingsCpp 1.0 import SettingsCpp
import DesktopToolsCpp 1.0 import DesktopToolsCpp
import LinphoneCallsCpp
AbstractWindow { AbstractWindow {
id: mainWindow id: mainWindow
@ -165,6 +164,7 @@ AbstractWindow {
CallProxy{ CallProxy{
id: callsModel id: callsModel
sourceModel: AppCpp.calls
onCurrentCallChanged: { onCurrentCallChanged: {
if(currentCall) { if(currentCall) {
mainWindow.call = currentCall mainWindow.call = currentCall

View file

@ -3,9 +3,8 @@ import QtQuick.Layouts
import QtQuick.Window import QtQuick.Window
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import Linphone import Linphone
import UtilsCpp 1.0 import UtilsCpp
import SettingsCpp 1.0 import SettingsCpp
import LinphoneAccountsCpp
AbstractWindow { AbstractWindow {
id: mainWindow id: mainWindow
@ -17,7 +16,7 @@ AbstractWindow {
color: DefaultStyle.grey_0 color: DefaultStyle.grey_0
signal callCreated() signal callCreated()
property var accountProxy: accountProxyLoader.item property var accountProxy
// TODO : use this to make the border transparent // TODO : use this to make the border transparent
// flags: Qt.Window | Qt.FramelessWindowHint | Qt.WindowTitleHint // flags: Qt.Window | Qt.FramelessWindowHint | Qt.WindowTitleHint
@ -98,11 +97,11 @@ AbstractWindow {
id: accountProxyLoader id: accountProxyLoader
active: AppCpp.coreStarted active: AppCpp.coreStarted
sourceComponent: AccountProxy { sourceComponent: AccountProxy {
Component.onCompleted: { sourceModel: AppCpp.accounts
onInitializedChanged: {
mainWindow.accountProxy = this mainWindow.accountProxy = this
mainWindow.initStackViewItem() mainWindow.initStackViewItem()
} }
onInitializedChanged: mainWindow.initStackViewItem()
} }
} }