mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
add several active profiles support to de and plasmoid
This commit is contained in:
parent
87376f1a5c
commit
1907d3ac2f
@ -151,7 +151,7 @@ bool Netctl::sourceRequestEvent(const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto)
|
QStringList Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
getNetctlAutoStatus(cmdNetctlAuto);
|
||||||
@ -166,15 +166,14 @@ QString Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetc
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
currentProfile = QString("");
|
QStringList currentProfile;
|
||||||
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
|
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
|
||||||
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts);
|
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts);
|
||||||
for (int i=0; i<profileList.count(); i++)
|
for (int i=0; i<profileList.count(); i++)
|
||||||
if (profileList[i][0] == QChar('*')) {
|
if (profileList[i][0] == QChar('*'))
|
||||||
currentProfile = profileList[i];
|
currentProfile.append(profileList[i]);
|
||||||
break;
|
for (int i=0; i<currentProfile.count(); i++)
|
||||||
}
|
currentProfile[i].remove(0, 2);
|
||||||
currentProfile.remove(0, 2);
|
|
||||||
|
|
||||||
return currentProfile;
|
return currentProfile;
|
||||||
}
|
}
|
||||||
@ -276,21 +275,26 @@ QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNet
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Netctl::getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto)
|
QStringList Netctl::getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
getNetctlAutoStatus(cmdNetctlAuto);
|
||||||
|
|
||||||
QString status = QString("static");
|
QStringList status;
|
||||||
if (netctlAutoStatus)
|
if (netctlAutoStatus)
|
||||||
status = QString("netctl-auto");
|
status.append(QString("netctl-auto"));
|
||||||
else {
|
else {
|
||||||
TaskResult process = runTask(cmdNetctl + QString(" is-enabled ") + getCurrentProfile(cmdNetctl, cmdNetctlAuto));
|
QStringList profiles = getCurrentProfile(cmdNetctl, cmdNetctlAuto);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
for (int i=0; i<profiles.count(); i++) {
|
||||||
if (process.exitCode != 0)
|
TaskResult process = runTask(cmdNetctl + QString(" is-enabled ") + profiles[i]);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode == 0)
|
if (process.exitCode != 0)
|
||||||
status = QString("enabled");
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
if (process.exitCode == 0)
|
||||||
|
status.append(QString("enabled"));
|
||||||
|
else
|
||||||
|
status.append(QString("static"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -303,7 +307,7 @@ QString Netctl::getStatus(const QString cmdNetctl, const QString cmdNetctlAuto)
|
|||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
getNetctlAutoStatus(cmdNetctlAuto);
|
||||||
|
|
||||||
QString status = QString("false");
|
QString status = QString("false");
|
||||||
QString currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto);
|
QStringList currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto);
|
||||||
if (!currentProfile.isEmpty())
|
if (!currentProfile.isEmpty())
|
||||||
status = QString("true");
|
status = QString("true");
|
||||||
|
|
||||||
@ -322,7 +326,8 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
configuration[QString("NETCTLAUTOCMD")]);
|
configuration[QString("NETCTLAUTOCMD")]);
|
||||||
} else if (source == QString("current")) {
|
} else if (source == QString("current")) {
|
||||||
value = getCurrentProfile(configuration[QString("NETCTLCMD")],
|
value = getCurrentProfile(configuration[QString("NETCTLCMD")],
|
||||||
configuration[QString("NETCTLAUTOCMD")]);
|
configuration[QString("NETCTLAUTOCMD")])
|
||||||
|
.join(QChar('|'));
|
||||||
} else if (source == QString("extip4")) {
|
} else if (source == QString("extip4")) {
|
||||||
if (configuration[QString("EXTIP4")] == QString("true"))
|
if (configuration[QString("EXTIP4")] == QString("true"))
|
||||||
value = getExtIp(configuration[QString("EXTIP4CMD")]);
|
value = getExtIp(configuration[QString("EXTIP4CMD")]);
|
||||||
@ -343,7 +348,8 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
.join(QChar(','));
|
.join(QChar(','));
|
||||||
} else if (source == QString("status")) {
|
} else if (source == QString("status")) {
|
||||||
value = getProfileStringStatus(configuration[QString("NETCTLCMD")],
|
value = getProfileStringStatus(configuration[QString("NETCTLCMD")],
|
||||||
configuration[QString("NETCTLAUTOCMD")]);
|
configuration[QString("NETCTLAUTOCMD")])
|
||||||
|
.join(QChar('|'));
|
||||||
}
|
}
|
||||||
setData(source, QString("value"), value);
|
setData(source, QString("value"), value);
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ class Netctl : public Plasma::DataEngine
|
|||||||
public:
|
public:
|
||||||
Netctl(QObject *parent, const QVariantList &args);
|
Netctl(QObject *parent, const QVariantList &args);
|
||||||
~Netctl();
|
~Netctl();
|
||||||
QString getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QStringList getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto);
|
||||||
QString getExtIp(const QString cmd);
|
QString getExtIp(const QString cmd);
|
||||||
QStringList getInterfaceList();
|
QStringList getInterfaceList();
|
||||||
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
|
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
|
||||||
QString getNetctlAutoStatus(const QString cmdNetctlAuto);
|
QString getNetctlAutoStatus(const QString cmdNetctlAuto);
|
||||||
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
|
||||||
QString getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QStringList getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
||||||
QString getStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QString getStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -352,6 +352,24 @@ void Netctl::stopProfileSlot()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Netctl::stopAllProfilesSlot()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
sendNotification(QString("Info"), i18n("Stop all profiles"));
|
||||||
|
if (useHelper)
|
||||||
|
sendDBusRequest(QString("StopAll"), QList<QVariant>());
|
||||||
|
else {
|
||||||
|
QProcess command;
|
||||||
|
QString commandLine = QString("");
|
||||||
|
if (useSudo)
|
||||||
|
commandLine = paths[QString("sudo")] + QString(" ");
|
||||||
|
commandLine += paths[QString("netctl")] + QString(" stop-all ");
|
||||||
|
command.startDetached(commandLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Netctl::switchToProfileSlot(QAction *profile)
|
void Netctl::switchToProfileSlot(QAction *profile)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -405,6 +423,7 @@ QList<QAction*> Netctl::contextualActions()
|
|||||||
if (info[QString("status")] == QString("(netctl-auto)")) {
|
if (info[QString("status")] == QString("(netctl-auto)")) {
|
||||||
contextMenu[QString("start")]->setVisible(false);
|
contextMenu[QString("start")]->setVisible(false);
|
||||||
contextMenu[QString("stop")]->setVisible(false);
|
contextMenu[QString("stop")]->setVisible(false);
|
||||||
|
contextMenu[QString("stopall")]->setVisible(false);
|
||||||
contextMenu[QString("switch")]->setVisible(true);
|
contextMenu[QString("switch")]->setVisible(true);
|
||||||
contextMenu[QString("restart")]->setVisible(false);
|
contextMenu[QString("restart")]->setVisible(false);
|
||||||
contextMenu[QString("enable")]->setVisible(false);
|
contextMenu[QString("enable")]->setVisible(false);
|
||||||
@ -414,11 +433,21 @@ QList<QAction*> Netctl::contextualActions()
|
|||||||
switchToProfileMenu->addAction(profile);
|
switchToProfileMenu->addAction(profile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
contextMenu[QString("start")]->setVisible(true);
|
if (info[QString("current")].contains(QChar('|'))) {
|
||||||
contextMenu[QString("stop")]->setVisible(status);
|
contextMenu[QString("start")]->setVisible(true);
|
||||||
contextMenu[QString("switch")]->setVisible(false);
|
contextMenu[QString("stop")]->setVisible(false);
|
||||||
contextMenu[QString("restart")]->setVisible(status);
|
contextMenu[QString("stopall")]->setVisible(true);
|
||||||
contextMenu[QString("enable")]->setVisible(status);
|
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(status);
|
||||||
|
contextMenu[QString("stopall")]->setVisible(false);
|
||||||
|
contextMenu[QString("switch")]->setVisible(false);
|
||||||
|
contextMenu[QString("restart")]->setVisible(status);
|
||||||
|
contextMenu[QString("enable")]->setVisible(status);
|
||||||
|
}
|
||||||
if (status) {
|
if (status) {
|
||||||
contextMenu[QString("start")]->setText(i18n("Start another profile"));
|
contextMenu[QString("start")]->setText(i18n("Start another profile"));
|
||||||
contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("current")]));
|
contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("current")]));
|
||||||
@ -465,6 +494,11 @@ void Netctl::createActions()
|
|||||||
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
|
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
|
||||||
menuActions.append(contextMenu[QString("stop")]);
|
menuActions.append(contextMenu[QString("stop")]);
|
||||||
|
|
||||||
|
contextMenu[QString("stopall")] = new QAction(i18n("Stop all profiles"), this);
|
||||||
|
contextMenu[QString("stopall")]->setIcon(QIcon::fromTheme("dialog-close"));
|
||||||
|
connect(contextMenu[QString("stopall")], SIGNAL(triggered(bool)), this, SLOT(stopAllProfilesSlot()));
|
||||||
|
menuActions.append(contextMenu[QString("stopall")]);
|
||||||
|
|
||||||
contextMenu[QString("switch")] = new QAction(i18n("Switch to profile"), this);
|
contextMenu[QString("switch")] = new QAction(i18n("Switch to profile"), this);
|
||||||
contextMenu[QString("switch")]->setIcon(QIcon::fromTheme("dialog-apply"));
|
contextMenu[QString("switch")]->setIcon(QIcon::fromTheme("dialog-apply"));
|
||||||
switchToProfileMenu = new QMenu(NULL);
|
switchToProfileMenu = new QMenu(NULL);
|
||||||
|
@ -87,6 +87,7 @@ private slots:
|
|||||||
void restartProfileSlot();
|
void restartProfileSlot();
|
||||||
void startProfileSlot(QAction *profile);
|
void startProfileSlot(QAction *profile);
|
||||||
void stopProfileSlot();
|
void stopProfileSlot();
|
||||||
|
void stopAllProfilesSlot();
|
||||||
void switchToProfileSlot(QAction *profile);
|
void switchToProfileSlot(QAction *profile);
|
||||||
// helper
|
// helper
|
||||||
void checkHelperStatus();
|
void checkHelperStatus();
|
||||||
|
Loading…
Reference in New Issue
Block a user