From f80d6aae6b641ebcaa20230ff3e90390a6006a8a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 14 Mar 2015 06:42:06 +0300 Subject: [PATCH] end work on interfaces --- sources/.kdev4/sources.kdev4 | 2 +- sources/3rdparty/listmap/listmap.cpp | 41 +++ sources/3rdparty/listmap/listmap.h | 29 +++ sources/gui/docs/netctl-gui-dbus-api.html | 9 +- sources/gui/src/CMakeLists.txt | 3 +- sources/gui/src/calls.cpp | 129 ++++++++++ sources/gui/src/calls.h | 22 +- sources/gui/src/dbusoperation.cpp | 3 +- sources/gui/src/mainwidget.cpp | 97 +++---- sources/gui/src/mainwidget.h | 2 - sources/gui/src/mainwindow.cpp | 125 ++------- sources/gui/src/mainwindow.h | 3 +- sources/gui/src/netctlautowindow.cpp | 2 +- sources/gui/src/netctlautowindow.h | 4 +- sources/gui/src/netctlguiadaptor.cpp | 6 - sources/gui/src/netctlguiadaptor.h | 1 - sources/gui/src/newprofilewidget.cpp | 71 +----- sources/gui/src/trayicon.cpp | 237 ++++++------------ sources/gui/src/trayicon.h | 15 +- sources/gui/src/wifimenuwidget.cpp | 91 ++----- sources/gui/src/wifimenuwidget.h | 6 +- sources/helper/src/CMakeLists.txt | 3 +- sources/helper/src/controladaptor.cpp | 17 +- sources/helper/src/controladaptor.h | 2 +- sources/helper/src/interfaceadaptor.cpp | 85 +++++-- sources/helper/src/interfaceadaptor.h | 7 +- sources/helper/src/netctladaptor.cpp | 9 +- sources/helper/src/netctladaptor.h | 2 +- sources/helper/src/netctlhelper.cpp | 7 +- .../netctlgui/include/netctlgui/netctlgui.h | 3 - .../include/netctlgui/netctlinteract.h | 3 + .../include/netctlgui/netctlinterface.h | 71 +++++- sources/netctlgui/src/netctlinteract.cpp | 9 +- sources/netctlgui/src/netctlinterface.cpp | 89 ++++++- sources/test/CMakeLists.txt | 11 +- sources/test/testnetctl.cpp | 6 +- sources/test/testnetctlprofile.cpp | 17 +- sources/test/testwpasup.cpp | 6 +- 38 files changed, 676 insertions(+), 569 deletions(-) create mode 100644 sources/3rdparty/listmap/listmap.cpp create mode 100644 sources/3rdparty/listmap/listmap.h diff --git a/sources/.kdev4/sources.kdev4 b/sources/.kdev4/sources.kdev4 index 587b19d..d7d83c5 100644 --- a/sources/.kdev4/sources.kdev4 +++ b/sources/.kdev4/sources.kdev4 @@ -8,7 +8,7 @@ ProjectRootRelative=./ [CMake][CMake Build Directory 0] Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build -Build Type=Debug +Build Type=Release CMake Binary=file:///usr/bin/cmake Environment Profile= Extra Arguments= diff --git a/sources/3rdparty/listmap/listmap.cpp b/sources/3rdparty/listmap/listmap.cpp new file mode 100644 index 0000000..ce77585 --- /dev/null +++ b/sources/3rdparty/listmap/listmap.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "listmap.h" + + +QMap listToMap(const QStringList list) +{ + QMap map; + for (int i=0; i map) +{ + QStringList list; + for (int i=0; i +#include + + +QMap listToMap(const QStringList list); +QStringList mapToList(const QMap map); + + +#endif /* LISTMAP_H */ diff --git a/sources/gui/docs/netctl-gui-dbus-api.html b/sources/gui/docs/netctl-gui-dbus-api.html index e31b4b2..814f2f5 100644 --- a/sources/gui/docs/netctl-gui-dbus-api.html +++ b/sources/gui/docs/netctl-gui-dbus-api.html @@ -243,7 +243,7 @@ small { QStringList netctlVerboseProfileList() - returns available profiles in format NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED from netctl even if netctl-auto is running + returns available profiles in format NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED|NETCTL-AUTO from netctl even if netctl-auto is running no @@ -253,7 +253,7 @@ small { QStringList VerboseProfileList() - returns available profiles in format NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED + returns available profiles in format NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED|NETCTL-AUTO no @@ -393,11 +393,6 @@ small { returns the application process UIDs [UID, EUID] no - - QStringList VerboseInformation() - returns information in format [isNetctlAutoActive, ProfileList, ActiveProfile, isProfileEnabled/autoIsProfileEnabled] - no -

External links

