mirror of
				https://github.com/arcan1s/netctl-gui.git
				synced 2025-10-31 13:43:42 +00:00 
			
		
		
		
	add several active profiles support to de and plasmoid
This commit is contained in:
		| @ -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; | ||||
|     getNetctlAutoStatus(cmdNetctlAuto); | ||||
| @ -166,15 +166,14 @@ QString Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetc | ||||
|     if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; | ||||
|     if (process.exitCode != 0) | ||||
|         if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; | ||||
|     currentProfile = QString(""); | ||||
|     QStringList currentProfile; | ||||
|     QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output); | ||||
|     QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts); | ||||
|     for (int i=0; i<profileList.count(); i++) | ||||
|         if (profileList[i][0] == QChar('*')) { | ||||
|             currentProfile = profileList[i]; | ||||
|             break; | ||||
|         } | ||||
|     currentProfile.remove(0, 2); | ||||
|         if (profileList[i][0] == QChar('*')) | ||||
|             currentProfile.append(profileList[i]); | ||||
|     for (int i=0; i<currentProfile.count(); i++) | ||||
|         currentProfile[i].remove(0, 2); | ||||
|  | ||||
|     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; | ||||
|     getNetctlAutoStatus(cmdNetctlAuto); | ||||
|  | ||||
|     QString status = QString("static"); | ||||
|     QStringList status; | ||||
|     if (netctlAutoStatus) | ||||
|         status = QString("netctl-auto"); | ||||
|         status.append(QString("netctl-auto")); | ||||
|     else { | ||||
|         TaskResult process = runTask(cmdNetctl + QString(" is-enabled ") + getCurrentProfile(cmdNetctl, cmdNetctlAuto)); | ||||
|         QStringList profiles = getCurrentProfile(cmdNetctl, cmdNetctlAuto); | ||||
|         for (int i=0; i<profiles.count(); i++) { | ||||
|             TaskResult process = runTask(cmdNetctl + QString(" is-enabled ") + profiles[i]); | ||||
|             if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; | ||||
|             if (process.exitCode != 0) | ||||
|                 if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; | ||||
|             if (process.exitCode == 0) | ||||
|             status = QString("enabled"); | ||||
|                 status.append(QString("enabled")); | ||||
|             else | ||||
|                 status.append(QString("static")); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return status; | ||||
| @ -303,7 +307,7 @@ QString Netctl::getStatus(const QString cmdNetctl, const QString cmdNetctlAuto) | ||||
|     getNetctlAutoStatus(cmdNetctlAuto); | ||||
|  | ||||
|     QString status = QString("false"); | ||||
|     QString currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto); | ||||
|     QStringList currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto); | ||||
|     if (!currentProfile.isEmpty()) | ||||
|         status = QString("true"); | ||||
|  | ||||
| @ -322,7 +326,8 @@ bool Netctl::updateSourceEvent(const QString &source) | ||||
|                 configuration[QString("NETCTLAUTOCMD")]); | ||||
|     } else if (source == QString("current")) { | ||||
|         value = getCurrentProfile(configuration[QString("NETCTLCMD")], | ||||
|                 configuration[QString("NETCTLAUTOCMD")]); | ||||
|                 configuration[QString("NETCTLAUTOCMD")]) | ||||
|                 .join(QChar('|')); | ||||
|     } else if (source == QString("extip4")) { | ||||
|         if (configuration[QString("EXTIP4")] == QString("true")) | ||||
|             value = getExtIp(configuration[QString("EXTIP4CMD")]); | ||||
| @ -343,7 +348,8 @@ bool Netctl::updateSourceEvent(const QString &source) | ||||
|                 .join(QChar(',')); | ||||
|     } else if (source == QString("status")) { | ||||
|         value = getProfileStringStatus(configuration[QString("NETCTLCMD")], | ||||
|                 configuration[QString("NETCTLAUTOCMD")]); | ||||
|                 configuration[QString("NETCTLAUTOCMD")]) | ||||
|                 .join(QChar('|')); | ||||
|     } | ||||
|     setData(source, QString("value"), value); | ||||
|  | ||||
|  | ||||
| @ -29,13 +29,13 @@ class Netctl : public Plasma::DataEngine | ||||
| public: | ||||
|     Netctl(QObject *parent, const QVariantList &args); | ||||
|     ~Netctl(); | ||||
|     QString getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto); | ||||
|     QStringList getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto); | ||||
|     QString getExtIp(const QString cmd); | ||||
|     QStringList getInterfaceList(); | ||||
|     QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol); | ||||
|     QString getNetctlAutoStatus(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); | ||||
|  | ||||
| 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) | ||||
| { | ||||
|     if (debug) qDebug() << PDEBUG; | ||||
| @ -405,6 +423,7 @@ QList<QAction*> Netctl::contextualActions() | ||||
|     if (info[QString("status")] == QString("(netctl-auto)")) { | ||||
|         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); | ||||
| @ -413,12 +432,22 @@ QList<QAction*> Netctl::contextualActions() | ||||
|             QAction *profile = new QAction(profileList[i], this); | ||||
|             switchToProfileMenu->addAction(profile); | ||||
|         } | ||||
|     } else { | ||||
|         if (info[QString("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(status); | ||||
|             contextMenu[QString("stopall")]->setVisible(false); | ||||
|             contextMenu[QString("switch")]->setVisible(false); | ||||
|             contextMenu[QString("restart")]->setVisible(status); | ||||
|             contextMenu[QString("enable")]->setVisible(status); | ||||
|         } | ||||
|         if (status) { | ||||
|             contextMenu[QString("start")]->setText(i18n("Start another profile")); | ||||
|             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())); | ||||
|     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")]->setIcon(QIcon::fromTheme("dialog-apply")); | ||||
|     switchToProfileMenu = new QMenu(NULL); | ||||
|  | ||||
| @ -87,6 +87,7 @@ private slots: | ||||
|     void restartProfileSlot(); | ||||
|     void startProfileSlot(QAction *profile); | ||||
|     void stopProfileSlot(); | ||||
|     void stopAllProfilesSlot(); | ||||
|     void switchToProfileSlot(QAction *profile); | ||||
|     // helper | ||||
|     void checkHelperStatus(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user