浏览代码

preferences are now saved and shared between standalone and kcm

Malte Veerman 10 年之前
父节点
当前提交
f047938b4c

+ 3 - 1
kcm/src/fancontrolkcm.cpp

@@ -1,6 +1,6 @@
 /*
  * <one line to give the library's name and an idea of what it does.>
- * Copyright 2015  <copyright holder> <email>
+ * 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
@@ -54,6 +54,8 @@ FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
     setAuthActionName("fancontrol.gui.helper.action");
     
     connect(m_base->loader(), &Loader::configFileChanged, [this] () { setNeedsSave(true); });
+    connect(m_base, &GUIBase::configChanged, this, &FancontrolKCM::emitConfigChanged);
+    connect(m_base, &GUIBase::unitChanged, this, &FancontrolKCM::emitUnitChanged);
     
     qmlRegisterType<GUIBase>();
 }

+ 27 - 1
kcm/src/fancontrolkcm.h

@@ -1,6 +1,6 @@
 /*
  * <one line to give the library's name and an idea of what it does.>
- * Copyright 2015  <copyright holder> <email>
+ * 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
@@ -35,6 +35,13 @@ class FancontrolKCM : public ConfigModule
     Q_OBJECT
     Q_PROPERTY(GUIBase *base READ base CONSTANT)
     Q_PROPERTY(bool manualControl READ manualControl WRITE setManualControl NOTIFY manualControlChanged)
+    Q_PROPERTY(Loader* loader READ loader CONSTANT)
+    Q_PROPERTY(SystemdCommunicator* systemdCom READ systemdCommunicator CONSTANT)
+    Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY configChanged)
+    Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY configChanged)
+    Q_PROPERTY(int unit READ unit WRITE setUnit NOTIFY unitChanged)
+    Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY configChanged)
+    Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY configChanged)
     
 public:
     
@@ -44,6 +51,20 @@ public:
     bool manualControl() const { return m_manualControl; }
     void setManualControl(bool manualControl);
     
+    //wrap base
+    Loader *loader() const { return m_base->loader(); }
+    SystemdCommunicator *systemdCommunicator() const { return m_base->systemdCommunicator(); }
+    qreal minTemp() const { return m_base->minTemp(); }
+    qreal maxTemp() const { return m_base->maxTemp(); }
+    int unit() const { return m_base->unit(); }
+    QString serviceName() const { return m_base->serviceName(); }
+    int interval() const { return m_base->interval(); }
+    void setMinTemp(int temp) { m_base->setMinTemp(temp); }
+    void setMaxTemp(int temp) { m_base->setMaxTemp(temp); }
+    void setUnit(int unit) { m_base->setUnit(unit); }
+    void setServiceName(const QString &name) { m_base->setServiceName(name); }
+    void setInterval(int interval) { m_base->setInterval(interval); }
+    
     
 public slots:
     
@@ -55,10 +76,15 @@ public slots:
 signals:
     
     void manualControlChanged();
+    void configChanged();
+    void unitChanged();
     
 
 protected:
     
+    void emitConfigChanged() { emit configChanged(); }
+    void emitUnitChanged() { emit unitChanged(); }
+    
     GUIBase *const m_base;
     bool m_manualControl;
 };

+ 4 - 3
lib/CMakeLists.txt

@@ -1,7 +1,8 @@
 set(LIB_SRCS src/hwmon.cpp
              src/loader.cpp
              src/sensors.cpp
-             src/guibase.cpp)
+             src/guibase.cpp
+             src/config.cpp)
                         
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
                           KF5::Auth
@@ -14,8 +15,8 @@ if(NOT NO_SYSTEMD)
     set(LIB_SRCS ${LIB_SRCS}
                  src/systemdcommunicator.cpp)
 
-    set(LIB_PUBLIC_LIBRARIES ${LIB_PUBLIC_LIBRARIES}
-                             Qt5::DBus)
+    set(LIB_PRIVATE_LIBRARIES ${LIB_PRIVATE_LIBRARIES}
+                              Qt5::DBus)
 
 endif(NOT NO_SYSTEMD)
 

+ 48 - 0
lib/src/config.cpp

@@ -0,0 +1,48 @@
+/*
+ * <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
+ * 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 "config.h"
+
+#define CONFIG_NAME "fancontrol-gui"
+
+Config *Config::m_instance = Q_NULLPTR;
+
+Config::Config(QObject *parent) : KCoreConfigSkeleton(KSharedConfig::openConfig(CONFIG_NAME), parent)
+{
+    setCurrentGroup("preferences");
+    addItemDouble("MinTemp", m_minTemp, 30.0);
+    addItemDouble("MaxTemp", m_maxTemp, 90.0);
+    addItemString("ServiceName", m_serviceName, "fancontrol");
+    
+    load();
+}
+
+Config* Config::instance()
+{
+    if (!m_instance)
+        m_instance = new Config;
+    
+    return m_instance;
+}
+
+
+// #include "config.moc"

+ 52 - 0
lib/src/config.h

@@ -0,0 +1,52 @@
+/*
+ * <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
+ * 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/>.
+ *
+ */
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <KF5/KConfigCore/KCoreConfigSkeleton>
+
+
+class Config : public KCoreConfigSkeleton
+{
+    
+Q_OBJECT
+
+public:
+    
+    static Config *instance();
+    
+    
+private:
+    
+    Config(QObject *parent = Q_NULLPTR);
+    ~Config() {}
+    Q_DISABLE_COPY(Config)
+    
+    static Config *m_instance;
+    
+    double m_minTemp;
+    double m_maxTemp;
+    QString m_serviceName;
+};
+
+#endif // CONFIG_H

