浏览代码

improvements to the kcm, fixes

Malte Veerman 10 年之前
父节点
当前提交
d8ec8f716b

+ 2 - 2
CMakeLists.txt

@@ -70,12 +70,12 @@ endif(BUILD_GUI)
 
 
 #Build the KCM
-if(BUILD_KCM)
+if(BUILD_KCM AND NOT NO_SYSTEMD)
 
     message(STATUS "Build the KCM")
     add_subdirectory(kcm)
     
-endif(BUILD_KCM)
+endif(BUILD_KCM AND NOT NO_SYSTEMD)
 
 
 #summary

+ 23 - 14
kcm/src/fancontrolkcm.cpp

@@ -32,7 +32,8 @@ K_PLUGIN_FACTORY_WITH_JSON(FancontrolKCMFactory, "kcm_fancontrol.json", register
 
 FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
     : ConfigModule(parent, args),
-    m_base(new GUIBase(this))
+    m_base(new GUIBase(this)),
+    m_manualControl(m_base->systemdCommunicator()->serviceEnabled())
 {
     KAboutData *about = new KAboutData("kcm_fancontrol",
                                        i18n("Fancontrol-KCM"),
@@ -56,31 +57,39 @@ FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
 
 void FancontrolKCM::save()
 {
-    qDebug() << "saving...";
-    setNeedsSave(!m_base->loader()->save()
-
-#ifndef NO_SYSTEMD
-		 || !m_base->systemdCommunicator()->restartService()
-#endif
+    bool needsSave = false;
+    needsSave = m_base->loader()->save() ? needsSave : true;
+    
+    if (m_base->systemdCommunicator()->serviceActive() && m_manualControl)
+        needsSave = m_base->systemdCommunicator()->restartService() ? needsSave : true;
+    else 
+        needsSave = m_base->systemdCommunicator()->setServiceActive(m_manualControl) ? needsSave : true;
 
-		);
+    needsSave = m_base->systemdCommunicator()->setServiceEnabled(m_manualControl) ? needsSave : true;
+    setNeedsSave(needsSave);
 }
 
 void FancontrolKCM::load()
 {
     setNeedsSave(!m_base->loader()->load(QUrl::fromLocalFile("/etc/fancontrol")));
-    qDebug() << "Loaded config file";
 }
 
 void FancontrolKCM::defaults() 
 {
-    
-#ifndef NO_SYSTEMD
     m_base->systemdCommunicator()->setServiceEnabled(false);
-    m_base->systemdCommunicator()->setServiceActive(false);    
-#endif
-    
+    m_base->systemdCommunicator()->setServiceActive(false);        
 }
 
+void FancontrolKCM::setManualControl(bool manualControl)
+{
+    if (m_manualControl != manualControl)
+    {
+        m_manualControl = manualControl;
+        emit manualControlChanged();
+        setNeedsSave(true);
+    }
+}
+
+
 
 #include "fancontrolkcm.moc"

+ 9 - 0
kcm/src/fancontrolkcm.h

@@ -34,12 +34,15 @@ class FancontrolKCM : public ConfigModule
 {
     Q_OBJECT
     Q_PROPERTY(GUIBase *base READ base CONSTANT)
+    Q_PROPERTY(bool manualControl READ manualControl WRITE setManualControl NOTIFY manualControlChanged)
     
 public:
     
     explicit FancontrolKCM(QObject *parent, const QVariantList &args = QVariantList());
     
     GUIBase *base() const { return m_base; }
+    bool manualControl() const { return m_manualControl; }
+    void setManualControl(bool manualControl);
     
     
 public slots:
@@ -48,10 +51,16 @@ public slots:
     void save() Q_DECL_OVERRIDE;
     void defaults() Q_DECL_OVERRIDE;
     
+    
+signals:
+    
+    void manualControlChanged();
+    
 
 protected:
     
     GUIBase *const m_base;
+    bool m_manualControl;
 };
 
 #endif // FANCONTROLKCM_H

+ 231 - 231
lib/src/loader.cpp

@@ -85,8 +85,8 @@ bool Loader::load(const QUrl &url)
         fileName = url.toLocalFile();
     else
     {
-	setError("Url is not a local file");
-	return false;
+        setError("Url is not a local file");
+        return false;
     }
     
     QTextStream stream;
@@ -95,10 +95,10 @@ bool Loader::load(const QUrl &url)
     if (file.open(QFile::ReadOnly | QFile::Text))
     {
         stream.setDevice(&file);
-	m_configFile = stream.readAll();
-	emit configFileChanged();
+        m_configFile = stream.readAll();
+        emit configFileChanged();
     }
-	
+
     else if (file.exists())
     {
         KAuth::Action action("fancontrol.gui.helper.action");
@@ -116,17 +116,14 @@ bool Loader::load(const QUrl &url)
         else
         {
             m_configFile = reply->data()["content"].toString();
-	    emit configFileChanged();
+            emit configFileChanged();
         }
     }
     else
     {
-	setError("File does not exist"); 
-	return false;
+        setError("File does not exist"); 
+        return false;
     }
-    
-    m_configUrl = url;
-    emit configUrlChanged();
 
     foreach (Hwmon *hwmon, m_hwmons)
     {
@@ -152,170 +149,173 @@ bool Loader::load(const QUrl &url)
     foreach (QString line, lines)
     {
         if (line.startsWith("INTERVAL="))
-	{
-	    line.remove("INTERVAL=");
-	    bool success;
-	    int interval = line.toInt(&success);
-	    if (success)
-		setInterval(interval, false);
+        {
+            line.remove("INTERVAL=");
+            bool success;
+            int interval = line.toInt(&success);
+            if (success)
+                setInterval(interval, false);
 	    
-	    else
-	    {
-		setError("Unable to parse interval line");
-		return false;
-	    }
-	}
+            else
+            {
+                setError("Unable to parse interval line");
+                return false;
+            }
+        }
         else if (line.startsWith("FCTEMPS="))
         {
-	    line.remove("FCTEMPS=");
+            line.remove("FCTEMPS=");
             QStringList fctemps = line.split(' ');
             foreach (QString fctemp, fctemps)
             {
-		QStringList nameValuePair = fctemp.split('=');
-		if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    QString temp = nameValuePair.at(1);
-		    int pwmSensorIndex = getSensorNumber(pwm);
-		    int tempSensorIndex = getSensorNumber(temp);
-		    Hwmon *pwmHwmon = m_hwmons.value(getHwmonNumber(pwm), Q_NULLPTR);
-
-		    if (pwmHwmon)
-		    {
-			Hwmon *tempHwmon = m_hwmons.value(getHwmonNumber(temp), Q_NULLPTR);
-			PwmFan *pwmPointer = pwmHwmon->pwmFan(pwmSensorIndex);
-			if (tempHwmon)
-			{
-			    Temp *tempPointer = tempHwmon->temp(tempSensorIndex);
-
-			    if (pwmPointer)
-			    {
-				pwmPointer->setTemp(tempPointer);
-				pwmPointer->setMinPwm(0);
-			    }
-			}
-			else if (pwmPointer)
-			    pwmPointer->setTemp(Q_NULLPTR);
-		    }
-		}
+                QStringList nameValuePair = fctemp.split('=');
+                if (nameValuePair.size() == 2)
+                {
+                    QString pwm = nameValuePair.at(0);
+                    QString temp = nameValuePair.at(1);
+                    int pwmSensorIndex = getSensorNumber(pwm);
+                    int tempSensorIndex = getSensorNumber(temp);
+                    Hwmon *pwmHwmon = m_hwmons.value(getHwmonNumber(pwm), Q_NULLPTR);
+
+                    if (pwmHwmon)
+                    {
+                        Hwmon *tempHwmon = m_hwmons.value(getHwmonNumber(temp), Q_NULLPTR);
+                        PwmFan *pwmPointer = pwmHwmon->pwmFan(pwmSensorIndex);
+                        if (tempHwmon)
+                        {
+                            Temp *tempPointer = tempHwmon->temp(tempSensorIndex);
+
+                            if (pwmPointer)
+                            {
+                                pwmPointer->setTemp(tempPointer);
+                                pwmPointer->setMinPwm(0);
+                            }
+                        }
+                        else if (pwmPointer)
+                            pwmPointer->setTemp(Q_NULLPTR);
+                    }
+                }
             }
         }
         else if (line.startsWith("MINTEMP="))
         {
-	    line.remove("MINTEMP=");
+            line.remove("MINTEMP=");
             QStringList mintemps = line.split(' ');
             foreach (QString mintemp, mintemps)
             {
-		QStringList nameValuePair = mintemp.split('=');
+                QStringList nameValuePair = mintemp.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMinTemp(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                    pwmPointer->setMinTemp(value);
+                }
             }
         }
         else if (line.startsWith("MAXTEMP="))
         {
-	    line.remove("MAXTEMP=");
+            line.remove("MAXTEMP=");
             QStringList maxtemps = line.split(' ');
             foreach (QString maxtemp, maxtemps)
             {
-		QStringList nameValuePair = maxtemp.split('=');
+                QStringList nameValuePair = maxtemp.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMaxTemp(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                        pwmPointer->setMaxTemp(value);
+                }
             }
         }
         else if (line.startsWith("MINSTART="))
         {
-	    line.remove("MINSTART=");
+            line.remove("MINSTART=");
             QStringList minstarts = line.split(' ');
             foreach (QString minstart, minstarts)
             {
-		QStringList nameValuePair = minstart.split('=');
+                QStringList nameValuePair = minstart.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMinStart(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                    pwmPointer->setMinStart(value);
+                }
             }
         }
         else if (line.startsWith("MINSTOP="))
         {
-	    line.remove("MINSTOP=");
+            line.remove("MINSTOP=");
             QStringList minstops = line.split(' ');
             foreach (QString minstop, minstops)
             {
-		QStringList nameValuePair = minstop.split('=');
+                QStringList nameValuePair = minstop.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMinStop(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                    pwmPointer->setMinStop(value);
+                }
             }
         }
         else if (line.startsWith("MINPWM="))
         {
-	    line.remove("MINPWM=");
+            line.remove("MINPWM=");
             QStringList minpwms = line.split(' ');
             foreach (QString minpwm, minpwms)
             {
-		QStringList nameValuePair = minpwm.split('=');
+                QStringList nameValuePair = minpwm.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMinPwm(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                    pwmPointer->setMinPwm(value);
+                }
             }
         }
         else if (line.startsWith("MAXPWM="))
         {
-	    line.remove("MAXPWM=");
+            line.remove("MAXPWM=");
             QStringList maxpwms = line.split(' ');
             foreach (QString maxpwm, maxpwms)
             {
-		QStringList nameValuePair = maxpwm.split('=');
+                QStringList nameValuePair = maxpwm.split('=');
                 if (nameValuePair.size() == 2)
-		{
-		    QString pwm = nameValuePair.at(0);
-		    int value = nameValuePair.at(1).toInt();
-		    int pwmHwmon = getHwmonNumber(pwm);
-		    int pwmSensor = getSensorNumber(pwm);
-		    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
-		    if (pwmPointer)
-			pwmPointer->setMaxPwm(value);
-		}
+                {
+                    QString pwm = nameValuePair.at(0);
+                    int value = nameValuePair.at(1).toInt();
+                    int pwmHwmon = getHwmonNumber(pwm);
+                    int pwmSensor = getSensorNumber(pwm);
+                    PwmFan *pwmPointer = m_hwmons.value(pwmHwmon, Q_NULLPTR)->pwmFan(pwmSensor);
+                    if (pwmPointer)
+                    pwmPointer->setMaxPwm(value);
+                }
             }
         }
     }
     
+    m_configUrl = url;
+    emit configUrlChanged();
+    
     success();
     return true;
 }
@@ -325,16 +325,16 @@ bool Loader::save(const QUrl &url)
     QString fileName;
     if (url.isEmpty())
     {
-	qDebug() << "Given empty url. Fallback to " << m_configUrl;
-	fileName = m_configUrl.toLocalFile();
+        qDebug() << "Given empty url. Fallback to " << m_configUrl;
+        fileName = m_configUrl.toLocalFile();
     }
     else if (url.isLocalFile())
-	fileName = url.toLocalFile();
+        fileName = url.toLocalFile();
     
     else
     {
-	setError("Url is not a local file");
-	return false;
+        setError("Url is not a local file");
+        return false;
     }
     
     QFile file(fileName);
@@ -391,109 +391,109 @@ void Loader::createConfigFile()
     QString configFile = "# This file was created by Fancontrol-GUI \n";
 
     if (m_interval != 0)
-	configFile += "INTERVAL=" + QString::number(m_interval) + "\n";
+        configFile += "INTERVAL=" + QString::number(m_interval) + "\n";
 
     if (!usedHwmons.isEmpty())
     {
-	configFile += "DEVPATH=";
-	foreach (Hwmon *hwmon, usedHwmons)
-	{
-	    QString sanitizedPath = hwmon->path();
-	    sanitizedPath.remove(QRegExp("^/sys/"));
-	    sanitizedPath.remove(QRegExp("/hwmon/hwmon\\d\\s*$"));
-	    configFile += "hwmon" + QString::number(hwmon->index()) + "=" + sanitizedPath + " ";
-	}
-	configFile += "\n";
-
-	configFile += "DEVNAME=";
-	foreach (Hwmon *hwmon, usedHwmons)
-	{
-	    configFile += "hwmon" + QString::number(hwmon->index()) + "=" + hwmon->name().split('.').first() + " ";
-	}
-	configFile += "\n";
-
-	if (!usedFans.isEmpty())
-	{
-	    configFile += "FCTEMPS=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		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 += "\n";
-
-	    configFile += "FCFANS=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		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 += "\n";
-
-	    configFile += "MINTEMP=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->minTemp()) + " ";
-	    }
-	    configFile += "\n";
-
-	    configFile += "MAXTEMP=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->maxTemp()) + " ";
-	    }
-	    configFile += "\n";
-
-	    configFile += "MINSTART=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->minStart()) + " ";
-	    }
-	    configFile += "\n";
-
-	    configFile += "MINSTOP=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->minStop()) + " ";
-	    }
-	    configFile += "\n";
-
-	    configFile += "MINPWM=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->minPwm()) + " ";
-	    }
-	    configFile += "\n";
-
-	    configFile += "MAXPWM=";
-	    foreach (PwmFan *pwmFan, usedFans)
-	    {
-		configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
-		configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-		configFile += QString::number(pwmFan->maxPwm()) + " ";
-	    }
-	    configFile += "\n";
-	}
+        configFile += "DEVPATH=";
+        foreach (Hwmon *hwmon, usedHwmons)
+        {
+            QString sanitizedPath = hwmon->path();
+            sanitizedPath.remove(QRegExp("^/sys/"));
+            sanitizedPath.remove(QRegExp("/hwmon/hwmon\\d\\s*$"));
+            configFile += "hwmon" + QString::number(hwmon->index()) + "=" + sanitizedPath + " ";
+        }
+        configFile += "\n";
+
+        configFile += "DEVNAME=";
+        foreach (Hwmon *hwmon, usedHwmons)
+        {
+            configFile += "hwmon" + QString::number(hwmon->index()) + "=" + hwmon->name().split('.').first() + " ";
+        }
+        configFile += "\n";
+
+        if (!usedFans.isEmpty())
+        {
+            configFile += "FCTEMPS=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                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 += "\n";
+
+            configFile += "FCFANS=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                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 += "\n";
+
+            configFile += "MINTEMP=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->minTemp()) + " ";
+            }
+            configFile += "\n";
+
+            configFile += "MAXTEMP=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->maxTemp()) + " ";
+            }
+            configFile += "\n";
+
+            configFile += "MINSTART=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->minStart()) + " ";
+            }
+            configFile += "\n";
+
+            configFile += "MINSTOP=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->minStop()) + " ";
+            }
+            configFile += "\n";
+
+            configFile += "MINPWM=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->minPwm()) + " ";
+            }
+            configFile += "\n";
+
+            configFile += "MAXPWM=";
+            foreach (PwmFan *pwmFan, usedFans)
+            {
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "pwm" + QString::number(pwmFan->index()) + "=";
+                configFile += QString::number(pwmFan->maxPwm()) + " ";
+            }
+            configFile += "\n";
+        }
     }
 
     if (configFile != m_configFile)
     {
-	m_configFile = configFile;
-	emit configFileChanged();
+        m_configFile = configFile;
+        emit configFileChanged();
     }
 }
 
