Fix bad thread on Contact creation.

Fix contact selection after creation.
This commit is contained in:
Julien Wadel 2025-01-09 17:24:07 +01:00
parent cde6bc0788
commit 28bb188941
6 changed files with 40 additions and 20 deletions

View file

@ -84,13 +84,13 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &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);
}

View file

@ -111,7 +111,7 @@ int MagicSearchProxy::loadUntil(const QString &address) {
if (listIndex == -1) return -1;
listIndex =
dynamic_cast<SortFilterList *>(sourceModel())->mapFromSource(magicSearchList->index(listIndex, 0)).row();
if (mMaxDisplayItems < listIndex) setMaxDisplayItems(listIndex + mDisplayItemsStep);
if (mMaxDisplayItems <= listIndex) setMaxDisplayItems(listIndex + mDisplayItemsStep);
return listIndex;
}
return -1;

View file

@ -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

View file

@ -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 {

View file

@ -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
}
}
}
}

View file

@ -17,6 +17,7 @@ ApplicationWindow {
property bool isFullscreen: visibility == Window.FullScreen
onIsFullscreenChanged: DesktopToolsCpp.screenSaverStatus = !isFullscreen
MouseArea {
anchors.fill: parent