mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-08-24 09:49:55 +00:00
add test support of several active profiles to gui, library and helper
This commit is contained in:
@ -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,
|
||||
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
|
||||
QList<QVariant>(), true, debug)[0].toString();
|
||||
if ((currentProfile.isEmpty()) || (currentProfile == profile))
|
||||
QStringList currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
|
||||
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);
|
||||
QList<QVariant> 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<QVariant> 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<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()));
|
||||
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)");
|
||||
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; i<enabled.split(QChar('|')).count(); i++)
|
||||
if (enabled.split(QChar('|'))[i] == QString("0"))
|
||||
status.append(QApplication::translate("TrayIcon", "static"));
|
||||
else
|
||||
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);
|
||||
@ -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;
|
||||
|
@ -45,6 +45,7 @@ private slots:
|
||||
bool restartProfileSlot();
|
||||
bool startProfileSlot(QAction *action);
|
||||
bool stopProfileSlot();
|
||||
bool stopAllProfilesSlot();
|
||||
bool switchToProfileSlot(QAction *action);
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user