Quellcode durchsuchen

Merge branch 'master' of https://github.com/Maldela/Fancontrol-GUI

Malte Veerman vor 10 Jahren
Ursprung
Commit
d76fe296f4

+ 1 - 0
fancontrol-gui/src/main.cpp

@@ -20,6 +20,7 @@
 #include <QtWidgets/QApplication>
 #include <QtQml/QQmlApplicationEngine>
 #include <QtQml/QQmlContext>
+
 #include <KDeclarative/KDeclarative>
 #include <KI18n/KLocalizedString>
 #include <KPackage/PackageLoader>

+ 2 - 0
helper/src/helper.cpp

@@ -24,6 +24,8 @@
 #include <QtCore/QProcess>
 #include <KAuth/KAuthHelperSupport>
 
+#include<KAuth/KAuthHelperSupport>
+
 #ifndef NO_SYSTEMD
 #include <QtDBus/QDBusInterface>
 #endif

+ 1 - 0
kcm/src/fancontrolkcm.cpp

@@ -23,6 +23,7 @@
 #include "fancontrolkcm.h"
 
 #include <QtQml/qqml.h>
+
 #include <KCoreAddons/KAboutData>
 #include <KCoreAddons/KPluginFactory>
 #include <KI18n/KLocalizedString>

+ 1 - 1
lib/src/config.h

@@ -24,7 +24,7 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-#include <KF5/KConfigCore/KCoreConfigSkeleton>
+#include <KConfigCore/KCoreConfigSkeleton>
 
 
 class Config : public KCoreConfigSkeleton

+ 1 - 1
lib/src/fan.h

@@ -43,7 +43,7 @@ public:
     void reset() Q_DECL_OVERRIDE;
 
     virtual int pwm() const { return 255; }
-    virtual void setPwm(int, bool) { }
+    virtual bool setPwm(int, bool) { return false; }
 
 
 signals:

+ 2 - 3
lib/src/loader.cpp

@@ -21,9 +21,6 @@
 #include "loader.h"
 
 #include "hwmon.h"
-#include "fan.h"
-#include "pwmfan.h"
-#include "temp.h"
 
 #include <QtCore/QFile>
 #include <QtCore/QDir>
@@ -33,6 +30,7 @@
 
 #include <KAuth/KAuthExecuteJob>
 
+
 #define HWMON_PATH "/sys/class/hwmon"
 
 
@@ -224,6 +222,7 @@ bool Loader::load(const QUrl &url)
     }
     else if (url.isLocalFile())
         fileName = url.toLocalFile();
+    
     else
     {
         setError("Url is not a local file");

+ 1 - 1
lib/src/loader.h

@@ -63,7 +63,7 @@ public:
     int interval() const { return m_interval; }
     void setInterval(int interval, bool writeNewConfig = true);
     QString error() const { return m_error; }
-        
+    
     
 public slots:
 

+ 56 - 24
lib/src/pwmfan.cpp

@@ -51,7 +51,7 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index),
     m_minStart(255),
     m_minStop(255),
     m_zeroRpm(0),
-    m_testStatus(notTesting)
+    m_testStatus(NotStarted)
 {
     connect(this, SIGNAL(tempChanged()), parent, SLOT(updateConfig()));
     connect(this, SIGNAL(hasTempChanged()), parent, SLOT(updateConfig()));
@@ -152,7 +152,7 @@ void PwmFan::reset()
             qDebug() << "Can't open pwmModeFile " << pwmModeFile->fileName();
 }
 
-void PwmFan::setPwm(int pwm, bool write)
+bool PwmFan::setPwm(int pwm, bool write)
 {
     if (m_pwm != pwm)
     {
@@ -167,6 +167,12 @@ void PwmFan::setPwm(int pwm, bool write)
             {
                 KAuth::Action action("fancontrol.gui.helper.action");
                 action.setHelperId("fancontrol.gui.helper");
+                if (!action.isValid())
+                {
+                    qDebug() << "setPwm action is invalid";
+                    return false;
+                }
+                
                 QVariantMap map;
                 map["action"] = "write";
                 map["filename"] = qobject_cast<QFile *>(m_pwmStream->device())->fileName();
@@ -175,13 +181,17 @@ void PwmFan::setPwm(int pwm, bool write)
                 KAuth::ExecuteJob *reply = action.execute();
 
                 if (!reply->exec())
-                    qDebug() << reply->errorString() << reply->errorText();
+                {
+                    qDebug() << "setPwm error:" << reply->errorString() << reply->errorText();
+                    return false;
+                }
             }
         }
     }
