deSettings;
- deSettings[QString("NETCTLCMD")] = uiDEConfig.lineEdit_netctl->text();
- deSettings[QString("NETCTLAUTOCMD")] = uiDEConfig.lineEdit_netctlAuto->text();
- if (uiDEConfig.checkBox_extIp4->checkState() == 0)
- deSettings[QString("EXTIP4")] = QString("false");
- else
- deSettings[QString("EXTIP4")] = QString("true");
- deSettings[QString("EXTIP4CMD")] = uiDEConfig.lineEdit_extIp4->text();
- if (uiDEConfig.checkBox_extIp6->checkState() == 0)
- deSettings[QString("EXTIP6")] = QString("false");
- else
- deSettings[QString("EXTIP6")] = QString("true");
- deSettings[QString("EXTIP6CMD")] = uiDEConfig.lineEdit_extIp6->text();
- writeDataEngineConfiguration(deSettings);
-}
-
-
-void Netctl::configChanged()
-{
- if (debug) qDebug() << PDEBUG;
-
- KConfigGroup cg = config();
-
- autoUpdateInterval = cg.readEntry("autoUpdateInterval", 1000);
- paths[QString("gui")] = cg.readEntry("guiPath", "/usr/bin/netctl-gui");
- paths[QString("helper")] = cg.readEntry("helperPath", "/usr/bin/netctlgui-helper");
- paths[QString("netctl")] = cg.readEntry("netctlPath", "/usr/bin/netctl");
- paths[QString("netctlAuto")] = cg.readEntry("netctlAutoPath", "/usr/bin/netctl-auto");
- paths[QString("sudo")] = cg.readEntry("sudoPath", "/usr/bin/kdesu");
- paths[QString("wifi")] = cg.readEntry("wifiPath", "/usr/bin/netctl-gui -t 3");
- useSudo = cg.readEntry("useSudo", true);
- useWifi = cg.readEntry("useWifi", false);
- bigInterface = cg.readEntry("showBigInterface", true);
- useHelper = cg.readEntry("useHelper", true);
- textPattern = cg.readEntry("textPattern", "$info
IPv4: $intip4
IPv6: $intip6");
-
- QString textAlign = cg.readEntry("textAlign", "center");
- QString fontFamily = cg.readEntry("fontFamily", "Terminus");
- int fontSize = cg.readEntry("fontSize", 10);
- QString fontColor = cg.readEntry("fontColor", "#000000");
- int fontWeight = cg.readEntry("fontWeight", 400);
- QString fontStyle = cg.readEntry("fontStyle", "normal");
- paths[QString("active")] = cg.readEntry("activeIconPath",
- "/usr/share/icons/hicolor/64x64/apps/netctl-idle.png");
- paths[QString("inactive")] = cg.readEntry("inactiveIconPath",
- "/usr/share/icons/hicolor/64x64/apps/netctl-offline.png");
-
- formatLine[0] = QString("\
-\
-")
- .arg(textAlign)
- .arg(fontFamily)
- .arg(QString::number(fontSize))
- .arg(QString::number(fontWeight))
- .arg(fontStyle)
- .arg(fontColor);
- formatLine[1] = QString("
");
-
- if (useHelper) startHelper();
- checkHelperStatus();
- connectToEngine();
-}
-
-
-void Netctl::setBigInterface()
-{
- if (debug) qDebug() << PDEBUG;
-
- if (uiWidConfig.checkBox_showBigInterface->checkState() == 0)
- uiWidConfig.textEdit->setDisabled(true);
- else if (uiWidConfig.checkBox_showBigInterface->checkState() == 2)
- uiWidConfig.textEdit->setDisabled(false);
-}
-
-
-void Netctl::setDataEngineExternalIp4()
-{
- if (debug) qDebug() << PDEBUG;
-
- if (uiDEConfig.checkBox_extIp4->checkState() == 0) {
- uiDEConfig.lineEdit_extIp4->setDisabled(true);
- uiDEConfig.pushButton_extIp4->setDisabled(true);
- } else if (uiDEConfig.checkBox_extIp4->checkState() == 2) {
- uiDEConfig.lineEdit_extIp4->setEnabled(true);
- uiDEConfig.pushButton_extIp4->setEnabled(true);
- }
-}
-
-
-void Netctl::setDataEngineExternalIp6()
-{
- if (debug) qDebug() << PDEBUG;
-
- if (uiDEConfig.checkBox_extIp6->checkState() == 0) {
- uiDEConfig.lineEdit_extIp6->setDisabled(true);
- uiDEConfig.pushButton_extIp6->setDisabled(true);
- } else if (uiDEConfig.checkBox_extIp6->checkState() == 2) {
- uiDEConfig.lineEdit_extIp6->setEnabled(true);
- uiDEConfig.pushButton_extIp6->setEnabled(true);
- }
-}
-
-
-void Netctl::setHelper()
-{
- if (uiWidConfig.checkBox_helper->checkState() == 0) {
- uiWidConfig.lineEdit_helper->setDisabled(true);
- uiWidConfig.pushButton_helper->setDisabled(true);
- } else if (uiWidConfig.checkBox_helper->checkState() == 2) {
- uiWidConfig.lineEdit_helper->setEnabled(true);
- uiWidConfig.pushButton_helper->setEnabled(true);
- }
-}
-
-
-void Netctl::setSudo()
-{
- if (debug) qDebug() << PDEBUG;
-
- if (uiWidConfig.checkBox_sudo->checkState() == 0) {
- uiWidConfig.lineEdit_sudo->setDisabled(true);
- uiWidConfig.pushButton_sudo->setDisabled(true);
- } else if (uiWidConfig.checkBox_sudo->checkState() == 2) {
- uiWidConfig.lineEdit_sudo->setEnabled(true);
- uiWidConfig.pushButton_sudo->setEnabled(true);
- }
-}
-
-
-void Netctl::setWifi()
-{
- if (debug) qDebug() << PDEBUG;
-
- if (uiWidConfig.checkBox_wifi->checkState() == 0) {
- uiWidConfig.lineEdit_wifi->setDisabled(true);
- uiWidConfig.pushButton_wifi->setDisabled(true);
- } else if (uiWidConfig.checkBox_wifi->checkState() == 2) {
- uiWidConfig.lineEdit_wifi->setEnabled(true);
- uiWidConfig.pushButton_wifi->setEnabled(true);
- }
-}
-
-
-#include "netctl.moc"
diff --git a/sources/plasmoid-kf5/netctl.h b/sources/plasmoid-kf5/netctl.h
deleted file mode 100644
index 58a62de..0000000
--- a/sources/plasmoid-kf5/netctl.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/***************************************************************************
- * This file is part of netctl-gui *
- * *
- * netctl-gui is free software: you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation, either version 3 of the *
- * License, or (at your option) any later version. *
- * *
- * netctl-gui is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
- ***************************************************************************/
-
-#ifndef NETCTL_PLASMOID_H
-#define NETCTL_PLASMOID_H
-
-
-class Netctl : public Plasma::PopupApplet
-{
- Q_OBJECT
-
-public:
- Netctl(QObject *parent, const QVariantList &args);
- ~Netctl();
- void init();
- QString parsePattern(const QString rawLine);
- QMap readDataEngineConfiguration();
- void writeDataEngineConfiguration(const QMap settings);
- QMap updateDataEngineConfiguration(const QMap rawConfig);
-
-public slots:
- // events
- void sendNotification(const QString eventId, const QString message);
- void showGui();
- void showWifi();
- // dataengine
- void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
- // configuration interface
- void configAccepted();
- void configChanged();
- void setBigInterface();
- void setDataEngineExternalIp4();
- void setDataEngineExternalIp6();
- void setHelper();
- void setSudo();
- void setWifi();
-
-private slots:
- // ui
- void updateIcon();
- void updateInterface(bool setHidden);
- // configuration interface
- void selectAbstractSomething();
- // context menu
- void enableProfileSlot();
- void restartProfileSlot();
- void startProfileSlot(QAction *profile);
- void stopProfileSlot();
- void stopAllProfilesSlot();
- void switchToProfileSlot(QAction *profile);
- // helper
- void checkHelperStatus();
- void startHelper();
-
-protected:
- void createConfigurationInterface(KConfigDialog *parent);
- QList contextualActions();
-
-private:
- // ui
- QWidget *graphicsWidget;
- QHBoxLayout *layout;
- IconLabel *iconLabel;
- QLabel *textLabel;
- // information
- bool status;
- QMap info;
- QStringList profileList;
- // context menu
- void createActions();
- QList menuActions;
- QMenu *startProfileMenu;
- QMenu *switchToProfileMenu;
- QMap contextMenu;
- // data engine
- Plasma::DataEngine *netctlEngine;
- void connectToEngine();
- void disconnectFromEngine();
- QList sendDBusRequest(const QString cmd, const QList args = QList());
- // configuration interface
- Ui::AppearanceWindow uiAppConfig;
- Ui::DataEngineWindow uiDEConfig;
- Ui::ConfigWindow uiWidConfig;
- Ui::About uiAboutConfig;
- // configuration
- int autoUpdateInterval;
- bool bigInterface;
- bool debug;
- QString textPattern;
- QStringList formatLine;
- QMap paths;
- bool useHelper, useSudo, useWifi;
-};
-
-K_EXPORT_PLASMA_APPLET(netctl, Netctl)
-
-
-#endif /* NETCTL_PLASMOID_H */
diff --git a/sources/plasmoid-kf5/plasmoid/contents/ui/main.qml b/sources/plasmoid-kf5/plasmoid/contents/ui/main.qml
index 7227b2b..0831769 100644
--- a/sources/plasmoid-kf5/plasmoid/contents/ui/main.qml
+++ b/sources/plasmoid-kf5/plasmoid/contents/ui/main.qml
@@ -59,12 +59,7 @@ Item {
}
property int interval: plasmoid.configuration.autoUpdateInterval
property string pattern: plasmoid.configuration.textPattern
- property variant paths: {
- "netctl": plasmoid.configuration.netctlPath,
- "sudo": plasmoid.configuration.sudoPath
- }
property bool status: false
- property bool useHelper: plasmoid.configuration.useHelper
// init
Plasmoid.icon: icon.source
@@ -76,15 +71,17 @@ Item {
interval: main.interval
onNewData: {
- if (data.isEmpty) return
+ if (data.value == "N\\A") return
if (sourceName == "active") {
- main.status = data.value == "true" ? true : false
+ status = data.value == "true"
icon.source = iconPath[data.value]
} else if (sourceName == "current") {
info["current"] = data.value
// text update
info["info"] = NetctlAdds.getInfo(info["current"], info["status"])
text.text = NetctlAdds.parsePattern(pattern, info)
+ // update menus
+ menuUpdate()
} else if (sourceName == "extip4") {
info["extip4"] = data.value
} else if (sourceName == "extip6") {
@@ -125,19 +122,113 @@ Item {
}
}
- QtControls.Action {
- id: stopProfile
- text: i18n("Stop profile")
- iconSource: "dialog-close"
- onTriggered: NetctlAdds.stopProfileSlot(info, useHelper, paths["netctl"], paths["sudo"])
+ Component.onCompleted: {
+ plasmoid.setAction("titleAction", "netctl-gui", plasmoid.icon)
+ plasmoid.setAction("startProfile", i18n("Start profile"), "dialog-apply")
+ plasmoid.setAction("stopProfile", i18n("Stop profile"), "dialog-close")
+ plasmoid.setAction("stopAllProfiles", i18n("Stop all profiles"), "dialog-close")
+ plasmoid.setAction("switchToProfile", i18n("Switch to profile"))
+ plasmoid.setAction("restartProfile", i18n("Restart profile"), "stock-refresh")
+ plasmoid.setAction("enableProfile", i18n("Enable profile"))
+ // FIXME: icon from resources
+ plasmoid.setAction("startWifi", i18n("Show WiFi menu"))
}
- Component.onCompleted: {
- plasmoid.setAction("stopProfile", i18n("Stop profile"), "dialog-close")
-// plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management");
+ function menuUpdate() {
+ var titleAction = plasmoid.action("titleAction")
+ var startAction = plasmoid.action("startProfile")
+ var stopAction = plasmoid.action("stopProfile")
+ var stopAllAction = plasmoid.action("stopAllProfiles")
+ var switchToAction = plasmoid.action("switchToProfile")
+ var restartAction = plasmoid.action("restartProfile")
+ var enableAction = plasmoid.action("enableProfile")
+ var wifiAction = plasmoid.action("startWifi")
+
+ titleAction.iconSource = plasmoid.icon
+ titleAction.text = info["current"] + " " + info["status"]
+
+ // FIXME: menu to actions
+ if (info["status"] == "(netctl-auto)") {
+ startAction.visible = false
+ stopAction.visible = false
+ stopAllAction.visible = false
+ switchToAction.visible = true
+ restartAction.visible = false
+ enableAction.visible = false
+ // MENU UPDATE
+ } else {
+ if (info["current"].indexOf("|") > -1) {
+ startAction.visible = true
+ stopAction.visible = false
+ stopAllAction.visible = true
+ switchToAction.visible = false
+ restartAction.visible = false
+ enableAction.visible = false
+ } else {
+ startAction.visible = true
+ stopAction.visible = status
+ stopAllAction.visible = false
+ switchToAction.visible = false
+ restartAction.visible = status
+ enableAction.visible = status
+ }
+ if (status) {
+ startAction.text = i18n("Start another profile")
+ stopAction.text = i18n("Stop %1", info["current"])
+ restartAction.text = i18n("Restart %1", info["current"])
+ if (info["status"].indexOf("enabled") > -1)
+ enableAction.text = i18n("Disable %1", info["current"])
+ else
+ enableAction.text = i18n("Enable %1", info["current"])
+ } else
+ startAction.text = i18n("Start profile")
+ // MENU UPDATE
+ }
+
+ wifiAction.visible = plasmoid.configuration.useWifi
+ }
+
+ // actions
+ function action_titleAction() {
+ NetctlAdds.startApplication(plasmoid.configuration.guiPath)
+ }
+
+ function action_startProfile() {
+// NetctlAdds.startProfileSlot(profile, status, plasmoid.configuration.useHelper,
+// plasmoid.configuration.netctlPath,
+// plasmoid.configuration.sudoPath)
}
function action_stopProfile() {
- NetctlAdds.stopProfileSlot(info, useHelper, paths["netctl"], paths["sudo"])
+ NetctlAdds.stopProfileSlot(info, plasmoid.configuration.useHelper,
+ plasmoid.configuration.netctlPath,
+ plasmoid.configuration.sudoPath)
+ }
+
+ function action_stopAllProfiles() {
+ NetctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper,
+ plasmoid.configuration.netctlPath,
+ plasmoid.configuration.sudoPath)
+ }
+
+ function action_switchToProfile() {
+// NetctlAdds.switchToProfileSlot(profile, plasmoid.configuration.useHelper,
+// plasmoid.configuration.netctlAutoPath)
+ }
+
+ function action_restartProfile() {
+ NetctlAdds.restartProfileSlot(info, plasmoid.configuration.useHelper,
+ plasmoid.configuration.netctlPath,
+ plasmoid.configuration.sudoPath)
+ }
+
+ function action_enableProfile() {
+ NetctlAdds.enableProfileSlot(info, plasmoid.configuration.useHelper,
+ plasmoid.configuration.netctlPath,
+ plasmoid.configuration.sudoPath)
+ }
+
+ function action_startWifi() {
+ NetctlAdds.startApplication(plasmoid.configuration.wifiPath)
}
}
diff --git a/sources/plasmoid-kf5/plugin/netctladds.cpp b/sources/plasmoid-kf5/plugin/netctladds.cpp
index fe7c538..70b370a 100644
--- a/sources/plasmoid-kf5/plugin/netctladds.cpp
+++ b/sources/plasmoid-kf5/plugin/netctladds.cpp
@@ -49,16 +49,14 @@ bool NetctlAdds::checkHelperStatus(const bool useHelper)
{
if (debug) qDebug() << PDEBUG;
- if (useHelper)
- return !sendDBusRequest(QString("Active"), QList()).isEmpty();
- else
- return useHelper;
+ return (useHelper && !sendDBusRequest(QString("Active"), QList()).isEmpty());
}
-void NetctlAdds::startHelper(const QString cmd)
+void NetctlAdds::startApplication(const QString cmd)
{
if (debug) qDebug() << PDEBUG;
+ if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
QProcess command;
diff --git a/sources/plasmoid-kf5/plugin/netctladds.h b/sources/plasmoid-kf5/plugin/netctladds.h
index 733aad9..b960fb8 100644
--- a/sources/plasmoid-kf5/plugin/netctladds.h
+++ b/sources/plasmoid-kf5/plugin/netctladds.h
@@ -65,7 +65,7 @@ private:
bool debug = false;
// helper
bool checkHelperStatus(const bool useHelper = true);
- void startHelper(const QString cmd = QString("/usr/bin/netctlgui-helper"));
+ void startApplication(const QString cmd = QString("/usr/bin/true"));
// dbus
QList sendDBusRequest(const QString cmd, const QList args = QList());
};