diff --git a/sources/gui/src/CMakeLists.txt b/sources/gui/src/CMakeLists.txt index 93b21fd..8081317 100644 --- a/sources/gui/src/CMakeLists.txt +++ b/sources/gui/src/CMakeLists.txt @@ -1,6 +1,7 @@ # set files file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp - ${PROJECT_TRDPARTY_DIR}/language/*.cpp) + ${PROJECT_TRDPARTY_DIR}/language/*.cpp + ${PROJECT_TRDPARTY_DIR}/listmap/*.cpp) file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h ${PROJECT_TRDPARTY_DIR}/language/*.h) file (GLOB_RECURSE FORMS *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui) diff --git a/sources/gui/src/calls.cpp b/sources/gui/src/calls.cpp index d86e6ab..8df6bf0 100644 --- a/sources/gui/src/calls.cpp +++ b/sources/gui/src/calls.cpp @@ -19,11 +19,32 @@ #include +#include #include #include "dbusoperation.h" +InterfaceAnswer createProfileSlot(const QString profile, QMap settings, + NetctlInterface* interface, const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + if (!useHelper) return interface->createProfile(profile, settings); + try { + QList args; + args.append(profile); + args.append(mapToList(settings)); + int responce = sendRequestToInterfaceWithArgs(QString("Create"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; + } +} + + InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface, const bool useHelper, const bool debug) { @@ -43,6 +64,25 @@ InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interf } +InterfaceAnswer removeProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + if (!useHelper) return interface->removeProfile(profile); + try { + QList args; + args.append(profile); + int responce = sendRequestToInterfaceWithArgs(QString("Remove"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; + } +} + + InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface, const bool useHelper, const bool debug) { @@ -114,3 +154,92 @@ InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *inte return InterfaceAnswer::Error; } } + + +InterfaceAnswer connectToEssid(const QString essid, QMap settings, + NetctlInterface* interface, const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; + + + if (!useHelper) return interface->connectToEssid(essid, settings); + try { + QList args; + args.append(essid); + args.append(mapToList(settings)); + int responce = sendRequestToInterfaceWithArgs(QString("Essid"), args, debug)[0].toInt(); + return static_cast(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return InterfaceAnswer::Error; + } +} + + +netctlInformation generalInformation(NetctlInterface* interface, const bool useHelper, + const bool debug) +{ + if (debug) qDebug() << PDEBUG; + + if (!useHelper) return interface->information(); + try { + QList responce = sendRequestToInterface(QString("Information"), debug); + // main + netctlInformation info; + info.netctlAuto = responce[0].toStringList().takeFirst().toInt(); + QList profiles = parseOutputNetctl(responce); + for (int i=0; i profileInformation(const QString profile, NetctlInterface* interface, + const bool useHelper, const bool debug) +{ + if (!useHelper) return interface->profileSettings(profile); + try { + QList args; + args.append(profile); + QStringList responce = sendRequestToInterfaceWithArgs(QString("Profile"), args, debug)[0].toStringList(); + return listToMap(responce); + } catch (...) { + if (debug) qDebug() << PDEBUG << ":" << "An exception recevied"; + return QMap(); + } +} + + +netctlCurrent trayInformation(NetctlInterface *interface, const bool useHelper, + const bool debug) +{ + if (debug) qDebug() << PDEBUG; + + if (!useHelper) return interface->status(); + try { + QStringList responce = sendRequestToInterface(QString("Status"), debug)[0].toStringList(); + netctlCurrent status; + status.netctlAuto = responce[0].toInt(); + status.profiles = responce[1].split(QChar('|')); + status.current = responce[2].split(QChar('|')); + QStringList enables = responce[3].split(QChar('|')); + for (int i=0; i #include #include +// control +InterfaceAnswer createProfileSlot(const QString profile, const QMap settings, + NetctlInterface *interface, const bool useHelper, + const bool debug = false); InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface, const bool useHelper, const bool debug = false); +InterfaceAnswer removeProfileSlot(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug = false); InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface, const bool useHelper, const bool debug = false); InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface, const bool useHelper, const bool debug = false); InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper, - const bool debug); + const bool debug = false); InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface, - const bool useHelper, const bool debug); + const bool useHelper, const bool debug = false); +// wireless connection +InterfaceAnswer connectToEssid(const QString essid, QMap settings, + NetctlInterface *interface, const bool useHelper, + const bool debug = false); +// information +netctlInformation generalInformation(NetctlInterface *interface, const bool useHelper, + const bool debug = false); +QMap profileInformation(const QString profile, NetctlInterface *interface, + const bool useHelper, const bool debug = false); +netctlCurrent trayInformation(NetctlInterface *interface, const bool useHelper, + const bool debug = false); #endif /* CALLS_H */ diff --git a/sources/gui/src/dbusoperation.cpp b/sources/gui/src/dbusoperation.cpp index 0ccf3d1..da0af1e 100644 --- a/sources/gui/src/dbusoperation.cpp +++ b/sources/gui/src/dbusoperation.cpp @@ -33,7 +33,7 @@ QList parseOutputNetctl(const QList raw) QStringList list = raw[0].toStringList(); for (int i=0; i parseOutputNetctl(const QList raw) profile.essid = info[4]; profile.active = info[5].toInt(); profile.enabled = info[6].toInt(); + profile.netctlAuto = info[7].toInt(); profileInfo.append(profile); } diff --git a/sources/gui/src/mainwidget.cpp b/sources/gui/src/mainwidget.cpp index 5b8faa6..2ef72f8 100644 --- a/sources/gui/src/mainwidget.cpp +++ b/sources/gui/src/mainwidget.cpp @@ -23,11 +23,11 @@ #include +#include "calls.h" #include "commonfunctions.h" #include "dbusoperation.h" #include "errorwindow.h" #include "mainwindow.h" -#include "netctlautowindow.h" MainWidget::MainWidget(QWidget *parent, const QMap settings, const bool debugCmd) @@ -140,28 +140,15 @@ void MainWidget::updateMainTab() } mainWindow->setDisabled(true); - QList profiles; - bool netctlAutoStatus = false; - if (useHelper) { - QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return updateMainTab(); - } - netctlAutoStatus = responce[0].toBool(); - profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); - } else { - netctlAutoStatus = mainWindow->netctlCommand->isNetctlAutoRunning(); - profiles = mainWindow->netctlCommand->getProfileList(); - } - ui->label_netctlAuto->setHidden(!netctlAutoStatus); + netctlInformation info = generalInformation(mainWindow->netctlInterface, + useHelper, debug); + ui->label_netctlAuto->setHidden(!info.netctlAuto); ui->tableWidget_main->setSortingEnabled(false); ui->tableWidget_main->selectRow(-1); ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder); ui->tableWidget_main->clear(); - ui->tableWidget_main->setRowCount(profiles.count()); + ui->tableWidget_main->setRowCount(info.netctlProfiles.count()); // create header QStringList headerList; @@ -171,35 +158,36 @@ void MainWidget::updateMainTab() headerList.append(QApplication::translate("MainWidget", "Enabled")); ui->tableWidget_main->setHorizontalHeaderLabels(headerList); // create items - for (int i=0; itableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name)); + ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(info.netctlProfiles[i].name)); ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); ui->tableWidget_main->item(i, 0)->setToolTip(toolTip); ui->tableWidget_main->item(i, 0)->setFont(font); // description - ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(profiles[i].description)); + ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(info.netctlProfiles[i].description)); ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter); ui->tableWidget_main->item(i, 1)->setToolTip(toolTip); // active - ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(profiles[i].active, true))); + ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(info.netctlProfiles[i].active, true))); ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); // enabled - ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(profiles[i].enabled, true))); + ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(info.netctlProfiles[i].enabled, true))); ui->tableWidget_main->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); } @@ -305,7 +293,10 @@ void MainWidget::mainTabEnableProfile() mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - mainWindow->showMessage(mainWindow->enableProfileSlot(profile)); + InterfaceAnswer answer = enableProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + // TODO check if status has been changed? + mainWindow->showMessage(answer != InterfaceAnswer::Error); updateMainTab(); } @@ -318,20 +309,9 @@ void MainWidget::mainTabRemoveProfile() mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - bool status = false; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return mainTabRemoveProfile(); - } - status = responce[0].toBool(); - } else - status = mainWindow->netctlProfile->removeProfile(profile); - mainWindow->showMessage(status); + InterfaceAnswer answer = removeProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); } @@ -349,7 +329,9 @@ void MainWidget::mainTabRestartProfile() mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - mainWindow->showMessage(mainWindow->restartProfileSlot(profile)); + InterfaceAnswer answer = restartProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); } @@ -367,7 +349,9 @@ void MainWidget::mainTabStartProfile() mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - mainWindow->showMessage(mainWindow->startProfileSlot(profile)); + InterfaceAnswer answer = startProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); } @@ -383,18 +367,9 @@ void MainWidget::mainTabStopAllProfiles() } mainWindow->setDisabled(true); - bool status = false; - if (useHelper) { - QList responce = sendRequestToCtrl(QString("StolAll"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return mainTabStopAllProfiles(); - } - status = responce[0].toBool(); - } else - status = mainWindow->netctlCommand->stopAllProfiles(); - mainWindow->showMessage(status); + InterfaceAnswer answer = stopAllProfilesSlot(mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); } @@ -412,7 +387,9 @@ void MainWidget::mainTabSwitchToProfile() mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - mainWindow->showMessage(mainWindow->switchToProfileSlot(profile)); + InterfaceAnswer answer = switchToProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); } @@ -449,7 +426,6 @@ void MainWidget::createObjects() ui->tableWidget_main->setColumnHidden(2, true); ui->tableWidget_main->setColumnHidden(3, true); updateToolBarState(static_cast(configuration[QString("NETCTL_TOOLBAR")].toInt())); - netctlAutoWin = new NetctlAutoWindow(mainWindow, debug, configuration); // append toolbar QMenu *actionMenu = new QMenu(this); @@ -464,6 +440,5 @@ void MainWidget::deleteObjects() { if (debug) qDebug() << PDEBUG; - if (netctlAutoWin != nullptr) delete netctlAutoWin; if (ui != nullptr) delete ui; } diff --git a/sources/gui/src/mainwidget.h b/sources/gui/src/mainwidget.h index bad480f..b8d7893 100644 --- a/sources/gui/src/mainwidget.h +++ b/sources/gui/src/mainwidget.h @@ -25,7 +25,6 @@ class MainWindow; -class NetctlAutoWindow; namespace Ui { class MainWidget; @@ -40,7 +39,6 @@ public: const QMap settings = QMap(), const bool debugCmd = false); ~MainWidget(); - NetctlAutoWindow *netctlAutoWin = nullptr; Qt::ToolBarArea getToolBarArea(); public slots: diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 92d3efe..c48f7e2 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -31,10 +31,12 @@ #include #include +#include #include #include #include "aboutwindow.h" +#include "calls.h" #include "commonfunctions.h" #include "dbusoperation.h" #include "errorwindow.h" @@ -124,29 +126,21 @@ QStringList MainWindow::printInformation() if (debug) qDebug() << PDEBUG; QStringList output; - output.append(QString("none")); - output.append(QString("(none)")); - if (useHelper) { - QList responce = sendRequestToLib(QString("Information"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return printInformation(); - } - if (responce[0].toStringList().count() != 2) return output; - output = responce[0].toStringList(); - } else { - if (netctlCommand->isNetctlAutoRunning()) { - output[0] = netctlCommand->autoGetActiveProfile(); - output[1] = QString("netctl-auto"); - } else { - QStringList currentProfiles = netctlCommand->getActiveProfile(); - output[0] = currentProfiles.join(QChar('|')); - QStringList statusList; - for (int i=0; igetProfileStatus(currentProfiles[i])); - output[1] = statusList.join(QChar('|')); - } + output.append(QApplication::translate("MainWindow", "none")); + output.append(QApplication::translate("MainWindow", "(none)")); + netctlCurrent current = printTrayInformation(); + if (current.current.isEmpty()) return output; + + QStringList profiles; + for (int i=0; i profiles; - if (useHelper) { - QList responce = sendRequestToLib(QString("ActiveProfile"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return printTrayInformation(); - } - current = responce[0].toString(); - responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return printTrayInformation(); - } - netctlAutoStatus = responce[0].toBool(); - profiles = parseOutputNetctl(sendRequestToLib(QString("VerboseProfileList"), debug)); - if (netctlAutoStatus) { - QList args; - args.append(current); - responce = sendRequestToLibWithArgs(QString("autoIsProfileEnabled"), args, debug); - enabled = QString::number(!responce.isEmpty() && responce[0].toBool()); - } else { - QStringList currentProfiles = current.split(QChar('|')); - QStringList enabledList; - for (int i=0; i args; - args.append(currentProfiles[i]); - responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); - enabledList.append(QString::number(!responce.isEmpty() && responce[0].toBool())); - enabled = enabledList.join(QChar('|')); - } - } - } else { - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - if (netctlAutoStatus) { - current = netctlCommand->autoGetActiveProfile(); - enabled = QString::number(netctlCommand->autoIsProfileEnabled(current)); - profiles = netctlCommand->getProfileListFromNetctlAuto(); - } else { - QStringList currentProfiles = netctlCommand->getActiveProfile(); - current = currentProfiles.join(QChar('|')); - QStringList enabledList; - for (int i=0; iisProfileEnabled(currentProfiles[i]))); - enabled = enabledList.join(QChar('|')); - profiles = netctlCommand->getProfileList(); - } - } - - information.append(QString::number(netctlAutoStatus)); - QStringList profileList; - for (int i=0; i responce = sendRequestToCtrl(QString("Active"), debug); - return (!responce.isEmpty() && responce[0].toBool()); + return (!responce.isEmpty()); } @@ -380,7 +308,7 @@ bool MainWindow::forceStopHelper() QList responce = sendRequestToCtrl(QString("Close"), debug); - return !responce.isEmpty(); + return (!responce.isEmpty()); } @@ -528,8 +456,6 @@ void MainWindow::updateToolBarState(const Qt::ToolBarArea area) addToolBar(area, ui->toolBar); ui->toolBar->show(); } - - qDebug() << findChildren().count(); } @@ -636,14 +562,15 @@ void MainWindow::createObjects() checkHelperStatus(); netctlCommand = new Netctl(debug, configuration); + netctlInterface = new NetctlInterface(debug, configuration); netctlProfile = new NetctlProfile(debug, configuration); wpaCommand = new WpaSup(debug, configuration); // frontend mainWidget = new MainWidget(this, configuration, debug); - netctlAutoWin = mainWidget->netctlAutoWin; + netctlAutoWin = new NetctlAutoWindow(this, configuration, debug); newProfileWidget = new NewProfileWidget(this, configuration, debug); wifiMenuWidget = new WiFiMenuWidget(this, configuration, debug); - trayIcon = new TrayIcon(this, debug); + trayIcon = new TrayIcon(this, configuration, debug); // windows ui->retranslateUi(this); ui->layout_main->addWidget(mainWidget); @@ -662,6 +589,7 @@ void MainWindow::deleteObjects() QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH); QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE); if (netctlCommand != nullptr) delete netctlCommand; + if (netctlInterface != nullptr) delete netctlInterface; if (netctlProfile != nullptr) delete netctlProfile; if (wpaCommand != nullptr) delete wpaCommand; @@ -669,6 +597,7 @@ void MainWindow::deleteObjects() if (settingsWin != nullptr) delete settingsWin; if (trayIcon != nullptr) delete trayIcon; if (mainWidget != nullptr) delete mainWidget; + if (netctlAutoWin != nullptr) delete netctlAutoWin; if (newProfileWidget != nullptr) delete newProfileWidget; if (wifiMenuWidget != nullptr) delete wifiMenuWidget; } diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 3ceefc8..8278293 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -50,11 +50,12 @@ public: Qt::ToolBarArea getToolBarArea(); QStringList printInformation(); QStringList printSettings(); - QStringList printTrayInformation(); + netctlCurrent printTrayInformation(); bool isHelperActive(); bool isHelperServiceActive(); // library interfaces Netctl *netctlCommand = nullptr; + NetctlInterface *netctlInterface = nullptr; NetctlProfile *netctlProfile = nullptr; WpaSup *wpaCommand = nullptr; diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index 7631fe5..c61917d 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -26,7 +26,7 @@ #include "mainwindow.h" -NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap settings) +NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const QMap settings, const bool debugCmd) : QMainWindow(parent), ui(new Ui::NetctlAutoWindow), debug(debugCmd) diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index 884aa97..680814d 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -34,8 +34,8 @@ class NetctlAutoWindow : public QMainWindow public: explicit NetctlAutoWindow(QWidget *parent = 0, - const bool debugCmd = false, - const QMap settings = QMap()); + const QMap settings = QMap(), + const bool debugCmd = false); ~NetctlAutoWindow(); Qt::ToolBarArea getToolBarArea(); diff --git a/sources/gui/src/netctlguiadaptor.cpp b/sources/gui/src/netctlguiadaptor.cpp index 2d9e612..1797086 100644 --- a/sources/gui/src/netctlguiadaptor.cpp +++ b/sources/gui/src/netctlguiadaptor.cpp @@ -133,9 +133,3 @@ QStringList NetctlGuiAdaptor::UIDs() return uids; } - - -QStringList NetctlGuiAdaptor::VerboseInformation() -{ - return mainWindow->printTrayInformation(); -} diff --git a/sources/gui/src/netctlguiadaptor.h b/sources/gui/src/netctlguiadaptor.h index c2074a7..668523e 100644 --- a/sources/gui/src/netctlguiadaptor.h +++ b/sources/gui/src/netctlguiadaptor.h @@ -48,7 +48,6 @@ public slots: bool ShowNetctlAuto(); bool ShowSettings(); QStringList UIDs(); - QStringList VerboseInformation(); private: MainWindow *mainWindow; diff --git a/sources/gui/src/newprofilewidget.cpp b/sources/gui/src/newprofilewidget.cpp index 80e92d2..7a89a12 100644 --- a/sources/gui/src/newprofilewidget.cpp +++ b/sources/gui/src/newprofilewidget.cpp @@ -24,6 +24,7 @@ #include +#include "calls.h" #include "bridgewidget.h" #include "commonfunctions.h" #include "dbusoperation.h" @@ -149,11 +150,8 @@ void NewProfileWidget::profileTabClear() if (debug) qDebug() << PDEBUG; ui->comboBox_profile->clear(); - QList profiles; - if (useHelper) - profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); - else - profiles = mainWindow->netctlCommand->getProfileList(); + QList profiles = generalInformation(mainWindow->netctlInterface, + useHelper, debug).netctlProfiles; for (int i=0; icomboBox_profile->addItem(profiles[i].name); ui->comboBox_profile->setCurrentIndex(-1); @@ -326,27 +324,9 @@ void NewProfileWidget::profileTabCreateProfile() } // call netctlprofile - bool status = false; - if (useHelper) { - QStringList settingsList; - for (int i=0; i args; - args.append(profile); - args.append(settingsList); - QList responce = sendRequestToCtrlWithArgs(QString("Create"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabCreateProfile(); - } - status = responce[0].toBool(); - - } else { - QString profileTempName = mainWindow->netctlProfile->createProfile(profile, settings); - status = mainWindow->netctlProfile->copyProfile(profileTempName); - } - mainWindow->showMessage(status); + InterfaceAnswer answer = createProfileSlot(profile, settings, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateProfileTab(); } @@ -358,25 +338,8 @@ void NewProfileWidget::profileTabLoadProfile() QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); if (profile.isEmpty()) return; - QMap settings; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLibWithArgs(QString("Profile"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabLoadProfile(); - } - QStringList settingsList = responce[0].toStringList(); - for (int i=0; inetctlProfile->getSettingsFromProfile(profile); + QMap settings = profileInformation(profile, mainWindow->netctlInterface, + useHelper, debug); if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); @@ -422,21 +385,9 @@ void NewProfileWidget::profileTabRemoveProfile() mainWindow->setDisabled(true); QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); - if (profile.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); - bool status = false; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabLoadProfile(); - } - status = responce[0].toBool(); - } else - status = mainWindow->netctlProfile->removeProfile(profile); - mainWindow->showMessage(status); + InterfaceAnswer answer = removeProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); updateProfileTab(); } diff --git a/sources/gui/src/trayicon.cpp b/sources/gui/src/trayicon.cpp index 87c3e60..9f95253 100644 --- a/sources/gui/src/trayicon.cpp +++ b/sources/gui/src/trayicon.cpp @@ -19,18 +19,19 @@ #include #include -#include #include +#include "calls.h" #include "mainwindow.h" -TrayIcon::TrayIcon(QObject *parent, const bool debugCmd) +TrayIcon::TrayIcon(QObject *parent, const QMap settings, const bool debugCmd) : QSystemTrayIcon(parent), debug(debugCmd) { mainWindow = dynamic_cast(parent); + useHelper = (settings[QString("USE_HELPER")] == QString("true")); init(); } @@ -44,41 +45,7 @@ TrayIcon::~TrayIcon() startProfileMenu->clear(); switchToProfileMenu->clear(); menuActions->clear(); - delete startProfileMenu; - delete switchToProfileMenu; delete menuActions; - for (int i=0; iprintInformation(); - QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]); - message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]); - showMessage(title, message, QSystemTrayIcon::Information); - } - else - return showInformationInWindow(); - return 0; -} - - -int TrayIcon::showInformationInWindow() -{ - if (debug) qDebug() << PDEBUG; - - QString title = QApplication::translate("TrayIcon", "netctl status"); - QStringList info = mainWindow->printInformation(); - QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]); - message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]); - - return QMessageBox::information(0, title, message); } @@ -86,79 +53,52 @@ void TrayIcon::updateMenu() { if (debug) qDebug() << PDEBUG; - QStringList info = mainWindow->printTrayInformation(); - bool netctlAutoStatus = info[0].toInt(); - QStringList profiles = info[1].split(QChar('|')); - QString current = info[2]; - QString enabled = info[3]; + netctlCurrent info = mainWindow->printTrayInformation(); - if (current.isEmpty()) { + if (info.current.isEmpty()) { contextMenu[QString("title")]->setIcon(QIcon(QString(":network-offline-64x64"))); contextMenu[QString("title")]->setText(QApplication::translate("TrayIcon", "(inactive)")); } else { contextMenu[QString("title")]->setIcon(QIcon(QString(":network-idle-64x64"))); - QStringList currentProfiles, status; - if (netctlAutoStatus) { - currentProfiles.append(current); - status.append(QApplication::translate("TrayIcon", "(netctl-auto)")); - } else { - for (int i=0; isetText(profiles.join(QString(" | "))); } - if (netctlAutoStatus) { - contextMenu[QString("start")]->setVisible(false); - contextMenu[QString("stop")]->setVisible(false); - contextMenu[QString("stopall")]->setVisible(false); - contextMenu[QString("switch")]->setVisible(true); - contextMenu[QString("restart")]->setVisible(false); - contextMenu[QString("enable")]->setVisible(false); + startProfileMenu->setVisible(!info.netctlAuto); + contextMenu[QString("stop")]->setVisible(!info.netctlAuto && (info.current.count() == 1)); + contextMenu[QString("stopall")]->setVisible(!info.netctlAuto && (info.current.count() > 1)); + switchToProfileMenu->setVisible(info.netctlAuto); + contextMenu[QString("restart")]->setVisible(!info.netctlAuto && (info.current.count() == 1)); + contextMenu[QString("enable")]->setVisible(!info.netctlAuto && (info.current.count() == 1)); + + if (info.netctlAuto) { switchToProfileMenu->clear(); - for (int i=0; iaddAction(profile); - } + for (int i=0; iaddAction(info.current[i]); } else { - if (current.contains(QChar('|'))) { - contextMenu[QString("start")]->setVisible(true); - contextMenu[QString("stop")]->setVisible(false); - contextMenu[QString("stopall")]->setVisible(true); - contextMenu[QString("switch")]->setVisible(false); - contextMenu[QString("restart")]->setVisible(false); - contextMenu[QString("enable")]->setVisible(false); - } else { - contextMenu[QString("start")]->setVisible(true); - contextMenu[QString("stop")]->setVisible(!current.isEmpty()); - contextMenu[QString("switch")]->setVisible(false); - contextMenu[QString("stopall")]->setVisible(false); - contextMenu[QString("restart")]->setVisible(!current.isEmpty()); - contextMenu[QString("enable")]->setVisible(!current.isEmpty()); - } - if (!current.isEmpty()) { - contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start another profile")); - contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(current)); - contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(current)); - if (enabled.split(QChar('|'))[0].toInt()) - contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(current)); + if (info.current.count() == 1) { + contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(info.current[0])); + contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(info.current[0])); + if (info.enables[0]) + contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(info.current[0])); else - contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(current)); - } else - contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start profile")); - startProfileMenu->clear(); - for (int i=0; iaddAction(profile); + contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(info.current[0])); } + startProfileMenu->clear(); + for (int i=0; iaddAction(info.current[i]); } if (mainWindow->isHidden()) @@ -176,55 +116,43 @@ void TrayIcon::createActions() menuActions = new QMenu(); - contextMenu[QString("title")] = new QAction(QIcon(":icon"), QApplication::translate("TrayIcon", "Status"), this); - menuActions->addAction(contextMenu[QString("title")]); - connect(contextMenu[QString("title")], SIGNAL(triggered(bool)), this, SLOT(showInformationInWindow())); - + contextMenu[QString("title")] = menuActions->addAction(QIcon(":icon"), + QApplication::translate("TrayIcon", "Status"), + mainWindow, + SLOT(showMainWindow())); menuActions->addSeparator(); - contextMenu[QString("start")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Start profile"), this); - startProfileMenu = new QMenu(); - contextMenu[QString("start")]->setMenu(startProfileMenu); - connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileSlot(QAction *))); - menuActions->addAction(contextMenu[QString("start")]); + startProfileMenu = menuActions->addMenu(QIcon::fromTheme("system-run"), + QApplication::translate("TrayIcon", "Start profile")); + connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileTraySlot(QAction *))); - contextMenu[QString("stop")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop profile"), this); - connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot())); - menuActions->addAction(contextMenu[QString("stop")]); + contextMenu[QString("stop")] = menuActions->addAction(QIcon::fromTheme("process-stop"), + QApplication::translate("TrayIcon", "Stop profile"), + this, + SLOT(startProfileTraySlot())); + contextMenu[QString("stopall")] = menuActions->addAction(QIcon::fromTheme("process-stop"), + QApplication::translate("TrayIcon", "Stop all profiles"), + this, + SLOT(stopAllProfilesTraySlot())); - contextMenu[QString("stopall")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop all profiles"), this); - connect(contextMenu[QString("stopall")], SIGNAL(triggered(bool)), this, SLOT(stopAllProfilesSlot())); - menuActions->addAction(contextMenu[QString("stopall")]); - - contextMenu[QString("switch")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Switch to profile"), this); - switchToProfileMenu = new QMenu(); - contextMenu[QString("switch")]->setMenu(switchToProfileMenu); - connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchToProfileSlot(QAction *))); - menuActions->addAction(contextMenu[QString("switch")]); - - contextMenu[QString("restart")] = new QAction(QIcon::fromTheme("view-refresh"), QApplication::translate("TrayIcon", "Restart profile"), this); - connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot())); - menuActions->addAction(contextMenu[QString("restart")]); - - contextMenu[QString("enable")] = new QAction(QApplication::translate("TrayIcon", "Enable profile"), this); - connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot())); - menuActions->addAction(contextMenu[QString("enable")]); + switchToProfileMenu = menuActions->addMenu(QIcon::fromTheme("system-run"), + QApplication::translate("TrayIcon", "Switch to profile")); + connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchToProfileTraySlot(QAction *))); + contextMenu[QString("restart")] = menuActions->addAction(QIcon::fromTheme("view-refresh"), + QApplication::translate("TrayIcon", "Restart profile"), + this, + SLOT(restartProfileTraySlot())); + contextMenu[QString("enable")] = menuActions->addAction(QIcon::fromTheme("list-add"), + QApplication::translate("TrayIcon", "Enable profile"), + this, + SLOT(enableProfileTraySlot())); menuActions->addSeparator(); - contextMenu[QString("gui")] = new QAction(QApplication::translate("TrayIcon", "Show"), this); - connect(contextMenu[QString("gui")], SIGNAL(triggered(bool)), mainWindow, SLOT(showMainWindow())); - menuActions->addAction(contextMenu[QString("gui")]); - - contextMenu[QString("auto")] = new QAction(QApplication::translate("TrayIcon", "Show netctl-auto"), this); - connect(contextMenu[QString("auto")], SIGNAL(triggered(bool)), mainWindow, SLOT(showNetctlAutoWindow())); - menuActions->addAction(contextMenu[QString("auto")]); - - menuActions->addSeparator(); - - contextMenu[QString("quit")] = new QAction(QApplication::translate("TrayIcon", "Quit"), this); - connect(contextMenu[QString("quit")], SIGNAL(triggered(bool)), mainWindow, SLOT(closeMainWindow())); - menuActions->addAction(contextMenu[QString("quit")]); + contextMenu[QString("quit")] = menuActions->addAction(QIcon::fromTheme("application-exit"), + QApplication::translate("TrayIcon", "Quit"), + mainWindow, + SLOT(closeMainWindow())); } @@ -249,9 +177,6 @@ void TrayIcon::itemActivated(const QSystemTrayIcon::ActivationReason reason) switch (reason) { case QSystemTrayIcon::Trigger: - showInformation(); - break; - case QSystemTrayIcon::DoubleClick: mainWindow->showMainWindow(); break; case QSystemTrayIcon::Context: @@ -265,59 +190,49 @@ void TrayIcon::itemActivated(const QSystemTrayIcon::ActivationReason reason) } -bool TrayIcon::enableProfileSlot() +void TrayIcon::enableProfileTraySlot() { if (debug) qDebug() << PDEBUG; QString profile = mainWindow->printInformation()[0]; - return mainWindow->enableProfileSlot(profile); + enableProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); } -bool TrayIcon::restartProfileSlot() +void TrayIcon::restartProfileTraySlot() { if (debug) qDebug() << PDEBUG; QString profile = mainWindow->printInformation()[0]; - return mainWindow->restartProfileSlot(profile); + restartProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); } -bool TrayIcon::startProfileSlot(QAction *action) +void TrayIcon::startProfileTraySlot(QAction *action) { if (debug) qDebug() << PDEBUG; QString profile = action->text().remove(QChar('&')); - return mainWindow->switchToProfileSlot(profile); + startProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); } -bool TrayIcon::stopProfileSlot() +void TrayIcon::stopAllProfilesTraySlot() { if (debug) qDebug() << PDEBUG; - QString profile = mainWindow->printInformation()[0]; - - return mainWindow->startProfileSlot(profile); + stopAllProfilesSlot(mainWindow->netctlInterface, useHelper, debug); } -bool TrayIcon::stopAllProfilesSlot() -{ - if (debug) qDebug() << PDEBUG; - - return mainWindow->stopAllProfilesSlot(); -} - - -bool TrayIcon::switchToProfileSlot(QAction *action) +void TrayIcon::switchToProfileTraySlot(QAction *action) { if (debug) qDebug() << PDEBUG; QString profile = action->text().remove(QChar('&')); - return mainWindow->switchToProfileSlot(profile); + switchToProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); } diff --git a/sources/gui/src/trayicon.h b/sources/gui/src/trayicon.h index 9207d88..720fd42 100644 --- a/sources/gui/src/trayicon.h +++ b/sources/gui/src/trayicon.h @@ -31,25 +31,24 @@ class TrayIcon : public QSystemTrayIcon public: explicit TrayIcon(QObject *parent = 0, + const QMap settings = QMap(), const bool debugCmd = false); ~TrayIcon(); public slots: - int showInformation(); - int showInformationInWindow(); void updateMenu(); private slots: void itemActivated(const QSystemTrayIcon::ActivationReason reason); - bool enableProfileSlot(); - bool restartProfileSlot(); - bool startProfileSlot(QAction *action); - bool stopProfileSlot(); - bool stopAllProfilesSlot(); - bool switchToProfileSlot(QAction *action); + void enableProfileTraySlot(); + void restartProfileTraySlot(); + void startProfileTraySlot(QAction *action); + void stopAllProfilesTraySlot(); + void switchToProfileTraySlot(QAction *action); private: bool debug; + bool useHelper = true; MainWindow *mainWindow; // contextual actions QMenu *menuActions; diff --git a/sources/gui/src/wifimenuwidget.cpp b/sources/gui/src/wifimenuwidget.cpp index 3de1c30..0084260 100644 --- a/sources/gui/src/wifimenuwidget.cpp +++ b/sources/gui/src/wifimenuwidget.cpp @@ -23,6 +23,7 @@ #include +#include "calls.h" #include "commonfunctions.h" #include "dbusoperation.h" #include "errorwindow.h" @@ -97,23 +98,10 @@ bool WiFiMenuWidget::wifiTabSelectEssidSlot(const QString essid) void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) { if (debug) qDebug() << PDEBUG; - + if (ui->tableWidget_wifi->currentItem() == nullptr) return; if (passwdWid != nullptr) delete passwdWid; - QStringList interfaces; - if (useHelper) { - QList responce = sendRequestToLib(QString("WirelessInterfaces"), debug); - if (responce.isEmpty()) - interfaces = mainWindow->netctlCommand->getWirelessInterfaceList(); - else - interfaces = responce[0].toStringList(); - } else - interfaces = mainWindow->netctlCommand->getWirelessInterfaceList(); - if (interfaces.isEmpty()) return; QMap settings; - settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); - settings[QString("Interface")] = interfaces[0]; - settings[QString("Connection")] = QString("wireless"); QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text(); if (security.contains(QString("WPA"))) settings[QString("Security")] = QString("wpa"); @@ -121,50 +109,35 @@ void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) settings[QString("Security")] = QString("wep"); else settings[QString("Security")] = QString("none"); - settings[QString("ESSID")] = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text()); if (!passwd.isEmpty()) settings[QString("Key")] = QString("'%1'").arg(passwd); - settings[QString("IP")] = QString("dhcp"); if (hiddenNetwork) settings[QString("Hidden")] = QString("yes"); + QString essid = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text()); + InterfaceAnswer answer = connectToEssid(essid, settings, mainWindow->netctlInterface, + useHelper, debug); - QString profile = QString("netctl-gui-%1").arg(settings[QString("ESSID")]); + QString profile = QString("netctl-gui-%1").arg(essid); profile.remove(QChar('"')).remove(QChar('\'')); - if (useHelper) { - QStringList settingsList; - for (int i=0; i args; - args.append(profile); - args.append(settingsList); - sendRequestToCtrlWithArgs(QString("Create"), args, debug); - } else { - QString profileTempName = mainWindow->netctlProfile->createProfile(profile, settings); - mainWindow->netctlProfile->copyProfile(profileTempName); - } QString message; - if (mainWindow->startProfileSlot(profile)) { - message = QApplication::translate("MainWindow", "Connection is successfully."); + if (answer == InterfaceAnswer::True) { + message = QApplication::translate("MainWindow", "Connection is successfully"); mainWindow->showMessage(true); } else { - message = QApplication::translate("MainWindow", "Connection failed."); + message = QApplication::translate("MainWindow", "Connection failed"); mainWindow->showMessage(false); } message += QString("\n"); message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile); int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"), message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save); + switch (select) { case QMessageBox::Save: break; case QMessageBox::Discard: default: - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - } else - mainWindow->netctlProfile->removeProfile(profile); + removeProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); break; } @@ -199,10 +172,10 @@ void WiFiMenuWidget::updateMenuWifi() } -void WiFiMenuWidget::updateText() +void WiFiMenuWidget::updateText(const netctlWifiInfo current) { if (debug) qDebug() << PDEBUG; - wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug)); + if (wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug))) return; if (!checkExternalApps(QString("wpasup"), configuration, debug)) { ErrorWindow::showWindow(1, QString(PDEBUG), debug); emit(mainWindow->needToBeConfigured()); @@ -210,13 +183,6 @@ void WiFiMenuWidget::updateText() } ui->label_wifi->setText(QApplication::translate("WiFiMenuWidget", "Processing...")); - netctlWifiInfo current; - if (useHelper) - current = parseOutputWifi(sendRequestToCtrl(QString("CurrentWiFi"), debug))[0]; - else - current = mainWindow->wpaCommand->scanWifi()[0]; - if (current.name.isEmpty()) return; - QString text = QString(""); text += QString("%1 - %2 - %3 ").arg(current.name).arg(current.security).arg(current.macs[0]); text += QString("(%1 %2)").arg(current.frequencies[0]).arg(QApplication::translate("WiFiMenuWidget", "MHz")); @@ -228,7 +194,7 @@ void WiFiMenuWidget::updateText() void WiFiMenuWidget::updateWifiTab() { if (debug) qDebug() << PDEBUG; - wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug)); + if (wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug))) return; if (!checkExternalApps(QString("wpasup"), configuration, debug)) { ErrorWindow::showWindow(1, QString(PDEBUG), debug); emit(mainWindow->needToBeConfigured()); @@ -259,6 +225,7 @@ void WiFiMenuWidget::updateWifiTab() headerList.append(QApplication::translate("WiFiMenuWidget", "Exists")); ui->tableWidget_wifi->setHorizontalHeaderLabels(headerList); // create items + netctlWifiInfo current = scanResults.isEmpty() ? netctlWifiInfo() : scanResults.takeFirst(); for (int i=0; itableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); #endif - updateText(); + updateText(current); mainWindow->setDisabled(false); mainWindow->showMessage(true); } @@ -375,13 +342,15 @@ void WiFiMenuWidget::wifiTabContextualMenu(const QPoint &pos) } -void WiFiMenuWidget::wifiTabSetEnabled(const bool state) +bool WiFiMenuWidget::wifiTabSetEnabled(const bool state) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "State" << state; - ui->tableWidget_wifi->setHidden(!state); - if (!state) ui->label_wifi->setText(QApplication::translate("WiFiMenuWidget", "Please install 'wpa_supplicant' before using it")); + ui->tableWidget_wifi->setEnabled(state); + if (!state) ui->label_wifi->setText(QApplication::translate("WiFiMenuWidget", "Please install 'wpa_supplicant' before use it")); + + return state; } @@ -396,6 +365,7 @@ void WiFiMenuWidget::wifiTabStart() if (ui->tableWidget_wifi->currentItem() == nullptr) return; mainWindow->setDisabled(true); + // name is hidden if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("")) { hiddenNetwork = true; @@ -414,21 +384,10 @@ void WiFiMenuWidget::wifiTabStart() // name isn't hidden hiddenNetwork = false; QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); - QString profileName = QString(""); if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 6)->text().isEmpty()) { - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLibWithArgs(QString("ProfileByEssid"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return wifiTabStart(); - } - profileName = responce[0].toString(); - } else - profileName = mainWindow->wpaCommand->existentProfile(profile); - mainWindow->showMessage(mainWindow->startProfileSlot(profileName)); + InterfaceAnswer answer = startProfileSlot(profile, mainWindow->netctlInterface, + useHelper, debug); + mainWindow->showMessage(answer == InterfaceAnswer::True); } else { QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); if (security == QString("none")) return connectToUnknownEssid(QString("")); diff --git a/sources/gui/src/wifimenuwidget.h b/sources/gui/src/wifimenuwidget.h index d0992a9..43ab573 100644 --- a/sources/gui/src/wifimenuwidget.h +++ b/sources/gui/src/wifimenuwidget.h @@ -53,11 +53,11 @@ public slots: private slots: // update slots void updateMenuWifi(); - void updateText(); + void updateText(const netctlWifiInfo current); void updateWifiTab(); // wifi tab slots void wifiTabContextualMenu(const QPoint &pos); - void wifiTabSetEnabled(const bool state); + bool wifiTabSetEnabled(const bool state); void wifiTabStart(); private: @@ -70,7 +70,7 @@ private: void createObjects(); void deleteObjects(); bool debug = false; - bool hiddenNetwork; + bool hiddenNetwork = false; bool useHelper = true; // configuration QMap configuration; diff --git a/sources/helper/src/CMakeLists.txt b/sources/helper/src/CMakeLists.txt index 53fda84..d4757dd 100644 --- a/sources/helper/src/CMakeLists.txt +++ b/sources/helper/src/CMakeLists.txt @@ -1,6 +1,7 @@ # set files file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp - ${PROJECT_TRDPARTY_DIR}/language/*.cpp) + ${PROJECT_TRDPARTY_DIR}/language/*.cpp + ${PROJECT_TRDPARTY_DIR}/listmap/*.cpp) file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h ${PROJECT_TRDPARTY_DIR}/language/*.h) diff --git a/sources/helper/src/controladaptor.cpp b/sources/helper/src/controladaptor.cpp index 4f63dc9..64818cb 100644 --- a/sources/helper/src/controladaptor.cpp +++ b/sources/helper/src/controladaptor.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include "netctlhelper.h" #include "version.h" @@ -80,11 +82,7 @@ QStringList ControlAdaptor::FindSettings() for (int i=0; i settings; - for (int i=0; icreateProfile(profile, settings); + QString temporaryProfile = netctlProfile->createProfile(profile, listToMap(settingsList)); return netctlProfile->copyProfile(temporaryProfile); } diff --git a/sources/helper/src/controladaptor.h b/sources/helper/src/controladaptor.h index b6ac94b..fabde9a 100644 --- a/sources/helper/src/controladaptor.h +++ b/sources/helper/src/controladaptor.h @@ -70,7 +70,7 @@ public slots: // wpaCommand QString CurrentWiFi(); QStringList VerboseWiFi(); - Q_DECL_DEPRECATED QStringList WiFi(); + QStringList WiFi(); private: bool debug; diff --git a/sources/helper/src/interfaceadaptor.cpp b/sources/helper/src/interfaceadaptor.cpp index 3f2ed6a..2135e46 100644 --- a/sources/helper/src/interfaceadaptor.cpp +++ b/sources/helper/src/interfaceadaptor.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include "netctlhelper.h" #include "version.h" @@ -38,6 +40,7 @@ InterfaceAdaptor::~InterfaceAdaptor() } +// control slots int InterfaceAdaptor::autoEnable(const QString profile) { return netctlInterface->autoEnableProfile(profile); @@ -46,15 +49,7 @@ int InterfaceAdaptor::autoEnable(const QString profile) int InterfaceAdaptor::Create(const QString profile, const QStringList settingsList) { - QMap settings; - for (int i=0; icreateProfile(profile, settings); + return netctlInterface->createProfile(profile, listToMap(settingsList)); } @@ -66,15 +61,7 @@ int InterfaceAdaptor::Enable(const QString profile) int InterfaceAdaptor::Essid(const QString essid, QStringList settingsList) { - QMap settings; - for (int i=0; iconnectToEssid(essid, settings); + return netctlInterface->connectToEssid(essid, listToMap(settingsList)); } @@ -84,6 +71,12 @@ int InterfaceAdaptor::KnownEssid(const QString essid) } +int InterfaceAdaptor::Remove(const QString profile) +{ + return netctlInterface->removeProfile(profile); +} + + int InterfaceAdaptor::Restart(const QString profile) { return netctlInterface->restartProfile(profile); @@ -110,13 +103,55 @@ int InterfaceAdaptor::SwitchTo(const QString profile) int InterfaceAdaptor::UnknownEssid(const QString essid, QStringList settingsList) { - QMap settings; - for (int i=0; iconnectToUnknownEssid(essid, listToMap(settingsList)); +} + + +// information +QStringList InterfaceAdaptor::Information() +{ + netctlInformation information = netctlInterface->information(); + QStringList info; + info.append(QString::number(information.netctlAuto)); + + QList profiles = information.netctlProfiles; + profiles.append(information.netctlAutoProfiles); + for (int i=0; iconnectToUnknownEssid(essid, settings); + return info; +} + + +QStringList InterfaceAdaptor::Profile(const QString profile) +{ + QMap settings = netctlInterface->profileSettings(profile); + + return mapToList(settings); +} + + +QStringList InterfaceAdaptor::Status() +{ + netctlCurrent current = netctlInterface->status(); + QStringList info; + info.append(QString::number(current.netctlAuto)); + info.append(current.profiles.join(QChar('|'))); + info.append(current.current.join(QChar('|'))); + QStringList enables; + for (int i=0; i + NetctlAdaptor::NetctlAdaptor(QObject *parent, const bool debugCmd, const QMap configuration) : QDBusAbstractAdaptor(parent), @@ -142,6 +144,7 @@ QStringList NetctlAdaptor::netctlVerboseProfileList() profileInfo.append(profilesInfo[i].essid); profileInfo.append(QString::number(profilesInfo[i].active)); profileInfo.append(QString::number(profilesInfo[i].enabled)); + profileInfo.append(QString::number(profilesInfo[i].netctlAuto)); info.append(profileInfo.join(QChar('|'))); } @@ -187,6 +190,7 @@ QStringList NetctlAdaptor::VerboseProfileList() profileInfo.append(profilesInfo[i].essid); profileInfo.append(QString::number(profilesInfo[i].active)); profileInfo.append(QString::number(profilesInfo[i].enabled)); + profileInfo.append(QString::number(profilesInfo[i].netctlAuto)); info.append(profileInfo.join(QChar('|'))); } @@ -198,11 +202,8 @@ QStringList NetctlAdaptor::VerboseProfileList() QStringList NetctlAdaptor::Profile(const QString profile) { QMap settings = netctlProfile->getSettingsFromProfile(profile); - QStringList settingsList; - for (int i=0; i #include +#include #include #include @@ -57,11 +58,7 @@ QStringList NetctlHelper::printSettings() { if (debug) qDebug() << PDEBUG; - QStringList settingsList; - for (int i=0; i #include +#include "netctlinteract.h" +#include "netctlprofile.h" +#include "wpasupinteract.h" -class Netctl; -class NetctlProfile; -class WpaSup; /** * @enum InterfaceAnswer @@ -51,6 +51,43 @@ enum InterfaceAnswer { Error }; +/** + * @struct netctlCurrent + * @brief current status structure + * @var netctlCurrent::current + * current profiles + * @var netctlCurrent::enables + * are current profiles enabled + * @var netctlCurrent::netctlAuto + * is netctl-auto active + * @var netctlCurrent::profiles + * list of profiles + */ +typedef struct +{ + QStringList current; + QList enables; + QStringList profiles; + bool netctlAuto = false; +} netctlCurrent; + +/** + * @struct netctlInformation + * @brief general information structure + * @var netctlCurrent::netctlProfiles + * list of profiles + * @var netctlCurrent::netctlAutoProfiles + * list of netctl-auto profiles + * @var netctlCurrent::netctlAuto + * is netctl-auto active + */ +typedef struct +{ + QList netctlProfiles; + QList netctlAutoProfiles; + bool netctlAuto = false; +} netctlInformation; + /** * @brief The NetctlInterface class provides complex methods to get access to library */ @@ -70,6 +107,7 @@ public: * @brief NetctlInterface class destructor */ ~NetctlInterface(); + // control methods /** * @brief method which enables or disables selected profile and returns its status * @remark netctl-auto only @@ -127,6 +165,14 @@ public: * @return InterfaceAnswer::Error if an error occurs */ InterfaceAnswer enableProfile(const QString profile); + /** + * @brief method which removes selected profile + * @remark netctl independ + * @param profile profile name + * @return InterfaceAnswer::True if profile does not exists anymore + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer removeProfile(const QString profile); /** * @brief method which restarts selected profile and returns its status * @remark netctl only @@ -161,6 +207,25 @@ public: * @return InterfaceAnswer::Error if an error occurs */ InterfaceAnswer switchToProfile(const QString profile); + // information + /** + * @brief method which returns general information + * @remark both netctl and netctl-auto + * @return netctlInformation structure + */ + netctlInformation information(); + /** + * @brief method which reads settings from profile + * @param profile profile name + * @return settings from profile + */ + QMap profileSettings(const QString profile); + /** + * @brief method which returns current status + * @remark both netctl and netctl-auto + * @return netctlCurrent structure + */ + netctlCurrent status(); private: /** diff --git a/sources/netctlgui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp index 7729f18..7776360 100644 --- a/sources/netctlgui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -203,6 +203,7 @@ QList Netctl::getProfileList() profileInfo.essid = profileValues[2]; profileInfo.interface = profileValues[3]; profileInfo.type = profileValues[0]; + profileInfo.netctlAuto = false; fullProfilesInfo.append(profileInfo); } @@ -227,12 +228,18 @@ QList Netctl::getProfileListFromNetctlAuto() profileInfo.enabled = (output[i][0] != QChar('!')); // external QStringList keys; + keys.append(QString("Connection")); keys.append(QString("Description")); keys.append(QString("ESSID")); + keys.append(QString("Interface")); QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name, keys); - profileInfo.description = profileValues[0]; + profileInfo.description = profileValues[1]; + profileInfo.essid = profileValues[2]; + profileInfo.interface = profileValues[3]; + profileInfo.type = profileValues[0]; profileInfo.essid = profileValues[1]; + profileInfo.netctlAuto = true; fullProfilesInfo.append(profileInfo); } diff --git a/sources/netctlgui/src/netctlinterface.cpp b/sources/netctlgui/src/netctlinterface.cpp index b2a97c3..9bddb29 100644 --- a/sources/netctlgui/src/netctlinterface.cpp +++ b/sources/netctlgui/src/netctlinterface.cpp @@ -25,7 +25,7 @@ #include -#include +#include #include @@ -89,10 +89,11 @@ InterfaceAnswer NetctlInterface::connectToEssid(const QString essid, QMapexistentProfile(essid).isEmpty()) + QString profile = wpaCommand->existentProfile(essid); + if (profile.isEmpty()) return connectToUnknownEssid(essid, settings); else - return connectToKnownEssid(essid); + return startProfile(profile); } @@ -187,6 +188,24 @@ InterfaceAnswer NetctlInterface::enableProfile(const QString profile) } +/** + * @fn removeProfile + */ +InterfaceAnswer NetctlInterface::removeProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlProfile == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + if (netctlProfile->removeProfile(profile)) + return InterfaceAnswer::True; + else + return InterfaceAnswer::Error; +} + + /** * @fn restartProfile */ @@ -266,3 +285,67 @@ InterfaceAnswer NetctlInterface::switchToProfile(const QString profile) return status; } + + +/** + * @fn information + */ +netctlInformation NetctlInterface::information() +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return netctlInformation(); + } + + netctlInformation info; + info.netctlAuto = netctlCommand->isNetctlAutoRunning(); + info.netctlProfiles = netctlCommand->getProfileList(); + if (info.netctlAuto) info.netctlAutoProfiles = netctlCommand->getProfileListFromNetctlAuto(); + + return info; +} + + +/** + * @fn profileSettings + */ +QMap NetctlInterface::profileSettings(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlProfile == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return QMap(); + } + + return netctlProfile->getSettingsFromProfile(profile); +} + + +/** + * @fn status + */ +netctlCurrent NetctlInterface::status() +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return netctlCurrent(); + } + + netctlCurrent current; + current.netctlAuto = netctlCommand->isNetctlAutoRunning(); + QList profiles; + if (current.netctlAuto) + profiles = netctlCommand->getProfileListFromNetctlAuto(); + else + profiles = netctlCommand->getProfileList(); + for (int i=0; i #include +#include #include #include "version.h" @@ -119,12 +120,9 @@ void TestNetctl::test_getRecommendedConfiguration() original.append(QString("SUDO_PATH==/usr/bin/sudo")); original.append(QString("SYSTEMCTL_PATH==/usr/bin/systemctl")); QMap resultMap = Netctl::getRecommendedConfiguration(); - QStringList result; - for (int i=0; i #include +#include #include #include "version.h" @@ -107,12 +108,9 @@ void TestNetctlProfile::test_getRecommendedConfiguration() original.append(QString("PROFILE_DIR==/etc/netctl")); original.append(QString("SUDO_PATH==/usr/bin/sudo")); QMap resultMap = NetctlProfile::getRecommendedConfiguration(); - QStringList result; - for (int i=0; i args; args.append(QString("netctlgui-test-full")); - QStringList profileSettingsList; - for (int i=0; i resultMap = netctl->getSettingsFromProfile(QString("netctlgui-test-full")); - for (int i=0; iremoveProfile(QString("netctlgui-test-full")); delete netctl; - QCOMPARE(result, original); - if (helper) QCOMPARE(dbus, result); + QCOMPARE(mapToList(resultMap), original); + if (helper) QCOMPARE(dbus, mapToList(resultMap)); } diff --git a/sources/test/testwpasup.cpp b/sources/test/testwpasup.cpp index 444b4d7..29fb74f 100644 --- a/sources/test/testwpasup.cpp +++ b/sources/test/testwpasup.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include "version.h" @@ -83,12 +84,9 @@ void TestWpaSup::test_getRecommendedConfiguration() original.append(QString("WPASUP_PATH==/usr/bin/wpa_supplicant")); original.append(QString("WPA_DRIVERS==nl80211,wext")); QMap resultMap = WpaSup::getRecommendedConfiguration(); - QStringList result; - for (int i=0; i