From 28bb18894129da7367424a7307fc2d2ff2720927 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 9 Jan 2025 17:24:07 +0100 Subject: [PATCH] Fix bad thread on Contact creation. Fix contact selection after creation. --- Linphone/core/friend/FriendCore.cpp | 4 ++-- Linphone/core/search/MagicSearchProxy.cpp | 2 +- .../Display/Contact/ContactListView.qml | 24 +++++++++++++++---- .../view/Page/Form/Contact/ContactEdition.qml | 9 +++---- .../view/Page/Main/Contact/ContactPage.qml | 20 +++++++++++----- Linphone/view/Page/Window/AbstractWindow.qml | 1 + 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Linphone/core/friend/FriendCore.cpp b/Linphone/core/friend/FriendCore.cpp index 6b8d886b6..8e7d1ac05 100644 --- a/Linphone/core/friend/FriendCore.cpp +++ b/Linphone/core/friend/FriendCore.cpp @@ -84,13 +84,13 @@ FriendCore::FriendCore(const std::shared_ptr &contact, bool is mStarred = contact->getStarred(); mIsSaved = true; mIsStored = isStored; + mIsLdap = ToolModel::friendIsInFriendList(ToolModel::getLdapFriendList(), contact); } else { mIsSaved = false; mStarred = false; mIsStored = false; + mIsLdap = false; } - - mIsLdap = ToolModel::friendIsInFriendList(ToolModel::getLdapFriendList(), contact); connect(this, &FriendCore::addressChanged, &FriendCore::allAddressesChanged); connect(this, &FriendCore::phoneNumberChanged, &FriendCore::allAddressesChanged); } diff --git a/Linphone/core/search/MagicSearchProxy.cpp b/Linphone/core/search/MagicSearchProxy.cpp index bbe3c5674..0a3e190f8 100644 --- a/Linphone/core/search/MagicSearchProxy.cpp +++ b/Linphone/core/search/MagicSearchProxy.cpp @@ -111,7 +111,7 @@ int MagicSearchProxy::loadUntil(const QString &address) { if (listIndex == -1) return -1; listIndex = dynamic_cast(sourceModel())->mapFromSource(magicSearchList->index(listIndex, 0)).row(); - if (mMaxDisplayItems < listIndex) setMaxDisplayItems(listIndex + mDisplayItemsStep); + if (mMaxDisplayItems <= listIndex) setMaxDisplayItems(listIndex + mDisplayItemsStep); return listIndex; } return -1; diff --git a/Linphone/view/Control/Display/Contact/ContactListView.qml b/Linphone/view/Control/Display/Contact/ContactListView.qml index 6745b8287..190eca8b3 100644 --- a/Linphone/view/Control/Display/Contact/ContactListView.qml +++ b/Linphone/view/Control/Display/Contact/ContactListView.qml @@ -68,8 +68,10 @@ ListView { mainItem.highlightedContact = item.searchResultItem item.forceActiveFocus() updatePosition() + _moveToIndex = false }else{// Move on the next items load. - _moveToIndex = true + // If visible, try to wait loading + _moveToIndex = visible } }else{ mainItem.currentIndex = -1 @@ -77,12 +79,10 @@ ListView { if(headerItem) { headerItem.forceActiveFocus() } + _moveToIndex = false } } - onCountChanged: if(_moveToIndex && count > mainItem.currentIndex ){ - _moveToIndex = false - selectIndex(mainItem.currentIndex) - } + onContactSelected: updatePosition() onExpandedChanged: if(!expanded) updatePosition() keyNavigationEnabled: false @@ -116,6 +116,20 @@ ListView { magicSearchProxy.forceUpdate() } } + // Workaround: itemAtIndex and count are decorellated and are not enough to know when the ListView has load all its children. + // So when itemAtIndex is not available, start this timer along count changed signal. + Timer{ + id: delaySelection + interval: 100 + running: _moveToIndex + onTriggered: { + _moveToIndex = false + if(count > mainItem.currentIndex) selectIndex(mainItem.currentIndex) + else{ + _moveToIndex = true + } + } + } header: FocusScope{ id: headerItem diff --git a/Linphone/view/Page/Form/Contact/ContactEdition.qml b/Linphone/view/Page/Form/Contact/ContactEdition.qml index 417f78824..910c1b772 100644 --- a/Linphone/view/Page/Form/Contact/ContactEdition.qml +++ b/Linphone/view/Page/Form/Contact/ContactEdition.qml @@ -17,9 +17,7 @@ MainRightPanel { target: contact.core function onIsSavedChanged() { if (contact.core.isSaved) { - var mainWin = UtilsCpp.getMainWindow() - UtilsCpp.smartShowWindow(mainWin) - mainWin.displayContactPage(contact) + mainItem.closeEdition(contact.core.defaultFullAddress) } } } @@ -28,13 +26,13 @@ MainRightPanel { property string oldPictureUri property int addressCount: 0 - signal closeEdition() + signal closeEdition(var redirectAddress) Dialog { id: confirmDialog onAccepted: { mainItem.contact.core.undo() - mainItem.closeEdition() + mainItem.closeEdition('') } width: 278 * DefaultStyle.dp text: qsTr("Les changements seront annulés. Souhaitez-vous continuer ?") @@ -81,7 +79,6 @@ MainRightPanel { return } mainItem.contact.core.save() - mainItem.closeEdition() } bannerContent: [ IconLabelButton { diff --git a/Linphone/view/Page/Main/Contact/ContactPage.qml b/Linphone/view/Page/Main/Contact/ContactPage.qml index 2cc435900..bc535ab47 100644 --- a/Linphone/view/Page/Main/Contact/ContactPage.qml +++ b/Linphone/view/Page/Main/Contact/ContactPage.qml @@ -18,20 +18,26 @@ AbstractMainPage { property bool leftPanelEnabled: !rightPanelStackView.currentItem || rightPanelStackView.currentItem.objectName != "contactEdition" property FriendGui selectedContact property string initialFriendToDisplay - onInitialFriendToDisplayChanged: if (initialFriendToDisplay != '' && contactList.selectContact(initialFriendToDisplay) != -1) initialFriendToDisplay = "" + onInitialFriendToDisplayChanged: { + if (initialFriendToDisplay != '' && contactList.selectContact(initialFriendToDisplay) != -1) initialFriendToDisplay = "" + else if(initialFriendToDisplay != '') console.warn("Abstract not selected yet: ", initialFriendToDisplay) + } onVisibleChanged: if (!visible) { rightPanelStackView.clear() contactList.resetSelections() } - - onSelectedContactChanged: { + function updateRightPanel(){ if (selectedContact) { + while(rightPanelStackView.depth > 1) rightPanelStackView.pop() if (!rightPanelStackView.currentItem || rightPanelStackView.currentItem.objectName != "contactDetail") rightPanelStackView.push(contactDetail) } else { if (rightPanelStackView.currentItem && rightPanelStackView.currentItem.objectName === "contactDetail") rightPanelStackView.clear() } } + onSelectedContactChanged: { + updateRightPanel() + } onNoItemButtonPressed: createContact("", "") @@ -747,9 +753,11 @@ AbstractMainPage { id: contactEdition ContactEdition { property string objectName: "contactEdition" - onCloseEdition: { - if (rightPanelStackView.depth <= 1) rightPanelStackView.clear() - else rightPanelStackView.pop(Control.StackView.Immediate) + onCloseEdition: redirectAddress => { + updateRightPanel() + if(redirectAddress){ + initialFriendToDisplay = redirectAddress + } } } } diff --git a/Linphone/view/Page/Window/AbstractWindow.qml b/Linphone/view/Page/Window/AbstractWindow.qml index 143ba1e75..9b1b472c3 100644 --- a/Linphone/view/Page/Window/AbstractWindow.qml +++ b/Linphone/view/Page/Window/AbstractWindow.qml @@ -17,6 +17,7 @@ ApplicationWindow { property bool isFullscreen: visibility == Window.FullScreen onIsFullscreenChanged: DesktopToolsCpp.screenSaverStatus = !isFullscreen + MouseArea { anchors.fill: parent