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/dbusoperation.cpp b/sources/gui/src/dbusoperation.cpp index c548bcf..ef15f1d 100644 --- a/sources/gui/src/dbusoperation.cpp +++ b/sources/gui/src/dbusoperation.cpp @@ -23,12 +23,11 @@ #include +#include "version.h" -QList parseOutputNetctl(const QList raw, - const bool debug) + +QList parseOutputNetctl(const QList raw) { - if (debug) qDebug() << PDEBUG; - QList profileInfo; if (raw.isEmpty()) return profileInfo; QStringList list = raw[0].toStringList(); @@ -47,11 +46,8 @@ QList parseOutputNetctl(const QList raw, } -QList parseOutputWifi(const QList raw, - const bool debug) +QList parseOutputWifi(const QList raw) { - if (debug) qDebug() << PDEBUG; - QList wifiInfo; if (raw.isEmpty()) return wifiInfo; QStringList list = raw[0].toStringList(); @@ -71,28 +67,61 @@ QList parseOutputWifi(const QList raw, } -QList sendDBusRequest(const QString service, const QString path, - const QString interface, const QString cmd, - const QList args, const bool system, - const bool debug) +QList sendRequestToHelper(const QString path, const QString cmd, + const QList args, const bool debug) { if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Service" << service; - if (debug) qDebug() << PDEBUG << ":" << "Path" << path; - if (debug) qDebug() << PDEBUG << ":" << "Interface" << interface; if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "args" << args; - if (debug) qDebug() << PDEBUG << ":" << "is system bus" << system; - QDBusConnection bus = QDBusConnection::sessionBus(); - if (system) - bus = QDBusConnection::systemBus(); - QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); + QDBusConnection bus = QDBusConnection::systemBus(); + QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, path, + DBUS_HELPER_INTERFACE, cmd); if (!args.isEmpty()) request.setArguments(args); QDBusMessage response = bus.call(request, QDBus::BlockWithGui); QList arguments = response.arguments(); - if (arguments.count() == 0) + if (arguments.isEmpty()) if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage(); return arguments; } + + +QList sendRequestToCtrl(const QString cmd, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + + return sendRequestToCtrlWithArgs(cmd, QList(), debug); +} + + +QList sendRequestToCtrlWithArgs(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_CTRL_PATH, cmd, args, debug); +} + + +QList sendRequestToLib(const QString cmd, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + + return sendRequestToLibWithArgs(cmd, QList(), debug); +} + + +QList sendRequestToLibWithArgs(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_LIB_PATH, cmd, args, debug); +} diff --git a/sources/gui/src/dbusoperation.h b/sources/gui/src/dbusoperation.h index 947a63d..1db5f53 100644 --- a/sources/gui/src/dbusoperation.h +++ b/sources/gui/src/dbusoperation.h @@ -23,14 +23,16 @@ #include -QList parseOutputNetctl(const QList raw, - const bool debug = false); -QList parseOutputWifi(const QList raw, - const bool debug = false); -QList sendDBusRequest(const QString service, const QString path, - const QString interface, const QString cmd, - const QList args = QList(), - const bool system = true, const bool debug = false); +QList parseOutputNetctl(const QList raw); +QList parseOutputWifi(const QList raw); +QList sendRequestToHelper(const QString path, const QString cmd, + const QList args, const bool debug = false); +QList sendRequestToCtrl(const QString cmd, const bool debug = false); +QList sendRequestToCtrlWithArgs(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); #endif /* DBUSOPERATION_H */ diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 8cebece..2b24be3 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -43,7 +43,7 @@ bool existingSessionOperation(const QString operation) QDBusMessage response = bus.call(request); QList arguments = response.arguments(); - return (!arguments.isEmpty() && bool(arguments[0].toInt())); + return (!arguments.isEmpty() && arguments[0].toBool()); } diff --git a/sources/gui/src/mainprivateslots.cpp b/sources/gui/src/mainprivateslots.cpp index 9b20016..3815124 100644 --- a/sources/gui/src/mainprivateslots.cpp +++ b/sources/gui/src/mainprivateslots.cpp @@ -169,18 +169,14 @@ void MainWindow::updateMainTab() QList profiles; bool netctlAutoStatus = false; if (useHelper) { - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"), - QList(), true, debug); + QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; return updateMainTab(); } netctlAutoStatus = responce[0].toBool(); - profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ProfileList"), - QList(), true, debug), debug); + profiles = parseOutputNetctl(sendRequestToLib(QString("ProfileList"), debug)); } else { netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); profiles = netctlCommand->getProfileList(); @@ -272,9 +268,7 @@ void MainWindow::updateWifiTab() ui->tabWidget->setDisabled(true); QList scanResults; if (useHelper) - scanResults = parseOutputWifi(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("WiFi"), - QList(), true, debug), debug); + scanResults = parseOutputWifi(sendRequestToCtrl(QString("WiFi"), debug)); else scanResults = wpaCommand->scanWifi(); @@ -464,9 +458,7 @@ void MainWindow::mainTabRemoveProfile() if (useHelper) { QList args; args.append(profile); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Remove"), - args, true, debug); + QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; @@ -538,9 +530,7 @@ void MainWindow::mainTabStopAllProfiles() ui->tabWidget->setDisabled(true); bool status = false; if (useHelper) { - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("StopAll"), - QList(), true, debug); + QList responce = sendRequestToCtrl(QString("StolAll"), debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; @@ -608,9 +598,7 @@ void MainWindow::profileTabClear() ui->comboBox_profile->clear(); QList profiles; if (useHelper) - profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ProfileList"), - QList(), true, debug), debug); + profiles = parseOutputNetctl(sendRequestToLib(QString("ProfileList"), debug)); else profiles = netctlCommand->getProfileList(); for (int i=0; i args; args.append(profile); args.append(settingsList); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Create"), - args, true, debug); + QList responce = sendRequestToCtrlWithArgs(QString("Create"), args, debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; @@ -826,9 +812,7 @@ void MainWindow::profileTabLoadProfile() if (useHelper) { QList args; args.append(profile); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Profile"), - args, true, debug); + QList responce = sendRequestToLibWithArgs(QString("Profile"), args, debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; @@ -893,9 +877,7 @@ void MainWindow::profileTabRemoveProfile() if (useHelper) { QList args; args.append(profile); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Remove"), - args, true, debug); + QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; @@ -996,9 +978,7 @@ void MainWindow::wifiTabStart() if (useHelper) { QList args; args.append(profile); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ProfileByEssid"), - args, true, debug); + QList responce = sendRequestToLibWithArgs(QString("ProfileByEssid"), args, debug); if (responce.isEmpty()) { if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; useHelper = false; diff --git a/sources/gui/src/mainpublicslots.cpp b/sources/gui/src/mainpublicslots.cpp index 9424e2e..0a8f3b1 100644 --- a/sources/gui/src/mainpublicslots.cpp +++ b/sources/gui/src/mainpublicslots.cpp @@ -91,12 +91,8 @@ bool MainWindow::enableProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Enable"), - args, true, debug); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileEnabled"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("Enable"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); if (responce.isEmpty()) current = netctlCommand->isProfileEnabled(profile); else @@ -119,12 +115,8 @@ bool MainWindow::restartProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Restart"), - args, true, debug)[0].toBool(); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileActive"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("Restart"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); if (responce.isEmpty()) current = netctlCommand->isProfileActive(profile); else @@ -147,22 +139,14 @@ bool MainWindow::startProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ActiveProfile"), - QList(), true, debug); + QList responce = sendRequestToLib(QString("ActiveProfile"), debug); QStringList currentProfile; if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Start"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("Start"), args, debug); else - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("SwitchTo"), - args, true, debug); - responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileActive"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); if (responce.isEmpty()) current = netctlCommand->isProfileActive(profile); else @@ -185,9 +169,7 @@ bool MainWindow::stopAllProfilesSlot() if (debug) qDebug() << PDEBUG; if (useHelper) - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("StopAll"), - QList(), true, debug); + sendRequestToCtrl(QString("StolAll"), debug); else netctlCommand->stopAllProfiles(); @@ -202,9 +184,7 @@ bool MainWindow::switchToProfileSlot(const QString profile) bool netctlAutoStatus = false; if (useHelper) { - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"), - QList(), true, debug); + QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); } else netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); @@ -214,12 +194,8 @@ bool MainWindow::switchToProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("autoStart"), - args, true, debug); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("autoIsProfileActive"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); if (responce.isEmpty()) current = netctlCommand->autoIsProfileActive(profile); else @@ -232,12 +208,8 @@ bool MainWindow::switchToProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("SwitchTo"), - args, true, debug); - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileActive"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); if (responce.isEmpty()) current = netctlCommand->isProfileActive(profile); else @@ -309,9 +281,7 @@ bool MainWindow::forceStopHelper() { if (debug) qDebug() << PDEBUG; - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Close"), - QList(), true, debug); + QList responce = sendRequestToCtrl(QString("Close"), debug); return !responce.isEmpty(); } @@ -436,9 +406,7 @@ void MainWindow::connectToUnknownEssid(const QString passwd) if (passwdWid != nullptr) delete passwdWid; QStringList interfaces; if (useHelper) { - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("WirelessInterfaces"), - QList(), true, debug); + QList responce = sendRequestToLib(QString("WirelessInterfaces"), debug); if (responce.isEmpty()) interfaces = netctlCommand->getWirelessInterfaceList(); else @@ -474,9 +442,7 @@ void MainWindow::connectToUnknownEssid(const QString passwd) QList args; args.append(profile); args.append(settingsList); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Create"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("Create"), args, debug); } else { QString profileTempName = netctlProfile->createProfile(profile, settings); netctlProfile->copyProfile(profileTempName); @@ -501,9 +467,7 @@ void MainWindow::connectToUnknownEssid(const QString passwd) if (useHelper) { QList args; args.append(profile); - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Remove"), - args, true, debug); + sendRequestToCtrlWithArgs(QString("Remove"), args, debug); } else netctlProfile->removeProfile(profile); break; diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index fc2e7f6..9a21a1a 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -123,11 +123,14 @@ QStringList MainWindow::printInformation() output.append(QString("none")); output.append(QString("(none)")); if (useHelper) { - QStringList request = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("Information"), - QList(), true, debug)[0].toStringList(); - if (request.count() != 2) return output; - output = request; + QList responce = sendRequestToLib(QString("Information"), debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return printInformation(); + } + if (responce[0].toStringList().count() != 2) return output; + output = responce[0].toStringList(); } else { if (netctlCommand->isNetctlAutoRunning()) { output[0] = netctlCommand->autoGetActiveProfile(); @@ -168,31 +171,34 @@ QStringList MainWindow::printTrayInformation() bool netctlAutoStatus = false; QList profiles; if (useHelper) { - current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ActiveProfile"), - QList(), true, debug)[0].toString(); - netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"), - QList(), true, debug)[0].toBool(); - profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ProfileList"), - QList(), true, debug), debug); + QList responce = sendRequestToLib(QString("ActiveProfile"), debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return printTrayInformation(); + } + current = responce[0].toString(); + responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return printTrayInformation(); + } + netctlAutoStatus = responce[0].toBool(); + profiles = parseOutputNetctl(sendRequestToLib(QString("ProfileList"), debug)); if (netctlAutoStatus) { QList args; args.append(current); - enabled = QString::number(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("autoIsProfileEnabled"), - args, true, debug)[0].toBool()); + responce = sendRequestToLibWithArgs(QString("autoIsProfileEnabled"), args, debug); + enabled = QString::number(!responce.isEmpty() && responce[0].toBool()); } else { QStringList currentProfiles = current.split(QChar('|')); QStringList enabledList; for (int i=0; i args; args.append(currentProfiles[i]); - enabledList.append(QString::number( - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileEnabled"), - args, true, debug)[0].toBool())); + responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); + enabledList.append(QString::number(!responce.isEmpty() && responce[0].toBool())); enabled = enabledList.join(QChar('|')); } } @@ -229,11 +235,9 @@ bool MainWindow::isHelperActive() { if (debug) qDebug() << PDEBUG; - QList responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Active"), - QList(), true, debug); + QList responce = sendRequestToCtrl(QString("Active"), debug); - return (!responce.isEmpty() && bool(responce[0].toInt())); + return (!responce.isEmpty() && responce[0].toBool()); } @@ -312,9 +316,7 @@ bool MainWindow::checkHelperStatus() if (useHelper) useHelper = isHelperActive(); if (useHelper) - sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, - DBUS_HELPER_INTERFACE, QString("Update"), - QList(), true, debug); + sendRequestToCtrl(QString("Update"), debug); else configuration[QString("FORCE_SUDO")] = QString("true"); if (isHelperServiceActive()) diff --git a/sources/helper/src/main.cpp b/sources/helper/src/main.cpp index c48588f..4de0f8e 100644 --- a/sources/helper/src/main.cpp +++ b/sources/helper/src/main.cpp @@ -43,7 +43,7 @@ bool existingSessionOperation(const QString operation) QDBusMessage response = bus.call(request); QList arguments = response.arguments(); - return (!arguments.isEmpty() && bool(arguments[0].toInt())); + return (!arguments.isEmpty() && arguments[0].toBool()); }