From 26afd90df98fd76d8e0f8da515115b40920d9fef Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 13 Mar 2015 05:12:06 +0300 Subject: [PATCH] + add toolbar config + create interface class * update UI --- sources/gui/docs/netctl-gui-dbus-api.html | 4 +- sources/gui/src/calls.cpp | 183 ++++++++++ sources/gui/src/calls.h | 31 ++ sources/gui/src/mainwidget.cpp | 50 +-- sources/gui/src/mainwidget.h | 7 +- sources/gui/src/mainwidget.ui | 45 +-- sources/gui/src/mainwindow.cpp | 219 ++++------- sources/gui/src/mainwindow.h | 18 +- sources/gui/src/mainwindow.ui | 6 + sources/gui/src/netctlautowindow.cpp | 48 ++- sources/gui/src/netctlautowindow.h | 6 +- sources/gui/src/newprofilewidget.cpp | 38 +- sources/gui/src/newprofilewidget.h | 4 +- sources/gui/src/settingswindow.cpp | 73 ++++ sources/gui/src/settingswindow.h | 2 + sources/gui/src/settingswindow.ui | 339 +++++++++++++++++- sources/gui/src/wifimenuwidget.cpp | 73 +++- sources/gui/src/wifimenuwidget.h | 6 +- sources/helper/src/controladaptor.cpp | 4 +- .../netctlgui/include/netctlgui/netctlgui.h | 1 + .../include/netctlgui/netctlinterface.h | 178 +++++++++ .../include/netctlgui/wpasupinteract.h | 4 +- sources/netctlgui/src/netctlinterface.cpp | 250 +++++++++++++ sources/netctlgui/src/wpasupinteract.cpp | 40 +-- 24 files changed, 1322 insertions(+), 307 deletions(-) create mode 100644 sources/gui/src/calls.cpp create mode 100644 sources/gui/src/calls.h create mode 100644 sources/netctlgui/include/netctlgui/netctlinterface.h create mode 100644 sources/netctlgui/src/netctlinterface.cpp diff --git a/sources/gui/docs/netctl-gui-dbus-api.html b/sources/gui/docs/netctl-gui-dbus-api.html index eae89be..e31b4b2 100644 --- a/sources/gui/docs/netctl-gui-dbus-api.html +++ b/sources/gui/docs/netctl-gui-dbus-api.html @@ -198,12 +198,12 @@ small { QStringList CurrentWiFi() - returns current WiFi point in format NAME|SECURITY|TYPE|FREQS|MACS|SIGNAL|ACTIVE|EXISTS + returns current WiFi point in format NAME|SECURITY|TYPE|FREQ|MAC|SIGNAL|ACTIVE|EXISTS yes QStringList VerboseWiFi() - returns available WiFi points in format NAME|SECURITY|TYPE|FREQS|MACS|SIGNAL|ACTIVE|EXISTS + returns available WiFi points in format NAME|SECURITY|TYPE|FREQS|MACS|SIGNAL|ACTIVE|EXISTS. First line is always active connection (see CurrentWiFi()) yes diff --git a/sources/gui/src/calls.cpp b/sources/gui/src/calls.cpp new file mode 100644 index 0000000..dbde957 --- /dev/null +++ b/sources/gui/src/calls.cpp @@ -0,0 +1,183 @@ +/*************************************************************************** + * 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 "calls.h" + +#include + +#include + +#include "dbusoperation.h" + + +bool enableProfileSlot(const QString profile, Netctl *netctlCommand, + const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + // enable + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("Enable"), args, debug); + // check + QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileEnabled(profile); + else + current = responce[0].toBool(); + } else { + // enable + netctlCommand->enableProfile(profile); + // check + current = netctlCommand->isProfileEnabled(profile); + } + + return current; +} + + +bool restartProfileSlot(const QString profile, Netctl *netctlCommand, + const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + // restart + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("Restart"), args, debug); + // check + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + // restart + netctlCommand->restartProfile(profile); + // check + current = netctlCommand->isProfileActive(profile); + } + + return current; +} + + +bool startProfileSlot(const QString profile, Netctl *netctlCommand, + const bool useHelper, const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + // get current + QList args; + args.append(profile); + QList responce = sendRequestToLib(QString("ActiveProfile"), debug); + QStringList currentProfile; + if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); + // start or switch + if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) + sendRequestToCtrlWithArgs(QString("Start"), args, debug); + else + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + // check + responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + // get current + QStringList currentProfile = netctlCommand->getActiveProfile(); + // start or switch + if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) + netctlCommand->startProfile(profile); + else + netctlCommand->switchToProfile(profile); + // check + current = netctlCommand->isProfileActive(profile); + } + + return current; +} + + +bool MainWindow::stopAllProfilesSlot() +{ + if (debug) qDebug() << PDEBUG; + + if (useHelper) + sendRequestToCtrl(QString("StolAll"), debug); + else + netctlCommand->stopAllProfiles(); + + return true; +} + + +bool MainWindow::switchToProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool netctlAutoStatus = false; + if (useHelper) { + QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); + if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); + } else + netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); + + bool current; + if (netctlAutoStatus) { + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->autoIsProfileActive(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->autoStartProfile(profile); + current = netctlCommand->autoIsProfileActive(profile); + } + } else { + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->switchToProfile(profile); + current = netctlCommand->isProfileActive(profile); + } + } + + return current; +} diff --git a/sources/gui/src/calls.h b/sources/gui/src/calls.h new file mode 100644 index 0000000..a63468c --- /dev/null +++ b/sources/gui/src/calls.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * 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/ * + ***************************************************************************/ + +#ifndef CALLS_H +#define CALLS_H + +#include +#include + +#include + + +bool enableProfileSlot(const QString profile, Netctl *netctlCommand, + const bool useHelper, const bool debug = false); + + +#endif /* CALLS_H */ diff --git a/sources/gui/src/mainwidget.cpp b/sources/gui/src/mainwidget.cpp index 66d5166..5b8faa6 100644 --- a/sources/gui/src/mainwidget.cpp +++ b/sources/gui/src/mainwidget.cpp @@ -51,6 +51,14 @@ MainWidget::~MainWidget() } +Qt::ToolBarArea MainWidget::getToolBarArea() +{ + if (debug) qDebug() << PDEBUG; + + return toolBarArea(ui->toolBar); +} + + bool MainWidget::mainTabSelectProfileSlot(const QString profile) { if (debug) qDebug() << PDEBUG; @@ -65,14 +73,6 @@ bool MainWidget::mainTabSelectProfileSlot(const QString profile) } -void MainWidget::showNetctlAutoWindow() -{ - if (debug) qDebug() << PDEBUG; - - netctlAutoWin->showWindow(); -} - - void MainWidget::update() { if (debug) qDebug() << PDEBUG; @@ -82,6 +82,19 @@ void MainWidget::update() } +void MainWidget::updateToolBarState(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area; + + removeToolBar(ui->toolBar); + if (area != Qt::NoToolBarArea) { + addToolBar(area, ui->toolBar); + ui->toolBar->show(); + } +} + + void MainWidget::updateMenuMain() { if (debug) qDebug() << PDEBUG; @@ -139,10 +152,10 @@ void MainWidget::updateMainTab() netctlAutoStatus = responce[0].toBool(); profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); } else { - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - profiles = netctlCommand->getProfileList(); + netctlAutoStatus = mainWindow->netctlCommand->isNetctlAutoRunning(); + profiles = mainWindow->netctlCommand->getProfileList(); } - ui->widget_netctlAuto->setHidden(!netctlAutoStatus); + ui->label_netctlAuto->setHidden(!netctlAutoStatus); ui->tableWidget_main->setSortingEnabled(false); ui->tableWidget_main->selectRow(-1); @@ -317,7 +330,7 @@ void MainWidget::mainTabRemoveProfile() } status = responce[0].toBool(); } else - status = netctlProfile->removeProfile(profile); + status = mainWindow->netctlProfile->removeProfile(profile); mainWindow->showMessage(status); updateMainTab(); @@ -380,7 +393,7 @@ void MainWidget::mainTabStopAllProfiles() } status = responce[0].toBool(); } else - status = netctlCommand->stopAllProfiles(); + status = mainWindow->netctlCommand->stopAllProfiles(); mainWindow->showMessage(status); updateMainTab(); @@ -412,7 +425,6 @@ void MainWidget::createActions() // menu actions connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(mainTabEnableProfile())); connect(ui->actionEdit, SIGNAL(triggered(bool)), this, SLOT(mainTabEditProfile())); - connect(ui->actionNetctl_auto, SIGNAL(triggered(bool)), this, SLOT(showNetctlAutoWindow())); connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(updateMainTab())); connect(ui->actionRemove, SIGNAL(triggered(bool)), this, SLOT(mainTabRemoveProfile())); connect(ui->actionRestart, SIGNAL(triggered(bool)), this, SLOT(mainTabRestartProfile())); @@ -420,7 +432,6 @@ void MainWidget::createActions() connect(ui->actionStop_all, SIGNAL(triggered(bool)), this, SLOT(mainTabStopAllProfiles())); connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(mainTabSwitchToProfile())); // main tab events - connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow())); connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(updateMenuMain())); @@ -432,15 +443,13 @@ void MainWidget::createObjects() { if (debug) qDebug() << PDEBUG; - // backend - netctlCommand = new Netctl(debug, configuration); - netctlProfile = new NetctlProfile(debug, configuration); // windows ui = new Ui::MainWidget; ui->setupUi(this); ui->tableWidget_main->setColumnHidden(2, true); ui->tableWidget_main->setColumnHidden(3, true); - netctlAutoWin = new NetctlAutoWindow(this, debug, configuration); + updateToolBarState(static_cast(configuration[QString("NETCTL_TOOLBAR")].toInt())); + netctlAutoWin = new NetctlAutoWindow(mainWindow, debug, configuration); // append toolbar QMenu *actionMenu = new QMenu(this); @@ -455,9 +464,6 @@ void MainWidget::deleteObjects() { if (debug) qDebug() << PDEBUG; - if (netctlCommand != nullptr) delete netctlCommand; - if (netctlProfile != nullptr) delete netctlProfile; - 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 1a8cb48..bad480f 100644 --- a/sources/gui/src/mainwidget.h +++ b/sources/gui/src/mainwidget.h @@ -40,11 +40,13 @@ public: const QMap settings = QMap(), const bool debugCmd = false); ~MainWidget(); + NetctlAutoWindow *netctlAutoWin = nullptr; + Qt::ToolBarArea getToolBarArea(); public slots: bool mainTabSelectProfileSlot(const QString profile); - void showNetctlAutoWindow(); void update(); + void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea); private slots: // update slots @@ -64,10 +66,7 @@ private: // ui MainWindow *mainWindow = nullptr; Ui::MainWidget *ui = nullptr; - NetctlAutoWindow *netctlAutoWin = nullptr; // backend - Netctl *netctlCommand = nullptr; - NetctlProfile *netctlProfile = nullptr; void createActions(); void createObjects(); void deleteObjects(); diff --git a/sources/gui/src/mainwidget.ui b/sources/gui/src/mainwidget.ui index 328cd8a..51447f8 100644 --- a/sources/gui/src/mainwidget.ui +++ b/sources/gui/src/mainwidget.ui @@ -16,32 +16,16 @@ 0 - - - - 0 - - - - - - 0 - 0 - - - - netctl-auto is running - - - - - - - Show - - - - + + + + 0 + 0 + + + + netctl-auto is running + @@ -105,7 +89,6 @@ false - @@ -114,14 +97,6 @@ - - - netctl-auto - - - Show netctl-auto window - - diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index cac20f0..92d3efe 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,7 @@ #include "dbusoperation.h" #include "errorwindow.h" #include "mainwidget.h" +#include "netctlautowindow.h" #include "netctlguiadaptor.h" #include "newprofilewidget.h" #include "passwdwidget.h" @@ -71,6 +73,8 @@ MainWindow::MainWindow(QWidget *parent, if (debug) qDebug() << PDEBUG << ":" << "settings" << args[QString("settings")].toBool(); if (debug) qDebug() << PDEBUG << ":" << "tab" << args[QString("tab")].toInt(); + ui = new Ui::MainWindow; + ui->setupUi(this); updateConfiguration(args); // main actions @@ -103,6 +107,15 @@ MainWindow::~MainWindow() if ((useHelper) && (configuration[QString("CLOSE_HELPER")] == QString("true"))) forceStopHelper(); deleteObjects(); + delete ui; +} + + +Qt::ToolBarArea MainWindow::getToolBarArea() +{ + if (debug) qDebug() << PDEBUG; + + return toolBarArea(ui->toolBar); } @@ -267,10 +280,19 @@ void MainWindow::closeMainWindow() { if (debug) qDebug() << PDEBUG; + storeToolBars(); qApp->quit(); } +void MainWindow::openProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + + newProfileWidget->profileTabOpenProfileSlot(profile); +} + + void MainWindow::showAboutWindow() { if (debug) qDebug() << PDEBUG; @@ -295,7 +317,7 @@ void MainWindow::showNetctlAutoWindow() { if (debug) qDebug() << PDEBUG; - mainWidget->showNetctlAutoWindow(); + netctlAutoWin->showWindow(); } @@ -303,160 +325,11 @@ void MainWindow::showSettingsWindow() { if (debug) qDebug() << PDEBUG; + storeToolBars(); settingsWin->showWindow(); } -bool MainWindow::enableProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Enable"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileEnabled(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->enableProfile(profile); - current = netctlCommand->isProfileEnabled(profile); - } - - return current; -} - - -void MainWindow::openProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - - newProfileWidget->profileTabOpenProfileSlot(profile); -} - - -bool MainWindow::restartProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Restart"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->restartProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - - return current; -} - - -bool MainWindow::startProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLib(QString("ActiveProfile"), debug); - QStringList currentProfile; - if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - sendRequestToCtrlWithArgs(QString("Start"), args, debug); - else - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - QStringList currentProfile = netctlCommand->getActiveProfile(); - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - netctlCommand->startProfile(profile); - else - netctlCommand->switchToProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - - return current; -} - - -bool MainWindow::stopAllProfilesSlot() -{ - if (debug) qDebug() << PDEBUG; - - if (useHelper) - sendRequestToCtrl(QString("StolAll"), debug); - else - netctlCommand->stopAllProfiles(); - - return true; -} - - -bool MainWindow::switchToProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool netctlAutoStatus = false; - if (useHelper) { - QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); - } else - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - - bool current; - if (netctlAutoStatus) { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->autoIsProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->autoStartProfile(profile); - current = netctlCommand->autoIsProfileActive(profile); - } - } else { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->switchToProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - } - - return current; -} - - void MainWindow::showApi() { if (debug) qDebug() << PDEBUG; @@ -556,6 +429,24 @@ void MainWindow::showMessage(const bool status) } +void MainWindow::storeToolBars() +{ + if (debug) qDebug() << PDEBUG; + + QSettings settings(configPath, QSettings::IniFormat); + + settings.beginGroup(QString("Toolbars")); + settings.setValue(QString("MAIN_TOOLBAR"), QString::number(getToolBarArea())); + settings.setValue(QString("NETCTL_TOOLBAR"), QString::number(mainWidget->getToolBarArea())); + settings.setValue(QString("NETCTLAUTO_TOOLBAR"), QString::number(netctlAutoWin->getToolBarArea())); + settings.setValue(QString("PROFILE_TOOLBAR"), QString::number(newProfileWidget->getToolBarArea())); + settings.setValue(QString("WIFI_TOOLBAR"), QString::number(wifiMenuWidget->getToolBarArea())); + settings.endGroup(); + + settings.sync(); +} + + void MainWindow::updateConfiguration(const QMap args) { if (debug) qDebug() << PDEBUG; @@ -627,6 +518,21 @@ void MainWindow::updateTabs(const int tab) } +void MainWindow::updateToolBarState(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area; + + removeToolBar(ui->toolBar); + if (area != Qt::NoToolBarArea) { + addToolBar(area, ui->toolBar); + ui->toolBar->show(); + } + + qDebug() << findChildren().count(); +} + + // private slots void MainWindow::setMainTab() { @@ -681,6 +587,7 @@ void MainWindow::createActions() { if (debug) qDebug() << PDEBUG; + connect(ui->actionNetctl_auto, SIGNAL(triggered()), this, SLOT(showNetctlAutoWindow())); connect(ui->actionNetctl, SIGNAL(triggered()), this, SLOT(setMainTab())); connect(ui->actionProfiles, SIGNAL(triggered()), this, SLOT(setProfileTab())); connect(ui->actionWiFi_menu, SIGNAL(triggered()), this, SLOT(setWifiTab())); @@ -729,17 +636,20 @@ void MainWindow::createObjects() checkHelperStatus(); netctlCommand = new Netctl(debug, configuration); + netctlProfile = new NetctlProfile(debug, configuration); + wpaCommand = new WpaSup(debug, configuration); // frontend mainWidget = new MainWidget(this, configuration, debug); + netctlAutoWin = mainWidget->netctlAutoWin; newProfileWidget = new NewProfileWidget(this, configuration, debug); wifiMenuWidget = new WiFiMenuWidget(this, configuration, debug); trayIcon = new TrayIcon(this, debug); // windows - ui = new Ui::MainWindow; - ui->setupUi(this); + ui->retranslateUi(this); ui->layout_main->addWidget(mainWidget); ui->layout_new->addWidget(newProfileWidget); ui->layout_wifi->addWidget(wifiMenuWidget); + updateToolBarState(static_cast(configuration[QString("MAIN_TOOLBAR")].toInt())); aboutWin = new AboutWindow(this, debug); settingsWin = new SettingsWindow(this, debug, configPath); } @@ -752,6 +662,8 @@ void MainWindow::deleteObjects() QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH); QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE); if (netctlCommand != nullptr) delete netctlCommand; + if (netctlProfile != nullptr) delete netctlProfile; + if (wpaCommand != nullptr) delete wpaCommand; if (aboutWin != nullptr) delete aboutWin; if (settingsWin != nullptr) delete settingsWin; @@ -759,7 +671,6 @@ void MainWindow::deleteObjects() if (mainWidget != nullptr) delete mainWidget; if (newProfileWidget != nullptr) delete newProfileWidget; if (wifiMenuWidget != nullptr) delete wifiMenuWidget; - if (ui != nullptr) delete ui; } diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 4086cfe..3ceefc8 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -27,6 +27,7 @@ class AboutWindow; class MainWidget; +class NetctlAutoWindow; class NewProfileWidget; class SettingsWindow; class TrayIcon; @@ -46,11 +47,16 @@ public: QTranslator *qtAppTranslator = 0, QTranslator *appTranslator = 0); ~MainWindow(); + Qt::ToolBarArea getToolBarArea(); QStringList printInformation(); QStringList printSettings(); QStringList printTrayInformation(); bool isHelperActive(); bool isHelperServiceActive(); + // library interfaces + Netctl *netctlCommand = nullptr; + NetctlProfile *netctlProfile = nullptr; + WpaSup *wpaCommand = nullptr; protected: void closeEvent(QCloseEvent *event); @@ -58,17 +64,11 @@ protected: public slots: // actions from trayicon void closeMainWindow(); + void openProfileSlot(const QString profile); void showAboutWindow(); void showMainWindow(); void showNetctlAutoWindow(); void showSettingsWindow(); - // trayicon control slots - bool enableProfileSlot(const QString profile); - void openProfileSlot(const QString profile); - bool startProfileSlot(const QString profile); - bool stopAllProfilesSlot(); - bool switchToProfileSlot(const QString profile); - bool restartProfileSlot(const QString profile); // open docs void showApi(); void showLibrary(); @@ -81,8 +81,10 @@ public slots: void setDisabled(const bool disabled = true); void setTab(int tab); void showMessage(const bool status); + void storeToolBars(); void updateConfiguration(const QMap args = QMap()); void updateTabs(const int tab); + void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea); signals: void needToBeConfigured(); @@ -99,11 +101,11 @@ private: Ui::MainWindow *ui = nullptr; AboutWindow *aboutWin = nullptr; MainWidget *mainWidget = nullptr; + NetctlAutoWindow *netctlAutoWin = nullptr; NewProfileWidget *newProfileWidget = nullptr; SettingsWindow *settingsWin = nullptr; WiFiMenuWidget *wifiMenuWidget = nullptr; // backend - Netctl *netctlCommand = nullptr; bool checkHelperStatus(); void createActions(); void createDBusSession(); diff --git a/sources/gui/src/mainwindow.ui b/sources/gui/src/mainwindow.ui index 976fcfa..9594544 100644 --- a/sources/gui/src/mainwindow.ui +++ b/sources/gui/src/mainwindow.ui @@ -88,6 +88,7 @@ false + @@ -213,6 +214,11 @@ Ctrl+W + + + netctl-auto + + diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index e3e5d54..7631fe5 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -20,10 +20,10 @@ #include -#include #include #include "dbusoperation.h" +#include "mainwindow.h" NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap settings) @@ -31,11 +31,12 @@ NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const Q ui(new Ui::NetctlAutoWindow), debug(debugCmd) { + mainWindow = dynamic_cast(parent); useHelper = (settings[QString("USE_HELPER")] == QString("true")); ui->setupUi(this); ui->tableWidget->setColumnHidden(2, true); ui->tableWidget->setColumnHidden(3, true); - netctlCommand = new Netctl(debug, settings); + updateToolBarState(static_cast(settings[QString("NETCTLAUTO_TOOLBAR")].toInt())); createActions(); ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready")); @@ -46,12 +47,18 @@ NetctlAutoWindow::~NetctlAutoWindow() { if (debug) qDebug() << PDEBUG; - delete netctlCommand; - delete ui; } +Qt::ToolBarArea NetctlAutoWindow::getToolBarArea() +{ + if (debug) qDebug() << PDEBUG; + + return toolBarArea(ui->toolBar); +} + + QString NetctlAutoWindow::checkStatus(const bool statusBool, const bool nullFalse) { if (debug) qDebug() << PDEBUG; @@ -98,6 +105,19 @@ void NetctlAutoWindow::showWindow() } +void NetctlAutoWindow::updateToolBarState(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area; + + removeToolBar(ui->toolBar); + if (area != Qt::NoToolBarArea) { + addToolBar(area, ui->toolBar); + ui->toolBar->show(); + } +} + + void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos) { if (debug) qDebug() << PDEBUG; @@ -166,8 +186,8 @@ void NetctlAutoWindow::netctlAutoUpdateTable() } running = responce[0].toBool(); } else { - enabled = netctlCommand->isNetctlAutoEnabled(); - running = netctlCommand->isNetctlAutoRunning(); + enabled = mainWindow->netctlCommand->isNetctlAutoEnabled(); + running = mainWindow->netctlCommand->isNetctlAutoRunning(); } ui->actionDisableAll->setEnabled(running); ui->actionEnableAll->setEnabled(running); @@ -189,7 +209,7 @@ void NetctlAutoWindow::netctlAutoUpdateTable() if (useHelper) profiles = parseOutputNetctl(sendRequestToLib(QString("VerboseProfileList"), debug)); else - profiles = netctlCommand->getProfileListFromNetctlAuto(); + profiles = mainWindow->netctlCommand->getProfileListFromNetctlAuto(); ui->tableWidget->setSortingEnabled(false); ui->tableWidget->selectRow(-1); @@ -267,7 +287,7 @@ void NetctlAutoWindow::netctlAutoDisableAllProfiles() } status = responce[0].toBool(); } else - status = netctlCommand->autoDisableAllProfiles(); + status = mainWindow->netctlCommand->autoDisableAllProfiles(); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -296,7 +316,7 @@ void NetctlAutoWindow::netctlAutoEnableProfile() } status = responce[0].toBool(); } else - status = netctlCommand->autoEnableProfile(profile); + status = mainWindow->netctlCommand->autoEnableProfile(profile); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -321,7 +341,7 @@ void NetctlAutoWindow::netctlAutoEnableAllProfiles() } status = responce[0].toBool(); } else - status = netctlCommand->autoEnableAllProfiles(); + status = mainWindow->netctlCommand->autoEnableAllProfiles(); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -350,7 +370,7 @@ void NetctlAutoWindow::netctlAutoStartProfile() } status = responce[0].toBool(); } else - status = netctlCommand->autoStartProfile(profile); + status = mainWindow->netctlCommand->autoStartProfile(profile); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -374,7 +394,7 @@ void NetctlAutoWindow::netctlAutoEnableService() } status = responce[0].toBool(); } else - status = netctlCommand->autoEnableService(); + status = mainWindow->netctlCommand->autoEnableService(); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -398,7 +418,7 @@ void NetctlAutoWindow::netctlAutoRestartService() } status = responce[0].toBool(); } else - status = netctlCommand->autoRestartService(); + status = mainWindow->netctlCommand->autoRestartService(); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else @@ -422,7 +442,7 @@ void NetctlAutoWindow::netctlAutoStartService() } status = responce[0].toBool(); } else - status = netctlCommand->autoStartService(); + status = mainWindow->netctlCommand->autoStartService(); if (status) ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); else diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index 15ffd77..884aa97 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -22,7 +22,7 @@ #include -class Netctl; +class MainWindow; namespace Ui { class NetctlAutoWindow; @@ -37,9 +37,11 @@ public: const bool debugCmd = false, const QMap settings = QMap()); ~NetctlAutoWindow(); + Qt::ToolBarArea getToolBarArea(); public slots: void showWindow(); + void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea); private slots: // table @@ -59,8 +61,8 @@ private slots: private: // ui Ui::NetctlAutoWindow *ui = nullptr; + MainWindow *mainWindow = nullptr; // backend - Netctl *netctlCommand = nullptr; QString checkStatus(const bool statusBool, const bool nullFalse = false); void createActions(); bool debug = false; diff --git a/sources/gui/src/newprofilewidget.cpp b/sources/gui/src/newprofilewidget.cpp index 19584ac..80e92d2 100644 --- a/sources/gui/src/newprofilewidget.cpp +++ b/sources/gui/src/newprofilewidget.cpp @@ -62,6 +62,14 @@ NewProfileWidget::~NewProfileWidget() } +Qt::ToolBarArea NewProfileWidget::getToolBarArea() +{ + if (debug) qDebug() << PDEBUG; + + return toolBarArea(ui->toolBar); +} + + void NewProfileWidget::profileTabOpenProfileSlot(const QString profile) { if (debug) qDebug() << PDEBUG; @@ -80,6 +88,19 @@ void NewProfileWidget::update() } +void NewProfileWidget::updateToolBarState(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area; + + removeToolBar(ui->toolBar); + if (area != Qt::NoToolBarArea) { + addToolBar(area, ui->toolBar); + ui->toolBar->show(); + } +} + + void NewProfileWidget::updateMenuProfile() { if (debug) qDebug() << PDEBUG; @@ -132,7 +153,7 @@ void NewProfileWidget::profileTabClear() if (useHelper) profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); else - profiles = netctlCommand->getProfileList(); + profiles = mainWindow->netctlCommand->getProfileList(); for (int i=0; icomboBox_profile->addItem(profiles[i].name); ui->comboBox_profile->setCurrentIndex(-1); @@ -322,8 +343,8 @@ void NewProfileWidget::profileTabCreateProfile() status = responce[0].toBool(); } else { - QString profileTempName = netctlProfile->createProfile(profile, settings); - status = netctlProfile->copyProfile(profileTempName); + QString profileTempName = mainWindow->netctlProfile->createProfile(profile, settings); + status = mainWindow->netctlProfile->copyProfile(profileTempName); } mainWindow->showMessage(status); @@ -355,7 +376,7 @@ void NewProfileWidget::profileTabLoadProfile() settings[key] = value; } } else - settings = netctlProfile->getSettingsFromProfile(profile); + settings = mainWindow->netctlProfile->getSettingsFromProfile(profile); if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); @@ -414,7 +435,7 @@ void NewProfileWidget::profileTabRemoveProfile() } status = responce[0].toBool(); } else - status = netctlProfile->removeProfile(profile); + status = mainWindow->netctlProfile->removeProfile(profile); mainWindow->showMessage(status); updateProfileTab(); @@ -442,12 +463,10 @@ void NewProfileWidget::createObjects() { if (debug) qDebug() << PDEBUG; - // backend - netctlCommand = new Netctl(debug, configuration); - netctlProfile = new NetctlProfile(debug, configuration); // windows ui = new Ui::NewProfileWidget; ui->setupUi(this); + updateToolBarState(static_cast(configuration[QString("PROFILE_TOOLBAR")].toInt())); // profile widgets generalWid = new GeneralWidget(this, configuration); ui->scrollAreaWidgetContents->layout()->addWidget(generalWid); @@ -478,9 +497,6 @@ void NewProfileWidget::deleteObjects() { if (debug) qDebug() << PDEBUG; - if (netctlCommand != nullptr) delete netctlCommand; - if (netctlProfile != nullptr) delete netctlProfile; - if (bridgeWid != nullptr) delete bridgeWid; if (ethernetWid != nullptr) delete ethernetWid; if (generalWid != nullptr) delete generalWid; diff --git a/sources/gui/src/newprofilewidget.h b/sources/gui/src/newprofilewidget.h index 9f6617c..e77f881 100644 --- a/sources/gui/src/newprofilewidget.h +++ b/sources/gui/src/newprofilewidget.h @@ -49,10 +49,12 @@ public: const QMap settings = QMap(), const bool debugCmd = false); ~NewProfileWidget(); + Qt::ToolBarArea getToolBarArea(); public slots: void profileTabOpenProfileSlot(const QString profile); void update(); + void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea); private slots: // update slots @@ -81,8 +83,6 @@ private: VlanWidget *vlanWid = nullptr; WirelessWidget *wirelessWid = nullptr; // backend - Netctl *netctlCommand = nullptr; - NetctlProfile *netctlProfile = nullptr; void createActions(); void createObjects(); void deleteObjects(); diff --git a/sources/gui/src/settingswindow.cpp b/sources/gui/src/settingswindow.cpp index 888b5d6..4a4b94e 100644 --- a/sources/gui/src/settingswindow.cpp +++ b/sources/gui/src/settingswindow.cpp @@ -76,6 +76,48 @@ void SettingsWindow::createActions() } +int SettingsWindow::indexByToolBarPosition(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Area" << area; + + switch (area) { + case Qt::LeftToolBarArea: + return 0; + case Qt::RightToolBarArea: + return 1; + case Qt::TopToolBarArea: + return 2; + case Qt::BottomToolBarArea: + return 3; + case Qt::NoToolBarArea: + default: + return 4; + } +} + + +Qt::ToolBarArea SettingsWindow::indexToToolBarPosition(const int index) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Index" << index; + + switch (index) { + case 0: + return Qt::LeftToolBarArea; + case 1: + return Qt::RightToolBarArea; + case 2: + return Qt::TopToolBarArea; + case 3: + return Qt::BottomToolBarArea; + case 4: + default: + return Qt::NoToolBarArea; + } +} + + // ESC press event void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) { @@ -169,6 +211,14 @@ void SettingsWindow::saveSettings() settings.setValue(QString("PREFERED_IFACE"), config[QString("PREFERED_IFACE")]); settings.endGroup(); + settings.beginGroup(QString("Toolbars")); + settings.setValue(QString("MAIN_TOOLBAR"), config[QString("MAIN_TOOLBAR")]); + settings.setValue(QString("NETCTL_TOOLBAR"), config[QString("NETCTL_TOOLBAR")]); + settings.setValue(QString("NETCTLAUTO_TOOLBAR"), config[QString("NETCTLAUTO_TOOLBAR")]); + settings.setValue(QString("PROFILE_TOOLBAR"), config[QString("PROFILE_TOOLBAR")]); + settings.setValue(QString("WIFI_TOOLBAR"), config[QString("WIFI_TOOLBAR")]); + settings.endGroup(); + settings.sync(); } @@ -293,12 +343,16 @@ QMap SettingsWindow::readSettings() config[QString("HELPER_SERVICE")] = ui->lineEdit_helperService->text(); config[QString("IFACE_DIR")] = ui->lineEdit_interfacesDir->text(); config[QString("LANGUAGE")] = ui->comboBox_language->currentText(); + config[QString("MAIN_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_mainToolbar->currentIndex())); config[QString("NETCTL_PATH")] = ui->lineEdit_netctlPath->text(); + config[QString("NETCTL_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_netctlToolbar->currentIndex())); config[QString("NETCTLAUTO_PATH")] = ui->lineEdit_netctlAutoPath->text(); config[QString("NETCTLAUTO_SERVICE")] = ui->lineEdit_netctlAutoService->text(); + config[QString("NETCTLAUTO_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_netctlAutoToolbar->currentIndex())); config[QString("PID_FILE")] = ui->lineEdit_pid->text(); config[QString("PREFERED_IFACE")] = ui->lineEdit_interface->text(); config[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text(); + config[QString("PROFILE_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_profilesToolbar->currentIndex())); config[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text(); if (ui->checkBox_components->checkState() == 2) config[QString("SKIPCOMPONENTS")] = QString("true"); @@ -318,6 +372,7 @@ QMap SettingsWindow::readSettings() config[QString("USE_HELPER")] = QString("true"); else config[QString("USE_HELPER")] = QString("false"); + config[QString("WIFI_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_wifiToolbar->currentIndex())); config[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text(); config[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text(); config[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text(); @@ -352,11 +407,19 @@ void SettingsWindow::setSettings(const QMap config) ui->lineEdit_interfacesDir->setText(config[QString("IFACE_DIR")]); int index = ui->comboBox_language->findText(config[QString("LANGUAGE")]); ui->comboBox_language->setCurrentIndex(index); + index = indexByToolBarPosition(static_cast(config[QString("MAIN_TOOLBAR")].toInt())); + ui->comboBox_mainToolbar->setCurrentIndex(index); ui->lineEdit_netctlPath->setText(config[QString("NETCTL_PATH")]); + index = indexByToolBarPosition(static_cast(config[QString("NETCTL_TOOLBAR")].toInt())); + ui->comboBox_netctlToolbar->setCurrentIndex(index); ui->lineEdit_netctlAutoPath->setText(config[QString("NETCTLAUTO_PATH")]); ui->lineEdit_netctlAutoService->setText(config[QString("NETCTLAUTO_SERVICE")]); + index = indexByToolBarPosition(static_cast(config[QString("NETCTLAUTO_TOOLBAR")].toInt())); + ui->comboBox_netctlAutoToolbar->setCurrentIndex(index); ui->lineEdit_pid->setText(config[QString("PID_FILE")]); ui->lineEdit_interface->setText(config[QString("PREFERED_IFACE")]); + index = indexByToolBarPosition(static_cast(config[QString("PROFILE_TOOLBAR")].toInt())); + ui->comboBox_profilesToolbar->setCurrentIndex(index); ui->lineEdit_profilePath->setText(config[QString("PROFILE_DIR")]); ui->lineEdit_rfkill->setText(config[QString("RFKILL_DIR")]); if (config[QString("SKIPCOMPONENTS")] == QString("true")) @@ -377,6 +440,8 @@ void SettingsWindow::setSettings(const QMap config) ui->checkBox_useHelper->setCheckState(Qt::Checked); else ui->checkBox_useHelper->setCheckState(Qt::Unchecked); + index = indexByToolBarPosition(static_cast(config[QString("WIFI_TOOLBAR")].toInt())); + ui->comboBox_wifiToolbar->setCurrentIndex(index); ui->lineEdit_wpaCliPath->setText(config[QString("WPACLI_PATH")]); ui->lineEdit_wpaSupPath->setText(config[QString("WPASUP_PATH")]); ui->lineEdit_wpaSupDrivers->setText(config[QString("WPA_DRIVERS")]); @@ -447,6 +512,14 @@ QMap SettingsWindow::getSettings(QString fileName) config[QString("PREFERED_IFACE")] = settings.value(QString("PREFERED_IFACE"), QString("")).toString(); settings.endGroup(); + settings.beginGroup(QString("Toolbars")); + config[QString("MAIN_TOOLBAR")] = settings.value(QString("MAIN_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("NETCTL_TOOLBAR")] = settings.value(QString("NETCTL_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("NETCTLAUTO_TOOLBAR")] = settings.value(QString("NETCTLAUTO_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("PROFILE_TOOLBAR")] = settings.value(QString("PROFILE_TOOLBAR"), Qt::TopToolBarArea).toString(); + config[QString("WIFI_TOOLBAR")] = settings.value(QString("WIFI_TOOLBAR"), Qt::TopToolBarArea).toString(); + settings.endGroup(); + for (int i=0; i readSettings(); diff --git a/sources/gui/src/settingswindow.ui b/sources/gui/src/settingswindow.ui index cf3230d..700bc36 100644 --- a/sources/gui/src/settingswindow.ui +++ b/sources/gui/src/settingswindow.ui @@ -37,12 +37,12 @@ 32 - - 0 - false + + true + false @@ -114,6 +114,14 @@ + + + Toolbars + + + + + @@ -314,7 +322,7 @@ true - + 0 @@ -612,8 +620,8 @@ 0 0 - 542 - 330 + 436 + 173 @@ -868,8 +876,8 @@ 0 0 - 542 - 330 + 436 + 45 @@ -953,8 +961,8 @@ 0 0 - 542 - 330 + 239 + 194 @@ -1371,6 +1379,317 @@ + + + + + + true + + + + + 0 + 0 + 542 + 330 + + + + + + + + + + 1 + 0 + + + + Main toolbar + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + + Left + + + + + Right + + + + + Top + + + + + Bottom + + + + + Disabled + + + + + + + + + + + + + 1 + 0 + + + + netctl toolbar + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + + Left + + + + + Right + + + + + Top + + + + + Bottom + + + + + Disabled + + + + + + + + + + + + + 1 + 0 + + + + netctl-auto toolbar + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + + Left + + + + + Right + + + + + Top + + + + + Bottom + + + + + Disabled + + + + + + + + + + + + + 1 + 0 + + + + Profiles toolbar + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + + Left + + + + + Right + + + + + Top + + + + + Bottom + + + + + Disabled + + + + + + + + + + + + + 1 + 0 + + + + WiFi toolbar + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + + Left + + + + + Right + + + + + Top + + + + + Bottom + + + + + Disabled + + + + + + + + + + Qt::Vertical + + + + 20 + 150 + + + + + + + + + + diff --git a/sources/gui/src/wifimenuwidget.cpp b/sources/gui/src/wifimenuwidget.cpp index ac2f3df..3de1c30 100644 --- a/sources/gui/src/wifimenuwidget.cpp +++ b/sources/gui/src/wifimenuwidget.cpp @@ -51,6 +51,14 @@ WiFiMenuWidget::~WiFiMenuWidget() } +Qt::ToolBarArea WiFiMenuWidget::getToolBarArea() +{ + if (debug) qDebug() << PDEBUG; + + return toolBarArea(ui->toolBar); +} + + void WiFiMenuWidget::update() { if (debug) qDebug() << PDEBUG; @@ -60,6 +68,19 @@ void WiFiMenuWidget::update() } +void WiFiMenuWidget::updateToolBarState(const Qt::ToolBarArea area) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area; + + removeToolBar(ui->toolBar); + if (area != Qt::NoToolBarArea) { + addToolBar(area, ui->toolBar); + ui->toolBar->show(); + } +} + + bool WiFiMenuWidget::wifiTabSelectEssidSlot(const QString essid) { if (debug) qDebug() << PDEBUG; @@ -82,11 +103,11 @@ void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) if (useHelper) { QList responce = sendRequestToLib(QString("WirelessInterfaces"), debug); if (responce.isEmpty()) - interfaces = netctlCommand->getWirelessInterfaceList(); + interfaces = mainWindow->netctlCommand->getWirelessInterfaceList(); else interfaces = responce[0].toStringList(); } else - interfaces = netctlCommand->getWirelessInterfaceList(); + interfaces = mainWindow->netctlCommand->getWirelessInterfaceList(); if (interfaces.isEmpty()) return; QMap settings; @@ -118,8 +139,8 @@ void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) args.append(settingsList); sendRequestToCtrlWithArgs(QString("Create"), args, debug); } else { - QString profileTempName = netctlProfile->createProfile(profile, settings); - netctlProfile->copyProfile(profileTempName); + QString profileTempName = mainWindow->netctlProfile->createProfile(profile, settings); + mainWindow->netctlProfile->copyProfile(profileTempName); } QString message; if (mainWindow->startProfileSlot(profile)) { @@ -143,7 +164,7 @@ void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) args.append(profile); sendRequestToCtrlWithArgs(QString("Remove"), args, debug); } else - netctlProfile->removeProfile(profile); + mainWindow->netctlProfile->removeProfile(profile); break; } @@ -178,6 +199,32 @@ void WiFiMenuWidget::updateMenuWifi() } +void WiFiMenuWidget::updateText() +{ + if (debug) qDebug() << PDEBUG; + wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug)); + if (!checkExternalApps(QString("wpasup"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + 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")); + + ui->label_wifi->setText(text); +} + + void WiFiMenuWidget::updateWifiTab() { if (debug) qDebug() << PDEBUG; @@ -193,7 +240,7 @@ void WiFiMenuWidget::updateWifiTab() if (useHelper) scanResults = parseOutputWifi(sendRequestToCtrl(QString("VerboseWiFi"), debug)); else - scanResults = wpaCommand->scanWifi(); + scanResults = mainWindow->wpaCommand->scanWifi(); ui->tableWidget_wifi->setSortingEnabled(false); ui->tableWidget_wifi->selectRow(-1); @@ -288,6 +335,7 @@ void WiFiMenuWidget::updateWifiTab() ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); #endif + updateText(); mainWindow->setDisabled(false); mainWindow->showMessage(true); } @@ -333,7 +381,7 @@ void WiFiMenuWidget::wifiTabSetEnabled(const bool state) if (debug) qDebug() << PDEBUG << ":" << "State" << state; ui->tableWidget_wifi->setHidden(!state); - ui->label_wifi->setHidden(state); + if (!state) ui->label_wifi->setText(QApplication::translate("WiFiMenuWidget", "Please install 'wpa_supplicant' before using it")); } @@ -379,7 +427,7 @@ void WiFiMenuWidget::wifiTabStart() } profileName = responce[0].toString(); } else - profileName = wpaCommand->existentProfile(profile); + profileName = mainWindow->wpaCommand->existentProfile(profile); mainWindow->showMessage(mainWindow->startProfileSlot(profileName)); } else { QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); @@ -421,15 +469,12 @@ void WiFiMenuWidget::createObjects() { if (debug) qDebug() << PDEBUG; - // backend - netctlCommand = new Netctl(debug, configuration); - netctlProfile = new NetctlProfile(debug, configuration); - wpaCommand = new WpaSup(debug, configuration); // windows ui = new Ui::WiFiMenuWidget; ui->setupUi(this); ui->tableWidget_wifi->setColumnHidden(5, true); ui->tableWidget_wifi->setColumnHidden(6, true); + updateToolBarState(static_cast(configuration[QString("WIFI_TOOLBAR")].toInt())); } @@ -437,9 +482,5 @@ void WiFiMenuWidget::deleteObjects() { if (debug) qDebug() << PDEBUG; - if (netctlCommand != nullptr) delete netctlCommand; - if (netctlProfile != nullptr) delete netctlProfile; - if (wpaCommand != nullptr) delete wpaCommand; - if (ui != nullptr) delete ui; } diff --git a/sources/gui/src/wifimenuwidget.h b/sources/gui/src/wifimenuwidget.h index 7f08e69..d0992a9 100644 --- a/sources/gui/src/wifimenuwidget.h +++ b/sources/gui/src/wifimenuwidget.h @@ -40,9 +40,11 @@ public: const QMap settings = QMap(), const bool debugCmd = false); ~WiFiMenuWidget(); + Qt::ToolBarArea getToolBarArea(); public slots: void update(); + void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea); bool wifiTabSelectEssidSlot(const QString essid); // wifi tab slots void connectToUnknownEssid(const QString passwd); @@ -51,6 +53,7 @@ public slots: private slots: // update slots void updateMenuWifi(); + void updateText(); void updateWifiTab(); // wifi tab slots void wifiTabContextualMenu(const QPoint &pos); @@ -63,9 +66,6 @@ private: Ui::WiFiMenuWidget *ui = nullptr; PasswdWidget *passwdWid = nullptr; // backend - Netctl *netctlCommand = nullptr; - NetctlProfile *netctlProfile = nullptr; - WpaSup *wpaCommand = nullptr; void createActions(); void createObjects(); void deleteObjects(); diff --git a/sources/helper/src/controladaptor.cpp b/sources/helper/src/controladaptor.cpp index 68762af..4f63dc9 100644 --- a/sources/helper/src/controladaptor.cpp +++ b/sources/helper/src/controladaptor.cpp @@ -271,7 +271,9 @@ QString ControlAdaptor::CurrentWiFi() QStringList ControlAdaptor::VerboseWiFi() { - QList wifiPoints = wpaCommand->scanWifi(); + QList wifiPoints; + wifiPoints.append(wpaCommand->current()); + wifiPoints.append(wpaCommand->scanWifi()); QStringList info; for (int i=0; i +#include +#include + + +class Netctl; +class NetctlProfile; +class WpaSup; + +/** + * @enum InterfaceAnswer + * @brief standard interface answer enumeration + * @var InterfaceAnswer::False + * false + * @var InterfaceAnswer::True + * true + * @var InterfaceAnswer::Error + * an error occurs + */ +enum InterfaceAnswer { + False = 0, + True, + Error +}; + +/** + * @brief The NetctlInterface class provides complex methods to get access to library + */ +class NetctlInterface : public QObject +{ + Q_OBJECT + +public: + /** + * @brief NetctlInterface class constructor + * @param debugCmd show debug messages + * @param settings default settings. See required keys in other modules + */ + explicit NetctlInterface(const bool debugCmd = false, + const QMap settings = QMap()); + /** + * @brief NetctlInterface class destructor + */ + ~NetctlInterface(); + /** + * @brief method which enables or disables selected profile and returns its status + * @remark netctl-auto only + * @param profile profile name + * @return InterfaceAnswer::False if profile is disabled + * @return InterfaceAnswer::True if profile is enabled + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer autoEnableProfile(const QString profile); + /** + * @brief method which creates and copies profile + * @remark netctl independ + * @param profile profile name + * @param settings profile settings + * @return InterfaceAnswer::False if profile cannot be created + * @return InterfaceAnswer::True if profile is created + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer createProfile(const QString profile, const QMap settings); + /** + * @brief method which connects to ESSID + * @remark netctl independ + * @param essid point ESSID + * @param settings profile settings (Security, ESSID, Key and Hidden are required) + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer connectToEssid(const QString essid, QMap settings); + /** + * @brief method which connects to existent profile by ESSID + * @remark netctl independ + * @param essid point ESSID + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer connectToKnownEssid(const QString essid); + /** + * @brief method which creates wireless profile and connects to it + * @remark netctl independ + * @param essid point ESSID + * @param settings profile settings (Security, ESSID, Key and Hidden are required) + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer connectToUnknownEssid(const QString essid, QMap settings); + /** + * @brief method which enables or disables selected profile and returns its status + * @remark netctl only + * @param profile profile name + * @return InterfaceAnswer::False if profile is disabled + * @return InterfaceAnswer::True if profile is enabled + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer enableProfile(const QString profile); + /** + * @brief method which restarts selected profile and returns its status + * @remark netctl only + * @param profile profile name + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer restartProfile(const QString profile); + /** + * @brief method which starts/stops or switchs to selected profile and returns its status + * @remark netctl only + * @param profile profile name + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer startProfile(const QString profile); + /** + * @brief method which switchs to selected profile and returns its status + * @remark both netctl and netctl-auto + * @param profile profile name + * @return InterfaceAnswer::False if profile is inactive + * @return InterfaceAnswer::True if profile is active + * @return InterfaceAnswer::Error if an error occurs + */ + InterfaceAnswer switchToProfile(const QString profile); + +private: + /** + * @brief Netctl class + */ + Netctl *netctlCommand = nullptr; + /** + * @brief NetctlProfile class + */ + NetctlProfile *netctlProfile = nullptr; + /** + * @brief WpaSup class + */ + WpaSup *wpaCommand = nullptr; + /** + * @brief show debug messages + */ + bool debug = false; +}; + + +#endif /* NETCTLINTERFACE_H */ diff --git a/sources/netctlgui/include/netctlgui/wpasupinteract.h b/sources/netctlgui/include/netctlgui/wpasupinteract.h index 1b7e05f..0b58e26 100644 --- a/sources/netctlgui/include/netctlgui/wpasupinteract.h +++ b/sources/netctlgui/include/netctlgui/wpasupinteract.h @@ -79,7 +79,7 @@ typedef struct QStringList macs; QString name; QString security; - int signal; + int signal = 0; PointType type = PointType::None; bool active = false; bool exists = false; @@ -137,7 +137,7 @@ public: * @return false if profile does not exist * @return true if profile exists */ - bool isProfileExists(const QString essid); + Q_DECL_DEPRECATED bool isProfileExists(const QString essid); public slots: // functions diff --git a/sources/netctlgui/src/netctlinterface.cpp b/sources/netctlgui/src/netctlinterface.cpp new file mode 100644 index 0000000..db62595 --- /dev/null +++ b/sources/netctlgui/src/netctlinterface.cpp @@ -0,0 +1,250 @@ +/*************************************************************************** + * 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/ * + ***************************************************************************/ +/** + * @file netctlinterface.cpp + * Source code of netctlgui library + * @author Evgeniy Alekseev + * @copyright GPLv3 + * @bug https://github.com/arcan1s/netctl-gui/issues + */ + + +#include + +#include +#include + + +/** + * @class NetctlInterface + */ +/** + * @fn NetctlInterface + */ +NetctlInterface::NetctlInterface(const bool debugCmd, const QMap settings) + : debug(debugCmd) +{ + netctlCommand = new Netctl(debug, settings); + netctlProfile = new NetctlProfile(debug, settings); + wpaCommand = new WpaSup(debug, settings); +} + + +/** + * @fn ~NetctlInterface + */ +NetctlInterface::~NetctlInterface() +{ + if (debug) qDebug() << PDEBUG; + + if (netctlCommand != nullptr) delete netctlCommand; + if (netctlProfile != nullptr) delete netctlProfile; + if (wpaCommand != nullptr) delete wpaCommand; +} + + +/** + * @fn autoEnableProfile + */ +InterfaceAnswer NetctlInterface::autoEnableProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + netctlCommand->autoEnableProfile(profile); + + return static_cast(netctlCommand->autoIsProfileEnabled(profile)); +} + + +/** + * @fn connectToEssid + */ +InterfaceAnswer NetctlInterface::connectToEssid(const QString essid, QMap settings) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + if (wpaCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + if (wpaCommand->existentProfile(essid).isEmpty()) + return connectToUnknownEssid(essid, settings); + else + return connectToKnownEssid(essid); +} + + +/** + * @fn connectToKnownEssid + */ +InterfaceAnswer NetctlInterface::connectToKnownEssid(const QString essid) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + if (wpaCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + QString profile = wpaCommand->existentProfile(essid); + if (profile.isEmpty()) return InterfaceAnswer::Error; + + return startProfile(profile); +} + + +/** + * @fn connectToUnknownEssid + */ +InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid, QMap settings) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + if (wpaCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + // append settings + QStringList interfaces = netctlCommand->getWirelessInterfaceList(); + if (interfaces.isEmpty()) return InterfaceAnswer::Error; + settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); + settings[QString("Interface")] = interfaces[0]; + settings[QString("Connection")] = QString("wireless"); + settings[QString("ESSID")] = QString("'%1'").arg(essid); + settings[QString("IP")] = QString("dhcp"); + + // save profile + QString profile = QString("netctl-gui-%1").arg(essid); + profile.remove(QChar('"')).remove(QChar('\'')); + if (createProfile(profile, settings) != InterfaceAnswer::True) return InterfaceAnswer::Error; + + // start it + return startProfile(profile); +} + + +/** + * @fn createProfile + */ +InterfaceAnswer NetctlInterface::createProfile(const QString profile, const QMap settings) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + QString profileTempName = netctlProfile->createProfile(profile, settings); + if (profileTempName.isEmpty()) return InterfaceAnswer::Error; + + return static_cast(netctlProfile->copyProfile(profileTempName)); +} + + +/** + * @fn enableProfile + */ +InterfaceAnswer NetctlInterface::enableProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + netctlCommand->enableProfile(profile); + + return static_cast(netctlCommand->isProfileEnabled(profile)); +} + + +/** + * @fn restartProfile + */ +InterfaceAnswer NetctlInterface::restartProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + netctlCommand->restartProfile(profile); + + return static_cast(netctlCommand->isProfileActive(profile)); +} + + +/** + * @fn startProfile + */ +InterfaceAnswer NetctlInterface::startProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + QStringList current = netctlCommand->getActiveProfile(); + if ((current.isEmpty()) || (current.contains(profile))) + netctlCommand->startProfile(profile); + else + netctlCommand->switchToProfile(profile); + + return static_cast(netctlCommand->isProfileActive(profile)); +} + + +/** + * @fn switchToProfile + */ +InterfaceAnswer NetctlInterface::switchToProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (netctlCommand == nullptr) { + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; + return InterfaceAnswer::Error; + } + + InterfaceAnswer status = InterfaceAnswer::Error; + bool netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); + if (netctlAutoStatus) { + netctlCommand->autoStartProfile(profile); + status = static_cast(netctlCommand->autoIsProfileActive(profile)); + } else { + netctlCommand->switchToProfile(profile); + status = static_cast(netctlCommand->isProfileActive(profile)); + } + + return status; +} diff --git a/sources/netctlgui/src/wpasupinteract.cpp b/sources/netctlgui/src/wpasupinteract.cpp index fc204dd..bca5874 100644 --- a/sources/netctlgui/src/wpasupinteract.cpp +++ b/sources/netctlgui/src/wpasupinteract.cpp @@ -96,9 +96,11 @@ QString WpaSup::existentProfile(const QString essid) QString profileFile = QString(""); QList profileList = netctlCommand->getProfileList(); - for (int i=0; igetValueFromProfile(profileList[i].name, QString("ESSID"))) - profileFile = profileList[i].name; + for (int i=0; i profileList = netctlCommand->getProfileList(); - for (int i=0; igetValueFromProfile(profileList[i].name, QString("ESSID"))) { - profileFile = profileList[i].name; - break; - } + for (int i=0; iisProfileActive(profileFile); } @@ -241,11 +243,11 @@ bool WpaSup::isProfileExists(const QString essid) bool exists = false; QList profileList = netctlCommand->getProfileList(); - for (int i=0; igetValueFromProfile(profileList[i].name, QString("ESSID"))) { - exists = true; - break; - } + for (int i=0; i profiles = netctlCommand->getProfileList(); - for (int j=0; j