浏览代码

big rework. made lib into a qml plugin.

Malte Veerman 9 年之前
父节点
当前提交
5916283696
共有 50 个文件被更改,包括 303 次插入216 次删除
  1. 3 8
      CMakeLists.txt
  2. 4 3
      fancontrol-gui/CMakeLists.txt
  3. 24 21
      fancontrol-gui/package/contents/ui/Application.qml
  4. 1 0
      fancontrol-gui/package/contents/ui/ConfigfileTab.qml
  5. 1 0
      fancontrol-gui/package/contents/ui/PwmFansTab.qml
  6. 1 0
      fancontrol-gui/package/contents/ui/SensorsTab.qml
  7. 1 1
      fancontrol-gui/package/contents/ui/SettingsTab.qml
  8. 16 0
      fancontrol-gui/package/metadata.desktop
  9. 6 38
      fancontrol-gui/src/main.cpp
  10. 1 4
      helper/CMakeLists.txt
  11. 16 12
      import/CMakeLists.txt
  12. 9 0
      import/qml/ErrorDialog.qml
  13. 0 0
      import/qml/OptionInput.qml
  14. 3 3
      import/qml/PwmFan.qml
  15. 1 1
      import/qml/PwmPoint.qml
  16. 2 2
      import/qml/StatusPoint.qml
  17. 0 0
      import/qml/colors.js
  18. 0 0
      import/qml/math.js
  19. 9 0
      import/qml/qmldir
  20. 0 0
      import/qml/units.js
  21. 0 0
      import/src/config.cpp
  22. 0 0
      import/src/config.h
  23. 0 0
      import/src/fan.cpp
  24. 0 0
      import/src/fan.h
  25. 0 0
      import/src/fancontrolaction.h
  26. 67 0
      import/src/fancontrolqmlextension.cpp
  27. 52 0
      import/src/fancontrolqmlextension.h
  28. 0 11
      import/src/guibase.cpp
  29. 1 4
      import/src/guibase.h
  30. 0 0
      import/src/hwmon.cpp
  31. 0 0
      import/src/hwmon.h
  32. 0 0
      import/src/loader.cpp
  33. 1 3
      import/src/loader.h
  34. 0 0
      import/src/pwmfan.cpp
  35. 0 0
      import/src/pwmfan.h
  36. 0 0
      import/src/pwmfanmodel.cpp
  37. 0 0
      import/src/pwmfanmodel.h
  38. 0 0
      import/src/sensor.cpp
  39. 0 0
      import/src/sensor.h
  40. 0 0
      import/src/systemdcommunicator.cpp
  41. 1 3
      import/src/systemdcommunicator.h
  42. 0 0
      import/src/temp.cpp
  43. 0 0
      import/src/temp.h
  44. 0 0
      import/src/tempmodel.cpp
  45. 0 0
      import/src/tempmodel.h
  46. 5 4
      kcm/CMakeLists.txt
  47. 65 43
      kcm/package/contents/ui/KCM.qml
  48. 2 2
      kcm/package/metadata.desktop
  49. 8 37
      kcm/src/fancontrolkcm.cpp
  50. 3 16
      kcm/src/fancontrolkcm.h

+ 3 - 8
CMakeLists.txt

@@ -47,7 +47,6 @@ find_package(KF5 COMPONENTS I18n Package REQUIRED)
 
 
 #includes
-include(GenerateExportHeader)
 include(KDEInstallDirs)
 include(KDECMakeSettings)
 include(KDECompilerSettings)
@@ -72,10 +71,6 @@ else(NOT NO_SYSTEMD)
 endif(NOT NO_SYSTEMD)
 
 
-#Shared library
-add_subdirectory(lib)
-
-
 #KHelper for actions that require superuser rights
 if(INSTALL_HELPER)
 
@@ -105,12 +100,12 @@ endif(BUILD_KCM)
 #install the shared parts
 if(INSTALL_SHARED)
 
-    #KPackage containing the QML and javascript files
-    kpackage_install_package(package kcm_fancontrol kcms)
+    #qml plugin
+    add_subdirectory(import)
 
 
     #icon
