add notification module

fix definition of network deivce
This commit is contained in:
arcan1s 2014-09-02 04:30:43 +04:00
parent a5c352bc06
commit b61d514cb2
9 changed files with 86 additions and 53 deletions

View File

@ -41,7 +41,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-62</y>
<width>677</width>
<height>640</height>
</rect>
@ -340,9 +340,6 @@ $m - uptime minutes without zero</string>
</item>
<item>
<widget class="QComboBox" name="comboBox_netdev">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>

View File

@ -99,7 +99,7 @@ QString AwesomeWidget::getNetworkDevice()
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
for (int i=0; i<rawInterfaceList.count(); i++)
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
(rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)))
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)))
device = rawInterfaceList[i].name();
}
@ -117,7 +117,7 @@ int AwesomeWidget::getNumberCpus()
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return QTextCodec::codecForMib(106)->toUnicode(process.output).toInt();
return QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed().toInt();
}

View File

@ -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();

View File

@ -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; i<qoutput.split(QString("\n\n")).count(); i++) {
QString sensor = qoutput.split(QString("\n\n"))[i];
@ -196,7 +196,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_mount->clear();
for (int i=0; i<qoutput.split(QChar('\n')).count(); i++) {
QString mountPoint = qoutput.split(QChar('\n'))[i].split(QString(" on "))[1].split(QString(" type "))[0];

View File

@ -18,13 +18,16 @@
#include "customlabel.h"
#include <QGraphicsSceneMouseEvent>
#include <QTextCodec>
#include "awesome-widget.h"
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
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; i<qoutput.split(QChar('\n')).count(); i++)
if (qoutput.split(QChar('\n'))[i] != QString("ps --no-headers -o command"))
processes.append(qoutput.split(QChar('\n'))[i]);
text += QString("ps stats: %1 | %2")
.arg(processes.count())
.arg(processes.join(QChar(',')));
widget->sendNotification(QString("system"), text);
}
emit(Plasma::Label::mousePressEvent(event));
}

View File

@ -36,6 +36,7 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
AwesomeWidget *widget;
bool debug;
bool enablePopup;
};

View File

@ -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"),

View File

@ -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

View File

@ -17,10 +17,10 @@
#include "awesome-widget.h"
#include <KNotification>
#include <Plasma/ToolTipManager>
#include <QGraphicsLinearLayout>
#include <QGraphicsView>
//#include <QThread>
#include "customlabel.h"
#include <pdebug/pdebug.h>
@ -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;