diff --git a/sources/.kdev4/sources.kdev4 b/sources/.kdev4/sources.kdev4 index d7d83c5..587b19d 100644 --- a/sources/.kdev4/sources.kdev4 +++ b/sources/.kdev4/sources.kdev4 @@ -8,7 +8,7 @@ ProjectRootRelative=./ [CMake][CMake Build Directory 0] Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build -Build Type=Release +Build Type=Debug CMake Binary=file:///usr/bin/cmake Environment Profile= Extra Arguments= diff --git a/sources/gui/src/calls.cpp b/sources/gui/src/calls.cpp index dbde957..d86e6ab 100644 --- a/sources/gui/src/calls.cpp +++ b/sources/gui/src/calls.cpp @@ -24,160 +24,93 @@ #include "dbusoperation.h" -bool enableProfileSlot(const QString profile, Netctl *netctlCommand, - const bool useHelper, const bool debug) +InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - bool current; - if (useHelper) { - // enable + if (!useHelper) return interface->enableProfile(profile); + try { QList args; args.append(profile); - sendRequestToCtrlWithArgs(QString("Enable"), args, debug); - // check - QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileEnabled(profile); - else - current = responce[0].toBool(); - } else { - // enable - netctlCommand->enableProfile(profile); - // check - current = netctlCommand->isProfileEnabled(profile); + int responce = sendRequestToInterfaceWithArgs(QString("Enable"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; } - - return current; } -bool restartProfileSlot(const QString profile, Netctl *netctlCommand, - const bool useHelper, const bool debug) +InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - bool current; - if (useHelper) { - // restart + if (!useHelper) return interface->restartProfile(profile); + try { QList args; args.append(profile); - sendRequestToCtrlWithArgs(QString("Restart"), args, debug); - // check - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - // restart - netctlCommand->restartProfile(profile); - // check - current = netctlCommand->isProfileActive(profile); + int responce = sendRequestToInterfaceWithArgs(QString("Restart"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; } - - return current; } -bool startProfileSlot(const QString profile, Netctl *netctlCommand, - const bool useHelper, const bool debug) +InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - bool current; - if (useHelper) { - // get current + if (!useHelper) return interface->startProfile(profile); + try { QList args; args.append(profile); - QList responce = sendRequestToLib(QString("ActiveProfile"), debug); - QStringList currentProfile; - if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); - // start or switch - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - sendRequestToCtrlWithArgs(QString("Start"), args, debug); - else - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - // check - responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - // get current - QStringList currentProfile = netctlCommand->getActiveProfile(); - // start or switch - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - netctlCommand->startProfile(profile); - else - netctlCommand->switchToProfile(profile); - // check - current = netctlCommand->isProfileActive(profile); + int responce = sendRequestToInterfaceWithArgs(QString("Start"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; } - - return current; } -bool MainWindow::stopAllProfilesSlot() +InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper, + const bool debug) { if (debug) qDebug() << PDEBUG; - if (useHelper) - sendRequestToCtrl(QString("StolAll"), debug); - else - netctlCommand->stopAllProfiles(); - - return true; + if (!useHelper) return interface->stopAllProfiles(); + try { + int responce = sendRequestToInterface(QString("StopAll"), debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; + } } -bool MainWindow::switchToProfileSlot(const QString profile) +InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - bool netctlAutoStatus = false; - if (useHelper) { - QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); - } else - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - - bool current; - if (netctlAutoStatus) { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->autoIsProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->autoStartProfile(profile); - current = netctlCommand->autoIsProfileActive(profile); - } - } else { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->switchToProfile(profile); - current = netctlCommand->isProfileActive(profile); - } + if (!useHelper) return interface->switchToProfile(profile); + try { + QList args; + args.append(profile); + int responce = sendRequestToInterfaceWithArgs(QString("SwitchTo"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; } - - return current; } diff --git a/sources/gui/src/calls.h b/sources/gui/src/calls.h index a63468c..cde7c26 100644 --- a/sources/gui/src/calls.h +++ b/sources/gui/src/calls.h @@ -24,8 +24,16 @@ #include -bool enableProfileSlot(const QString profile, Netctl *netctlCommand, - const bool useHelper, const bool debug = false); +InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug = false); +InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug = false); +InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug = false); +InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper, + const bool debug); +InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug); #endif /* CALLS_H */ diff --git a/sources/gui/src/dbusoperation.cpp b/sources/gui/src/dbusoperation.cpp index f242dd6..0ccf3d1 100644 --- a/sources/gui/src/dbusoperation.cpp +++ b/sources/gui/src/dbusoperation.cpp @@ -114,6 +114,26 @@ QList sendRequestToCtrlWithArgs(const QString cmd, const QList sendRequestToInterface(const QString cmd, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + + return sendRequestToInterfaceWithArgs(cmd, QList(), debug); +} + + +QList sendRequestToInterfaceWithArgs(const QString cmd, const QList args, + const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "args" << args; + + return sendRequestToHelper(DBUS_INTERFACE_PATH, cmd, args, debug); +} + + QList sendRequestToLib(const QString cmd, const bool debug) { if (debug) qDebug() << PDEBUG; diff --git a/sources/gui/src/dbusoperation.h b/sources/gui/src/dbusoperation.h index 1db5f53..26d79c8 100644 --- a/sources/gui/src/dbusoperation.h +++ b/sources/gui/src/dbusoperation.h @@ -30,6 +30,9 @@ QList sendRequestToHelper(const QString path, const QString cmd, QList sendRequestToCtrl(const QString cmd, const bool debug = false); QList sendRequestToCtrlWithArgs(const QString cmd, const QList args, const bool debug = false); +QList sendRequestToInterface(const QString cmd, const bool debug = false); +QList sendRequestToInterfaceWithArgs(const QString cmd, const QList args, + const bool debug = false); QList sendRequestToLib(const QString cmd, const bool debug = false); QList sendRequestToLibWithArgs(const QString cmd, const QList args, const bool debug = false); diff --git a/sources/helper/src/interfaceadaptor.cpp b/sources/helper/src/interfaceadaptor.cpp new file mode 100644 index 0000000..3f2ed6a --- /dev/null +++ b/sources/helper/src/interfaceadaptor.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * 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 "interfaceadaptor.h" + +#include +#include + +#include "netctlhelper.h" +#include "version.h" + + +InterfaceAdaptor::InterfaceAdaptor(QObject *parent, const bool debugCmd, const QMap configuration) + : QDBusAbstractAdaptor(parent), + debug(debugCmd) +{ + netctlInterface = new NetctlInterface(debug, configuration); +} + + +InterfaceAdaptor::~InterfaceAdaptor() +{ + if (netctlInterface != nullptr) delete netctlInterface; +} + + +int InterfaceAdaptor::autoEnable(const QString profile) +{ + return netctlInterface->autoEnableProfile(profile); +} + + +int InterfaceAdaptor::Create(const QString profile, const QStringList settingsList) +{ + QMap settings; + for (int i=0; icreateProfile(profile, settings); +} + + +int InterfaceAdaptor::Enable(const QString profile) +{ + return netctlInterface->enableProfile(profile); +} + + +int InterfaceAdaptor::Essid(const QString essid, QStringList settingsList) +{ + QMap settings; + for (int i=0; iconnectToEssid(essid, settings); +} + + +int InterfaceAdaptor::KnownEssid(const QString essid) +{ + return netctlInterface->connectToKnownEssid(essid); +} + + +int InterfaceAdaptor::Restart(const QString profile) +{ + return netctlInterface->restartProfile(profile); +} + + +int InterfaceAdaptor::Start(const QString profile) +{ + return netctlInterface->startProfile(profile); +} + + +int InterfaceAdaptor::StopAll() +{ + return netctlInterface->stopAllProfiles(); +} + + +int InterfaceAdaptor::SwitchTo(const QString profile) +{ + return netctlInterface->switchToProfile(profile); +} + + +int InterfaceAdaptor::UnknownEssid(const QString essid, QStringList settingsList) +{ + QMap settings; + for (int i=0; iconnectToUnknownEssid(essid, settings); +} diff --git a/sources/helper/src/interfaceadaptor.h b/sources/helper/src/interfaceadaptor.h new file mode 100644 index 0000000..f9f10b2 --- /dev/null +++ b/sources/helper/src/interfaceadaptor.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * 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 INTERFACEADAPTOR_H +#define INTERFACEADAPTOR_H + +#include + +#include + + +class InterfaceAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.netctlgui.helper") + +public: + explicit InterfaceAdaptor(QObject *parent = 0, + const bool debugCmd = false, + const QMap configuration = QMap()); + ~InterfaceAdaptor(); + +public slots: + // interface + int autoEnable(const QString profile); + int Create(const QString profile, const QStringList settingsList); + int Enable(const QString profile); + int Essid(const QString essid, QStringList settingsList); + int KnownEssid(const QString essid); + int Restart(const QString profile); + int Start(const QString profile); + int StopAll(); + int SwitchTo(const QString profile); + int UnknownEssid(const QString essid, QStringList settingsList); + +private: + bool debug; + NetctlInterface *netctlInterface = nullptr; +}; + + +#endif /* INTERFACEADAPTOR_H */ diff --git a/sources/helper/src/netctlhelper.cpp b/sources/helper/src/netctlhelper.cpp index f7f5ee1..46ce53b 100644 --- a/sources/helper/src/netctlhelper.cpp +++ b/sources/helper/src/netctlhelper.cpp @@ -28,6 +28,7 @@ #include #include "controladaptor.h" +#include "interfaceadaptor.h" #include "netctladaptor.h" #include "version.h" @@ -88,6 +89,13 @@ void NetctlHelper::createInterface() if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message(); return quitHelper(); } + if (!bus.registerObject(DBUS_INTERFACE_PATH, + new InterfaceAdaptor(this, debug, configuration), + QDBusConnection::ExportAllContents)) { + if (debug) qDebug() << PDEBUG << ":" << "Could not register interface object"; + if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message(); + return quitHelper(); + } // session bus if (!session) return; QDBusConnection sessionBus = QDBusConnection::sessionBus(); @@ -107,6 +115,13 @@ void NetctlHelper::createInterface() if (debug) qDebug() << PDEBUG << ":" << "Could not register session control object"; if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message(); } + if (!sessionBus.registerObject(DBUS_INTERFACE_PATH, + new InterfaceAdaptor(this, debug, configuration), + QDBusConnection::ExportAllContents)) { + if (debug) qDebug() << PDEBUG << ":" << "Could not register session interface object"; + if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message(); + return quitHelper(); + } } @@ -116,11 +131,13 @@ void NetctlHelper::deleteInterface() QDBusConnection::systemBus().unregisterObject(DBUS_LIB_PATH); QDBusConnection::systemBus().unregisterObject(DBUS_CTRL_PATH); + QDBusConnection::systemBus().unregisterObject(DBUS_INTERFACE_PATH); QDBusConnection::systemBus().unregisterService(DBUS_HELPER_SERVICE); // session bus if (!session) return; QDBusConnection::sessionBus().unregisterObject(DBUS_LIB_PATH); QDBusConnection::sessionBus().unregisterObject(DBUS_CTRL_PATH); + QDBusConnection::sessionBus().unregisterObject(DBUS_INTERFACE_PATH); QDBusConnection::sessionBus().unregisterService(DBUS_HELPER_SERVICE); } @@ -176,6 +193,14 @@ QMap NetctlHelper::getSettings(const QString file) config[QString("PREFERED_IFACE")] = settings.value(QString("PREFERED_IFACE"), QString("")).toString(); settings.endGroup(); + settings.beginGroup(QString("Toolbars")); + config[QString("MAIN_TOOLBAR")] = settings.value(QString("MAIN_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("NETCTL_TOOLBAR")] = settings.value(QString("NETCTL_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("NETCTLAUTO_TOOLBAR")] = settings.value(QString("NETCTLAUTO_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("PROFILE_TOOLBAR")] = settings.value(QString("PROFILE_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("WIFI_TOOLBAR")] = settings.value(QString("WIFI_TOOLBAR"), Qt::TopToolBarArea).toString(); + settings.endGroup(); + for (int i=0; istopAllProfiles()) + return InterfaceAnswer::True; + else + return InterfaceAnswer::Error; +} + + /** * @fn switchToProfile */ diff --git a/sources/version.h.in b/sources/version.h.in index 1649fd2..989f576 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -49,6 +49,7 @@ #define DBUS_HELPER_SERVICE "org.netctlgui.helper" #define DBUS_HELPER_INTERFACE "org.netctlgui.helper" #define DBUS_CTRL_PATH "/ctrl" +#define DBUS_INTERFACE_PATH "/interface" #define DBUS_LIB_PATH "/netctl" #endif /* VERSION_H */