loader.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <malte.veerman@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef LOADER_H
  20. #define LOADER_H
  21. #include <QtCore/QObject>
  22. #include <QtCore/QUrl>
  23. #include <QtCore/QList>
  24. #include <QtCore/QString>
  25. #include <QtCore/QPair>
  26. class QTimer;
  27. class KJob;
  28. class QProcess;
  29. namespace Fancontrol
  30. {
  31. class Hwmon;
  32. class PwmFan;
  33. class Temp;
  34. class Fan;
  35. class GUIBase;
  36. class Loader : public QObject
  37. {
  38. Q_OBJECT
  39. Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
  40. Q_PROPERTY(QString configPath READ configPath NOTIFY configUrlChanged)
  41. Q_PROPERTY(QString config READ config NOTIFY configChanged)
  42. Q_PROPERTY(QList<QObject *> hwmons READ hwmonsAsObjects NOTIFY hwmonsChanged)
  43. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  44. Q_PROPERTY(bool sensorsDetected READ sensorsDetected NOTIFY sensorsDetectedChanged)
  45. Q_PROPERTY(bool restartServiceAfterTesting READ restartServiceAfterTesting WRITE setRestartServiceAfterTesting NOTIFY restartServiceAfterTestingChanged)
  46. Q_PROPERTY(bool needsSave READ needsSave NOTIFY needsSaveChanged)
  47. public:
  48. explicit Loader(GUIBase *parent = Q_NULLPTR);
  49. Q_INVOKABLE void parseHwmons();
  50. Q_INVOKABLE bool load(const QUrl & = QUrl());
  51. Q_INVOKABLE bool save(const QUrl & = QUrl());
  52. Q_INVOKABLE void testFans();
  53. Q_INVOKABLE void abortTestingFans();
  54. Q_INVOKABLE void detectSensors();
  55. QUrl configUrl() const { return m_configUrl; }
  56. QString configPath() const { return m_configUrl.path(); }
  57. QString config() const { return m_config; }
  58. QList<Hwmon *> hwmons() const { return m_hwmons; }
  59. bool sensorsDetected() const { return m_sensorsDetected; }
  60. bool restartServiceAfterTesting() const { return m_reactivateAfterTesting; }
  61. void setRestartServiceAfterTesting(bool restart);
  62. QList<QObject *> hwmonsAsObjects() const;
  63. int interval() const { return m_interval; }
  64. void setInterval(int interval, bool writeNewConfig = true);
  65. PwmFan *pwmFan(const QPair<int, int> &indexPair) const { return pwmFan(indexPair.first, indexPair.second); }
  66. Temp *temp(const QPair<int, int> &indexPair) const { return temp(indexPair.first, indexPair.second); }
  67. Fan *fan(const QPair<int, int> &indexPair) const { return fan(indexPair.first, indexPair.second); }
  68. PwmFan *pwmFan(int hwmonIndex, int pwmFanIndex) const;
  69. Temp *temp(int hwmonIndex, int tempIndex) const;
  70. Fan *fan(int hwmonIndex, int fanIndex) const;
  71. void toDefault();
  72. bool needsSave() const { return m_config != m_configFileContent; }
  73. public slots:
  74. void updateConfig();
  75. void handleDetectSensorsResult(KJob *job);
  76. void handleDetectSensorsResult(int exitCode);
  77. void handleTestStatusChanged();
  78. protected:
  79. bool parseConfig(QString config);
  80. void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value));
  81. QPair<int, int> getEntryNumbers(const QString &entry);
  82. QString createConfig() const;
  83. QList<Hwmon *> m_hwmons;
  84. private:
  85. bool m_reactivateAfterTesting;
  86. int m_interval;
  87. QUrl m_configUrl;
  88. QString m_config;
  89. QString m_configFileContent;
  90. QTimer *m_timer;
  91. bool m_sensorsDetected;
  92. signals:
  93. void configUrlChanged();
  94. void configChanged();
  95. void hwmonsChanged();
  96. void intervalChanged();
  97. void error(QString, bool = false);
  98. void info(QString);
  99. void sensorsUpdateNeeded();
  100. void invalidConfigUrl();
  101. void sensorsDetectedChanged();
  102. void restartServiceAfterTestingChanged();
  103. void requestSetServiceActive(bool);
  104. void needsSaveChanged();
  105. };
  106. }
  107. #endif // LOADER_H