瀏覽代碼

Overhaul of fan speed testing. Reverting back to synchronous calls. Implementing functionality to run as root without KHelper.

Malte Veerman 9 年之前
父節點
當前提交
dea39e3957

+ 1 - 3
CMakeLists.txt

@@ -43,7 +43,7 @@ find_package(Qt5Core REQUIRED)
 
 
 #Find KF5
-find_package(KF5 COMPONENTS I18n Package REQUIRED)
+find_package(KF5 COMPONENTS I18n REQUIRED)
 
 
 #includes
@@ -59,8 +59,6 @@ include_directories (${CMAKE_SOURCE_DIR})
 if(NOT NO_SYSTEMD)
 
     message(STATUS "Compiling for Systemd")
-    find_package(Qt5DBus REQUIRED)
-    include_directories(${Qt5DBus_INCLUDE_DIRS})
 
 else(NOT NO_SYSTEMD)
 

+ 5 - 3
fancontrol-gui/CMakeLists.txt

@@ -1,14 +1,16 @@
 set(Fancontrol_GUI_SRCS src/main.cpp
                         src/windowconfig.cpp)
 
-set(LIBRARIES Qt5::Widgets
+set(LIBRARIES Qt5::Gui
+              Qt5::Widgets
+              KF5::CoreAddons
               KF5::Declarative
               KF5::I18n
               KF5::ConfigGui
               KF5::ConfigCore)
 
-find_package(Qt5 COMPONENTS Widgets REQUIRED)
-find_package(KF5 COMPONENTS Declarative Config REQUIRED)
+find_package(Qt5 COMPONENTS Gui Widgets REQUIRED)
+find_package(KF5 COMPONENTS CoreAddons Package Declarative Config REQUIRED)
 
 include_directories(${Qt5Widgets_INCLUDE_DIRS})
 add_definitions(${Qt5Widgets_DEFINITIONS})

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

@@ -94,7 +94,7 @@ ColumnLayout {
 
     Action {
         id: detectFansAction
-        text: i18n("Detect fans")
+        text: loader.sensorsDetected ? i18n("Detect fans again") : i18n("Detect fans")
         iconName: "dialog-password"
         onTriggered: loader.detectSensors()
     }

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

@@ -25,7 +25,6 @@
 
 #include <KDeclarative/QmlObject>
 #include <KI18n/KLocalizedString>
-#include <KPackage/PackageLoader>
 #include <KCoreAddons/KAboutData>
 
 #include "windowconfig.h"
@@ -58,8 +57,7 @@ int main(int argc, char *argv[])
     about.processCommandLine(&parser);
 
     KDeclarative::QmlObject qmlObject;
-    WindowConfig *windowConfig = WindowConfig::instance();
-    qmlObject.rootContext()->setContextProperty(QStringLiteral("windowConfig"), windowConfig);
+    qmlObject.rootContext()->setContextProperty(QStringLiteral("windowConfig"), WindowConfig::instance());
 
     qmlObject.loadPackage("fancontrol-gui");
     

+ 5 - 1
helper/CMakeLists.txt

@@ -1,10 +1,14 @@
-set(LIBRARIES KF5::Auth
+set(LIBRARIES Qt5::Core
+              KF5::Auth
               KF5::I18n)
 
 if(NOT NO_SYSTEMD)
 
     set(LIBRARIES ${LIBRARIES}
                   Qt5::DBus)
+                  
+    find_package(Qt5DBus REQUIRED)
+    include_directories(${Qt5DBus_INCLUDE_DIRS})
 
 endif(NOT NO_SYSTEMD)
 

+ 3 - 0
import/CMakeLists.txt

@@ -34,6 +34,9 @@ if(NOT NO_SYSTEMD)
 
     set(LIB_PRIVATE_LIBRARIES ${LIB_PRIVATE_LIBRARIES}
                               Qt5::DBus)
+                              
+    find_package(Qt5DBus REQUIRED)
+    include_directories(${Qt5DBus_INCLUDE_DIRS})
 
 endif(NOT NO_SYSTEMD)
 

+ 4 - 0
import/src/fan.cpp

@@ -62,8 +62,10 @@ QString Fan::name() const
     KConfigGroup names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
     KConfigGroup localNames = names.group(m_parent->name());
     QString name = localNames.readEntry("fan" + QString::number(m_index), QString());
+    
     if (name.isEmpty())
         return "fan" + QString::number(m_index);
+    
     return name;
 }
 
@@ -71,6 +73,7 @@ void Fan::setName(const QString &name)
 {
     KConfigGroup names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
     KConfigGroup localNames = names.group(m_parent->name());
+    
     if (name != localNames.readEntry("fan" + QString::number(m_index), QString())
         && !name.isEmpty())
     {
@@ -104,6 +107,7 @@ void Fan::update()
     m_rpmStream->seek(0);
     int rpm;
     *m_rpmStream >> rpm;
+    
     if (rpm != m_rpm)
     {
         m_rpm = rpm;

+ 10 - 8
import/src/hwmon.cpp

@@ -20,6 +20,8 @@
 
 #include "hwmon.h"
 
+#include "loader.h"
+
 #include <QtCore/QDir>
 #include <QtCore/QTextStream>
 
@@ -27,7 +29,7 @@
 namespace Fancontrol
 {
 
-Hwmon::Hwmon(const QString &path, QObject *parent) : QObject(parent),
+Hwmon::Hwmon(const QString &path, Loader *parent) : QObject(parent),
     m_path(path),
     m_valid(true)
 {
@@ -52,10 +54,10 @@ Hwmon::Hwmon(const QString &path, QObject *parent) : QObject(parent),
     else
         m_name = path.split('/').last();
 
-    connect(this, SIGNAL(configUpdateNeeded()), parent, SLOT(createConfigFile()));
-    connect(this, SIGNAL(pwmFansChanged()), parent, SLOT(emitAllPwmFansChanged()));
-    connect(this, SIGNAL(tempsChanged()), parent, SLOT(emitAllTempsChanged()));
-    connect(this, SIGNAL(errorChanged(QString)), parent, SLOT(setError(QString)));
+    connect(this, &Hwmon::configUpdateNeeded, parent, &Loader::createConfigFile);
+    connect(this, &Hwmon::pwmFansChanged, parent, &Loader::emitAllPwmFansChanged);
+    connect(this, &Hwmon::tempsChanged, parent, &Loader::emitAllTempsChanged);
+    connect(this, &Hwmon::errorChanged, parent, &Loader::setError);
 
     if (m_valid)
         initialize();
@@ -87,7 +89,7 @@ void Hwmon::initialize()
                 if (!newPwmFan)
                 {
                     newPwmFan = new PwmFan(this, index);
-                    connect(this, SIGNAL(sensorsUpdateNeeded()), newPwmFan, SLOT(update()));
+                    connect(this, &Hwmon::sensorsUpdateNeeded, newPwmFan, &PwmFan::update);
                     m_pwmFans << newPwmFan;
                     emit pwmFansChanged();
                 }
@@ -116,7 +118,7 @@ void Hwmon::initialize()
                 if (!newFan)
                 {
                     newFan = new Fan(this, index);
-                    connect(this, SIGNAL(sensorsUpdateNeeded()), newFan, SLOT(update()));
+                    connect(this, &Hwmon::sensorsUpdateNeeded, newFan, &Fan::update);
                     m_fans << newFan;
                     emit fansChanged();
                 }
@@ -140,7 +142,7 @@ void Hwmon::initialize()
             if (!newTemp)
             {
                 newTemp = new Temp(this, index);
-                connect(this, SIGNAL(sensorsUpdateNeeded()), newTemp, SLOT(update()));
+                connect(this, &Hwmon::sensorsUpdateNeeded, newTemp, &Temp::update);
                 m_temps << newTemp;
                 emit tempsChanged();
             }

+ 4 - 6
import/src/hwmon.h

@@ -32,6 +32,8 @@
 
 namespace Fancontrol
 {
+    
+class Loader;
 
 class Hwmon : public QObject
 {
@@ -46,7 +48,7 @@ class Hwmon : public QObject
 
 public:
 
-    explicit Hwmon(const QString &path, QObject *parent = Q_NULLPTR);
+    explicit Hwmon(const QString &path, Loader *parent = Q_NULLPTR);
 
     void initialize();
     QString name() const { return m_name; }
@@ -70,10 +72,6 @@ public slots:
 
     void updateConfig() { emit configUpdateNeeded(); }
     void updateSensors() { emit sensorsUpdateNeeded(); }
-
-
-protected slots:
-
     void setError(const QString &error);
 
 
@@ -84,7 +82,7 @@ signals:
     void tempsChanged();
     void configUpdateNeeded();
     void sensorsUpdateNeeded();
-    void errorChanged(QString);
+    void errorChanged(QString, bool = false);
 
 
 private:

+ 65 - 22
import/src/loader.cpp

@@ -27,6 +27,7 @@
 #include <QtCore/QDir>
 #include <QtCore/QTextStream>
 #include <QtCore/QTimer>
+#include <QtCore/QProcess>
 #include <QtCore/QDebug>
 
 #include <KAuth/KAuthExecuteJob>
@@ -46,14 +47,15 @@ namespace Fancontrol
 Loader::Loader(QObject *parent) : QObject(parent),
     m_interval(10),
     m_configUrl(QUrl::fromLocalFile(QStringLiteral(STANDARD_CONFIG_FILE))),
-    m_timer(new QTimer(this))
+    m_timer(new QTimer(this)),
+    m_sensorsDetected(false)
 {
     parseHwmons();
 
     m_timer->setSingleShot(false);
     m_timer->start(1);
 
-    connect(m_timer, SIGNAL(timeout()), this, SLOT(updateSensors()));
+    connect(m_timer, &QTimer::timeout, this, &Loader::updateSensors);
 }
 
 void Loader::parseHwmons()
@@ -108,7 +110,7 @@ void Loader::parseHwmons()
             Hwmon *newHwmon = new Hwmon(hwmonPath, this);
             if (newHwmon->isValid())
             {
-                connect(this, SIGNAL(sensorsUpdateNeeded()), newHwmon, SLOT(updateSensors()));
+                connect(this, &Loader::sensorsUpdateNeeded, newHwmon, &Hwmon::updateSensors);
                 m_hwmons << newHwmon;
                 emit hwmonsChanged();
             }
@@ -308,7 +310,7 @@ bool Loader::load(const QUrl &url)
     //They get reconnected later
     foreach (Hwmon *hwmon, m_hwmons)
     {
-        disconnect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
+        disconnect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
         foreach (QObject *pwmFan, hwmon->pwmFans())
         {
             qobject_cast<PwmFan *>(pwmFan)->reset();
@@ -345,8 +347,8 @@ bool Loader::load(const QUrl &url)
             {
                 //Connect hwmons again
                 foreach (Hwmon *hwmon, m_hwmons)
-                    connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-
+                    connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                
                 setError(i18n("Unable to parse interval line: \n %1", line), true);
                 return false;
             }
@@ -393,8 +395,8 @@ bool Loader::load(const QUrl &url)
                     {
                         //Connect hwmons again
                         foreach (Hwmon *hwmon, m_hwmons)
-                            connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-
+                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                        
                         setError(i18n("Can not parse %1", devname), true);
                         return false;
                     }
@@ -403,8 +405,8 @@ bool Loader::load(const QUrl &url)
                     {
                         //Connect hwmons again
                         foreach (Hwmon *hwmon, m_hwmons)
-                            connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-
+                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                        
                         setError(i18n("Invalid config file!"), true);
                         return false;
                     }
@@ -446,8 +448,8 @@ bool Loader::load(const QUrl &url)
         {
             //Connect hwmons again
             foreach (Hwmon *hwmon, m_hwmons)
-                connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-
+                connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+            
             setError(i18n("Unrecognized line in config:\n%1", line), true);
             return false;
         }
@@ -457,8 +459,8 @@ bool Loader::load(const QUrl &url)
 
     //Connect hwmons again
     foreach (Hwmon *hwmon, m_hwmons)
-        connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-
+        connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+    
     emit configUrlChanged();
 
     return true;
@@ -675,15 +677,48 @@ void Loader::abortTestingFans()
 
 void Loader::detectSensors()
 {
-    KAuth::Action action = newFancontrolAction();
-    QVariantMap map;
-    map[QStringLiteral("action")] = QVariant("detectSensors");
-
-    action.setArguments(map);
-    KAuth::ExecuteJob *job = action.execute();
+    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));
+}
 
-    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleDetectSensorsResult(KJob*)));
-    job->start();
+void Loader::handleDetectSensorsResult(int exitCode)
+{
+    QProcess *process = qobject_cast<QProcess *>(sender());
+    
+    if (exitCode)
+    {
+        if (process)
+            setError(process->readAllStandardOutput());
+        
+        KAuth::Action action = newFancontrolAction();
+        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();
+    }
+    else
+    {
+        if (!m_sensorsDetected)
+        {
+            m_sensorsDetected = true;
+            emit sensorsDetectedChanged();
+        }
+        
+        parseHwmons();
+    }
+    
+    if (process)
+        process->deleteLater();
 }
 
 void Loader::handleDetectSensorsResult(KJob *job)
@@ -700,7 +735,15 @@ void Loader::handleDetectSensorsResult(KJob *job)
         setError(job->errorString() + job->errorText(), true);
     }
     else
+    {
+        if (!m_sensorsDetected)
+        {
+            m_sensorsDetected = true;
+            emit sensorsDetectedChanged();
+        }
+        
         parseHwmons();
+    }
 }
 
 QList<QObject *> Loader::hwmonsAsObjects() const

+ 7 - 5
import/src/loader.h

@@ -30,6 +30,7 @@
 
 class QTimer;
 class KJob;
+class QProcess;
 
 namespace Fancontrol
 {
@@ -47,6 +48,7 @@ class Loader : public QObject
     Q_PROPERTY(QList<QObject *> allTemps READ allTemps NOTIFY allTempsChanged)
     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)
 
 
 public:
@@ -62,6 +64,7 @@ public:
     QUrl configUrl() const { return m_configUrl; }
     QString configFile() const { return m_configFile; }
     QList<Hwmon *> hwmons() const { return m_hwmons; }
+    bool sensorsDetected() const { return m_sensorsDetected; }
     QList<QObject *> hwmonsAsObjects() const;
     QList<QObject *> allTemps() const;
     int interval() const { return m_interval; }
@@ -74,16 +77,13 @@ public:
 public slots:
 
     void updateSensors() { emit sensorsUpdateNeeded(); }
-
-
-protected slots:
-
     void createConfigFile();
     void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
     void emitAllTempsChanged() { emit allTempsChanged(); }
     void setError(const QString &error, bool critical = false);
     void handleDetectSensorsResult(KJob *job);
-
+    void handleDetectSensorsResult(int exitCode);
+    
 
 protected:
 
@@ -101,6 +101,7 @@ private:
     QString m_configFile;
     QString m_error;
     QTimer *m_timer;
+    bool m_sensorsDetected;
 
 
 signals:
@@ -115,6 +116,7 @@ signals:
     void allTempsChanged();
     void invalidConfigUrl();
     void criticalError();
+    void sensorsDetectedChanged();
 };
 
 }

+ 69 - 83
import/src/pwmfan.cpp

@@ -58,15 +58,15 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index),
     m_zeroRpm(0),
     m_testStatus(NotStarted)
 {
-    connect(this, SIGNAL(tempChanged()), parent, SLOT(updateConfig()));
-    connect(this, SIGNAL(hasTempChanged()), parent, SLOT(updateConfig()));
-    connect(this, SIGNAL(minTempChanged()), parent, SLOT(updateConfig()));
-    connect(this, SIGNAL(maxTempChanged()), parent, SLOT(updateConfig()));
-    connect(this, SIGNAL(minPwmChanged()), parent, SLOT(updateConfig()));
-    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()));
+    connect(this, &PwmFan::tempChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::hasTempChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::minTempChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::maxTempChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::minPwmChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::maxPwmChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::minStartChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::minStopChanged, parent, &Hwmon::updateConfig);
+    connect(this, &PwmFan::testStatusChanged, parent, &Hwmon::updateConfig);
 
     if (QDir(parent->path()).isReadable())
     {
@@ -182,33 +182,26 @@ 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();
-                connect(job, SIGNAL(result(KJob*)), this, SLOT(handleSetPwmResult(KJob*)));
-                job->start();
+                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();
             }
         }
     }
     return true;
 }
 