+ 63 - 6
lib/src/guibase.cpp

@@ -1,6 +1,6 @@
 /*
  * <one line to give the library's name and an idea of what it does.>
- * Copyright 2015  <copyright holder> <email>
+ * 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
@@ -20,6 +20,7 @@
  *
  */
 
+#include "config.h"
 #include "guibase.h"
 #include "sensors.h"
 #include "hwmon.h"
@@ -28,15 +29,16 @@
 #include <QLocale>
 
 GUIBase::GUIBase(QObject *parent) : QObject(parent),    
-    
+    m_config(Config::instance()),
+
 #ifndef NO_SYSTEMD
-    m_com(new SystemdCommunicator(this)),
+    m_com(new SystemdCommunicator(m_config->findItem("ServiceName")->property().toString(), this)),
 #endif
 
-    m_loader(new Loader(this)),
-    m_minTemp(30),
-    m_maxTemp(90)
+    m_loader(new Loader(this))
 {
+    connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
+        
     QLocale locale = QLocale::system();
     QLocale::MeasurementSystem system = locale.measurementSystem();
     m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
@@ -51,4 +53,59 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     qmlRegisterType<SystemdCommunicator>();
 #endif
     
+}
+
+qreal GUIBase::maxTemp() const
+{
+    return m_config->findItem("MaxTemp")->property().toReal();
+}
+
+qreal GUIBase::minTemp() const
+{
+    return m_config->findItem("MinTemp")->property().toReal();
+}
+
+QString GUIBase::serviceName() const
+{
+    return m_config->findItem("ServiceName")->property().toString();
+}
+
+int GUIBase::interval() const
+{
+    return m_loader->interval();
+}
+
+void GUIBase::setMaxTemp(qreal temp)
+{
+    if (temp != maxTemp())
+        m_config->findItem("MaxTemp")->setProperty(temp);
+}
+
+void GUIBase::setMinTemp(qreal temp)
+{
+    if (temp != minTemp())
+        m_config->findItem("MinTemp")->setProperty(temp);
+}
+
+void GUIBase::setServiceName(const QString& name)
+{
+    if(name != serviceName())
+    {
+        m_config->findItem("ServiceName")->setProperty(name);
+
+#ifndef NO_SYSTEMD
+        m_com->setServiceName(name);
+#endif
+            
+    }
+}
+
+void GUIBase::setInterval(int i)
+{
+    m_loader->setInterval(i);
+}
+
+void GUIBase::saveConfig()
+{
+    m_config->save();
 }

