Explorar o código

improved error handling and removed lots of qdebug

Malte Veerman %!s(int64=9) %!d(string=hai) anos
pai
achega
846273c685

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

@@ -123,7 +123,7 @@ ApplicationWindow {
         id: errorDialog
         visible: false
         modality: Qt.ApplicationModal
-        loader: Fancontrol.base.loader
+        base: Fancontrol.base
     }
 
     Action {

+ 3 - 3
import/qml/ErrorDialog.qml

@@ -27,7 +27,7 @@ Dialog {
     id: dialog
 
     property alias text: text.text
-    property QtObject loader
+    property QtObject base
 
     title: i18n("Error")
     width: text.implicitWidth + 20
@@ -37,11 +37,11 @@ Dialog {
     Label {
         id: text
         anchors.centerIn: parent
-        text: !!loader ? loader.error : ""
+        text: !!base ? base.error : ""
     }
     
     Connections {
-        target: loader
+        target: base
         onCriticalError: dialog.open()
     }
 }

+ 2 - 3
import/src/fan.cpp

@@ -25,7 +25,6 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QDir>
 #include <QtCore/QFile>
-#include <QtCore/QDebug>
 
 #include <KConfigCore/KSharedConfig>
 #include <KConfigCore/KConfigGroup>
@@ -50,7 +49,7 @@ Fan::Fan(Hwmon *parent, uint index) :
         else
         {
             delete rpmFile;
-            qWarning() << "Can't open rpmFile " << parent->path() + "/fan" + QString::number(index) + "_input";
+            emit errorChanged("Can't open rpmFile: " + parent->path() + "/fan" + QString::number(index) + "_input");
         }
     }
 }
@@ -103,7 +102,7 @@ void Fan::reset()
         else
         {
             delete rpmFile;
-            qWarning() << "Can't open rpmFile " << m_parent->path() + "/fan" + QString::number(m_index) + "_input";
+            emit errorChanged("Can't open rpmFile: " + m_parent->path() + "/fan" + QString::number(m_index) + "_input");
         }
     }
 }

+ 1 - 5
import/src/fancontrolaction.h

@@ -25,7 +25,6 @@
 #define FANCONTROLACTION_H
 
 
-#include <QtCore/QDebug>
 #include <KAuth/KAuthAction>
 
 
@@ -37,12 +36,9 @@ inline KAuth::Action newFancontrolAction()
     KAuth::Action action(QStringLiteral("fancontrol.gui.helper.action"));
     action.setHelperId(QStringLiteral("fancontrol.gui.helper"));
     
-    if (!action.isValid())
-        qDebug() << "Action is invalid!";
-    
     return action;
 }
 
 }
 
-#endif // FANCONTROLACTION_H
+#endif // FANCONTROLACTION_H

+ 24 - 2
import/src/guibase.cpp

@@ -27,6 +27,7 @@
 #include "hwmon.h"
 
 #include <QtCore/QLocale>
+#include <QtCore/QDebug>
 
 
 namespace Fancontrol
@@ -139,9 +140,13 @@ void GUIBase::setConfigUrl(const QUrl &url)
 {
     if (url != configUrl())
     {
-        m_config->findItem(QStringLiteral("ConfigUrl"))->setProperty(url.toString());
         m_configValid = m_loader->load(url);
-        emit configUrlChanged();
+
+        if (m_configValid)
+        {
+            m_config->findItem(QStringLiteral("ConfigUrl"))->setProperty(url.toString());
+            emit configUrlChanged();
+        }
     }
 }
 
@@ -162,5 +167,22 @@ bool GUIBase::hasSystemdCommunicator() const
 #endif
 }
 
+void GUIBase::setError(const QString &error, bool critical)
+{
+    if (error.isEmpty() || error == m_error)
+        return;
+
+    m_error = error;
+    emit errorChanged();
+
+    if (critical)
+    {
+        qCritical() << error;
+        emit criticalError();
+    }
+    else
+        qWarning() << error;
+}
+
 
 }

+ 8 - 2
import/src/guibase.h

@@ -57,6 +57,7 @@ class GUIBase : public QObject
     Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
     Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
     Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
+    Q_PROPERTY(QString error READ error NOTIFY errorChanged)
 
 public:
 
@@ -74,13 +75,14 @@ public:
     QUrl configUrl() const;
     bool configValid() const { return m_configValid; }
     QString unit() const { return m_unit; }
+    QString error() const { return m_error; }
     void setMinTemp(qreal minTemp);
     void setMaxTemp(qreal maxTemp);
     void setServiceName(const QString &name);
     void setConfigUrl(const QUrl &url);
     void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(m_unit); } }