-void PwmFan::handleSetPwmResult(KJob *job)
-{
-    if (job->error())
-    {
-        if (job->error() == KAuth::ActionReply::HelperBusyError)
-        {
-            qDebug() << "Helper busy...";
-            
-            QTimer::singleShot(50, this, [this] (){ setPwm(m_pwm); });
-            return;
-        }
-        
-        emit errorChanged(i18n("Could not set pwm: ") + job->errorText());
-        return;
-    }
-    update();
-}
-
 bool PwmFan::setPwmMode(int pwmMode, bool write)
 {
     if (m_pwmMode != pwmMode)
@@ -230,65 +223,56 @@ bool PwmFan::setPwmMode(int pwmMode, bool write)
                 map[QStringLiteral("filename")] = qobject_cast<QFile *>(m_modeStream->device())->fileName();
                 map[QStringLiteral("content")] = QString::number(pwmMode);
                 action.setArguments(map);
+
                 KAuth::ExecuteJob *job = action.execute();
-                connect(job, SIGNAL(result(KJob*)), this, SLOT(handleSetPwmModeResult(KJob*)));
-                job->start();
+                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 mode: ") + job->errorText());
+                }
+                update();
             }
         }
     }
     return true;
 }
 
-void PwmFan::handleSetPwmModeResult(KJob *job)
-{
-    if (job->error())
-    {
-        if (job->error() == KAuth::ActionReply::HelperBusyError)
-        {
-            qDebug() << "Helper busy...";
-            
-            QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
-            return;
-        }
-        
-        emit errorChanged(i18n("Could not set pwm mode: ") + job->errorText());
-        return;
-    }
-    update();
-}
-
 void PwmFan::test()
 {
-    KAuth::Action action = newFancontrolAction();
-    KAuth::ExecuteJob *job = action.execute();
-    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleTestAuthReply(KJob*)));
-    job->start();
-}
-
-void PwmFan::handleTestAuthReply(KJob *job)
-{  
-    if (job->error())
+    if (!m_modeStream->device()->isWritable() || !m_pwmStream->device()->isWritable())
     {
-        if (job->error() == KAuth::ActionReply::HelperBusyError)
+        KAuth::Action action = newFancontrolAction();
+        KAuth::ExecuteJob *job = action.execute();
+
+        if (!job->exec())
         {
-            qDebug() << "Helper busy...";
+            if (job->error() == KAuth::ActionReply::HelperBusyError)
+            {
+                qDebug() << "Helper busy...";
+                
+                QTimer::singleShot(100, this, &PwmFan::test);
+                return;
+            }
             
-            QTimer::singleShot(100, this, &PwmFan::test);
+            emit errorChanged(i18n("Authorization error: ") + job->errorText());
+            m_testStatus = Error;
+            emit testStatusChanged();
             return;
         }
-        
-        emit errorChanged(i18n("Authorization error: ") + job->errorText());
-        m_testStatus = Error;
-        emit testingChanged();
-        return;
     }
     
     setPwm(255);
     
     m_testStatus = FindingStop1;
-    emit testingChanged();
+    emit testStatusChanged();
     
-    QTimer::singleShot(500, this, SLOT(continueTest()));
+    QTimer::singleShot(500, this, &PwmFan::continueTest);
     qDebug() << "Start testing...";
 }
 