+ 23 - 11
lib/src/guibase.h

@@ -1,6 +1,6 @@
 /*
  * <one line to give the library's name and an idea of what it does.>
- * Copyright 2015  <copyright holder> <email>
+ * 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
@@ -38,6 +38,8 @@
 #include "fancontrol_gui_lib_export.h"
 
 
+class Config;
+
 class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
 {
     Q_OBJECT
@@ -48,13 +50,16 @@ class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
     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(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY configChanged)
+    Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY configChanged)
     Q_PROPERTY(int unit READ unit WRITE setUnit NOTIFY unitChanged)
+    Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY configChanged)
+    Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY configChanged)
 
 public:
     
     explicit GUIBase(QObject *parent = Q_NULLPTR);
+    ~GUIBase() { saveConfig(); }
 
     Loader *loader() const { return m_loader; }
     
@@ -62,31 +67,38 @@ public:
     SystemdCommunicator *systemdCommunicator() const { return m_com; }
 #endif
 
-    qreal minTemp() const { return m_minTemp; }
-    qreal maxTemp() const { return m_maxTemp; }
+    qreal minTemp() const;
+    qreal maxTemp() const;
+    QString serviceName() const;
+    int interval() const;
     int unit() const { return m_unit; }
-    void setMinTemp(qreal minTemp) { if (minTemp != m_minTemp) { m_minTemp = minTemp; emit minTempChanged(); } }
-    void setMaxTemp(qreal maxTemp) { if (maxTemp != m_maxTemp) { m_maxTemp = maxTemp; emit maxTempChanged(); } }
-    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); } }    
+    void setMinTemp(qreal minTemp);
+    void setMaxTemp(qreal maxTemp);
+    void setServiceName(const QString &name);
+    void setInterval(int i);
+    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); } }
+    void saveConfig();
 
     Q_INVOKABLE bool hasSystemdCommunicator() const { return SYSTEMD_BOOL; }
     
     
 signals:
 
-    void minTempChanged();
-    void maxTempChanged();
+    void configChanged();
     void unitChanged();
     
     
 protected:
     
+    void emitConfigChanged() { emit configChanged(); }
+
+    Config *m_config;
+
 #ifndef NO_SYSTEMD
     SystemdCommunicator *const m_com;
 #endif
     
     Loader *const m_loader; 
-    qreal m_minTemp, m_maxTemp;
     int m_unit;
 };
 

+ 3 - 0
lib/src/hwmon.cpp

@@ -18,6 +18,9 @@
  */
 
 #include "hwmon.h"
+#include "sensors.h"
+#include "loader.h"
+
 #include <QDir>
 #include <QTextStream>
 #include <QtQml>

+ 1 - 5
lib/src/hwmon.h

@@ -22,16 +22,12 @@
 
 #include <QObject>
 
-#include "sensors.h"
-#include "loader.h"
-#include "fancontrol_gui_lib_export.h"
-
 class Fan;
 class PwmFan;
 class Temp;
 class Loader;
 
-class FANCONTROL_GUI_LIB_EXPORT Hwmon : public QObject
+class Hwmon : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QString name READ name CONSTANT)

+ 8 - 4
lib/src/loader.cpp

@@ -18,10 +18,13 @@
  */
 
 #include "loader.h"
+#include "hwmon.h"
+#include "sensors.h"
 
 #include <QFile>
 #include <QDir>
 #include <QTextStream>