-    PwmFanModel *pwmFanModel() const { return m_pwmFanModel; };
-    TempModel *tempModel() const { return m_tempModel; };
+    PwmFanModel *pwmFanModel() const { return m_pwmFanModel; }
+    TempModel *tempModel() const { return m_tempModel; }
     
     Q_INVOKABLE bool hasSystemdCommunicator() const;
 
@@ -89,6 +91,7 @@ public slots:
     
     void save(bool saveLoader = false, const QUrl &url = QUrl());
     void load();
+    void setError(const QString &error, bool critical = false);
     
     
 signals:
@@ -98,6 +101,8 @@ signals:
     void serviceNameChanged();
     void configUrlChanged();
     void unitChanged(QString);
+    void errorChanged();
+    void criticalError();
 
 
 protected:
@@ -107,6 +112,7 @@ protected:
 
 private:
 
+    QString m_error;
     Config *const m_config;
 
 #ifndef NO_SYSTEMD

+ 3 - 4
import/src/hwmon.cpp

@@ -24,7 +24,6 @@
 
 #include <QtCore/QDir>
 #include <QtCore/QTextStream>
-#include <QtCore/QDebug>
 
 
 namespace Fancontrol
@@ -84,7 +83,7 @@ void Hwmon::initialize()
 
         if (!success)
         {
-            qWarning() << "Not a valid Sensor:" << entry;
+            emit errorChanged("Not a valid Sensor:" + entry);
             continue;
         }
 
@@ -229,9 +228,9 @@ Temp* Hwmon::temp(int i) const
     return m_temps.value(i, Q_NULLPTR);
 }
 
-void Hwmon::setError(const QString &error)
+void Hwmon::setError(const QString &error, bool critical)
 {
-    emit errorChanged(error);
+    emit errorChanged(error, critical);
 }
 
 bool Hwmon::testing() const

+ 1 - 1
import/src/hwmon.h

@@ -73,7 +73,7 @@ public slots:
 
     void updateConfig() { emit configUpdateNeeded(); }
     void updateSensors() { emit sensorsUpdateNeeded(); }
-    void setError(const QString &error);
+    void setError(const QString &error, bool critical = false);
 
 
 signals:

+ 76 - 106
import/src/loader.cpp

@@ -20,6 +20,7 @@
 
 #include "loader.h"
 
+#include "guibase.h"
 #include "hwmon.h"
 #include "fancontrolaction.h"
 
@@ -28,7 +29,6 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QTimer>
 #include <QtCore/QProcess>
-#include <QtCore/QDebug>
 
 #include <KAuth/KAuthExecuteJob>
 #include <KI18n/KLocalizedString>
