Explorar el Código

More improvements to fan testing

Maldela hace 9 años
padre
commit
d341b1a4b7

+ 0 - 9
import/qml/FanItem.qml

@@ -452,26 +452,17 @@ Rectangle {
             Button {
                 id: testButton
 
-                property bool reactivateAfterTesting
-
                 text: !!fan ? fan.testing ? i18n("Abort test") : i18n("Test start and stop values") : ""
                 iconName: "dialog-password"
                 anchors.right: parent.right
                 onClicked: {
                     if (fan.testing) {
-                        systemdCom.serviceActive = reactivateAfterTesting;
                         fan.abortTest();
                     } else {
-                        reactivateAfterTesting = systemdCom.serviceActive;
-                        systemdCom.serviceActive = false;
                         minStartInput.value = Qt.binding(function() { return Math.round(fan.minStart / 2.55) });
                         fan.test();
                     }
                 }
-                Connections {
-                    target: fan
-                    onTestStatusChanged: if (fan.testStatus === Fancontrol.PwmFan.Finished && testButton.reactivateAfterTesting) systemdCom.serviceActive = true
-                }
             }
         }
     }

+ 4 - 0
import/src/guibase.cpp

@@ -46,6 +46,10 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
 {
     connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
 
+#ifndef NO_SYSTEMD
+    connect(m_loader, &Loader::requestSetServiceActive, m_com, &SystemdCommunicator::setServiceActive);
+#endif
+
     QLocale locale = QLocale::system();
     QLocale::MeasurementSystem system = locale.measurementSystem();
     m_unit = (system != QLocale::ImperialUSSystem) ? 0 : 2;

+ 18 - 0
import/src/hwmon.cpp

@@ -30,6 +30,7 @@ namespace Fancontrol
 {
 
 Hwmon::Hwmon(const QString &path, Loader *parent) : QObject(parent),
+    m_parent(parent),
     m_path(path),
     m_valid(true)
 {
@@ -90,6 +91,7 @@ void Hwmon::initialize()
                 {
                     newPwmFan = new PwmFan(this, index);
                     connect(this, &Hwmon::sensorsUpdateNeeded, newPwmFan, &PwmFan::update);
+                    connect(newPwmFan, &PwmFan::testStatusChanged, m_parent, &Loader::handleTestStatusChanged);
                     m_pwmFans << newPwmFan;
                     emit pwmFansChanged();
                 }
@@ -216,4 +218,20 @@ void Hwmon::setError(const QString &error)
     emit errorChanged(error);
 }
 
+bool Hwmon::testing() const
+{
+    bool testing = false;
+
+    foreach(const PwmFan *fan, m_pwmFans)
+    {
+        if (fan->testing())
+        {
+            testing = true;
+            break;
+        }
+    }
+
+    return testing;
+}
+
 }

+ 3 - 1
import/src/hwmon.h

@@ -32,7 +32,7 @@
 
 namespace Fancontrol
 {
-    
+
 class Loader;
 
 class Hwmon : public QObject
@@ -66,6 +66,7 @@ public:
     PwmFan * pwmFan(int i) const;
     Temp * temp(int i) const;
     bool isValid() const { return m_valid; }
+    bool testing() const;
 
 
 public slots:
@@ -87,6 +88,7 @@ signals:
 
 private:
 
+    Loader *m_parent;
     QString m_name;
     const QString m_path;
     bool m_valid;

+ 56 - 27
import/src/loader.cpp

@@ -45,6 +45,7 @@ namespace Fancontrol
 {
 
 Loader::Loader(QObject *parent) : QObject(parent),
+    m_reactivateAfterTesting(true),
     m_interval(10),
     m_configUrl(QUrl::fromLocalFile(QStringLiteral(STANDARD_CONFIG_FILE))),
     m_timer(new QTimer(this)),
@@ -267,7 +268,7 @@ bool Loader::load(const QUrl &url)
     else if (file.exists())
     {
         KAuth::Action action = newFancontrolAction();
-        
+
         if (action.isValid())
         {
             QVariantMap map;
@@ -282,7 +283,7 @@ bool Loader::load(const QUrl &url)
                     qDebug() << "Aborted by user";
                     return false;
                 }
-                
+
                 qDebug() << "Error while loading:" << reply->error();
                 setError(reply->errorString() + reply->errorText(), true);
                 return false;
@@ -354,7 +355,7 @@ bool Loader::load(const QUrl &url)
                 //Connect hwmons again
                 foreach (Hwmon *hwmon, m_hwmons)
                     connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
-                
+
                 setError(i18n("Unable to parse interval line: \n %1", line), true);
                 return false;
             }
@@ -402,7 +403,7 @@ bool Loader::load(const QUrl &url)
                         //Connect hwmons again
                         foreach (Hwmon *hwmon, m_hwmons)
                             connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
-                        
+
                         setError(i18n("Can not parse %1", devname), true);
                         return false;
                     }
@@ -412,7 +413,7 @@ bool Loader::load(const QUrl &url)
                         //Connect hwmons again
                         foreach (Hwmon *hwmon, m_hwmons)
                             connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
-                        
+
                         setError(i18n("Invalid config file!"), true);
                         return false;
                     }
@@ -455,7 +456,7 @@ bool Loader::load(const QUrl &url)
             //Connect hwmons again
             foreach (Hwmon *hwmon, m_hwmons)
                 connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
-            
+
             setError(i18n("Unrecognized line in config:\n%1", line), true);
             return false;
         }
