1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-04 07:35:26 +02:00

mainwindow: save/restore window geometry

Save virtual desktop geometry and window visibility state settings
and set them for the application window when loading.

Gitlab: #604
Change-Id: I053716d9c7b5d23e1bd7f33a1c41aedefb6cf9c8
This commit is contained in:
Andreas Traczyk 2022-01-11 13:38:57 -05:00
parent 0c1b1cd426
commit 70a6972b7e
8 changed files with 77 additions and 34 deletions

View file

@ -52,6 +52,8 @@ ApplicationWindow {
appContainer: appContainer appContainer: appContainer
} }
property bool windowSettingsLoaded: false
function checkLoadedSource() { function checkLoadedSource() {
var sourceString = mainApplicationLoader.source.toString() var sourceString = mainApplicationLoader.source.toString()
@ -80,35 +82,20 @@ ApplicationWindow {
// is set, then we can quit // is set, then we can quit
if (force || !UtilsAdapter.getAppValue(Settings.MinimizeOnClose) || if (force || !UtilsAdapter.getAppValue(Settings.MinimizeOnClose) ||
!UtilsAdapter.getAccountListSize()) { !UtilsAdapter.getAccountListSize()) {
// Save the window geometry and state before quitting.
var geometry = Qt.rect(appWindow.x, appWindow.y,
appWindow.width, appWindow.height)
AppSettingsManager.setValue(Settings.WindowGeometry, geometry)
AppSettingsManager.setValue(Settings.WindowState, appWindow.visibility)
Qt.quit() Qt.quit()
} else } else {
hide() hide()
}
} }
title: JamiStrings.appTitle title: JamiStrings.appTitle
width: { visible: mainApplicationLoader.status === Loader.Ready && windowSettingsLoaded
if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView)
return JamiTheme.wizardViewMinWidth
return JamiTheme.mainViewPreferredWidth
}
height: {
if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView)
return JamiTheme.wizardViewMinHeight
return JamiTheme.mainViewPreferredHeight
}
minimumWidth: {
if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView)
return JamiTheme.wizardViewMinWidth
return JamiTheme.mainViewMinWidth
}
minimumHeight: {
if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView)
return JamiTheme.wizardViewMinHeight
return JamiTheme.mainViewMinHeight
}
visible: mainApplicationLoader.status === Loader.Ready
// To facilitate reparenting of the callview during // To facilitate reparenting of the callview during
// fullscreen mode, we need QQuickItem based object. // fullscreen mode, we need QQuickItem based object.
@ -143,10 +130,47 @@ ApplicationWindow {
} }
} }
// Set `visible = false` when loading a new QML file.
onSourceChanged: windowSettingsLoaded = false
onLoaded: { onLoaded: {
if (UtilsAdapter.getAppValue(Settings.StartMinimized)) { if (UtilsAdapter.getAppValue(Settings.StartMinimized)) {
showMinimized() showMinimized()
} else {
if (checkLoadedSource() === MainApplicationWindow.LoadedSource.WizardView) {
appWindow.width = JamiTheme.wizardViewMinWidth
appWindow.height = JamiTheme.wizardViewMinHeight
appWindow.minimumWidth = JamiTheme.wizardViewMinWidth
appWindow.minimumHeight = JamiTheme.wizardViewMinHeight
} else {
// Main window, load settings if possible.
var geometry = AppSettingsManager.getValue(Settings.WindowGeometry)
// Position.
if (!isNaN(geometry.x) && !isNaN(geometry.y)) {
appWindow.x = geometry.x
appWindow.y = geometry.y
}
// Dimensions.
appWindow.width = geometry.width ?
geometry.width :
JamiTheme.mainViewPreferredWidth
appWindow.height = geometry.height ?
geometry.height :
JamiTheme.mainViewPreferredHeight
appWindow.minimumWidth = JamiTheme.mainViewMinWidth
appWindow.minimumHeight = JamiTheme.mainViewMinHeight
// State.
const visibilityStr = AppSettingsManager.getValue(Settings.WindowState)
appWindow.visibility = parseInt(visibilityStr)
}
} }
// This will trigger `visible = true`.
windowSettingsLoaded = true
// Quiet check for updates on start if set to. // Quiet check for updates on start if set to.
if (UtilsAdapter.getAppValue(Settings.AutoUpdate)) { if (UtilsAdapter.getAppValue(Settings.AutoUpdate)) {
UpdateManager.checkForUpdates(true) UpdateManager.checkForUpdates(true)
@ -170,6 +194,14 @@ ApplicationWindow {
} }
} }
Connections {
target: MainApplication
function onCloseRequested() {
close(true)
}
}
Connections { Connections {
target: { target: {
if (Qt.platform.os !== "windows" && Qt.platform.os !== "macos") if (Qt.platform.os !== "windows" && Qt.platform.os !== "macos")

View file

@ -1,4 +1,4 @@
/*! /*
* Copyright (C) 2021-2022 Savoir-faire Linux Inc. * Copyright (C) 2021-2022 Savoir-faire Linux Inc.
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
* *
@ -20,6 +20,9 @@
#include "appsettingsmanager.h" #include "appsettingsmanager.h"
const QString defaultDownloadPath = QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation);
AppSettingsManager::AppSettingsManager(QObject* parent) AppSettingsManager::AppSettingsManager(QObject* parent)
: QObject(parent) : QObject(parent)
, settings_(new QSettings("jami.net", "Jami", this)) , settings_(new QSettings("jami.net", "Jami", this))

View file

@ -1,4 +1,4 @@
/*! /*
* Copyright (C) 2020-2022 Savoir-faire Linux Inc. * Copyright (C) 2020-2022 Savoir-faire Linux Inc.
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
* *
@ -26,9 +26,9 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStandardPaths> #include <QStandardPaths>
#include <QWindow> // for QWindow::AutomaticVisibility
const QString defaultDownloadPath = QStandardPaths::writableLocation( extern const QString defaultDownloadPath;
QStandardPaths::DownloadLocation);
// clang-format off // clang-format off
#define KEYS \ #define KEYS \
@ -44,11 +44,13 @@ const QString defaultDownloadPath = QStandardPaths::writableLocation(
X(EnableDarkTheme, false) \ X(EnableDarkTheme, false) \
X(AutoUpdate, true) \ X(AutoUpdate, true) \
X(StartMinimized, false) \ X(StartMinimized, false) \
X(NeverShowMeAgain, false) X(NeverShowMeAgain, false) \
X(WindowGeometry, QRectF(qQNaN(), qQNaN(), 0., 0.)) \
X(WindowState, QWindow::AutomaticVisibility)
/* /*
* A class to expose settings keys in both c++ and QML. * A class to expose settings keys in both c++ and QML.
* Note: this using a non-constructable class instead of a * Note: this is using a non-constructable class instead of a
* namespace allows for QML enum auto-completion in QtCreator. * namespace allows for QML enum auto-completion in QtCreator.
* This works well when there is only one enum class. Otherwise, * This works well when there is only one enum class. Otherwise,
* to prevent element name collision when defining multiple enums, * to prevent element name collision when defining multiple enums,

View file

@ -25,7 +25,6 @@
#include <QObject> #include <QObject>
#include <QPixmap> #include <QPixmap>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSettings>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
LRCInstance::LRCInstance(migrateCallback willMigrateCb, LRCInstance::LRCInstance(migrateCallback willMigrateCb,

View file

@ -248,7 +248,8 @@ MainApplication::init()
initQmlLayer(); initQmlLayer();
settingsManager_->setValue(Settings::Key::StartMinimized, results[opts::STARTMINIMIZED].toBool()); settingsManager_->setValue(Settings::Key::StartMinimized,
results[opts::STARTMINIMIZED].toBool());
initSystray(); initSystray();
@ -441,13 +442,14 @@ MainApplication::initSystray()
#endif #endif
QAction* quitAction = new QAction(quitString, this); QAction* quitAction = new QAction(quitString, this);
connect(quitAction, &QAction::triggered, this, &MainApplication::cleanup); connect(quitAction, &QAction::triggered, this, &MainApplication::closeRequested);
QAction* restoreAction = new QAction(tr("&Show Jami"), this); QAction* restoreAction = new QAction(tr("&Show Jami"), this);
connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp); connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp);
connect(systemTray_.get(), connect(systemTray_.get(),
&QSystemTrayIcon::activated, &QSystemTrayIcon::activated,
this,
[this](QSystemTrayIcon::ActivationReason reason) { [this](QSystemTrayIcon::ActivationReason reason) {
if (reason != QSystemTrayIcon::ActivationReason::Context) { if (reason != QSystemTrayIcon::ActivationReason::Context) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS

View file

@ -65,6 +65,9 @@ public:
bool init(); bool init();
void restoreApp(); void restoreApp();
Q_SIGNALS:
void closeRequested();
private: private:
void vsConsoleDebug(); void vsConsoleDebug();
void fileDebug(QFile* debugFile); void fileDebug(QFile* debugFile);

View file

@ -103,7 +103,7 @@ registerTypes(QQmlEngine* engine,
AppSettingsManager* settingsManager, AppSettingsManager* settingsManager,
PreviewEngine* previewEngine, PreviewEngine* previewEngine,
ScreenInfo* screenInfo, ScreenInfo* screenInfo,
QObject* parent) MainApplication* parent)
{ {
// setup the adapters (their lifetimes are that of MainApplication) // setup the adapters (their lifetimes are that of MainApplication)
auto callAdapter = new CallAdapter(systemTray, lrcInstance, parent); auto callAdapter = new CallAdapter(systemTray, lrcInstance, parent);
@ -180,6 +180,7 @@ registerTypes(QQmlEngine* engine,
QML_REGISTERSINGLETONTYPE_URL(NS_CONSTANTS, "qrc:/src/constant/JamiResources.qml", JamiResources); QML_REGISTERSINGLETONTYPE_URL(NS_CONSTANTS, "qrc:/src/constant/JamiResources.qml", JamiResources);
QML_REGISTERSINGLETONTYPE_URL(NS_CONSTANTS, "qrc:/src/constant/MsgSeq.qml", MsgSeq); QML_REGISTERSINGLETONTYPE_URL(NS_CONSTANTS, "qrc:/src/constant/MsgSeq.qml", MsgSeq);
QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, parent, "MainApplication")
QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, screenInfo, "CurrentScreenInfo") QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, screenInfo, "CurrentScreenInfo")
QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, lrcInstance, "LRCInstance") QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, lrcInstance, "LRCInstance")
QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, settingsManager, "AppSettingsManager") QML_REGISTERSINGLETONTYPE_POBJECT(NS_CONSTANTS, settingsManager, "AppSettingsManager")

View file

@ -35,6 +35,7 @@ class LRCInstance;
class AppSettingsManager; class AppSettingsManager;
class PreviewEngine; class PreviewEngine;
class ScreenInfo; class ScreenInfo;
class MainApplication;
// Hack for QtCreator autocomplete (part 1) // Hack for QtCreator autocomplete (part 1)
// https://bugreports.qt.io/browse/QTCREATORBUG-20569 // https://bugreports.qt.io/browse/QTCREATORBUG-20569
@ -66,5 +67,5 @@ void registerTypes(QQmlEngine* engine,
AppSettingsManager* appSettingsManager, AppSettingsManager* appSettingsManager,
PreviewEngine* previewEngine, PreviewEngine* previewEngine,
ScreenInfo* screenInfo, ScreenInfo* screenInfo,
QObject* parent); MainApplication* parent);
} }