@@ -501,12 +501,12 @@ void Loader::setInterval(int interval, bool writeNewConfig)
 {
     if (interval != m_interval)
     {
-	m_interval = interval;
-	emit intervalChanged();
-	qDebug() << "Changed interval to" << interval;
-	
-	if (writeNewConfig)
-	    createConfigFile();
+        m_interval = interval;
+        emit intervalChanged();
+        qDebug() << "Changed interval to" << interval;
+
+        if (writeNewConfig)
+            createConfigFile();
     }
 }
 
@@ -541,12 +541,12 @@ QList< QObject* > Loader::allPwmFans() const
 int Loader::getHwmonNumber(const QString &str)
 {
     if (str.isEmpty())
-	return -1;
+        return -1;
     
     QString hwmon = str.split('/', QString::SkipEmptyParts).at(0);
     
     if (!hwmon.startsWith("hwmon"))
-	return -1;
+        return -1;
     
     bool success;
     
@@ -555,7 +555,7 @@ int Loader::getHwmonNumber(const QString &str)
     int result = hwmon.toInt(&success);
     
     if (success)
-	return result;
+        return result;
     
     return -1;
 }
@@ -563,17 +563,17 @@ int Loader::getHwmonNumber(const QString &str)
 int Loader::getSensorNumber(const QString &str)
 {
     if (str.isEmpty())
-	return -1;
+        return -1;
     
     QStringList list = str.split('/', QString::SkipEmptyParts);
     
     if (list.size() != 2)
-	return -1;
+        return -1;
     
     QString sensor = list.at(1);
     
     if (!sensor.contains(QRegExp("pwm|fan|temp|_input")))
-	return -1;
+        return -1;
     
     bool success;
     
@@ -582,7 +582,7 @@ int Loader::getSensorNumber(const QString &str)
     int result = sensor.toInt(&success);
     
     if (success)
-	return result - 1;
+        return result - 1;
     
     return -1;
 }