@@ -466,7 +467,7 @@ bool Loader::load(const QUrl &url)
     //Connect hwmons again
     foreach (Hwmon *hwmon, m_hwmons)
         connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
-    
+
     emit configUrlChanged();
 
     return true;
@@ -499,7 +500,7 @@ bool Loader::save(const QUrl &url)
     else
     {
         KAuth::Action action = newFancontrolAction();
-        
+
         if (action.isValid())
         {
             QVariantMap map;
@@ -517,7 +518,7 @@ bool Loader::save(const QUrl &url)
                     qDebug() << "Aborted by user";
                     return false;
                 }
-                
+
                 qDebug() << "Error while saving:" << reply->error();
                 setError(reply->errorString() + reply->errorText(), true);
                 return false;
@@ -566,14 +567,14 @@ void Loader::createConfigFile()
             configFile += QStringLiteral("hwmon") + QString::number(hwmon->index()) + "=" + sanitizedPath + QChar(QChar::Space);
         }
         configFile += QChar(QChar::LineFeed);
-        
+
         configFile += QStringLiteral("DEVNAME=");
         foreach (Hwmon *hwmon, usedHwmons)
         {
             configFile += QStringLiteral("hwmon") + QString::number(hwmon->index()) + "=" + hwmon->name().split('.').first() + QChar(QChar::Space);
         }
         configFile += QChar(QChar::LineFeed);
-        
+
         if (!usedFans.isEmpty())
         {
             configFile += QStringLiteral("FCTEMPS=");
@@ -585,7 +586,7 @@ void Loader::createConfigFile()
                 configFile += QStringLiteral("temp") + QString::number(pwmFan->temp()->index()) + QStringLiteral("_input ");
             }
             configFile += QChar(QChar::LineFeed);
-            
+
             configFile += QStringLiteral("FCFANS=");
             foreach (PwmFan *pwmFan, usedFans)
             {
@@ -595,7 +596,7 @@ void Loader::createConfigFile()
                 configFile += QStringLiteral("fan") + QString::number(pwmFan->index()) + QStringLiteral("_input ");
             }
             configFile += QChar(QChar::LineFeed);
-            
+
             configFile += QStringLiteral("MINTEMP=");
             foreach (PwmFan *pwmFan, usedFans)
             {
@@ -604,7 +605,7 @@ void Loader::createConfigFile()
                 configFile += QString::number(pwmFan->minTemp()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
-            
+
             configFile += QStringLiteral("MAXTEMP=");
             foreach (PwmFan *pwmFan, usedFans)
             {
@@ -613,7 +614,7 @@ void Loader::createConfigFile()
                 configFile += QString::number(pwmFan->maxTemp()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
-            
+
             configFile += QStringLiteral("MINSTART=");
             foreach (PwmFan *pwmFan, usedFans)
             {
@@ -622,7 +623,7 @@ void Loader::createConfigFile()
                 configFile += QString::number(pwmFan->minStart()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
-            
+
             configFile += QStringLiteral("MINSTOP=");
             foreach (PwmFan *pwmFan, usedFans)
             {
@@ -691,10 +692,10 @@ void Loader::detectSensors()
 {
     QString program = QStringLiteral("sensors-detect");
     QStringList arguments = QStringList() << QStringLiteral("--auto");
-    
+
     QProcess *process = new QProcess(this);
     process->start(program, arguments);
-    
+
     connect(process, static_cast<void(QProcess::*)(int)>(&QProcess::finished),
             this, static_cast<void(Loader::*)(int)>(&Loader::handleDetectSensorsResult));
 }
@@ -702,22 +703,22 @@ void Loader::detectSensors()
 void Loader::handleDetectSensorsResult(int exitCode)
 {
     QProcess *process = qobject_cast<QProcess *>(sender());
-    
+
     if (exitCode)
     {
         if (process)
             setError(process->readAllStandardOutput());
-        
+
         KAuth::Action action = newFancontrolAction();
-        
+
         if (action.isValid())
         {
             QVariantMap map;
             map[QStringLiteral("action")] = QVariant("detectSensors");
-            
+
             action.setArguments(map);
             KAuth::ExecuteJob *job = action.execute();
-            
+
             connect(job, &KAuth::ExecuteJob::result, this, static_cast<void(Loader::*)(KJob *)>(&Loader::handleDetectSensorsResult));
             job->start();
         }
@@ -731,10 +732,10 @@ void Loader::handleDetectSensorsResult(int exitCode)
             m_sensorsDetected = true;
             emit sensorsDetectedChanged();
         }
-        
+
         parseHwmons();
     }
-    
+
     if (process)
         process->deleteLater();
 }
@@ -748,7 +749,7 @@ void Loader::handleDetectSensorsResult(KJob *job)
             qDebug() << "Aborted by user";
             return;
         }
-            
+
         qDebug() << "Error while detecting sensors:" << job->error();
         setError(job->errorString() + job->errorText(), true);
     }
@@ -759,7 +760,7 @@ void Loader::handleDetectSensorsResult(KJob *job)
             m_sensorsDetected = true;
             emit sensorsDetectedChanged();
         }
-        
+
         parseHwmons();
     }
 }
@@ -798,4 +799,32 @@ void Loader::setError (const QString &error, bool critical)
         qWarning() << error;
 }
 
