浏览代码

Fixed window size restoration

Malte Veerman 6 年之前
父节点
当前提交
8cdd09b10e

+ 0 - 1
fancontrol-gui/CMakeLists.txt

@@ -1,5 +1,4 @@
 set(Fancontrol_GUI_SRCS src/main.cpp
-                        src/windowconfig.cpp
                         src/systemtrayicon.cpp)
 
 set(LIBRARIES Qt5::Gui

+ 0 - 2
fancontrol-gui/package/contents/ui/Application.qml

@@ -52,7 +52,6 @@ Kirigami.ApplicationWindow {
     onWideScreenChanged: drawer.drawerOpen = wideScreen
 
     onClosing: {
-        windowConfig.save(window);
         if (Fancontrol.Base.needsApply && !saveOnCloseDialog.answered) {
             close.accepted = false;
             saveOnCloseDialog.open();
@@ -62,7 +61,6 @@ Kirigami.ApplicationWindow {
 
     Component.onCompleted: {
         Fancontrol.Base.load();
-        windowConfig.restore(window);
         window.visible = !Fancontrol.Base.startMinimized;
         leftPage = "SensorsTab.qml";
     }

+ 18 - 2
fancontrol-gui/src/main.cpp

@@ -27,14 +27,21 @@
 #include <KI18n/KLocalizedString>
 #include <KCoreAddons/KAboutData>
 #include <KDBusAddons/KDBusService>
+#include <KConfigCore/KSharedConfig>
+#include <KConfigGui/KWindowConfig>
 
 #include "systemtrayicon.h"
-#include "windowconfig.h"
+
+
+#ifndef CONFIG_NAME
+#define CONFIG_NAME "fancontrol-gui"
+#endif
 
 
 Q_DECLARE_LOGGING_CATEGORY(FANCONTROL)
 Q_LOGGING_CATEGORY(FANCONTROL, "fancontrol-gui")
 
+
 void handleArguments(QStringList args)
 {
     if (args.isEmpty())
@@ -89,8 +96,17 @@ int main(int argc, char *argv[])
     qmlRegisterType<SystemTrayIcon>("Fancontrol.Gui", 1, 0, "SystemTrayIcon");
 
     KDeclarative::QmlObject qmlObject;
-    qmlObject.rootContext()->setContextProperty(QStringLiteral("windowConfig"), WindowConfig::instance());
     qmlObject.loadPackage(QStringLiteral("org.kde.fancontrol.gui"));
+    if (auto window = qobject_cast<QWindow*>(qmlObject.rootObject()))
+    {
+        KConfigGroup configGroup(KSharedConfig::openConfig(QStringLiteral(CONFIG_NAME)), "window");
+        KWindowConfig::restoreWindowSize(window, configGroup);
+        QObject::connect(&app, &QApplication::aboutToQuit, window, [window] () {
+            KConfigGroup configGroup(KSharedConfig::openConfig(QStringLiteral(CONFIG_NAME)), "window");
+            KWindowConfig::saveWindowSize(window, configGroup);
+            configGroup.sync();
+        });
+    }
 
     return app.exec();
 }

+ 0 - 68
fancontrol-gui/src/windowconfig.cpp

@@ -1,68 +0,0 @@
-/*
- * Copyright 2015  Malte Veerman <malte.veerman@gmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License or (at your option) version 3 or any later version
- * accepted by the membership of KDE e.V. (or its successor approved
- * by the membership of KDE e.V.), which shall act as a proxy
- * defined in Section 14 of version 3 of the license.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "windowconfig.h"
-
-#include <QtGui/QWindow>
-#include <QtGui/QScreen>
-
-#include <KConfigCore/KSharedConfig>
-#include <KConfigGui/KWindowConfig>
-
-
-#ifndef CONFIG_NAME
-#define CONFIG_NAME "fancontrol-gui"
-#endif
-
-
-WindowConfig *WindowConfig::s_instance = Q_NULLPTR;
-
-WindowConfig::WindowConfig(QObject *parent) : QObject(parent)
-{
-}
-
-WindowConfig* WindowConfig::instance()
-{
-    if (!s_instance)
-        s_instance = new WindowConfig;
-
-    return s_instance;
-}
-
-void WindowConfig::save(QWindow *window)
-{
-    if (!window)
-        return;
-
-    KConfigGroup configGroup(KSharedConfig::openConfig(QStringLiteral(CONFIG_NAME)), "window");
-    KWindowConfig::saveWindowSize(window, configGroup);
-    configGroup.sync();
-}
-
-void WindowConfig::restore(QWindow *window)
-{
-    if (!window)
-        return;
-
-    KConfigGroup configGroup(KSharedConfig::openConfig(QStringLiteral(CONFIG_NAME)), "window");
-    KWindowConfig::restoreWindowSize(window, configGroup);
-}

+ 0 - 51
fancontrol-gui/src/windowconfig.h

@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2015  Malte Veerman <malte.veerman@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-
-#ifndef WINDOWCONFIG_H
-#define WINDOWCONFIG_H
-
-
-#include <QtCore/QObject>
-
-
-class QWindow;
-
-class WindowConfig : public QObject
-{
-    Q_OBJECT
-
-public:
-
-    static WindowConfig *instance();
-
-    Q_INVOKABLE void save(QWindow *window);
-    Q_INVOKABLE void restore(QWindow *window);
-
-
-private:
-
-    WindowConfig(QObject *parent = Q_NULLPTR);
-    ~WindowConfig() {}
-    Q_DISABLE_COPY(WindowConfig)
-
-    static WindowConfig *s_instance;
-};
-
-#endif //WINDOWCONFIG_H