+#include <QTimer>
 #include <QDebug>
 
 #include <KF5/KAuth/kauthexecutejob.h>
@@ -31,14 +34,15 @@
 Loader::Loader(QObject *parent) : QObject(parent),
     m_interval(10),
     m_configUrl(QUrl::fromLocalFile("/etc/fancontrol")),
-    m_error("Success")
+    m_error("Success"),
+    m_timer(new QTimer(this))
 {
     parseHwmons();
     
-    m_timer.setSingleShot(false);
-    m_timer.start(1);
+    m_timer->setSingleShot(false);
+    m_timer->start(1);
     
-    connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSensors()));
+    connect(m_timer, SIGNAL(timeout()), this, SLOT(updateSensors()));
 }
 
 void Loader::parseHwmons()

+ 4 - 4
lib/src/loader.h

@@ -22,12 +22,13 @@
 
 #include <QObject>
 #include <QUrl>
-#include <QTimer>
+#include <QList>
+#include <QString>
 
-#include "hwmon.h"
 #include "fancontrol_gui_lib_export.h"
 
 class Hwmon;
+class QTimer;
 
 class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
 {
@@ -56,7 +57,6 @@ public:
     QList<QObject *> allTemps() const;
     int interval() const { return m_interval; }
     void setInterval(int interval, bool writeNewConfig = true);
-    Hwmon * hwmon(int i) { return m_hwmons.value(i, Q_NULLPTR); }
     QString error() const { return m_error; }
     
     static int getHwmonNumber(const QString &str); 
@@ -85,7 +85,7 @@ protected:
     QUrl m_configUrl;
     QString m_configFile;
     QString m_error;
-    QTimer m_timer;
+    QTimer *m_timer;
 
 
 signals:

+ 3 - 4
lib/src/sensors.h

@@ -25,7 +25,6 @@
 #include <QTimer>
 
 #include "hwmon.h"
-#include "fancontrol_gui_lib_export.h"
 
 class Hwmon;
 
@@ -66,7 +65,7 @@ protected:
 };
 
 
-class FANCONTROL_GUI_LIB_EXPORT Temp : public Sensor
+class Temp : public Sensor
 {
     Q_OBJECT
     Q_PROPERTY(QString label READ label NOTIFY labelChanged)
@@ -101,7 +100,7 @@ protected:
 };
 
 
-class FANCONTROL_GUI_LIB_EXPORT Fan : public Sensor
+class Fan : public Sensor
 {
     Q_OBJECT
     Q_PROPERTY(int rpm READ rpm NOTIFY rpmChanged)
@@ -135,7 +134,7 @@ protected:
 };
 
 