@@ -298,10 +282,8 @@ void PwmFan::abortTest()
     {
         qDebug() << "Abort testing";
         
-        disconnect(this, 0, this, SLOT(continueTest()));
-
         m_testStatus = Cancelled;
-        emit testingChanged();
+        emit testStatusChanged();
 
         setPwm(255);
     }
@@ -309,16 +291,20 @@ void PwmFan::abortTest()
 
 void PwmFan::continueTest()
 {
-    KAuth::Action action = newFancontrolAction();
-    
-    if (action.status() != KAuth::Action::AuthorizedStatus)
+    if (!m_modeStream->device()->isWritable() || !m_pwmStream->device()->isWritable())
     {
-        m_testStatus = Error;
-        emit testingChanged();
-        return;
+        KAuth::Action action = newFancontrolAction();
+        
+        if (action.status() != KAuth::Action::AuthorizedStatus)
+        {
+            m_testStatus = Error;
+            emit testStatusChanged();
+            return;
+        }
     }
     
     update();
+    
     switch (m_testStatus)
     {
     case FindingStop1:
@@ -340,7 +326,7 @@ void PwmFan::continueTest()
                 qDebug() << "Start finding start value...";
             }
         }
-        QTimer::singleShot(500, this, SLOT(continueTest()));
+        QTimer::singleShot(500, this, &PwmFan::continueTest);
         break;
 
     case FindingStart:
