From 028b636d2244650e1a6fa4c445e3456b4f2da77c Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 6 Mar 2014 22:10:27 +0400 Subject: [PATCH] changes before renaming --- sources/dataengine/netctl.cpp | 9 ++---- sources/plasmoid/netctl.cpp | 58 +++++++++++++++++++++++------------ sources/plasmoid/netctl.h | 3 ++ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/sources/dataengine/netctl.cpp b/sources/dataengine/netctl.cpp index 7aa4e2f..3897122 100644 --- a/sources/dataengine/netctl.cpp +++ b/sources/dataengine/netctl.cpp @@ -206,14 +206,11 @@ bool Netctl::updateSourceEvent(const QString &source) QStringList profile = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); for (int i=0; i -1) { + if (profile[i].indexOf(QString("enabled")) > -1) value = QString("enabled"); - break; - } - else if (profile[i].indexOf(QString("static")) > -1) { + else if (profile[i].indexOf(QString("static")) > -1) value = QString("static"); - break; - } + break; } } setData(source, QString("value"), value); diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index 794e16b..99b573a 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -75,22 +75,37 @@ void Netctl::init() iconFrame->setLayout(iconLayout); iconLayout->addItem(iconWidget); fullSpaceLayout->addItem(iconFrame); - // text - textFrame = new Plasma::Frame(); - QGraphicsLinearLayout *textLayout = new QGraphicsLinearLayout(); - textLabel = new Plasma::Label(); - textLayout->addItem(textLabel); - textFrame->setLayout(textLayout); - fullSpaceLayout->addItem(textFrame); - textFrame->hide(); - // stretch - fullSpaceLayout->addStretch(1); // read variables configChanged(); } +void Netctl::addTextFrame(const bool state) +{ + if (state) { + textFrame = new Plasma::Frame(); + QGraphicsLinearLayout *textLayout = new QGraphicsLinearLayout(); + textLabel = new Plasma::Label(); + textLayout->addItem(textLabel); + textFrame->setLayout(textLayout); + fullSpaceLayout->addItem(textFrame); + } + else { + fullSpaceLayout->removeItem(textFrame); + delete textLabel; + delete textFrame; + } +} + + +void Netctl::updateWidget() +{ + update(); + resize(0, 0); +} + + // context menu void Netctl::startProfileSlot(QAction *profile) { @@ -100,9 +115,10 @@ void Netctl::startProfileSlot(QAction *profile) if (status) commandLine = netctlPath + QString(" stop ") + profileName + QString(" && "); if (useSudo) - commandLine = sudoPath + QString(" \"") + commandLine + netctlPath + QString(" start ") + profile->text().mid(1) + QString("\""); + commandLine = sudoPath + QString(" \"") + commandLine + + netctlPath + QString(" start ") + profile->text().remove(QString("&")) + QString("\""); else - commandLine = commandLine + netctlPath + QString(" start ") + profile->text().mid(1); + commandLine = commandLine + netctlPath + QString(" start ") + profile->text().remove(QString("&")); command.startDetached(commandLine); } @@ -135,10 +151,10 @@ void Netctl::enableProfileAutoloadSlot() { QProcess command; QString commandLine, enableStatus; - if (profileStatus == QString("(enable")) - enableStatus = QString("disable"); + if (profileStatus.contains(QString("enabled"))) + enableStatus = QString(" disable "); else - enableStatus = QString("enable"); + enableStatus = QString(" enable "); if (useSudo) commandLine = sudoPath + QString(" \"") + netctlPath + enableStatus + profileName + QString("\""); else @@ -180,7 +196,7 @@ QList Netctl::contextualActions() restartProfile->setVisible(true); restartProfile->setText(QString("Restart ") + profileName); enableProfileAutoload->setVisible(true); - if (profileStatus == QString("(enable")) + if (profileStatus.contains(QString("enabled"))) enableProfileAutoload->setText(QString("Disable ") + profileName); else enableProfileAutoload->setText(QString("Enable ") + profileName); @@ -235,8 +251,9 @@ void Netctl::connectToEngine() netctlEngine->connectSource(QString("intIp"), this, autoUpdateInterval); if (showNetDev) netctlEngine->connectSource(QString("interfaces"), this, autoUpdateInterval); - textFrame->show(); + addTextFrame(true); } + updateWidget(); } @@ -253,9 +270,9 @@ void Netctl::disconnectFromEngine() netctlEngine->disconnectSource(QString("intIp"), this); if (showNetDev) netctlEngine->disconnectSource(QString("interfaces"), this); - textFrame->hide(); + addTextFrame(false); } - update(); + updateWidget(); } @@ -263,7 +280,7 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da { if (data.keys().count() == 0) return; - QString value = data[QString("value")].toString();; + QString value = data[QString("value")].toString(); if (value.isEmpty()) value = QString("N\\A"); @@ -280,6 +297,7 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da if (showNetDev) text.append(interfaces); textLabel->setText(formatLine[0] + text.join(QString("
")) + formatLine[1]); + updateWidget(); } else if (sourceName == QString("extIp")) { extIp = value; diff --git a/sources/plasmoid/netctl.h b/sources/plasmoid/netctl.h index 4255a99..e156bd4 100644 --- a/sources/plasmoid/netctl.h +++ b/sources/plasmoid/netctl.h @@ -52,6 +52,9 @@ public slots: void setSudo(); private slots: + // main interface + void addTextFrame(const bool state = true); + void updateWidget(); // configuration interface void selectGuiExe(); void selectNetctlExe();