瀏覽代碼

initial work for auto testing of fans and simplifying the helper.

Malte Veerman 10 年之前
父節點
當前提交
ae4bffc52d

+ 3 - 15
helper/fancontrol-gui.actions

@@ -2,20 +2,8 @@
 Name=Fancontrol-GUI
 URL=http://github.com/maldela/fancontrol-gui
 
-[fancontrol.gui.helper.write]
-Name=Save your configfile
-Description=Save the fancontrol configuration file
-Policy=auth_admin
-Persistence=session
-
-[fancontrol.gui.helper.read]
-Name=Read configfile
-Description=Read the fancontrol configuration file
-Policy=auth_admin
-Persistence=session
-
-[fancontrol.gui.helper.dbusaction]
-Name=Manipulate systemd over DBus
-Description=Manipulate systemd to start, stop or restart the fancontrol service
+[fancontrol.gui.helper.action]
+Name=Action with su rights
+Description=This action requires superuser rights.
 Policy=auth_admin
 Persistence=session

+ 53 - 53
helper/src/helper.cpp

@@ -24,81 +24,81 @@
 
 #ifndef NO_SYSTEMD
 #include <QtDBus>
+#endif
 
-ActionReply Helper::dbusaction(const QVariantMap &arguments)
+ActionReply Helper::action(const QVariantMap &arguments)
 {
-    QString method = arguments["method"].toString();
-    QVariantList argsForCall = arguments["arguments"].toList();
-
     ActionReply reply;
 
-    QDBusConnection systembus = QDBusConnection::systemBus();
+#ifndef NO_SYSTEMD
+    if (arguments["action"] == "dbusaction")
+    {
+        QString method = arguments["method"].toString();
+        QVariantList argsForCall = arguments["arguments"].toList();
 
-    QDBusInterface *iface = new QDBusInterface ("org.freedesktop.systemd1",
-                                                "/org/freedesktop/systemd1",
-                                                "org.freedesktop.systemd1.Manager",
-                                                systembus,
-                                                this);
+        QDBusConnection systembus = QDBusConnection::systemBus();
 
-    QDBusMessage dbusreply;
+        QDBusInterface *iface = new QDBusInterface ("org.freedesktop.systemd1",
+                                                    "/org/freedesktop/systemd1",
+                                                    "org.freedesktop.systemd1.Manager",
+                                                    systembus,
+                                                    this);
 
-    if (iface->isValid())
-        dbusreply = iface->callWithArgumentList(QDBus::AutoDetect, method, argsForCall);
-    delete iface;
+        QDBusMessage dbusreply;
 
-    if (method != "Reexecute")
-    {
-        if (dbusreply.type() == QDBusMessage::ErrorMessage)
+        if (iface->isValid())
+            dbusreply = iface->callWithArgumentList(QDBus::AutoDetect, method, argsForCall);
+        delete iface;
+
+        if (method != "Reexecute")
         {
-            reply.setErrorCode(ActionReply::DBusError);
-            reply.setErrorDescription(dbusreply.errorMessage());
+            if (dbusreply.type() == QDBusMessage::ErrorMessage)
+            {
+                reply.setErrorCode(ActionReply::DBusError);
+                reply.setErrorDescription(dbusreply.errorMessage());
+            }
         }
     }
-
-    return reply;
-}
+    else
 #endif
-
-ActionReply Helper::read(const QVariantMap &args)
-{
-    ActionReply reply;
-    QString filename = args["filename"].toString();
-    QFile file(filename);
-
-    if (!file.open(QIODevice::ReadOnly))
+    if (arguments["action"] == "read")
     {
-       reply = ActionReply::HelperErrorType;
-       reply.setErrorCode(ActionReply::AuthorizationDeniedError);
+        QString filename = arguments["filename"].toString();
+        QFile file(filename);
 
-       return reply;
-    }
+        if (!file.open(QIODevice::ReadOnly))
+        {
+           reply = ActionReply::HelperErrorType;
+           reply.setErrorCode(ActionReply::AuthorizationDeniedError);
 
-    QTextStream stream(&file);
-    QString content = stream.readAll();
+           return reply;
+        }
 
-    QVariantMap retdata;
-    retdata["content"] = content;
+        QTextStream stream(&file);
+        QString content = stream.readAll();
 
-    reply.setData(retdata);
-    return reply;
-}
+        QVariantMap retdata;
+        retdata["content"] = content;
 
-ActionReply Helper::write(const QVariantMap &args)
-{
-    ActionReply reply;
-    QString filename = args["filename"].toString();
-    QFile file(filename);
+        reply.setData(retdata);
+    }
 
-    if (!file.open(QIODevice::WriteOnly))
+    else if (arguments["action"] == "write")
     {
-       reply = ActionReply::HelperErrorType;
-       reply.addData("errorDescription", file.errorString());
+        QString filename = arguments["filename"].toString();
+        QFile file(filename);
 
-       return reply;
-    }
+        if (!file.open(QIODevice::WriteOnly))
+        {
+           reply = ActionReply::HelperErrorType;
+           reply.addData("errorDescription", file.errorString());
 
-    QTextStream stream(&file);
-    stream << args["content"].toString();
+           return reply;
+        }
+
+        QTextStream stream(&file);
+        stream << arguments["content"].toString();
+    }
 
     return reply;
 }

