mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
add test support of several active profiles to gui, library and helper
This commit is contained in:
parent
f238ba3a6a
commit
87376f1a5c
@ -138,10 +138,11 @@ bool MainWindow::startProfileSlot(const QString profile)
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QString currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
QStringList currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
|
||||
QList<QVariant>(), true, debug)[0].toString();
|
||||
if ((currentProfile.isEmpty()) || (currentProfile == profile))
|
||||
QList<QVariant>(), 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<QVariant>(), true, debug);
|
||||
else
|
||||
netctlCommand->stopAllProfiles();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::switchToProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
@ -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; i<currentProfiles.count(); i++)
|
||||
statusList.append(netctlCommand->getProfileStatus(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<netctlProfileInfo> 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<QVariant>(), true, debug), debug);
|
||||
if (netctlAutoStatus) {
|
||||
QList<QVariant> args;
|
||||
args.append(current);
|
||||
if (netctlAutoStatus)
|
||||
enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
enabled = QString::number(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,
|
||||
args, true, debug)[0].toBool());
|
||||
} else {
|
||||
QStringList currentProfiles = current.split(QChar('|'));
|
||||
QStringList enabledList;
|
||||
for (int i=0; i<currentProfiles.count(); i++) {
|
||||
QList<QVariant> 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();
|
||||
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; i<currentProfiles.count(); i++)
|
||||
enabledList.append(QString::number(netctlCommand->isProfileEnabled(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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)");
|
||||
status.append(QApplication::translate("TrayIcon", "(netctl-auto)"));
|
||||
else {
|
||||
for (int i=0; i<enabled.split(QChar('|')).count(); i++)
|
||||
if (enabled.split(QChar('|'))[i] == QString("0"))
|
||||
status.append(QApplication::translate("TrayIcon", "static"));
|
||||
else
|
||||
status = QApplication::translate("TrayIcon", "(static)");
|
||||
contextMenu[QString("title")]->setText(current + QString(" ") + status);
|
||||
status.append(QApplication::translate("TrayIcon", "enabled"));
|
||||
}
|
||||
contextMenu[QString("title")]->setText(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);
|
||||
@ -117,17 +122,27 @@ void TrayIcon::updateMenu()
|
||||
QAction *profile = new QAction(profiles[i], this);
|
||||
switchToProfileMenu->addAction(profile);
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
|
@ -45,6 +45,7 @@ private slots:
|
||||
bool restartProfileSlot();
|
||||
bool startProfileSlot(QAction *action);
|
||||
bool stopProfileSlot();
|
||||
bool stopAllProfilesSlot();
|
||||
bool switchToProfileSlot(QAction *action);
|
||||
|
||||
private:
|
||||
|
@ -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)
|
||||
|
@ -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; i<profiles.count(); i++)
|
||||
status.append(netctlCommand->getProfileStatus(profiles[i]));
|
||||
return status.join(QChar('|'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 ""
|
||||
|
@ -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<netctlProfileInfo> fullProfilesInfo = getProfileList();
|
||||
for (int i=0; i<fullProfilesInfo.count(); i++)
|
||||
if (fullProfilesInfo[i].active) {
|
||||
profile = fullProfilesInfo[i].name;
|
||||
break;
|
||||
}
|
||||
if (fullProfilesInfo[i].active)
|
||||
profile.append(fullProfilesInfo[i].name);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
@ -23,6 +23,35 @@
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
void TestNetctl::createTestProfile()
|
||||
{
|
||||
QMap<QString, QString> settings = NetctlProfile::getRecommendedConfiguration();
|
||||
settings[QString("FORCE_SUDO")] = QString("true");
|
||||
NetctlProfile *netctl = new NetctlProfile(false, settings);
|
||||
|
||||
QMap<QString, QString> 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<QString, QString> 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,10 @@ class TestNetctl : public QObject
|
||||
private slots:
|
||||
void test_getRecommendedConfiguration();
|
||||
void test_getActiveProfile();
|
||||
|
||||
private:
|
||||
void createTestProfile();
|
||||
void removeTestProfile();
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user