From 92ec04cae129a5b844db697af04a773a4b209bac Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 12 Apr 2014 15:27:14 +0400 Subject: [PATCH] refactoring of plasmoid added function to start wifi menu --- create_archive.sh | 2 +- sources/plasmoid/configwindow.ui | 55 ++++++++++++++- sources/plasmoid/netctl.cpp | 108 ++++++++++++++++++++++------- sources/plasmoid/netctl.h | 13 ++-- sources/plasmoid/plasmoid.cppcheck | 6 ++ 5 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 sources/plasmoid/plasmoid.cppcheck diff --git a/create_archive.sh b/create_archive.sh index e730c46..a3f44bf 100755 --- a/create_archive.sh +++ b/create_archive.sh @@ -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) diff --git a/sources/plasmoid/configwindow.ui b/sources/plasmoid/configwindow.ui index 3d0f594..4b91c3f 100644 --- a/sources/plasmoid/configwindow.ui +++ b/sources/plasmoid/configwindow.ui @@ -7,7 +7,7 @@ 0 0 480 - 320 + 343 @@ -185,6 +185,55 @@ + + + + + 100 + 23 + + + + Browse + + + + + + + + + + + + 150 + 23 + + + + Show 'Start WiFi menu' + + + true + + + + + + + + + + + 100 + 23 + + + + Browse + + + @@ -643,6 +692,10 @@ pushButton_netctl checkBox_sudo lineEdit_sudo + pushButton_sudo + checkBox_wifi + lineEdit_wifi + pushButton_wifi checkBox_showBigInterface checkBox_showNetDev checkBox_showExtIp diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index ef4df81..d47935f 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -175,23 +175,27 @@ void Netctl::restartProfileSlot() QList 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; isetMenu(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" diff --git a/sources/plasmoid/netctl.h b/sources/plasmoid/netctl.h index 3684651..a0a6f8b 100644 --- a/sources/plasmoid/netctl.h +++ b/sources/plasmoid/netctl.h @@ -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 menuActions; QMenu *startProfileMenu; - QAction *enableProfile; - QAction *startProfile; - QAction *stopProfile; - QAction *restartProfile; + QMap contextMenu; // data engine Plasma::DataEngine *netctlEngine; void connectToEngine(); void disconnectFromEngine(); - // notification - // // configuration interface Ui::ConfigWindow uiConfig; // configuration @@ -100,7 +99,7 @@ private: QMap bigInterface; QStringList formatLine; QMap paths; - bool useSudo; + bool useSudo, useWifi; }; K_EXPORT_PLASMA_APPLET(netctl, Netctl) diff --git a/sources/plasmoid/plasmoid.cppcheck b/sources/plasmoid/plasmoid.cppcheck new file mode 100644 index 0000000..075652f --- /dev/null +++ b/sources/plasmoid/plasmoid.cppcheck @@ -0,0 +1,6 @@ + + + + qt + +