+ 1 - 6
helper/src/helper.h

@@ -28,10 +28,5 @@ class Helper : public QObject
 
     public Q_SLOTS:
 
-#ifndef NO_SYSTEMD
-        ActionReply dbusaction(const QVariantMap &args);
-#endif
-
-        ActionReply read(const QVariantMap &args);
-        ActionReply write(const QVariantMap &args);
+        ActionReply action(const QVariantMap &args);
 };

+ 25 - 7
share/qml/PwmFan.qml

@@ -405,13 +405,31 @@ Rectangle {
             }
         }
 
-        Button {
-            text: "Auto"
-            height: 15
-            enabled: !fan.testing
-            onClicked: {
-                systemdCom.dbusAction("StopUnit", [systemdCom.serviceName + ".service", "replace"]);
-                fan.test();
+        RowLayout {
+            anchors.left: parent.left
+            anchors.right: parent.right
+
+            Text {
+                text: "Test start and stop values"
+                Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
+                enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
+                color: enabled ? palette.text : disabledPalette.text
+                renderType: Text.NativeRendering
+            }
+            Button {
+                text: fan.testing? "Abort" : "Test"
+                anchors.right: parent.right
+                height: hwmonBox.height
+                onClicked: {
+                    if (fan.testing) {
+                        systemdCom.dbusAction("StartUnit", [systemdCom.serviceName + ".service", "replace"]);
+                        fan.abortTesting();
+                    } else {
+                        systemdCom.dbusAction("StopUnit", [systemdCom.serviceName + ".service", "replace"]);
+                        minStartInput.text = Qt.binding(function() { return fan.minStart });
+                        fan.test();
+                    }
+                }
             }
         }
     }

+ 4 - 2
share/src/loader.cpp

@@ -88,9 +88,10 @@ void Loader::open(const QUrl &url)
     }
     else if (file.exists())
     {
-        Action action("fancontrol.gui.helper.read");
+        Action action("fancontrol.gui.helper.action");
         action.setHelperId("fancontrol.gui.helper");
         QVariantMap map;
+        map["action"] = "read";
         map["filename"] = fileName;
         action.setArguments(map);
         ExecuteJob *reply = action.execute();
@@ -284,9 +285,10 @@ void Loader::save(const QUrl &url)
     }
     else
     {
-        Action action("fancontrol.gui.helper.write");
+        Action action("fancontrol.gui.helper.action");
         action.setHelperId("fancontrol.gui.helper");
         QVariantMap map;
+        map["action"] = "write";
         map["content"] = m_configFile;
 
         map["filename"] = fileName;

+ 11 - 1
share/src/sensors.cpp

@@ -135,9 +135,10 @@ bool PwmFan::writePwm(int pwm)
         m_pwmStream << m_pwm;
     else
     {
-        KAuth::Action action("fancontrol.gui.helper.write");
+        KAuth::Action action("fancontrol.gui.helper.action");
         action.setHelperId("fancontrol.gui.helper");
         QVariantMap map;
+        map["action"] = "write";
         map["filename"] = qobject_cast<QFile *>(m_pwmStream.device())->fileName();
         map["content"] = pwm;
         action.setArguments(map);
@@ -159,6 +160,15 @@ void PwmFan::test()
     qDebug() << "Start testing...";
 }
 
+void PwmFan::abortTesting()
+{
+    setPwm(255);
+    m_testTimer.stop();
+
+    m_testing = false;
+    emit testingChanged();
+}
+
 void PwmFan::continueTesting()
 {
     update();

+ 1 - 0
share/src/sensors.h

@@ -177,6 +177,7 @@ public:
     void setActive(bool active);
     void reset();
     Q_INVOKABLE void test();
+    Q_INVOKABLE void abortTesting();
 
 
 signals:

+ 2 - 1
share/src/systemdcommunicator.cpp

@@ -171,9 +171,10 @@ void SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
 #ifndef NO_KF5_AUTH
         if (dbusreply.errorMessage() == "Interactive authentication required.")
         {
-            Action action("fancontrol.gui.helper.dbusaction");
+            Action action("fancontrol.gui.helper.action");
             action.setHelperId("fancontrol.gui.helper");
             QVariantMap map;
+            map["action"] = "dbusaction";
             map["method"] = method;
             map["arguments"] = arguments;
             action.setArguments(map);