now plasmoid works normally

This commit is contained in:
arcan1s 2014-02-01 04:19:53 +04:00
parent 695f697a9e
commit 40b05e2ea5
3 changed files with 104 additions and 20 deletions

View File

@ -46,7 +46,7 @@
<widget class="QLabel" name="label_autoUpdate">
<property name="minimumSize">
<size>
<width>100</width>
<width>150</width>
<height>23</height>
</size>
</property>
@ -170,6 +170,29 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_sudo">
<item>
<widget class="QCheckBox" name="checkBox_sudo">
<property name="minimumSize">
<size>
<width>150</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>Use sudo for netctl</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_sudo"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_showBigInterface">
<property name="text">
@ -624,6 +647,8 @@
<tabstop>pushButton_gui</tabstop>
<tabstop>lineEdit_netctl</tabstop>
<tabstop>pushButton_netctl</tabstop>
<tabstop>checkBox_sudo</tabstop>
<tabstop>lineEdit_sudo</tabstop>
<tabstop>checkBox_showBigInterface</tabstop>
<tabstop>checkBox_showNetDev</tabstop>
<tabstop>checkBox_showExtIp</tabstop>

View File

@ -27,11 +27,9 @@
#include <plasma/theme.h>
#include <QGraphicsLinearLayout>
#include <QMenu>
#include <QProcess>
// temporary
#include <stdio.h>
Netctl::Netctl(QObject *parent, const QVariantList &args) :
Plasma::Applet(parent, args)
@ -87,27 +85,58 @@ void Netctl::init()
// context menu
void Netctl::startProfileSlot()
void Netctl::startProfileSlot(QAction *action)
{
QProcess command;
QString commandLine;
commandLine = QString("");
if (status)
commandLine = netctlPath + QString(" stop ") + profileName + QString(" && ");
if (useSudo)
commandLine = sudoPath + QString(" \"") + commandLine + netctlPath + QString(" start ") + action->text().mid(1) + QString("\"");
else
commandLine = commandLine + netctlPath + QString(" start ") + action->text().mid(1);
command.startDetached(commandLine);
}
void Netctl::stopProfileSlot()
{
QProcess command;
QString commandLine;
if (useSudo)
commandLine = sudoPath + QString(" \"") + netctlPath + QString(" stop ") + profileName + QString("\"");
else
commandLine = netctlPath + QString(" stop ") + profileName;
command.startDetached(commandLine);
}
void Netctl::restartProfileSlot()
{
QProcess command;
QString commandLine;
if (useSudo)
commandLine = sudoPath + QString(" \"") + netctlPath + QString(" restart ") + profileName + QString("\"");
else
commandLine = netctlPath + QString(" restart ") + profileName;
command.startDetached(commandLine);
}
void Netctl::enableProfileAutoloadSlot()
{
QProcess command;
QString commandLine, enableStatus;
if (profileStatus == QString("(enable"))
enableStatus = QString("disable");
else
enableStatus = QString("enable");
if (useSudo)
commandLine = sudoPath + QString(" \"") + netctlPath + enableStatus + profileName + QString("\"");
else
commandLine = netctlPath + enableStatus + profileName;
command.startDetached(commandLine);
}
@ -116,6 +145,9 @@ void Netctl::createActions()
menuActions.clear();
startProfile = new QAction(QString("Start profile"), this);
startProfileMenu = new QMenu(NULL);
startProfile->setMenu(startProfileMenu);
connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileSlot(QAction *)));
menuActions.append(startProfile);
stopProfile = new QAction(QString("Stop profile"), this);
@ -153,6 +185,13 @@ QList<QAction*> Netctl::contextualActions()
enableProfileAutoload->setVisible(false);
}
startProfileMenu->clear();
for (int i=0; i<profileList.count(); i++) {
QAction *profile = new QAction(profileList[i], this);
startProfileMenu->addAction(profile);
}
return menuActions;
}
@ -167,7 +206,6 @@ void Netctl::showGui()
void Netctl::sendNotification(const QString eventId, const int num)
{
// send notification
KNotification *notification = new KNotification(eventId);
notification->setComponentData(KComponentData("plasma_applet_netctl"));
notification->setTitle(QString(i18n("Netctl plasmoid")));
@ -222,10 +260,10 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da
if (data.keys().count() == 0)
return;
QString value = data[QString("value")].toString();;
if (sourceName == QString("currentProfile")) {
if (value.isEmpty())
value = QString("N\\A");
if (sourceName == QString("currentProfile")) {
profileName = value;
// update text
@ -240,22 +278,16 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da
textLabel->setText(formatLine[0] + text.join(QString("<br>")) + formatLine[1]);
}
else if (sourceName == QString("extIp")) {
if (value.isEmpty())
value = QString("N\\A");
extIp = value;
}
else if (sourceName == QString("intIp")) {
if (value.isEmpty())
value = QString("N\\A");
intIp = value;
}
else if (sourceName == QString("interfaces")) {
if (value.isEmpty())
value = QString("N\\A");
interfaces = value;
}
else if (sourceName == QString("profiles")) {
return;
profileList = value.split(QString(","));
}
else if (sourceName == QString("statusBool")) {
if (value == QString("true")) {
@ -318,6 +350,11 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
uiConfig.spinBox_autoUpdate->setValue(autoUpdateInterval);
uiConfig.lineEdit_gui->setText(guiPath);
uiConfig.lineEdit_netctl->setText(netctlPath);
if (useSudo)
uiConfig.checkBox_sudo->setCheckState(Qt::Checked);
else
uiConfig.checkBox_sudo->setCheckState(Qt::Unchecked);
uiConfig.lineEdit_sudo->setText(sudoPath);
if (showBigInterface)
uiConfig.checkBox_showBigInterface->setCheckState(Qt::Checked);
else
@ -351,6 +388,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
parent->addPage(configwin, i18n("Netctl plasmoid"), Applet::icon());
connect(uiConfig.checkBox_showBigInterface, SIGNAL(stateChanged(int)), this, SLOT(setBigInterface()));
connect(uiConfig.checkBox_sudo, SIGNAL(stateChanged(int)), this, SLOT(setSudo()));
connect(uiConfig.pushButton_gui, SIGNAL(clicked()), this, SLOT(selectGuiExe()));
connect(uiConfig.pushButton_netctl, SIGNAL(clicked()), this, SLOT(selectNetctlExe()));
@ -370,6 +408,11 @@ void Netctl::configAccepted()
cg.writeEntry("autoUpdateInterval", uiConfig.spinBox_autoUpdate->value());
cg.writeEntry("guiPath", uiConfig.lineEdit_gui->text());
cg.writeEntry("netctlPath", uiConfig.lineEdit_netctl->text());
if (uiConfig.checkBox_sudo->checkState() == 0)
cg.writeEntry("useSudo", false);
else
cg.writeEntry("useSudo", true);
cg.writeEntry("sudoPath", uiConfig.lineEdit_sudo->text());
if (uiConfig.checkBox_showBigInterface->checkState() == 0)
cg.writeEntry("showBigInterface", false);
else
@ -404,6 +447,8 @@ void Netctl::configChanged()
autoUpdateInterval = cg.readEntry("autoUpdateInterval", 1000);
guiPath = cg.readEntry("guiPath", "/usr/bin/netctl-gui");
netctlPath = cg.readEntry("netctlPath", "/usr/bin/netctl");
useSudo = cg.readEntry("useSudo", true);
sudoPath = cg.readEntry("sudoPath", "/usr/bin/kdesu -c");
showBigInterface = cg.readEntry("showBigInterface", true);
showNetDev = cg.readEntry("showNetDev", true);
showExtIp = cg.readEntry("showExtIp", true);
@ -443,4 +488,13 @@ void Netctl::setBigInterface()
}
void Netctl::setSudo()
{
if (uiConfig.checkBox_sudo->checkState() == 0)
uiConfig.lineEdit_sudo->setDisabled(true);
else if (uiConfig.checkBox_showBigInterface->checkState() == 2)
uiConfig.lineEdit_sudo->setEnabled(true);
}
#include "netctl.moc"

View File

@ -46,6 +46,7 @@ public slots:
void configAccepted();
void configChanged();
void setBigInterface();
void setSudo();
private slots:
// configuration interface
@ -54,7 +55,7 @@ private slots:
void selectActiveIcon();
void selectInactiveIcon();
// context menu
void startProfileSlot();
void startProfileSlot(QAction *action);
void stopProfileSlot();
void restartProfileSlot();
void enableProfileAutoloadSlot();
@ -78,11 +79,13 @@ private:
QString intIp;
QString extIp;
QString interfaces;
QStringList profileList;
QStringList formatLine;
// context menu
void createActions();
QList<QAction*> menuActions;
QAction *startProfile;
QMenu *startProfileMenu;
QAction *stopProfile;
QAction *restartProfile;
QAction *enableProfileAutoload;
@ -95,6 +98,8 @@ private:
int autoUpdateInterval;
QString guiPath;
QString netctlPath;
bool useSudo;
QString sudoPath;
bool showBigInterface;
bool showNetDev;
bool showExtIp;