mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-09 11:55:53 +00:00
edit of plasmoid
This commit is contained in:
@ -137,8 +137,10 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
}
|
}
|
||||||
else if (source == QString("intIp")) {
|
else if (source == QString("intIp")) {
|
||||||
if (QDir(netDir).exists()) {
|
if (QDir(netDir).exists()) {
|
||||||
|
value = QString("127.0.0.1/8");
|
||||||
QStringList netDevices = QDir(netDir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList netDevices = QDir(netDir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
for (int i=0; i<netDevices.count(); i++) {
|
for (int i=0; i<netDevices.count(); i++)
|
||||||
|
if (netDevices[i] != QString("lo")) {
|
||||||
cmdOutput = QString("");
|
cmdOutput = QString("");
|
||||||
command.start(ipCmd + QString(" addr show ") + netDevices[i]);
|
command.start(ipCmd + QString(" addr show ") + netDevices[i]);
|
||||||
command.waitForFinished(-1);
|
command.waitForFinished(-1);
|
||||||
|
@ -18,14 +18,11 @@
|
|||||||
#include "netctl.h"
|
#include "netctl.h"
|
||||||
#include "ui_configwindow.h"
|
#include "ui_configwindow.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <ctime>
|
|
||||||
#include <KConfigDialog>
|
#include <KConfigDialog>
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
#include <QGraphicsLinearLayout>
|
|
||||||
#include <QGraphicsSceneMouseEvent>
|
|
||||||
#include <Plasma/DataEngine>
|
#include <Plasma/DataEngine>
|
||||||
#include <Plasma/Frame>
|
#include <QGraphicsLinearLayout>
|
||||||
|
|
||||||
#include <plasma/theme.h>
|
#include <plasma/theme.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -36,15 +33,17 @@ Netctl::Netctl(QObject *parent, const QVariantList &args) :
|
|||||||
setBackgroundHints(DefaultBackground);
|
setBackgroundHints(DefaultBackground);
|
||||||
setHasConfigurationInterface(true);
|
setHasConfigurationInterface(true);
|
||||||
// text format init
|
// text format init
|
||||||
formatLine.append("");
|
formatLine.append(QString(""));
|
||||||
formatLine.append("");
|
formatLine.append(QString(""));
|
||||||
|
profileStatus = QString("N\\A");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Netctl::~Netctl()
|
Netctl::~Netctl()
|
||||||
{
|
{
|
||||||
delete iconWidget;
|
delete iconWidget;
|
||||||
delete textLabel;
|
delete iconFrame;
|
||||||
|
delete textFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,43 +51,34 @@ void Netctl::init()
|
|||||||
{
|
{
|
||||||
// generate ui
|
// generate ui
|
||||||
// main layout
|
// main layout
|
||||||
QGraphicsLinearLayout *fullSpaceLayout = new QGraphicsLinearLayout();
|
fullSpaceLayout = new QGraphicsLinearLayout();
|
||||||
fullSpaceLayout->setContentsMargins(0,0,0,0);
|
|
||||||
setLayout(fullSpaceLayout);
|
setLayout(fullSpaceLayout);
|
||||||
|
|
||||||
// frame
|
// frames
|
||||||
Plasma::Frame *frame = new Plasma::Frame();
|
|
||||||
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
|
|
||||||
layout->setContentsMargins(0,0,0,0);
|
|
||||||
frame->setLayout(layout);
|
|
||||||
fullSpaceLayout->addItem(frame);
|
|
||||||
|
|
||||||
// icon
|
// icon
|
||||||
iconWidget = new Plasma::IconWidget(KIcon("/home/arcanis/Documents/github/netctlplasmoid/sources/icons/network-idle-64x64.png"), QString(), this);
|
iconFrame = new Plasma::Frame();
|
||||||
iconWidget->setIcon(KIcon("/home/arcanis/Documents/github/netctlplasmoid/sources/icons/network-idle-64x64.png"));
|
QGraphicsLinearLayout *iconLayout = new QGraphicsLinearLayout();
|
||||||
// connect(shutdownIcon.iconWidget, SIGNAL(clicked()), this, SLOT(onShutdown()));
|
iconWidget = new Plasma::IconWidget(KIcon(""), QString(), this);
|
||||||
layout->addItem(iconWidget);
|
connect(iconWidget, SIGNAL(doubleClicked()), this, SLOT(showGui()));
|
||||||
|
iconFrame->setLayout(iconLayout);
|
||||||
// label
|
iconLayout->addItem(iconWidget);
|
||||||
textLabel = new Plasma::Label(this);
|
fullSpaceLayout->addItem(iconFrame);
|
||||||
textLabel->setText("test1\ntest2\ntest3");
|
// text
|
||||||
fullSpaceLayout->addItem(textLabel);
|
textFrame = new Plasma::Frame();
|
||||||
|
QGraphicsLinearLayout *textLayout = new QGraphicsLinearLayout();
|
||||||
|
textLabel = new Plasma::Label();
|
||||||
|
textLayout->addItem(textLabel);
|
||||||
|
fullSpaceLayout->addStretch(1);
|
||||||
|
|
||||||
// read variables
|
// read variables
|
||||||
configChanged();
|
configChanged();
|
||||||
this->resize(100,48);
|
this->resize(150,64);
|
||||||
|
|
||||||
// connect to dataengine
|
|
||||||
connectToEngine();
|
|
||||||
printf ("done init\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Netctl::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
int Netctl::showGui()
|
||||||
{
|
{
|
||||||
// mouse double click event
|
return 0;
|
||||||
// add gui support
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,15 +98,39 @@ int Netctl::sendNotification(QString eventId, int num)
|
|||||||
// data engine interaction
|
// data engine interaction
|
||||||
void Netctl::connectToEngine()
|
void Netctl::connectToEngine()
|
||||||
{
|
{
|
||||||
printf ("source\n");
|
|
||||||
Plasma::DataEngine *netctlEngine = dataEngine(QString("netctl"));
|
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("profiles"), this, autoUpdateInterval);
|
||||||
netctlEngine->connectSource(QString("statusBool"), this, autoUpdateInterval);
|
netctlEngine->connectSource(QString("statusBool"), this, autoUpdateInterval);
|
||||||
|
if (showBigInterface) {
|
||||||
|
netctlEngine->connectSource(QString("currentProfile"), this, autoUpdateInterval);
|
||||||
netctlEngine->connectSource(QString("statusString"), this, autoUpdateInterval);
|
netctlEngine->connectSource(QString("statusString"), this, autoUpdateInterval);
|
||||||
|
if (showExtIp)
|
||||||
|
netctlEngine->connectSource(QString("extIp"), this, autoUpdateInterval);
|
||||||
|
if (showIntIp)
|
||||||
|
netctlEngine->connectSource(QString("intIp"), this, autoUpdateInterval);
|
||||||
|
if (showNetDev)
|
||||||
|
netctlEngine->connectSource(QString("interfaces"), this, autoUpdateInterval);
|
||||||
|
fullSpaceLayout->insertItem(1, textFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Netctl::disconnectFromEngine()
|
||||||
|
{
|
||||||
|
Plasma::DataEngine *netctlEngine = dataEngine(QString("netctl"));
|
||||||
|
netctlEngine->disconnectSource(QString("profiles"), this);
|
||||||
|
netctlEngine->disconnectSource(QString("statusBool"), this);
|
||||||
|
if (showBigInterface) {
|
||||||
|
netctlEngine->disconnectSource(QString("currentProfile"), this);
|
||||||
|
netctlEngine->disconnectSource(QString("statusString"), this);
|
||||||
|
if (showExtIp)
|
||||||
|
netctlEngine->disconnectSource(QString("extIp"), this);
|
||||||
|
if (showIntIp)
|
||||||
|
netctlEngine->disconnectSource(QString("intIp"), this);
|
||||||
|
if (showNetDev)
|
||||||
|
netctlEngine->disconnectSource(QString("interfaces"), this);
|
||||||
|
fullSpaceLayout->removeItem(textFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,16 +138,41 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da
|
|||||||
{
|
{
|
||||||
if (data.keys().count() == 0)
|
if (data.keys().count() == 0)
|
||||||
return;
|
return;
|
||||||
QString value;
|
QString value = data[QString("value")].toString();;
|
||||||
printf ("dataupdate\n");
|
|
||||||
|
|
||||||
if (sourceName == QString("currentProfile"))
|
if (sourceName == QString("currentProfile")) {
|
||||||
{
|
|
||||||
value = data[QString("value")].toString();
|
|
||||||
if (value == QString(""))
|
if (value == QString(""))
|
||||||
value = QString("N\\A");
|
value = QString("N\\A");
|
||||||
textLabel->setText(value);
|
profileName = value;
|
||||||
}
|
}
|
||||||
|
else if (sourceName == QString("extIp")) {
|
||||||
|
if (value == QString(""))
|
||||||
|
value = QString("N\\A");
|
||||||
|
extIp = value;
|
||||||
|
}
|
||||||
|
else if (sourceName == QString("intIp")) {
|
||||||
|
if (value == QString(""))
|
||||||
|
value = QString("N\\A");
|
||||||
|
intIp = value;
|
||||||
|
}
|
||||||
|
else if (sourceName == QString("interfaces")) {
|
||||||
|
if (value == QString(""))
|
||||||
|
value = QString("N\\A");
|
||||||
|
interfaces = value;
|
||||||
|
}
|
||||||
|
else if (sourceName == QString("profiles")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (sourceName == QString("statusBool")) {
|
||||||
|
if (value == QString("true"))
|
||||||
|
iconWidget->setIcon(activeIconPath);
|
||||||
|
else
|
||||||
|
iconWidget->setIcon(inactiveIconPath);
|
||||||
|
}
|
||||||
|
else if (sourceName == QString("statusString")) {
|
||||||
|
profileStatus = QString("(") + value + QString(")");
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +223,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
|||||||
|
|
||||||
void Netctl::configAccepted()
|
void Netctl::configAccepted()
|
||||||
{
|
{
|
||||||
|
disconnectFromEngine();
|
||||||
KConfigGroup cg = config();
|
KConfigGroup cg = config();
|
||||||
|
|
||||||
cg.writeEntry("autoUpdateInterval", uiConfig.spinBox_autoUpdate->value());
|
cg.writeEntry("autoUpdateInterval", uiConfig.spinBox_autoUpdate->value());
|
||||||
@ -231,8 +271,10 @@ void Netctl::configChanged()
|
|||||||
fontColor = cg.readEntry("fontColor", "#000000");
|
fontColor = cg.readEntry("fontColor", "#000000");
|
||||||
fontWeight = cg.readEntry("fontWeight", 400);
|
fontWeight = cg.readEntry("fontWeight", 400);
|
||||||
fontStyle = cg.readEntry("fontStyle", "normal");
|
fontStyle = cg.readEntry("fontStyle", "normal");
|
||||||
activeIconPath = cg.readEntry("activeIconPath", "/usr/share/icons/hicolor/64x64/apps/network-idle.png");
|
// activeIconPath = cg.readEntry("activeIconPath", "/usr/share/icons/hicolor/64x64/apps/network-idle.png");
|
||||||
inactiveIconPath = cg.readEntry("inactiveIconPath", "/usr/share/icons/hicolor/64x64/apps/network-offline.png");
|
// inactiveIconPath = cg.readEntry("inactiveIconPath", "/usr/share/icons/hicolor/64x64/apps/network-offline.png");
|
||||||
|
activeIconPath = cg.readEntry("activeIconPath", "/home/arcanis/Documents/github/netctlplasmoid/sources/icons/network-idle-64x64.png");
|
||||||
|
inactiveIconPath = cg.readEntry("inactiveIconPath", "/home/arcanis/Documents/github/netctlplasmoid/sources/icons/network-offline-64x64.png");
|
||||||
|
|
||||||
formatLine[0] = ("<p align=\"justify\"><span style=\" font-family:'" + fontFamily + \
|
formatLine[0] = ("<p align=\"justify\"><span style=\" font-family:'" + fontFamily + \
|
||||||
"'; font-style:" + fontStyle + \
|
"'; font-style:" + fontStyle + \
|
||||||
@ -241,6 +283,7 @@ void Netctl::configChanged()
|
|||||||
"; color:" + fontColor + \
|
"; color:" + fontColor + \
|
||||||
";\">");
|
";\">");
|
||||||
formatLine[1] = ("</span></p>");
|
formatLine[1] = ("</span></p>");
|
||||||
|
connectToEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#define NETCTL_PLASMOID_H
|
#define NETCTL_PLASMOID_H
|
||||||
|
|
||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
|
#include <Plasma/Frame>
|
||||||
|
#include <Plasma/IconWidget>
|
||||||
#include <Plasma/Label>
|
#include <Plasma/Label>
|
||||||
#include <plasma/widgets/iconwidget.h>
|
|
||||||
|
|
||||||
#include <ui_configwindow.h>
|
#include <ui_configwindow.h>
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// ui
|
// ui
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
int showGui();
|
||||||
int sendNotification(QString eventId, int num);
|
int sendNotification(QString eventId, int num);
|
||||||
// for dataengine
|
// for dataengine
|
||||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
||||||
@ -51,11 +52,22 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// ui
|
// ui
|
||||||
|
QGraphicsLinearLayout *fullSpaceLayout;
|
||||||
|
// icon
|
||||||
|
Plasma::Frame *iconFrame;
|
||||||
Plasma::IconWidget *iconWidget;
|
Plasma::IconWidget *iconWidget;
|
||||||
|
// text
|
||||||
|
Plasma::Frame *textFrame;
|
||||||
Plasma::Label *textLabel;
|
Plasma::Label *textLabel;
|
||||||
|
QString profileName;
|
||||||
|
QString profileStatus;
|
||||||
|
QString intIp;
|
||||||
|
QString extIp;
|
||||||
|
QString interfaces;
|
||||||
QStringList formatLine;
|
QStringList formatLine;
|
||||||
// data engine
|
// data engine
|
||||||
void connectToEngine();
|
void connectToEngine();
|
||||||
|
void disconnectFromEngine();
|
||||||
// configuration interface
|
// configuration interface
|
||||||
Ui::ConfigWindow uiConfig;
|
Ui::ConfigWindow uiConfig;
|
||||||
// configuration
|
// configuration
|
||||||
|
Reference in New Issue
Block a user