+    return true;
 }
 
-void PwmFan::setPwmMode(int pwmMode, bool write)
+bool PwmFan::setPwmMode(int pwmMode, bool write)
 {
     if (m_pwmMode != pwmMode)
     {
@@ -192,10 +202,17 @@ void PwmFan::setPwmMode(int pwmMode, bool write)
         {
             if (m_modeStream->device()->isWritable())
                 *m_modeStream << pwmMode;
+
             else
             {
                 KAuth::Action action("fancontrol.gui.helper.action");
                 action.setHelperId("fancontrol.gui.helper");
+                if (!action.isValid())
+                {
+                    qDebug() << "setPwmMode action is invalid";
+                    return false;
+                }
+                
                 QVariantMap map;
                 map["action"] = "write";
                 map["filename"] = qobject_cast<QFile *>(m_modeStream->device())->fileName();
@@ -204,28 +221,41 @@ void PwmFan::setPwmMode(int pwmMode, bool write)
                 KAuth::ExecuteJob *reply = action.execute();
 
                 if (!reply->exec())
-                    qDebug() << reply->errorString() << reply->errorText();
+                {
+                    qDebug() << "setPwmMode error:" << reply->errorString() << reply->errorText();
+                    return false;
+                }
             }
         }
     }
+    return true;
 }
 
-void PwmFan::test()
+bool PwmFan::test()
 {
-    m_testStatus = findingStop1;
-    emit testingChanged();
-
-    setPwmMode(1);
-    setPwm(255);
-    QTimer::singleShot(500, this, SLOT(continueTest()));
-    qDebug() << "Start testing...";
+    if (setPwmMode(1) && setPwm(255))
+    {
+        m_testStatus = FindingStop1;
+        emit testingChanged();
+        
+        QTimer::singleShot(500, this, SLOT(continueTest()));
+        qDebug() << "Start testing...";
+    }
+    else
+    {
+        qDebug() << "Testing failed";
+        return false;
+    }
+    
+    return true;
 }
 
 void PwmFan::abortTest()
 {
-    disconnect(SLOT(continueTest()));
+    setPwm(255);
+    disconnect(0, 0, this, SLOT(continueTest()));
 
-    m_testStatus = notTesting;
+    m_testStatus = Cancelled;
     emit testingChanged();
 
     setPwm(255);
@@ -236,7 +266,7 @@ void PwmFan::continueTest()
     update();
     switch (m_testStatus)
     {
-    case findingStop1:
+    case FindingStop1:
         if (m_rpm > 0)
         {
             setPwm(qMin(m_pwm * 0.95, m_pwm - 5.0));
@@ -250,7 +280,7 @@ void PwmFan::continueTest()
             }
             else
             {
-                m_testStatus = findingStart;
+                m_testStatus = FindingStart;
                 m_zeroRpm = 0;
                 qDebug() << "Start finding start value...";
             }
@@ -258,19 +288,19 @@ void PwmFan::continueTest()
         QTimer::singleShot(500, this, SLOT(continueTest()));
         break;
 
-    case findingStart:
+    case FindingStart:
         if (m_rpm == 0)
             setPwm(m_pwm + 2);
         else
         {
-            m_testStatus = findingStop2;
+            m_testStatus = FindingStop2;
             setMinStart(m_pwm);
             qDebug() << "Start finding stop value...";
         }
         QTimer::singleShot(1000, this, SLOT(continueTest()));
         break;
 
-    case findingStop2:
+    case FindingStop2:
         if (m_rpm > 0)
         {
             setPwm(m_pwm - 1);
@@ -286,7 +316,7 @@ void PwmFan::continueTest()
             }
             else
             {
-                m_testStatus = notTesting;
+                m_testStatus = Finished;
                 emit testingChanged();
                 m_zeroRpm = 0;
                 setMinStop(m_pwm + 5);
@@ -295,14 +325,16 @@ void PwmFan::continueTest()
         }
         break;
 
-    case notTesting:
-        break;
-
     default:
         break;
     }
 }
 