@@ -44,13 +44,16 @@
 namespace Fancontrol
 {
 
-Loader::Loader(QObject *parent) : QObject(parent),
+Loader::Loader(GUIBase *parent) : QObject(parent),
     m_reactivateAfterTesting(true),
     m_interval(10),
     m_configUrl(QUrl::fromLocalFile(QStringLiteral(STANDARD_CONFIG_FILE))),
     m_timer(new QTimer(this)),
     m_sensorsDetected(false)
 {
+    if (parent)
+        connect(this, &Loader::errorChanged, parent, &GUIBase::setError);
+
     parseHwmons();
 
     m_timer->setSingleShot(false);
@@ -68,12 +71,12 @@ void Loader::parseHwmons()
 
     else if (hwmonDir.exists())
     {
-        setError(i18n("%1 is not readable!", QStringLiteral(HWMON_PATH)), true);
+        emit errorChanged(i18n("%1 is not readable!", QStringLiteral(HWMON_PATH)), true);
         return;
     }
     else
     {
-        setError(i18n("%1 does not exist!", QStringLiteral(HWMON_PATH)), true);
+        emit errorChanged(i18n("%1 does not exist!", QStringLiteral(HWMON_PATH)), true);
         return;
     }
 
@@ -144,15 +147,12 @@ Temp * Loader::getTemp(const QPair<int, int> &indexPair) const
 QPair<int, int> Loader::getEntryNumbers(const QString &entry)
 {
     if (entry.isEmpty())
-    {
-        qWarning() << "Loader::getHwmonNumber(): given empty string.";
         return QPair<int, int>(-1, -1);
-    }
 
     auto list = entry.split('/', QString::SkipEmptyParts);
     if (list.size() != 2)
     {
-        qWarning() << "Invalid entry to parse:" << entry << "Should contain exactly one \'/\'";
+        emit errorChanged(i18n("Invalid entry to parse: %1", entry));
         return QPair<int, int>(-1, -1);
     }
     auto &hwmon = list[0];
@@ -160,12 +160,12 @@ QPair<int, int> Loader::getEntryNumbers(const QString &entry)
 
     if (!hwmon.startsWith(QStringLiteral("hwmon")))
     {
-        qWarning() << "Invalid entry to parse:" << entry << "Should begin with \"hwmon\"";
+        emit errorChanged(i18n("Invalid entry to parse: %1", entry));
         return QPair<int, int>(-1, -1);
     }
     if (!sensor.contains(QRegExp("^(pwm|fan|temp)\\d+")))
     {
-        qWarning() << "Invalid entry to parse:" << entry << "\n Sensor should begin with  pwm|fan|temp followed by a number";
+        emit errorChanged(i18n("Invalid entry to parse: %1", entry));
         return QPair<int, int>(-1, -1);
     }
 
@@ -178,26 +178,23 @@ QPair<int, int> Loader::getEntryNumbers(const QString &entry)
     const auto hwmonResult = hwmon.toInt(&success);
     if (!success)
     {
-        qWarning() << "Invalid entry to parse:" << entry << "Could not convert" << hwmon << "to int";
+        emit errorChanged(i18n("Invalid entry to parse: %1", entry));
         return QPair<int, int>(-1, -1);
     }
     const auto sensorResult = sensor.toInt(&success);
     if (!success)
     {
-        qWarning() << "Invalid entry to parse:" << entry << "Could not convert" << sensor << "to int";
+        emit errorChanged(i18n("Invalid entry to parse: %1", entry));
         return QPair<int, int>(-1, -1);
     }
 
     return QPair<int, int>(hwmonResult, sensorResult - 1);
 }
 
-void Loader::parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int)) const
+void Loader::parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int))
 {
     if (!memberSetFunction)
-    {
-        qWarning() << "Loader::parseConfigLine(): Null for member function pointer";
         return;
-    }
 
     const auto entries = line.split(' ');
 
@@ -218,10 +215,10 @@ void Loader::parseConfigLine(const QString &line, void (PwmFan::*memberSetFuncti
                     (fan->*memberSetFunction)(value);
             }
             else
-                qWarning() << valueString << "is not an int";
+                emit errorChanged(valueString + " is not an int");
         }
         else
-            qWarning() << "Invalid Entry:" << entry;
+            emit errorChanged(i18n("Invalid entry to parse: %1", entry));
     }
 }
 
@@ -230,7 +227,7 @@ bool Loader::load(const QUrl &url)
     QString fileName;
     if (url.isEmpty())
     {
-        qDebug() << "Given empty url. Fallback to" << m_configUrl;
+//        qDebug() << "Given empty url. Fallback to" << m_configUrl;
         fileName = m_configUrl.toLocalFile();
     }
     else if (url.isValid())
@@ -240,13 +237,13 @@ bool Loader::load(const QUrl &url)
 
         else
         {
-            setError(i18n("%1 is not a local file!", url.toDisplayString()));
+            emit errorChanged(i18n("%1 is not a local file!", url.toDisplayString()));
             return false;
         }
     }
     else
     {
-        setError(i18n("%1 is not a valid url!", url.toDisplayString()));
+        emit errorChanged(i18n("%1 is not a valid url!", url.toDisplayString()));
         return false;
     }
 
@@ -256,12 +253,6 @@ bool Loader::load(const QUrl &url)
 
     if (file.open(QFile::ReadOnly | QFile::Text))
     {
-        if (!url.isEmpty())
-        {
-            m_configUrl = url;
-            emit configUrlChanged();
-        }
-
         stream.setDevice(&file);
         fileContent = stream.readAll();
     }
@@ -280,36 +271,22 @@ bool Loader::load(const QUrl &url)
             {
                 if (reply->error() == 4)
                 {
-                    qDebug() << "Aborted by user";
+//                    qDebug() << "Aborted by user";
                     return false;
                 }
 
-                qDebug() << "Error while loading:" << reply->error();
-                setError(reply->errorString() + reply->errorText(), true);
+                emit errorChanged(reply->errorString() + reply->errorText(), true);
                 return false;
             }
             else
-            {
-                if (!url.isEmpty())
-                {
-                    m_configUrl = url;
-                    emit configUrlChanged();
-                }
-
                 fileContent = reply->data().value(QStringLiteral("content")).toString();
-            }
         }
         else
-            setError(i18n("Action not supported! Try running the application as root."), true);
+            emit errorChanged(i18n("Action not supported! Try running the application as root."), true);
     }
     else
     {
-        if (!url.isEmpty())
-        {
-            emit invalidConfigUrl();
-            setError(i18n("%1 does not exist!", file.fileName()));
-        }
-
+        emit errorChanged(i18n("File does not exist: %1" ,fileName));
         return false;
     }
 
