diff --git a/sources/gui/src/mainpublicslots.cpp b/sources/gui/src/mainpublicslots.cpp index a5d58c1..0c3fc6a 100644 --- a/sources/gui/src/mainpublicslots.cpp +++ b/sources/gui/src/mainpublicslots.cpp @@ -138,10 +138,11 @@ bool MainWindow::startProfileSlot(const QString profile) if (useHelper) { QList args; args.append(profile); - QString currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("ActiveProfile"), - QList(), true, debug)[0].toString(); - if ((currentProfile.isEmpty()) || (currentProfile == profile)) + QStringList currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, + DBUS_HELPER_INTERFACE, QString("ActiveProfile"), + QList(), true, debug)[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); @@ -153,8 +154,8 @@ bool MainWindow::startProfileSlot(const QString profile) DBUS_HELPER_INTERFACE, QString("isProfileActive"), args, true, debug)[0].toBool(); } else { - QString currentProfile = netctlCommand->getActiveProfile(); - if ((currentProfile.isEmpty()) || (currentProfile == profile)) + QStringList currentProfile = netctlCommand->getActiveProfile(); + if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) netctlCommand->startProfile(profile); else netctlCommand->switchToProfile(profile); @@ -165,6 +166,21 @@ bool MainWindow::startProfileSlot(const QString profile) } +bool MainWindow::stopAllProfilesSlot() +{ + if (debug) qDebug() << PDEBUG; + + if (useHelper) + sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, + DBUS_HELPER_INTERFACE, QString("StopAll"), + QList(), true, debug); + else + netctlCommand->stopAllProfiles(); + + return true; +} + + bool MainWindow::switchToProfileSlot(const QString profile) { if (debug) qDebug() << PDEBUG; diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index fa7f72b..b987d72 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -132,8 +132,12 @@ QStringList MainWindow::printInformation() profile = netctlCommand->autoGetActiveProfile(); status = QString("netctl-auto"); } else { - profile = netctlCommand->getActiveProfile(); - status = netctlCommand->getProfileStatus(profile); + QStringList currentProfiles = netctlCommand->getActiveProfile(); + profile = currentProfiles.join(QChar('|')); + QStringList statusList; + for (int i=0; igetProfileStatus(currentProfiles[i])); + status = statusList.join(QChar('|')); } } QStringList output; @@ -163,7 +167,7 @@ QStringList MainWindow::printTrayInformation() QStringList information; QString current; - bool enabled = false; + QString enabled; bool netctlAutoStatus = false; QList profiles; if (useHelper) { @@ -176,25 +180,38 @@ QStringList MainWindow::printTrayInformation() profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, DBUS_HELPER_INTERFACE, QString("ProfileList"), QList(), true, debug), debug); - QList args; - args.append(current); - if (netctlAutoStatus) - enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("autoIsProfileEnabled"), - args, true, debug)[0].toBool(); - else - enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, - DBUS_HELPER_INTERFACE, QString("isProfileEnabled"), - args, true, debug)[0].toBool(); + 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()); + } 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())); + enabled = enabledList.join(QChar('|')); + } + } } else { netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); if (netctlAutoStatus) { current = netctlCommand->autoGetActiveProfile(); - enabled = netctlCommand->autoIsProfileEnabled(current); + enabled = QString::number(netctlCommand->autoIsProfileEnabled(current)); profiles = netctlCommand->getProfileListFromNetctlAuto(); } else { - current = netctlCommand->getActiveProfile(); - enabled = netctlCommand->isProfileEnabled(current); + QStringList currentProfiles = netctlCommand->getActiveProfile(); + current = currentProfiles.join(QChar('|')); + QStringList enabledList; + for (int i=0; iisProfileEnabled(currentProfiles[i]))); + enabled = enabledList.join(QChar('|')); profiles = netctlCommand->getProfileList(); } } @@ -205,7 +222,7 @@ QStringList MainWindow::printTrayInformation() profileList.append(profiles[i].name); information.append(profileList.join(QChar('|'))); information.append(current); - information.append(QString::number(enabled)); + information.append(enabled); return information; } diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index e3b741d..97ccb2b 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -76,6 +76,7 @@ public slots: // trayicon control slots bool enableProfileSlot(const QString profile); bool startProfileSlot(const QString profile); + bool stopAllProfilesSlot(); bool switchToProfileSlot(const QString profile); bool restartProfileSlot(const QString profile); // open docs diff --git a/sources/gui/src/trayicon.cpp b/sources/gui/src/trayicon.cpp index e3d3dc7..f16187b 100644 --- a/sources/gui/src/trayicon.cpp +++ b/sources/gui/src/trayicon.cpp @@ -89,26 +89,31 @@ void TrayIcon::updateMenu() bool netctlAutoStatus = info[0].toInt(); QStringList profiles = info[1].split(QChar('|')); QString current = info[2]; - bool enabled = info[3].toInt(); + QString enabled = info[3]; if (current.isEmpty()) { contextMenu[QString("title")]->setIcon(QIcon(QString(":network-offline-64x64"))); contextMenu[QString("title")]->setText(QApplication::translate("TrayIcon", "(inactive)")); } else { contextMenu[QString("title")]->setIcon(QIcon(QString(":network-idle-64x64"))); - QString status; + QStringList status; if (netctlAutoStatus) - status = QApplication::translate("TrayIcon", "(netctl-auto)"); - else if (enabled) - status = QApplication::translate("TrayIcon", "(enabled)"); - else - status = QApplication::translate("TrayIcon", "(static)"); - contextMenu[QString("title")]->setText(current + QString(" ") + status); + status.append(QApplication::translate("TrayIcon", "(netctl-auto)")); + else { + for (int i=0; isetText(current + QString(" ") + + QString("(") + status.join(QChar('|')) + QString(")")); } if (netctlAutoStatus) { contextMenu[QString("start")]->setVisible(false); contextMenu[QString("stop")]->setVisible(false); + contextMenu[QString("stopall")]->setVisible(false); contextMenu[QString("switch")]->setVisible(true); contextMenu[QString("restart")]->setVisible(false); contextMenu[QString("enable")]->setVisible(false); @@ -118,16 +123,26 @@ void TrayIcon::updateMenu() switchToProfileMenu->addAction(profile); } } else { - contextMenu[QString("start")]->setVisible(true); - contextMenu[QString("stop")]->setVisible(!current.isEmpty()); - contextMenu[QString("switch")]->setVisible(false); - contextMenu[QString("restart")]->setVisible(!current.isEmpty()); - contextMenu[QString("enable")]->setVisible(!current.isEmpty()); + if (current.contains(QChar('|'))) { + contextMenu[QString("start")]->setVisible(true); + contextMenu[QString("stop")]->setVisible(false); + contextMenu[QString("stopall")]->setVisible(true); + contextMenu[QString("switch")]->setVisible(false); + contextMenu[QString("restart")]->setVisible(false); + contextMenu[QString("enable")]->setVisible(false); + } else { + contextMenu[QString("start")]->setVisible(true); + contextMenu[QString("stop")]->setVisible(!current.isEmpty()); + contextMenu[QString("switch")]->setVisible(false); + contextMenu[QString("stopall")]->setVisible(false); + contextMenu[QString("restart")]->setVisible(!current.isEmpty()); + contextMenu[QString("enable")]->setVisible(!current.isEmpty()); + } if (!current.isEmpty()) { contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start another profile")); contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(current)); contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(current)); - if (enabled) + if (enabled.split(QChar('|'))[0].toInt()) contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(current)); else contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(current)); @@ -168,6 +183,10 @@ void TrayIcon::createActions() connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot())); menuActions->addAction(contextMenu[QString("stop")]); + contextMenu[QString("stopall")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop all profiles"), this); + connect(contextMenu[QString("stopall")], SIGNAL(triggered(bool)), this, SLOT(stopAllProfilesSlot())); + menuActions->addAction(contextMenu[QString("stopall")]); + contextMenu[QString("switch")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Switch to profile"), this); switchToProfileMenu = new QMenu(); contextMenu[QString("switch")]->setMenu(switchToProfileMenu); @@ -277,6 +296,14 @@ bool TrayIcon::stopProfileSlot() } +bool TrayIcon::stopAllProfilesSlot() +{ + if (debug) qDebug() << PDEBUG; + + return mainWindow->stopAllProfilesSlot(); +} + + bool TrayIcon::switchToProfileSlot(QAction *action) { if (debug) qDebug() << PDEBUG; diff --git a/sources/gui/src/trayicon.h b/sources/gui/src/trayicon.h index e595eb0..9207d88 100644 --- a/sources/gui/src/trayicon.h +++ b/sources/gui/src/trayicon.h @@ -45,6 +45,7 @@ private slots: bool restartProfileSlot(); bool startProfileSlot(QAction *action); bool stopProfileSlot(); + bool stopAllProfilesSlot(); bool switchToProfileSlot(QAction *action); private: diff --git a/sources/helper/src/CMakeLists.txt b/sources/helper/src/CMakeLists.txt index d0ebd96..befdbed 100644 --- a/sources/helper/src/CMakeLists.txt +++ b/sources/helper/src/CMakeLists.txt @@ -54,7 +54,9 @@ endif() add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) +add_executable (${SUBPROJECT}-suid ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) +target_link_libraries (${SUBPROJECT}-suid ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) # install properties install (TARGETS ${SUBPROJECT} DESTINATION bin) -install (TARGETS ${SUBPROJECT} DESTINATION bin RENAME ${SUBPROJECT}-suid +install (TARGETS ${SUBPROJECT}-suid DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE SETUID) diff --git a/sources/helper/src/netctladaptor.cpp b/sources/helper/src/netctladaptor.cpp index fa6b136..a2051ff 100644 --- a/sources/helper/src/netctladaptor.cpp +++ b/sources/helper/src/netctladaptor.cpp @@ -42,7 +42,7 @@ QString NetctlAdaptor::ActiveProfile() if (isNetctlAutoActive()) return netctlCommand->autoGetActiveProfile(); else - return netctlCommand->getActiveProfile(); + return netctlCommand->getActiveProfile().join(QChar('|')); } @@ -50,8 +50,13 @@ QString NetctlAdaptor::ActiveProfileStatus() { if (isNetctlAutoActive()) return QString("netctl-auto"); - else - return netctlCommand->getProfileStatus(ActiveProfile()); + else { + QStringList status; + QStringList profiles = ActiveProfile().split(QChar('|')); + for (int i=0; igetProfileStatus(profiles[i])); + return status.join(QChar('|')); + } } diff --git a/sources/netctlgui/include/netctlgui/netctlinteract.h b/sources/netctlgui/include/netctlgui/netctlinteract.h index 76109be..52c3b9a 100644 --- a/sources/netctlgui/include/netctlgui/netctlinteract.h +++ b/sources/netctlgui/include/netctlgui/netctlinteract.h @@ -86,7 +86,7 @@ public: * @brief method which returns active profile name * @return profile name or "" */ - QString getActiveProfile(); + QStringList getActiveProfile(); /** * @brief method which returns active profile name from netctl-auto * @return profile name or "" diff --git a/sources/netctlgui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp index 6384796..55454a5 100644 --- a/sources/netctlgui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -147,17 +147,15 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri /** * @fn getActiveProfile */ -QString Netctl::getActiveProfile() +QStringList Netctl::getActiveProfile() { if (debug) qDebug() << PDEBUG; - QString profile = QString(""); + QStringList profile; QList fullProfilesInfo = getProfileList(); for (int i=0; i +void TestNetctl::createTestProfile() +{ + QMap settings = NetctlProfile::getRecommendedConfiguration(); + settings[QString("FORCE_SUDO")] = QString("true"); + NetctlProfile *netctl = new NetctlProfile(false, settings); + + QMap profileSettings; + profileSettings["Connection"] = QString("dummy"); + profileSettings["Description"] = QString("Simple test profile"); + profileSettings["IP"] = QString("no"); + profileSettings["IP6"] = QString("no"); + profileSettings["Interface"] = QString("test"); + + netctl->copyProfile(netctl->createProfile(QString("aaatest"), settings)); + delete netctl; +} + + +void TestNetctl::removeTestProfile() +{ + QMap settings = NetctlProfile::getRecommendedConfiguration(); + settings[QString("FORCE_SUDO")] = QString("true"); + NetctlProfile *netctl = new NetctlProfile(false, settings); + + netctl->removeProfile(QString("aaatest")); + delete netctl; +} + + void TestNetctl::test_getRecommendedConfiguration() { QStringList original; @@ -56,7 +85,15 @@ void TestNetctl::test_getActiveProfile() settings[QString("FORCE_SUDO")] = QString("true"); Netctl *netctl = new Netctl(false, settings); + createTestProfile(); + netctl->startProfile(QString("aaatest")); + QString original = QString("aaatest"); + QString result = netctl->getActiveProfile(); + netctl->startProfile(QString("aaatest")); + removeTestProfile(); delete netctl; + + QCOMPARE(result, original); } diff --git a/sources/test/testnetctl.h b/sources/test/testnetctl.h index 1166293..18851a3 100644 --- a/sources/test/testnetctl.h +++ b/sources/test/testnetctl.h @@ -28,6 +28,10 @@ class TestNetctl : public QObject private slots: void test_getRecommendedConfiguration(); void test_getActiveProfile(); + +private: + void createTestProfile(); + void removeTestProfile(); };