diff --git a/CHANGELOG b/CHANGELOG index 3312023..54a2ab2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ Ver.1.2.0: + [all] added icons ++ [dataengine] added support of netctl-auto + [gui] added suppoort of macvlan + [gui] added ability to remove profile + [gui] added support of hidden wifi network @@ -8,6 +9,7 @@ Ver.1.2.0: + [gui] added clear() function to profileTab + [gui] added support of netctl-auto + [lib] detached backend from frontend ++ [plasmoid] added support of netctl-auto * [all] small changes in the project architecture * [gui] more debug information * [gui] changed lineEdit_profile to comboBox diff --git a/README.md b/README.md index ad81e36..7303c9b 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,9 @@ Installation Available cmake flags: * `-DBUILD_DATAENGINE:BOOL=0` - do not build DataEngine + * `-DBUILD_DOCS:BOOL=0` - do not build developer documentation * `-DBUILD_GUI:BOOL=0` - do not build GUI + * `-DBUILD_LIBRARY:BOOL=0` - do not build library * `-DBUILD_PLASMOID:BOOL=0` - do not build Plasmoid * `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI @@ -69,7 +71,7 @@ Additional information TODO (wish list) ---------------- -* netctl-auto support to dataengine +* split configuration interface * man pages * code review diff --git a/sources/dataengine/netctl.conf b/sources/dataengine/netctl.conf index 29c1662..2d098cc 100644 --- a/sources/dataengine/netctl.conf +++ b/sources/dataengine/netctl.conf @@ -3,6 +3,8 @@ ## Commands # command CMD=/usr/bin/netctl +# netctl-auto command +NETCTLAUTOCMD=/usr/bin/netctl-auto # ip command IPCMD=/usr/bin/ip diff --git a/sources/dataengine/netctl.cpp b/sources/dataengine/netctl.cpp index 2abc78d..b84f5b8 100644 --- a/sources/dataengine/netctl.cpp +++ b/sources/dataengine/netctl.cpp @@ -61,6 +61,7 @@ void Netctl::readConfiguration() rawConfig[QString("EXTIPCMD")] = QString("wget -qO- http://ifconfig.me/ip"); rawConfig[QString("IPCMD")] = QString("/usr/bin/ip"); rawConfig[QString("NETDIR")] = QString("/sys/class/net/"); + rawConfig[QString("NETCTLAUTOCMD")] = QString("/usr/bin/netctl-auto"); QString fileName = KGlobal::dirs()->findResource("config", "netctl.conf"); QFile confFile(fileName); @@ -101,7 +102,8 @@ QMap Netctl::updateConfiguration(const QMap key.remove(QChar(' ')); if ((key != QString("CMD")) && (key != QString("EXTIPCMD")) && - (key != QString("IPCMD"))) + (key != QString("IPCMD")) && + (key != QString("NETCTLAUTOCMD"))) value.remove(QChar(' ')); config[key] = value; } @@ -196,15 +198,20 @@ bool Netctl::getProfileStatus(const QString cmd) } -QString Netctl::getProfileStringStatus(const QString cmd) +QString Netctl::getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto) { QProcess command; QString status = QString("static"); - QString profile = getCurrentProfile(cmd); - command.start(cmd + QString(" is-enabled ") + profile); - command.waitForFinished(-1); - if (command.exitCode() == 0) - status = QString("enabled"); + // check netctl-auto + if (!getCurrentProfile(cmdNetctlAuto).isEmpty()) + status = QString("netctl-auto"); + else { + // check netctl + command.start(cmdNetctl + QString(" is-enabled ") + getCurrentProfile(cmdNetctl)); + command.waitForFinished(-1); + if (command.exitCode() == 0) + status = QString("enabled"); + } return status; } @@ -214,7 +221,9 @@ bool Netctl::updateSourceEvent(const QString &source) QString key = QString("value"); QString value = QString(""); if (source == QString("currentProfile")) { - value = getCurrentProfile(configuration[QString("CMD")]); + value = getCurrentProfile(configuration[QString("NETCTLAUTOCMD")]); + if (value.isEmpty()) + value = getCurrentProfile(configuration[QString("CMD")]); } else if (source == QString("extIp")) { if (configuration[QString("EXTIP")] == QString("true")) @@ -227,16 +236,21 @@ bool Netctl::updateSourceEvent(const QString &source) value = getIntIp(configuration[QString("IPCMD")], configuration[QString("NETDIR")]); } else if (source == QString("profiles")) { - value = getProfileList(configuration[QString("CMD")]).join(QChar(',')); + value = getProfileList(configuration[QString("NETCTLAUTOCMD")]).join(QChar(',')); + if (value.isEmpty()) + value = getProfileList(configuration[QString("CMD")]).join(QChar(',')); } else if (source == QString("statusBool")) { - if (getProfileStatus(configuration[QString("CMD")])) + if (getProfileStatus(configuration[QString("NETCTLAUTOCMD")])) + value = QString("true"); + else if (getProfileStatus(configuration[QString("CMD")])) value = QString("true"); else value = QString("false"); } else if (source == QString("statusString")) { - value = getProfileStringStatus(configuration[QString("CMD")]); + value = getProfileStringStatus(configuration[QString("CMD")], + configuration[QString("NETCTLAUTOCMD")]); } setData(source, key, value); return true; diff --git a/sources/dataengine/netctl.h b/sources/dataengine/netctl.h index 313ce37..ce0909b 100644 --- a/sources/dataengine/netctl.h +++ b/sources/dataengine/netctl.h @@ -33,7 +33,7 @@ public: QString getIntIp(const QString cmd, const QString dir); QStringList getProfileList(const QString cmd); bool getProfileStatus(const QString cmd); - QString getProfileStringStatus(const QString cmd); + QString getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto); protected: bool sourceRequestEvent(const QString &name); @@ -41,6 +41,7 @@ protected: QStringList sources() const; private: + bool isNetctlAutoRunning(); // configuration QMap configuration; void readConfiguration(); diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index f6aa7a7..f299920 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -54,7 +54,7 @@ void NetctlAutoWindow::createActions() connect(ui->actionDisableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoDisableAllProfiles())); connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile())); connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));\ - connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoAppendTable())); + connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoUpdateTable())); connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile())); // service connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService())); @@ -68,7 +68,7 @@ void NetctlAutoWindow::createActions() // buttons connect(ui->pushButton_enable, SIGNAL(clicked(bool)), this, SLOT(netctlAutoEnableProfile())); - connect(ui->pushButton_refresh, SIGNAL(clicked(bool)), this, SLOT(netctlAutoAppendTable())); + connect(ui->pushButton_refresh, SIGNAL(clicked(bool)), this, SLOT(netctlAutoUpdateTable())); connect(ui->pushButton_switch, SIGNAL(clicked(bool)), this, SLOT(netctlAutoStartProfile())); } @@ -77,14 +77,14 @@ void NetctlAutoWindow::showWindow() { if (debug) qDebug() << "[NetctlAutoWindow]" << "[showWindow]"; - netctlAutoAppendTable(); + netctlAutoUpdateTable(); show(); } -void NetctlAutoWindow::netctlAutoAppendTable() +void NetctlAutoWindow::netctlAutoUpdateTable() { - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoAppendTable]"; + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoUpdateTable]"; ui->tableWidget->setDisabled(true); QList profiles = netctlCommand->getProfileListFromNetctlAuto(); @@ -233,7 +233,7 @@ void NetctlAutoWindow::netctlAutoDisableAllProfiles() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -251,7 +251,7 @@ void NetctlAutoWindow::netctlAutoEnableProfile() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -265,7 +265,7 @@ void NetctlAutoWindow::netctlAutoEnableAllProfiles() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -283,7 +283,7 @@ void NetctlAutoWindow::netctlAutoStartProfile() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -296,7 +296,7 @@ void NetctlAutoWindow::netctlAutoEnableService() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -309,7 +309,7 @@ void NetctlAutoWindow::netctlAutoRestartService() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } @@ -322,7 +322,7 @@ void NetctlAutoWindow::netctlAutoStartService() else ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error")); - netctlAutoAppendTable(); + netctlAutoUpdateTable(); } diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index b79c451..6823b21 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -44,8 +44,8 @@ public slots: private slots: // table - void netctlAutoAppendTable(); void netctlAutoContextualMenu(const QPoint &pos); + void netctlAutoUpdateTable(); // netctl-auto void netctlAutoDisableAllProfiles(); void netctlAutoEnableProfile(); diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index 18d139b..f5a5c7c 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -45,6 +45,7 @@ Netctl::Netctl(QObject *parent, const QVariantList &args) Netctl::~Netctl() { // delete startProfileMenu; +// delete switchToProfileMenu; // delete startProfile; // delete stopProfile; // delete restartProfile; @@ -127,21 +128,29 @@ void Netctl::enableProfileSlot() void Netctl::startProfileSlot(QAction *profile) { + bool ready = true; QProcess command; QString commandLine; commandLine = QString(""); sendNotification(QString("Info"), i18n("Start profile %1", profile->text().remove(QString("&")))); - if (status) - commandLine = paths[QString("netctl")] + QString(" stop ") + - info[QString("name")] + QString(" && "); - if (useSudo) - commandLine = paths[QString("sudo")] + QString(" ") + commandLine + - paths[QString("netctl")] + QString(" start ") + - profile->text().remove(QString("&")); - else - commandLine = commandLine + paths[QString("netctl")] + QString(" start ") + - profile->text().remove(QString("&")); - command.startDetached(commandLine); + if (status) { + commandLine = paths[QString("netctl")] + QString(" stop ") + info[QString("name")]; + if (useSudo) + commandLine = paths[QString("sudo")] + QString(" ") + commandLine; + command.start(commandLine); + command.waitForFinished(-1); + if (command.exitCode() != 0) + ready = false; + } + if (ready) { + if (useSudo) + commandLine = paths[QString("sudo")] + QString(" ") + paths[QString("netctl")] + + QString(" start ") + profile->text().remove(QString("&")); + else + commandLine = paths[QString("netctl")] + QString(" start ") + + profile->text().remove(QString("&")); + command.startDetached(commandLine); + } } @@ -159,6 +168,18 @@ void Netctl::stopProfileSlot() } +void Netctl::switchToProfileSlot(QAction *profile) +{ + QProcess command; + QString commandLine; + commandLine = QString(""); + sendNotification(QString("Info"), i18n("Switch to profile %1", profile->text().remove(QString("&")))); + commandLine = paths[QString("netctl-auto")] + QString(" switch-to ") + + profile->text().remove(QString("&")); + command.startDetached(commandLine); +} + + void Netctl::restartProfileSlot() { QProcess command; @@ -181,35 +202,55 @@ QList Netctl::contextualActions() contextMenu[QString("title")]->setIcon(QIcon(paths[QString("inactive")])); contextMenu[QString("title")]->setText(info[QString("name")] + QString(" ") + info[QString("status")]); - if (status) { - contextMenu[QString("start")]->setText(i18n("Start another profile")); - contextMenu[QString("stop")]->setVisible(true); - contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("name")])); - contextMenu[QString("restart")]->setVisible(true); - contextMenu[QString("restart")]->setText(i18n("Restart %1", info[QString("name")])); - contextMenu[QString("enable")]->setVisible(true); - if (info[QString("status")].contains(QString("enabled"))) - contextMenu[QString("enable")]->setText(i18n("Disable %1", info[QString("name")])); - else - contextMenu[QString("enable")]->setText(i18n("Enable %1", info[QString("name")])); - } - else { - contextMenu[QString("start")]->setText(i18n("Start profile")); + if (info[QString("status")] == QString("(netctl-auto)")) { + contextMenu[QString("start")]->setVisible(false); contextMenu[QString("stop")]->setVisible(false); + contextMenu[QString("switch")]->setVisible(true); contextMenu[QString("restart")]->setVisible(false); contextMenu[QString("enable")]->setVisible(false); + + switchToProfileMenu->clear(); + for (int i=0; iaddAction(profile); + } + } + else { + contextMenu[QString("start")]->setVisible(true); + contextMenu[QString("stop")]->setVisible(true); + contextMenu[QString("switch")]->setVisible(false); + contextMenu[QString("restart")]->setVisible(true); + contextMenu[QString("enable")]->setVisible(true); + + if (status) { + contextMenu[QString("start")]->setText(i18n("Start another profile")); + contextMenu[QString("stop")]->setVisible(true); + contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("name")])); + contextMenu[QString("restart")]->setVisible(true); + contextMenu[QString("restart")]->setText(i18n("Restart %1", info[QString("name")])); + contextMenu[QString("enable")]->setVisible(true); + if (info[QString("status")].contains(QString("enabled"))) + contextMenu[QString("enable")]->setText(i18n("Disable %1", info[QString("name")])); + else + contextMenu[QString("enable")]->setText(i18n("Enable %1", info[QString("name")])); + } + else { + contextMenu[QString("start")]->setText(i18n("Start profile")); + contextMenu[QString("stop")]->setVisible(false); + contextMenu[QString("restart")]->setVisible(false); + contextMenu[QString("enable")]->setVisible(false); + } + startProfileMenu->clear(); + for (int i=0; iaddAction(profile); + } } if (useWifi) contextMenu[QString("wifi")]->setVisible(true); else contextMenu[QString("wifi")]->setVisible(false); - startProfileMenu->clear(); - for (int i=0; iaddAction(profile); - } - return menuActions; } @@ -234,6 +275,14 @@ void Netctl::createActions() connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot())); menuActions.append(contextMenu[QString("stop")]); + contextMenu[QString("switch")] = new QAction(i18n("Switch to profile"), this); + contextMenu[QString("switch")]->setIcon(QIcon::fromTheme("dialog-apply")); + switchToProfileMenu = new QMenu(NULL); + contextMenu[QString("switch")]->setMenu(switchToProfileMenu); + connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, + SLOT(switchToProfileSlot(QAction *))); + menuActions.append(contextMenu[QString("switch")]); + contextMenu[QString("restart")] = new QAction(i18n("Restart profile"), this); contextMenu[QString("restart")]->setIcon(QIcon::fromTheme("stock-refresh")); connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot())); @@ -406,6 +455,14 @@ void Netctl::selectNetctlExe() } +void Netctl::selectNetctlAutoExe() +{ + KUrl url = KFileDialog::getOpenUrl(KUrl(), "*"); + if (!url.isEmpty()) + uiWidConfig.lineEdit_netctlAuto->setText(url.path()); +} + + void Netctl::selectSudoExe() { KUrl url = KFileDialog::getOpenUrl(KUrl(), "*"); @@ -435,6 +492,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent) uiWidConfig.spinBox_autoUpdate->setValue(autoUpdateInterval); uiWidConfig.lineEdit_gui->setText(paths[QString("gui")]); uiWidConfig.lineEdit_netctl->setText(paths[QString("netctl")]); + uiWidConfig.lineEdit_netctlAuto->setText(paths[QString("netctlAuto")]); if (useSudo) uiWidConfig.checkBox_sudo->setCheckState(Qt::Checked); else @@ -491,6 +549,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent) connect(uiWidConfig.pushButton_gui, SIGNAL(clicked()), this, SLOT(selectGuiExe())); connect(uiWidConfig.pushButton_netctl, SIGNAL(clicked()), this, SLOT(selectNetctlExe())); + connect(uiWidConfig.pushButton_netctlAuto, SIGNAL(clicked()), this, SLOT(selectNetctlAutoExe())); connect(uiWidConfig.pushButton_sudo, SIGNAL(clicked()), this, SLOT(selectSudoExe())); connect(uiWidConfig.pushButton_wifi, SIGNAL(clicked()), this, SLOT(selecWifiExe())); connect(uiAppConfig.pushButton_activeIcon, SIGNAL(clicked()), this, SLOT(selectActiveIcon())); @@ -509,6 +568,7 @@ void Netctl::configAccepted() cg.writeEntry("autoUpdateInterval", uiWidConfig.spinBox_autoUpdate->value()); cg.writeEntry("guiPath", uiWidConfig.lineEdit_gui->text()); cg.writeEntry("netctlPath", uiWidConfig.lineEdit_netctl->text()); + cg.writeEntry("netctlAutoPath", uiWidConfig.lineEdit_netctlAuto->text()); if (uiWidConfig.checkBox_sudo->checkState() == 0) cg.writeEntry("useSudo", false); else @@ -553,6 +613,7 @@ 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"); + paths[QString("netctlAuto")] = cg.readEntry("netctlAutoPath", "/usr/bin/netctl-auto"); 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); diff --git a/sources/plasmoid/netctl.h b/sources/plasmoid/netctl.h index 363538d..724665e 100644 --- a/sources/plasmoid/netctl.h +++ b/sources/plasmoid/netctl.h @@ -62,12 +62,14 @@ private slots: void selectGuiExe(); void selectInactiveIcon(); void selectNetctlExe(); + void selectNetctlAutoExe(); void selectSudoExe(); void selectWifiExe(); // context menu void enableProfileSlot(); void startProfileSlot(QAction *profile); void stopProfileSlot(); + void switchToProfileSlot(QAction *profile); void restartProfileSlot(); protected: @@ -88,6 +90,7 @@ private: void createActions(); QList menuActions; QMenu *startProfileMenu; + QMenu *switchToProfileMenu; QMap contextMenu; // data engine Plasma::DataEngine *netctlEngine; diff --git a/sources/plasmoid/widget.ui b/sources/plasmoid/widget.ui index afbc504..59e42b1 100644 --- a/sources/plasmoid/widget.ui +++ b/sources/plasmoid/widget.ui @@ -7,7 +7,7 @@ 0 0 480 - 341 + 339 @@ -19,8 +19,8 @@ Configuration Window - - + + @@ -30,106 +30,7 @@ - - - - Show network devices - - - true - - - - - - - - - - 150 - 23 - - - - Show 'Start WiFi menu' - - - true - - - - - - - - - - - 100 - 23 - - - - Browse - - - - - - - - - Show more detailed interface - - - true - - - - - - - Show internal IP - - - true - - - - - - - - - - 80 - 23 - - - - Path to GUI - - - - - - - - - - - 100 - 23 - - - - Browse - - - - - - + @@ -187,23 +88,46 @@ - - - - Show external IP - - - true - - + + + + + + + 150 + 23 + + + + Path to GUI + + + + + + + + + + + 100 + 23 + + + + Browse + + + + - + - 80 + 150 23 @@ -230,7 +154,40 @@ - + + + + + + + 150 + 23 + + + + Path to netctl-auto + + + + + + + + + + + 100 + 23 + + + + Browse + + + + + + @@ -266,7 +223,83 @@ - + + + + + + + 150 + 23 + + + + Show 'Start WiFi menu' + + + true + + + + + + + + + + + 100 + 23 + + + + Browse + + + + + + + + + Show more detailed interface + + + true + + + + + + + Show network devices + + + true + + + + + + + Show external IP + + + true + + + + + + + Show internal IP + + + true + + + + Qt::Vertical