systemdcommunicator.h 2.6 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 "fancontrol_gui_lib_export.h"
  23. class QDBusInterface;
  24. namespace Fancontrol
  25. {
  26. class FANCONTROL_GUI_LIB_EXPORT SystemdCommunicator : public QObject
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  30. Q_PROPERTY(bool serviceExists READ serviceExists NOTIFY serviceNameChanged)
  31. Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
  32. Q_PROPERTY(bool serviceActive READ serviceActive WRITE setServiceActive NOTIFY serviceActiveChanged)
  33. public:
  34. explicit SystemdCommunicator(const QString &serviceName = QString(), QObject *parent = Q_NULLPTR);
  35. QString serviceName() const { return m_serviceName; }
  36. void setServiceName(const QString &name);
  37. bool serviceExists();
  38. bool serviceEnabled();
  39. bool serviceActive();
  40. bool setServiceEnabled(bool enabled);
  41. bool setServiceActive(bool active);
  42. QString error() const { return m_error; }
  43. Q_INVOKABLE bool restartService();
  44. signals:
  45. void serviceNameChanged();
  46. void serviceEnabledChanged();
  47. void serviceActiveChanged();
  48. void errorChanged();
  49. protected slots:
  50. void updateServiceProperties(QString, QVariantMap, QStringList);
  51. protected:
  52. bool dbusAction(const QString &method, const QVariantList &arguments = QVariantList());
  53. void setError(const QString &error) { if (error != m_error) { m_error = error; emit errorChanged(); } }
  54. void success() { setError("Success"); }
  55. private:
  56. QString m_serviceName;
  57. QString m_serviceObjectPath;
  58. QString m_error;
  59. QDBusInterface * const m_managerInterface;
  60. QDBusInterface *m_serviceInterface;
  61. };
  62. }
  63. #endif // SYSTEMDCOMMUNICATOR_H