@@ -359,7 +336,7 @@ bool Loader::load(const QUrl &url)
                 foreach (const auto &hwmon, m_hwmons)
                     connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
 
-                setError(i18n("Unable to parse interval line: \n %1", line), true);
+                emit errorChanged(i18n("Unable to parse interval line: %1", line), true);
                 return false;
             }
         }
@@ -385,7 +362,7 @@ bool Loader::load(const QUrl &url)
                     }
                 }
                 else
-                    qWarning() << "Invalid entry:" << fctemp;
+                    emit errorChanged(i18n("Invalid entry: %1", fctemp));
             }
         }
         else if (line.startsWith(QStringLiteral("DEVNAME=")))
@@ -409,7 +386,7 @@ bool Loader::load(const QUrl &url)
                         foreach (const auto &hwmon, m_hwmons)
                             connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
 
-                        setError(i18n("Can not parse %1", devname), true);
+                        emit errorChanged(i18n("Can not parse %1", devname), true);
                         return false;
                     }
 
@@ -419,7 +396,7 @@ bool Loader::load(const QUrl &url)
                         foreach (const auto &hwmon, m_hwmons)
                             connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
 
-                        setError(i18n("Invalid config file!"), true);
+                        emit errorChanged(i18n("Invalid config file!"), true);
                         return false;
                     }
                 }
@@ -462,7 +439,7 @@ bool Loader::load(const QUrl &url)
             foreach (const auto &hwmon, m_hwmons)
                 connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
 
-            setError(i18n("Unrecognized line in config:\n%1", line), true);
+            emit errorChanged(i18n("Unrecognized line in config: %1", line), true);
             return false;
         }
     }
@@ -473,7 +450,11 @@ bool Loader::load(const QUrl &url)
     foreach (const auto &hwmon, m_hwmons)
         connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
 
-    emit configUrlChanged();
+    if (!url.isEmpty())
+    {
+        m_configUrl = url;
+        emit configUrlChanged();
+    }
 
     return true;
 }
@@ -483,7 +464,7 @@ bool Loader::save(const QUrl &url)
     QString fileName;
     if (url.isEmpty())
     {
-        qDebug() << "Given empty url. Fallback to " << m_configUrl;
+//        qDebug() << "Given empty url. Fallback to " << m_configUrl;
         fileName = m_configUrl.toLocalFile();
     }
     else if (url.isLocalFile())
@@ -491,7 +472,7 @@ bool Loader::save(const QUrl &url)
 
     else
     {
-        setError(i18n("%1 is not a local file!", url.toDisplayString()), true);
+        emit errorChanged(i18n("%1 is not a local file!", url.toDisplayString()), true);
         return false;
     }
 
@@ -514,23 +495,22 @@ bool Loader::save(const QUrl &url)
             map[QStringLiteral("content")] = m_configFile;
 
             action.setArguments(map);
-            auto *reply = action.execute();
+            auto reply = action.execute();
 
             if (!reply->exec())
             {
                 if (reply->error() == 4)
                 {
-                    qDebug() << "Aborted by user";
+//                    qDebug() << "Aborted by user";
                     return false;
                 }
 
-                qDebug() << "Error while saving:" << reply->error();
-                setError(reply->errorString() + reply->errorText(), true);
+                emit errorChanged(reply->errorString() + reply->errorText(), true);
                 return false;
             }
         }
         else
-            setError(i18n("Action not supported! Try running the application as root."), true);
+            emit errorChanged(i18n("Action not supported! Try running the application as root."), true);
     }
 
     return true;
@@ -561,108 +541,108 @@ void Loader::createConfigFile()
     auto configFile = QStringLiteral("# This file was created by Fancontrol-GUI") + QChar(QChar::LineFeed);
 
     if (m_interval != 0)
