it works!

This commit is contained in:
arcan1s 2014-01-31 15:50:42 +04:00
parent ef5d319337
commit 0f5cd12f17
4 changed files with 54 additions and 7 deletions

View File

@ -1,4 +1,4 @@
netctlmonitor netctl-plasmoid
============= ===============
Plasmoid written on C++ which interacts with netctl Plasmoid written on C++ which interacts with netctl

View File

@ -200,15 +200,19 @@ bool Netctl::updateSourceEvent(const QString &source)
command.start(cmd + QString(" status ") + currentProfile); command.start(cmd + QString(" status ") + currentProfile);
command.waitForFinished(-1); command.waitForFinished(-1);
cmdOutput = command.readAllStandardOutput(); cmdOutput = command.readAllStandardOutput();
value = QString("static");
if (cmdOutput != QString("")) { if (cmdOutput != QString("")) {
QStringList profile = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); QStringList profile = cmdOutput.split(QString("\n"), QString::SkipEmptyParts);
for (int i=0; i<profile.count(); i++) for (int i=0; i<profile.count(); i++)
if (profile[i].split(QString(" "), QString::SkipEmptyParts)[0] == QString("Loaded:")) if (profile[i].split(QString(" "), QString::SkipEmptyParts)[0] == QString("Loaded:")) {
if (profile[i].indexOf(QString("enabled")) > -1) { if (profile[i].indexOf(QString("enabled")) > -1) {
value = QString("enabled"); value = QString("enabled");
break; break;
} }
else if (profile[i].indexOf(QString("static")) > -1) {
value = QString("static");
break;
}
}
} }
setData(source, QString("value"), value); setData(source, QString("value"), value);
} }

View File

@ -24,6 +24,7 @@
#include <KNotification> #include <KNotification>
#include <QGraphicsLinearLayout> #include <QGraphicsLinearLayout>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <Plasma/DataEngine>
#include <Plasma/Frame> #include <Plasma/Frame>
#include <plasma/theme.h> #include <plasma/theme.h>
#include <stdio.h> #include <stdio.h>
@ -75,7 +76,11 @@ void Netctl::init()
// read variables // read variables
configChanged(); configChanged();
this->resize(-1,48); this->resize(100,48);
// connect to dataengine
connectToEngine();
printf ("done init\n");
} }
@ -100,6 +105,39 @@ int Netctl::sendNotification(QString eventId, int num)
} }
// data engine interaction
void Netctl::connectToEngine()
{
printf ("source\n");
Plasma::DataEngine *netctlEngine = dataEngine(QString("netctl"));
netctlEngine->connectSource(QString("currentProfile"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("extIp"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("interfaces"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("intIp"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("profiles"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("statusBool"), this, autoUpdateInterval);
netctlEngine->connectSource(QString("statusString"), this, autoUpdateInterval);
}
void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
{
if (data.keys().count() == 0)
return;
QString value;
printf ("dataupdate\n");
if (sourceName == QString("currentProfile"))
{
value = data[QString("value")].toString();
if (value == QString(""))
value = QString("N\\A");
textLabel->setText(value);
}
update();
}
// configuration interface // configuration interface
void Netctl::createConfigurationInterface(KConfigDialog *parent) void Netctl::createConfigurationInterface(KConfigDialog *parent)
{ {

View File

@ -36,8 +36,11 @@ public:
void init(); void init();
public slots: public slots:
// ui
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
int sendNotification(QString eventId, int num); int sendNotification(QString eventId, int num);
// for dataengine
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
// for configuration interface // for configuration interface
void configAccepted(); void configAccepted();
void configChanged(); void configChanged();
@ -51,6 +54,10 @@ private:
Plasma::IconWidget *iconWidget; Plasma::IconWidget *iconWidget;
Plasma::Label *textLabel; Plasma::Label *textLabel;
QStringList formatLine; QStringList formatLine;
// data engine
void connectToEngine();
// configuration interface
Ui::ConfigWindow uiConfig;
// configuration // configuration
int autoUpdateInterval; int autoUpdateInterval;
QString guiPath; QString guiPath;
@ -65,8 +72,6 @@ private:
QString fontStyle; QString fontStyle;
QString activeIconPath; QString activeIconPath;
QString inactiveIconPath; QString inactiveIconPath;
// configuration interface
Ui::ConfigWindow uiConfig;
}; };
K_EXPORT_PLASMA_APPLET(netctl, Netctl) K_EXPORT_PLASMA_APPLET(netctl, Netctl)