-class FANCONTROL_GUI_LIB_EXPORT PwmFan : public Fan
+class PwmFan : public Fan
 {
     Q_OBJECT
     Q_PROPERTY(int pwm READ pwm WRITE setPwm NOTIFY pwmChanged)

+ 54 - 25
lib/src/systemdcommunicator.cpp

@@ -20,38 +20,64 @@
 #include "systemdcommunicator.h"
 
 #include <KF5/KAuth/kauthexecutejob.h>
+#include <QDebug>
+#include <QVariant>
+#include <QtDBus/QDBusArgument>
+#include <QtDBus/QDBusInterface>
+
 
 using namespace KAuth;
 
-#include <QDebug>
-#include <QVariant>
 
+typedef struct
+{
+    QString path;
+    QString state;
+} SystemdUnitFile;
+Q_DECLARE_METATYPE(SystemdUnitFile)
+
+typedef QList<SystemdUnitFile> SystemdUnitFileList;
+Q_DECLARE_METATYPE(SystemdUnitFileList)
 
-SystemdCommunicator::SystemdCommunicator(QObject *parent) : QObject(parent)
+QDBusArgument &operator <<(QDBusArgument &argument, const SystemdUnitFile &unitFile);
+const QDBusArgument &operator >>(const QDBusArgument &argument, SystemdUnitFile &unitFile);
+
+
+SystemdCommunicator::SystemdCommunicator(const QString &serviceName, QObject *parent) : QObject(parent),
+    m_error("Success"),
+    m_managerInterface(new QDBusInterface("org.freedesktop.systemd1",
+                                          "/org/freedesktop/systemd1",
+                                          "org.freedesktop.systemd1.Manager",
+                                          QDBusConnection::systemBus(),
+                                          this)),
+    m_serviceInterface(Q_NULLPTR)
 {
-    setServiceName("fancontrol");
-    m_error = "Success";
+    if (serviceName.isEmpty())
+        setServiceName("fancontrol");
+    else 
+        setServiceName(serviceName);
 }
 
 void SystemdCommunicator::setServiceName(const QString &name)
 {
     if (name != m_serviceName)
     {
+        if (m_serviceInterface)
+        {
+            QDBusConnection::systemBus().disconnect("org.freedesktop.systemd1",
+                                                    m_serviceObjectPath,
+                                                    "org.freedesktop.DBus.Properties",
+                                                    "PropertiesChanged",
+                                                    this,
+                                                    SLOT(updateServiceProperties(QString, QVariantMap, QStringList)));
+            m_serviceInterface->deleteLater();
+            m_serviceInterface = Q_NULLPTR;
+        }
+        
         m_serviceName = name;
 
         if (serviceExists())
         {
-            if (m_serviceInterface)
-            {
-                QDBusConnection::systemBus().disconnect("org.freedesktop.systemd1",
-                                                        m_serviceObjectPath,
-                                                        "org.freedesktop.DBus.Properties",
-                                                        "PropertiesChanged",
-                                                        this,
-                                                        SLOT(updateServiceProperties(QString, QVariantMap, QStringList)));
-                m_serviceInterface->deleteLater();
-            }
-            
             QVariantList arguments;
             arguments << QVariant(m_serviceName + ".service");
             QDBusMessage dbusreply = m_managerInterface->callWithArgumentList(QDBus::AutoDetect, "LoadUnit", arguments);
@@ -78,17 +104,20 @@ void SystemdCommunicator::setServiceName(const QString &name)
                                                      SLOT(updateServiceProperties(QString, QVariantMap, QStringList)));
             }
         }
+    
+        emit serviceNameChanged();
+        emit serviceEnabledChanged();
+        emit serviceActiveChanged();
     }