+ 35 - 18
lib/src/systemdcommunicator.cpp

@@ -140,34 +140,51 @@ bool SystemdCommunicator::serviceEnabled()
     return false;
 }
 
-void SystemdCommunicator::setServiceEnabled(bool enabled)
+bool SystemdCommunicator::setServiceEnabled(bool enabled)
 {
-    if (serviceExists() && enabled != serviceEnabled())
+    if (serviceExists())
     {
-	QString action = enabled ? "EnableUnitFiles" : "DisableUnitFiles";
-        QStringList files = QStringList() << m_serviceName + ".service";
-        QVariantList arguments = QVariantList() << files << false;
-	if (enabled)
-	    arguments << true;
+        if (enabled != serviceEnabled())
+        {
+            QString action = enabled ? "EnableUnitFiles" : "DisableUnitFiles";
+            QStringList files = QStringList() << m_serviceName + ".service";
+            QVariantList arguments = QVariantList() << files << false;
+            if (enabled)
+                arguments << true;
 
-	if (dbusAction(action, arguments))
-	{
-	    dbusAction("Reload");
-            emit serviceEnabledChanged();
+            if (dbusAction(action, arguments))
+            {
+                if (dbusAction("Reload"))
+                {
+                    emit serviceEnabledChanged();
+                    return true;
+                }
+            }
+            return false;
         }
+        return true;
     }
+    return false;
 }
 
-void SystemdCommunicator::setServiceActive(bool active)
+bool SystemdCommunicator::setServiceActive(bool active)
 {
-    if (serviceExists() && active != serviceActive())
+    if (serviceExists())
     {
-	QVariantList args = QVariantList() << m_serviceName + ".service" << "replace";
-	QString action = active ? "ReloadOrRestartUnit" : "StopUnit";
-	
-	if (dbusAction(action, args))
-		emit serviceActiveChanged();
+        if (active != serviceActive())
+        {
+            QVariantList args = QVariantList() << m_serviceName + ".service" << "replace";
+            QString action = active ? "ReloadOrRestartUnit" : "StopUnit";
+            
+            if (dbusAction(action, args))
+            {
+                emit serviceActiveChanged();
+                return true;
+            }
+        }
+        return true;
     }
+    return false;
 }
 
 bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &arguments)

