guibase.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * <one line to give the library's name and an idea of what it does.>
  3. * Copyright 2015 Malte Veerman maldela@halloarsch.de
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License or (at your option) version 3 or any later version
  9. * accepted by the membership of KDE e.V. (or its successor approved
  10. * by the membership of KDE e.V.), which shall act as a proxy
  11. * defined in Section 14 of version 3 of the license.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "guibase.h"
  23. #include "config.h"
  24. #include "hwmon.h"
  25. #include <QtQml>
  26. #include <QLocale>
  27. GUIBase::GUIBase(QObject *parent) : QObject(parent),
  28. m_config(Config::instance()),
  29. #ifndef NO_SYSTEMD
  30. m_com(new SystemdCommunicator(m_config->findItem("ServiceName")->property().toString(), this)),
  31. #endif
  32. m_loader(new Loader(this))
  33. {
  34. connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
  35. QLocale locale = QLocale::system();
  36. QLocale::MeasurementSystem system = locale.measurementSystem();
  37. m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
  38. qmlRegisterType<Loader>();
  39. qmlRegisterType<Hwmon>();
  40. qmlRegisterType<Fan>();
  41. qmlRegisterType<PwmFan>();
  42. qmlRegisterType<Temp>();
  43. #ifndef NO_SYSTEMD
  44. qmlRegisterType<SystemdCommunicator>();
  45. #endif
  46. }
  47. void GUIBase::load()
  48. {
  49. m_config->load();
  50. emitConfigChanged();
  51. m_loader->load();
  52. #ifndef NO_SYSTEMD
  53. m_com->setServiceName(m_config->findItem("ServiceName")->property().toString());
  54. #endif
  55. }
  56. void GUIBase::save(bool saveLoader)
  57. {
  58. m_config->save();
  59. if (saveLoader)
  60. m_loader->save();
  61. }
  62. qreal GUIBase::maxTemp() const
  63. {
  64. return m_config->findItem("MaxTemp")->property().toReal();
  65. }
  66. qreal GUIBase::minTemp() const
  67. {
  68. return m_config->findItem("MinTemp")->property().toReal();
  69. }
  70. QString GUIBase::serviceName() const
  71. {
  72. return m_config->findItem("ServiceName")->property().toString();
  73. }
  74. void GUIBase::setMaxTemp(qreal temp)
  75. {
  76. if (temp != maxTemp())
  77. {
  78. m_config->findItem("MaxTemp")->setProperty(temp);
  79. emit maxTempChanged();
  80. }
  81. }
  82. void GUIBase::setMinTemp(qreal temp)
  83. {
  84. if (temp != minTemp())
  85. {
  86. m_config->findItem("MinTemp")->setProperty(temp);
  87. emit minTempChanged();
  88. }
  89. }
  90. void GUIBase::setServiceName(const QString& name)
  91. {
  92. if(name != serviceName())
  93. {
  94. m_config->findItem("ServiceName")->setProperty(name);
  95. #ifndef NO_SYSTEMD
  96. m_com->setServiceName(name);
  97. #endif
  98. emit serviceNameChanged();
  99. }
  100. }
  101. void GUIBase::emitConfigChanged()
  102. {
  103. emit serviceNameChanged();
  104. emit minTempChanged();
  105. emit maxTempChanged();
  106. }