fancontrolkcm.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "fancontrolkcm.h"
  23. #include <QtQml/qqml.h>
  24. #include <KCoreAddons/KAboutData>
  25. #include <KCoreAddons/KPluginFactory>
  26. #include <KI18n/KLocalizedString>
  27. K_PLUGIN_FACTORY_WITH_JSON(FancontrolKCMFactory, "kcm_fancontrol.json", registerPlugin<FancontrolKCM>();)
  28. FancontrolKCM::FancontrolKCM(QObject *parent, const QVariantList& args)
  29. : ConfigModule(parent, args),
  30. m_base(new GUIBase(this)),
  31. m_manualControl(false)
  32. {
  33. if (!m_base->hasSystemdCommunicator())
  34. qFatal("Fancontrol-gui-lib was compiled without systemd support!");
  35. KAboutData *about = new KAboutData("kcm_fancontrol",
  36. i18n("Fancontrol-KCM"),
  37. "0.1",
  38. i18n("KDE Fancontrol Module"),
  39. KAboutLicense::KAboutLicense::GPL_V2,
  40. "Copyright (C) 2015 Malte Veerman",
  41. QString(),
  42. "http://github.com/maldela/fancontrol-gui",
  43. "http://github.com/maldela/fancontrol-gui/issues");
  44. about->addAuthor(i18n("Malte Veerman"), i18n("Main Developer"), "maldela@halloarsch.de");
  45. setAboutData(about);
  46. setButtons(Apply | Default);
  47. setAuthActionName("fancontrol.gui.helper.action");
  48. connect(m_base->loader(), &Loader::configFileChanged, [this] () { setNeedsSave(true); });
  49. connect(m_base, &GUIBase::minTempChanged, [this] () { setNeedsSave(true); });
  50. connect(m_base, &GUIBase::maxTempChanged, [this] () { setNeedsSave(true); });
  51. connect(m_base, &GUIBase::serviceNameChanged, [this] () { setNeedsSave(true); });
  52. qmlRegisterType<GUIBase>();
  53. }
  54. void FancontrolKCM::save()
  55. {
  56. m_base->save(true);
  57. if (m_base->systemdCommunicator()->serviceActive() && m_manualControl)
  58. m_base->systemdCommunicator()->restartService();
  59. else
  60. m_base->systemdCommunicator()->setServiceActive(m_manualControl);
  61. m_base->systemdCommunicator()->setServiceEnabled(m_manualControl);
  62. setNeedsSave(false);
  63. }
  64. void FancontrolKCM::load()
  65. {
  66. m_base->load();
  67. setManualControl(m_base->systemdCommunicator()->serviceEnabled());
  68. setNeedsSave(false);
  69. }
  70. void FancontrolKCM::defaults()
  71. {
  72. setManualControl(false);
  73. setNeedsSave(true);
  74. }
  75. void FancontrolKCM::setManualControl(bool manualControl)
  76. {
  77. if (m_manualControl != manualControl)
  78. {
  79. m_manualControl = manualControl;
  80. emit manualControlChanged();
  81. setNeedsSave(true);
  82. }
  83. }
  84. #include "fancontrolkcm.moc"