瀏覽代碼

some cleanups

Malte Veerman 9 年之前
父節點
當前提交
4290e800b4
共有 5 個文件被更改,包括 44 次插入50 次删除
  1. 13 13
      kcm/src/fancontrolkcm.cpp
  2. 10 10
      lib/src/guibase.cpp
  3. 16 16
      lib/src/guibase.h
  4. 4 8
      package/contents/ui/Application.qml
  5. 1 3
      package/contents/ui/KCM.qml

+ 13 - 13
kcm/src/fancontrolkcm.cpp

@@ -1,7 +1,7 @@
 /*
  * <one line to give the library's name and an idea of what it does.>
  * Copyright 2015  Malte Veerman maldela@halloarsch.de
- * 
+ *
  * 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
@@ -9,15 +9,15 @@
  * 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 "fancontrolkcm.h"
@@ -39,7 +39,7 @@ FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
 {
     if (!m_base->hasSystemdCommunicator())
         qFatal("Fancontrol-gui-lib was compiled without systemd support!");
-             
+
     KAboutData *about = new KAboutData("kcm_fancontrol",
                                        i18n("Fancontrol-KCM"),
                                        "0.1",
@@ -49,27 +49,27 @@ FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
                                        QString(),
                                        "http://github.com/maldela/fancontrol-gui",
                                        "http://github.com/maldela/fancontrol-gui/issues");
-    about->addAuthor(i18n("Malte Veerman"), i18n("Main Developer"), "maldela@halloarsch.de"); 
+    about->addAuthor(i18n("Malte Veerman"), i18n("Main Developer"), "maldela@halloarsch.de");
     setAboutData(about);
-    
+
     setButtons(Apply | Default);
     setAuthActionName("fancontrol.gui.helper.action");
-      
+
     connect(m_base->loader(), &Loader::configFileChanged, [this] () { setNeedsSave(true); });
     connect(m_base, &GUIBase::minTempChanged, [this] () { setNeedsSave(true); });
     connect(m_base, &GUIBase::maxTempChanged, [this] () { setNeedsSave(true); });
     connect(m_base, &GUIBase::serviceNameChanged, [this] () { setNeedsSave(true); });
-    
+
     qmlRegisterType<GUIBase>();
 }
 
 void FancontrolKCM::save()
 {
     m_base->save(true);
-    
+
     if (m_base->systemdCommunicator()->serviceActive() && m_manualControl)
         m_base->systemdCommunicator()->restartService();
-    else 
+    else
         m_base->systemdCommunicator()->setServiceActive(m_manualControl);
 
     m_base->systemdCommunicator()->setServiceEnabled(m_manualControl);
@@ -83,7 +83,7 @@ void FancontrolKCM::load()
     setNeedsSave(false);
 }
 
-void FancontrolKCM::defaults() 
+void FancontrolKCM::defaults()
 {
     setManualControl(false);
     setNeedsSave(true);
@@ -100,4 +100,4 @@ void FancontrolKCM::setManualControl(bool manualControl)
 }
 
 
-#include "fancontrolkcm.moc"
+#include "fancontrolkcm.moc"

+ 10 - 10
lib/src/guibase.cpp

@@ -33,7 +33,7 @@
 namespace Fancontrol
 {
 
-GUIBase::GUIBase(QObject *parent) : QObject(parent),    
+GUIBase::GUIBase(QObject *parent) : QObject(parent),
     m_config(Config::instance()),
 
 #ifndef NO_SYSTEMD
@@ -44,7 +44,7 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     m_configValid(false)
 {
     connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
-        
+
     QLocale locale = QLocale::system();
     QLocale::MeasurementSystem system = locale.measurementSystem();
     m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
@@ -54,18 +54,18 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     qmlRegisterType<Fan>();
     qmlRegisterType<PwmFan>();
     qmlRegisterType<Temp>();
-    
+
 #ifndef NO_SYSTEMD
     qmlRegisterType<SystemdCommunicator>();
 #endif
-    
+
 }
 
 void GUIBase::load()
 {
     m_config->load();
     m_configValid = m_loader->load(configUrl());
-    
+
 #ifndef NO_SYSTEMD
     m_com->setServiceName(serviceName());
 #endif
@@ -73,12 +73,12 @@ void GUIBase::load()
     emitConfigChanged();
 }
 
-void GUIBase::save(bool saveLoader)
+void GUIBase::save(bool saveLoader, const QUrl &url)
 {
     m_config->save();
-    
+
     if (saveLoader)
-        m_loader->save();
+        m_loader->save(url);
 }
 
 qreal GUIBase::maxTemp() const
@@ -128,7 +128,7 @@ void GUIBase::setServiceName(const QString& name)
 #ifndef NO_SYSTEMD
         m_com->setServiceName(name);
 #endif
-        
+
         emit serviceNameChanged();
     }
 }
@@ -151,4 +151,4 @@ void GUIBase::emitConfigChanged()
     emit configUrlChanged();
 }
 
-}
+}

+ 16 - 16
lib/src/guibase.h

@@ -47,13 +47,13 @@ class Config;
 class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
 {
     Q_OBJECT
-    
+
     Q_PROPERTY(Loader* loader READ loader CONSTANT)
-    
+
 #ifndef NO_SYSTEMD
     Q_PROPERTY(SystemdCommunicator* systemdCom READ systemdCommunicator CONSTANT)
 #endif
-    
+
     Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
     Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
     Q_PROPERTY(int unit READ unit WRITE setUnit NOTIFY unitChanged)
@@ -62,11 +62,11 @@ class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
     Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
 
 public:
-    
+
     explicit GUIBase(QObject *parent = Q_NULLPTR);
 
     Loader *loader() const { return m_loader; }
-    
+
 #ifndef NO_SYSTEMD
     SystemdCommunicator *systemdCommunicator() const { return m_com; }
 #endif
@@ -83,11 +83,11 @@ public:
     void setConfigUrl(const QUrl &url);
     void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); } }
     void load();
-    
-    Q_INVOKABLE void save(bool saveLoader = false);
+
+    Q_INVOKABLE void save(bool saveLoader = false, const QUrl &url = QUrl());
     Q_INVOKABLE bool hasSystemdCommunicator() const { return SYSTEMD_BOOL; }
-    
-    
+
+
 signals:
 
     void minTempChanged();
@@ -95,13 +95,13 @@ signals:
     void serviceNameChanged();
     void configUrlChanged();
     void unitChanged();
-    
-    
+
+
 protected:
-    
+
     void emitConfigChanged();
-    
-    
+
+
 private:
 
     Config *m_config;
@@ -109,8 +109,8 @@ private:
 #ifndef NO_SYSTEMD
     SystemdCommunicator *const m_com;
 #endif
-    
-    Loader *const m_loader; 
+
+    Loader *const m_loader;
     int m_unit;
     bool m_configValid;
 };

+ 4 - 8
package/contents/ui/Application.qml

@@ -30,7 +30,7 @@ ApplicationWindow {
     width: 1024
     height: 768
     visible: true
-    
+
     onClosing: base.save()
 
     menuBar: MenuBar {
@@ -135,7 +135,7 @@ ApplicationWindow {
     Action {
         id: saveAction
         text: i18n("Save configuration file")
-        onTriggered: base.loader.save()
+        onTriggered: base.save(true)
         iconName: "document-save"
         tooltip: i18n("Save configuration file") + " (" + base.loader.configUrl.toString() + ")"
         shortcut: StandardKey.Save
@@ -149,9 +149,7 @@ ApplicationWindow {
         selectMultiple: false
         modality: Qt.NonModal
 
-        onAccepted: {
-            base.configUrl = fileUrl;
-        }
+        onAccepted: base.configUrl = fileUrl;
     }
     FileDialog {
         id: saveFileDialog
@@ -161,8 +159,6 @@ ApplicationWindow {
         selectMultiple: false
         modality: Qt.NonModal
 
-        onAccepted: {
-            base.loader.save(fileUrl);
-        }
+        onAccepted: base.save(true, fileUrl);
     }
 }

+ 1 - 3
package/contents/ui/KCM.qml

@@ -268,9 +268,7 @@ Item {
         selectExisting: true
         selectMultiple: false
 
-        onAccepted: {
-            base.configUrl = fileUrl;
-        }
+        onAccepted: base.configUrl = fileUrl;
     }
 
     ErrorDialog {