mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-14 14:25:52 +00:00
plasmoid fixes
This commit is contained in:
@ -19,17 +19,21 @@ import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Layouts 1.0 as QtLayouts
|
||||
|
||||
import org.kde.plasma.netctl 1.0
|
||||
import org.kde.plasma.private.netctl 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: aboutPage
|
||||
// backend
|
||||
NetctlAdds {
|
||||
id: netctlAdds;
|
||||
}
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: pageColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property bool debug: NetctlAdds.isDebugEnabled()
|
||||
property bool debug: netctlAdds.isDebugEnabled()
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
@ -44,20 +48,20 @@ Item {
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: NetctlAdds.getAboutText("header")
|
||||
text: netctlAdds.getAboutText("header")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
text: NetctlAdds.getAboutText("description")
|
||||
text: netctlAdds.getAboutText("description")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
textFormat: Text.RichText
|
||||
text: NetctlAdds.getAboutText("links")
|
||||
text: netctlAdds.getAboutText("links")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
|
||||
@ -66,7 +70,7 @@ Item {
|
||||
font.capitalization: Font.SmallCaps
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
textFormat: Text.RichText
|
||||
text: NetctlAdds.getAboutText("copy")
|
||||
text: netctlAdds.getAboutText("copy")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,14 +82,14 @@ Item {
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
text: NetctlAdds.getAboutText("translators")
|
||||
text: netctlAdds.getAboutText("translators")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
textFormat: Text.RichText
|
||||
text: NetctlAdds.getAboutText("3rdparty")
|
||||
text: netctlAdds.getAboutText("3rdparty")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
}
|
||||
|
@ -21,17 +21,21 @@ import QtQuick.Controls.Styles 1.3 as QtStyles
|
||||
import QtQuick.Dialogs 1.1 as QtDialogs
|
||||
import QtQuick.Layouts 1.0 as QtLayouts
|
||||
|
||||
import org.kde.plasma.netctl 1.0
|
||||
import org.kde.plasma.private.netctl 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: appearancePage
|
||||
// backend
|
||||
NetctlAdds {
|
||||
id: netctlAdds;
|
||||
}
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: pageColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property bool debug: NetctlAdds.isDebugEnabled()
|
||||
property bool debug: netctlAdds.isDebugEnabled()
|
||||
property variant weight: {
|
||||
25: 0,
|
||||
50: 1,
|
||||
@ -110,7 +114,10 @@ Item {
|
||||
id: selectFont
|
||||
width: parent.width * 2 / 3
|
||||
text: plasmoid.configuration.fontFamily
|
||||
onClicked: fontDialog.visible = true
|
||||
onClicked: {
|
||||
fontDialog.setFont()
|
||||
fontDialog.visible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,21 +315,28 @@ Item {
|
||||
id: colorDialog
|
||||
title: i18n("Select a color")
|
||||
color: selectColor.text
|
||||
onAccepted: {
|
||||
selectColor.text = colorDialog.color
|
||||
}
|
||||
onAccepted: selectColor.text = colorDialog.color
|
||||
}
|
||||
|
||||
QtDialogs.FontDialog {
|
||||
id: fontDialog
|
||||
title: i18n("Select a font")
|
||||
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
|
||||
signal setFont
|
||||
|
||||
onAccepted: {
|
||||
selectFont.text = fontDialog.font.family
|
||||
fontSize.value = fontDialog.font.pointSize
|
||||
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
|
||||
fontWeight.currentIndex = weight[fontDialog.font.weight]
|
||||
}
|
||||
onSetFont: {
|
||||
fontDialog.font = Qt.font({
|
||||
family: selectFont.text,
|
||||
pointSize: fontSize.value > 0 ? fontSize.value : 12,
|
||||
italic: fontStyle.currentIndex == 1,
|
||||
weight: Font.Normal,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -21,19 +21,23 @@ import QtQuick.Dialogs 1.1 as QtDialogs
|
||||
import QtQuick.Layouts 1.0 as QtLayouts
|
||||
import QtQuick.Controls.Styles 1.3 as QtStyles
|
||||
|
||||
import org.kde.plasma.netctl 1.0
|
||||
import org.kde.plasma.private.netctl 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: dataenginePage
|
||||
// backend
|
||||
NetctlAdds {
|
||||
id: netctlAdds;
|
||||
}
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: pageColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property bool debug: NetctlAdds.isDebugEnabled()
|
||||
property bool debug: netctlAdds.isDebugEnabled()
|
||||
|
||||
property variant cfg_dataengine: NetctlAdds.readDataEngineConfiguration()
|
||||
property variant cfg_dataengine: netctlAdds.readDataEngineConfiguration()
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
@ -228,6 +232,6 @@ Item {
|
||||
Component.onDestruction: {
|
||||
cfg_dataengine["EXTIP4"] = extIp4.checked ? "true" : "false"
|
||||
cfg_dataengine["EXTIP6"] = extIp6.checked ? "true" : "false"
|
||||
NetctlAdds.writeDataEngineConfiguration(cfg_dataengine)
|
||||
netctlAdds.writeDataEngineConfiguration(cfg_dataengine)
|
||||
}
|
||||
}
|
||||
|
@ -22,15 +22,19 @@ import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
|
||||
import org.kde.plasma.netctl 1.0
|
||||
import org.kde.plasma.private.netctl 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: main
|
||||
// backend
|
||||
NetctlAdds {
|
||||
id: netctlAdds;
|
||||
}
|
||||
|
||||
// variables
|
||||
// internal
|
||||
property bool debug: NetctlAdds.isDebugEnabled()
|
||||
property bool debug: netctlAdds.isDebugEnabled()
|
||||
property variant fontWeight: {
|
||||
"light": Font.Light,
|
||||
"normal": Font.Normal,
|
||||
@ -52,8 +56,9 @@ Item {
|
||||
}
|
||||
property string sudoPath: plasmoid.configuration.useSudo ? plasmoid.configuration.sudoPath : ""
|
||||
// signals
|
||||
signal needUpdate
|
||||
signal needMenuUpdate
|
||||
signal needIconUpdate(string newIcon)
|
||||
signal needTextUpdate(string newText, string newToolTip)
|
||||
signal needMenuUpdate(string current, string stringStatus, bool status)
|
||||
|
||||
// init
|
||||
Plasmoid.icon: iconPath["false"]
|
||||
@ -71,7 +76,7 @@ Item {
|
||||
onNewData: {
|
||||
if (debug) console.log("[main::onNewData] : Update source " + sourceName)
|
||||
|
||||
NetctlAdds.setDataBySource(sourceName, data)
|
||||
netctlAdds.setDataBySource(sourceName, data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,28 +115,30 @@ Item {
|
||||
plasmoid.setAction("restartProfile", i18n("Restart profile"), "view-refresh")
|
||||
plasmoid.setAction("enableProfile", i18n("Enable profile"))
|
||||
plasmoid.setAction("startWifi", i18n("Show WiFi menu"), "netctl-gui-wifi")
|
||||
// helper
|
||||
if (plasmoid.configuration.useHelper) {
|
||||
NetctlAdds.runCmd(plasmoid.configuration.helperPath)
|
||||
plasmoid.configuration.useHelper = NetctlAdds.checkHelperStatus()
|
||||
}
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(false)
|
||||
|
||||
NetctlAdds.needToBeUpdated.connect(needUpdate)
|
||||
netctlAdds.needIconToBeUpdated.connect(needIconUpdate)
|
||||
netctlAdds.needMenuUpdate.connect(needMenuUpdate)
|
||||
netctlAdds.needTextToBeUpdated.connect(needTextUpdate)
|
||||
}
|
||||
|
||||
onNeedUpdate: {
|
||||
if (debug) console.log("[main::onNeedUpdate]")
|
||||
onNeedIconUpdate: {
|
||||
if (debug) console.log("[main::onNeedIconUpdate]")
|
||||
|
||||
var iconStatus = NetctlAdds.valueByKey("active")
|
||||
icon.source = iconPath[iconStatus]
|
||||
Plasmoid.icon = iconPath[iconStatus]
|
||||
text.text = NetctlAdds.parsePattern(plasmoid.configuration.textPattern)
|
||||
Plasmoid.toolTipSubText = NetctlAdds.valueByKey("info")
|
||||
needMenuUpdate()
|
||||
icon.source = iconPath[newIcon]
|
||||
Plasmoid.icon = iconPath[newIcon]
|
||||
}
|
||||
|
||||
onNeedTextUpdate: {
|
||||
if (debug) console.log("[main::onNeedTextUpdate]")
|
||||
|
||||
text.text = newText
|
||||
Plasmoid.toolTipSubText = newToolTip
|
||||
}
|
||||
|
||||
onNeedMenuUpdate: {
|
||||
if (debug) console.log("[main::onNetctlStateChanged]")
|
||||
if (debug) console.log("[main::onNeedMenuUpdate]")
|
||||
|
||||
var titleAction = plasmoid.action("titleAction")
|
||||
var startAction = plasmoid.action("startProfile")
|
||||
@ -142,10 +149,6 @@ Item {
|
||||
var enableAction = plasmoid.action("enableProfile")
|
||||
var wifiAction = plasmoid.action("startWifi")
|
||||
|
||||
var current = NetctlAdds.valueByKey("current")
|
||||
var status = NetctlAdds.valueByKey("active") == "true"
|
||||
var stringStatus = NetctlAdds.valueByKey("status")
|
||||
|
||||
titleAction.iconSource = plasmoid.icon
|
||||
titleAction.text = current + " " + stringStatus
|
||||
|
||||
@ -187,16 +190,29 @@ Item {
|
||||
wifiAction.visible = plasmoid.configuration.useWifi
|
||||
}
|
||||
|
||||
Plasmoid.onUserConfiguringChanged: {
|
||||
if (plasmoid.userConfiguring) return
|
||||
if (debug) console.log("[main::onUserConfiguringChanged]")
|
||||
|
||||
// helper
|
||||
if (plasmoid.configuration.useHelper) {
|
||||
netctlAdds.runCmd(plasmoid.configuration.helperPath)
|
||||
plasmoid.configuration.useHelper = netctlAdds.checkHelperStatus()
|
||||
}
|
||||
// init submodule
|
||||
netctlAdds.setPattern(plasmoid.configuration.textPattern)
|
||||
}
|
||||
|
||||
function action_titleAction() {
|
||||
if (debug) console.log("[main::action_titleAction]")
|
||||
|
||||
NetctlAdds.runCmd(plasmoid.configuration.guiPath)
|
||||
netctlAdds.runCmd(plasmoid.configuration.guiPath)
|
||||
}
|
||||
|
||||
function action_startProfile() {
|
||||
if (debug) console.log("[main::action_startProfile]")
|
||||
|
||||
NetctlAdds.startProfileSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.startProfileSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
sudoPath)
|
||||
}
|
||||
@ -204,7 +220,7 @@ Item {
|
||||
function action_stopProfile() {
|
||||
if (debug) console.log("[main::action_stopProfile]")
|
||||
|
||||
NetctlAdds.stopProfileSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.stopProfileSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
sudoPath)
|
||||
}
|
||||
@ -212,7 +228,7 @@ Item {
|
||||
function action_stopAllProfiles() {
|
||||
if (debug) console.log("[main::action_stopAllProfiles]")
|
||||
|
||||
NetctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
sudoPath)
|
||||
}
|
||||
@ -220,14 +236,14 @@ Item {
|
||||
function action_switchToProfile() {
|
||||
if (debug) console.log("[main::action_switchToProfile]")
|
||||
|
||||
NetctlAdds.switchToProfileSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.switchToProfileSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlAutoPath)
|
||||
}
|
||||
|
||||
function action_restartProfile() {
|
||||
if (debug) console.log("[main::action_restartProfile]")
|
||||
|
||||
NetctlAdds.restartProfileSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.restartProfileSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
sudoPath)
|
||||
}
|
||||
@ -235,7 +251,7 @@ Item {
|
||||
function action_enableProfile() {
|
||||
if (debug) console.log("[main::action_enableProfile]")
|
||||
|
||||
NetctlAdds.enableProfileSlot(plasmoid.configuration.useHelper,
|
||||
netctlAdds.enableProfileSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
sudoPath)
|
||||
}
|
||||
@ -243,6 +259,6 @@ Item {
|
||||
function action_startWifi() {
|
||||
if (debug) console.log("[main::action_startWifi]")
|
||||
|
||||
NetctlAdds.runCmd(plasmoid.configuration.wifiPath)
|
||||
netctlAdds.runCmd(plasmoid.configuration.wifiPath)
|
||||
}
|
||||
}
|
||||
|
@ -21,17 +21,20 @@ import QtQuick.Dialogs 1.1 as QtDialogs
|
||||
import QtQuick.Layouts 1.0 as QtLayouts
|
||||
import QtQuick.Controls.Styles 1.3 as QtStyles
|
||||
|
||||
import org.kde.plasma.netctl 1.0
|
||||
import org.kde.plasma.private.netctl 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: widgetPage
|
||||
NetctlAdds {
|
||||
id: netctlAdds;
|
||||
}
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: pageColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property bool debug: NetctlAdds.isDebugEnabled()
|
||||
property bool debug: netctlAdds.isDebugEnabled()
|
||||
|
||||
property alias cfg_autoUpdateInterval: autoUpdate.value
|
||||
property alias cfg_guiPath: guiPath.text
|
||||
|
@ -14,7 +14,7 @@ X-Plasma-RemoteLocation=
|
||||
X-KDE-PluginInfo-Author=Evgeniy Alekseev
|
||||
X-KDE-PluginInfo-Email=esalexeev@gmail.com
|
||||
X-KDE-PluginInfo-Name=org.kde.plasma.netctl
|
||||
X-KDE-PluginInfo-Version=1.4.8
|
||||
X-KDE-PluginInfo-Version=1.4.9
|
||||
X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui
|
||||
X-KDE-PluginInfo-Category=Network
|
||||
X-KDE-PluginInfo-Depends=
|
||||
|
@ -21,13 +21,12 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE})
|
||||
|
||||
file (GLOB_RECURSE SUBPROJECT_SOURCE ${PROJECT_TRDPARTY_DIR}/pdebug/*.cpp
|
||||
*.cpp)
|
||||
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp)
|
||||
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||
|
||||
add_library (${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
|
||||
target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
|
||||
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/netctl)
|
||||
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/netctl)
|
||||
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/netctl)
|
||||
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/netctl)
|
||||
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})
|
||||
|
@ -21,18 +21,9 @@
|
||||
#include "netctladds.h"
|
||||
|
||||
|
||||
static QObject *netctl_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(scriptEngine);
|
||||
|
||||
return new NetctlAdds();
|
||||
}
|
||||
|
||||
|
||||
void NetctlPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.netctl"));
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.netctl"));
|
||||
|
||||
qmlRegisterSingletonType<NetctlAdds>(uri, 1, 0, "NetctlAdds", netctl_singletontype_provider);
|
||||
qmlRegisterType<NetctlAdds>(uri, 1, 0, "NetctlAdds");
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <pdebug/pdebug-time.h>
|
||||
|
||||
#include "netctladds.h"
|
||||
#include "version.h"
|
||||
@ -36,13 +35,13 @@
|
||||
NetctlAdds::NetctlAdds(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qInstallMessageHandler(debugString);
|
||||
// debug
|
||||
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
|
||||
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
|
||||
debug = (debugEnv == QString("yes"));
|
||||
|
||||
connect(this, SIGNAL(needToNotify(bool)), this, SLOT(notifyAboutStatusChanging(bool)));
|
||||
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(parsePattern()));
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +51,7 @@ NetctlAdds::~NetctlAdds()
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus)
|
||||
void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Status" << currentStatus;
|
||||
@ -64,7 +63,21 @@ void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus)
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant> NetctlAdds::sendDBusRequest(const QString cmd, const QList<QVariant> args)
|
||||
void NetctlAdds::parsePattern() const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString parsed = pattern;
|
||||
foreach(QString value, values.keys())
|
||||
parsed.replace(QString("$%1").arg(value), values[value]);
|
||||
// fix newline
|
||||
parsed.replace(QString("\n"), QString("<br>"));
|
||||
|
||||
return emit(needTextToBeUpdated(parsed, values[QString("info")]));
|
||||
}
|
||||
|
||||
|
||||
QVariantList NetctlAdds::sendDBusRequest(const QString cmd, const QVariantList args) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
@ -73,26 +86,24 @@ QList<QVariant> NetctlAdds::sendDBusRequest(const QString cmd, const QList<QVari
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, cmd);
|
||||
if (!args.isEmpty())
|
||||
request.setArguments(args);
|
||||
if (!args.isEmpty()) request.setArguments(args);
|
||||
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
if (arguments.size() == 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage();
|
||||
QVariantList arguments = response.arguments();
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage();
|
||||
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdds::checkHelperStatus()
|
||||
bool NetctlAdds::checkHelperStatus() const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return sendDBusRequest(QString("Active"), QList<QVariant>()).isEmpty();
|
||||
return !sendDBusRequest(QString("Active")).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
QString NetctlAdds::getAboutText(const QString type)
|
||||
QString NetctlAdds::getAboutText(const QString type) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Type" << type;
|
||||
@ -120,9 +131,9 @@ QString NetctlAdds::getAboutText(const QString type)
|
||||
QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(QChar(';'), QString::SkipEmptyParts);
|
||||
for (int i=0; i<trdPartyList.count(); i++)
|
||||
trdPartyList[i] = QString("<a href=\"%3\">%1</a> (%2 license)")
|
||||
.arg(trdPartyList[i].split(QChar(','))[0])
|
||||
.arg(trdPartyList[i].split(QChar(','))[1])
|
||||
.arg(trdPartyList[i].split(QChar(','))[2]);
|
||||
.arg(trdPartyList.at(i).split(QChar(',')).at(0))
|
||||
.arg(trdPartyList.at(i).split(QChar(',')).at(1))
|
||||
.arg(trdPartyList.at(i).split(QChar(',')).at(2));
|
||||
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
|
||||
}
|
||||
|
||||
@ -130,7 +141,7 @@ QString NetctlAdds::getAboutText(const QString type)
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdds::isDebugEnabled()
|
||||
bool NetctlAdds::isDebugEnabled() const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -138,21 +149,7 @@ bool NetctlAdds::isDebugEnabled()
|
||||
}
|
||||
|
||||
|
||||
QString NetctlAdds::parsePattern(const QString pattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString parsed = pattern;
|
||||
for (int i=0; i<values.keys().count(); i++)
|
||||
parsed.replace(QString("$%1").arg(values.keys()[i]), valueByKey(values.keys()[i]));
|
||||
// fix newline
|
||||
parsed.replace(QString("\n"), QString("<br>"));
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::runCmd(const QString cmd)
|
||||
void NetctlAdds::runCmd(const QString cmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
||||
@ -174,13 +171,26 @@ void NetctlAdds::setDataBySource(const QString sourceName, const QVariantMap dat
|
||||
values[sourceName] = data[QString("value")].toString();
|
||||
|
||||
if (needUpdate) {
|
||||
emit(needToBeUpdated());
|
||||
if (sourceName == QString("active"))
|
||||
if (sourceName == QString("active")) {
|
||||
emit(needToNotify(values[QString("active")] == QString("true")));
|
||||
emit(needIconToBeUpdated(values[QString("active")]));
|
||||
}
|
||||
emit(needToBeUpdated());
|
||||
emit(needMenuUpdate(values[QString("current")], values[QString("status")],
|
||||
values[QString("active")] == QString("true")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::setPattern(const QString _pattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Pattern" << _pattern;
|
||||
|
||||
pattern = _pattern;
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
// since it is a static method we need to identify is debug enabled again
|
||||
@ -197,17 +207,8 @@ void NetctlAdds::sendNotification(const QString eventId, const QString message)
|
||||
}
|
||||
|
||||
|
||||
QString NetctlAdds::valueByKey(const QString key)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Key" << key;
|
||||
|
||||
return values[key];
|
||||
}
|
||||
|
||||
|
||||
// context menu
|
||||
void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
|
||||
void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -220,82 +221,75 @@ void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, cons
|
||||
sendNotification(QString("Info"), i18n("Set profile %1 enabled", values[QString("current")]));
|
||||
}
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
QVariantList args;
|
||||
args.append(values[QString("current")]);
|
||||
sendDBusRequest(QString("Enable"), args);
|
||||
} else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 %2%3%4").arg(sudoCmd).arg(cmd).arg(enableStatus).arg(values[QString("current")]);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(QString("%1 %2%3%4").arg(sudoCmd).arg(cmd).arg(enableStatus).arg(values[QString("current")]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::restartProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
|
||||
void NetctlAdds::restartProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
sendNotification(QString("Info"), i18n("Restart profile %1", values[QString("current")]));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
QVariantList args;
|
||||
args.append(values[QString("current")]);
|
||||
sendDBusRequest(QString("Restart"), args);
|
||||
} else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 %2 restart %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(QString("%1 %2 restart %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::startProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
|
||||
void NetctlAdds::startProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList profiles = values[QString("profiles")].split(QChar(','));
|
||||
bool ok;
|
||||
QString profile = QInputDialog::getItem(0, i18n("Select profile"), i18n("Profile:"),
|
||||
QString profile = QInputDialog::getItem(nullptr, i18n("Select profile"), i18n("Profile:"),
|
||||
profiles, 0, false, &ok);
|
||||
if (!ok || profile.isEmpty()) return;
|
||||
|
||||
sendNotification(QString("Info"), i18n("Start profile %1", profile));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
QVariantList args;
|
||||
args.append(profile);
|
||||
if (values[QString("active")] == QString("true"))
|
||||
sendDBusRequest(QString("SwitchTo"), args);
|
||||
else
|
||||
sendDBusRequest(QString("Start"), args);
|
||||
} else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 %2").arg(sudoCmd).arg(cmd);
|
||||
if (values[QString("active")] == QString("true"))
|
||||
commandLine += QString(" switch-to %1").arg(profile);
|
||||
else
|
||||
commandLine += QString(" start %1").arg(profile);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::stopProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
|
||||
void NetctlAdds::stopProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
sendNotification(QString("Info"), i18n("Stop profile %1", values[QString("current")]));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
QVariantList args;
|
||||
args.append(values[QString("current")]);
|
||||
sendDBusRequest(QString("Start"), args);
|
||||
} else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 %2 stop %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(QString("%1 %2 stop %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
|
||||
void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -303,37 +297,33 @@ void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, co
|
||||
if (useHelper)
|
||||
sendDBusRequest(QString("StopAll"), QList<QVariant>());
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 %2 stop-all").arg(sudoCmd).arg(cmd);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(QString("%1 %2 stop-all").arg(sudoCmd).arg(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::switchToProfileSlot(const bool useHelper, const QString cmd)
|
||||
void NetctlAdds::switchToProfileSlot(const bool useHelper, const QString cmd) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList profiles = values[QString("profiles")].split(QChar(','));
|
||||
bool ok;
|
||||
QString profile = QInputDialog::getItem(0, i18n("Select profile"), i18n("Profile:"),
|
||||
QString profile = QInputDialog::getItem(nullptr, i18n("Select profile"), i18n("Profile:"),
|
||||
profiles, 0, false, &ok);
|
||||
if (!ok || profile.isEmpty()) return;
|
||||
|
||||
sendNotification(QString("Info"), i18n("Switch to profile %1", profile));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
QVariantList args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(QString("autoStart"), args);
|
||||
} else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("%1 switch-to %2").arg(cmd).arg(profile);
|
||||
command.startDetached(commandLine);
|
||||
runCmd(QString("%1 switch-to %2").arg(cmd).arg(profile));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QVariantMap NetctlAdds::readDataEngineConfiguration()
|
||||
QVariantMap NetctlAdds::readDataEngineConfiguration() const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -359,7 +349,7 @@ QVariantMap NetctlAdds::readDataEngineConfiguration()
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::writeDataEngineConfiguration(const QVariantMap configuration)
|
||||
void NetctlAdds::writeDataEngineConfiguration(const QVariantMap configuration) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
|
@ -32,47 +32,52 @@ public:
|
||||
NetctlAdds(QObject *parent = 0);
|
||||
~NetctlAdds();
|
||||
|
||||
Q_INVOKABLE bool checkHelperStatus();
|
||||
Q_INVOKABLE QString getAboutText(const QString type = "header");
|
||||
Q_INVOKABLE bool isDebugEnabled();
|
||||
Q_INVOKABLE QString parsePattern(const QString pattern);
|
||||
Q_INVOKABLE void runCmd(const QString cmd);
|
||||
Q_INVOKABLE bool checkHelperStatus() const;
|
||||
Q_INVOKABLE QString getAboutText(const QString type = QString("header")) const;
|
||||
Q_INVOKABLE bool isDebugEnabled() const;
|
||||
Q_INVOKABLE void runCmd(const QString cmd) const;
|
||||
Q_INVOKABLE void setDataBySource(const QString sourceName, const QVariantMap data);
|
||||
Q_INVOKABLE void setPattern(const QString _pattern);
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE QString valueByKey(const QString key);
|
||||
// context menu
|
||||
Q_INVOKABLE void enableProfileSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl"),
|
||||
const QString sudoCmd = QString(""));
|
||||
const QString sudoCmd = QString("")) const;
|
||||
Q_INVOKABLE void restartProfileSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl"),
|
||||
const QString sudoCmd = QString(""));
|
||||
const QString sudoCmd = QString("")) const;
|
||||
Q_INVOKABLE void startProfileSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl"),
|
||||
const QString sudoCmd = QString(""));
|
||||
const QString sudoCmd = QString("")) const;
|
||||
Q_INVOKABLE void stopProfileSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl"),
|
||||
const QString sudoCmd = QString(""));
|
||||
const QString sudoCmd = QString("")) const;
|
||||
Q_INVOKABLE void stopAllProfilesSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl"),
|
||||
const QString sudoCmd = QString(""));
|
||||
const QString sudoCmd = QString("")) const;
|
||||
Q_INVOKABLE void switchToProfileSlot(const bool useHelper = true,
|
||||
const QString cmd = QString("netctl-auto"));
|
||||
const QString cmd = QString("netctl-auto")) const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration);
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
|
||||
signals:
|
||||
void needToBeUpdated();
|
||||
void needToNotify(const bool currentStatus);
|
||||
void needIconToBeUpdated(const QString newIcon) const;
|
||||
void needMenuUpdate(const QString current, const QString status, const bool isActive) const;
|
||||
void needTextToBeUpdated(const QString newText, const QString newToolTip) const;
|
||||
void needToBeUpdated() const;
|
||||
void needToNotify(const bool currentStatus) const;
|
||||
|
||||
private slots:
|
||||
void notifyAboutStatusChanging(const bool currentStatus);
|
||||
void notifyAboutStatusChanging(const bool currentStatus) const;
|
||||
void parsePattern() const;
|
||||
|
||||
private:
|
||||
bool debug = false;
|
||||
QList<QVariant> sendDBusRequest(const QString cmd, const QList<QVariant> args = QList<QVariant>());
|
||||
QMap<QString, QString> values;
|
||||
QVariantList sendDBusRequest(const QString cmd,
|
||||
const QVariantList args = QVariantList()) const;
|
||||
QString pattern;
|
||||
QHash<QString, QString> values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
module org.kde.plasma.netctl
|
||||
module org.kde.plasma.private.netctl
|
||||
|
||||
plugin netctlplugin
|
||||
|
Reference in New Issue
Block a user