From 6176f1971cb6ef95493e0a91c8a8fad79173f430 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 14 Mar 2024 17:08:25 +0100 Subject: [PATCH] Fix deadlocks and qml errors. --- .../core/conference/ConferenceInfoCore.cpp | 38 +++++++++++-------- Linphone/model/core/CoreModel.cpp | 1 + Linphone/tool/Utils.cpp | 17 ++++++--- Linphone/tool/thread/Thread.cpp | 8 +++- Linphone/view/Item/Call/CallContactsLists.qml | 3 -- Linphone/view/Item/ComboBox.qml | 12 +++--- Linphone/view/Item/Contact/ContactsList.qml | 21 ++++++---- Linphone/view/Item/Meeting/NewMeeting.qml | 4 +- external/linphone-sdk | 2 +- 9 files changed, 62 insertions(+), 44 deletions(-) diff --git a/Linphone/core/conference/ConferenceInfoCore.cpp b/Linphone/core/conference/ConferenceInfoCore.cpp index 68c6dcc20..a20df2eee 100644 --- a/Linphone/core/conference/ConferenceInfoCore.cpp +++ b/Linphone/core/conference/ConferenceInfoCore.cpp @@ -85,16 +85,18 @@ ConferenceInfoCore::ConferenceInfoCore(std::shared_ptr } mConferenceInfoState = LinphoneEnums::fromLinphone(conferenceInfo->getState()); } else { - auto defaultAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); - if (defaultAccount) { - auto accountAddress = defaultAccount->getContactAddress(); - if (accountAddress) { - auto cleanedClonedAddress = accountAddress->clone(); - cleanedClonedAddress->clean(); - mOrganizerAddress = Utils::coreStringToAppString(cleanedClonedAddress->asStringUriOnly()); - qDebug() << "set organizer address" << mOrganizerAddress; + App::postModelSync([this]() { + auto defaultAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); + if (defaultAccount) { + auto accountAddress = defaultAccount->getContactAddress(); + if (accountAddress) { + auto cleanedClonedAddress = accountAddress->clone(); + cleanedClonedAddress->clean(); + mOrganizerAddress = Utils::coreStringToAppString(cleanedClonedAddress->asStringUriOnly()); + qDebug() << "set organizer address" << mOrganizerAddress; + } } - } + }); } connect(this, &ConferenceInfoCore::endDateTimeChanged, @@ -146,7 +148,7 @@ void ConferenceInfoCore::setSelf(SafeSharedPointer me) { void ConferenceInfoCore::setSelf(QSharedPointer me) { if (me) { if (mConferenceInfoModel) { - mCoreModelConnection = nullptr; + mConfInfoModelConnection = nullptr; mConfInfoModelConnection = QSharedPointer>( new SafeConnection(me, mConferenceInfoModel), &QObject::deleteLater); @@ -175,9 +177,10 @@ void ConferenceInfoCore::setSelf(QSharedPointer me) { mConfInfoModelConnection->makeConnectToModel(&ConferenceInfoModel::conferenceInfoDeleted, &ConferenceInfoCore::removed); - mConfInfoModelConnection->makeConnectToModel( - &ConferenceInfoModel::stateChanged, - [this](linphone::ConferenceScheduler::State state) { qDebug() << "conf state changed"; }); + mConfInfoModelConnection->makeConnectToModel(&ConferenceInfoModel::stateChanged, + [this](linphone::ConferenceScheduler::State state) { + qDebug() << "conf state changed:" << (int)state; + }); mConfInfoModelConnection->makeConnectToModel( &ConferenceInfoModel::invitationsSent, [this](const std::list> &failedInvitations) { @@ -332,7 +335,7 @@ void ConferenceInfoCore::addParticipant(const QString &address) { } QVariantMap participant; auto displayNameObj = Utils::getDisplayName(address); - if (displayNameObj) participant["displayName"] = displayNameObj->getValue(); + participant["displayName"] = displayNameObj ? displayNameObj->getValue() : ""; participant["address"] = address; participant["role"] = (int)LinphoneEnums::ParticipantRole::Listener; mParticipants.append(participant); @@ -515,8 +518,11 @@ void ConferenceInfoCore::save() { } thisCopy->writeIntoModel(mConferenceInfoModel); thisCopy->deleteLater(); - confSchedulerModel->setInfo(linphoneConf); - mCoreModelConnection->invokeToCore([this]() { setSelf(mCoreModelConnection->mCore); }); + mCoreModelConnection->invokeToCore([this, confSchedulerModel, linphoneConf]() { + setSelf(mCoreModelConnection->mCore); + mCoreModelConnection->invokeToModel( + [this, confSchedulerModel, linphoneConf]() { confSchedulerModel->setInfo(linphoneConf); }); + }); }); } } diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index cf71c5d9a..c328d4a15 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -105,6 +105,7 @@ std::shared_ptr CoreModel::getInstance() { } std::shared_ptr CoreModel::getCore() { + mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); return mCore; } diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 7e508ce44..6701a1329 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -281,12 +281,17 @@ QString Utils::generateLinphoneSipAddress(const QString &uri) { } QString Utils::findAvatarByAddress(const QString &address) { - auto defaultFriendList = CoreModel::getInstance()->getCore()->getDefaultFriendList(); - if (!defaultFriendList) return QString(); - auto linphoneAddr = ToolModel::interpretUrl(address); - auto linFriend = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr); - if (linFriend) return Utils::coreStringToAppString(linFriend->getPhoto()); - return QString(); + QString avatar; + + App::postModelSync([address, avatar]() mutable { + auto defaultFriendList = CoreModel::getInstance()->getCore()->getDefaultFriendList(); + if (!defaultFriendList) return; + auto linphoneAddr = ToolModel::interpretUrl(address); + auto linFriend = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr); + if (linFriend) avatar = Utils::coreStringToAppString(linFriend->getPhoto()); + }); + + return avatar; } QString Utils::generateSavedFilename(const QString &from, const QString &to) { diff --git a/Linphone/tool/thread/Thread.cpp b/Linphone/tool/thread/Thread.cpp index 2daca432d..274865f7f 100644 --- a/Linphone/tool/thread/Thread.cpp +++ b/Linphone/tool/thread/Thread.cpp @@ -39,13 +39,17 @@ bool Thread::isInLinphoneThread() { bool Thread::mustBeInLinphoneThread(const QString &context) { bool isLinphoneThread = isInLinphoneThread(); - if (!isLinphoneThread) qCritical() << "[Thread] Not processing in Linphone thread from " << context; + if (!isLinphoneThread) { // Bracket to easier debugging. + qCritical() << "[Thread] Not processing in Linphone thread from " << context; + } return isLinphoneThread; } bool Thread::mustBeInMainThread(const QString &context) { if (!qApp) return true; bool isMainThread = QThread::currentThread() == qApp->thread(); - if (!isMainThread) qCritical() << "[Thread] Not processing in Main thread from " << context; + if (!isMainThread) { + qCritical() << "[Thread] Not processing in Main thread from " << context; + } return isMainThread; } diff --git a/Linphone/view/Item/Call/CallContactsLists.qml b/Linphone/view/Item/Call/CallContactsLists.qml index b53a857a6..74d6de7a2 100644 --- a/Linphone/view/Item/Call/CallContactsLists.qml +++ b/Linphone/view/Item/Call/CallContactsLists.qml @@ -232,9 +232,6 @@ Item { model: MagicSearchProxy { searchText: searchBarText.length === 0 ? "*" : searchBarText } - onContactSelected: (contact) => { - if (contact.core.allAddresses.length > 1) { - startCallPopup.contact = contact onSelectedContactChanged: { if (selectedContact) { if (selectedContact.core.allAddresses.length > 1) { diff --git a/Linphone/view/Item/ComboBox.qml b/Linphone/view/Item/ComboBox.qml index 1a2a86e32..63818414c 100644 --- a/Linphone/view/Item/ComboBox.qml +++ b/Linphone/view/Item/ComboBox.qml @@ -129,7 +129,7 @@ Control.ComboBox { visible: source != "" width: visible ? 20 * DefaultStyle.dp : 0 sourceSize.width: 20 * DefaultStyle.dp - source: modelData.img ? modelData.img : "" + source: modelData && modelData.img ? modelData.img : "" fillMode: Image.PreserveAspectFit anchors.left: parent.left anchors.leftMargin: visible ? 10 * DefaultStyle.dp : 0 @@ -137,11 +137,11 @@ Control.ComboBox { } Text { - text: modelData.text - ? modelData.text - : modelData - ? modelData - : "" + text: modelData + ? modelData.text + ? modelData.text + : modelData + : "" elide: Text.ElideRight maximumLineCount: 1 wrapMode: Text.WrapAnywhere diff --git a/Linphone/view/Item/Contact/ContactsList.qml b/Linphone/view/Item/Contact/ContactsList.qml index e6a7c4088..b51677904 100644 --- a/Linphone/view/Item/Contact/ContactsList.qml +++ b/Linphone/view/Item/Contact/ContactsList.qml @@ -34,7 +34,7 @@ ListView { property int delegateLeftMargin: 0 currentIndex: -1 - property var delegateButtons + property var delegateButtons: [] property FriendGui selectedContact: model.getAt(currentIndex) || null @@ -120,20 +120,25 @@ ListView { } RowLayout { + id: actionsRow z: 1 - height: parent.height - anchors.right: parent.right + anchors.fill: parent anchors.rightMargin: 5 * DefaultStyle.dp - anchors.verticalCenter: parent.verticalCenter - children: mainItem.delegateButtons || [] + RowLayout{ + Layout.fillWidth: true + Layout.fillHeight: true + children: mainItem.delegateButtons + } PopupButton { id: friendPopup z: 1 - hoverEnabled: mainItem.hoverEnabled - visible: mainItem.contactMenuVisible && (contactArea.containsMouse || hovered || popup.opened) && (!delegateButtons || delegateButtons.children.length === 0) + Layout.rightMargin: 5 * DefaultStyle.dp + Layout.alignment: Qt.AlignVCenter popup.x: 0 popup.padding: 10 * DefaultStyle.dp - Layout.rightMargin: 5 * DefaultStyle.dp + hoverEnabled: mainItem.hoverEnabled + visible: mainItem.contactMenuVisible && (contactArea.containsMouse || hovered || popup.opened) && (!mainItem.delegateButtons || mainItem.delegateButtons.length === 0) + popup.contentItem: ColumnLayout { Button { background: Item{} diff --git a/Linphone/view/Item/Meeting/NewMeeting.qml b/Linphone/view/Item/Meeting/NewMeeting.qml index 29495cbf3..50bee85ce 100644 --- a/Linphone/view/Item/Meeting/NewMeeting.qml +++ b/Linphone/view/Item/Meeting/NewMeeting.qml @@ -334,7 +334,7 @@ ColumnLayout { model: mainItem.conferenceInfoGui.core.participants delegate: Item { height: 56 * DefaultStyle.dp - width: parent.width + width: participantList.width RowLayout { anchors.fill: parent Avatar { @@ -374,4 +374,4 @@ ColumnLayout { Item { Layout.fillHeight: true } -} \ No newline at end of file +} diff --git a/external/linphone-sdk b/external/linphone-sdk index 98c2b724e..0dda330ac 160000 --- a/external/linphone-sdk +++ b/external/linphone-sdk @@ -1 +1 @@ -Subproject commit 98c2b724e1a045eb46ccba23a912ba6e1ac0647d +Subproject commit 0dda330ac9ccd7f5b495ac147e88ff7dbb620762