detached backend from frontend

This commit is contained in:
arcan1s 2014-07-11 09:56:48 +04:00
parent eccb6b6578
commit 9852fb8f68
20 changed files with 637 additions and 132 deletions

View File

@ -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):

View File

@ -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 ()

View File

@ -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

View File

@ -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:

View File

@ -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<availableLanguages.count(); i++)
if (language == availableLanguages[i])
return availableLanguages[i];
for (int i=0; i<availableLanguages.count(); i++)
if (language.contains(availableLanguages[i] + QChar('_')))
return availableLanguages[i];
return defaultLanguage;
}
QString Language::defineLanguage(const QString configPath)
{
QString language;
@ -66,19 +79,6 @@ QString Language::defineLanguageFromLocale()
{
return QLocale::system().name();
}
\
QString Language::checkLanguage(const QString language, const QString defaultLanguage)
{
QStringList availableLanguages = getAvailableLanguages();
for (int i=0; i<availableLanguages.count(); i++)
if (language == availableLanguages[i])
return availableLanguages[i];
for (int i=0; i<availableLanguages.count(); i++)
if (language.contains(availableLanguages[i] + QChar('_')))
return availableLanguages[i];
return defaultLanguage;
}
QStringList Language::getAvailableLanguages()

View File

@ -21,17 +21,17 @@
#include <QStringList>
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();
};

View File

@ -23,6 +23,10 @@
#include <QFileInfo>
#include <QProcess>
#include <netctlgui/netctlinteract.h>
#include <netctlgui/netctlprofile.h>
#include <netctlgui/wpasupinteract.h>
#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<QStringList> 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<QStringList> 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<QString, QString> 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<QString, QString> 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<QString, QString> 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)) {

View File

@ -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;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>487</width>
<height>515</height>
<width>483</width>
<height>511</height>
</rect>
</property>
<property name="windowTitle">
@ -89,16 +89,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_mainRemove">
<property name="text">
<string>Remove</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="spacer_mainButtons">
<property name="orientation">
@ -112,19 +102,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_mainEnable">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_mainRestart">
<property name="enabled">
@ -203,8 +180,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
<width>451</width>
<height>353</height>
</rect>
</property>
<property name="sizePolicy">
@ -371,7 +348,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>487</width>
<width>483</width>
<height>22</height>
</rect>
</property>
@ -382,12 +359,34 @@
<addaction name="actionSettings"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuActions">
<property name="title">
<string>Actions</string>
</property>
<addaction name="actionMainRefresh"/>
<addaction name="actionWifiRefresh"/>
<addaction name="actionProfileClear"/>
<addaction name="separator"/>
<addaction name="actionMainStart"/>
<addaction name="actionMainRestart"/>
<addaction name="actionMainEnable"/>
<addaction name="actionProfileLoad"/>
<addaction name="actionProfileSave"/>
<addaction name="actionWifiStart"/>
<addaction name="separator"/>
<addaction name="actionMainEdit"/>
<addaction name="actionMainRemove"/>
<addaction name="actionProfileRemove"/>
</widget>
<addaction name="menuMenu"/>
<addaction name="menuActions"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionSettings">
<property name="icon">
<iconset theme="configure"/>
<iconset theme="configure">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Settings</string>
@ -398,7 +397,9 @@
</action>
<action name="actionQuit">
<property name="icon">
<iconset theme="exit"/>
<iconset theme="exit">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Quit</string>
@ -407,13 +408,104 @@
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionMainRefresh">
<property name="icon">
<iconset theme="stock-refresh"/>
</property>
<property name="text">
<string>Refresh</string>
</property>
</action>
<action name="actionMainStart">
<property name="icon">
<iconset theme="dialog-apply"/>
</property>
<property name="text">
<string>Start profile</string>
</property>
</action>
<action name="actionMainRestart">
<property name="icon">
<iconset theme="stock-refresh"/>
</property>
<property name="text">
<string>Restart profile</string>
</property>
</action>
<action name="actionMainEnable">
<property name="text">
<string>Enable profile</string>
</property>
</action>
<action name="actionMainEdit">
<property name="icon">
<iconset theme="edit"/>
</property>
<property name="text">
<string>Edit profile</string>
</property>
</action>
<action name="actionMainRemove">
<property name="icon">
<iconset theme="edit-delete"/>
</property>
<property name="text">
<string>Remove profile</string>
</property>
</action>
<action name="actionProfileClear">
<property name="icon">
<iconset theme="edit-clear"/>
</property>
<property name="text">
<string>Clear</string>
</property>
</action>
<action name="actionWifiRefresh">
<property name="icon">
<iconset theme="stock-refresh"/>
</property>
<property name="text">
<string>Refresh</string>
</property>
</action>
<action name="actionProfileLoad">
<property name="icon">
<iconset theme="document-open"/>
</property>
<property name="text">
<string>Load profile</string>
</property>
</action>
<action name="actionProfileSave">
<property name="icon">
<iconset theme="document-save"/>
</property>
<property name="text">
<string>Save profile</string>
</property>
</action>
<action name="actionWifiStart">
<property name="icon">
<iconset theme="dialog-apply"/>
</property>
<property name="text">
<string>Start Wi-Fi</string>
</property>
</action>
<action name="actionProfileRemove">
<property name="icon">
<iconset theme="edit-delete"/>
</property>
<property name="text">
<string>Remove profile</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>tableWidget_main</tabstop>
<tabstop>pushButton_mainRefresh</tabstop>
<tabstop>pushButton_mainRemove</tabstop>
<tabstop>pushButton_mainEnable</tabstop>
<tabstop>pushButton_mainRestart</tabstop>
<tabstop>pushButton_mainStart</tabstop>
<tabstop>lineEdit_profile</tabstop>