@@ -352,7 +338,7 @@ void PwmFan::continueTest()
             setMinStart(m_pwm);
             qDebug() << "Start finding stop value...";
         }
-        QTimer::singleShot(1000, this, SLOT(continueTest()));
+        QTimer::singleShot(1000, this, &PwmFan::continueTest);
         break;
 
     case FindingStop2:
@@ -360,19 +346,19 @@ void PwmFan::continueTest()
         {
             setPwm(m_pwm - 1);
             m_zeroRpm = 0;
-            QTimer::singleShot(1000, this, SLOT(continueTest()));
+            QTimer::singleShot(1000, this, &PwmFan::continueTest);
         }
         else
         {
             if (m_zeroRpm < MAX_ERRORS_FOR_RPM_ZERO)
             {
                 m_zeroRpm++;
-                QTimer::singleShot(500, this, SLOT(continueTest()));
+                QTimer::singleShot(500, this, &PwmFan::continueTest);
             }
             else
             {
                 m_testStatus = Finished;
-                emit testingChanged();
+                emit testStatusChanged();
                 m_zeroRpm = 0;
                 setMinStop(m_pwm + 5);
                 qDebug() << "Finished testing!";
@@ -408,4 +394,4 @@ void PwmFan::setActive(bool a)
     }
 }
 