+void Loader::handleTestStatusChanged()
+{
+    bool testing = false;
+
+    foreach (const Hwmon *hwmon, m_hwmons)
+    {
+        if (hwmon->testing() == true)
+        {
+            testing = true;
+            break;
+        }
+    }
+
+    if (!testing && !m_reactivateAfterTesting)
+        return;
+
+    emit requestSetServiceActive(!testing);
+}
+
+void Loader::setRestartServiceAfterTesting(bool restart)
+{
+    if (m_reactivateAfterTesting == restart)
+        return;
+
+    m_reactivateAfterTesting = restart;
+    emit restartServiceAfterTestingChanged();
+}
+
 }

+ 8 - 1
import/src/loader.h

@@ -49,6 +49,7 @@ class Loader : public QObject
     Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
     Q_PROPERTY(QString error READ error NOTIFY errorChanged)
     Q_PROPERTY(bool sensorsDetected READ sensorsDetected NOTIFY sensorsDetectedChanged)
+    Q_PROPERTY(bool restartServiceAfterTesting READ restartServiceAfterTesting WRITE setRestartServiceAfterTesting NOTIFY restartServiceAfterTestingChanged)
 
 
 public:
@@ -65,6 +66,8 @@ public:
     QString configFile() const { return m_configFile; }
     QList<Hwmon *> hwmons() const { return m_hwmons; }
     bool sensorsDetected() const { return m_sensorsDetected; }
+    bool restartServiceAfterTesting() const { return m_reactivateAfterTesting; }
+    void setRestartServiceAfterTesting(bool restart);
     QList<QObject *> hwmonsAsObjects() const;
     QList<QObject *> allTemps() const;
     int interval() const { return m_interval; }
@@ -83,7 +86,8 @@ public slots:
     void setError(const QString &error, bool critical = false);
     void handleDetectSensorsResult(KJob *job);
     void handleDetectSensorsResult(int exitCode);
-    
+    void handleTestStatusChanged();
+
 
 protected:
 
@@ -95,6 +99,7 @@ private:
     PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
     Temp *getTemp(const QPair<int, int> &indexPair) const;
 
+    bool m_reactivateAfterTesting;
     int m_interval;
     QList<Hwmon *> m_hwmons;
     QUrl m_configUrl;
@@ -117,6 +122,8 @@ signals:
     void invalidConfigUrl();
     void criticalError();
     void sensorsDetectedChanged();
+    void restartServiceAfterTestingChanged();
+    void requestSetServiceActive(bool);
 };
 
 }

+ 23 - 30
import/src/pwmfan.cpp

