From 891b3b43efedd05c7d619fac8fddb7a891017035 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 6 Aug 2014 22:56:01 +0400 Subject: [PATCH] add control interface --- sources/gui/src/controladaptor.cpp | 108 +++++++++++++++++++++++++++++ sources/gui/src/controladaptor.h | 58 ++++++++++++++++ sources/gui/src/mainwindow.cpp | 5 ++ sources/version.h.in | 1 + 4 files changed, 172 insertions(+) create mode 100644 sources/gui/src/controladaptor.cpp create mode 100644 sources/gui/src/controladaptor.h diff --git a/sources/gui/src/controladaptor.cpp b/sources/gui/src/controladaptor.cpp new file mode 100644 index 0000000..05c4cde --- /dev/null +++ b/sources/gui/src/controladaptor.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "controladaptor.h" + + +ControlAdaptor::ControlAdaptor(QObject *parent, const QMap configuration) + : QDBusAbstractAdaptor(parent) +{ + netctlCommand = new Netctl(false, configuration); + netctlProfile = new NetctlProfile(false, configuration); +} + + +ControlAdaptor::~ControlAdaptor() +{ + delete netctlCommand; + delete netctlProfile; +} + + +// netctlCommand +bool ControlAdaptor::autoDisableAll() +{ + return netctlCommand->autoDisableAllProfiles(); +} + + +bool ControlAdaptor::autoEnable(const QString profile) +{ + return netctlCommand->autoEnableProfile(profile); +} + + +bool ControlAdaptor::autoEnableAll() +{ + return netctlCommand->autoEnableAllProfiles(); +} + + +bool ControlAdaptor::autoStart(const QString profile) +{ + return netctlCommand->autoStartProfile(profile); +} + + +bool ControlAdaptor::autoServiceEnable() +{ + return netctlCommand->autoEnableService(); +} + + +bool ControlAdaptor::autoServiceRestart() +{ + return netctlCommand->autoRestartService(); +} + + +bool ControlAdaptor::autoServiceStart() +{ + return netctlCommand->autoStartService(); +} + + +bool ControlAdaptor::Enable(const QString profile) +{ + return netctlCommand->enableProfile(profile); +} + + +bool ControlAdaptor::Restart(const QString profile) +{ + return netctlCommand->restartProfile(profile); +} + + +bool ControlAdaptor::Start(const QString profile) +{ + return netctlCommand->startProfile(profile); +} + + +bool ControlAdaptor::SwitchTo(const QString profile) +{ + return netctlCommand->switchToProfile(profile); +} + + +// netctlProfile +bool ControlAdaptor::Remove(const QString profile) +{ + return netctlProfile->removeProfile(profile); +} diff --git a/sources/gui/src/controladaptor.h b/sources/gui/src/controladaptor.h new file mode 100644 index 0000000..57d8bc2 --- /dev/null +++ b/sources/gui/src/controladaptor.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef CONTROLADAPTOR_H +#define CONTROLADAPTOR_H + +#include + +#include + + +class ControlAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.netctlgui") + +public: + explicit ControlAdaptor(QObject *parent = 0, + const QMap configuration = QMap()); + ~ControlAdaptor(); + +public slots: + // netctlCommand + bool autoDisableAll(); + bool autoEnable(const QString profile); + bool autoEnableAll(); + bool autoStart(const QString profile); + bool autoServiceEnable(); + bool autoServiceRestart(); + bool autoServiceStart(); + bool Enable(const QString profile); + bool Restart(const QString profile); + bool Start(const QString profile); + bool SwitchTo(const QString profile); + // netctlProfile + bool Remove(const QString profile); + +private: + Netctl *netctlCommand; + NetctlProfile *netctlProfile; +}; + + +#endif /* CONTROLADAPTOR_H */ diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index b340b06..a279738 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -30,6 +30,7 @@ #include "aboutwindow.h" #include "bridgewidget.h" +#include "controladaptor.h" #include "errorwindow.h" #include "ethernetwidget.h" #include "generalwidget.h" @@ -370,6 +371,10 @@ void MainWindow::createDBusSession() new NetctlAdaptor(this, configuration), QDBusConnection::ExportAllContents)) if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register library object"; + if (!bus.registerObject(QString(DBUS_CONTROL_PATH), + new ControlAdaptor(this, configuration), + QDBusConnection::ExportAllContents)) + if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register control object"; } diff --git a/sources/version.h.in b/sources/version.h.in index 81c9494..9cf9096 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -27,6 +27,7 @@ #define PROJECT_BUILD_PLASMOID "@BUILD_PLASMOID@" #define PROJECT_USE_QT5 "@USE_QT5@" +#define DBUS_CONTROL_PATH "/ctrl" #define DBUS_INTERFACE "org.freedesktop.netctlgui" #define DBUS_LIB_PATH "/netctl" #define DBUS_OBJECT_PATH "/netctlgui"