-        configFile += QStringLiteral("INTERVAL=") + QString::number(m_interval) + QChar(QChar::LineFeed);
+        configFile += "INTERVAL=" + QString::number(m_interval) + QChar(QChar::LineFeed);
 
     if (!usedHwmons.isEmpty())
     {
-        configFile += QStringLiteral("DEVPATH=");
+        configFile += "DEVPATH=";
 
         foreach (const auto &hwmon, usedHwmons)
         {
             auto sanitizedPath = hwmon->path();
             sanitizedPath.remove(QRegExp("^/sys/"));
             sanitizedPath.remove(QRegExp("/hwmon/hwmon\\d\\s*$"));
-            configFile += QStringLiteral("hwmon") + QString::number(hwmon->index()) + "=" + sanitizedPath + QChar(QChar::Space);
+            configFile += "hwmon" + QString::number(hwmon->index()) + "=" + sanitizedPath + QChar(QChar::Space);
         }
         configFile += QChar(QChar::LineFeed);
 
-        configFile += QStringLiteral("DEVNAME=");
+        configFile += "DEVNAME=";
 
         foreach (const auto &hwmon, usedHwmons)
-            configFile += QStringLiteral("hwmon") + QString::number(hwmon->index()) + "=" + hwmon->name().split('.').first() + QChar(QChar::Space);
+            configFile += "hwmon" + QString::number(hwmon->index()) + "=" + hwmon->name().split('.').first() + QChar(QChar::Space);
 
         configFile += QChar(QChar::LineFeed);
 
         if (!usedFans.isEmpty())
         {
-            configFile += QStringLiteral("FCTEMPS=");
+            configFile += "FCTEMPS=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->temp()->parent()->index()) + "/";
-                configFile += QStringLiteral("temp") + QString::number(pwmFan->temp()->index()) + QStringLiteral("_input ");
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->temp()->parent()->index()) + "/";
+                configFile += "temp" + QString::number(pwmFan->temp()->index()) + "_input ";
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("FCFANS=");
+            configFile += "FCFANS=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("fan") + QString::number(pwmFan->index()) + QStringLiteral("_input ");
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "fan" + QString::number(pwmFan->index()) + "_input ";
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MINTEMP=");
+            configFile += "MINTEMP=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minTemp()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MAXTEMP=");
+            configFile += "MAXTEMP=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->maxTemp()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MINSTART=");
+            configFile += "MINSTART=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minStart()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MINSTOP=");
+            configFile += "MINSTOP=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minStop()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MINPWM=");
+            configFile += "MINPWM=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minPwm()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
 
-            configFile += QStringLiteral("MAXPWM=");
+            configFile += "MAXPWM=";
 
             foreach (const auto &pwmFan, usedFans)
             {
-                configFile += QStringLiteral("hwmon") + QString::number(pwmFan->parent()->index()) + "/";
-                configFile += QStringLiteral("pwm") + QString::number(pwmFan->index()) + "=";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->maxPwm()) + QChar(QChar::Space);
             }
             configFile += QChar(QChar::LineFeed);
@@ -719,7 +699,7 @@ void Loader::handleDetectSensorsResult(int exitCode)
     if (exitCode)
     {
         if (process)
-            setError(process->readAllStandardOutput());
+            emit errorChanged(process->readAllStandardOutput());
 
         auto action = newFancontrolAction();
 
@@ -735,7 +715,7 @@ void Loader::handleDetectSensorsResult(int exitCode)
             job->start();
         }
         else
-            setError(i18n("Action not supported! Try running the application as root."), true);
+            emit errorChanged(i18n("Action not supported! Try running the application as root."), true);
     }
     else
     {
@@ -758,12 +738,11 @@ void Loader::handleDetectSensorsResult(KJob *job)
     {
         if (job->error() == 4)
         {
-            qDebug() << "Aborted by user";
+//            qDebug() << "Aborted by user";
             return;
         }
 
-        qDebug() << "Error while detecting sensors:" << job->error();
-        setError(job->errorString() + job->errorText(), true);
+        emit errorChanged(job->errorString() + job->errorText(), true);
     }
     else
     {
@@ -788,16 +767,7 @@ QList<QObject *> Loader::hwmonsAsObjects() const
 
 void Loader::setError (const QString &error, bool critical)
 {
-    m_error = error;
-    emit errorChanged();
-
-    if (critical)
-    {
-        qCritical() << error;
-        emit criticalError();
-    }
-    else
-        qWarning() << error;
+    emit errorChanged(error, critical);
 }
 
 void Loader::handleTestStatusChanged()

+ 6 - 11
import/src/loader.h

@@ -38,6 +38,7 @@ namespace Fancontrol
 class Hwmon;
 class PwmFan;
 class Temp;
+class GUIBase;
 
 class Loader : public QObject
 {
@@ -53,7 +54,7 @@ class Loader : public QObject
 
 public:
 
-    explicit Loader(QObject *parent = Q_NULLPTR);
+    explicit Loader(GUIBase *parent = Q_NULLPTR);
 
     Q_INVOKABLE void parseHwmons();
     Q_INVOKABLE bool load(const QUrl & = QUrl());
@@ -72,8 +73,6 @@ public:
     void setInterval(int interval, bool writeNewConfig = true);
     QString error() const { return m_error; }
 
-    static QPair<int, int> getEntryNumbers(const QString &entry);
-
 
 public slots:
 
@@ -84,16 +83,13 @@ public slots:
     void setError(const QString &error, bool critical = false);
     void handleDetectSensorsResult(KJob *job);
     void handleDetectSensorsResult(int exitCode);
-    void handleTestStatusChanged();
-
-
-protected:
-
-    void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value)) const;
+    void handleTestStatusChanged();    
 
 
 private:
 
+    void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value));
+    QPair<int, int> getEntryNumbers(const QString &entry);
     PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
     Temp *getTemp(const QPair<int, int> &indexPair) const;
 
