Browse Source

More device fixes

Malte Veerman 5 năm trước cách đây
mục cha
commit
3fc3711fd8
3 tập tin đã thay đổi với 17 bổ sung11 xóa
  1. 6 4
      import/src/fan.cpp
  2. 4 2
      import/src/pwmfan.cpp
  3. 7 5
      import/src/temp.cpp

+ 6 - 4
import/src/fan.cpp

@@ -100,13 +100,15 @@ void Fan::toDefault()
 {
     if (m_rpmStream->device() && parent())
     {
-        auto device = m_rpmStream->device();
+        auto rpmDevice = m_rpmStream->device();
         m_rpmStream->setDevice(Q_NULLPTR);
-        delete device;
+        delete rpmDevice;
 
-        if (QDir(parent()->path()).isReadable())
+        auto path = device() ? parent()->path() + "/device" : parent()->path();
+
+        if (QDir(path).isReadable())
         {
-            const auto rpmFile = new QFile(parent()->path() + "/fan" + QString::number(index()) + "_input", this);
+            const auto rpmFile = new QFile(path + "/fan" + QString::number(index()) + "_input", this);
 
             if (rpmFile->open(QFile::ReadOnly))
             {

+ 4 - 2
import/src/pwmfan.cpp

@@ -161,6 +161,8 @@ void PwmFan::toDefault()
 
     if (m_pwmStream->device() && m_enableStream->device() && parent())
     {
+        auto path = device() ? parent()->path() + "/device" : parent()->path();
+
         auto device = m_pwmStream->device();
         m_pwmStream->setDevice(Q_NULLPTR);
         delete device;
@@ -169,7 +171,7 @@ void PwmFan::toDefault()
         m_enableStream->setDevice(Q_NULLPTR);
         delete device;
 
-        const auto pwmFile = new QFile(parent()->path() + "/pwm" + QString::number(index()), this);
+        const auto pwmFile = new QFile(path + "/pwm" + QString::number(index()), this);
 
         if (pwmFile->open(QFile::ReadWrite))
         {
@@ -187,7 +189,7 @@ void PwmFan::toDefault()
             delete pwmFile;
         }
 
-        const auto pwmEnableFile = new QFile(parent()->path() + "/pwm" + QString::number(index()) + "_enable", this);
+        const auto pwmEnableFile = new QFile(path + "/pwm" + QString::number(index()) + "_enable", this);
 
         if (pwmEnableFile->open(QFile::ReadWrite))
         {

+ 7 - 5
import/src/temp.cpp

@@ -122,13 +122,15 @@ void Temp::toDefault()
 {
     if (m_valueStream->device() && parent())
     {
-        auto device = m_valueStream->device();
+        auto valueDevice = m_valueStream->device();
         m_valueStream->setDevice(Q_NULLPTR);
-        delete device;
+        delete valueDevice;
 
-        if (QDir(parent()->path()).isReadable())
+        auto path = device() ? parent()->path() + "/device" : parent()->path();
+
+        if (QDir(path).isReadable())
         {
-            const auto valueFile = new QFile(parent()->path() + "/temp" + QString::number(index()) + "_input", this);
+            const auto valueFile = new QFile(path + "/temp" + QString::number(index()) + "_input", this);
 
             if (valueFile->open(QFile::ReadOnly))
             {
@@ -137,7 +139,7 @@ void Temp::toDefault()
                 m_value /= 1000;
             }
             else
-                emit error(i18n("Can't open value file: \'%1\'", parent()->path() + "/temp" + QString::number(index()) + "_input"));
+                emit error(i18n("Can't open value file: \'%1\'", valueFile->fileName()));
         }
     }
 }