Ver Fonte

fixes and improvements in actionreply handling and fan testing

Malte Veerman há 9 anos atrás
pai
commit
7b5cb51710

+ 1 - 0
helper/src/helper.cpp

@@ -128,6 +128,7 @@ ActionReply Helper::action(const QVariantMap &arguments)
             return reply;
         }
     }
+    
     else
     {
         reply.setType(ActionReply::HelperErrorType);

+ 2 - 1
lib/CMakeLists.txt

@@ -9,7 +9,8 @@ set(LIB_SRCS src/hwmon.cpp
                         
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
                           KF5::Auth
-                          KF5::ConfigCore)
+                          KF5::ConfigCore
+                          KF5::I18n)
 
 set(LIB_PUBLIC_LIBRARIES Qt5::Core)
               

+ 48 - 20
lib/src/pwmfan.cpp

@@ -165,6 +165,8 @@ bool PwmFan::setPwm(int pwm, bool write)
 
         if (write)
         {
+            setPwmMode(1);
+            
             if (m_pwmStream->device()->isWritable())
                 *m_pwmStream << pwm;
             else
@@ -195,7 +197,15 @@ void PwmFan::handleSetPwmResult(KJob *job)
 {
     if (job->error())
     {
-        emit errorChanged(i18n("Could not set pwm:") + job->errorString() + job->errorText());
+        if (job->error() == KAuth::ActionReply::HelperBusyError)
+        {
+            qDebug() << "Helper busy...";
+            
+            QTimer::singleShot(50, this, [this] (){ setPwm(m_pwm); });
+            return;
+        }
+        
+        emit errorChanged(i18n("Could not set pwm: ") + job->errorText());
         return;
     }
     update();
@@ -241,7 +251,15 @@ void PwmFan::handleSetPwmModeResult(KJob *job)
 {
     if (job->error())
     {
-        emit errorChanged(i18n("Could not set pwm mode:") + job->errorString() + job->errorText());
+        if (job->error() == KAuth::ActionReply::HelperBusyError)
+        {
+            qDebug() << "Helper busy...";
+            
+            QTimer::singleShot(50, this, [this] (){ setPwmMode(m_pwmMode); });
+            return;
+        }
+        
+        emit errorChanged(i18n("Could not set pwm mode: ") + job->errorText());
         return;
     }
     update();
@@ -256,7 +274,7 @@ bool PwmFan::test()
         emit errorChanged("Test action is invalid");
         return false;
     }
-    KAuth::ExecuteJob *job = action.execute(KAuth::Action::AuthorizeOnlyMode);
+    KAuth::ExecuteJob *job = action.execute();
     connect(job, SIGNAL(result(KJob*)), this, SLOT(handleTestAuthReply(KJob*)));
     job->start();
     
@@ -264,28 +282,23 @@ bool PwmFan::test()
 }
 
 void PwmFan::handleTestAuthReply(KJob *job)
-{
+{  
     if (job->error())
     {
-        m_testStatus = Error;
-        emit testingChanged();
+        if (job->error() == KAuth::ActionReply::HelperBusyError)
+        {
+            qDebug() << "Helper busy...";
+            
+            QTimer::singleShot(100, this, &PwmFan::test);
+            return;
+        }
         
-        emit errorChanged(i18n("Test job error:") + job->errorString() + job->errorText());
-        return;
-    }
-    
-    KAuth::Action action("fancontrol.gui.helper.action");
-    action.setHelperId("fancontrol.gui.helper");
-    if (action.status() != KAuth::Action::AuthorizedStatus)
-    {
+        emit errorChanged(i18n("Authorization error: ") + job->errorText());
         m_testStatus = Error;
         emit testingChanged();
-        
-        emit errorChanged(i18n("Authentication error"));
         return;
     }
-       
-    setPwmMode(1);
+    
     setPwm(255);
     
     m_testStatus = FindingStop1;
@@ -299,8 +312,9 @@ void PwmFan::abortTest()
 {
     if (m_testStatus >= FindingStop1 && m_testStatus <= FindingStart)
     {
-        setPwm(255);
-        disconnect(0, 0, this, SLOT(continueTest()));
+        qDebug() << "Abort testing";
+        
+        disconnect(this, 0, this, SLOT(continueTest()));
 
         m_testStatus = Cancelled;
         emit testingChanged();
@@ -311,6 +325,20 @@ void PwmFan::abortTest()
 
 void PwmFan::continueTest()
 {
+    KAuth::Action action("fancontrol.gui.helper.action");
+    action.setHelperId("fancontrol.gui.helper");
+    if (!action.isValid())
+    {
+        emit errorChanged("Test action is invalid");
+        return;
+    }
+    if (action.status() != KAuth::Action::AuthorizedStatus)
+    {
+        m_testStatus = Error;
+        emit testingChanged();
+        return;
+    }
+    
     update();
     switch (m_testStatus)
     {

+ 39 - 3
lib/src/systemdcommunicator.cpp

@@ -22,6 +22,7 @@
 
 #include <QtCore/QDebug>
 #include <QtCore/QVariant>
+#include <QtCore/QTimer>
 #include <QtDBus/QDBusArgument>
 #include <QtDBus/QDBusInterface>
 
@@ -210,6 +211,7 @@ bool SystemdCommunicator::setServiceEnabled(bool enabled)
 
 bool SystemdCommunicator::setServiceActive(bool active)
 {
+    qDebug() << "Set service active:" << active;
     if (serviceExists())
     {
         if (active != serviceActive())
@@ -223,6 +225,7 @@ bool SystemdCommunicator::setServiceActive(bool active)
                 return true;
             }
         }
+        
         return true;
     }
     return false;
@@ -239,9 +242,14 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
         else
             dbusreply = m_managerInterface->callWithArgumentList(QDBus::AutoDetect, method, arguments);
     }
+    else
+    {
+        qDebug() << "Invalid manager interface!";
+        return false;
+    }
 
     if (dbusreply.type() == QDBusMessage::ErrorMessage)
-    {
+    {      
         if (dbusreply.errorMessage() == "Interactive authentication required.")
         {
             KAuth::Action action("fancontrol.gui.helper.action");
@@ -266,9 +274,26 @@ bool SystemdCommunicator::dbusAction(const QString &method, const QVariantList &
 }
 
 void SystemdCommunicator::handleDbusActionResult(KJob *job)
-{
+{   
     if (job->error())
-        setError(job->errorString() + job->errorText());
+    {
+        if (job->error() == KAuth::ActionReply::HelperBusyError)
+        {
+            qDebug() << "Helper busy...";
+            
+            KAuth::ExecuteJob *executeJob = static_cast<KAuth::ExecuteJob *>(job);
+            if (executeJob)
+            {
+                KAuth::ExecuteJob *newJob = executeJob->action().execute();
+                connect(newJob, SIGNAL(result(KJob*)), this, SLOT(handleDbusActionResult(KJob*)));
+                
+                QTimer::singleShot(50, this, [newJob] (){ newJob->start(); });
+                return;
+            }
+        }
+        
+        setError(job->errorText());
+    }
 }
 
 bool SystemdCommunicator::restartService()
@@ -293,4 +318,15 @@ void SystemdCommunicator::updateServiceProperties(QString, QVariantMap propchang
         emit serviceEnabledChanged();
 }
 
+void SystemdCommunicator::setError(const QString &error)
+{
+    qCritical() << error;
+    
+    if (error != m_error)
+    {
+        m_error = error; 
+        emit errorChanged();
+    }
+}
+
 }

+ 1 - 1
lib/src/systemdcommunicator.h

@@ -72,7 +72,7 @@ protected slots:
 protected:
     
     bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
-    void setError(const QString &error) { if (error != m_error) { m_error = error; emit errorChanged(); } }
+    void setError(const QString &error);
     
     
 private:

+ 1 - 0
package/contents/ui/ErrorDialog.qml

@@ -25,6 +25,7 @@ Dialog {
     property alias text: text.text
     
     title: i18n("Error")
+    width: text.implicitWidth + 20
     standardButtons: StandardButton.Ok
     onAccepted: close()
     

+ 2 - 9
package/contents/ui/PwmFan.qml

@@ -360,22 +360,15 @@ Rectangle {
                 anchors.right: parent.right
                 onClicked: {
                     if (fan.testing) {
+                        systemdCom.serviceActive = reactivateAfterTesting;
                         fan.abortTest();
-                        systemdCom.serviceActive = true;
                     } else {
                         reactivateAfterTesting = systemdCom.serviceActive;
                         systemdCom.serviceActive = false;
                         minStartInput.value = Qt.binding(function() { return Math.round(fan.minStart / 2.55) });
-                        if (!fan.test()) {
-                            systemdCom.serviceActive = reactivateAfterTesting;
-                        }
+                        fan.test();
                     }
                 }
-                
-                Connections {
-                    target: fan
-                    onTestingChanged: if (!fan.testing) systemdCom.serviceActive = testButton.reactivateAfterTesting
-                }
             }
         }
     }