@@ -113,12 +109,11 @@ signals:
     void configFileChanged();
     void hwmonsChanged();
     void intervalChanged();
-    void errorChanged();
+    void errorChanged(QString, bool = false);
     void sensorsUpdateNeeded();
     void allPwmFansChanged();
     void allTempsChanged();
     void invalidConfigUrl();
-    void criticalError();
     void sensorsDetectedChanged();
     void restartServiceAfterTestingChanged();
     void requestSetServiceActive(bool);

+ 11 - 12
import/src/pwmfan.cpp

@@ -30,7 +30,6 @@
 #include <QtCore/QTimer>
 #include <QtCore/QDir>
 #include <QtCore/QFile>
-#include <QtCore/QDebug>
 
 #include <KConfigCore/KConfigGroup>
 #include <KConfigCore/KSharedConfig>
@@ -85,7 +84,7 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index),
         else
         {
             delete pwmFile;
-            qWarning() << "Can't open pwmFile " << pwmFile->fileName();
+            emit errorChanged("Can't open pwmFile: " + pwmFile->fileName());
         }
 
         const auto pwmModeFile = new QFile(parent->path() + "/pwm" + QString::number(index) + "_mode", this);
@@ -103,7 +102,7 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index),
         else
         {
             delete pwmModeFile;
-            qWarning() << "Can't open pwmModeFile " << pwmModeFile->fileName();
+            emit errorChanged("Can't open pwmModeFile: " + pwmModeFile->fileName());
         }
     }
 }
@@ -153,7 +152,7 @@ void PwmFan::reset()
     else
     {
         delete pwmFile;
-        qWarning() << "Can't open pwmFile " << pwmFile->fileName();
+        emit errorChanged("Can't open pwmFile: " + pwmFile->fileName());
     }
 
     const auto pwmModeFile = new QFile(m_parent->path() + "/pwm" + QString::number(m_index) + "_mode", this);
@@ -171,7 +170,7 @@ void PwmFan::reset()
     else
     {
         delete pwmModeFile;
-        qWarning() << "Can't open pwmModeFile " << pwmModeFile->fileName();
+        emit errorChanged("Can't open pwmModeFile: " + pwmModeFile->fileName());
     }
 }
 
@@ -205,7 +204,7 @@ bool PwmFan::setPwm(int pwm, bool write)
                     {
                         if (job->error() == KAuth::ActionReply::HelperBusyError)
                         {
-                            qDebug() << "Helper busy...";
+//                            qDebug() << "Helper busy...";
 
                             QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
                         }
@@ -251,7 +250,7 @@ bool PwmFan::setPwmMode(int pwmMode, bool write)
                     {
                         if (job->error() == KAuth::ActionReply::HelperBusyError)
                         {
-                            qDebug() << "Helper busy...";
+//                            qDebug() << "Helper busy...";
 
                             QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
                         }
@@ -299,14 +298,14 @@ void PwmFan::test()
     emit testStatusChanged();
 
     QTimer::singleShot(500, this, &PwmFan::continueTest);
-    qDebug() << "Start testing...";
+//    qDebug() << "Start testing...";
 }
 
 void PwmFan::abortTest()
 {
     if (m_testStatus >= FindingStop1 && m_testStatus <= FindingStart)
     {
-        qDebug() << "Abort testing";
+//        qDebug() << "Abort testing";
 
         m_testStatus = Cancelled;
         emit testStatusChanged();
@@ -349,7 +348,7 @@ void PwmFan::continueTest()
             {
                 m_testStatus = FindingStart;
                 m_zeroRpm = 0;
-                qDebug() << "Start finding start value...";
+//                qDebug() << "Start finding start value...";
             }
         }
         QTimer::singleShot(500, this, &PwmFan::continueTest);
@@ -362,7 +361,7 @@ void PwmFan::continueTest()
         {
             m_testStatus = FindingStop2;
             setMinStart(m_pwm);
-            qDebug() << "Start finding stop value...";
+//            qDebug() << "Start finding stop value...";
         }
         QTimer::singleShot(1000, this, &PwmFan::continueTest);
         break;
@@ -388,7 +387,7 @@ void PwmFan::continueTest()
                 m_zeroRpm = 0;
                 setMinStop(m_pwm + 5);
                 setPwm(255);
-                qDebug() << "Finished testing PwmFan" << m_index;
+//                qDebug() << "Finished testing PwmFan" << m_index;
             }
         }
         break;

