瀏覽代碼

don't add minimized fans to the config file, code cleanups

Malte Veerman 10 年之前
父節點
當前提交
0f2be99c58
共有 2 個文件被更改,包括 40 次插入91 次删除
  1. 39 91
      share/src/loader.cpp
  2. 1 0
      share/src/sensors.cpp

+ 39 - 91
share/src/loader.cpp

@@ -305,6 +305,7 @@ void Loader::save(const QUrl &url)
 void Loader::createConfigFile()
 {
     QList<Hwmon *> usedHwmons;
+    QList<PwmFan *> usedFans;
     foreach (Hwmon *hwmon, m_hwmons)
     {
         if (hwmon->pwmFans().size() > 0)
@@ -312,9 +313,12 @@ void Loader::createConfigFile()
         foreach (QObject *fan, hwmon->pwmFans())
         {
             PwmFan *pwmFan = qobject_cast<PwmFan *>(fan);
-            if (pwmFan->hasTemp() && pwmFan->temp())
+            if (pwmFan->active() && pwmFan->hasTemp() && pwmFan->temp())
+            {
+                usedFans << pwmFan;
                 if (!usedHwmons.contains(pwmFan->temp()->parent()))
                     usedHwmons << pwmFan->temp()->parent();
+            }
         }
     }
 
@@ -338,132 +342,76 @@ void Loader::createConfigFile()
     m_configFile += "\n";
 
     m_configFile += "FCTEMPS=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp() && pwmFan->temp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += "hwmon" + QString::number(pwmFan->temp()->parent()->index()) + "/";
-                m_configFile += "temp" + QString::number(pwmFan->temp()->index()) + "_input ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += "hwmon" + QString::number(pwmFan->temp()->parent()->index()) + "/";
+        m_configFile += "temp" + QString::number(pwmFan->temp()->index()) + "_input ";
     }
     m_configFile += "\n";
 
     m_configFile += "FCFANS=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "fan" + QString::number(pwmFan->index()) + "_input ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "fan" + QString::number(pwmFan->index()) + "_input ";
     }
     m_configFile += "\n";
 
     m_configFile += "MINTEMP=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->minTemp()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->minTemp()) + " ";
     }
     m_configFile += "\n";
 
     m_configFile += "MAXTEMP=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->maxTemp()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->maxTemp()) + " ";
     }
     m_configFile += "\n";
 
     m_configFile += "MINSTART=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->minStart()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->minStart()) + " ";
     }
     m_configFile += "\n";
 
     m_configFile += "MINSTOP=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp())
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->minStop()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->minStop()) + " ";
     }
     m_configFile += "\n";
 
     m_configFile += "MINPWM=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp() && pwmFan->minPwm() != 0)
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->minPwm()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->minPwm()) + " ";
     }
     m_configFile += "\n";
 
     m_configFile += "MAXPWM=";
-    foreach (Hwmon *hwmon, m_hwmons)
+    foreach (PwmFan *pwmFan, usedFans)
     {
-        foreach (QObject *object, hwmon->pwmFans())
-        {
-            PwmFan *pwmFan = qobject_cast<PwmFan *>(object);
-            if (pwmFan->hasTemp() && pwmFan->maxPwm() != 255)
-            {
-                m_configFile += "hwmon" + QString::number(hwmon->index()) + "/";
-                m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                m_configFile += QString::number(pwmFan->maxPwm()) + " ";
-            }
-        }
+        m_configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+        m_configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+        m_configFile += QString::number(pwmFan->maxPwm()) + " ";
     }
     m_configFile += "\n";
 

+ 1 - 0
share/src/sensors.cpp

@@ -103,6 +103,7 @@ PwmFan::PwmFan(Hwmon *parent, uint index) : Fan(parent, index)
     connect(this, SIGNAL(maxPwmChanged()), parent, SLOT(updateConfig()));
     connect(this, SIGNAL(minStartChanged()), parent, SLOT(updateConfig()));
     connect(this, SIGNAL(minStopChanged()), parent, SLOT(updateConfig()));
+    connect(this, SIGNAL(activeChanged()), parent, SLOT(updateConfig()));
     connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(continueTesting()));
 
     if (QDir(parent->path()).isReadable())