Browse Source

split createConfigFile() into createConfig() and updateConfig()

Malte Veerman 9 years ago
parent
commit
9740162d5a
3 changed files with 25 additions and 17 deletions
  1. 1 1
      import/src/hwmon.cpp
  2. 21 14
      import/src/loader.cpp
  3. 3 2
      import/src/loader.h

+ 1 - 1
import/src/hwmon.cpp

@@ -59,7 +59,7 @@ Hwmon::Hwmon(const QString &path, Loader *parent) : QObject(parent),
 
 
     delete nameFile;
     delete nameFile;
 
 
-    connect(this, &Hwmon::configUpdateNeeded, parent, &Loader::createConfigFile);
+    connect(this, &Hwmon::configUpdateNeeded, parent, &Loader::updateConfig);
     connect(this, &Hwmon::pwmFansChanged, parent, &Loader::emitAllPwmFansChanged);
     connect(this, &Hwmon::pwmFansChanged, parent, &Loader::emitAllPwmFansChanged);
     connect(this, &Hwmon::tempsChanged, parent, &Loader::emitAllTempsChanged);
     connect(this, &Hwmon::tempsChanged, parent, &Loader::emitAllTempsChanged);
     connect(this, &Hwmon::error, parent, &Loader::error);
     connect(this, &Hwmon::error, parent, &Loader::error);

+ 21 - 14
import/src/loader.cpp

@@ -294,7 +294,7 @@ bool Loader::load(const QUrl &url)
     //They get reconnected later
     //They get reconnected later
     foreach (const auto &hwmon, m_hwmons)
     foreach (const auto &hwmon, m_hwmons)
     {
     {
-        disconnect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+        disconnect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
         foreach (const auto &pwmFan, hwmon->pwmFans())
         foreach (const auto &pwmFan, hwmon->pwmFans())
         {
         {
             qobject_cast<PwmFan *>(pwmFan)->reset();
             qobject_cast<PwmFan *>(pwmFan)->reset();
@@ -334,7 +334,7 @@ bool Loader::load(const QUrl &url)
             {
             {
                 //Connect hwmons again
                 //Connect hwmons again
                 foreach (const auto &hwmon, m_hwmons)
                 foreach (const auto &hwmon, m_hwmons)
-                    connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                    connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
 
 
                 emit error(i18n("Unable to parse interval line: %1", line), true);
                 emit error(i18n("Unable to parse interval line: %1", line), true);
                 return false;
                 return false;
@@ -384,7 +384,7 @@ bool Loader::load(const QUrl &url)
                     {
                     {
                         //Connect hwmons again
                         //Connect hwmons again
                         foreach (const auto &hwmon, m_hwmons)
                         foreach (const auto &hwmon, m_hwmons)
-                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
 
 
                         emit error(i18n("Can not parse %1", devname), true);
                         emit error(i18n("Can not parse %1", devname), true);
                         return false;
                         return false;
@@ -394,7 +394,7 @@ bool Loader::load(const QUrl &url)
                     {
                     {
                         //Connect hwmons again
                         //Connect hwmons again
                         foreach (const auto &hwmon, m_hwmons)
                         foreach (const auto &hwmon, m_hwmons)
-                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                            connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
 
 
                         emit error(i18n("Invalid config file!"), true);
                         emit error(i18n("Invalid config file!"), true);
                         return false;
                         return false;
@@ -437,18 +437,18 @@ bool Loader::load(const QUrl &url)
         {
         {
             //Connect hwmons again
             //Connect hwmons again
             foreach (const auto &hwmon, m_hwmons)
             foreach (const auto &hwmon, m_hwmons)
-                connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+                connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
 
 
             emit error(i18n("Unrecognized line in config: %1", line), true);
             emit error(i18n("Unrecognized line in config: %1", line), true);
             return false;
             return false;
         }
         }
     }
     }
 
 
-    createConfigFile();
+    updateConfig();
 
 
     //Connect hwmons again
     //Connect hwmons again
     foreach (const auto &hwmon, m_hwmons)
     foreach (const auto &hwmon, m_hwmons)
-        connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::createConfigFile);
+        connect(hwmon, &Hwmon::configUpdateNeeded, this, &Loader::updateConfig);
 
 
     if (!url.isEmpty())
     if (!url.isEmpty())
     {
     {
@@ -516,7 +516,18 @@ bool Loader::save(const QUrl &url)
     return true;
     return true;
 }
 }
 
 
-void Loader::createConfigFile()
+void Loader::updateConfig()
+{
+    const auto configFile = createConfig();
+
+    if (configFile != m_configFile)
+    {
+        m_configFile = configFile;
+        emit configFileChanged();
+    }
+}
+
+QString Loader::createConfig() const
 {
 {
     QList<Hwmon *> usedHwmons;
     QList<Hwmon *> usedHwmons;
     QList<PwmFan *> usedFans;
     QList<PwmFan *> usedFans;
@@ -649,11 +660,7 @@ void Loader::createConfigFile()
         }
         }
     }
     }
 
 
-    if (configFile != m_configFile)
-    {
-        m_configFile = configFile;
-        emit configFileChanged();
-    }
+    return configFile;
 }
 }
 
 
 void Loader::setInterval(int interval, bool writeNewConfig)
 void Loader::setInterval(int interval, bool writeNewConfig)
@@ -664,7 +671,7 @@ void Loader::setInterval(int interval, bool writeNewConfig)
         emit intervalChanged();
         emit intervalChanged();
 
 
         if (writeNewConfig)
         if (writeNewConfig)
-            createConfigFile();
+            updateConfig();
     }
     }
 }
 }
 
 

+ 3 - 2
import/src/loader.h

@@ -75,18 +75,19 @@ public:
 public slots:
 public slots:
 
 
     void updateSensors() { emit sensorsUpdateNeeded(); }
     void updateSensors() { emit sensorsUpdateNeeded(); }
-    void createConfigFile();
+    void updateConfig();
     void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
     void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
     void emitAllTempsChanged() { emit allTempsChanged(); }
     void emitAllTempsChanged() { emit allTempsChanged(); }
     void handleDetectSensorsResult(KJob *job);
     void handleDetectSensorsResult(KJob *job);
     void handleDetectSensorsResult(int exitCode);
     void handleDetectSensorsResult(int exitCode);
-    void handleTestStatusChanged();    
+    void handleTestStatusChanged();
 
 
 
 
 private:
 private:
 
 
     void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value));
     void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value));
     QPair<int, int> getEntryNumbers(const QString &entry);
     QPair<int, int> getEntryNumbers(const QString &entry);
+    QString createConfig() const;
     PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
     PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
     Temp *getTemp(const QPair<int, int> &indexPair) const;
     Temp *getTemp(const QPair<int, int> &indexPair) const;