+ 14 - 20
import/src/systemdcommunicator.cpp

@@ -21,8 +21,8 @@
 #include "systemdcommunicator.h"
 
 #include "fancontrolaction.h"
+#include "guibase.h"
 
-#include <QtCore/QDebug>
 #include <QtCore/QVariant>
 #include <QtCore/QTimer>
 #include <QtDBus/QDBusArgument>
@@ -67,7 +67,7 @@ const QDBusArgument& operator >>(const QDBusArgument &argument, SystemdUnitFile
 namespace Fancontrol
 {
 
-SystemdCommunicator::SystemdCommunicator(QObject *parent, const QString &serviceName) : QObject(parent),
+SystemdCommunicator::SystemdCommunicator(GUIBase *parent, const QString &serviceName) : QObject(parent),
     m_managerInterface(new QDBusInterface(QStringLiteral("org.freedesktop.systemd1"),
                                           QStringLiteral("/org/freedesktop/systemd1"),
                                           QStringLiteral("org.freedesktop.systemd1.Manager"),
@@ -75,6 +75,9 @@ SystemdCommunicator::SystemdCommunicator(QObject *parent, const QString &service
                                           this)),
     m_serviceInterface(Q_NULLPTR)
 {
+    if (parent)
+        connect(this, &SystemdCommunicator::errorChanged, parent, &GUIBase::setError);
+
     if (serviceName.isEmpty())
         setServiceName(QStringLiteral(STANDARD_SERVICE_NAME));
     else
@@ -110,8 +113,7 @@ void SystemdCommunicator::setServiceName(const QString &name)
             const auto dbusreply = m_managerInterface->callWithArgumentList(QDBus::AutoDetect, QStringLiteral("LoadUnit"), arguments);
             if (dbusreply.type() == QDBusMessage::ErrorMessage)
             {
-                m_error = dbusreply.errorMessage();
-                emit errorChanged();
+                emit errorChanged(dbusreply.errorMessage());
                 m_serviceObjectPath.clear();
             }
             else
@@ -153,7 +155,7 @@ bool SystemdCommunicator::serviceExists()
 
     if (dbusreply.type() == QDBusMessage::ErrorMessage)
     {
-        setError(dbusreply.errorMessage());
+        emit errorChanged(dbusreply.errorMessage());
         return false;
     }
     SystemdUnitFileList list = qdbus_cast<SystemdUnitFileList>(dbusreply.arguments().at(0));
@@ -164,7 +166,7 @@ bool SystemdCommunicator::serviceExists()
             return true;
     }
 
-    setError(i18n("Service %1 doesn't exist", m_serviceName));
+    emit errorChanged(i18n("Service does not exist: %1", m_serviceName));
     return false;
 }
 
@@ -218,7 +220,7 @@ bool SystemdCommunicator::setServiceEnabled(bool enabled)
 
 bool SystemdCommunicator::setServiceActive(bool active)
 {
-    qDebug() << "Set service active:" << active;
+//    qDebug() << "Set service active:" << active;
 
     if (serviceExists())
     {
@@ -243,7 +245,7 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
 {
     if (!m_managerInterface->isValid())
     {
-        qDebug() << "Invalid manager interface!";
+        emit errorChanged(i18n("Invalid manager interface!"), true);
         return false;
 
     }
@@ -269,7 +271,7 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
         return true;
     }
 
-    setError(dbusreply.errorMessage());
+    emit errorChanged(dbusreply.errorMessage());
     return false;
 
 }
@@ -280,7 +282,7 @@ void SystemdCommunicator::handleDbusActionResult(KJob *job)
     {
         if (job->error() == KAuth::ActionReply::HelperBusyError)
         {
-            qDebug() << "Helper busy...";
+//            qDebug() << "Helper busy...";
 
             const auto executeJob = static_cast<KAuth::ExecuteJob *>(job);
             if (executeJob)
@@ -293,7 +295,7 @@ void SystemdCommunicator::handleDbusActionResult(KJob *job)
             }
         }
 
-        setError(job->errorText());
+        emit errorChanged(job->errorText());
     }
 }
 
@@ -307,7 +309,7 @@ bool SystemdCommunicator::restartService()
         return dbusAction(QStringLiteral("ReloadOrRestartUnit"), args);
     }
 
-    setError(i18n("Service does not exist"));
+    emit errorChanged(i18n("Service does not exist: %1", m_serviceName));
     return false;
 }
 