-}
+}

+ 18 - 17
import/src/pwmfan.h

@@ -48,10 +48,23 @@ class PwmFan : public Fan
     Q_PROPERTY(int minStart READ minStart WRITE setMinStart NOTIFY minStartChanged)
     Q_PROPERTY(int minStop READ minStop WRITE setMinStop NOTIFY minStopChanged)
     Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
-    Q_PROPERTY(bool testing READ testing NOTIFY testingChanged)
+    Q_PROPERTY(bool testing READ testing NOTIFY testStatusChanged)
+    Q_PROPERTY(TestStatus testStatus READ testStatus NOTIFY testStatusChanged)
     Q_PROPERTY(int pwmMode READ pwmMode WRITE setPwmMode NOTIFY pwmModeChanged)
+    Q_ENUMS(TestStatus)
 
 public:
+    
+    enum TestStatus
+    {
+        NotStarted,
+        FindingStop1,
+        FindingStop2,
+        FindingStart,
+        Finished,
+        Cancelled,
+        Error
+    };
 
     explicit PwmFan(Hwmon *parent, uint index);
     virtual ~PwmFan();
@@ -66,6 +79,7 @@ public:
     int minStart() const { return m_minStart; }
     int minStop() const { return m_minStop; }
     int pwmMode() const { return m_pwmMode; }