-
-    emit serviceNameChanged();
-    emit serviceEnabledChanged();
-    emit serviceActiveChanged();
 }
 
 bool SystemdCommunicator::serviceExists()
 {
-    if (m_serviceInterface && m_serviceInterface->isValid())
-        return true;
+    if (m_serviceInterface)
+    {
+        if (m_serviceInterface->isValid())
+            return true;
+    }
     
     QDBusMessage dbusreply;
 
@@ -121,7 +150,7 @@ bool SystemdCommunicator::serviceExists()
 
 bool SystemdCommunicator::serviceActive()
 {
-    if (serviceExists())
+    if (serviceExists() && m_serviceInterface)
     {
         if (m_serviceInterface->property("ActiveState").toString() == "active")
             return true;
@@ -131,7 +160,7 @@ bool SystemdCommunicator::serviceActive()
 
 bool SystemdCommunicator::serviceEnabled()
 {
-    if (serviceExists())
+    if (serviceExists() && m_serviceInterface)
     {
         if (m_serviceInterface->property("UnitFileState").toString() == "enabled")
             return true;
@@ -191,7 +220,7 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
 {
     QDBusMessage dbusreply;
 
-    if (m_managerInterface && m_managerInterface->isValid())
+    if (m_managerInterface->isValid())
     {
         if (arguments.isEmpty())
             dbusreply = m_managerInterface->call(QDBus::AutoDetect, method);

+ 7 - 24
lib/src/systemdcommunicator.h

@@ -21,15 +21,15 @@
 #define SYSTEMDCOMMUNICATOR_H
 
 #include <QObject>
-#include <QtDBus/QDBusArgument>
-#include <QtDBus/QDBusInterface>
 
 #include "fancontrol_gui_lib_export.h"
 
+
+class QDBusInterface;
+
 class FANCONTROL_GUI_LIB_EXPORT SystemdCommunicator : public QObject
 {
     Q_OBJECT
-    Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
     Q_PROPERTY(QString error READ error NOTIFY errorChanged)
     Q_PROPERTY(bool serviceExists READ serviceExists NOTIFY serviceNameChanged)
     Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
@@ -37,7 +37,7 @@ class FANCONTROL_GUI_LIB_EXPORT SystemdCommunicator : public QObject
 
 public:
 
-    explicit SystemdCommunicator(QObject *parent = Q_NULLPTR);
+    explicit SystemdCommunicator(const QString &serviceName = QString(), QObject *parent = Q_NULLPTR);
 
     QString serviceName() const { return m_serviceName; }
     void setServiceName(const QString &name);
@@ -47,7 +47,6 @@ public:
     bool setServiceEnabled(bool enabled);
     bool setServiceActive(bool active);
     QString error() const { return m_error; }
-    Q_INVOKABLE bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
     Q_INVOKABLE bool restartService();
 
 
@@ -66,31 +65,15 @@ protected slots:
     
 protected:
     
+    bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
     void setError(const QString &error) { if (error != m_error) { m_error = error; emit errorChanged(); } }
     void success() { setError("Success"); }
 
     QString m_serviceName;
     QString m_serviceObjectPath;
     QString m_error;
-    QDBusInterface *m_managerInterface = new QDBusInterface("org.freedesktop.systemd1",
-                                                            "/org/freedesktop/systemd1",
-                                                            "org.freedesktop.systemd1.Manager",
-                                                            QDBusConnection::systemBus(),
-                                                            this);
-    QDBusInterface *m_serviceInterface = Q_NULLPTR;
+    QDBusInterface * const m_managerInterface;
+    QDBusInterface *m_serviceInterface;
 };
 
-typedef struct
-{
-    QString path;
-    QString state;
-} SystemdUnitFile;
-Q_DECLARE_METATYPE(SystemdUnitFile)
-
-typedef QList<SystemdUnitFile> SystemdUnitFileList;
-Q_DECLARE_METATYPE(SystemdUnitFileList)
-
-QDBusArgument &operator <<(QDBusArgument &argument, const SystemdUnitFile &unitFile);
-const QDBusArgument &operator >>(const QDBusArgument &argument, SystemdUnitFile &unitFile);
-
 #endif // SYSTEMDCOMMUNICATOR_H

+ 9 - 32
package/contents/ui/Application.qml

@@ -19,7 +19,6 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.3
-import QtQuick.Window 2.2
 import QtQuick.Dialogs 1.2
 import QtQuick.Layouts 1.1
 
@@ -113,48 +112,26 @@ ApplicationWindow {
             id: settingsTab
             title: i18n("Settings")
             SettingsTab {
-                baseObject: base
-            }
-        }
-    }
-
-    statusBar: StatusBar {
-        Label {
-            property string systemdError: base.hasSystemdCommunicator() ? base.systemdCom.error : ""
-            property string loaderError: base.loader.error
-
-            color: "red"
-
-            onSystemdErrorChanged: {
-                if (systemdError !== "Success" && systemdError.search("succeeded") == -1)
-                    text = systemdError;
-                else if (loaderError === "Success" || loaderError === "")
-                    text = ""
-            }
-            onLoaderErrorChanged: {
-                if (loaderError !== "Success")
-                    text = loaderError;
-                else if (systemdError === "Success" || systemdError === "")
-                    text = ""
+                gui: base
             }
         }
     }
     
     Action {
-	id: loadAction
+        id: loadAction
         text: i18n("Load configuration file")
         iconName: "document-open"
-	onTriggered: openFileDialog.open()
-	tooltip: i18n("Load configuration file")
-	shortcut: StandardKey.Open
+        onTriggered: openFileDialog.open()
+        tooltip: i18n("Load configuration file")
+        shortcut: StandardKey.Open
     }
     Action {
-	id: saveAction
-	text: i18n("Save configuration file")
+        id: saveAction
+        text: i18n("Save configuration file")
         onTriggered: base.loader.save()
         iconName: "document-save"
-	tooltip: i18n("Save configuration file")
-	shortcut: StandardKey.Save
+        tooltip: i18n("Save configuration file")
+        shortcut: StandardKey.Save
     }
     
     FileDialog {

+ 7 - 5
package/contents/ui/KCM.qml

@@ -49,7 +49,7 @@ ColumnLayout {
         }
         ComboBox {
             id: fanCombobox
-            model: ArrayFunctions.namesWithPaths(kcm.base.loader.allPwmFans)
+            model: ArrayFunctions.namesWithPaths(kcm.loader.allPwmFans)
             Layout.fillWidth: true
             Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
         }
@@ -58,10 +58,12 @@ ColumnLayout {
     PwmFan {
         id: fan
         minimizable: false
-        unit: kcm.base.unit
-        fan: kcm.base.loader.allPwmFans[fanCombobox.currentIndex]
-        loader: kcm.base.loader
-        systemdCom: kcm.base.systemdCom
+        unit: kcm.unit
+        fan: kcm.loader.allPwmFans[fanCombobox.currentIndex]
+        loader: kcm.loader
+        systemdCom: kcm.systemdCom
+        minTemp: kcm.minTemp
+        maxTemp: kcm.maxTemp
         Layout.fillWidth: true
         Layout.fillHeight: true
     }

+ 6 - 7
package/contents/ui/PwmFan.qml

@@ -58,7 +58,7 @@ Rectangle {
         canvas.requestPaint();
     }
     
-    onFanChanged: update()
+    onFanChanged: update();
     onLoaderChanged: update()
     onUnitChanged: if (fan) canvas.requestPaint()
     onMinTempChanged: if (fan) canvas.requestPaint()
@@ -201,19 +201,19 @@ Rectangle {
             visible: parent.contains(Coordinates.centerOf(this)) && fan.hasTemp
             
             Behavior on unscaledTemp {
-                SpringAnimation { 
+                SpringAnimation {
                     epsilon: 0.1
                     spring: 1.0
-                    damping: 0.5
+                    damping: 0.4
                 }
             }
             Behavior on unscaledPwm {
-                SpringAnimation { 
+                SpringAnimation {
                     epsilon: 0.1
                     spring: 1.0
-                    damping: 0.5
+                    damping: 0.4
                 }
-            }
+            }                
         }
         PwmPoint {
             id: stopPoint
@@ -415,7 +415,6 @@ Rectangle {
 
         RowLayout {
             visible: systemdCom
-            enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
             
             Label {
                 text: i18n("Test start and stop values")

+ 17 - 41
package/contents/ui/SettingsTab.qml

@@ -25,10 +25,8 @@ import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/units.js" as Units
 
 Item {
-    property QtObject baseObject
-    property QtObject loader: baseObject ? baseObject.loader : null
-    property QtObject systemdCom: baseObject ? baseObject.hasSystemdCommunicator() ? baseObject.systemdCom : null : null
-    property int interval: loader ? loader.interval : 1
+    property QtObject gui
+    property QtObject systemdCom: gui && gui.hasSystemdCommunicator() ? gui.systemdCom : null
     property int padding: 10
     property real textWidth: 0
     property var locale: Qt.locale()
@@ -58,8 +56,8 @@ Item {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
                 inputMethodHints: Qt.ImhDigitsOnly
-                text: Number(interval).toLocaleString(locale)
-                onTextChanged: if (text && text != "0") loader.interval = parseInt(Number.fromLocaleString(locale, text))
+                text: Number(gui ? gui.interval : 1).toLocaleString(locale, 'f', 0)
+                onTextChanged: if (text && text != "0") gui.interval = parseInt(Number.fromLocaleString(root.locale, text))
             }
         }
         RowLayout {
@@ -77,12 +75,12 @@ Item {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
                 inputMethodHints: Qt.ImhDigitsOnly
-                onTextChanged: if (activeFocus) baseObject.minTemp = Units.toCelsius(Number.fromLocaleString(locale, text), baseObject.unit)
-                Component.onCompleted: text = Units.fromCelsius(baseObject.minTemp, baseObject.unit)
+                onTextChanged: if (activeFocus) gui.minTemp = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit)
+                Component.onCompleted: text = Units.fromCelsius(gui.minTemp, gui.unit)
                 
                 Connections {
-                    target: baseObject
-                    onUnitChanged: minTempValue.text = Units.fromCelsius(baseObject.minTemp, baseObject.unit)
+                    target: gui
+                    onUnitChanged: minTempValue.text = Units.fromCelsius(gui.minTemp, gui.unit)
                 }
             }
         }
@@ -101,33 +99,12 @@ Item {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
                 inputMethodHints: Qt.ImhDigitsOnly
-                onTextChanged: if (activeFocus) baseObject.maxTemp = Units.toCelsius(Number.fromLocaleString(locale, text), baseObject.unit)
-                Component.onCompleted: text = Units.fromCelsius(baseObject.maxTemp, baseObject.unit)
+                onTextChanged: if (activeFocus) gui.maxTemp = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit)
+                Component.onCompleted: text = Units.fromCelsius(gui.maxTemp, gui.unit)
                 
                 Connections {
-                    target: baseObject
-                    onUnitChanged: maxTempValue.text = Units.fromCelsius(baseObject.maxTemp, baseObject.unit)
-                }
-            }
-        }
-        RowLayout {
-            width: parent.width
-
-            Label {
-                Layout.preferredWidth: root.textWidth
-                clip: true
-                text: i18n("Unit:")
-                horizontalAlignment: Text.AlignRight
-                Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
-            }
-            ComboBox {
-                id: unitBox
-                Layout.minimumWidth: implicitWidth
-                Layout.fillWidth: true
-                model: [i18n("Celsius"), i18n("Kelvin"), i18n("Fahrenheit")]
-                currentIndex: baseObject.unit
-                onCurrentIndexChanged: {
-                    baseObject.unit = currentIndex;
+                    target: gui
+                    onUnitChanged: maxTempValue.text = Units.fromCelsius(gui.maxTemp, gui.unit)
                 }
             }
         }
@@ -148,8 +125,8 @@ Item {
                     Layout.minimumWidth: implicitWidth
                     Layout.fillWidth: true
                     color: systemdCom.serviceExists ? "green" : "red"
-                    text: systemdCom.serviceName
-                    onTextChanged: systemdCom.serviceName = text
+                    text: gui.serviceName
+                    onTextChanged: gui.serviceName = text
                 }
             }
         }
@@ -165,13 +142,12 @@ Item {
                     horizontalAlignment: Text.AlignRight
                     Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
                 }
-                ComboBox {
+                CheckBox {
                     id: autostartBox
                     Layout.minimumWidth: implicitWidth
                     Layout.fillWidth: true
-                    model: [i18n("disabled") , i18n("enabled")]
-                    currentIndex: systemdCom.serviceEnabled ? 1 : 0
-                    onCurrentIndexChanged: systemdCom.serviceEnabled = (currentIndex == 1) ? true : false
+                    checked: systemdCom.serviceEnabled
+                    onCheckedChanged: systemdCom.serviceEnabled = checked
                 }
             }
         }