@@ -320,12 +322,4 @@ void SystemdCommunicator::updateServiceProperties(QString, QVariantMap propchang
         emit serviceEnabledChanged();
 }
 
-void SystemdCommunicator::setError(const QString &error)
-{
-    qCritical() << error;
-
-    m_error = error;
-    emit errorChanged();
-}
-
 }

+ 4 - 6
import/src/systemdcommunicator.h

@@ -30,17 +30,18 @@ class KJob;
 namespace Fancontrol
 {
 
+class GUIBase;
+
 class SystemdCommunicator : public QObject
 {
     Q_OBJECT
-    Q_PROPERTY(QString error READ error NOTIFY errorChanged)
     Q_PROPERTY(bool serviceExists READ serviceExists NOTIFY serviceNameChanged)
     Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
     Q_PROPERTY(bool serviceActive READ serviceActive WRITE setServiceActive NOTIFY serviceActiveChanged)
 
 public:
 
-    explicit SystemdCommunicator(QObject *parent = Q_NULLPTR, const QString &serviceName = QString());
+    explicit SystemdCommunicator(GUIBase *parent = Q_NULLPTR, const QString &serviceName = QString());
 
     QString serviceName() const { return m_serviceName; }
     void setServiceName(const QString &name);
@@ -49,7 +50,6 @@ public:
     bool serviceActive();
     bool setServiceEnabled(bool enabled);
     bool setServiceActive(bool active);
-    QString error() const { return m_error; }
     Q_INVOKABLE bool restartService();
 
 
@@ -58,7 +58,7 @@ signals:
     void serviceNameChanged();
     void serviceEnabledChanged();
     void serviceActiveChanged();
-    void errorChanged();
+    void errorChanged(QString, bool = false);
 
 
 protected slots:
@@ -70,14 +70,12 @@ protected slots:
 protected:
     
     bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
-    void setError(const QString &error);
     
     
 private:
 
     QString m_serviceName;
     QString m_serviceObjectPath;
-    QString m_error;
     QDBusInterface * const m_managerInterface;
     QDBusInterface *m_serviceInterface;
 };

+ 5 - 6
import/src/temp.cpp

@@ -26,7 +26,6 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QFile>
 #include <QtCore/QDir>
-#include <QtCore/QDebug>
 
 #include <KConfigCore/KSharedConfig>
 #include <KConfigCore/KConfigGroup>
@@ -55,7 +54,7 @@ Temp::Temp(Hwmon *parent, uint index) :
         else
         {
             delete valueFile;
-            qCritical() << "Can't open valueFile " << parent->path() + "/temp" + QString::number(index) + "_input";
+            emit errorChanged("Can't open valueFile " + parent->path() + "/temp" + QString::number(index) + "_input");
         }
 
         if (labelFile->exists())
@@ -63,10 +62,10 @@ Temp::Temp(Hwmon *parent, uint index) :
             if (labelFile->open(QFile::ReadOnly))
                 m_label = QTextStream(labelFile).readLine();
             else
-                qWarning() << "Can't open labelFile " << parent->path() + "/temp" + QString::number(index) + "_label";
+                emit errorChanged("Can't open labelFile: " + parent->path() + "/temp" + QString::number(index) + "_label");
         }
         else
-            qWarning() << parent->path() + "/temp" + QString::number(index) << "has no label.";
+            emit errorChanged(parent->path() + "/temp" + QString::number(index) + "has no label.");
 
         delete labelFile;
     }
@@ -123,7 +122,7 @@ void Temp::reset()
             m_value /= 1000;
         }
         else
-            qCritical() << "Can't open valueFile " << m_parent->path() + "/temp" + QString::number(m_index) + "_input";
+            emit errorChanged("Can't open valueFile " + m_parent->path() + "/temp" + QString::number(m_index) + "_input");
     }
 }
 
@@ -135,7 +134,7 @@ void Temp::update()
     const auto value = m_valueStream->readAll().toInt(&success) / 1000;
 
     if (!success)
-        qCritical() << "Can't update value of temp:" << m_parent->path() + "/temp" + QString::number(m_index);
+        emit errorChanged("Can't update value of temp:" + m_parent->path() + "/temp" + QString::number(m_index));
     
     if (value != m_value)
     {

+ 0 - 2
import/src/tempmodel.cpp

@@ -24,8 +24,6 @@
 #include "tempmodel.h"
 #include "temp.h"
 
-#include <QDebug>
-
 
 namespace Fancontrol
 {

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

@@ -343,6 +343,6 @@ Item {
     Fancontrol.ErrorDialog {
         id: errorDialog
         modality: Qt.ApplicationModal
-        loader: root.loader
+        base: base
     }
 }