From 0c9499910cd98ca51dfc6ac99570285eb612d171 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Wed, 22 Mar 2023 13:19:21 -0400 Subject: [PATCH] mainapplication: fix spoiled rebase Reverts accidental rebase issues in f6f9034 (Patchset 24 -> 25). Fixes view management during last account deletion and first account creation. Gitlab: #902 Change-Id: Ieacf816ef9a30e27973115dc70d029106b72bb07 --- src/app/MainApplicationWindow.qml | 37 ++++++++++++------ src/app/ViewCoordinator.qml | 13 ++++--- src/app/ViewManager.qml | 38 ++++++++----------- src/app/accountadapter.cpp | 4 +- src/app/accountadapter.h | 1 - src/app/mainview/components/SidePanel.qml | 12 +++--- src/app/settingsview/SettingsView.qml | 11 +++++- .../components/CurrentAccountSettings.qml | 1 - 8 files changed, 64 insertions(+), 53 deletions(-) diff --git a/src/app/MainApplicationWindow.qml b/src/app/MainApplicationWindow.qml index 2b78a8969..b8f10e34d 100644 --- a/src/app/MainApplicationWindow.qml +++ b/src/app/MainApplicationWindow.qml @@ -72,14 +72,29 @@ ApplicationWindow { function startClient() { if (UtilsAdapter.getAccountListSize() !== 0) { - mainApplicationLoader.setSource(JamiQmlUtils.mainViewLoadPath) + setMainLoaderSource(JamiQmlUtils.mainViewLoadPath) } else { - mainApplicationLoader.setSource(JamiQmlUtils.wizardViewLoadPath) + setMainLoaderSource(JamiQmlUtils.wizardViewLoadPath) } } function startAccountMigration() { - mainApplicationLoader.setSource(JamiQmlUtils.accountMigrationViewLoadPath) + setMainLoaderSource(JamiQmlUtils.accountMigrationViewLoadPath) + } + + function setMainLoaderSource(source) { + if (checkLoadedSource() === MainApplicationWindow.LoadedSource.MainView) { + cleanupMainView() + } + mainApplicationLoader.setSource(source) + } + + function cleanupMainView() { + // Save the main view window size if loading anything else. + layoutManager.saveWindowSettings() + + // Unload any created views used by the main view. + viewCoordinator.deinit() } function close(force = false) { @@ -87,9 +102,9 @@ ApplicationWindow { // is set, then we can quit if (force || !UtilsAdapter.getAppValue(Settings.MinimizeOnClose) || !UtilsAdapter.getAccountListSize()) { - // Save the window geometry and state before quitting. - layoutManager.saveWindowSettings() - viewCoordinator.deinit() + if (checkLoadedSource() === MainApplicationWindow.LoadedSource.MainView) { + cleanupMainView() + } Qt.quit() } else { layoutManager.closeToTray() @@ -123,7 +138,7 @@ ApplicationWindow { target: viewCoordinator function onRequestAppWindowWizardView() { - mainApplicationLoader.setSource(JamiQmlUtils.wizardViewLoadPath) + setMainLoaderSource(JamiQmlUtils.wizardViewLoadPath) } } @@ -132,9 +147,9 @@ ApplicationWindow { function onLoaderSourceChangeRequested(sourceToLoad) { if (sourceToLoad === MainApplicationWindow.LoadedSource.WizardView) - mainApplicationLoader.setSource(JamiQmlUtils.wizardViewLoadPath) + setMainLoaderSource(JamiQmlUtils.wizardViewLoadPath) else - mainApplicationLoader.setSource(JamiQmlUtils.mainViewLoadPath) + setMainLoaderSource(JamiQmlUtils.mainViewLoadPath) } } @@ -144,9 +159,7 @@ ApplicationWindow { onLoaded: { if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView) { // Onboarding wizard window, these settings are fixed. - // - window screen should default to the primary - // - position should default to being centered based on the - // following dimensions + // - window screen will default to the primary // - the window will showNormal once windowSettingsLoaded is // set to true(then forcing visible to true) appWindow.width = JamiTheme.wizardViewMinWidth diff --git a/src/app/ViewCoordinator.qml b/src/app/ViewCoordinator.qml index 76f3034ef..c4c9148d8 100644 --- a/src/app/ViewCoordinator.qml +++ b/src/app/ViewCoordinator.qml @@ -46,18 +46,19 @@ QtObject { // The `main` view of the application window. property StackView rootView - property var currentViewName: rootView && rootView.currentItem.objectName || null + property var currentViewName: rootView && rootView.currentItem && + rootView.currentItem.objectName || null - function init(appWindow) { + function init(mainStackView) { rootView = Qt.createQmlObject(`import QtQuick; import QtQuick.Controls StackView { anchors.fill: parent }`, - appWindow) + mainStackView) initialized() } function deinit() { viewManager.destroyAllViews() - rootView.destroy() + if (rootView) rootView.destroy() } // Finds a view and gets its index within the StackView it's in. @@ -120,8 +121,8 @@ QtObject { // Dismiss by object. function dismissObj(obj) { - if (obj.StackView.view !== rootView) { - print("view not in the stack:", obj) + // Check if it makes sense to remove this view at all. + if (obj.StackView.view !== rootView || !viewManager.viewCount()) { return } diff --git a/src/app/ViewManager.qml b/src/app/ViewManager.qml index 3cf03d6cf..310af0e94 100644 --- a/src/app/ViewManager.qml +++ b/src/app/ViewManager.qml @@ -24,8 +24,11 @@ QtObject { property variant views: ({}) // A map of view names to path strings. property variant viewPaths: ({}) - // The number of views. - property int nViews: 0 + + // The number of views loaded (`views` is only resized). + function viewCount() { + return Object.keys(views).length + } // Destroy all views. function destroyAllViews() { @@ -35,7 +38,7 @@ QtObject { } function createView(path, parent=null, cb=null, props={}) { - if (views[path] !== undefined) { + if (views.hasOwnProperty(path)) { // an instance of <path> already exists if (cb !== null) { cb(views[path]) @@ -56,7 +59,6 @@ QtObject { obj.objectName : path.replace(/^.*[\\\/]/, '').replace(/\.[^/.]+$/, "") viewPaths[viewName] = path - nViews = Object.keys(views).length if (cb !== null) { cb(obj) } @@ -69,32 +71,22 @@ QtObject { } function destroyView(path) { - if (views[path] === undefined) { - print(path, "instance does not exist", Object.keys(views)) + // The view may already have been destroyed. + if (!views.hasOwnProperty(path)) { return false } views[path].destroy() - views[path] = undefined - // QObject::destroy is queued, and we can't connect to its completion, - // so we queue the resulting mutation to our view storage. - Qt.callLater(function() { - delete views[path] - // Remove the view name from the viewPaths map. - for (var viewName in viewPaths) { - if (viewPaths[viewName] === path) { - delete viewPaths[viewName] - break - } + delete views[path] + // Remove the view name from the viewPaths map. + for (var viewName in viewPaths) { + if (viewPaths[viewName] === path) { + delete viewPaths[viewName] + break } - nViews = Object.keys(views).length - }) + } return true } - function hasView(viewName) { - return nViews && viewPaths[viewName] !== undefined - } - function getView(viewName) { return views[viewPaths[viewName]] || null } diff --git a/src/app/accountadapter.cpp b/src/app/accountadapter.cpp index 74eb92100..a60446ad3 100644 --- a/src/app/accountadapter.cpp +++ b/src/app/accountadapter.cpp @@ -257,12 +257,10 @@ AccountAdapter::deleteCurrentAccount() &lrc::api::AccountModel::accountRemoved, [this](const QString& accountId) { Q_UNUSED(accountId); - // For testing purpose - Q_EMIT accountRemoved(); + Q_EMIT lrcInstance_->accountListChanged(); }); lrcInstance_->accountModel().removeAccount(lrcInstance_->get_currentAccountId()); - Q_EMIT lrcInstance_->accountListChanged(); } bool diff --git a/src/app/accountadapter.h b/src/app/accountadapter.h index 8b4749416..7ecfa9442 100644 --- a/src/app/accountadapter.h +++ b/src/app/accountadapter.h @@ -88,7 +88,6 @@ Q_SIGNALS: void reportFailure(); void accountCreationFailed(); void accountAdded(QString accountId, int index); - void accountRemoved(); void accountConfigFinalized(); private: diff --git a/src/app/mainview/components/SidePanel.qml b/src/app/mainview/components/SidePanel.qml index d5eeb0590..768a36372 100644 --- a/src/app/mainview/components/SidePanel.qml +++ b/src/app/mainview/components/SidePanel.qml @@ -241,13 +241,13 @@ SidePanelBase { anchors.right: parent.right anchors.rightMargin: 15 - Shortcut { - sequence: "Ctrl+F" - context: Qt.ApplicationShortcut - onActivated: { - contactSearchBar.forceActiveFocus() - } + Shortcut { + sequence: "Ctrl+F" + context: Qt.ApplicationShortcut + onActivated: { + contactSearchBar.forceActiveFocus() } + } ContactSearchBar { id: contactSearchBar diff --git a/src/app/settingsview/SettingsView.qml b/src/app/settingsview/SettingsView.qml index c50760abc..2ba325b31 100644 --- a/src/app/settingsview/SettingsView.qml +++ b/src/app/settingsview/SettingsView.qml @@ -47,6 +47,7 @@ ListSelectionView { onDismissed: { // Trigger an update to messages if needed. + // Currently needed when changing the show link preview setting. CurrentConversation.reloadInteractions() settingsViewRect.stopBooth() if (UtilsAdapter.getAccountListSize() === 0) { @@ -168,7 +169,15 @@ ListSelectionView { isSIP: settingsViewRect.isSIP onNavigateToMainView: dismiss() - onNavigateToNewWizardView: dismiss() + Connections { + target: LRCInstance + + function onAccountListChanged() { + if (!UtilsAdapter.getAccountListSize()) { + viewCoordinator.requestAppWindowWizardView() + } + } + } onAdvancedSettingsToggled: function (settingsVisible) { if (settingsVisible) diff --git a/src/app/settingsview/components/CurrentAccountSettings.qml b/src/app/settingsview/components/CurrentAccountSettings.qml index bfea23ea0..4ced54f45 100644 --- a/src/app/settingsview/components/CurrentAccountSettings.qml +++ b/src/app/settingsview/components/CurrentAccountSettings.qml @@ -37,7 +37,6 @@ Rectangle { property int preferredColumnWidth : Math.min(root.width / 2 - 50, 350) signal navigateToMainView - signal navigateToNewWizardView signal advancedSettingsToggled(bool settingsVisible) function updateAccountInfoDisplayed() { -- GitLab