@@ -120,18 +120,18 @@ void PwmFan::update()
 void PwmFan::reset()
 {
     Fan::reset();
-    
+
     setHasTemp(false);
     setTemp(Q_NULLPTR);
-    
+
     QIODevice *oldFile = m_pwmStream->device();
     delete m_pwmStream;
     delete oldFile;
-    
+
     oldFile = m_modeStream->device();
     delete m_modeStream;
     delete oldFile;
-    
+
     QFile *pwmFile = new QFile(m_parent->path() + "/pwm" + QString::number(m_index), this);
         if (pwmFile->open(QFile::ReadWrite))
         {
@@ -171,13 +171,13 @@ bool PwmFan::setPwm(int pwm, bool write)
         if (write)
         {
             setPwmMode(1);
-            
+
             if (m_pwmStream->device()->isWritable())
                 *m_pwmStream << pwm;
             else
             {
                 KAuth::Action action = newFancontrolAction();
-                
+
                 if (action.isValid())
                 {
                     QVariantMap map;
@@ -185,17 +185,17 @@ bool PwmFan::setPwm(int pwm, bool write)
                     map[QStringLiteral("filename")] = qobject_cast<QFile *>(m_pwmStream->device())->fileName();
                     map[QStringLiteral("content")] = QString::number(pwm);
                     action.setArguments(map);
-                    
+
                     KAuth::ExecuteJob *job = action.execute();
                     if (!job->exec())
                     {
                         if (job->error() == KAuth::ActionReply::HelperBusyError)
                         {
                             qDebug() << "Helper busy...";
-                            
+
                             QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
                         }
-                        
+
                         emit errorChanged(i18n("Could not set pwm: ") + job->errorText());
                     }
                     update();
@@ -223,7 +223,7 @@ bool PwmFan::setPwmMode(int pwmMode, bool write)
             else
             {
                 KAuth::Action action = newFancontrolAction();
-                
+
                 if (action.isValid())
                 {
                     QVariantMap map;
@@ -238,10 +238,10 @@ bool PwmFan::setPwmMode(int pwmMode, bool write)
                         if (job->error() == KAuth::ActionReply::HelperBusyError)
                         {
                             qDebug() << "Helper busy...";
-                            
+
                             QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
                         }
-                        
+
                         emit errorChanged(i18n("Could not set pwm mode: ") + job->errorText());
                     }
                     update();
@@ -259,21 +259,13 @@ void PwmFan::test()
     if (!m_modeStream->device()->isWritable() || !m_pwmStream->device()->isWritable())
     {
         KAuth::Action action = newFancontrolAction();
-        
+
         if (action.isValid())
         {
-            KAuth::ExecuteJob *job = action.execute();
+            KAuth::ExecuteJob *job = action.execute(KAuth::Action::AuthorizeOnlyMode);
 
             if (!job->exec())
             {
-                if (job->error() == KAuth::ActionReply::HelperBusyError)
-                {
-                    qDebug() << "Helper busy...";
-                    
-                    QTimer::singleShot(100, this, &PwmFan::test);
-                    return;
-                }
-                
                 emit errorChanged(i18n("Authorization error: ") + job->errorText());
                 m_testStatus = Error;
                 emit testStatusChanged();
@@ -286,12 +278,12 @@ void PwmFan::test()
             return;
         }
     }
-    
+
     setPwm(255);
-    
+
     m_testStatus = FindingStop1;
     emit testStatusChanged();
-    
+
     QTimer::singleShot(500, this, &PwmFan::continueTest);
     qDebug() << "Start testing...";
 }
@@ -301,7 +293,7 @@ void PwmFan::abortTest()
     if (m_testStatus >= FindingStop1 && m_testStatus <= FindingStart)
     {
         qDebug() << "Abort testing";
-        
+
         m_testStatus = Cancelled;
         emit testStatusChanged();
 
@@ -314,7 +306,7 @@ void PwmFan::continueTest()
     if (!m_modeStream->device()->isWritable() || !m_pwmStream->device()->isWritable())
     {
         KAuth::Action action = newFancontrolAction();
-        
+
         if (action.status() != KAuth::Action::AuthorizedStatus)
         {
             m_testStatus = Error;
@@ -322,9 +314,9 @@ void PwmFan::continueTest()
             return;
         }
     }
-    
+
     update();
-    
+
     switch (m_testStatus)
     {
     case FindingStop1:
@@ -381,7 +373,8 @@ void PwmFan::continueTest()
                 emit testStatusChanged();
                 m_zeroRpm = 0;
                 setMinStop(m_pwm + 5);
-                qDebug() << "Finished testing!";
+                setPwm(255);
+                qDebug() << "Finished testing PwmFan" << m_index;
             }
         }
         break;

+ 2 - 2
import/src/pwmfan.h

@@ -54,7 +54,7 @@ class PwmFan : public Fan
     Q_ENUMS(TestStatus)
 
 public:
-    
+
     enum TestStatus
     {
         NotStarted,
@@ -110,7 +110,7 @@ signals:
     void minStartChanged();
     void minStopChanged();
     void activeChanged();
-    void testStatusChanged();
+    void testStatusChanged(bool = false);
     void pwmModeChanged();
 
 

+ 4 - 1
kcm/package/contents/ui/KCM.qml

@@ -100,7 +100,10 @@ Item {
         visible: pwmFans.length > 0
         text: i18n("Control fans manually")
         checked: systemdCom.serviceEnabled && systemdCom.serviceActive;
-        onCheckedChanged: if (checked !== systemdCom.serviceActive || checked !== systemdCom.serviceEnabled) kcm.needsSave = true
+        onCheckedChanged: if (checked !== systemdCom.serviceActive || checked !== systemdCom.serviceEnabled) {
+            kcm.needsSave = true;
+            loader.restartServiceAfterTesting = checked;
+        }
     }
 
     ColumnLayout {