+bool PwmFan::testing() const
+{
+    return m_testStatus == FindingStop1 || m_testStatus == FindingStop2 || m_testStatus == FindingStart;
+}
+
 bool PwmFan::active() const
 {
     KConfigGroup active = KSharedConfig::openConfig("fancontrol-gui")->group("active");

+ 13 - 8
lib/src/pwmfan.h

@@ -63,8 +63,8 @@ public:
     int minStop() const { return m_minStop; }
     int pwmMode() const { return m_pwmMode; }
     bool active() const;
-    bool testing() const { return m_testStatus != notTesting; }
-    void setPwm(int pwm, bool write = true);
+    bool testing() const;
+    bool setPwm(int pwm, bool write = true);
     void setTemp(Temp *temp) { setHasTemp(temp != Q_NULLPTR); if (temp != m_temp) { m_temp = temp; emit tempChanged(); } }
     void setHasTemp(bool hasTemp) { if (hasTemp != m_hasTemp) { m_hasTemp = hasTemp; emit hasTempChanged(); } }
     void setMinTemp(int minTemp) { if (minTemp != m_minTemp) { m_minTemp = minTemp; emit minTempChanged(); } }
@@ -73,10 +73,10 @@ public:
     void setMaxPwm(int maxPwm) { if (maxPwm != m_maxPwm) { m_maxPwm = maxPwm; emit maxPwmChanged(); } }
     void setMinStart(int minStart) { if (minStart != m_minStart) { m_minStart = minStart; emit minStartChanged(); } }
     void setMinStop(int minStop) { if (minStop != m_minStop) { m_minStop = minStop; emit minStopChanged(); } }
-    void setPwmMode(int pwmMode, bool write = true);
+    bool setPwmMode(int pwmMode, bool write = true);
     void setActive(bool active);
     void reset() Q_DECL_OVERRIDE;
-    Q_INVOKABLE void test();
+    Q_INVOKABLE bool test();
     Q_INVOKABLE void abortTest();
 
 
@@ -100,6 +100,8 @@ protected slots:
 
     void update();
     void continueTest();
+//     void handlePwmActionReply();
+//     void handlePwmModeActionReply();
 
 
 private:
@@ -120,10 +122,13 @@ private:
 
     enum
     {
-        findingStop1,
-        findingStop2,
-        findingStart,
-        notTesting
+        NotStarted,
+        FindingStop1,
+        FindingStop2,
+        FindingStart,
+        Finished,
+        Cancelled,
+        Error
     } m_testStatus;
 };
 #endif // PWMFAN_H

+ 2 - 1
lib/src/systemdcommunicator.cpp

@@ -20,12 +20,13 @@
 
 #include "systemdcommunicator.h"
 
-#include <KAuth/kauthexecutejob.h>
 #include <QtCore/QDebug>
 #include <QtCore/QVariant>
 #include <QtDBus/QDBusArgument>
 #include <QtDBus/QDBusInterface>
 
+#include <KAuth/KAuthExecuteJob>
+
 
 using namespace KAuth;
 

+ 5 - 1
package/contents/scripts/arrayfunctions.js

@@ -25,10 +25,14 @@ function names(array) {
     return names;
 }
 
+function nameWithPath(fan) {
+    return fan.name + "  (" + fan.path + ")";
+}
+
 function namesWithPaths(array) {
     var namesWithPaths = [];
     for (var i=0; i<array.length; i++) {
-        namesWithPaths[i] = array[i].name + "  (" + array[i].path + ")";
+        namesWithPaths[i] = nameWithPath(array[i]);
     }
     return namesWithPaths;
 }

+ 17 - 4
package/contents/ui/KCM.qml

