loader.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  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 GUIBase;
  35. class Loader : public QObject
  36. {
  37. Q_OBJECT
  38. Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
  39. Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
  40. Q_PROPERTY(QList<QObject *> hwmons READ hwmonsAsObjects NOTIFY hwmonsChanged)
  41. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  42. Q_PROPERTY(bool sensorsDetected READ sensorsDetected NOTIFY sensorsDetectedChanged)
  43. Q_PROPERTY(bool restartServiceAfterTesting READ restartServiceAfterTesting WRITE setRestartServiceAfterTesting NOTIFY restartServiceAfterTestingChanged)
  44. public:
  45. explicit Loader(GUIBase *parent = Q_NULLPTR);
  46. Q_INVOKABLE void parseHwmons();
  47. Q_INVOKABLE bool load(const QUrl & = QUrl());
  48. Q_INVOKABLE bool save(const QUrl & = QUrl());
  49. Q_INVOKABLE void testFans();
  50. Q_INVOKABLE void abortTestingFans();
  51. Q_INVOKABLE void detectSensors();
  52. QUrl configUrl() const { return m_configUrl; }
  53. QString configFile() const { return m_configFile; }
  54. QList<Hwmon *> hwmons() const { return m_hwmons; }
  55. bool sensorsDetected() const { return m_sensorsDetected; }
  56. bool restartServiceAfterTesting() const { return m_reactivateAfterTesting; }
  57. void setRestartServiceAfterTesting(bool restart);
  58. QList<QObject *> hwmonsAsObjects() const;
  59. int interval() const { return m_interval; }
  60. void setInterval(int interval, bool writeNewConfig = true);
  61. public slots:
  62. void updateSensors() { emit sensorsUpdateNeeded(); }
  63. void updateConfig();
  64. void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
  65. void emitAllTempsChanged() { emit allTempsChanged(); }
  66. void handleDetectSensorsResult(KJob *job);
  67. void handleDetectSensorsResult(int exitCode);
  68. void handleTestStatusChanged();
  69. private:
  70. void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value));
  71. QPair<int, int> getEntryNumbers(const QString &entry);
  72. QString createConfig() const;
  73. PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
  74. Temp *getTemp(const QPair<int, int> &indexPair) const;
  75. bool m_reactivateAfterTesting;
  76. int m_interval;
  77. QList<Hwmon *> m_hwmons;
  78. QUrl m_configUrl;
  79. QString m_configFile;
  80. QTimer *m_timer;
  81. bool m_sensorsDetected;
  82. signals:
  83. void configUrlChanged();
  84. void configFileChanged();
  85. void hwmonsChanged();
  86. void intervalChanged();
  87. void error(QString, bool = false);
  88. void sensorsUpdateNeeded();
  89. void allPwmFansChanged();
  90. void allTempsChanged();
  91. void invalidConfigUrl();
  92. void sensorsDetectedChanged();
  93. void restartServiceAfterTestingChanged();
  94. void requestSetServiceActive(bool);
  95. };
  96. }
  97. #endif // LOADER_H