mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 23:47:21 +00:00
add plasmoid helper integration
This commit is contained in:
parent
501b43002e
commit
fe672aa8cc
@ -64,7 +64,7 @@ Additional information
|
||||
TODO (wish list)
|
||||
----------------
|
||||
|
||||
* plasmoid helper integration
|
||||
* refactoring (I think that classes with more than 1k lines is not good :/)
|
||||
* remove suid from helper (polkit integration or run through sudo)
|
||||
* security notes / project architecture
|
||||
* autotests
|
||||
|
@ -435,6 +435,20 @@ void MainWindow::reportABug()
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::checkHelperStatus()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[checkHelperStatus]";
|
||||
|
||||
if (useHelper) useHelper = isHelperActive();
|
||||
if (useHelper)
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Update"),
|
||||
QList<QVariant>(), true, debug);
|
||||
if (isHelperServiceActive())
|
||||
configuration[QString("CLOSE_HELPER")] = QString("false");
|
||||
}
|
||||
|
||||
|
||||
// main tab slots
|
||||
void MainWindow::mainTabContextualMenu(const QPoint &pos)
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "aboutwindow.h"
|
||||
@ -495,6 +496,9 @@ void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
|
||||
useHelper = false;
|
||||
configuration[QString("USE_HELPER")] = QString("false");
|
||||
}
|
||||
// some helper fixs
|
||||
// because interface will be created with a delay
|
||||
QTimer::singleShot(1000, this, SLOT(checkHelperStatus()));
|
||||
|
||||
// update translation
|
||||
qApp->removeTranslator(translator);
|
||||
@ -506,14 +510,6 @@ void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
|
||||
delete settingsWin;
|
||||
|
||||
createObjects();
|
||||
// some helper fixs
|
||||
if (useHelper) useHelper = isHelperActive();
|
||||
if (useHelper)
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Update"),
|
||||
QList<QVariant>(), true, debug);
|
||||
if (isHelperServiceActive())
|
||||
configuration[QString("CLOSE_HELPER")] = QString("false");
|
||||
// update ui
|
||||
setTab(args[QString("tab")].toInt() - 1);
|
||||
createActions();
|
||||
|
@ -96,6 +96,7 @@ public slots:
|
||||
void setHiddenName(const QString name);
|
||||
|
||||
private slots:
|
||||
void checkHelperStatus();
|
||||
void reportABug();
|
||||
// menu update slots
|
||||
void setMenuActionsShown(const bool state = true);
|
||||
|
@ -23,10 +23,13 @@
|
||||
#include <KUrl>
|
||||
#include <plasma/theme.h>
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QMenu>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTimer>
|
||||
|
||||
#include "netctl.h"
|
||||
#include "ui_about.h"
|
||||
@ -290,8 +293,6 @@ void Netctl::enableProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[enableProfileSlot]";
|
||||
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
QString enableStatus = QString("");
|
||||
if (info[QString("status")].contains(QString("enabled"))) {
|
||||
enableStatus = QString(" disable ");
|
||||
@ -301,11 +302,40 @@ void Netctl::enableProfileSlot()
|
||||
enableStatus = QString(" enable ");
|
||||
sendNotification(QString("Info"), i18n("Set profile %1 enabled", info[QString("name")]));
|
||||
}
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + enableStatus + info[QString("name")];
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(info[QString("name")]);
|
||||
sendDBusRequest(QString("Enable"), args);
|
||||
}
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + enableStatus + info[QString("name")];
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
command.startDetached(commandLine);
|
||||
|
||||
void Netctl::restartProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[restartProfileSlot]";
|
||||
|
||||
sendNotification(QString("Info"), i18n("Restart profile %1", info[QString("name")]));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(info[QString("name")]);
|
||||
sendDBusRequest(QString("Restart"), args);
|
||||
}
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + QString(" restart ") + info[QString("name")];
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -314,17 +344,26 @@ void Netctl::startProfileSlot(QAction *profile)
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[startProfileSlot]";
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[startProfileSlot]" << ":" << "Profile" << profile->text().remove(QChar('&'));
|
||||
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Start profile %1", profile->text().remove(QChar('&'))));
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
if (status)
|
||||
commandLine += paths[QString("netctl")] + QString(" switch-to ") + profile->text().remove(QChar('&'));
|
||||
else
|
||||
commandLine += paths[QString("netctl")] + QString(" start ") + profile->text().remove(QChar('&'));
|
||||
|
||||
command.startDetached(commandLine);
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile->text().remove(QChar('&')));
|
||||
if (status)
|
||||
sendDBusRequest(QString("SwitchTo"), args);
|
||||
else
|
||||
sendDBusRequest(QString("Start"), args);
|
||||
}
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
if (status)
|
||||
commandLine += paths[QString("netctl")] + QString(" switch-to ") + profile->text().remove(QChar('&'));
|
||||
else
|
||||
commandLine += paths[QString("netctl")] + QString(" start ") + profile->text().remove(QChar('&'));
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -332,14 +371,20 @@ void Netctl::stopProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[stopProfileSlot]";
|
||||
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Stop profile %1", info[QString("name")]));
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + QString(" stop ") + info[QString("name")];
|
||||
|
||||
command.startDetached(commandLine);
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(info[QString("name")]);
|
||||
sendDBusRequest(QString("Start"), args);
|
||||
}
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + QString(" stop ") + info[QString("name")];
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -348,29 +393,37 @@ void Netctl::switchToProfileSlot(QAction *profile)
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[switchToProfileSlot]";
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[switchToProfileSlot]" << ":" << "Profile" << profile->text().remove(QChar('&'));
|
||||
|
||||
QProcess command;
|
||||
QString commandLine;
|
||||
commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Switch to profile %1", profile->text().remove(QChar('&'))));
|
||||
commandLine = paths[QString("netctlAuto")] + QString(" switch-to ") +
|
||||
profile->text().remove(QChar('&'));
|
||||
|
||||
sendNotification(QString("Info"), i18n("Switch to profile %1", profile->text().remove(QChar('&'))));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile->text().remove(QChar('&')));
|
||||
sendDBusRequest(QString("autoStart"), args);
|
||||
}
|
||||
else {
|
||||
QProcess command;
|
||||
QString commandLine = paths[QString("netctlAuto")] + QString(" switch-to ") +
|
||||
profile->text().remove(QChar('&'));
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Netctl::startHelper()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[startHelper]";
|
||||
|
||||
QProcess command;
|
||||
QString commandLine = paths[QString("helper")];
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
|
||||
|
||||
void Netctl::restartProfileSlot()
|
||||
void Netctl::checkHelperStatus()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[restartProfileSlot]";
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[checkHelperStatus]";
|
||||
|
||||
QProcess command;
|
||||
QString commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Restart profile %1", info[QString("name")]));
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ");
|
||||
commandLine += paths[QString("netctl")] + QString(" restart ") + info[QString("name")];
|
||||
|
||||
command.startDetached(commandLine);
|
||||
if (useHelper) useHelper = !sendDBusRequest(QString("Active"), QList<QVariant>()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@ -608,6 +661,26 @@ void Netctl::disconnectFromEngine()
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant> Netctl::sendDBusRequest(const QString cmd, const QList<QVariant> args)
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[sendDBusRequest]";
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[sendDBusRequest]" << ":" << "cmd" << cmd;
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[sendDBusRequest]" << ":" << "args" << args;
|
||||
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, cmd);
|
||||
if (!args.isEmpty())
|
||||
request.setArguments(args);
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
if (arguments.size() == 0)
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[sendDBusRequest]" << ":" << "Error message" << response.errorMessage();
|
||||
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
// configuration interface
|
||||
void Netctl::selectAbstractSomething()
|
||||
{
|
||||
@ -625,6 +698,8 @@ void Netctl::selectAbstractSomething()
|
||||
}
|
||||
else if (sender() == uiWidConfig.pushButton_gui)
|
||||
lineEdit = uiWidConfig.lineEdit_gui;
|
||||
else if (sender() == uiWidConfig.pushButton_helper)
|
||||
lineEdit = uiWidConfig.lineEdit_helper;
|
||||
else if (sender() == uiWidConfig.pushButton_netctl)
|
||||
lineEdit = uiWidConfig.lineEdit_netctl;
|
||||
else if (sender() == uiWidConfig.pushButton_netctlAuto)
|
||||
@ -662,6 +737,12 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
||||
|
||||
uiWidConfig.spinBox_autoUpdate->setValue(autoUpdateInterval);
|
||||
uiWidConfig.lineEdit_gui->setText(paths[QString("gui")]);
|
||||
if (useHelper)
|
||||
uiWidConfig.checkBox_helper->setCheckState(Qt::Checked);
|
||||
else
|
||||
uiWidConfig.checkBox_helper->setCheckState(Qt::Unchecked);
|
||||
uiWidConfig.lineEdit_helper->setText(paths[QString("helper")]);
|
||||
setHelper();
|
||||
uiWidConfig.lineEdit_netctl->setText(paths[QString("netctl")]);
|
||||
uiWidConfig.lineEdit_netctlAuto->setText(paths[QString("netctlAuto")]);
|
||||
if (useSudo)
|
||||
@ -742,6 +823,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
||||
parent->addPage(deWidget, i18n("DataEngine"), Applet::icon());
|
||||
parent->addPage(aboutWidget, i18n("About"), QString("help-about"));
|
||||
|
||||
connect(uiWidConfig.checkBox_helper, SIGNAL(stateChanged(int)), this, SLOT(setHelper()));
|
||||
connect(uiWidConfig.checkBox_showBigInterface, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(setBigInterface()));
|
||||
connect(uiWidConfig.checkBox_sudo, SIGNAL(stateChanged(int)), this, SLOT(setSudo()));
|
||||
@ -750,6 +832,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
||||
connect(uiDEConfig.checkBox_extIp6, SIGNAL(stateChanged(int)), this, SLOT(setDataEngineExternalIp6()));
|
||||
|
||||
connect(uiWidConfig.pushButton_gui, SIGNAL(clicked()), this, SLOT(selectAbstractSomething()));
|
||||
connect(uiWidConfig.pushButton_helper, SIGNAL(clicked()), this, SLOT(selectAbstractSomething()));
|
||||
connect(uiWidConfig.pushButton_netctl, SIGNAL(clicked()), this, SLOT(selectAbstractSomething()));
|
||||
connect(uiWidConfig.pushButton_netctlAuto, SIGNAL(clicked()), this, SLOT(selectAbstractSomething()));
|
||||
connect(uiWidConfig.pushButton_sudo, SIGNAL(clicked()), this, SLOT(selectAbstractSomething()));
|
||||
@ -775,6 +858,11 @@ void Netctl::configAccepted()
|
||||
|
||||
cg.writeEntry("autoUpdateInterval", uiWidConfig.spinBox_autoUpdate->value());
|
||||
cg.writeEntry("guiPath", uiWidConfig.lineEdit_gui->text());
|
||||
if (uiWidConfig.checkBox_helper->checkState() == 0)
|
||||
cg.writeEntry("useHelper", false);
|
||||
else
|
||||
cg.writeEntry("useHelper", true);
|
||||
cg.writeEntry("helperPath", uiWidConfig.lineEdit_helper->text());
|
||||
cg.writeEntry("netctlPath", uiWidConfig.lineEdit_netctl->text());
|
||||
cg.writeEntry("netctlAutoPath", uiWidConfig.lineEdit_netctlAuto->text());
|
||||
if (uiWidConfig.checkBox_sudo->checkState() == 0)
|
||||
@ -829,6 +917,7 @@ void Netctl::configChanged()
|
||||
|
||||
autoUpdateInterval = cg.readEntry("autoUpdateInterval", 1000);
|
||||
paths[QString("gui")] = cg.readEntry("guiPath", "/usr/bin/netctl-gui");
|
||||
paths[QString("helper")] = cg.readEntry("helperPath", "/usr/bin/netctlgui-helper");
|
||||
paths[QString("netctl")] = cg.readEntry("netctlPath", "/usr/bin/netctl");
|
||||
paths[QString("netctlAuto")] = cg.readEntry("netctlAutoPath", "/usr/bin/netctl-auto");
|
||||
paths[QString("sudo")] = cg.readEntry("sudoPath", "/usr/bin/kdesu");
|
||||
@ -836,6 +925,7 @@ void Netctl::configChanged()
|
||||
useSudo = cg.readEntry("useSudo", true);
|
||||
useWifi = cg.readEntry("useWifi", false);
|
||||
bigInterface = cg.readEntry("showBigInterface", true);
|
||||
useHelper = cg.readEntry("useHelper", true);
|
||||
textPattern = cg.readEntry("textPattern", "$current $status<br>IPv4: $intip4<br>IPv6: $intip6");
|
||||
|
||||
QString textAlign = cg.readEntry("textAlign", "center");
|
||||
@ -860,6 +950,8 @@ void Netctl::configChanged()
|
||||
.arg(fontColor);
|
||||
formatLine[1] = QString("</p></body></html>");
|
||||
|
||||
if (useHelper) startHelper();
|
||||
QTimer::singleShot(1000, this, SLOT(checkHelperStatus()));
|
||||
connectToEngine();
|
||||
}
|
||||
|
||||
@ -905,6 +997,19 @@ void Netctl::setDataEngineExternalIp6()
|
||||
}
|
||||
|
||||
|
||||
void Netctl::setHelper()
|
||||
{
|
||||
if (uiWidConfig.checkBox_helper->checkState() == 0) {
|
||||
uiWidConfig.lineEdit_helper->setDisabled(true);
|
||||
uiWidConfig.pushButton_helper->setDisabled(true);
|
||||
}
|
||||
else if (uiWidConfig.checkBox_helper->checkState() == 2) {
|
||||
uiWidConfig.lineEdit_helper->setEnabled(true);
|
||||
uiWidConfig.pushButton_helper->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Netctl::setSudo()
|
||||
{
|
||||
if (debug) qDebug() << "[PLASMOID]" << "[setSudo]";
|
||||
|
@ -73,6 +73,7 @@ public slots:
|
||||
void setBigInterface();
|
||||
void setDataEngineExternalIp();
|
||||
void setDataEngineExternalIp6();
|
||||
void setHelper();
|
||||
void setSudo();
|
||||
void setWifi();
|
||||
|
||||
@ -84,10 +85,13 @@ private slots:
|
||||
void selectAbstractSomething();
|
||||
// context menu
|
||||
void enableProfileSlot();
|
||||
void restartProfileSlot();
|
||||
void startProfileSlot(QAction *profile);
|
||||
void stopProfileSlot();
|
||||
void switchToProfileSlot(QAction *profile);
|
||||
void restartProfileSlot();
|
||||
// helper
|
||||
void checkHelperStatus();
|
||||
void startHelper();
|
||||
|
||||
protected:
|
||||
void createConfigurationInterface(KConfigDialog *parent);
|
||||
@ -113,6 +117,7 @@ private:
|
||||
Plasma::DataEngine *netctlEngine;
|
||||
void connectToEngine();
|
||||
void disconnectFromEngine();
|
||||
QList<QVariant> sendDBusRequest(const QString cmd, const QList<QVariant> args = QList<QVariant>());
|
||||
// configuration interface
|
||||
Ui::AppearanceWindow uiAppConfig;
|
||||
Ui::DataEngineWindow uiDEConfig;
|
||||
@ -125,7 +130,7 @@ private:
|
||||
QString textPattern;
|
||||
QStringList formatLine;
|
||||
QMap<QString, QString> paths;
|
||||
bool useSudo, useWifi;
|
||||
bool useHelper, useSudo, useWifi;
|
||||
};
|
||||
|
||||
K_EXPORT_PLASMA_APPLET(netctl, Netctl)
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>335</height>
|
||||
<height>342</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@ -111,6 +111,42 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_helper">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_helper">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use helper</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_helper"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_helper">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_netctl">
|
||||
<item>
|
||||
|
Loading…
Reference in New Issue
Block a user