@@ -84,8 +84,16 @@ Item {
                 renderType: Text.NativeRendering
             }
             ComboBox {
-                id: fanCombobox
-                model: ArrayFunctions.namesWithPaths(kcm.loader.allPwmFans)
+                id: fanComboBox
+                model: ListModel {
+                    property var fans: kcm.loader.allPwmFans
+                    id: fanList
+                    Component.onCompleted: {
+                        for (var i=0; i<fans.length; i++) {
+                            fanList.append({"text": ArrayFunctions.nameWithPath(fans[i])});
+                        }
+                    }
+                }
                 Layout.fillWidth: true
                 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
             }
@@ -100,14 +108,19 @@ Item {
         Loader {
             Layout.fillWidth: true
             Layout.fillHeight: true
-            active: !!kcm.loader.allPwmFans[fanCombobox.currentIndex]
+            active: !!kcm.loader.allPwmFans[fanComboBox.currentIndex]
             sourceComponent: PwmFan {
                 unit: kcm.base.unit
-                fan: kcm.loader.allPwmFans[fanCombobox.currentIndex]
+                fan: kcm.loader.allPwmFans[fanComboBox.currentIndex]
                 loader: kcm.loader
                 systemdCom: kcm.systemdCom
                 minTemp: kcm.base.minTemp
                 maxTemp: kcm.base.maxTemp
+                onNameChanged: {
+                    if (fanComboBox.currentText != ArrayFunctions.nameWithPath(fan)) {
+                        fanList.setProperty(fanComboBox.currentIndex, "text", ArrayFunctions.nameWithPath(fan));
+                    }
+                }
             }
         }
         

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

@@ -35,7 +35,8 @@ Rectangle {
     property int margin: 5
     property int minimizeDuration: 400
     property int unit: 0
-
+    readonly property alias name: nameField.text
+    
     id: root
     color: "transparent"
     border.color: palette.windowText
@@ -86,8 +87,8 @@ Rectangle {
         }
         visible: root.height >= height + margin*2
         text: fan.name
+        onTextChanged: fan.name = text
         color: palette.text
-        onTextChanged: fan.name = text;
         horizontalAlignment: TextEdit.AlignLeft
         wrapMode: TextEdit.Wrap
         font.bold: true
@@ -379,8 +380,10 @@ Rectangle {
                     } else {
                         reactivateAfterTesting = systemdCom.serviceActive;
                         systemdCom.serviceActive = false;
-                        minStartInput.value = Qt.binding(function() { return fan.minStart });
-                        fan.test();
+                        minStartInput.value = Qt.binding(function() { return Math.round(fan.minStart / 2.55) });
+                        if (!fan.test()) {
+                            systemdCom.serviceActive = reactivateAfterTesting;
+                        }
                     }
                 }
                 

+ 17 - 4
package/contents/ui/PwmFansTab.qml

@@ -41,8 +41,16 @@ ColumnLayout {
             renderType: Text.NativeRendering
         }
         ComboBox {
-            id: fanCombobox
-            model: ArrayFunctions.namesWithPaths(loader.allPwmFans)
+            id: fanComboBox
+            model: ListModel {
+                property var fans: loader.allPwmFans
+                id: fanList
+                Component.onCompleted: {
+                    for (var i=0; i<fans.length; i++) {
+                        fanList.append({"text": ArrayFunctions.nameWithPath(fans[i])});
+                    }
+                }
+            }
             Layout.fillWidth: true
             Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
         }
@@ -55,14 +63,19 @@ ColumnLayout {
     Loader {
         Layout.fillHeight: true
         Layout.fillWidth: true
-        active: !!baseObject.loader.allPwmFans[fanCombobox.currentIndex]
+        active: !!baseObject.loader.allPwmFans[fanComboBox.currentIndex]
         sourceComponent: PwmFan {
             unit: baseObject.unit
-            fan: loader.allPwmFans[fanCombobox.currentIndex]
+            fan: loader.allPwmFans[fanComboBox.currentIndex]
             loader: root.loader
             systemdCom: baseObject.systemdCom
             minTemp: baseObject.minTemp
             maxTemp: baseObject.maxTemp
+            onNameChanged: {
+                if (fanComboBox.currentText != ArrayFunctions.nameWithPath(fan)) {
+                    fanList.setProperty(fanComboBox.currentIndex, "text", ArrayFunctions.nameWithPath(fan));
+                }
+            }
         }
     }