Save and restore window size
This commit is contained in:
18
qml/main.qml
18
qml/main.qml
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
import QtQuick 2.14
|
import QtQuick 2.14
|
||||||
import QtQuick.Controls 2.14 as QQC2
|
import QtQuick.Controls 2.14 as QQC2
|
||||||
|
import QtQuick.Window 2.2
|
||||||
import QtQuick.Layouts 1.14
|
import QtQuick.Layouts 1.14
|
||||||
|
|
||||||
import org.kde.kirigami 2.12 as Kirigami
|
import org.kde.kirigami 2.12 as Kirigami
|
||||||
@@ -34,6 +35,23 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClosing: Controller.saveWindowGeometry(root)
|
||||||
|
|
||||||
|
// This timer allows to batch update the window size change to reduce
|
||||||
|
// the io load and also work around the fact that x/y/width/height are
|
||||||
|
// changed when loading the page and overwrite the saved geometry from
|
||||||
|
// the previous session.
|
||||||
|
Timer {
|
||||||
|
id: saveWindowGeometryTimer
|
||||||
|
interval: 1000
|
||||||
|
onTriggered: Controller.saveWindowGeometry(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
onWidthChanged: saveWindowGeometryTimer.restart()
|
||||||
|
onHeightChanged: saveWindowGeometryTimer.restart()
|
||||||
|
onXChanged: saveWindowGeometryTimer.restart()
|
||||||
|
onYChanged: saveWindowGeometryTimer.restart()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage opening and close rooms
|
* Manage opening and close rooms
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,15 +8,16 @@
|
|||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
#include <qt5keychain/keychain.h>
|
#include <qt5keychain/keychain.h>
|
||||||
#else
|
#endif
|
||||||
#include <KConfig>
|
#include <KConfig>
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#endif
|
#include <KWindowConfig>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QQuickWindow>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -565,6 +566,15 @@ void Controller::setActiveConnection(Connection *connection)
|
|||||||
Q_EMIT activeConnectionChanged();
|
Q_EMIT activeConnectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::saveWindowGeometry(QQuickWindow *window)
|
||||||
|
{
|
||||||
|
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
||||||
|
KConfigGroup windowGroup(&dataResource, "Window");
|
||||||
|
KWindowConfig::saveWindowPosition(window, windowGroup);
|
||||||
|
KWindowConfig::saveWindowSize(window, windowGroup);
|
||||||
|
dataResource.sync();
|
||||||
|
}
|
||||||
|
|
||||||
NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth)
|
NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth)
|
||||||
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
|
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class QKeySequences;
|
|||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
|
class QQuickWindow;
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
@@ -118,6 +119,7 @@ public Q_SLOTS:
|
|||||||
static void playAudio(const QUrl &localFile);
|
static void playAudio(const QUrl &localFile);
|
||||||
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
|
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
|
||||||
static void markAllMessagesAsRead(Quotient::Connection *conn);
|
static void markAllMessagesAsRead(Quotient::Connection *conn);
|
||||||
|
void saveWindowGeometry(QQuickWindow *);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO libQuotient 0.7: Drop
|
// TODO libQuotient 0.7: Drop
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@@ -19,6 +19,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <KLocalizedContext>
|
#include <KLocalizedContext>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
#include <KWindowConfig>
|
||||||
|
|
||||||
#include "neochat-version.h"
|
#include "neochat-version.h"
|
||||||
|
|
||||||
@@ -152,6 +153,17 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const auto rootObjects = engine.rootObjects();
|
||||||
|
for (auto obj : rootObjects) {
|
||||||
|
auto view = qobject_cast<QQuickWindow*>(obj);
|
||||||
|
if (view) {
|
||||||
|
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
||||||
|
KConfigGroup windowGroup(&dataResource, "Window");
|
||||||
|
KWindowConfig::restoreWindowSize(view, windowGroup);
|
||||||
|
KWindowConfig::restoreWindowPosition(view, windowGroup);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return QApplication::exec();
|
return QApplication::exec();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user