guibase.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2015 Malte Veerman <malte.veerman@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License or (at your option) version 3 or any later version
  8. * accepted by the membership of KDE e.V. (or its successor approved
  9. * by the membership of KDE e.V.), which shall act as a proxy
  10. * defined in Section 14 of version 3 of the license.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #ifndef GUIBASE_H
  22. #define GUIBASE_H
  23. #include <QtCore/QObject>
  24. #include <QtCore/QUrl>
  25. #include "loader.h"
  26. #include "pwmfanmodel.h"
  27. #include "tempmodel.h"
  28. #ifndef NO_SYSTEMD
  29. #include "systemdcommunicator.h"
  30. #endif
  31. namespace Fancontrol
  32. {
  33. class Config;
  34. class GUIBase : public QObject
  35. {
  36. Q_OBJECT
  37. #ifndef NO_SYSTEMD
  38. Q_PROPERTY(SystemdCommunicator* systemdCom READ systemdCommunicator CONSTANT)
  39. #endif
  40. Q_PROPERTY(PwmFanModel *pwmFanModel READ pwmFanModel CONSTANT)
  41. Q_PROPERTY(TempModel *tempModel READ tempModel CONSTANT)
  42. Q_PROPERTY(Loader* loader READ loader CONSTANT)
  43. Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
  44. Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
  45. Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
  46. Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
  47. Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
  48. Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
  49. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  50. Q_PROPERTY(bool needsApply READ needsApply NOTIFY needsApplyChanged)
  51. public:
  52. explicit GUIBase(QObject *parent = Q_NULLPTR);
  53. Loader *loader() const { return m_loader; }
  54. #ifndef NO_SYSTEMD
  55. SystemdCommunicator *systemdCommunicator() const { return m_com; }
  56. #endif
  57. qreal minTemp() const;
  58. qreal maxTemp() const;
  59. QString serviceName() const;
  60. QUrl configUrl() const;
  61. bool configValid() const { return m_configValid; }
  62. QString unit() const { return m_unit; }
  63. QString error() const { return m_error; }
  64. void setMinTemp(qreal minTemp);
  65. void setMaxTemp(qreal maxTemp);
  66. void setServiceName(const QString &name);
  67. void setConfigUrl(const QUrl &url);
  68. void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(m_unit); } }
  69. bool needsApply() const;
  70. PwmFanModel *pwmFanModel() const { return m_pwmFanModel; }
  71. TempModel *tempModel() const { return m_tempModel; }
  72. Q_INVOKABLE bool hasSystemdCommunicator() const;
  73. Q_INVOKABLE void apply();
  74. Q_INVOKABLE void reset();
  75. public slots:
  76. void load();
  77. void handleError(const QString &error, bool critical = false);
  78. void handleInfo(const QString &info);
  79. signals:
  80. void minTempChanged();
  81. void maxTempChanged();
  82. void serviceNameChanged();
  83. void configUrlChanged();
  84. void unitChanged(QString);
  85. void errorChanged();
  86. void criticalError();
  87. void needsApplyChanged();
  88. private:
  89. QString m_error;
  90. Config *const m_config;
  91. #ifndef NO_SYSTEMD
  92. SystemdCommunicator *const m_com;
  93. #endif
  94. Loader *const m_loader;
  95. QString m_unit;
  96. bool m_configValid;
  97. bool m_configChanged;
  98. PwmFanModel *m_pwmFanModel;
  99. TempModel *m_tempModel;
  100. };
  101. }
  102. #endif // GUIBASE_H