Browse Source

abort testing of all fans when manually starting fancontrol service

Malte Veerman 9 years ago
parent
commit
1b04159c06

+ 10 - 2
lib/src/hwmon.cpp

@@ -181,9 +181,17 @@ QList<QObject *> Hwmon::temps() const
 
 void Hwmon::testFans()
 {
-    for (int i=0; i<m_pwmFans.size(); i++)
+    foreach (PwmFan *const fan, m_pwmFans)
     {
-        m_pwmFans.at(i)->test();
+        fan->test();
+    }
+}
+
+void Hwmon::abortTestingFans()
+{
+    foreach (PwmFan *const fan, m_pwmFans)
+    {
+        fan->abortTest();
     }
 }
 

+ 1 - 0
lib/src/hwmon.h

@@ -56,6 +56,7 @@ public:
     QList<QObject *> pwmFans() const;
     QList<QObject *> temps() const;
     Q_INVOKABLE void testFans();
+    Q_INVOKABLE void abortTestingFans();
     Fan * fan(int i) const;
     PwmFan * pwmFan(int i) const;
     Temp * temp(int i) const;

+ 9 - 1
lib/src/loader.cpp

@@ -446,7 +446,7 @@ void Loader::createConfigFile()
         foreach (QObject *fan, hwmon->pwmFans())
         {
             PwmFan *pwmFan = qobject_cast<PwmFan *>(fan);
-            if (pwmFan->hasTemp() && pwmFan->temp())
+            if (pwmFan->hasTemp() && pwmFan->temp() && !pwmFan->testing())
             {
                 usedFans << pwmFan;
                 if (!usedHwmons.contains(pwmFan->temp()->parent()))
@@ -584,6 +584,14 @@ void Loader::testFans()
     }
 }
 
+void Loader::abortTestingFans()
+{
+    for (int i=0; i<m_hwmons.size(); i++)
+    {
+        m_hwmons.at(i)->abortTestingFans();
+    }
+}
+
 void Loader::detectSensors()
 {
     KAuth::Action action("fancontrol.gui.helper.action");

+ 1 - 0
lib/src/loader.h

@@ -60,6 +60,7 @@ public:
     Q_INVOKABLE bool load(const QUrl & = QUrl());
     Q_INVOKABLE bool save(const QUrl & = QUrl());
     Q_INVOKABLE void testFans();
+    Q_INVOKABLE void abortTestingFans();
     Q_INVOKABLE void detectSensors();
     QUrl configUrl() const { return m_configUrl; }
     QString configFile() const { return m_configFile; }

+ 3 - 4
lib/src/pwmfan.cpp

@@ -65,6 +65,7 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index),
     connect(this, SIGNAL(maxPwmChanged()), parent, SLOT(updateConfig()));
     connect(this, SIGNAL(minStartChanged()), parent, SLOT(updateConfig()));
     connect(this, SIGNAL(minStopChanged()), parent, SLOT(updateConfig()));
+    connect(this, SIGNAL(testingChanged()), parent, SLOT(updateConfig()));
 
     if (QDir(parent->path()).isReadable())
     {
@@ -265,20 +266,18 @@ void PwmFan::handleSetPwmModeResult(KJob *job)
     update();
 }
 
-bool PwmFan::test()
+void PwmFan::test()
 {
     KAuth::Action action("fancontrol.gui.helper.action");
     action.setHelperId("fancontrol.gui.helper");
     if (!action.isValid())
     {
         emit errorChanged("Test action is invalid");
-        return false;
+        return;
     }
     KAuth::ExecuteJob *job = action.execute();
     connect(job, SIGNAL(result(KJob*)), this, SLOT(handleTestAuthReply(KJob*)));
     job->start();
-    
-    return true;
 }
 
 void PwmFan::handleTestAuthReply(KJob *job)

+ 1 - 1
lib/src/pwmfan.h

@@ -80,7 +80,7 @@ public:
     bool setPwmMode(int pwmMode, bool write = true);
     void setActive(bool active);
     void reset() Q_DECL_OVERRIDE;
-    Q_INVOKABLE bool test();
+    Q_INVOKABLE void test();
     Q_INVOKABLE void abortTest();
 
 

+ 1 - 0
lib/src/systemdcommunicator.cpp

@@ -212,6 +212,7 @@ bool SystemdCommunicator::setServiceEnabled(bool enabled)
 bool SystemdCommunicator::setServiceActive(bool active)
 {
     qDebug() << "Set service active:" << active;
+       
     if (serviceExists())
     {
         if (active != serviceActive())

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

@@ -57,7 +57,10 @@ ApplicationWindow {
                 active: base.hasSystemdCommunicator()
                 sourceComponent: ToolButton {
                     iconName: base.systemdCom.serviceActive ? "system-reboot" : "system-run"
-                    onClicked: base.systemdCom.serviceActive ? base.systemdCom.restartService() : base.systemdCom.serviceActive = true;
+                    onClicked: {
+                        base.loader.abortTestingFans();
+                        base.systemdCom.serviceActive ? base.systemdCom.restartService() : base.systemdCom.serviceActive = true;
+                    }
                     tooltip: base.systemdCom.serviceActive ? i18n("Restart fancontrol") : i18n("Start fancontrol")
                 }
             }