+ 2 - 2
lib/src/systemdcommunicator.h

@@ -44,8 +44,8 @@ public:
     bool serviceExists();
     bool serviceEnabled();
     bool serviceActive();
-    void setServiceEnabled(bool enabled);
-    void setServiceActive(bool active);
+    bool setServiceEnabled(bool enabled);
+    bool setServiceActive(bool active);
     QString error() const { return m_error; }
     Q_INVOKABLE bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
     Q_INVOKABLE bool restartService();

+ 4 - 5
package/contents/ui/KCM.qml

@@ -31,17 +31,16 @@ ColumnLayout {
     
     CheckBox {
         id: enabledBox
-        anchors.left: parent.left
-        anchors.right: parent.right
         text: i18n("Control fans manually")
-        checked: kcm.base.systemdCom.serviceEnabled
-        onCheckedChanged: kcm.base.systemdCom.serviceEnabled = checked
+        checked: kcm.manualControl
+        onCheckedChanged: kcm.manualControl = checked
     }
     
     RowLayout {
         enabled: enabledBox.checked
         
         Label {
+            id: fanLabel
             text: i18n("Fan:")
             Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
             renderType: Text.NativeRendering
@@ -50,7 +49,7 @@ ColumnLayout {
             id: fanCombobox
             model: ArrayFunctions.names(kcm.base.loader.allPwmFans)
             Layout.fillWidth: true
-            Layout.maximumWidth: 300
+            Layout.maximumWidth: root.width - fanLabel.width - parent.spacing
         }
     }
     

+ 11 - 16
package/contents/ui/PwmFan.qml

@@ -60,9 +60,9 @@ Rectangle {
     }
     
     onFanChanged: update()
-    onUnitChanged: update()
-    onMinTempChanged: update()
-    onMaxTempChanged: update()
+    onUnitChanged: canvas.requestPaint()
+    onMinTempChanged: canvas.requestPaint()
+    onMaxTempChanged: canvas.requestPaint()
     
     Connections {
         target: loader
@@ -346,20 +346,16 @@ Rectangle {
                 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
                 onCheckedChanged: fan.hasTemp = checked
             }
-            Row {    
-                Layout.fillWidth: true
-                
+            RowLayout {                  
                 ComboBox {
                     property QtObject hwmon: loader.hwmons[currentIndex]
 
                     id: hwmonBox
-                    width: (parent.width-slash.width) / 2
-                    anchors.verticalCenter: parent.verticalCenter
+                    Layout.fillWidth: true
                     model: ArrayFunctions.names(loader.hwmons)
                     enabled: hasTempCheckBox.checked
                 }
                 Label {
-                    id: slash
                     text: "/"
                     anchors.verticalCenter: parent.verticalCenter
                     verticalAlignment: Text.AlignVCenter
@@ -368,8 +364,7 @@ Rectangle {
                 }
                 ComboBox {
                     id: tempBox
-                    width: (parent.width-slash.width) / 2
-                    anchors.verticalCenter: parent.verticalCenter
+                    Layout.fillWidth: true
                     model: ArrayFunctions.names(hwmonBox.hwmon.temps)
                     enabled: hasTempCheckBox.checked
                     onCurrentIndexChanged: { 
@@ -396,16 +391,16 @@ Rectangle {
         }
 
         RowLayout {
+            enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
+
             Label {
                 text: i18n("Pwm value for fan to start:")
                 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
-                enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
                 renderType: Text.NativeRendering
             }
             OptionInput {
                 id: minStartInput
                 Layout.fillWidth: true
-                enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
                 text: fan.minStart
                 onTextChanged: fan.minStart = parseInt(text)
             }
@@ -413,22 +408,22 @@ Rectangle {
 
         RowLayout {
             visible: systemdCom
+            enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
             
             Label {
                 text: i18n("Test start and stop values")
                 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
-                enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
                 renderType: Text.NativeRendering
             }
             Item {
                 Layout.fillWidth: true
             }
             Button {
-                id: testButton
                 property bool reactivateAfterTesting
+
+                id: testButton
                 text: fan.testing? i18n("Abort") : i18n("Test")
                 anchors.right: parent.right
-                height: hwmonBox.height
                 onClicked: {
                     if (fan.testing) {
                         fan.abortTesting();