-    install(FILES icon.svg RENAME "fancontrol_gui.svg" DESTINATION "${ICON_INSTALL_DIR}/hicolor/scalable/apps")
+    install(FILES icon.svg RENAME "fancontrol_gui.svg" DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/scalable/apps")
 
 
     #translations

+ 4 - 3
fancontrol-gui/CMakeLists.txt

@@ -1,8 +1,7 @@
 set(Fancontrol_GUI_SRCS src/main.cpp
                         src/windowconfig.cpp)
 
-set(LIBRARIES fancontrol_gui_lib
-              Qt5::Widgets
+set(LIBRARIES Qt5::Widgets
               KF5::Declarative
               KF5::I18n
               KF5::ConfigGui
@@ -18,4 +17,6 @@ add_executable(fancontrol_gui ${Fancontrol_GUI_SRCS})
 target_link_libraries(fancontrol_gui ${LIBRARIES})
 
 install(TARGETS fancontrol_gui ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
-install(FILES metadata.desktop RENAME "fancontrol_gui.desktop" DESTINATION ${XDG_APPS_INSTALL_DIR})
+install(FILES metadata.desktop RENAME "fancontrol_gui.desktop" DESTINATION ${KDE_INSTALL_APPDIR})
+
+kpackage_install_package(package fancontrol-gui genericqml)

+ 24 - 21
package/contents/ui/Application.qml → fancontrol-gui/package/contents/ui/Application.qml

@@ -22,6 +22,7 @@ import QtQuick 2.4
 import QtQuick.Controls 1.3
 import QtQuick.Dialogs 1.2
 import QtQuick.Layouts 1.1
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 ApplicationWindow {
@@ -32,11 +33,14 @@ ApplicationWindow {
     visible: true
 
     onClosing: {
-        base.save();
+        Fancontrol.base.save();
         windowConfig.save(window);
     }
     
-    Component.onCompleted: windowConfig.restore(window)
+    Component.onCompleted: {
+        Fancontrol.base.load();
+        windowConfig.restore(window);
+    }
 
     menuBar: MenuBar {
         Menu {
@@ -63,22 +67,22 @@ ApplicationWindow {
             ToolButton { action: loadAction }
             ToolButton { action: saveAction }
             Loader {
-                active: base.hasSystemdCommunicator()
+                active: Fancontrol.base.hasSystemdCommunicator()
                 sourceComponent: ToolButton {
-                    iconName: base.systemdCom.serviceActive ? "system-reboot" : "system-run"
+                    iconName: Fancontrol.base.systemdCom.serviceActive ? "system-reboot" : "system-run"
                     onClicked: {
-                        base.loader.abortTestingFans();
-                        base.systemdCom.serviceActive ? base.systemdCom.restartService() : base.systemdCom.serviceActive = true;
+                        Fancontrol.base.loader.abortTestingFans();
+                        Fancontrol.base.systemdCom.serviceActive ? base.systemdCom.restartService() : base.systemdCom.serviceActive = true;
                     }
-                    tooltip: base.systemdCom.serviceActive ? i18n("Restart fancontrol") : i18n("Start fancontrol")
+                    tooltip: Fancontrol.base.systemdCom.serviceActive ? i18n("Restart fancontrol") : i18n("Start fancontrol")
                 }
             }
             Loader {
-                active: base.hasSystemdCommunicator()
+                active: Fancontrol.base.hasSystemdCommunicator()
                 sourceComponent: ToolButton {
                     iconName: "system-shutdown"
-                    enabled: base.systemdCom.serviceActive
-                    onClicked: base.systemdCom.serviceActive = false;
+                    enabled: Fancontrol.base.systemdCom.serviceActive
+                    onClicked: Fancontrol.base.systemdCom.serviceActive = false;
                     tooltip: i18n("Stop fancontrol")
                 }
             }
@@ -97,36 +101,35 @@ ApplicationWindow {
         Tab {
             title: i18n("Sensors")
             SensorsTab {
-                loader: base.loader
+                loader: Fancontrol.base.loader
             }
         }
         Tab {
             title: i18n("PwmFans")
             PwmFansTab {
-                baseObject: base
+                baseObject: Fancontrol.base
             }
         }
         Tab {
             title: i18n("Configfile")
             ConfigfileTab {
-                loader: base.loader
+                loader: Fancontrol.base.loader
             }
         }
         Tab {
             id: settingsTab
             title: i18n("Settings")
             SettingsTab {
-                gui: base
+                gui: Fancontrol.base
             }
         }
     }
 
-    ErrorDialog {
+    Fancontrol.ErrorDialog {
         id: errorDialog
-        visible: !!base.loader.error
+        visible: false
         modality: Qt.ApplicationModal
-        text: base.loader.error
-        onTextChanged: show()
+        loader: Fancontrol.base.loader
     }
 
     Action {
@@ -142,7 +145,7 @@ ApplicationWindow {
         text: i18n("Save configuration file")
         onTriggered: base.save(true)
         iconName: "document-save"
-        tooltip: i18n("Save configuration file") + " (" + base.loader.configUrl.toString() + ")"
+        tooltip: i18n("Save configuration file") + " (" + Fancontrol.base.loader.configUrl.toString() + ")"
         shortcut: StandardKey.Save
     }
 
@@ -154,7 +157,7 @@ ApplicationWindow {
         selectMultiple: false
         modality: Qt.NonModal
 
-        onAccepted: base.configUrl = fileUrl;
+        onAccepted: Fancontrol.base.configUrl = fileUrl;
     }
     FileDialog {
         id: saveFileDialog
@@ -164,6 +167,6 @@ ApplicationWindow {
         selectMultiple: false
         modality: Qt.NonModal
 
-        onAccepted: base.save(true, fileUrl);
+        onAccepted: Fancontrol.base.save(true, fileUrl);
     }
 }

+ 1 - 0
package/contents/ui/ConfigfileTab.qml → fancontrol-gui/package/contents/ui/ConfigfileTab.qml

@@ -21,6 +21,7 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
+import Fancontrol.Qml 1.0
 
 
 ColumnLayout {

+ 1 - 0
package/contents/ui/PwmFansTab.qml → fancontrol-gui/package/contents/ui/PwmFansTab.qml

@@ -21,6 +21,7 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.4
 import QtQuick.Layouts 1.2
+import Fancontrol.Qml 1.0
 
 
 ColumnLayout {

+ 1 - 0
package/contents/ui/SensorsTab.qml → fancontrol-gui/package/contents/ui/SensorsTab.qml

@@ -21,6 +21,7 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
+import Fancontrol.Qml 1.0
 
 
 RowLayout {

+ 1 - 1
package/contents/ui/SettingsTab.qml → fancontrol-gui/package/contents/ui/SettingsTab.qml

@@ -21,7 +21,7 @@
 import QtQuick 2.4
 import QtQuick.Layouts 1.1
 import QtQuick.Controls 1.2
-import "../scripts/units.js" as Units
+import Fancontrol.Qml 1.0
 
 
 Item {

+ 16 - 0
fancontrol-gui/package/metadata.desktop

@@ -0,0 +1,16 @@
+[Desktop Entry]
+Name=Fancontrol-GUI-QML-Package
+Comment=Control PWM-fans
+Icon=fancontrol_gui
+Encoding=UTF-8
+Keywords=
+Type=Service
+X-KDE-PluginInfo-Author=Malte Veerman
+X-KDE-PluginInfo-Email=maldela@halloarsch.de
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-Name=fancontrol-gui
+X-KDE-PluginInfo-Version=0.4
+X-KDE-PluginInfo-Website=
+X-KDE-ServiceTypes=Plasma/Generic
+X-Plasma-API=declarativeappletscript 
+X-Plasma-MainScript=ui/Application.qml

+ 6 - 38
fancontrol-gui/src/main.cpp

@@ -18,19 +18,16 @@
  */
 
 #include <QtWidgets/QApplication>
-#include <QtQml/QQmlApplicationEngine>
 #include <QtQml/QQmlContext>
 #include <QtCore/QCommandLineParser>
 #include <QtCore/QLoggingCategory>
-#include <QtCore/QFileInfo>
 #include <QtGui/QIcon>
 
-#include <KDeclarative/KDeclarative>
+#include <KDeclarative/QmlObject>
 #include <KI18n/KLocalizedString>
 #include <KPackage/PackageLoader>
 #include <KCoreAddons/KAboutData>
 
-#include "lib/src/guibase.h"
 #include "windowconfig.h"
 
 
@@ -46,7 +43,7 @@ int main(int argc, char *argv[])
 
     KAboutData about(QStringLiteral("fancontrol_gui"),
                      i18n("Fancontrol-GUI"),
-                     QStringLiteral("0.3"),
+                     QStringLiteral("0.4"),
                      i18n("Graphical user interface for fancontrol"),
                      KAboutLicense::KAboutLicense::GPL_V2,
                      QStringLiteral("Copyright (C) 2015 Malte Veerman"),
@@ -60,40 +57,11 @@ int main(int argc, char *argv[])
     parser.process(app);
     about.processCommandLine(&parser);
 
-    QQmlApplicationEngine engine;
-    QQmlContext *context = engine.rootContext();
-
-    KDeclarative::KDeclarative decl;
-    decl.setDeclarativeEngine(&engine);
-    decl.setupBindings();
-
-    Fancontrol::GUIBase base;
-    base.load();
-    context->setContextProperty(QStringLiteral("base"), &base);
-
+    KDeclarative::QmlObject qmlObject;
     WindowConfig *windowConfig = WindowConfig::instance();
-    context->setContextProperty(QStringLiteral("windowConfig"), windowConfig);
-
-    KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
-
-    QStringList possiblePackageLocations = QStringList() << QStringLiteral("/usr/share/kpackage/kcms")
-                                                         << QStringLiteral("/usr/local/share/kpackage/kcms")
-                                                         << QStringLiteral("kpackage/kcms")
-                                                         << QStringLiteral("/opt/share/kpackage/kcms");
-
-    foreach (const QString location, possiblePackageLocations)
-    {
-        package.setDefaultPackageRoot(location);
-        package.setPath(QStringLiteral("kcm_fancontrol"));
-        package.addFileDefinition("appqmlroot", QStringLiteral("ui/Application.qml"), i18n("The Application's root QML file"));
-        package.setRequired("appqmlroot", true);
+    qmlObject.rootContext()->setContextProperty(QStringLiteral("windowConfig"), windowConfig);
 
-        if (package.isValid())
-        {
-            engine.load(QUrl::fromLocalFile(package.filePath("appqmlroot")));
-            return app.exec();
-        }
-    }   
+    qmlObject.loadPackage("fancontrol-gui");
     
-    return 1;
+    return app.exec();
 }

+ 1 - 4
helper/CMakeLists.txt

@@ -12,10 +12,7 @@ find_package(KF5Auth REQUIRED)
 
 add_executable(fancontrol-gui-helper src/helper.cpp)
 target_link_libraries(fancontrol-gui-helper ${LIBRARIES})
-install(TARGETS fancontrol-gui-helper DESTINATION ${KAUTH_HELPER_INSTALL_ABSOLUTE_DIR})
-
-set(SYSCONF_INSTALL_DIR "/etc")
-set(DBUS_SYSTEM_SERVICES_INSTALL_DIR "/usr/share/dbus-1/system-services")
+install(TARGETS fancontrol-gui-helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
 
 kauth_install_helper_files(fancontrol-gui-helper fancontrol.gui.helper root)
 kauth_install_actions(fancontrol.gui.helper fancontrol_gui.actions)

+ 16 - 12
lib/CMakeLists.txt → import/CMakeLists.txt

@@ -7,7 +7,18 @@ set(LIB_SRCS src/hwmon.cpp
              src/guibase.cpp
              src/config.cpp
              src/pwmfanmodel.cpp
-             src/tempmodel.cpp)
+             src/tempmodel.cpp
+             src/fancontrolqmlextension.cpp)
+             
+set(QML_FILES qml/qmldir
+              qml/ErrorDialog.qml
+              qml/OptionInput.qml
+              qml/PwmFan.qml
+              qml/PwmPoint.qml
+              qml/StatusPoint.qml
+              qml/colors.js
+              qml/math.js
+              qml/units.js)
 
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
                           KF5::Auth
@@ -31,15 +42,8 @@ find_package(KF5 COMPONENTS Auth Config REQUIRED)
 
 include_directories(${Qt5Qml_INCLUDE_DIRS})
 
-add_library(fancontrol_gui_lib SHARED ${LIB_SRCS})
-target_link_libraries(fancontrol_gui_lib PRIVATE ${LIB_PRIVATE_LIBRARIES} PUBLIC ${LIB_PUBLIC_LIBRARIES})
+add_library(fancontrol_qml_plugin SHARED ${LIB_SRCS})
+target_link_libraries(fancontrol_qml_plugin PRIVATE ${LIB_PRIVATE_LIBRARIES} PUBLIC ${LIB_PUBLIC_LIBRARIES})
 
-target_compile_features(fancontrol_gui_lib PRIVATE cxx_lambdas)
-
-generate_export_header(fancontrol_gui_lib)
-
-if(INSTALL_SHARED)
-
-    install(TARGETS fancontrol_gui_lib ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
-
-endif(INSTALL_SHARED)
+install(TARGETS fancontrol_qml_plugin DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")
+install(FILES ${QML_FILES} DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")

+ 9 - 0
package/contents/ui/ErrorDialog.qml → import/qml/ErrorDialog.qml

@@ -24,7 +24,10 @@ import QtQuick.Controls 1.2
 
 
 Dialog {
+    id: dialog
+
     property alias text: text.text
+    property QtObject loader
 
     title: i18n("Error")
     width: text.implicitWidth + 20
@@ -34,5 +37,11 @@ Dialog {
     Label {
         id: text
         anchors.centerIn: parent
+        text: !!loader ? loader.error : ""
+    }
+    
+    Connections {
+        target: loader
+        onCriticalError: dialog.open()
     }
 }

+ 0 - 0
package/contents/ui/OptionInput.qml → import/qml/OptionInput.qml


+ 3 - 3
package/contents/ui/PwmFan.qml → import/qml/PwmFan.qml

@@ -21,9 +21,9 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.4
 import QtQuick.Layouts 1.1
-import "../scripts/math.js" as MoreMath
-import "../scripts/units.js" as Units
-import "../scripts/colors.js" as Colors
+import "math.js" as MoreMath
+import "units.js" as Units
+import "colors.js" as Colors
 
 
 Rectangle {

+ 1 - 1
package/contents/ui/PwmPoint.qml → import/qml/PwmPoint.qml

@@ -20,7 +20,7 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.4
-import "../scripts/units.js" as Units
+import "units.js" as Units
 
 
 Rectangle {

+ 2 - 2
package/contents/ui/StatusPoint.qml → import/qml/StatusPoint.qml

@@ -20,8 +20,8 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.2
-import "../scripts/units.js" as Units
-import "../scripts/math.js" as MoreMath
+import "units.js" as Units
+import "math.js" as MoreMath
 
 
 Rectangle {

+ 0 - 0
package/contents/scripts/colors.js → import/qml/colors.js


+ 0 - 0
package/contents/scripts/math.js → import/qml/math.js


+ 9 - 0
import/qml/qmldir

@@ -0,0 +1,9 @@
+module Fancontrol.Qml
+plugin fancontrol_qml_plugin
+internal StatusPoint StatusPoint.qml
+internal PwmPoint PwmPoint.qml
+PwmFan 1.0 PwmFan.qml
+ErrorDialog 1.0 ErrorDialog.qml
+OptionInput 1.0 OptionInput.qml
+Units 1.0 units.js
+

+ 0 - 0
package/contents/scripts/units.js → import/qml/units.js


+ 0 - 0
lib/src/config.cpp → import/src/config.cpp


+ 0 - 0
lib/src/config.h → import/src/config.h


+ 0 - 0
lib/src/fan.cpp → import/src/fan.cpp


+ 0 - 0
lib/src/fan.h → import/src/fan.h


+ 0 - 0
lib/src/fancontrolaction.h → import/src/fancontrolaction.h


+ 67 - 0
import/src/fancontrolqmlextension.cpp

@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016  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 "fancontrolqmlextension.h"
+
+#include "guibase.h"
+#include "loader.h"
+#include "hwmon.h"
+#include "fan.h"
+#include "pwmfan.h"
+#include "temp.h"
+
+#ifndef NO_SYSTEMD
+#include "systemdcommunicator.h"
+#endif
+
+#include <QtQml/qqml.h>
+
+
+namespace Fancontrol
+{
+
+void FancontrolQmlExtension::registerTypes(const char* uri)
+{
+    Q_ASSERT(uri == QLatin1String("Fancontrol.Qml"));
+    
+    qmlRegisterType<Loader>();
+    qmlRegisterType<Hwmon>();
+    qmlRegisterType<Fan>();
+    qmlRegisterType<PwmFan>();
+    qmlRegisterType<Temp>();
+    qmlRegisterSingletonType<GUIBase>(uri, 1, 0, "base", base);
+    
+#ifndef NO_SYSTEMD
+    qmlRegisterType<SystemdCommunicator>();
+#endif
+}
+
+QObject * FancontrolQmlExtension::base(QQmlEngine *engine, QJSEngine *jsengine)
+{
+    Q_UNUSED(engine)
+    Q_UNUSED(jsengine)
+    
+    return new GUIBase;
+}
+
+
+}
+

+ 52 - 0
import/src/fancontrolqmlextension.h

@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016  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 FANCONTROLQMLEXTENSION_H
+#define FANCONTROLQMLEXTENSION_H
+
+
+#include <QtQml/QQmlExtensionPlugin>
+
+
+class QQmlEngine;
+class QJSEngine;
+
+namespace Fancontrol
+{
+
+class FancontrolQmlExtension : public QQmlExtensionPlugin
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID "Fancontrol.Qml")
+    
+public:
+    
+    void registerTypes(const char *uri) Q_DECL_OVERRIDE;
+    
+    
+private:
+    
+    static QObject * base(QQmlEngine *engine, QJSEngine *jsengine);
+};
+
+}
+
+#endif // FANCONTROLQMLEXTENSION_H

+ 0 - 11
lib/src/guibase.cpp → import/src/guibase.cpp

@@ -26,7 +26,6 @@
 #include "config.h"
 #include "hwmon.h"
 
-#include <QtQml/qqml.h>
 #include <QtCore/QLocale>
 
 
@@ -51,16 +50,6 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     QLocale::MeasurementSystem system = locale.measurementSystem();
     m_unit = (system != QLocale::ImperialUSSystem) ? 0 : 2;
 
-    qmlRegisterType<Loader>();
-    qmlRegisterType<Hwmon>();
-    qmlRegisterType<Fan>();
-    qmlRegisterType<PwmFan>();
-    qmlRegisterType<Temp>();
-
-#ifndef NO_SYSTEMD
-    qmlRegisterType<SystemdCommunicator>();
-#endif
-
     m_tempModel->setUnit(m_unit);
     foreach (Hwmon *hwmon, m_loader->hwmons())
     {

+ 1 - 4
lib/src/guibase.h → import/src/guibase.h

@@ -1,5 +1,4 @@
 /*
- * <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
@@ -39,15 +38,13 @@
 #define SYSTEMD_BOOL false
 #endif
 
-#include "fancontrol_gui_lib_export.h"
-
 
 namespace Fancontrol
 {
 
 class Config;
 
-class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
+class GUIBase : public QObject
 {
     Q_OBJECT
 

+ 0 - 0
lib/src/hwmon.cpp → import/src/hwmon.cpp


+ 0 - 0
lib/src/hwmon.h → import/src/hwmon.h


+ 0 - 0
lib/src/loader.cpp → import/src/loader.cpp


+ 1 - 3
lib/src/loader.h → import/src/loader.h

@@ -27,8 +27,6 @@
 #include <QtCore/QString>
 #include <QtCore/QPair>
 
-#include "fancontrol_gui_lib_export.h"
-
 
 class QTimer;
 class KJob;
@@ -40,7 +38,7 @@ class Hwmon;
 class PwmFan;
 class Temp;
 
-class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
+class Loader : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)

+ 0 - 0
lib/src/pwmfan.cpp → import/src/pwmfan.cpp


+ 0 - 0
lib/src/pwmfan.h → import/src/pwmfan.h


+ 0 - 0
lib/src/pwmfanmodel.cpp → import/src/pwmfanmodel.cpp


+ 0 - 0
lib/src/pwmfanmodel.h → import/src/pwmfanmodel.h


+ 0 - 0
lib/src/sensor.cpp → import/src/sensor.cpp


+ 0 - 0
lib/src/sensor.h → import/src/sensor.h


+ 0 - 0
lib/src/systemdcommunicator.cpp → import/src/systemdcommunicator.cpp


+ 1 - 3
lib/src/systemdcommunicator.h → import/src/systemdcommunicator.h

@@ -23,8 +23,6 @@
 
 #include <QtCore/QObject>
 
-#include "fancontrol_gui_lib_export.h"
-
 
 class QDBusInterface;
 class KJob;
@@ -32,7 +30,7 @@ class KJob;
 namespace Fancontrol
 {
 
-class FANCONTROL_GUI_LIB_EXPORT SystemdCommunicator : public QObject
+class SystemdCommunicator : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(QString error READ error NOTIFY errorChanged)

+ 0 - 0
lib/src/temp.cpp → import/src/temp.cpp


+ 0 - 0
lib/src/temp.h → import/src/temp.h


+ 0 - 0
lib/src/tempmodel.cpp → import/src/tempmodel.cpp


+ 0 - 0
lib/src/tempmodel.h → import/src/tempmodel.h


+ 5 - 4
kcm/CMakeLists.txt

@@ -1,7 +1,6 @@
 set(LIBRARIES KF5::QuickAddons
               KF5::CoreAddons
-              KF5::I18n
-              fancontrol_gui_lib)
+              KF5::I18n)
 
 find_package(KF5Declarative REQUIRED)
 
@@ -9,7 +8,9 @@ add_library(kcm_fancontrol MODULE src/fancontrolkcm.cpp)
 
 target_link_libraries(kcm_fancontrol ${LIBRARIES})
 
-install(TARGETS kcm_fancontrol DESTINATION "${CMAKE_INSTALL_PLUGINDIR}/kcms")
-install(FILES kcm_fancontrol.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+install(TARGETS kcm_fancontrol DESTINATION "${KDE_INSTALL_QTPLUGINDIR}/kcms")
+install(FILES kcm_fancontrol.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
+
+kpackage_install_package(package kcm_fancontrol kcms)
 
 kcoreaddons_desktop_to_json(kcm_fancontrol "kcm_fancontrol.desktop")

+ 65 - 43
package/contents/ui/KCM.qml → kcm/package/contents/ui/KCM.qml

@@ -20,25 +20,55 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.3
-import QtQuick.Layouts 1.1
+import QtQuick.Layouts 1.2
 import QtQuick.Dialogs 1.2
 import org.kde.kcm 1.0
-import "../scripts/units.js" as Units
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 Item {
-    property QtObject base: kcm.base
-    property QtObject loader: !!base ? base.loader : null
-    property QtObject systemdCom: !!base ? base.systemdCom : null
-    property QtObject pwmFanModel: !!base ? base.pwmFanModel : null
-    property QtObject tempModel: !!base ? base.tempModel : null
+    property QtObject loader: Fancontrol.base.loader
+    property QtObject systemdCom: Fancontrol.base.systemdCom
+    property QtObject pwmFanModel: Fancontrol.base.pwmFanModel
+    property QtObject tempModel: Fancontrol.base.tempModel
     property var locale: Qt.locale()
     property real textWidth: 0
-    property var pwmFans: pwmFanModel ? pwmFanModel.fans : null
+    property var pwmFans: pwmFanModel ? pwmFanModel.fans : []
 
     id: root
     implicitWidth: 1024
     implicitHeight: 768
+    
+    Connections {
+        target: loader
+        onConfigFileChanged: kcm.needsSave = true
+    }
+    
+    Connections {
+        target: Fancontrol.base
+        onMinTempChanged: kcm.needsSave = true
+        onMaxTempChanged: kcm.needsSave = true
+        onServiceNameChanged: kcm.needsSave = true
+        onConfigUrlChanged: kcm.needsSave = true
+    }
+    
+    Connections {
+        target: kcm
+        onAboutToSave: {
+            base.save(true);
+            if (systemdCom.serviceActive && enabledBox.checked) {
+                systemdCom.restartService();
+            } else {
+                systemdCom.serviceActive = enabledBox.checked;
+            }
+            systemdCom.serviceEnabled = enabledBox.checked;
+        }
+        onAboutToLoad: {
+            Fancontrol.base.load();
+            enabledBox.checked = systemdCom.serviceEnabled && systemdCom.serviceActive;
+        }
+        onAboutToDefault: enabledBox.checked = false
+    }
 
     ColumnLayout {
         id: noFansInfo
@@ -46,7 +76,7 @@ Item {
         width: parent.width
         anchors.verticalCenter: parent.verticalCenter
         spacing: 20
-        visible: pwmFanModel.count == 0
+        visible: pwmFans.length === 0
 
         Label {
             Layout.alignment: Qt.AlignCenter
@@ -67,15 +97,10 @@ Item {
         id: enabledBox
 
         anchors.top: parent.top
-        visible: pwmFanModel.count > 0
+        visible: pwmFans.length > 0
         text: i18n("Control fans manually")
-        checked: kcm.manualControl
-        onCheckedChanged: kcm.manualControl = checked
-
-        Connections {
-            target: kcm
-            onManualControlChanged: enabledBox.checked = kcm.manualControl
-        }
+        checked: systemdCom.serviceEnabled && systemdCom.serviceActive;
+        onCheckedChanged: if (checked !== systemdCom.serviceActive || checked !== systemdCom.serviceEnabled) kcm.needsSave = true
     }
 
     ColumnLayout {
@@ -114,13 +139,13 @@ Item {
             Layout.fillWidth: true
             Layout.fillHeight: true
             active: !!pwmFans[fanComboBox.currentIndex]
-            sourceComponent: PwmFan {
-                unit: base.unit
+            sourceComponent: Fancontrol.PwmFan {
+                unit: Fancontrol.base.unit
                 fan: pwmFans[fanComboBox.currentIndex]
                 systemdCom: root.systemdCom
                 tempModel: root.tempModel
-                minTemp: base.minTemp
-                maxTemp: base.maxTemp
+                minTemp: Fancontrol.base.minTemp
+                maxTemp: Fancontrol.base.maxTemp
             }
         }
     }
@@ -133,6 +158,7 @@ Item {
         anchors.bottom: settingsArea.top
         width: parent.width
         height: advancedArrow.height
+        visible: enabledBox.checked
 
         Image {
             id: advancedArrow
@@ -157,7 +183,7 @@ Item {
     ColumnLayout {
         id: settingsArea
 
-        visible: enabledBox.checked && parent.height - enabledBox.height - bodyLayout.height > height
+        visible: enabledBox.checked && parent.height - enabledBox.height - bodyLayout.height - advancedButton.height > height
         width: parent.width
         anchors.bottom: parent.bottom
         clip: true
@@ -224,10 +250,10 @@ Item {
                 Layout.fillWidth: true
                 decimals: 2
                 maximumValue: maxTempBox.value
-                minimumValue: Units.fromKelvin(0, base.unit)
-                value: Units.fromCelsius(base.minTemp, base.unit)
-                suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
-                onValueChanged: base.minTemp = value
+                minimumValue: Units.fromKelvin(0, Fancontrol.base.unit)
+                value: Units.fromCelsius(Fancontrol.base.minTemp, Fancontrol.base.unit)
+                suffix: Fancontrol.base.unit == 0 ? i18n("°C") : Fancontrol.base.unit == 1 ? i18n("K") : i18n("°F")
+                onValueChanged: Fancontrol.base.minTemp = value
             }
         }
         RowLayout {
@@ -247,9 +273,9 @@ Item {
                 decimals: 2
                 maximumValue: Number.POSITIVE_INFINITY
                 minimumValue: minTempBox.value
-                value: Units.fromCelsius(base.maxTemp, base.unit)
-                suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
-                onValueChanged: base.maxTemp = value
+                value: Units.fromCelsius(Fancontrol.base.maxTemp, Fancontrol.base.unit)
+                suffix: Fancontrol.base.unit == 0 ? i18n("°C") : Fancontrol.base.unit == 1 ? i18n("K") : i18n("°F")
+                onValueChanged: Fancontrol.base.maxTemp = value
             }
         }
         RowLayout {
@@ -262,12 +288,12 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
+            Fancontrol.OptionInput {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
                 color: systemdCom.serviceExists ? "green" : "red"
-                value: base.serviceName
-                onTextChanged: base.serviceName = text
+                value: Fancontrol.base.serviceName
+                onTextChanged: Fancontrol.base.serviceName = text
             }
         }
         RowLayout {
@@ -280,12 +306,12 @@ Item {
                 horizontalAlignment: Text.AlignRight
                 Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
             }
-            OptionInput {
+            Fancontrol.OptionInput {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                text: base.configUrl.toString().replace("file://", "")
-                color: base.configValid ? "green" : "red"
-                onTextChanged: base.configUrl = text
+                text: Fancontrol.base.configUrl.toString().replace("file://", "")
+                color: Fancontrol.base.configValid ? "green" : "red"
+                onTextChanged: Fancontrol.base.configUrl = text
             }
             Button {
                 action: loadAction
@@ -308,16 +334,12 @@ Item {
         selectExisting: true
         selectMultiple: false
 
-        onAccepted: base.configUrl = fileUrl;
+        onAccepted: Fancontrol.base.configUrl = fileUrl;
     }
 
-    ErrorDialog {
+    Fancontrol.ErrorDialog {
         id: errorDialog
         modality: Qt.ApplicationModal
-        text: loader.error
-    }
-    Connections {
-        target: loader
-        onCriticalError: errorDialog.open()
+        loader: root.loader
     }
 }

+ 2 - 2
package/metadata.desktop → kcm/package/metadata.desktop

@@ -9,8 +9,8 @@ X-KDE-PluginInfo-Author=Malte Veerman
 X-KDE-PluginInfo-Email=maldela@halloarsch.de
 X-KDE-PluginInfo-License=GPL
 X-KDE-PluginInfo-Name=kcm_fancontrol
-X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-Version=0.4
 X-KDE-PluginInfo-Website=
 X-KDE-ServiceTypes=Plasma/Generic
 X-Plasma-API=declarativeappletscript 
-X-Plasma-MainScript=ui/KCM.qml
+X-Plasma-MainScript=ui/KCM.qml

+ 8 - 37
kcm/src/fancontrolkcm.cpp

@@ -22,8 +22,6 @@
 
 #include "fancontrolkcm.h"
 
-#include <QtQml/qqml.h>
-
 #include <KCoreAddons/KAboutData>
 #include <KCoreAddons/KPluginFactory>
 #include <KI18n/KLocalizedString>
@@ -33,16 +31,11 @@ K_PLUGIN_FACTORY_WITH_JSON(FancontrolKCMFactory, "kcm_fancontrol.json", register
 
 
 FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
-    : ConfigModule(parent, args),
-    m_base(new GUIBase(this)),
-    m_manualControl(false)
+    : ConfigModule(parent, args)
 {
-    if (!m_base->hasSystemdCommunicator())
-        qFatal("Fancontrol-gui-lib was compiled without systemd support!");
-
     KAboutData *about = new KAboutData(QStringLiteral("kcm_fancontrol"),
                                        i18n("Fancontrol-KCM"),
-                                       QStringLiteral("0.1"),
+                                       QStringLiteral("0.3"),
                                        i18n("KDE Fancontrol Module"),
                                        KAboutLicense::KAboutLicense::GPL_V2,
                                        QStringLiteral("Copyright (C) 2015 Malte Veerman"),
@@ -54,50 +47,28 @@ FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
 
     setButtons(Apply | Default);
     setAuthActionName(QStringLiteral("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
-        m_base->systemdCommunicator()->setServiceActive(m_manualControl);
-
-    m_base->systemdCommunicator()->setServiceEnabled(m_manualControl);
+    emit aboutToSave();
+    
     setNeedsSave(false);
 }
 
 void FancontrolKCM::load()
 {
-    m_base->load();
-    setManualControl(m_base->systemdCommunicator()->serviceEnabled() || m_base->systemdCommunicator()->serviceActive());
+    emit aboutToLoad();
+    
     setNeedsSave(false);
 }
 
 void FancontrolKCM::defaults()
 {
-    setManualControl(false);
+    emit aboutToDefault();
+    
     setNeedsSave(true);
 }
 
-void FancontrolKCM::setManualControl(bool manualControl)
-{
-    if (m_manualControl != manualControl)
-    {
-        m_manualControl = manualControl;
-        emit manualControlChanged();
-        setNeedsSave(true);
-    }
-}
-
 
 #include "fancontrolkcm.moc"

+ 3 - 16
kcm/src/fancontrolkcm.h

@@ -25,26 +25,17 @@
 
 #include <KDeclarative/KQuickAddons/ConfigModule>
 
-#include "lib/src/guibase.h"
-
 
 using namespace KQuickAddons;
-using namespace Fancontrol;
 
 class FancontrolKCM : public ConfigModule
 {
     Q_OBJECT
-    Q_PROPERTY(GUIBase *base READ base CONSTANT)
-    Q_PROPERTY(bool manualControl READ manualControl WRITE setManualControl NOTIFY manualControlChanged)
     
 public:
     
     explicit FancontrolKCM(QObject *parent, const QVariantList &args = QVariantList());
     
-    GUIBase *base() const { return m_base; }
-    bool manualControl() const { return m_manualControl; }
-    void setManualControl(bool manualControl);
-    
     
 public slots:
     
@@ -55,13 +46,9 @@ public slots:
     
 signals:
     
-    void manualControlChanged();
-    
-
-private:
-    
-    GUIBase *const m_base;
-    bool m_manualControl;
+    void aboutToSave();
+    void aboutToLoad();
+    void aboutToDefault();
 };
 
 #endif // FANCONTROLKCM_H