+    TestStatus testStatus() const { return m_testStatus; }
     bool active() const;
     bool testing() const;
     bool setPwm(int pwm, bool write = true) Q_DECL_OVERRIDE;
@@ -96,17 +110,14 @@ signals:
     void minStartChanged();
     void minStopChanged();
     void activeChanged();
-    void testingChanged();
+    void testStatusChanged();
     void pwmModeChanged();
 
 
-protected slots:
+public slots:
 
     void update() Q_DECL_OVERRIDE;
     void continueTest();
-    void handleSetPwmResult(KJob *job);
-    void handleSetPwmModeResult(KJob *job);
-    void handleTestAuthReply(KJob *job);
 
 
 private:
@@ -124,17 +135,7 @@ private:
     int m_minStop;
     int m_pwmMode;
     int m_zeroRpm;
-
-    enum
-    {
-        NotStarted,
-        FindingStop1,
-        FindingStop2,
-        FindingStart,
-        Finished,
-        Cancelled,
-        Error
-    } m_testStatus;
+    TestStatus m_testStatus;
 };
 
 }

+ 2 - 2
import/src/sensor.cpp

@@ -31,7 +31,7 @@ Sensor::Sensor(Hwmon *parent, uint index, const QString &path) : QObject(parent)
     m_index(index),
     m_path(path)
 {
-    connect(this, SIGNAL(errorChanged(QString)), parent, SLOT(setError(QString)));
+    connect(this, &Sensor::errorChanged, parent, &Hwmon::setError);
 }
 
