mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-07 19:05:52 +00:00
detached backend from frontend
This commit is contained in:
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -1,220 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 "netctlinteract.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
Netctl::Netctl(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
|
||||
: parent(wid),
|
||||
debug(debugCmd)
|
||||
{
|
||||
netctlCommand = settings[QString("NETCTL_PATH")];
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
}
|
||||
|
||||
|
||||
Netctl::~Netctl()
|
||||
{
|
||||
delete profileDirectory;
|
||||
}
|
||||
|
||||
|
||||
// functions
|
||||
QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, const QString profile)
|
||||
{
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine +
|
||||
QString(" ") + profile;
|
||||
else
|
||||
commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile;
|
||||
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)
|
||||
{
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine +
|
||||
QString(" ") + profile;
|
||||
else
|
||||
commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile;
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
if (command.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// general information
|
||||
QList<QStringList> Netctl::getProfileList()
|
||||
{
|
||||
QList<QStringList> fullProfilesInfo;
|
||||
QStringList profiles = profileDirectory->entryList(QDir::Files);
|
||||
QStringList descriptions = getProfileDescriptions(profiles);
|
||||
QStringList statuses = getProfileStatuses(profiles);
|
||||
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
QStringList profileInfo;
|
||||
profileInfo.append(profiles[i]);
|
||||
profileInfo.append(descriptions[i]);
|
||||
profileInfo.append(statuses[i]);
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
return fullProfilesInfo;
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
{
|
||||
QStringList descriptions;
|
||||
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profileList[i];
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Check" << profileUrl;
|
||||
QFile profile(profileUrl);
|
||||
QString fileStr;
|
||||
if (profile.open(QIODevice::ReadOnly))
|
||||
while (true) {
|
||||
fileStr = QString(profile.readLine());
|
||||
if (fileStr[0] != '#')
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("Description"))
|
||||
descriptions.append(fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed());
|
||||
if (profile.atEnd())
|
||||
break;
|
||||
}
|
||||
else
|
||||
descriptions.append(QString("<unknown>"));
|
||||
}
|
||||
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
descriptions[i].remove(QChar('\''));
|
||||
descriptions[i].remove(QChar('"'));
|
||||
}
|
||||
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileStatuses(const QStringList profileList)
|
||||
{
|
||||
QStringList statuses;
|
||||
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QString status;
|
||||
if (isProfileActive(profileList[i]))
|
||||
status = QString("active");
|
||||
else
|
||||
status = QString("inactive");
|
||||
if (isProfileEnabled(profileList[i]))
|
||||
status = status + QString(" (enabled)");
|
||||
else
|
||||
status = status + QString(" (static)");
|
||||
statuses.append(status);
|
||||
}
|
||||
|
||||
return statuses;
|
||||
}
|
||||
|
||||
|
||||
QString Netctl::getSsidFromProfile(const QString profile)
|
||||
{
|
||||
QString ssidName = QString("");
|
||||
QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getSsidFromProfile]" << ":" << "Check" << profileUrl;
|
||||
QFile profileFile(profileUrl);
|
||||
QString fileStr;
|
||||
if (!profileFile.open(QIODevice::ReadOnly))
|
||||
return ssidName;
|
||||
|
||||
while (true) {
|
||||
fileStr = QString(profileFile.readLine());
|
||||
if (fileStr[0] != '#') {
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID"))
|
||||
ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed();
|
||||
}
|
||||
if (profileFile.atEnd())
|
||||
break;
|
||||
}
|
||||
|
||||
profileFile.close();
|
||||
|
||||
ssidName.remove(QChar('\''));
|
||||
ssidName.remove(QChar('"'));
|
||||
return ssidName;
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::isProfileActive(const QString profile)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return netctlCall(false, QString("is-enabled"), profile);
|
||||
}
|
||||
|
||||
|
||||
// functions
|
||||
bool Netctl::enableProfile(const QString profile)
|
||||
{
|
||||
if (isProfileEnabled(profile))
|
||||
return netctlCall(true, QString("disable"), profile);
|
||||
else
|
||||
return netctlCall(true, QString("enable"), profile);
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::restartProfile(const QString profile)
|
||||
{
|
||||
return netctlCall(true, QString("restart"), profile);
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::startProfile(const QString profile)
|
||||
{
|
||||
if (isProfileActive(profile))
|
||||
return netctlCall(true, QString("stop"), profile);
|
||||
else
|
||||
return netctlCall(true, QString("start"), profile);
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of netctl-gui *
|
||||
* *
|
||||
* netctl-gui is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* netctl-gui is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NETCTLINTERACT_H
|
||||
#define NETCTLINTERACT_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class Netctl : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Netctl(MainWindow *wid = 0,
|
||||
const bool debugCmd = false,
|
||||
const QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~Netctl();
|
||||
// general information
|
||||
QList<QStringList> getProfileList();
|
||||
QStringList getProfileDescriptions(const QStringList profileList);
|
||||
QStringList getProfileStatuses(const QStringList profileList);
|
||||
QString getSsidFromProfile(const QString profile);
|
||||
bool isProfileActive(const QString profile);
|
||||
bool isProfileEnabled(const QString profile);
|
||||
|
||||
public slots:
|
||||
// functions
|
||||
bool enableProfile(const QString profile);
|
||||
bool restartProfile(const QString profile);
|
||||
bool startProfile(const QString profile);
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
bool debug;
|
||||
QString netctlCommand;
|
||||
QDir *profileDirectory;
|
||||
QString sudoCommand;
|
||||
// functions
|
||||
QString getNetctlOutput(const bool sudo, const QString commandLine, const QString profile);
|
||||
bool netctlCall(const bool sudo, const QString commandLine, const QString profile);
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETCTLINTERACT_H */
|
@ -1,173 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 "netctlprofile.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
NetctlProfile::NetctlProfile(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
|
||||
: parent(wid),
|
||||
debug(debugCmd)
|
||||
{
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
}
|
||||
|
||||
|
||||
NetctlProfile::~NetctlProfile()
|
||||
{
|
||||
delete profileDirectory;
|
||||
}
|
||||
|
||||
|
||||
bool NetctlProfile::copyProfile(const QString oldPath)
|
||||
{
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool NetctlProfile::removeProfile(const QString profile)
|
||||
{
|
||||
QString profilePath = profileDirectory->absolutePath() + QDir::separator() + profile;
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings)
|
||||
{
|
||||
|
||||
QString profileTempName = QDir::homePath() + QDir::separator() +
|
||||
QString(".cache") + QDir::separator() + QFileInfo(profile).fileName();
|
||||
QFile profileFile(profileTempName);
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Save to" << profileTempName;
|
||||
|
||||
if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return profileTempName;
|
||||
|
||||
QTextStream out(&profileFile);
|
||||
for (int i=0; i<settings.keys().count(); i++) {
|
||||
out << settings.keys()[i] << QString("=");
|
||||
if ((settings.keys()[i] == QString("BindsToInterfaces")) ||
|
||||
(settings.keys()[i] == QString("After")) ||
|
||||
(settings.keys()[i] == QString("Address")) ||
|
||||
(settings.keys()[i] == QString("Routes")) ||
|
||||
(settings.keys()[i] == QString("Address6")) ||
|
||||
(settings.keys()[i] == QString("Routes6")) ||
|
||||
(settings.keys()[i] == QString("IPCustom")) ||
|
||||
(settings.keys()[i] == QString("DNS")) ||
|
||||
(settings.keys()[i] == QString("DNSOptions")) ||
|
||||
(settings.keys()[i] == QString("WPAConfigSection")) ||
|
||||
(settings.keys()[i] == QString("WPAConfigSection")))
|
||||
out << QString("(") + settings[settings.keys()[i]] << QString(")\n");
|
||||
else
|
||||
out << settings[settings.keys()[i]] << QString("\n");
|
||||
}
|
||||
profileFile.close();
|
||||
|
||||
return profileTempName;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile)
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
QString fileStr, profileUrl;
|
||||
if (profile[0] == QDir::separator())
|
||||
profileUrl = profile;
|
||||
else
|
||||
profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile;
|
||||
QFile profileFile(profileUrl);
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Read from" << profileUrl;
|
||||
|
||||
if (!profileFile.open(QIODevice::ReadOnly))
|
||||
return settings;
|
||||
while (true) {
|
||||
fileStr = QString(profileFile.readLine());
|
||||
if (fileStr[0] != '#') {
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) {
|
||||
if ((fileStr.split(QString("="))[1][0] == QChar('(')) &&
|
||||
(fileStr.split(QString("="))[1][fileStr.split(QString("="))[1].size()-2] == QChar(')')))
|
||||
settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed();
|
||||
else if (fileStr.split(QString("="))[1][0] == QChar('(')) {
|
||||
QString parameterName = fileStr.split(QString("="))[0];
|
||||
QStringList parameter;
|
||||
if (!fileStr.split(QString("="))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed()
|
||||
.isEmpty())
|
||||
parameter.append(fileStr.split(QString("="))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed());
|
||||
while(true) {
|
||||
fileStr = QString(profileFile.readLine());
|
||||
if (fileStr[fileStr.size()-2] == QChar(')'))
|
||||
break;
|
||||
if (!fileStr.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed()
|
||||
.isEmpty())
|
||||
parameter.append(fileStr.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed());
|
||||
if (profileFile.atEnd())
|
||||
break;
|
||||
}
|
||||
settings[parameterName] = parameter.join(QString("\n"));
|
||||
}
|
||||
else
|
||||
settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1]
|
||||
.trimmed();
|
||||
}
|
||||
|
||||
}
|
||||
if (profileFile.atEnd())
|
||||
break;
|
||||
}
|
||||
|
||||
profileFile.close();
|
||||
return settings;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of netctl-gui *
|
||||
* *
|
||||
* netctl-gui is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* netctl-gui is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NETCTLPROFILE_H
|
||||
#define NETCTLPROFILE_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class NetctlProfile : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NetctlProfile(MainWindow *wid = 0,
|
||||
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);
|
||||
QMap<QString, QString> getSettingsFromProfile(const QString profile);
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
bool debug;
|
||||
QDir *profileDirectory;
|
||||
QString sudoCommand;
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETCTLPROFILE_H */
|
@ -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;
|
||||
|
@ -1,46 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of netctl-gui *
|
||||
* *
|
||||
* netctl-gui is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* netctl-gui is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SLEEPTHREAD_H
|
||||
#define SLEEPTHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
|
||||
|
||||
class SleepThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static void usleep(long iSleepTime)
|
||||
{
|
||||
QThread::usleep(iSleepTime);
|
||||
}
|
||||
|
||||
static void sleep(long iSleepTime)
|
||||
{
|
||||
QThread::sleep(iSleepTime);
|
||||
}
|
||||
|
||||
static void msleep(long iSleepTime)
|
||||
{
|
||||
QThread::msleep(iSleepTime);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* SLEEPTHREAD_H */
|
@ -1,232 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 "wpasupinteract.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "netctlinteract.h"
|
||||
#include "sleepthread.h"
|
||||
|
||||
|
||||
WpaSup::WpaSup(MainWindow *wid, const bool debugCmd, const QMap<QString, QString> settings)
|
||||
: parent(wid),
|
||||
debug(debugCmd)
|
||||
{
|
||||
ctrlDir = settings[QString("CTRL_DIR")];
|
||||
ctrlGroup = settings[QString("CTRL_GROUP")];
|
||||
ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
|
||||
mainInterface = settings[QString("PREFERED_IFACE")];
|
||||
pidFile = settings[QString("PID_FILE")];
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
wpaCliPath = settings[QString("WPACLI_PATH")];
|
||||
wpaDrivers = settings[QString("WPA_DRIVERS")];
|
||||
wpaSupPath = settings[QString("WPASUP_PATH")];
|
||||
|
||||
// terminate old loaded profile
|
||||
if (QFile(pidFile).exists() || QDir(ctrlDir).exists())
|
||||
stopWpaSupplicant();
|
||||
}
|
||||
|
||||
|
||||
WpaSup::~WpaSup()
|
||||
{
|
||||
delete ifaceDirectory;
|
||||
}
|
||||
|
||||
|
||||
// general information
|
||||
QString WpaSup::existentProfile(const QString profile)
|
||||
{
|
||||
QString profileFile = QString("");
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0]))
|
||||
profileFile = profileList[i][0];
|
||||
return profileFile;
|
||||
}
|
||||
|
||||
|
||||
QStringList WpaSup::getInterfaceList()
|
||||
{
|
||||
QStringList interfaces;
|
||||
|
||||
if (!mainInterface.isEmpty())
|
||||
interfaces.append(mainInterface);
|
||||
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (int i=0; i<allInterfaces.count(); i++) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getInterfaceList]" << ":" << "Check directory"
|
||||
<< ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless");
|
||||
if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] +
|
||||
QDir::separator() + QString("wireless")).exists())
|
||||
interfaces.append(allInterfaces[i]);
|
||||
}
|
||||
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileActive(const QString profile)
|
||||
{
|
||||
QString profileFile;
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0]))
|
||||
profileFile = profileList[i][0];
|
||||
return parent->netctlCommand->isProfileActive(profileFile);
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileExists(const QString profile)
|
||||
{
|
||||
bool exists = false;
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0]))
|
||||
exists = true;
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
// functions
|
||||
bool WpaSup::wpaCliCall(const QString commandLine)
|
||||
{
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
if (command.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QString WpaSup::getWpaCliOutput(const QString commandLine)
|
||||
{
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
return command.readAllStandardOutput();
|
||||
}
|
||||
|
||||
|
||||
QList<QStringList> WpaSup::scanWifi()
|
||||
{
|
||||
QList<QStringList> scanResults;
|
||||
if (!startWpaSupplicant()) {
|
||||
stopWpaSupplicant();
|
||||
return scanResults;
|
||||
}
|
||||
if (!wpaCliCall(QString("scan")))
|
||||
return scanResults;
|
||||
SleepThread::sleep(3);
|
||||
|
||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"), QString::SkipEmptyParts);
|
||||
// remove table header
|
||||
rawOutput.removeFirst();
|
||||
// remove duplicates
|
||||
QStringList rawList;
|
||||
for (int i=0; i<rawOutput.count(); i++) {
|
||||
bool exist = false;
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
for (int j=0; j<rawList.count(); j++)
|
||||
if (rawList[j].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[4] ==
|
||||
rawList[j].split(QString("\t"), QString::SkipEmptyParts)[4])
|
||||
exist = true;
|
||||
if (!exist)
|
||||
rawList.append(rawOutput[i]);
|
||||
}
|
||||
|
||||
for (int i=0; i<rawList.count(); i++) {
|
||||
QStringList wifiPoint;
|
||||
|
||||
// point name
|
||||
if (rawList[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[4]);
|
||||
else
|
||||
wifiPoint.append(QString("<hidden>"));
|
||||
// profile status
|
||||
QString status;
|
||||
if (isProfileExists(wifiPoint[0])) {
|
||||
status = QString("exists");
|
||||
if (isProfileActive(wifiPoint[0]))
|
||||
status = status + QString(" (active)");
|
||||
else
|
||||
status = status + QString(" (inactive)");
|
||||
}
|
||||
else
|
||||
status = QString("new");
|
||||
wifiPoint.append(status);
|
||||
// point signal
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[2]);
|
||||
// point security
|
||||
QString security = rawList[i].split(QString("\t"), QString::SkipEmptyParts)[3];
|
||||
if (security.contains(QString("WPA2")))
|
||||
security = QString("WPA2");
|
||||
else if (security.contains(QString("WPA")))
|
||||
security = QString("WPA");
|
||||
else if (security.contains(QString("WEP")))
|
||||
security = QString("WEP");
|
||||
else
|
||||
security = QString("none");
|
||||
wifiPoint.append(security);
|
||||
|
||||
scanResults.append(wifiPoint);
|
||||
}
|
||||
|
||||
stopWpaSupplicant();
|
||||
return scanResults;
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::startWpaSupplicant()
|
||||
{
|
||||
if (!QFile(pidFile).exists()) {
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
QString commandText = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
||||
QString(" -i ") + interface + QString(" -D ") + wpaDrivers +
|
||||
QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\"");
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << command.exitCode();
|
||||
if (command.exitCode() != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::stopWpaSupplicant()
|
||||
{
|
||||
return wpaCliCall(QString("terminate"));
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of netctl-gui *
|
||||
* *
|
||||
* netctl-gui is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* netctl-gui is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef WPASUPINTERACT_H
|
||||
#define WPASUPINTERACT_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class WpaSup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WpaSup(MainWindow *wid = 0,
|
||||
const bool debugCmd = false,
|
||||
const QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~WpaSup();
|
||||
// general information
|
||||
QString existentProfile(const QString profile);
|
||||
QStringList getInterfaceList();
|
||||
bool isProfileActive(const QString profile);
|
||||
bool isProfileExists(const QString profile);
|
||||
|
||||
public slots:
|
||||
// functions
|
||||
QList<QStringList> scanWifi();
|
||||
bool startWpaSupplicant();
|
||||
bool stopWpaSupplicant();
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
bool debug;
|
||||
QString ctrlDir;
|
||||
QString ctrlGroup;
|
||||
QDir *ifaceDirectory;
|
||||
QString mainInterface;
|
||||
QString pidFile;
|
||||
QString sudoCommand;
|
||||
QString wpaCliPath;
|
||||
QString wpaDrivers;
|
||||
QString wpaSupPath;
|
||||
// functions
|
||||
bool wpaCliCall(const QString commandLine);
|
||||
QString getWpaCliOutput(const QString commandLine);
|
||||
};
|
||||
|
||||
|
||||
#endif /* WPASUPINTERACT_H */
|
Reference in New Issue
Block a user