View File

@ -23,6 +23,7 @@
#include <QFileDialog>
#include <QTextStream>
#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<QString, QString> 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<QString, QString> SettingsWindow::readSettings()
{
if (debug) qDebug() << "[SettingsWindow]" << "[readSettings]";
QMap<QString, QString> settings;
settings[QString("CTRL_DIR")] = ui->lineEdit_wpaDir->text();
@ -217,6 +247,8 @@ QMap<QString, QString> SettingsWindow::readSettings()
void SettingsWindow::setSettings(const QMap<QString, QString> 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<QString, QString> settings)
QMap<QString, QString> SettingsWindow::getDefault()
{
if (debug) qDebug() << "[SettingsWindow]" << "[getDefault]";
QMap<QString, QString> settings;
settings[QString("CTRL_DIR")] = QString("/run/wpa_supplicant_netctl-gui");
@ -268,6 +302,8 @@ QMap<QString, QString> SettingsWindow::getDefault()
QMap<QString, QString> SettingsWindow::getSettings()
{
if (debug) qDebug() << "[SettingsWindow]" << "[getSettings]";
QMap<QString, QString> settings;
QFile configFile(file);
QString fileStr;

View File

@ -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})

View File

@ -23,15 +23,12 @@
#include <QObject>
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<QString, QString> settings = QMap<QString, QString>());
~Netctl();
// general information
@ -49,7 +46,6 @@ public slots:
bool startProfile(const QString profile);
private:
MainWindow *parent;
bool debug;
QString netctlCommand;
QDir *profileDirectory;

View File

@ -23,24 +23,21 @@
#include <QObject>
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<QString, QString> settings = QMap<QString, QString>());
~NetctlProfile();
bool copyProfile(const QString oldPath);
bool removeProfile(const QString profile);
QString createProfile(const QString profile, const QMap<QString, QString> settings);
QString getNameByString(const QString profile);
QMap<QString, QString> getSettingsFromProfile(const QString profile);
private:
MainWindow *parent;
bool debug;
QDir *profileDirectory;
QString sudoCommand;

View File

@ -23,15 +23,14 @@
#include <QObject>
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<QString, QString> settings = QMap<QString, QString>());
~WpaSup();
// general information
@ -47,7 +46,7 @@ public slots:
bool stopWpaSupplicant();
private:
MainWindow *parent;
Netctl *netctlCommand;
bool debug;
QString ctrlDir;
QString ctrlGroup;

View File

@ -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/)

View File

@ -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 <netctlgui/netctlinteract.h>
#include <netctlgui/netctlprofile.h>
#include <netctlgui/sleepthread.h>
#include <netctlgui/wpasupinteract.h>
int main(int argc, char *argv[])
{
return 0;
}

View File