-}
+}

+ 1 - 1
import/src/sensor.h

@@ -58,7 +58,7 @@ public slots:
 signals:
 
     void nameChanged();
-    void errorChanged(QString);
+    void errorChanged(QString, bool = false);
 
 
 protected:

+ 5 - 4
import/src/systemdcommunicator.cpp

@@ -268,11 +268,12 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
             action.setArguments(map);
 
             KAuth::ExecuteJob *job = action.execute();
-            connect(job, SIGNAL(result(KJob*)), this, SLOT(handleDbusActionResult(KJob*)));
+            connect(job, &KAuth::ExecuteJob::result, this, &SystemdCommunicator::handleDbusActionResult);
             job->start();
 
             return true;
         }
+        
         setError(dbusreply.errorMessage());
         return false;
     }
@@ -292,9 +293,9 @@ void SystemdCommunicator::handleDbusActionResult(KJob *job)
             if (executeJob)
             {
                 KAuth::ExecuteJob *newJob = executeJob->action().execute();
-                connect(newJob, SIGNAL(result(KJob*)), this, SLOT(handleDbusActionResult(KJob*)));
-
-                QTimer::singleShot(50, this, [newJob] (){ newJob->start(); });
+                connect(newJob, &KAuth::ExecuteJob::result, this, &SystemdCommunicator::handleDbusActionResult);
+                
+                QTimer::singleShot(50, newJob, &KAuth::ExecuteJob::start);
                 return;
             }
         }

+ 3 - 0
import/src/temp.cpp

@@ -70,10 +70,12 @@ QString Temp::name() const
     KConfigGroup names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
     KConfigGroup localNames = names.group(m_parent->name());
     QString name = localNames.readEntry("temp" + QString::number(m_index), QString());
+    
     if (name.isEmpty())
     {
         if (m_label.isEmpty())
             return "temp" + QString::number(m_index);
+        
         return m_label;
     }
     return name;
@@ -118,6 +120,7 @@ void Temp::update()
     int value;
     *m_valueStream >> value;
     value /= 1000;
+    
     if (value != m_value)
     {
         m_value = value;

+ 3 - 2
kcm/CMakeLists.txt

@@ -1,8 +1,9 @@
-set(LIBRARIES KF5::QuickAddons
+set(LIBRARIES Qt5::Core
+              KF5::QuickAddons
               KF5::CoreAddons
               KF5::I18n)
 
-find_package(KF5Declarative REQUIRED)
+find_package(KF5 COMPONENTS CoreAddons Package Declarative REQUIRED)
 
 add_library(kcm_fancontrol MODULE src/fancontrolkcm.cpp)
 

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

@@ -87,7 +87,7 @@ Item {
 
         Button {
             Layout.alignment: Qt.AlignCenter
-            text: i18n("Detect fans")
+            text: loader.sensorsDetected ? i18n("Detect fans again") : i18n("Detect fans")
             iconName: kcm.needsAuthorization ? "dialog-password" : ""
             onClicked: loader.detectSensors()
         }