loader.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <QObject>
  22. #include <QUrl>
  23. #include <QList>
  24. #include <QString>
  25. #include "fancontrol_gui_lib_export.h"
  26. class Hwmon;
  27. class QTimer;
  28. class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
  29. {
  30. Q_OBJECT
  31. Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
  32. Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
  33. Q_PROPERTY(QList<QObject *> hwmons READ hwmons NOTIFY hwmonsChanged)
  34. Q_PROPERTY(QList<QObject *> allPwmFans READ allPwmFans NOTIFY allPwmFansChanged)
  35. Q_PROPERTY(QList<QObject *> allTemps READ allTemps NOTIFY allTempsChanged)
  36. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  37. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  38. public:
  39. explicit Loader(QObject *parent = Q_NULLPTR);
  40. Q_INVOKABLE void parseHwmons();
  41. Q_INVOKABLE bool load(const QUrl & = QUrl());
  42. Q_INVOKABLE bool save(const QUrl & = QUrl());
  43. Q_INVOKABLE void testFans();
  44. QUrl configUrl() const { return m_configUrl; }
  45. QString configFile() const { return m_configFile; }
  46. QList<QObject *> hwmons() const;
  47. QList<QObject *> allPwmFans() const;
  48. QList<QObject *> allTemps() const;
  49. int interval() const { return m_interval; }
  50. void setInterval(int interval, bool writeNewConfig = true);
  51. QString error() const { return m_error; }
  52. static int getHwmonNumber(const QString &str);
  53. static int getSensorNumber(const QString &str);
  54. public slots:
  55. void updateSensors() { emit sensorsUpdateNeeded(); }
  56. protected slots:
  57. void createConfigFile();
  58. void emitAllPwmFansChanged() { emit allPwmFansChanged(); }
  59. void emitAllTempsChanged() { emit allTempsChanged(); }
  60. protected:
  61. void setError(const QString &error);
  62. void success() { setError("Success"); }
  63. int m_interval;
  64. QList<Hwmon *> m_hwmons;
  65. QUrl m_configUrl;
  66. QString m_configFile;
  67. QString m_error;
  68. QTimer *m_timer;
  69. signals:
  70. void configUrlChanged();
  71. void configFileChanged();
  72. void hwmonsChanged();
  73. void intervalChanged();
  74. void errorChanged();
  75. void sensorsUpdateNeeded();
  76. void allPwmFansChanged();
  77. void allTempsChanged();
  78. };
  79. #endif // LOADER_H