guibase.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/qqml.h>
  26. #include <QtCore/QLocale>
  27. namespace Fancontrol
  28. {
  29. GUIBase::GUIBase(QObject *parent) : QObject(parent),
  30. m_config(Config::instance()),
  31. #ifndef NO_SYSTEMD
  32. m_com(new SystemdCommunicator(m_config->findItem("ServiceName")->property().toString(), this)),
  33. #endif
  34. m_loader(new Loader(this))
  35. {
  36. connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
  37. QLocale locale = QLocale::system();
  38. QLocale::MeasurementSystem system = locale.measurementSystem();
  39. m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
  40. qmlRegisterType<Loader>();
  41. qmlRegisterType<Hwmon>();
  42. qmlRegisterType<Fan>();
  43. qmlRegisterType<PwmFan>();
  44. qmlRegisterType<Temp>();
  45. #ifndef NO_SYSTEMD
  46. qmlRegisterType<SystemdCommunicator>();
  47. #endif
  48. }
  49. void GUIBase::load()
  50. {
  51. m_config->load();
  52. emitConfigChanged();
  53. m_loader->load();
  54. #ifndef NO_SYSTEMD
  55. m_com->setServiceName(m_config->findItem("ServiceName")->property().toString());
  56. #endif
  57. }
  58. void GUIBase::save(bool saveLoader)
  59. {
  60. m_config->save();
  61. if (saveLoader)
  62. m_loader->save();
  63. }
  64. qreal GUIBase::maxTemp() const
  65. {
  66. return m_config->findItem("MaxTemp")->property().toReal();
  67. }
  68. qreal GUIBase::minTemp() const
  69. {
  70. return m_config->findItem("MinTemp")->property().toReal();
  71. }
  72. QString GUIBase::serviceName() const
  73. {
  74. return m_config->findItem("ServiceName")->property().toString();
  75. }
  76. void GUIBase::setMaxTemp(qreal temp)
  77. {
  78. if (temp != maxTemp())
  79. {
  80. m_config->findItem("MaxTemp")->setProperty(temp);
  81. emit maxTempChanged();
  82. }
  83. }
  84. void GUIBase::setMinTemp(qreal temp)
  85. {
  86. if (temp != minTemp())
  87. {
  88. m_config->findItem("MinTemp")->setProperty(temp);
  89. emit minTempChanged();
  90. }
  91. }
  92. void GUIBase::setServiceName(const QString& name)
  93. {
  94. if(name != serviceName())
  95. {
  96. m_config->findItem("ServiceName")->setProperty(name);
  97. #ifndef NO_SYSTEMD
  98. m_com->setServiceName(name);
  99. #endif
  100. emit serviceNameChanged();
  101. }
  102. }
  103. void GUIBase::emitConfigChanged()
  104. {
  105. emit serviceNameChanged();
  106. emit minTempChanged();
  107. emit maxTempChanged();
  108. }
  109. }