systemdcommunicator.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef SYSTEMDCOMMUNICATOR_H
  20. #define SYSTEMDCOMMUNICATOR_H
  21. #include <QtCore/QObject>
  22. #include <QtCore/QString>
  23. #include <QtCore/QVariantMap>
  24. #include <QtCore/QVariantList>
  25. class QDBusInterface;
  26. class KJob;
  27. namespace Fancontrol
  28. {
  29. class GUIBase;
  30. class SystemdCommunicator : public QObject
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(bool serviceExists READ serviceExists NOTIFY serviceNameChanged)
  34. Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
  35. Q_PROPERTY(bool serviceActive READ serviceActive WRITE setServiceActive NOTIFY serviceActiveChanged)
  36. public:
  37. explicit SystemdCommunicator(GUIBase *parent = Q_NULLPTR, const QString &serviceName = QString());
  38. QString serviceName() const { return m_serviceName; }
  39. void setServiceName(const QString &name);
  40. bool serviceExists();
  41. bool serviceEnabled();
  42. bool serviceActive();
  43. bool setServiceEnabled(bool enabled);
  44. bool setServiceActive(bool active);
  45. Q_INVOKABLE bool restartService();
  46. signals:
  47. void serviceNameChanged();
  48. void serviceEnabledChanged();
  49. void serviceActiveChanged();
  50. void error(QString, bool = false);
  51. protected slots:
  52. void updateServiceProperties(QString, QVariantMap, QStringList);
  53. void handleDbusActionResult(KJob *job);
  54. protected:
  55. bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
  56. private:
  57. QString m_serviceName;
  58. QString m_serviceObjectPath;
  59. QDBusInterface * const m_managerInterface;
  60. QDBusInterface *m_serviceInterface;
  61. };
  62. }
  63. #endif // SYSTEMDCOMMUNICATOR_H