mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 16:07:19 +00:00
add notification module
fix definition of network deivce
This commit is contained in:
parent
a5c352bc06
commit
b61d514cb2
@ -41,7 +41,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>-62</y>
|
||||||
<width>677</width>
|
<width>677</width>
|
||||||
<height>640</height>
|
<height>640</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -340,9 +340,6 @@ $m - uptime minutes without zero</string>
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="comboBox_netdev">
|
<widget class="QComboBox" name="comboBox_netdev">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -99,7 +99,7 @@ QString AwesomeWidget::getNetworkDevice()
|
|||||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||||
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
|
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
|
||||||
(rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)))
|
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)))
|
||||||
device = rawInterfaceList[i].name();
|
device = rawInterfaceList[i].name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ int AwesomeWidget::getNumberCpus()
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
return QTextCodec::codecForMib(106)->toUnicode(process.output).toInt();
|
return QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed().toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ public slots:
|
|||||||
void configAccepted();
|
void configAccepted();
|
||||||
void configChanged();
|
void configChanged();
|
||||||
// update events
|
// update events
|
||||||
|
void sendNotification(const QString eventId, const QString message);
|
||||||
void updateNetworkDevice();
|
void updateNetworkDevice();
|
||||||
void updateText(bool clear = false);
|
void updateText(bool clear = false);
|
||||||
void updateTooltip();
|
void updateTooltip();
|
||||||
|
@ -170,7 +170,7 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
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();
|
uiAdvancedConfig.listWidget_tempDevice->clear();
|
||||||
for (int i=0; i<qoutput.split(QString("\n\n")).count(); i++) {
|
for (int i=0; i<qoutput.split(QString("\n\n")).count(); i++) {
|
||||||
QString sensor = qoutput.split(QString("\n\n"))[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 (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
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();
|
uiAdvancedConfig.listWidget_mount->clear();
|
||||||
for (int i=0; i<qoutput.split(QChar('\n')).count(); i++) {
|
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];
|
QString mountPoint = qoutput.split(QChar('\n'))[i].split(QString(" on "))[1].split(QString(" type "))[0];
|
||||||
|
@ -18,13 +18,16 @@
|
|||||||
#include "customlabel.h"
|
#include "customlabel.h"
|
||||||
|
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include "awesome-widget.h"
|
#include "awesome-widget.h"
|
||||||
#include <pdebug/pdebug.h>
|
#include <pdebug/pdebug.h>
|
||||||
|
#include <task/taskadds.h>
|
||||||
|
|
||||||
|
|
||||||
CustomLabel::CustomLabel(AwesomeWidget *wid, const bool debugCmd)
|
CustomLabel::CustomLabel(AwesomeWidget *wid, const bool debugCmd)
|
||||||
: Plasma::Label(wid),
|
: Plasma::Label(wid),
|
||||||
|
widget(wid),
|
||||||
debug(debugCmd)
|
debug(debugCmd)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -50,7 +53,59 @@ void CustomLabel::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button();
|
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));
|
emit(Plasma::Label::mousePressEvent(event));
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ protected:
|
|||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AwesomeWidget *widget;
|
||||||
bool debug;
|
bool debug;
|
||||||
bool enablePopup;
|
bool enablePopup;
|
||||||
};
|
};
|
||||||
|
@ -297,7 +297,7 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
|
|||||||
if (configuration[QString("useCustomNetdev")].toInt() == 2) {
|
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("/transmitter/data"), this);
|
||||||
sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/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"),
|
sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"),
|
||||||
this, configuration[QString("interval")].toInt());
|
this, configuration[QString("interval")].toInt());
|
||||||
sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"),
|
sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"),
|
||||||
|
@ -1,42 +1,7 @@
|
|||||||
[Global]
|
[Global]
|
||||||
IconName=system
|
IconName=system
|
||||||
Name=PyTextMonitor
|
Name=ptm-awesome-widget
|
||||||
Comment=PyTextMonitor information
|
Comment=Awesome widget 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
|
|
||||||
|
|
||||||
[Event/system]
|
[Event/system]
|
||||||
Name=System information
|
Name=System information
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include "awesome-widget.h"
|
#include "awesome-widget.h"
|
||||||
|
|
||||||
|
#include <KNotification>
|
||||||
#include <Plasma/ToolTipManager>
|
#include <Plasma/ToolTipManager>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
//#include <QThread>
|
|
||||||
|
|
||||||
#include "customlabel.h"
|
#include "customlabel.h"
|
||||||
#include <pdebug/pdebug.h>
|
#include <pdebug/pdebug.h>
|
||||||
@ -47,9 +47,9 @@ void AwesomeWidget::reinit()
|
|||||||
if (configuration[QString("leftStretch")].toInt() == 2)
|
if (configuration[QString("leftStretch")].toInt() == 2)
|
||||||
mainLayout->addStretch(1);
|
mainLayout->addStretch(1);
|
||||||
if (configuration[QString("popup")].toInt() == 0)
|
if (configuration[QString("popup")].toInt() == 0)
|
||||||
textLabel->setPopupEnabled(true);
|
|
||||||
else
|
|
||||||
textLabel->setPopupEnabled(false);
|
textLabel->setPopupEnabled(false);
|
||||||
|
else
|
||||||
|
textLabel->setPopupEnabled(true);
|
||||||
updateText(true);
|
updateText(true);
|
||||||
mainLayout->addItem(textLabel);
|
mainLayout->addItem(textLabel);
|
||||||
resize(10, 10);
|
resize(10, 10);
|
||||||
@ -59,12 +59,26 @@ void AwesomeWidget::reinit()
|
|||||||
keys = getKeys();
|
keys = getKeys();
|
||||||
foundKeys = findKeys();
|
foundKeys = findKeys();
|
||||||
initValues();
|
initValues();
|
||||||
values[QString("netdev")] = getNetworkDevice();
|
updateNetworkDevice();
|
||||||
// thread()->wait(60000);
|
|
||||||
connectToEngine();
|
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()
|
void AwesomeWidget::updateNetworkDevice()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
Loading…
Reference in New Issue
Block a user