refactoring of plasmoid

added function to start wifi menu
This commit is contained in:
arcan1s 2014-04-12 15:27:14 +04:00
parent 501151828d
commit 92ec04cae1
5 changed files with 149 additions and 35 deletions

View File

@ -3,7 +3,7 @@
ARCHIVE="netctl-gui"
SRCDIR="sources"
FILES="AUTHORS CHANGELOG COPYING README.md"
IGNORELIST="gui/resources/translations/english.qm gui/resources/translations/russian.qm"
IGNORELIST="build gui/resources/translations/english.qm gui/resources/translations/russian.qm dataengine/dataengine.cppcheck gui/gui.cppcheck plasmoid/plasmoid.cppcheck"
VERSION=$(grep -m1 PROJECT_VERSION_MAJOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\
$(grep -m1 PROJECT_VERSION_MINOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\
$(grep -m1 PROJECT_VERSION_PATCH sources/CMakeLists.txt | awk '{print $3}' | cut -c 1)

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>480</width>
<height>320</height>
<height>343</height>
</rect>
</property>
<property name="minimumSize">
@ -185,6 +185,55 @@
<item>
<widget class="QLineEdit" name="lineEdit_sudo"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_sudo">
<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_wifi">
<item>
<widget class="QCheckBox" name="checkBox_wifi">
<property name="minimumSize">
<size>
<width>150</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>Show 'Start WiFi menu'</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_wifi"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_wifi">
<property name="minimumSize">
<size>
<width>100</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -643,6 +692,10 @@
<tabstop>pushButton_netctl</tabstop>
<tabstop>checkBox_sudo</tabstop>
<tabstop>lineEdit_sudo</tabstop>
<tabstop>pushButton_sudo</tabstop>
<tabstop>checkBox_wifi</tabstop>
<tabstop>lineEdit_wifi</tabstop>
<tabstop>pushButton_wifi</tabstop>
<tabstop>checkBox_showBigInterface</tabstop>
<tabstop>checkBox_showNetDev</tabstop>
<tabstop>checkBox_showExtIp</tabstop>

View File

@ -175,23 +175,27 @@ void Netctl::restartProfileSlot()
QList<QAction*> Netctl::contextualActions()
{
if (status) {
startProfile->setText(i18n("Start another profile"));
stopProfile->setVisible(true);
stopProfile->setText(i18n("Stop ") + info[QString("name")]);
restartProfile->setVisible(true);
restartProfile->setText(i18n("Restart ") + info[QString("name")]);
enableProfile->setVisible(true);
contextMenu[QString("start")]->setText(i18n("Start another profile"));
contextMenu[QString("stop")]->setVisible(true);
contextMenu[QString("stop")]->setText(i18n("Stop ") + info[QString("name")]);
contextMenu[QString("restart")]->setVisible(true);
contextMenu[QString("restart")]->setText(i18n("Restart ") + info[QString("name")]);
contextMenu[QString("enable")]->setVisible(true);
if (info[QString("status")].contains(QString("enabled")))
enableProfile->setText(i18n("Disable ") + info[QString("name")]);
contextMenu[QString("enable")]->setText(i18n("Disable ") + info[QString("name")]);
else
enableProfile->setText(i18n("Enable ") + info[QString("name")]);
contextMenu[QString("enable")]->setText(i18n("Enable ") + info[QString("name")]);
}
else {
startProfile->setText(i18n("Start profile"));
stopProfile->setVisible(false);
restartProfile->setVisible(false);
enableProfile->setVisible(false);
contextMenu[QString("start")]->setText(i18n("Start profile"));
contextMenu[QString("stop")]->setVisible(false);
contextMenu[QString("restart")]->setVisible(false);
contextMenu[QString("enable")]->setVisible(false);
}
if (useWifi)
contextMenu[QString("wifi")]->setVisible(true);
else
contextMenu[QString("wifi")]->setVisible(false);
startProfileMenu->clear();
for (int i=0; i<profileList.count(); i++) {
@ -207,24 +211,28 @@ void Netctl::createActions()
{
menuActions.clear();
startProfile = new QAction(i18n("Start profile"), this);
contextMenu[QString("start")] = new QAction(i18n("Start profile"), this);
startProfileMenu = new QMenu(NULL);
startProfile->setMenu(startProfileMenu);
contextMenu[QString("start")]->setMenu(startProfileMenu);
connect(startProfileMenu, SIGNAL(triggered(QAction *)), this,
SLOT(startProfileSlot(QAction *)));
menuActions.append(startProfile);
menuActions.append(contextMenu[QString("start")]);
stopProfile = new QAction(i18n("Stop profile"), this);
connect(stopProfile, SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
menuActions.append(stopProfile);
contextMenu[QString("stop")] = new QAction(i18n("Stop profile"), this);
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
menuActions.append(contextMenu[QString("stop")]);
restartProfile = new QAction(i18n("Restart profile"), this);
connect(restartProfile, SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot()));
menuActions.append(restartProfile);
contextMenu[QString("restart")] = new QAction(i18n("Restart profile"), this);
connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot()));
menuActions.append(contextMenu[QString("restart")]);
enableProfile = new QAction(i18n("Enable profile"), this);
connect(enableProfile, SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot()));
menuActions.append(enableProfile);
contextMenu[QString("enable")] = new QAction(i18n("Enable profile"), this);
connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot()));
menuActions.append(contextMenu[QString("enable")]);
contextMenu[QString("wifi")] = new QAction(i18n("Show WiFi menu"), this);
connect(contextMenu[QString("wifi")], SIGNAL(triggered(bool)), this, SLOT(showWifi()));
menuActions.append(contextMenu[QString("wifi")]);
}
@ -248,6 +256,14 @@ void Netctl::showGui()
}
void Netctl::showWifi()
{
sendNotification(QString("Info"), i18n("Start WiFi menu"));
QProcess command;
command.startDetached(paths[QString("wifi")]);
}
// data engine interaction
void Netctl::connectToEngine()
{
@ -376,6 +392,22 @@ void Netctl::selectNetctlExe()
}
void Netctl::selectSudoExe()
{
KUrl url = KFileDialog::getOpenUrl(KUrl(), "*");
if (!url.isEmpty())
uiConfig.lineEdit_sudo->setText(url.path());
}
void Netctl::selectWifiExe()
{
KUrl url = KFileDialog::getOpenUrl(KUrl(), "*");
if (!url.isEmpty())
uiConfig.lineEdit_wifi->setText(url.path());
}
void Netctl::createConfigurationInterface(KConfigDialog *parent)
{
QWidget *configwin = new QWidget;
@ -392,6 +424,11 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
else
uiConfig.checkBox_sudo->setCheckState(Qt::Unchecked);
uiConfig.lineEdit_sudo->setText(paths[QString("sudo")]);
if (useWifi)
uiConfig.checkBox_wifi->setCheckState(Qt::Checked);
else
uiConfig.checkBox_wifi->setCheckState(Qt::Unchecked);
uiConfig.lineEdit_wifi->setText(paths[QString("wifi")]);
if (bigInterface[QString("main")])
uiConfig.checkBox_showBigInterface->setCheckState(Qt::Checked);
else
@ -433,9 +470,12 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
connect(uiConfig.checkBox_showBigInterface, SIGNAL(stateChanged(int)), this,
SLOT(setBigInterface()));
connect(uiConfig.checkBox_sudo, SIGNAL(stateChanged(int)), this, SLOT(setSudo()));
connect(uiConfig.checkBox_wifi, SIGNAL(stateChanged(int)), this, SLOT(setWifi()));
connect(uiConfig.pushButton_gui, SIGNAL(clicked()), this, SLOT(selectGuiExe()));
connect(uiConfig.pushButton_netctl, SIGNAL(clicked()), this, SLOT(selectNetctlExe()));
connect(uiConfig.pushButton_sudo, SIGNAL(clicked()), this, SLOT(selectSudoExe()));
connect(uiConfig.pushButton_wifi, SIGNAL(clicked()), this, SLOT(selecWifiExe()));
connect(uiConfig.pushButton_activeIcon, SIGNAL(clicked()), this, SLOT(selectActiveIcon()));
connect(uiConfig.pushButton_inactiveIcon, SIGNAL(clicked()), this, SLOT(selectInactiveIcon()));
@ -457,6 +497,11 @@ void Netctl::configAccepted()
else
cg.writeEntry("useSudo", true);
cg.writeEntry("sudoPath", uiConfig.lineEdit_sudo->text());
if (uiConfig.checkBox_wifi->checkState() == 0)
cg.writeEntry("useWifi", false);
else
cg.writeEntry("useWifi", true);
cg.writeEntry("wifiPath", uiConfig.lineEdit_wifi->text());
if (uiConfig.checkBox_showBigInterface->checkState() == 0)
cg.writeEntry("showBigInterface", false);
else
@ -491,8 +536,10 @@ void Netctl::configChanged()
autoUpdateInterval = cg.readEntry("autoUpdateInterval", 1000);
paths[QString("gui")] = cg.readEntry("guiPath", "/usr/bin/netctl-gui");
paths[QString("netctl")] = cg.readEntry("netctlPath", "/usr/bin/netctl");
useSudo = cg.readEntry("useSudo", true);
paths[QString("sudo")] = cg.readEntry("sudoPath", "/usr/bin/kdesu");
paths[QString("wifi")] = cg.readEntry("wifiPath", "/usr/bin/netctl-gui -t 3");
useSudo = cg.readEntry("useSudo", true);
useWifi = cg.readEntry("useWifi", true);
bigInterface[QString("main")] = cg.readEntry("showBigInterface", true);
bigInterface[QString("extIp")] = cg.readEntry("showExtIp", false);
bigInterface[QString("netDev")] = cg.readEntry("showNetDev", true);
@ -538,9 +585,18 @@ void Netctl::setSudo()
{
if (uiConfig.checkBox_sudo->checkState() == 0)
uiConfig.lineEdit_sudo->setDisabled(true);
else if (uiConfig.checkBox_showBigInterface->checkState() == 2)
else if (uiConfig.checkBox_sudo->checkState() == 2)
uiConfig.lineEdit_sudo->setEnabled(true);
}
void Netctl::setWifi()
{
if (uiConfig.checkBox_wifi->checkState() == 0)
uiConfig.lineEdit_wifi->setDisabled(true);
else if (uiConfig.checkBox_wifi->checkState() == 2)
uiConfig.checkBox_wifi->setEnabled(true);
}
#include "netctl.moc"

View File

@ -43,6 +43,7 @@ public slots:
// events
void sendNotification(const QString eventId, const QString message);
void showGui();
void showWifi();
// dataengine
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
// configuration interface
@ -50,6 +51,7 @@ public slots:
void configChanged();
void setBigInterface();
void setSudo();
void setWifi();
private slots:
// ui
@ -59,6 +61,8 @@ private slots:
void selectGuiExe();
void selectInactiveIcon();
void selectNetctlExe();
void selectSudoExe();
void selectWifiExe();
// context menu
void enableProfileSlot();
void startProfileSlot(QAction *profile);
@ -83,16 +87,11 @@ private:
void createActions();
QList<QAction*> menuActions;
QMenu *startProfileMenu;
QAction *enableProfile;
QAction *startProfile;
QAction *stopProfile;
QAction *restartProfile;
QMap<QString, QAction*> contextMenu;
// data engine
Plasma::DataEngine *netctlEngine;
void connectToEngine();
void disconnectFromEngine();
// notification
//
// configuration interface
Ui::ConfigWindow uiConfig;
// configuration
@ -100,7 +99,7 @@ private:
QMap<QString, bool> bigInterface;
QStringList formatLine;
QMap<QString, QString> paths;
bool useSudo;
bool useSudo, useWifi;
};
K_EXPORT_PLASMA_APPLET(netctl, Netctl)

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<libraries>
<library>qt</library>
</libraries>
</project>