guibase.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "config.h"
  23. #include "guibase.h"
  24. #include "sensors.h"
  25. #include "hwmon.h"
  26. #include <QtQml>
  27. #include <QLocale>
  28. GUIBase::GUIBase(QObject *parent) : QObject(parent),
  29. m_config(Config::instance()),
  30. #ifndef NO_SYSTEMD
  31. m_com(new SystemdCommunicator(m_config->findItem("ServiceName")->property().toString(), this)),
  32. #endif
  33. m_loader(new Loader(this))
  34. {
  35. connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
  36. QLocale locale = QLocale::system();
  37. QLocale::MeasurementSystem system = locale.measurementSystem();
  38. m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
  39. qmlRegisterType<Loader>();
  40. qmlRegisterType<Hwmon>();
  41. qmlRegisterType<Fan>();
  42. qmlRegisterType<PwmFan>();
  43. qmlRegisterType<Temp>();
  44. #ifndef NO_SYSTEMD
  45. qmlRegisterType<SystemdCommunicator>();
  46. #endif
  47. }
  48. qreal GUIBase::maxTemp() const
  49. {
  50. return m_config->findItem("MaxTemp")->property().toReal();
  51. }
  52. qreal GUIBase::minTemp() const
  53. {
  54. return m_config->findItem("MinTemp")->property().toReal();
  55. }
  56. QString GUIBase::serviceName() const
  57. {
  58. return m_config->findItem("ServiceName")->property().toString();
  59. }
  60. int GUIBase::interval() const
  61. {
  62. return m_loader->interval();
  63. }
  64. void GUIBase::setMaxTemp(qreal temp)
  65. {
  66. if (temp != maxTemp())
  67. m_config->findItem("MaxTemp")->setProperty(temp);
  68. }
  69. void GUIBase::setMinTemp(qreal temp)
  70. {
  71. if (temp != minTemp())
  72. m_config->findItem("MinTemp")->setProperty(temp);
  73. }
  74. void GUIBase::setServiceName(const QString& name)
  75. {
  76. if(name != serviceName())
  77. {
  78. m_config->findItem("ServiceName")->setProperty(name);
  79. #ifndef NO_SYSTEMD
  80. m_com->setServiceName(name);
  81. #endif
  82. }
  83. }
  84. void GUIBase::setInterval(int i)
  85. {
  86. m_loader->setInterval(i);
  87. }
  88. void GUIBase::saveConfig()
  89. {
  90. m_config->save();
  91. }