loader.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #include "fancontrol_gui_lib_export.h"
  27. class QTimer;
  28. class KJob;
  29. namespace Fancontrol
  30. {
  31. class Hwmon;
  32. class PwmFan;
  33. class Temp;
  34. class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
  35. {
  36. Q_OBJECT
  37. Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
  38. Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
  39. Q_PROPERTY(QList<QObject *> hwmons READ hwmons NOTIFY hwmonsChanged)
  40. Q_PROPERTY(QList<QObject *> allPwmFans READ allPwmFans NOTIFY allPwmFansChanged)
  41. Q_PROPERTY(QList<QObject *> allTemps READ allTemps NOTIFY allTempsChanged)
  42. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  43. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  44. public:
  45. explicit Loader(QObject *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<QObject *> hwmons() const;
  55. QList<QObject *> allPwmFans() const;
  56. QList<QObject *> allTemps() const;
  57. int interval() const { return m_interval; }
  58. void setInterval(int interval, bool writeNewConfig = true);
  59. QString error() const { return m_error; }
  60. static QPair<int, int> getEntryNumbers(const QString &entry);
  61. public slots:
  62. void updateSensors() { emit sensorsUpdateNeeded(); }
  63. protected slots:
  64. void createConfigFile();
  65. void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
  66. void emitAllTempsChanged() { emit allTempsChanged(); }
  67. void setError(const QString &error, bool critical = false);
  68. void handleDetectSensorsResult(KJob *job);
  69. protected:
  70. void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value)) const;
  71. private:
  72. PwmFan *getPwmFan(const QPair<int, int> &indexPair) const;
  73. Temp *getTemp(const QPair<int, int> &indexPair) const;
  74. int m_interval;
  75. QList<Hwmon *> m_hwmons;
  76. QUrl m_configUrl;
  77. QString m_configFile;
  78. QString m_error;
  79. QTimer *m_timer;
  80. signals:
  81. void configUrlChanged();
  82. void configFileChanged();
  83. void hwmonsChanged();
  84. void intervalChanged();
  85. void errorChanged();
  86. void sensorsUpdateNeeded();
  87. void allPwmFansChanged();
  88. void allTempsChanged();
  89. void invalidConfigUrl();
  90. void criticalError();
  91. };
  92. }
  93. #endif // LOADER_H