From b61d514cb2a1adee72647d1775802f6bd88ca3cc Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 2 Sep 2014 04:30:43 +0400 Subject: [PATCH] add notification module fix definition of network deivce --- sources/awesome-widget/advanced.ui | 5 +- sources/awesome-widget/awesome-widget.cpp | 4 +- sources/awesome-widget/awesome-widget.h | 1 + sources/awesome-widget/configuration.cpp | 4 +- sources/awesome-widget/customlabel.cpp | 59 ++++++++++++++++++- sources/awesome-widget/customlabel.h | 1 + sources/awesome-widget/deinteraction.cpp | 2 +- .../plasma_applet_awesome-widget.notifyrc | 39 +----------- sources/awesome-widget/reinit.cpp | 24 ++++++-- 9 files changed, 86 insertions(+), 53 deletions(-) diff --git a/sources/awesome-widget/advanced.ui b/sources/awesome-widget/advanced.ui index f4636f6..6030cd7 100644 --- a/sources/awesome-widget/advanced.ui +++ b/sources/awesome-widget/advanced.ui @@ -41,7 +41,7 @@ 0 - 0 + -62 677 640 @@ -340,9 +340,6 @@ $m - uptime minutes without zero - - false - 0 diff --git a/sources/awesome-widget/awesome-widget.cpp b/sources/awesome-widget/awesome-widget.cpp index 34ef80a..9fa2de0 100644 --- a/sources/awesome-widget/awesome-widget.cpp +++ b/sources/awesome-widget/awesome-widget.cpp @@ -99,7 +99,7 @@ QString AwesomeWidget::getNetworkDevice() QList rawInterfaceList = QNetworkInterface::allInterfaces(); for (int i=0; itoUnicode(process.output).toInt(); + return QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed().toInt(); } diff --git a/sources/awesome-widget/awesome-widget.h b/sources/awesome-widget/awesome-widget.h index 602a330..cbf353a 100644 --- a/sources/awesome-widget/awesome-widget.h +++ b/sources/awesome-widget/awesome-widget.h @@ -64,6 +64,7 @@ public slots: void configAccepted(); void configChanged(); // update events + void sendNotification(const QString eventId, const QString message); void updateNetworkDevice(); void updateText(bool clear = false); void updateTooltip(); diff --git a/sources/awesome-widget/configuration.cpp b/sources/awesome-widget/configuration.cpp index 7b36208..10e8049 100644 --- a/sources/awesome-widget/configuration.cpp +++ b/sources/awesome-widget/configuration.cpp @@ -170,7 +170,7 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent) if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; - qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output); + qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); uiAdvancedConfig.listWidget_tempDevice->clear(); for (int i=0; itoUnicode(process.output); + qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); uiAdvancedConfig.listWidget_mount->clear(); for (int i=0; i +#include #include "awesome-widget.h" #include +#include CustomLabel::CustomLabel(AwesomeWidget *wid, const bool debugCmd) : Plasma::Label(wid), + widget(wid), debug(debugCmd) { } @@ -50,7 +53,59 @@ void CustomLabel::mousePressEvent(QGraphicsSceneMouseEvent *event) if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button(); - if ((enablePopup) && (event->button() == Qt::LeftButton)) - {} + if ((enablePopup) && (event->button() == Qt::LeftButton)) { + QString cmd, text; + TaskResult process; + + // kernel + cmd = QString("uname -rsm"); + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + text += QString("Kernel: %1\n").arg(QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed()); + // hostname + cmd = QString("uname -n"); + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + text += QString("Hostname: %1\n").arg(QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed()); + // whoami + cmd = QString("whoami"); + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + text += QString("Whoami: %1\n").arg(QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed()); + // uptime + cmd = QString("uptime"); + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + text += QString("Uptime: %1\n").arg(QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed()); + // ps stats + cmd = QString("ps --no-headers -o command"); + if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; + process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); + QStringList processes; + for (int i=0; isendNotification(QString("system"), text); + } emit(Plasma::Label::mousePressEvent(event)); } diff --git a/sources/awesome-widget/customlabel.h b/sources/awesome-widget/customlabel.h index abd5e74..3136112 100644 --- a/sources/awesome-widget/customlabel.h +++ b/sources/awesome-widget/customlabel.h @@ -36,6 +36,7 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); private: + AwesomeWidget *widget; bool debug; bool enablePopup; }; diff --git a/sources/awesome-widget/deinteraction.cpp b/sources/awesome-widget/deinteraction.cpp index 25c1ec5..f704350 100644 --- a/sources/awesome-widget/deinteraction.cpp +++ b/sources/awesome-widget/deinteraction.cpp @@ -297,7 +297,7 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng if (configuration[QString("useCustomNetdev")].toInt() == 2) { sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), this); sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), this); - values[QString("netdev")] = getNetworkDevice(); + updateNetworkDevice(); sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), this, configuration[QString("interval")].toInt()); sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), diff --git a/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc b/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc index 1621895..d57c01f 100644 --- a/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc +++ b/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc @@ -1,42 +1,7 @@ [Global] IconName=system -Name=PyTextMonitor -Comment=PyTextMonitor information - -[Event/battery] -Name=Battery information -Comment=Battery information -Action=Popup - -[Event/disk] -Name=Disk information -Comment=Disk information -Action=Popup - -[Event/graphical] -Name=GPU information -Comment=GPU information -Action=Popup - -[Event/memory] -Name=Memory information -Comment=Memory information -Action=Popup - -[Event/network] -Name=Network information -Comment=Network information -Action=Popup - -[Event/player] -Name=Now playing -Comment=Now playing -Action=Popup - -[Event/processor] -Name=Processor information -Comment=Processor information -Action=Popup +Name=ptm-awesome-widget +Comment=Awesome widget information [Event/system] Name=System information diff --git a/sources/awesome-widget/reinit.cpp b/sources/awesome-widget/reinit.cpp index 27435ca..7a1729e 100644 --- a/sources/awesome-widget/reinit.cpp +++ b/sources/awesome-widget/reinit.cpp @@ -17,10 +17,10 @@ #include "awesome-widget.h" +#include #include #include #include -//#include #include "customlabel.h" #include @@ -47,9 +47,9 @@ void AwesomeWidget::reinit() if (configuration[QString("leftStretch")].toInt() == 2) mainLayout->addStretch(1); if (configuration[QString("popup")].toInt() == 0) - textLabel->setPopupEnabled(true); - else textLabel->setPopupEnabled(false); + else + textLabel->setPopupEnabled(true); updateText(true); mainLayout->addItem(textLabel); resize(10, 10); @@ -59,12 +59,26 @@ void AwesomeWidget::reinit() keys = getKeys(); foundKeys = findKeys(); initValues(); - values[QString("netdev")] = getNetworkDevice(); -// thread()->wait(60000); + updateNetworkDevice(); connectToEngine(); } +void AwesomeWidget::sendNotification(const QString eventId, const QString message) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Event" << eventId; + if (debug) qDebug() << PDEBUG << ":" << "Message" << message; + + KNotification *notification = new KNotification(eventId); + notification->setComponentData(KComponentData("plasma_applet_awesome-widget")); + notification->setTitle(QString("Awesome Widget ::: ") + eventId); + notification->setText(message); + notification->sendEvent(); + delete notification; +} + + void AwesomeWidget::updateNetworkDevice() { if (debug) qDebug() << PDEBUG;