guibase.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/QStringListModel>
  25. #include <QtCore/QUrl>
  26. #include "loader.h"
  27. #include "pwmfanmodel.h"
  28. #include "tempmodel.h"
  29. #ifndef NO_SYSTEMD
  30. #include "systemdcommunicator.h"
  31. #endif
  32. namespace Fancontrol
  33. {
  34. class Config;
  35. class GUIBase : public QObject
  36. {
  37. Q_OBJECT
  38. #ifndef NO_SYSTEMD
  39. Q_PROPERTY(SystemdCommunicator* systemdCom READ systemdCommunicator CONSTANT)
  40. #endif
  41. Q_PROPERTY(PwmFanModel *pwmFanModel READ pwmFanModel CONSTANT)
  42. Q_PROPERTY(TempModel *tempModel READ tempModel CONSTANT)
  43. Q_PROPERTY(QStringListModel *profileModel READ profileModel CONSTANT)
  44. Q_PROPERTY(Loader* loader READ loader CONSTANT)
  45. Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
  46. Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
  47. Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
  48. Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
  49. Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
  50. Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
  51. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  52. Q_PROPERTY(bool needsApply READ needsApply NOTIFY needsApplyChanged)
  53. public:
  54. explicit GUIBase(QObject *parent = Q_NULLPTR);
  55. Loader *loader() const { return m_loader; }
  56. #ifndef NO_SYSTEMD
  57. SystemdCommunicator *systemdCommunicator() const { return m_com; }
  58. #endif
  59. qreal minTemp() const;
  60. qreal maxTemp() const;
  61. QString serviceName() const;
  62. QUrl configUrl() const;
  63. bool configValid() const { return m_configValid; }
  64. QString unit() const { return m_unit; }
  65. QString error() const { return m_error; }
  66. void setMinTemp(qreal minTemp);
  67. void setMaxTemp(qreal maxTemp);
  68. void setServiceName(const QString &name);
  69. void setConfigUrl(const QUrl &url);
  70. void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(m_unit); } }
  71. bool needsApply() const;
  72. PwmFanModel *pwmFanModel() const { return m_pwmFanModel; }
  73. TempModel *tempModel() const { return m_tempModel; }
  74. QStringListModel *profileModel() const { return m_profileModel; }
  75. Q_INVOKABLE bool hasSystemdCommunicator() const;
  76. Q_INVOKABLE void apply();
  77. Q_INVOKABLE void reset();
  78. Q_INVOKABLE void applyProfile(const QString &profile);
  79. Q_INVOKABLE void applyProfile(int);
  80. Q_INVOKABLE void saveProfile(const QString &profile, bool updateModel = true);
  81. Q_INVOKABLE void deleteProfile(const QString &profile, bool updateModel = true);
  82. Q_INVOKABLE void deleteProfile(int, bool updateModel = true);
  83. public slots:
  84. void load();
  85. void handleError(const QString &error, bool critical = false);
  86. void handleInfo(const QString &info);
  87. signals:
  88. void minTempChanged();
  89. void maxTempChanged();
  90. void serviceNameChanged();
  91. void configUrlChanged();
  92. void unitChanged(QString);
  93. void errorChanged();
  94. void criticalError();
  95. void needsApplyChanged();
  96. private:
  97. QString m_error;
  98. Config *const m_config;
  99. #ifndef NO_SYSTEMD
  100. SystemdCommunicator *const m_com;
  101. #endif
  102. Loader *const m_loader;
  103. QString m_unit;
  104. bool m_configValid;
  105. bool m_configChanged;
  106. PwmFanModel *m_pwmFanModel;
  107. TempModel *m_tempModel;
  108. QStringListModel *m_profileModel;
  109. };
  110. }
  111. #endif // GUIBASE_H