@ -15,18 +15,15 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "netctlinteract.h"
#include <QDebug>
#include <QFile>
#include <QProcess>
#include "mainwindow.h"
#include <netctlgui/netctlinteract.h>
Netctl::Netctl(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
: parent(wid),
debug(debugCmd)
Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> 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<QString, QString
Netctl::~Netctl()
{
if (debug) qDebug() << "[Netctl]" << "[~Netctl]";
delete profileDirectory;
}
@ -43,6 +42,8 @@ Netctl::~Netctl()
// functions
QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]";
QProcess command;
QString commandText;
if (sudo)
@ -53,12 +54,15 @@ QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, cons
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
return command.readAllStandardOutput();
}
bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[netctlCall]";
QProcess command;
QString commandText;
if (sudo)
@ -70,6 +74,7 @@ bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QStrin
command.start(commandText);
command.waitForFinished(-1);
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Cmd returns" << command.exitCode();
if (command.exitCode() == 0)
return true;
else
@ -80,6 +85,8 @@ bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QStrin
// general information
QList<QStringList> Netctl::getProfileList()
{
if (debug) qDebug() << "[Netctl]" << "[getProfileList]";
QList<QStringList> fullProfilesInfo;
QStringList profiles = profileDirectory->entryList(QDir::Files);
QStringList descriptions = getProfileDescriptions(profiles);
@ -92,12 +99,14 @@ QList<QStringList> 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; i<profileList.count(); i++) {
@ -130,6 +139,8 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList)
QStringList Netctl::getProfileStatuses(const QStringList profileList)
{
if (debug) qDebug() << "[Netctl]" << "[getProfileStatuses]";
QStringList statuses;
for (int i=0; i<profileList.count(); i++) {
@ -151,6 +162,8 @@ QStringList Netctl::getProfileStatuses(const QStringList profileList)
QString Netctl::getSsidFromProfile(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[getSsidFromProfile]";
QString ssidName = QString("");
QString profileUrl = profileDirectory->absolutePath() + 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

View File

@ -15,7 +15,6 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "netctlprofile.h"
#include <QDebug>
#include <QFile>
@ -23,12 +22,11 @@
#include <QProcess>
#include <QTextStream>
#include "mainwindow.h"
#include <netctlgui/netctlprofile.h>
NetctlProfile::NetctlProfile(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
: parent(wid),
debug(debugCmd)
NetctlProfile::NetctlProfile(const bool debugCmd, const QMap<QString, QString> 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 QMap<QS
NetctlProfile::~NetctlProfile()
{
if (debug) qDebug() << "[NetctlProfile]" << "[~NetctlProfile]";
delete profileDirectory;
}
bool NetctlProfile::copyProfile(const QString oldPath)
{
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]";
QString newPath = profileDirectory->absolutePath() + 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<QString, QString> 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<QString,
}
QString NetctlProfile::getNameByString(const QString profile)
{
if (debug) qDebug() << "[NetctlProfile]" << "[getNameByString]";
if (debug) qDebug() << "[NetctlProfile]" << "[getNameByString]" << ":" << "Raw string" << profile;
return QFileInfo(profile).fileName();
}
QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile)
{
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]";
QMap<QString, QString> 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;

View File

@ -15,20 +15,19 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "wpasupinteract.h"
#include <QDebug>
#include <QProcess>
#include "mainwindow.h"
#include "netctlinteract.h"
#include "sleepthread.h"
#include <netctlgui/netctlinteract.h>
#include <netctlgui/sleepthread.h>
#include <netctlgui/wpasupinteract.h>
WpaSup::WpaSup(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
: parent(wid),
debug(debugCmd)
WpaSup::WpaSup(const bool debugCmd, const QMap<QString, QString> 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<QString, QString
WpaSup::~WpaSup()
{
if (debug) qDebug() << "[WpaSup]" << "[~WpaSup]";
delete netctlCommand;
delete ifaceDirectory;
}
@ -54,17 +56,22 @@ WpaSup::~WpaSup()
// general information
QString WpaSup::existentProfile(const QString profile)
{
if (debug) qDebug() << "[WpaSup]" << "[existentProfile]";
QString profileFile = QString("");
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
QList<QStringList> profileList = netctlCommand->getProfileList();
for (int i=0; i<profileList.count(); i++)
if (profile == parent->netctlCommand->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<QStringList> profileList = parent->netctlCommand->getProfileList();
QList<QStringList> profileList = netctlCommand->getProfileList();
for (int i=0; i<profileList.count(); i++)
if (profile == parent->netctlCommand->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<QStringList> profileList = parent->netctlCommand->getProfileList();
QList<QStringList> profileList = netctlCommand->getProfileList();
for (int i=0; i<profileList.count(); i++)
if (profile == parent->netctlCommand->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<QStringList> WpaSup::scanWifi()
{
if (debug) qDebug() << "[WpaSup]" << "[scanWifi]";
QList<QStringList> scanResults;
if (!startWpaSupplicant()) {
stopWpaSupplicant();
@ -208,6 +228,8 @@ QList<QStringList> 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"));
}