diff --git a/CHANGELOG b/CHANGELOG index a484197..c0c8115 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,10 @@ Ver.1.2.0: + [gui] added ability to remove profile + [gui] added support of hidden wifi network + [gui] added contextual menu to tables ++ [gui] added actions menu ++ [lib] detached backend from frontend * [all] small changes in the project architecture +* [gui] more debug information * [plasmoid] edited configuration interface Ver.1.1.0 (netctl-1.7 update): diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 9cd01a4..73eb2c8 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -17,8 +17,12 @@ message (STATUS "Version: ${PROJECT_VERSION}") # install options option (USE_QT5 "Use Qt5 instead of Qt4" ON) option (BUILD_GUI "Build GUI" ON) +option (BUILD_LIBRARY "Build library" ON) option (BUILD_DATAENGINE "Build data engine" ON) option (BUILD_PLASMOID "Build plasmoid" ON) +if (BUILD_GUI) + set (BUILD_LIBRARY ON) +endif () if (BUILD_PLASMOID) set (BUILD_DATAENGINE ON) endif () @@ -34,10 +38,14 @@ else () endif () # resources +set (PROJECT_LIBRARY netctlgui) set (PROJECT_RESOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources) add_subdirectory (${PROJECT_RESOURCE_DIR}) # components +if (BUILD_LIBRARY) + add_subdirectory (${PROJECT_LIBRARY}) +endif() if (BUILD_GUI) add_subdirectory (gui) endif () diff --git a/sources/gui/src/CMakeLists.txt b/sources/gui/src/CMakeLists.txt index bcf1709..7074ee1 100644 --- a/sources/gui/src/CMakeLists.txt +++ b/sources/gui/src/CMakeLists.txt @@ -11,7 +11,12 @@ message (STATUS "${SUBPROJECT} Headers: ${HEADERS}") message (STATUS "${SUBPROJECT} Forms: ${FORMS}") # include_path -include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/include/ + ${CMAKE_CURRENT_BINARY_DIR}/../ + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}) +link_directories (${PROJECT_LIBRARY}/src/lib) if (USE_QT5) find_package(Qt5Core REQUIRED) @@ -41,7 +46,7 @@ if (USE_QT5) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) - target_link_libraries (${SUBPROJECT} ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES}) + target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES}) else () find_package (Qt4 REQUIRED) include (${QT_USE_FILE}) @@ -65,7 +70,7 @@ else () source_group ("Generated Files" FILES ${MOC_SOURCES}) add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) - target_link_libraries (${SUBPROJECT} ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}) + target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}) endif() # install properties diff --git a/sources/gui/src/errorwindow.cpp b/sources/gui/src/errorwindow.cpp index a015d2a..66d6332 100644 --- a/sources/gui/src/errorwindow.cpp +++ b/sources/gui/src/errorwindow.cpp @@ -26,18 +26,23 @@ ErrorWindow::ErrorWindow(QWidget *parent, const bool debugCmd, const int message debug(debugCmd), ui(new Ui::ErrorWindow) { - ui->setupUi(this); if (debug) qDebug() << "[ErrorWindow]" << "[ErrorWindow]" << ":" << "Initializate with error code" << messageNumber; + + ui->setupUi(this); setMessage(messageNumber); } ErrorWindow::~ErrorWindow() { + if (debug) qDebug() << "[ErrorWindow]" << "[~ErrorWindow]"; + delete ui; } void ErrorWindow::setMessage(const int mess) { + if (debug) qDebug() << "[ErrorWindow]" << "[setMessage]"; + QString message; switch(mess) { case 1: diff --git a/sources/gui/src/language.cpp b/sources/gui/src/language.cpp index 20291e1..752ff54 100644 --- a/sources/gui/src/language.cpp +++ b/sources/gui/src/language.cpp @@ -27,6 +27,19 @@ Language::Language(const QString configPath) } +QString Language::checkLanguage(const QString language, const QString defaultLanguage) +{ + QStringList availableLanguages = getAvailableLanguages(); + for (int i=0; i -class Language +class Language : public QObject { + Q_OBJECT + public: explicit Language(const QString configPath); + static QString checkLanguage(const QString language, + const QString defaultLanguage = QString("en")); static QString defineLanguage(const QString configPath); static QString defineLanguageFromFile(const QString configPath); static QString defineLanguageFromLocale(); - -private: - static QString checkLanguage(const QString language, - const QString defaultLanguage = QString("en")); static QStringList getAvailableLanguages(); }; diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 1d131cd..f1bea5f 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -23,6 +23,10 @@ #include #include +#include +#include +#include + #include "bridgewidget.h" #include "errorwindow.h" #include "ethernetwidget.h" @@ -30,15 +34,12 @@ #include "ipwidget.h" #include "macvlanwidget.h" #include "mobilewidget.h" -#include "netctlinteract.h" -#include "netctlprofile.h" #include "passwdwidget.h" #include "pppoewidget.h" #include "settingswindow.h" #include "tunnelwidget.h" #include "tuntapwidget.h" #include "vlanwidget.h" -#include "wpasupinteract.h" #include "wirelesswidget.h" @@ -85,9 +86,9 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool d wirelessWid = new WirelessWidget(this, configuration); ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid); // backend - netctlCommand = new Netctl(this, debug, configuration); - netctlProfile = new NetctlProfile(this, debug, configuration); - wpaCommand = new WpaSup(this, debug, configuration); + netctlCommand = new Netctl(debug, configuration); + netctlProfile = new NetctlProfile(debug, configuration); + wpaCommand = new WpaSup(debug, configuration); createActions(); setIconsToButtons(); @@ -98,6 +99,8 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool d MainWindow::~MainWindow() { + if (debug) qDebug() << "[MainWindow]" << "[~MainWindow]"; + delete netctlCommand; delete netctlProfile; delete wpaCommand; @@ -121,6 +124,8 @@ MainWindow::~MainWindow() bool MainWindow::checkExternalApps(const QString apps = QString("all")) { + if (debug) qDebug() << "[MainWindow]" << "[checkExternalApps]"; + QStringList commandLine; commandLine.append("which"); commandLine.append(configuration[QString("SUDO_PATH")]); @@ -145,6 +150,10 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all")) bool MainWindow::checkState(const QString state, const QString item) { + if (debug) qDebug() << "[MainWindow]" << "[checkState]"; + if (debug) qDebug() << "[MainWindow]" << "[checkState]" << ":" << "Text" << item; + if (debug) qDebug() << "[MainWindow]" << "[checkState]" << ":" << "State" << state; + if (item.contains(state)) return true; else @@ -155,14 +164,29 @@ bool MainWindow::checkState(const QString state, const QString item) // window signals void MainWindow::createActions() { + if (debug) qDebug() << "[MainWindow]" << "[createActions]"; + connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int))); connect(ui->actionSettings, SIGNAL(triggered(bool)), settingsWin, SLOT(showWindow())); connect(ui->actionQuit, SIGNAL(triggered(bool)), this, SLOT(close())); + // actions menu + connect(ui->menuActions, SIGNAL(aboutToShow()), this, SLOT(updateMenu())); + connect(ui->actionMainEdit, SIGNAL(triggered(bool)), this, SLOT(mainTabEditProfile())); + connect(ui->actionMainEnable, SIGNAL(triggered(bool)), this, SLOT(mainTabEnableProfile())); + connect(ui->actionMainRefresh, SIGNAL(triggered(bool)), this, SLOT(updateMainTab())); + connect(ui->actionMainRemove, SIGNAL(triggered(bool)), this, SLOT(mainTabRemoveProfile())); + connect(ui->actionMainRestart, SIGNAL(triggered(bool)), this, SLOT(mainTabRestartProfile())); + connect(ui->actionMainStart, SIGNAL(triggered(bool)), this, SLOT(mainTabStartProfile())); + connect(ui->actionProfileClear, SIGNAL(triggered(bool)), this, SLOT(profileTabClear())); + connect(ui->actionProfileLoad, SIGNAL(triggered(bool)), this, SLOT(profileTabLoadProfile())); + connect(ui->actionProfileRemove, SIGNAL(triggered(bool)), this, SLOT(profileTabRemoveProfile())); + connect(ui->actionProfileSave, SIGNAL(triggered(bool)), this, SLOT(profileTabCreateProfile())); + connect(ui->actionWifiRefresh, SIGNAL(triggered(bool)), this, SLOT(updateWifiTab())); + connect(ui->actionWifiStart, SIGNAL(triggered(bool)), this, SLOT(wifiTabStart())); + // main tab events connect(ui->pushButton_mainRefresh, SIGNAL(clicked(bool)), this, SLOT(updateMainTab())); - connect(ui->pushButton_mainRemove, SIGNAL(clicked(bool)), this, SLOT(mainTabRemoveProfile())); - connect(ui->pushButton_mainEnable, SIGNAL(clicked(bool)), this, SLOT(mainTabEnableProfile())); connect(ui->pushButton_mainRestart, SIGNAL(clicked(bool)), this, SLOT(mainTabRestartProfile())); connect(ui->pushButton_mainStart, SIGNAL(clicked(bool)), this, SLOT(mainTabStartProfile())); connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); @@ -188,6 +212,8 @@ void MainWindow::createActions() void MainWindow::setIconsToButtons() { + if (debug) qDebug() << "[MainWindow]" << "[setIconsToButtons]"; + // tab widget ui->tabWidget->setTabIcon(0, QIcon(":icon")); ui->tabWidget->setTabIcon(1, QIcon::fromTheme("document-new")); @@ -195,7 +221,6 @@ void MainWindow::setIconsToButtons() // main tab ui->pushButton_mainRefresh->setIcon(QIcon::fromTheme("stock-refresh")); - ui->pushButton_mainRemove->setIcon(QIcon::fromTheme("edit-delete")); ui->pushButton_mainRestart->setIcon(QIcon::fromTheme("stock-refresh")); // profile tab @@ -206,13 +231,38 @@ void MainWindow::setIconsToButtons() // wifi tab ui->pushButton_wifiRefresh->setIcon(QIcon::fromTheme("stock-refresh")); -// ui->pushButton_wifiStart->setIcon(QIcon("")); } // window slots +void MainWindow::setMenuActionsShown(const bool state) +{ + if (debug) qDebug() << "[MainWindow]" << "[setMenuActionsShown]"; + if (debug) qDebug() << "[MainWindow]" << "[setMenuActionsShown]" << ":" << "State" << state; + + // main + ui->actionMainEdit->setVisible(state); + ui->actionMainEnable->setVisible(state); + ui->actionMainRefresh->setVisible(state); + ui->actionMainRemove->setVisible(state); + ui->actionMainRestart->setVisible(state); + ui->actionMainStart->setVisible(state); + // profile + ui->actionProfileClear->setVisible(state); + ui->actionProfileLoad->setVisible(state); + ui->actionProfileRemove->setVisible(state); + ui->actionProfileSave->setVisible(state); + // wifi + ui->actionWifiRefresh->setVisible(state); + ui->actionWifiStart->setVisible(state); +} + + void MainWindow::updateTabs(const int tab) { + if (debug) qDebug() << "[MainWindow]" << "[updateTabs]"; + if (debug) qDebug() << "[MainWindow]" << "[updateTabs]" << ":" << "Update tab" << tab; + if (tab == 0) updateMainTab(); else if (tab == 1) @@ -222,15 +272,32 @@ void MainWindow::updateTabs(const int tab) } +void MainWindow::updateMenu() +{ + if (debug) qDebug() << "[MainWindow]" << "[updateMenu]"; + + setMenuActionsShown(false); + int tab = ui->tabWidget->currentIndex(); + if (debug) qDebug() << "[MainWindow]" << "[updateMenu]" << ":" << "Current tab" << tab; + if (tab == 0) + updateMenuMain(); + else if (tab == 1) + updateMenuProfile(); + else if (tab == 2) + updateMenuWifi(); +} + + void MainWindow::updateMainTab() { + if (debug) qDebug() << "[MainWindow]" << "[updateMainTab]"; + if (!checkExternalApps(QString("netctl"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); return; } - if (debug) qDebug() << "[MainWindow]" << "[updateMainTab]"; ui->tabWidget->setDisabled(true); QList profiles = netctlCommand->getProfileList();; @@ -270,9 +337,39 @@ void MainWindow::updateMainTab() } +void MainWindow::updateMenuMain() +{ + if (debug) qDebug() << "[MainWindow]" << "[updateMenuMain]"; + + ui->actionMainRefresh->setVisible(true); + if (ui->tableWidget_main->currentItem() == 0) + return; + QString item = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text(); + if (!checkState(QString("inactive"), item)) { + ui->actionMainRestart->setVisible(true); + ui->actionMainStart->setText(QApplication::translate("MainWindow", "Stop profile")); + ui->actionMainStart->setIcon(QIcon::fromTheme("dialog-close")); + } + else { + ui->actionMainRestart->setVisible(false); + ui->actionMainStart->setText(QApplication::translate("MainWindow", "Start profile")); + ui->actionMainStart->setIcon(QIcon::fromTheme("dialog-apply")); + } + ui->actionMainStart->setVisible(true); + if (checkState(QString("enabled"), item)) + ui->actionMainEnable->setText(QApplication::translate("MainWindow", "Disable profile")); + else + ui->actionMainEnable->setText(QApplication::translate("MainWindow", "Enable profile")); + ui->actionMainEnable->setVisible(true); + ui->actionMainEdit->setVisible(true); + ui->actionMainRemove->setVisible(true); +} + + void MainWindow::updateProfileTab() { if (debug) qDebug() << "[MainWindow]" << "[updateProfileTab]"; + ui->tabWidget->setDisabled(true); profileTabClear(); ui->tabWidget->setEnabled(true); @@ -282,8 +379,28 @@ void MainWindow::updateProfileTab() } +void MainWindow::updateMenuProfile() +{ + if (debug) qDebug() << "[MainWindow]" << "[updateMenuProfile]"; + + ui->actionProfileClear->setVisible(true); + if (ui->lineEdit_profile->text().isEmpty()) { + ui->actionProfileLoad->setVisible(false); + ui->actionProfileRemove->setVisible(false); + ui->actionProfileSave->setVisible(false); + } + else { + ui->actionProfileLoad->setVisible(true); + ui->actionProfileRemove->setVisible(true); + ui->actionProfileSave->setVisible(true); + } +} + + void MainWindow::updateWifiTab() { + if (debug) qDebug() << "[MainWindow]" << "[updateWifiTab]"; + wifiTabSetEnabled(checkExternalApps(QString("wpasup"))); if (!checkExternalApps(QString("wpasup"))) { errorWin = new ErrorWindow(this, debug, 1); @@ -293,7 +410,6 @@ void MainWindow::updateWifiTab() QList scanResults = wpaCommand->scanWifi(); - if (debug) qDebug() << "[MainWindow]" << "[updateWifiTab]"; ui->tabWidget->setDisabled(true); ui->tableWidget_wifi->setSortingEnabled(false); ui->tableWidget_wifi->selectRow(-1); @@ -334,11 +450,40 @@ void MainWindow::updateWifiTab() } +void MainWindow::updateMenuWifi() +{ + if (debug) qDebug() << "[MainWindow]" << "[updateMenuWifi]"; + + ui->actionWifiRefresh->setVisible(true); + if (ui->tableWidget_wifi->currentItem() == 0) + return; + QString item = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); + if (checkState(QString("exists"), item)) { + if (!checkState(QString("inactive"), item)) { + ui->actionWifiStart->setText(QApplication::translate("MainWindow", "Stop WiFi")); + ui->actionWifiStart->setIcon(QIcon::fromTheme("dialog-close")); + } + else { + ui->actionWifiStart->setText(QApplication::translate("MainWindow", "Start WiFi")); + ui->actionWifiStart->setIcon(QIcon::fromTheme("dialog-apply")); + } + } + else { + ui->actionWifiStart->setText(QApplication::translate("MainWindow", "Start WiFi")); + ui->actionWifiStart->setIcon(QIcon::fromTheme("dialog-apply")); + } + ui->actionWifiStart->setVisible(true); +} + + // main tab slots void MainWindow::mainTabContextualMenu(const QPoint &pos) { if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]"; + if (ui->tableWidget_main->currentItem() == 0) + return; + // create menu QMenu menu(this); QAction *refreshTable = menu.addAction(QApplication::translate("MainWindow", "Refresh")); @@ -349,6 +494,8 @@ void MainWindow::mainTabContextualMenu(const QPoint &pos) restartProfile->setIcon(QIcon::fromTheme("stock-refresh")); QAction *enableProfile = menu.addAction(QApplication::translate("MainWindow", "Enable profile")); menu.addSeparator(); + QAction *editProfile = menu.addAction(QApplication::translate("MainWindow", "Edit profile")); + editProfile->setIcon(QIcon::fromTheme("edit")); QAction *removeProfile = menu.addAction(QApplication::translate("MainWindow", "Remove profile")); removeProfile->setIcon(QIcon::fromTheme("edit-delete")); @@ -387,6 +534,10 @@ void MainWindow::mainTabContextualMenu(const QPoint &pos) if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Enable profile"; mainTabEnableProfile(); } + else if (action == editProfile) { + if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Edit profile"; + mainTabEditProfile(); + } else if (action == removeProfile) { if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Remove profile"; mainTabRemoveProfile(); @@ -394,9 +545,23 @@ void MainWindow::mainTabContextualMenu(const QPoint &pos) } +void MainWindow::mainTabEditProfile() +{ + if (debug) qDebug() << "[MainWindow]" << "[mainTabEditProfile]"; + + ui->tabWidget->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + ui->tabWidget->setCurrentIndex(1); + ui->lineEdit_profile->setText(profile); + + profileTabLoadProfile(); +} + + void MainWindow::mainTabRemoveProfile() { if (debug) qDebug() << "[MainWindow]" << "[mainTabRemoveProfile]"; + ui->tabWidget->setDisabled(true); // call netctlprofile QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); @@ -411,6 +576,8 @@ void MainWindow::mainTabRemoveProfile() void MainWindow::mainTabEnableProfile() { + if (debug) qDebug() << "[MainWindow]" << "[mainTabEnableProfile]"; + if (!checkExternalApps(QString("netctl"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); @@ -419,7 +586,6 @@ void MainWindow::mainTabEnableProfile() if (ui->tableWidget_main->currentItem() == 0) return; - if (debug) qDebug() << "[MainWindow]" << "[mainTabEnableProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->enableProfile(profile); @@ -436,12 +602,15 @@ void MainWindow::mainTabEnableProfile() else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); } + updateMainTab(); } void MainWindow::mainTabRestartProfile() { + if (debug) qDebug() << "[MainWindow]" << "[mainTabRestartProfile]"; + if (!checkExternalApps(QString("netctl"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); @@ -450,7 +619,6 @@ void MainWindow::mainTabRestartProfile() if (ui->tableWidget_main->currentItem() == 0) return; - if (debug) qDebug() << "[MainWindow]" << "[mainTabRestartProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->restartProfile(profile); @@ -458,12 +626,15 @@ void MainWindow::mainTabRestartProfile() ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); + updateMainTab(); } void MainWindow::mainTabStartProfile() { + if (debug) qDebug() << "[MainWindow]" << "[mainTabStartProfile]"; + if (!checkExternalApps(QString("netctl"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); @@ -472,7 +643,6 @@ void MainWindow::mainTabStartProfile() if (ui->tableWidget_main->currentItem() == 0) return; - if (debug) qDebug() << "[MainWindow]" << "[mainTabStartProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->startProfile(profile); @@ -489,6 +659,7 @@ void MainWindow::mainTabStartProfile() else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); } + updateMainTab(); } @@ -496,20 +667,19 @@ void MainWindow::mainTabStartProfile() void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); + if (debug) qDebug() << "[MainWindow]" << "[mainTabRefreshButtons]"; + if (!checkExternalApps(QString("netctl"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); return; } if (current == 0) { - ui->pushButton_mainEnable->setDisabled(true); ui->pushButton_mainRestart->setDisabled(true); ui->pushButton_mainStart->setDisabled(true); return; } - if (debug) qDebug() << "[MainWindow]" << "[mainTabRefreshButtons]"; - ui->pushButton_mainEnable->setEnabled(true); ui->pushButton_mainStart->setEnabled(true); QString item = ui->tableWidget_main->item(current->row(), 2)->text(); @@ -523,10 +693,6 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt ui->pushButton_mainStart->setText(QApplication::translate("MainWindow", "Start")); ui->pushButton_mainStart->setIcon(QIcon::fromTheme("dialog-apply")); } - if (checkState(QString("enabled"), item)) - ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Disable")); - else - ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Enable")); } @@ -534,6 +700,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt void MainWindow::profileTabBrowseProfile() { if (debug) qDebug() << "[MainWindow]" << "[profileTabBrowseProfile]"; + QString filename = QFileDialog::getSaveFileName( this, QApplication::translate("MainWindow", "Save profile as..."), @@ -547,6 +714,8 @@ void MainWindow::profileTabBrowseProfile() void MainWindow::profileTabChangeState(const QString current) { if (debug) qDebug() << "[MainWindow]" << "[profileTabChangeState]"; + if (debug) qDebug() << "[MainWindow]" << "[profileTabChangeState]" << ":" << "Current type" << current; + if (current == QString("ethernet")) { generalWid->setShown(true); ipWid->setShown(true); @@ -684,6 +853,7 @@ void MainWindow::profileTabChangeState(const QString current) void MainWindow::profileTabClear() { if (debug) qDebug() << "[MainWindow]" << "[profileTabClear]"; + ui->lineEdit_profile->clear(); generalWid->clear(); @@ -704,6 +874,8 @@ void MainWindow::profileTabClear() void MainWindow::profileTabCreateProfile() { + if (debug) qDebug() << "[MainWindow]" << "[profileTabCreateProfile]"; + // error checking if (ui->lineEdit_profile->text().isEmpty()) { errorWin = new ErrorWindow(this, debug, 3); @@ -839,10 +1011,9 @@ void MainWindow::profileTabCreateProfile() } } - if (debug) qDebug() << "[MainWindow]" << "[profileTabCreateProfile]"; ui->tabWidget->setDisabled(true); // read settings - QString profile = ui->lineEdit_profile->text(); + QString profile = netctlProfile->getNameByString(ui->lineEdit_profile->text()); QMap settings; settings = generalWid->getSettings(); if (generalWid->connectionType->currentText() == QString("ethernet")) { @@ -938,7 +1109,8 @@ void MainWindow::profileTabCreateProfile() void MainWindow::profileTabLoadProfile() { if (debug) qDebug() << "[MainWindow]" << "[profileTabLoadProfile]"; - QString profile = ui->lineEdit_profile->text(); + + QString profile = netctlProfile->getNameByString(ui->lineEdit_profile->text()); QMap settings = netctlProfile->getSettingsFromProfile(profile); generalWid->setSettings(settings); @@ -985,11 +1157,30 @@ void MainWindow::profileTabLoadProfile() } +void MainWindow::profileTabRemoveProfile() +{ + if (debug) qDebug() << "[MainWindow]" << "[profileTabRemoveProfile]"; + + ui->tabWidget->setDisabled(true); + // call netctlprofile + QString profile = netctlProfile->getNameByString(ui->lineEdit_profile->text()); + if (netctlProfile->removeProfile(profile)) + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); + else + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); + + updateProfileTab(); +} + + // wifi tab slots void MainWindow::wifiTabContextualMenu(const QPoint &pos) { if (debug) qDebug() << "[MainWindow]" << "[wifiTabContextualMenu]"; + if (ui->tableWidget_wifi->currentItem() == 0) + return; + // create menu QMenu menu(this); QAction *refreshTable = menu.addAction(QApplication::translate("MainWindow", "Refresh")); @@ -1029,6 +1220,9 @@ void MainWindow::wifiTabContextualMenu(const QPoint &pos) void MainWindow::wifiTabSetEnabled(const bool state) { + if (debug) qDebug() << "[MainWindow]" << "[wifiTabSetEnables]"; + if (debug) qDebug() << "[MainWindow]" << "[wifiTabSetEnables]" << ":" << "State" << state; + if (state) { ui->tableWidget_wifi->show(); ui->pushButton_wifiRefresh->setEnabled(true); @@ -1045,10 +1239,11 @@ void MainWindow::wifiTabSetEnabled(const bool state) void MainWindow::connectToUnknownEssid(const QString passwd) { + if (debug) qDebug() << "[MainWindow]" << "[connectToUnknownEssid]"; + if (!passwd.isEmpty()) delete passwdWid; - if (debug) qDebug() << "[MainWindow]" << "[connectToUnknownEssid]"; QMap settings; settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); settings[QString("Interface")] = wpaCommand->getInterfaceList()[0]; @@ -1076,19 +1271,26 @@ void MainWindow::connectToUnknownEssid(const QString passwd) ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); + updateWifiTab(); } void MainWindow::setHiddenName(const QString name) { + if (debug) qDebug() << "[MainWindow]" << "[setHiddenName]"; + if (debug) qDebug() << "[MainWindow]" << "[setHiddenName]" << ":" << "Set name" << name; + ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name); + wifiTabStart(); } void MainWindow::wifiTabStart() { + if (debug) qDebug() << "[MainWindow]" << "[wifiTabStart]"; + if (!checkExternalApps(QString("wpasup"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); @@ -1109,7 +1311,6 @@ void MainWindow::wifiTabStart() return; } - if (debug) qDebug() << "[MainWindow]" << "[wifiTabStart]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); QString item = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); @@ -1147,6 +1348,7 @@ void MainWindow::wifiTabStart() return; } } + updateWifiTab(); } @@ -1154,6 +1356,8 @@ void MainWindow::wifiTabStart() void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); + if (debug) qDebug() << "[MainWindow]" << "[wifiTabRefreshButtons]"; + if (!checkExternalApps(QString("wpasup"))) { errorWin = new ErrorWindow(this, debug, 1); errorWin->show(); @@ -1168,7 +1372,6 @@ void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt return; } - if (debug) qDebug() << "[MainWindow]" << "[wifiTabRefreshButtons]"; ui->pushButton_wifiStart->setEnabled(true); QString item = ui->tableWidget_wifi->item(current->row(), 1)->text(); if (checkState(QString("exists"), item)) { diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 350db88..85c8ef0 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -55,9 +55,6 @@ public: const bool debugCmd = false, const int tabNum = 1); ~MainWindow(); - Netctl *netctlCommand; - NetctlProfile *netctlProfile; - WpaSup *wpaCommand; public slots: void updateTabs(const int tab); @@ -66,11 +63,19 @@ public slots: void setHiddenName(const QString name); private slots: + // menu update slots + void setMenuActionsShown(const bool state = true); + void updateMenu(); + void updateMenuMain(); + void updateMenuProfile(); + void updateMenuWifi(); + // tab update slots void updateMainTab(); void updateProfileTab(); void updateWifiTab(); // main tab slots void mainTabContextualMenu(const QPoint &pos); + void mainTabEditProfile(); void mainTabRemoveProfile(); void mainTabEnableProfile(); void mainTabRestartProfile(); @@ -82,6 +87,7 @@ private slots: void profileTabClear(); void profileTabCreateProfile(); void profileTabLoadProfile(); + void profileTabRemoveProfile(); // wifi tab slots void wifiTabContextualMenu(const QPoint &pos); void wifiTabSetEnabled(const bool state); @@ -103,6 +109,9 @@ private: VlanWidget *vlanWid; WirelessWidget *wirelessWid; // backend + Netctl *netctlCommand; + NetctlProfile *netctlProfile; + WpaSup *wpaCommand; ErrorWindow *errorWin; PasswdWidget *passwdWid; SettingsWindow *settingsWin; diff --git a/sources/gui/src/mainwindow.ui b/sources/gui/src/mainwindow.ui index 4b82b90..4cf6155 100644 --- a/sources/gui/src/mainwindow.ui +++ b/sources/gui/src/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 487 - 515 + 483 + 511 @@ -89,16 +89,6 @@ - - - - Remove - - - true - - - @@ -112,19 +102,6 @@ - - - - false - - - Enable - - - true - - - @@ -203,8 +180,8 @@ 0 0 - 96 - 26 + 451 + 353 @@ -371,7 +348,7 @@ 0 0 - 487 + 483 22 @@ -382,12 +359,34 @@ + + + Actions + + + + + + + + + + + + + + + + + - + + + Settings @@ -398,7 +397,9 @@ - + + + Quit @@ -407,13 +408,104 @@ Ctrl+Q + + + + + + Refresh + + + + + + + + Start profile + + + + + + + + Restart profile + + + + + Enable profile + + + + + + + + Edit profile + + + + + + + + Remove profile + + + + + + + + Clear + + + + + + + + Refresh + + + + + + + + Load profile + + + + + + + + Save profile + + + + + + + + Start Wi-Fi + + + + + + + + Remove profile + + tabWidget tableWidget_main pushButton_mainRefresh - pushButton_mainRemove - pushButton_mainEnable pushButton_mainRestart pushButton_mainStart lineEdit_profile diff --git a/sources/gui/src/settingswindow.cpp b/sources/gui/src/settingswindow.cpp index 6429fdf..3ccc9fd 100644 --- a/sources/gui/src/settingswindow.cpp +++ b/sources/gui/src/settingswindow.cpp @@ -23,6 +23,7 @@ #include #include +#include "language.h" #include "mainwindow.h" @@ -41,12 +42,16 @@ SettingsWindow::SettingsWindow(MainWindow *wid, const bool debugCmd, const QStri SettingsWindow::~SettingsWindow() { + if (debug) qDebug() << "[SettingsWindow]" << "[~SettingsWindow]"; + delete ui; } void SettingsWindow::createActions() { + if (debug) qDebug() << "[SettingsWindow]" << "[createActions]"; + connect(ui->comboBox_language, SIGNAL(currentIndexChanged(int)), ui->label_info, SLOT(show())); connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked(bool)), this, SLOT(close())); connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this, SLOT(setDefault())); @@ -66,6 +71,8 @@ void SettingsWindow::createActions() // ESC press event void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) { + if (debug) qDebug() << "[SettingsWindow]" << "[keyPressEvent]"; + if (pressedKey->key() == Qt::Key_Escape) close(); } @@ -73,14 +80,17 @@ void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) void SettingsWindow::addLanguages() { + if (debug) qDebug() << "[SettingsWindow]" << "[addLanguages]"; + ui->comboBox_language->clear(); - ui->comboBox_language->addItem(QString("en")); - ui->comboBox_language->addItem(QString("ru")); + ui->comboBox_language->addItems(Language::getAvailableLanguages()); } void SettingsWindow::saveSettings() { + if (debug) qDebug() << "[SettingsWindow]" << "[saveSettings]"; + QMap settings = readSettings(); QFile configFile(file); @@ -95,6 +105,8 @@ void SettingsWindow::saveSettings() void SettingsWindow::setDefault() { + if (debug) qDebug() << "[SettingsWindow]" << "[setDefault]"; + setSettings(getDefault()); saveSettings(); } @@ -102,6 +114,8 @@ void SettingsWindow::setDefault() void SettingsWindow::selectIfaceDir() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectIfaceDir]"; + QString directory = QFileDialog::getExistingDirectory( this, QApplication::translate("SettingsWindow", "Select path to directory with interfaces"), @@ -113,6 +127,8 @@ void SettingsWindow::selectIfaceDir() void SettingsWindow::selectNetctlPath() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectNetctlPath]"; + QString filename = QFileDialog::getOpenFileName( this, QApplication::translate("SettingsWindow", "Select netctl command"), @@ -125,6 +141,8 @@ void SettingsWindow::selectNetctlPath() void SettingsWindow::selectProfileDir() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectProfileDir]"; + QString directory = QFileDialog::getExistingDirectory( this, QApplication::translate("SettingsWindow", "Select path to profile directory"), @@ -136,6 +154,8 @@ void SettingsWindow::selectProfileDir() void SettingsWindow::selectRfkillDir() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectRfkillDir]"; + QString directory = QFileDialog::getExistingDirectory( this, QApplication::translate("SettingsWindow", "Select path to directory with rfkill devices"), @@ -147,6 +167,8 @@ void SettingsWindow::selectRfkillDir() void SettingsWindow::selectSudoPath() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectSudoPath]"; + QString filename = QFileDialog::getOpenFileName( this, QApplication::translate("SettingsWindow", "Select sudo command"), @@ -159,6 +181,8 @@ void SettingsWindow::selectSudoPath() void SettingsWindow::selectWpaCliPath() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectWpaCliPath]"; + QString filename = QFileDialog::getOpenFileName( this, QApplication::translate("SettingsWindow", "Select wpa_cli command"), @@ -171,6 +195,8 @@ void SettingsWindow::selectWpaCliPath() void SettingsWindow::selectWpaSupPath() { + if (debug) qDebug() << "[SettingsWindow]" << "[selectWpaSupPath]"; + QString filename = QFileDialog::getOpenFileName( this, QApplication::translate("SettingsWindow", "Select wpa_supplicant command"), @@ -183,6 +209,8 @@ void SettingsWindow::selectWpaSupPath() void SettingsWindow::showWindow() { + if (debug) qDebug() << "[SettingsWindow]" << "[showWindow]"; + setSettings(getSettings()); ui->label_info->hide(); show(); @@ -191,6 +219,8 @@ void SettingsWindow::showWindow() QMap SettingsWindow::readSettings() { + if (debug) qDebug() << "[SettingsWindow]" << "[readSettings]"; + QMap settings; settings[QString("CTRL_DIR")] = ui->lineEdit_wpaDir->text(); @@ -217,6 +247,8 @@ QMap SettingsWindow::readSettings() void SettingsWindow::setSettings(const QMap settings) { + if (debug) qDebug() << "[SettingsWindow]" << "[setSettings]"; + ui->lineEdit_wpaDir->setText(settings[QString("CTRL_DIR")]); ui->lineEdit_wpaGroup->setText(settings[QString("CTRL_GROUP")]); ui->lineEdit_interfacesDir->setText(settings[QString("IFACE_DIR")]); @@ -242,6 +274,8 @@ void SettingsWindow::setSettings(const QMap settings) QMap SettingsWindow::getDefault() { + if (debug) qDebug() << "[SettingsWindow]" << "[getDefault]"; + QMap settings; settings[QString("CTRL_DIR")] = QString("/run/wpa_supplicant_netctl-gui"); @@ -268,6 +302,8 @@ QMap SettingsWindow::getDefault() QMap SettingsWindow::getSettings() { + if (debug) qDebug() << "[SettingsWindow]" << "[getSettings]"; + QMap settings; QFile configFile(file); QString fileStr; diff --git a/sources/netctlgui/CMakeLists.txt b/sources/netctlgui/CMakeLists.txt new file mode 100644 index 0000000..26131ae --- /dev/null +++ b/sources/netctlgui/CMakeLists.txt @@ -0,0 +1,13 @@ +# set project name +set (SUBPROJECT ${PROJECT_LIBRARY}) +message (STATUS "Subproject ${SUBPROJECT}") + +# set directories +set (SUBPROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) +set (SUBPROJECT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) + +# additional targets +set (TARGETS "") +set (HEADERS "") + +add_subdirectory (${SUBPROJECT_SOURCE_DIR}) diff --git a/sources/gui/src/netctlinteract.h b/sources/netctlgui/include/netctlgui/netctlinteract.h similarity index 94% rename from sources/gui/src/netctlinteract.h rename to sources/netctlgui/include/netctlgui/netctlinteract.h index f0410cc..fc39ad5 100644 --- a/sources/gui/src/netctlinteract.h +++ b/sources/netctlgui/include/netctlgui/netctlinteract.h @@ -23,15 +23,12 @@ #include -class MainWindow; - class Netctl : public QObject { Q_OBJECT public: - explicit Netctl(MainWindow *wid = 0, - const bool debugCmd = false, + explicit Netctl(const bool debugCmd = false, const QMap settings = QMap()); ~Netctl(); // general information @@ -49,7 +46,6 @@ public slots: bool startProfile(const QString profile); private: - MainWindow *parent; bool debug; QString netctlCommand; QDir *profileDirectory; diff --git a/sources/gui/src/netctlprofile.h b/sources/netctlgui/include/netctlgui/netctlprofile.h similarity index 92% rename from sources/gui/src/netctlprofile.h rename to sources/netctlgui/include/netctlgui/netctlprofile.h index 7236ee5..4d830e8 100644 --- a/sources/gui/src/netctlprofile.h +++ b/sources/netctlgui/include/netctlgui/netctlprofile.h @@ -23,24 +23,21 @@ #include -class MainWindow; - class NetctlProfile : public QObject { Q_OBJECT public: - explicit NetctlProfile(MainWindow *wid = 0, - const bool debugCmd = false, + explicit NetctlProfile(const bool debugCmd = false, const QMap settings = QMap()); ~NetctlProfile(); bool copyProfile(const QString oldPath); bool removeProfile(const QString profile); QString createProfile(const QString profile, const QMap settings); + QString getNameByString(const QString profile); QMap getSettingsFromProfile(const QString profile); private: - MainWindow *parent; bool debug; QDir *profileDirectory; QString sudoCommand; diff --git a/sources/gui/src/sleepthread.h b/sources/netctlgui/include/netctlgui/sleepthread.h similarity index 100% rename from sources/gui/src/sleepthread.h rename to sources/netctlgui/include/netctlgui/sleepthread.h diff --git a/sources/gui/src/wpasupinteract.h b/sources/netctlgui/include/netctlgui/wpasupinteract.h similarity index 94% rename from sources/gui/src/wpasupinteract.h rename to sources/netctlgui/include/netctlgui/wpasupinteract.h index a80a542..8b93859 100644 --- a/sources/gui/src/wpasupinteract.h +++ b/sources/netctlgui/include/netctlgui/wpasupinteract.h @@ -23,15 +23,14 @@ #include -class MainWindow; +class Netctl; class WpaSup : public QObject { Q_OBJECT public: - explicit WpaSup(MainWindow *wid = 0, - const bool debugCmd = false, + explicit WpaSup(const bool debugCmd = false, const QMap settings = QMap()); ~WpaSup(); // general information @@ -47,7 +46,7 @@ public slots: bool stopWpaSupplicant(); private: - MainWindow *parent; + Netctl *netctlCommand; bool debug; QString ctrlDir; QString ctrlGroup; diff --git a/sources/netctlgui/src/CMakeLists.txt b/sources/netctlgui/src/CMakeLists.txt new file mode 100644 index 0000000..77497a5 --- /dev/null +++ b/sources/netctlgui/src/CMakeLists.txt @@ -0,0 +1,46 @@ +# set files +file (GLOB SOURCES *.cpp) +file (GLOB HEADERS ${SUBPROJECT_INCLUDE_DIR}/${SUBPROJECT}/*.h) + +message (STATUS "${SUBPROJECT} Sources: ${SOURCES}") +message (STATUS "${SUBPROJECT} Headers: ${HEADERS}") + +# include_path +include_directories (${SUBPROJECT_INCLUDE_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/../ + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}) + +if (USE_QT5) + find_package(Qt5Core REQUIRED) + find_package(Qt5Widgets REQUIRED) + add_definitions(${Qt5Core_DEFINITIONS}) + add_definitions(${Qt5Widgets_DEFINITIONS}) + qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) + + source_group ("Header Files" FILES ${HEADERS}) + source_group ("Source Files" FILES ${SOURCES}) + source_group ("Generated Files" FILES ${MOC_SOURCES}) + + include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) + add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES}) + set_target_properties (${SUBPROJECT} PROPERTIES SOVERSION ${PROJECT_VERSION}) + target_link_libraries (${SUBPROJECT} ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES}) +else () + find_package (Qt4 REQUIRED) + include (${QT_USE_FILE}) + qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) + + source_group ("Header Files" FILES ${HEADERS}) + source_group ("Source Files" FILES ${SOURCES}) + source_group ("Generated Files" FILES ${MOC_SOURCES}) + + add_library (${SUBPROJECT} SHARED ${SOURCES} ${HEADERS} ${MOC_SOURCES}) + set_target_properties (${SUBPROJECT} PROPERTIES SOVERSION ${PROJECT_VERSION}) + target_link_libraries (${SUBPROJECT} ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}) +endif() + +# install properties +install (TARGETS ${SUBPROJECT} DESTINATION lib) +install (DIRECTORY ${SUBPROJECT_INCLUDE_DIR}/ DESTINATION include/) diff --git a/sources/netctlgui/src/main.cpp b/sources/netctlgui/src/main.cpp new file mode 100644 index 0000000..2075724 --- /dev/null +++ b/sources/netctlgui/src/main.cpp @@ -0,0 +1,28 @@ +/*************************************************************************** + * 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 +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/sources/gui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp similarity index 89% rename from sources/gui/src/netctlinteract.cpp rename to sources/netctlgui/src/netctlinteract.cpp index 446203f..a1d4969 100644 --- a/sources/gui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -15,18 +15,15 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ -#include "netctlinteract.h" - #include #include #include -#include "mainwindow.h" +#include -Netctl::Netctl(MainWindow *wid, const bool debugCmd, const QMap settings) - : parent(wid), - debug(debugCmd) +Netctl::Netctl(const bool debugCmd, const QMap settings) + : debug(debugCmd) { netctlCommand = settings[QString("NETCTL_PATH")]; profileDirectory = new QDir(settings[QString("PROFILE_DIR")]); @@ -36,6 +33,8 @@ Netctl::Netctl(MainWindow *wid, const bool debugCmd, const QMap Netctl::getProfileList() { + if (debug) qDebug() << "[Netctl]" << "[getProfileList]"; + QList fullProfilesInfo; QStringList profiles = profileDirectory->entryList(QDir::Files); QStringList descriptions = getProfileDescriptions(profiles); @@ -92,12 +99,14 @@ QList Netctl::getProfileList() profileInfo.append(statuses[i]); fullProfilesInfo.append(profileInfo); } + return fullProfilesInfo; } QStringList Netctl::getProfileDescriptions(const QStringList profileList) { + if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]"; QStringList descriptions; for (int i=0; iabsolutePath() + QDir::separator() + profile; if (debug) qDebug() << "[Netctl]" << "[getSsidFromProfile]" << ":" << "Check" << profileUrl; @@ -180,17 +193,22 @@ QString Netctl::getSsidFromProfile(const QString profile) bool Netctl::isProfileActive(const QString profile) { + if (debug) qDebug() << "[Netctl]" << "[isProfileActive]"; + bool status = false; QString cmdOutput = getNetctlOutput(false, QString("status"), profile); if (!cmdOutput.isEmpty()) if (cmdOutput.contains(QString("Active: active"))) status = true; + return status; } bool Netctl::isProfileEnabled(const QString profile) { + if (debug) qDebug() << "[Netctl]" << "[isProfileEnabled]"; + return netctlCall(false, QString("is-enabled"), profile); } @@ -198,6 +216,8 @@ bool Netctl::isProfileEnabled(const QString profile) // functions bool Netctl::enableProfile(const QString profile) { + if (debug) qDebug() << "[Netctl]" << "[enableProfile]"; + if (isProfileEnabled(profile)) return netctlCall(true, QString("disable"), profile); else @@ -207,12 +227,16 @@ bool Netctl::enableProfile(const QString profile) bool Netctl::restartProfile(const QString profile) { + if (debug) qDebug() << "[Netctl]" << "[restartProfile]"; + return netctlCall(true, QString("restart"), profile); } bool Netctl::startProfile(const QString profile) { + if (debug) qDebug() << "[Netctl]" << "[startProfile]"; + if (isProfileActive(profile)) return netctlCall(true, QString("stop"), profile); else diff --git a/sources/gui/src/netctlprofile.cpp b/sources/netctlgui/src/netctlprofile.cpp similarity index 86% rename from sources/gui/src/netctlprofile.cpp rename to sources/netctlgui/src/netctlprofile.cpp index 369ac14..f31cad5 100644 --- a/sources/gui/src/netctlprofile.cpp +++ b/sources/netctlgui/src/netctlprofile.cpp @@ -15,7 +15,6 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ -#include "netctlprofile.h" #include #include @@ -23,12 +22,11 @@ #include #include -#include "mainwindow.h" +#include -NetctlProfile::NetctlProfile(MainWindow *wid, const bool debugCmd, const QMap settings) - : parent(wid), - debug(debugCmd) +NetctlProfile::NetctlProfile(const bool debugCmd, const QMap settings) + : debug(debugCmd) { profileDirectory = new QDir(settings[QString("PROFILE_DIR")]); sudoCommand = settings[QString("SUDO_PATH")]; @@ -37,18 +35,23 @@ NetctlProfile::NetctlProfile(MainWindow *wid, const bool debugCmd, const QMapabsolutePath() + QDir::separator() + QFileInfo(oldPath).fileName(); QProcess command; QString commandText = sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath; if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << commandText; command.start(commandText); command.waitForFinished(-1); + if (command.exitCode() == 0) return true; else @@ -58,12 +61,15 @@ bool NetctlProfile::copyProfile(const QString oldPath) bool NetctlProfile::removeProfile(const QString profile) { - QString profilePath = profileDirectory->absolutePath() + QDir::separator() + profile; + if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]"; + + QString profilePath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName(); QProcess command; QString commandText = sudoCommand + QString(" /usr/bin/rm ") + profilePath; if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << commandText; command.start(commandText); command.waitForFinished(-1); + if (command.exitCode() == 0) return true; else @@ -74,6 +80,8 @@ bool NetctlProfile::removeProfile(const QString profile) QString NetctlProfile::createProfile(const QString profile, const QMap settings) { + if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]"; + if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Profile name" << profile; QString profileTempName = QDir::homePath() + QDir::separator() + QString(".cache") + QDir::separator() + QFileInfo(profile).fileName(); @@ -107,14 +115,22 @@ QString NetctlProfile::createProfile(const QString profile, const QMap NetctlProfile::getSettingsFromProfile(const QString profile) { + if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]"; + QMap settings; QString fileStr, profileUrl; - if (profile[0] == QDir::separator()) - profileUrl = profile; - else - profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile; + profileUrl = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName(); QFile profileFile(profileUrl); if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Read from" << profileUrl; diff --git a/sources/gui/src/wpasupinteract.cpp b/sources/netctlgui/src/wpasupinteract.cpp similarity index 84% rename from sources/gui/src/wpasupinteract.cpp rename to sources/netctlgui/src/wpasupinteract.cpp index d76f087..63856df 100644 --- a/sources/gui/src/wpasupinteract.cpp +++ b/sources/netctlgui/src/wpasupinteract.cpp @@ -15,20 +15,19 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ -#include "wpasupinteract.h" - #include #include -#include "mainwindow.h" -#include "netctlinteract.h" -#include "sleepthread.h" +#include +#include +#include -WpaSup::WpaSup(MainWindow *wid, const bool debugCmd, const QMap settings) - : parent(wid), - debug(debugCmd) +WpaSup::WpaSup(const bool debugCmd, const QMap settings) + : debug(debugCmd) { + netctlCommand = new Netctl(debug, settings); + ctrlDir = settings[QString("CTRL_DIR")]; ctrlGroup = settings[QString("CTRL_GROUP")]; ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]); @@ -47,6 +46,9 @@ WpaSup::WpaSup(MainWindow *wid, const bool debugCmd, const QMap profileList = parent->netctlCommand->getProfileList(); + QList profileList = netctlCommand->getProfileList(); for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) + if (profile == netctlCommand->getSsidFromProfile(profileList[i][0])) profileFile = profileList[i][0]; + return profileFile; } QStringList WpaSup::getInterfaceList() { + if (debug) qDebug() << "[WpaSup]" << "[getInterfaceList]"; + QStringList interfaces; if (!mainInterface.isEmpty()) @@ -84,22 +91,28 @@ QStringList WpaSup::getInterfaceList() bool WpaSup::isProfileActive(const QString profile) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]"; + QString profileFile; - QList profileList = parent->netctlCommand->getProfileList(); + QList profileList = netctlCommand->getProfileList(); for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) + if (profile == netctlCommand->getSsidFromProfile(profileList[i][0])) profileFile = profileList[i][0]; - return parent->netctlCommand->isProfileActive(profileFile); + + return netctlCommand->isProfileActive(profileFile); } bool WpaSup::isProfileExists(const QString profile) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]"; + bool exists = false; - QList profileList = parent->netctlCommand->getProfileList(); + QList profileList = netctlCommand->getProfileList(); for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) + if (profile == netctlCommand->getSsidFromProfile(profileList[i][0])) exists = true; + return exists; } @@ -107,6 +120,8 @@ bool WpaSup::isProfileExists(const QString profile) // functions bool WpaSup::wpaCliCall(const QString commandLine) { + if (debug) qDebug() << "[WpaSup]" << "[getInterfaceList]"; + QString interface = getInterfaceList()[0]; QProcess command; QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + @@ -125,6 +140,8 @@ bool WpaSup::wpaCliCall(const QString commandLine) QString WpaSup::getWpaCliOutput(const QString commandLine) { + if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]"; + QString interface = getInterfaceList()[0]; QProcess command; QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + @@ -132,12 +149,15 @@ QString WpaSup::getWpaCliOutput(const QString commandLine) if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << commandText; command.start(commandText); command.waitForFinished(-1); + return command.readAllStandardOutput(); } QList WpaSup::scanWifi() { + if (debug) qDebug() << "[WpaSup]" << "[scanWifi]"; + QList scanResults; if (!startWpaSupplicant()) { stopWpaSupplicant(); @@ -208,6 +228,8 @@ QList WpaSup::scanWifi() bool WpaSup::startWpaSupplicant() { + if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]"; + if (!QFile(pidFile).exists()) { QString interface = getInterfaceList()[0]; QProcess command; @@ -222,11 +244,14 @@ bool WpaSup::startWpaSupplicant() if (command.exitCode() != 0) return false; } + return true; } bool WpaSup::stopWpaSupplicant() { + if (debug) qDebug() << "[WpaSup]" << "[stopWpaSupplicant]"; + return wpaCliCall(QString("terminate")); }