add gui for netctl-auto

This commit is contained in:
arcan1s 2014-07-12 13:23:43 +04:00
parent c3f090d9a0
commit de22663156
11 changed files with 575 additions and 44 deletions

View File

@ -49,14 +49,17 @@ int main(int argc, char *argv[])
helpMessage += QApplication::translate("MainWindow", " Evgeniy Alekseev aka arcanis\n");
helpMessage += QApplication::translate("MainWindow", " E-mail : esalexeev@gmail.com\n\n");
helpMessage += QApplication::translate("MainWindow", "Usage:\n");
helpMessage += QApplication::translate("MainWindow", "netctl-gui [ --default ] [ -d | --debug ] [ -t NUM | --tab NUM ] [ -h | --help]\n\n");
helpMessage += QApplication::translate("MainWindow", "netctl-gui [ -d | --debug ] [ --default ] [ --netctl-auto ] [ -t NUM | --tab NUM ]\n");
helpMessage += QApplication::translate("MainWindow", " [ -h | --help]\n\n");
helpMessage += QApplication::translate("MainWindow", "Parametrs:\n");
helpMessage += QApplication::translate("MainWindow", " --default - start with default settings\n");
helpMessage += QApplication::translate("MainWindow", " -d --debug - print debug information\n");
helpMessage += QApplication::translate("MainWindow", " -t NUM --tab NUM - open a tab with number NUM\n");
helpMessage += QApplication::translate("MainWindow", " -h --help - show this help and exit\n");
helpMessage += QApplication::translate("MainWindow", " -d --debug - print debug information\n");
helpMessage += QApplication::translate("MainWindow", " --default - start with default settings\n");
helpMessage += QApplication::translate("MainWindow", " --netctl-auto - show netctl-auto window\n");
helpMessage += QApplication::translate("MainWindow", " -t NUM --tab NUM - open a tab with number NUM\n");
helpMessage += QApplication::translate("MainWindow", " -h --help - show this help and exit\n");
bool defaultSettings = false;
bool debug = false;
bool netctlAuto = false;
int tabNumber = 1;
for (int i=1; i<argc; i++) {
@ -80,6 +83,13 @@ int main(int argc, char *argv[])
(argv[i][3] == 'g') && (argv[i][4] == '\0'))) {
debug = true;
}
// netctl-auto
else if ((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 'n') && (argv[i][3] == 'e') &&
(argv[i][4] == 't') && (argv[i][5] == 'c') && (argv[i][6] == 't') && (argv[i][7] == 'l') &&
(argv[i][8] == '-') && (argv[i][9] == 'a') && (argv[i][10] == 'u') && (argv[i][11] == 't') &&
(argv[i][12] == 'o') && (argv[i][13] == '\0')) {
netctlAuto = true;
}
// tab number
else if (((argv[i][0] == '-') && (argv[i][1] == 't') && (argv[i][2] == '\0')) ||
((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 't') &&
@ -94,7 +104,7 @@ int main(int argc, char *argv[])
}
}
MainWindow w(0, defaultSettings, debug, tabNumber);
MainWindow w(0, defaultSettings, debug, netctlAuto, tabNumber);
w.show();
return a.exec();
}

View File

@ -44,7 +44,7 @@
#include "wirelesswidget.h"
MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool debugCmd, const int tabNum)
MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool debugCmd, const bool netctlAuto, const int tabNum)
: QMainWindow(parent),
ui(new Ui::MainWindow),
debug(debugCmd)
@ -96,6 +96,9 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool d
setIconsToButtons();
updateTabs(ui->tabWidget->currentIndex());
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Ready"));
if (netctlAuto)
netctlAutoWin->showWindow();
}
@ -136,6 +139,9 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all"))
commandLine.append(configuration[QString("NETCTL_PATH")]);
commandLine.append(configuration[QString("NETCTLAUTO_PATH")]);
}
if ((apps == QString("systemctl")) || (apps == QString("all"))) {
commandLine.append(configuration[QString("SYSTEMCTL_PATH")]);
}
if ((apps == QString("wpasup")) || (apps == QString("all"))) {
commandLine.append(configuration[QString("WPACLI_PATH")]);
commandLine.append(configuration[QString("WPASUP_PATH")]);

View File

@ -54,6 +54,7 @@ public:
explicit MainWindow(QWidget *parent = 0,
const bool defaultSettings = false,
const bool debugCmd = false,
const bool netctlAuto = false,
const int tabNum = 1);
~MainWindow();

View File

@ -32,6 +32,7 @@ NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const Q
netctlCommand = new Netctl(debug, settings);
createActions();
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready"));
}
@ -52,17 +53,23 @@ void NetctlAutoWindow::createActions()
connect(ui->actionClose, SIGNAL(triggered(bool)), this, SLOT(close()));
connect(ui->actionDisableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoDisableAllProfiles()));
connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile()));
connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));
connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));\
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoAppendTable()));
connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile()));
// service
connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService()));
connect(ui->actionRestartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoRestartService()));
connect(ui->actionStartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartService()));
// table actions
connect(ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(startProfile()));
connect(ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(netctlAutoStartProfile()));
connect(ui->tableWidget, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(netctlAutoRefreshButtons(QTableWidgetItem *, QTableWidgetItem *)));
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(netctlAutoContextualMenu(QPoint)));
// buttons
connect(ui->pushButton_enable, SIGNAL(clicked(bool)), SLOT(netctlAutoEnableProfile()));
connect(ui->pushButton_switch, SIGNAL(clicked(bool)), SLOT(netctlAutoStartProfile()));
connect(ui->pushButton_enable, SIGNAL(clicked(bool)), this, SLOT(netctlAutoEnableProfile()));
connect(ui->pushButton_refresh, SIGNAL(clicked(bool)), this, SLOT(netctlAutoAppendTable()));
connect(ui->pushButton_switch, SIGNAL(clicked(bool)), this, SLOT(netctlAutoStartProfile()));
}
@ -77,10 +84,30 @@ void NetctlAutoWindow::showWindow()
void NetctlAutoWindow::netctlAutoAppendTable()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[appendTable]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoAppendTable]";
ui->tableWidget->setDisabled(true);
QList<QStringList> profiles = netctlCommand->getProfileListFromNetctlAuto();
// actions
if (netctlCommand->isNetctlAutoEnabled())
ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Disable service"));
else
ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Enable service"));
ui->actionEnableService->setVisible(true);
if (netctlCommand->isNetctlAutoRunning()) {
ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is running"));
ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Stop service"));
ui->actionRestartService->setVisible(true);
}
else {
ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Start service"));
ui->actionRestartService->setVisible(false);
ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is not running"));
netctlAutoRefreshButtons(0, 0);
return;
}
ui->tableWidget->setSortingEnabled(false);
ui->tableWidget->selectRow(-1);
ui->tableWidget->sortByColumn(0, Qt::AscendingOrder);
@ -88,24 +115,34 @@ void NetctlAutoWindow::netctlAutoAppendTable()
ui->tableWidget->setRowCount(profiles.count());
// create header
ui->tableWidget->setHorizontalHeaderLabels(QApplication::translate("NetctlAutoWindow", "Profile==Description==Active==Disabled")
ui->tableWidget->setHorizontalHeaderLabels(QApplication::translate("NetctlAutoWindow", "Name==Description==Active==Disabled")
.split(QString("==")));
// create items
for (int i=0; i<profiles.count(); i++) {
// name
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(profiles[i][0]));
ui->tableWidget->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
if (profiles[i][2] == QString("*")) {
QFont font;
font.setBold(true);
ui->tableWidget->item(i, 0)->setFont(font);
}
else if (profiles[i][2] == QString("!")) {
QFont font;
font.setItalic(true);
ui->tableWidget->item(i, 0)->setFont(font);
}
// description
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(profiles[i][1]));
ui->tableWidget->item(i, 1)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
if (profiles[i][2] == "*") {
if (profiles[i][2] == QString("*")) {
// active
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QApplication::translate("NetctlAutoWindow", "yes")));
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
else
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString("")));
if (profiles[i][2] == "!") {
if (profiles[i][2] == QString("!")) {
// disabled
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(QApplication::translate("NetctlAutoWindow", "yes")));
ui->tableWidget->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
@ -121,14 +158,17 @@ void NetctlAutoWindow::netctlAutoAppendTable()
#else
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
ui->tableWidget->setEnabled(true);
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Updated"));
netctlAutoRefreshButtons(0, 0);
update();
}
void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[contextualMenu]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]";
if (ui->tableWidget->currentItem() == 0)
return;
@ -153,32 +193,31 @@ void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
enableProfile->setVisible(true);
startProfile->setVisible(true);
if (ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 3)->text() == QString("yes")) {
enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
enableProfile->setIcon(QIcon::fromTheme("edit-delete"));
}
else {
// buttons
enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
enableProfile->setIcon(QIcon::fromTheme("edit-add"));
}
else {
enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
enableProfile->setIcon(QIcon::fromTheme("edit-delete"));
}
}
// actions
QAction *action = menu.exec(ui->tableWidget->viewport()->mapToGlobal(pos));
if (action == startProfile) {
if (debug) qDebug() << "[NetctlAutoWindow]" << "[contextualMenu]" << "Switch to profile";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Switch to profile";
netctlAutoStartProfile();
}
else if (action == enableProfile) {
if (debug) qDebug() << "[NetctlAutoWindow]" << "[contextualMenu]" << "Enable profile";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable profile";
netctlAutoEnableProfile();
}
else if (action == enableAllProfiles) {
if (debug) qDebug() << "[NetctlAutoWindow]" << "[contextualMenu]" << "Enable all profiles";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable all profiles";
netctlAutoEnableAllProfiles();
}
else if (action == disableAllProfiles) {
if (debug) qDebug() << "[NetctlAutoWindow]" << "[contextualMenu]" << "Disable all profiles";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Disable all profiles";
netctlAutoDisableAllProfiles();
}
}
@ -186,32 +225,111 @@ void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
void NetctlAutoWindow::netctlAutoDisableAllProfiles()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[disableAllProfiles]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoDisableAllProfiles]";
ui->tableWidget->setDisabled(true);
if (netctlCommand->autoDisableAllProfiles())
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoEnableProfile()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[enableProfile]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoEnableProfile]";
if (ui->tableWidget->currentItem() == 0)
return;
ui->tableWidget->setDisabled(true);
QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text();
if (netctlCommand->autoEnableProfile(profile))
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoEnableAllProfiles()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[enableAllProfiles]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoEnableAllProfiles]";
ui->tableWidget->setDisabled(true);
if (netctlCommand->autoEnableAllProfiles())
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoStartProfile()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[startProfile]";
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoStartProfile]";
if (ui->tableWidget->currentItem() == 0)
return;
ui->tableWidget->setDisabled(true);
QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text();
if (netctlCommand->autoStartProfile(profile))
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoEnableService()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoEnableService]";
if (netctlCommand->autoEnableService())
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoRestartService()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoRestartService]";
if (netctlCommand->autoRestartService())
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoStartService()
{
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoStartService]";
if (netctlCommand->autoStartService())
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoAppendTable();
}
void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous)
{
Q_UNUSED(previous);
if (debug) qDebug() << "[NetctlAutoWindow]" << "[refreshButtons]" << current->row();
if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoRefreshButtons]";
if (current == 0) {
// buttons
@ -239,14 +357,6 @@ void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTabl
ui->actionEnable->setVisible(true);
ui->actionSwitch->setVisible(true);
if (ui->tableWidget->item(current->row(), 3)->text() == QString("yes")) {
// buttons
ui->pushButton_enable->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
ui->pushButton_enable->setIcon(QIcon::fromTheme("edit-delete"));
// menu
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable profile"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete"));
}
else {
// buttons
ui->pushButton_enable->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
ui->pushButton_enable->setIcon(QIcon::fromTheme("edit-add"));
@ -254,5 +364,13 @@ void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTabl
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable profile"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-add"));
}
else {
// buttons
ui->pushButton_enable->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
ui->pushButton_enable->setIcon(QIcon::fromTheme("edit-delete"));
// menu
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable profile"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete"));
}
}
}

View File

@ -43,14 +43,19 @@ public slots:
void showWindow();
private slots:
void netctlAutoAppendTable();
// table
void netctlAutoAppendTable();
void netctlAutoContextualMenu(const QPoint &pos);
// netctl-auto
void netctlAutoDisableAllProfiles();
void netctlAutoEnableProfile();
void netctlAutoEnableAllProfiles();
void netctlAutoStartProfile();
void netctlAutoRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous);
// service
void netctlAutoEnableService();
void netctlAutoRestartService();
void netctlAutoStartService();
private:
Netctl *netctlCommand;

View File

@ -15,6 +15,16 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_info">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="contextMenuPolicy">
@ -40,7 +50,7 @@
</attribute>
<column>
<property name="text">
<string>Profile</string>
<string>Name</string>
</property>
</column>
<column>
@ -63,9 +73,12 @@
<item>
<layout class="QHBoxLayout" name="layout_buttons">
<item>
<widget class="QPushButton" name="pushButton_enable">
<widget class="QPushButton" name="pushButton_refresh">
<property name="text">
<string>Enable</string>
<string>Refresh</string>
</property>
<property name="icon">
<iconset theme="stock-refresh"/>
</property>
</widget>
</item>
@ -82,8 +95,21 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_enable">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_switch">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Switch</string>
</property>
@ -109,16 +135,23 @@
<property name="title">
<string>Menu</string>
</property>
<addaction name="actionRefresh"/>
<addaction name="separator"/>
<addaction name="actionSwitch"/>
<addaction name="actionEnable"/>
<addaction name="separator"/>
<addaction name="actionEnableAll"/>
<addaction name="actionDisableAll"/>
<addaction name="separator"/>
<addaction name="actionStartService"/>
<addaction name="actionRestartService"/>
<addaction name="actionEnableService"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
</widget>
<addaction name="menuMenu"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionEnable">
<property name="icon">
<iconset theme="edit-add">
@ -168,6 +201,29 @@
<string>Disable all profiles</string>
</property>
</action>
<action name="actionStartService">
<property name="text">
<string>Start service</string>
</property>
</action>
<action name="actionRestartService">
<property name="text">
<string>Restart service</string>
</property>
</action>
<action name="actionEnableService">
<property name="text">
<string>Enable service</string>
</property>
</action>
<action name="actionRefresh">
<property name="icon">
<iconset theme="stock-refresh"/>
</property>
<property name="text">
<string>Refresh</string>
</property>
</action>
</widget>
<resources/>
<connections/>

View File

@ -64,6 +64,7 @@ void SettingsWindow::createActions()
connect(ui->pushButton_profilePath, SIGNAL(clicked(bool)), SLOT(selectProfileDir()));
connect(ui->pushButton_rfkill, SIGNAL(clicked(bool)), SLOT(selectRfkillDir()));
connect(ui->pushButton_sudo, SIGNAL(clicked(bool)), SLOT(selectSudoPath()));
connect(ui->pushButton_systemctlPath, SIGNAL(clicked(bool)), SLOT(selectSystemctlPath()));
connect(ui->pushButton_wpaActiondPath, SIGNAL(clicked(bool)), SLOT(selectWpaActiondPath()));
connect(ui->pushButton_wpaCliPath, SIGNAL(clicked(bool)), SLOT(selectWpaCliPath()));
connect(ui->pushButton_wpaSupPath, SIGNAL(clicked(bool)), SLOT(selectWpaSupPath()));
@ -195,6 +196,20 @@ void SettingsWindow::selectSudoPath()
}
void SettingsWindow::selectSystemctlPath()
{
if (debug) qDebug() << "[SettingsWindow]" << "[selectSystemctlPath]";
QString filename = QFileDialog::getOpenFileName(
this,
QApplication::translate("SettingsWindow", "Select systemctl command"),
QString("/usr/bin/"),
QApplication::translate("SettingsWindow", "All files (*)"));
if (!filename.isEmpty())
ui->lineEdit_systemctlPath->setText(filename);
}
void SettingsWindow::selectWpaActiondPath()
{
if (debug) qDebug() << "[SettingsWindow]" << "[selectWpaActiondPath]";
@ -259,11 +274,13 @@ QMap<QString, QString> SettingsWindow::readSettings()
settings[QString("LANGUAGE")] = ui->comboBox_language->currentText();
settings[QString("NETCTL_PATH")] = ui->lineEdit_netctlPath->text();
settings[QString("NETCTLAUTO_PATH")] = ui->lineEdit_netctlAutoPath->text();
settings[QString("NETCTLAUTO_SERVICE")] = ui->lineEdit_netctlAutoService->text();
settings[QString("PID_FILE")] = ui->lineEdit_pid->text();
settings[QString("PREFERED_IFACE")] = ui->lineEdit_interface->text();
settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text();
settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text();
settings[QString("SUDO_PATH")] = ui->lineEdit_sudo->text();
settings[QString("SYSTEMCTL_PATH")] = ui->lineEdit_systemctlPath->text();
settings[QString("WPAACTIOND_PATH")] = ui->lineEdit_wpaActiondPath->text();
settings[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text();
settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text();
@ -290,11 +307,13 @@ void SettingsWindow::setSettings(const QMap<QString, QString> settings)
ui->comboBox_language->setCurrentIndex(i);
ui->lineEdit_netctlPath->setText(settings[QString("NETCTL_PATH")]);
ui->lineEdit_netctlAutoPath->setText(settings[QString("NETCTLAUTO_PATH")]);
ui->lineEdit_netctlAutoService->setText(settings[QString("NETCTLAUTO_SERVICE")]);
ui->lineEdit_pid->setText(settings[QString("PID_FILE")]);
ui->lineEdit_interface->setText(settings[QString("PREFERED_IFACE")]);
ui->lineEdit_profilePath->setText(settings[QString("PROFILE_DIR")]);
ui->lineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]);
ui->lineEdit_sudo->setText(settings[QString("SUDO_PATH")]);
ui->lineEdit_systemctlPath->setText(settings[QString("SYSTEMCTL_PATH")]);
ui->lineEdit_wpaActiondPath->setText(settings[QString("WPAACTIOND_PATH")]);
ui->lineEdit_wpaCliPath->setText(settings[QString("WPACLI_PATH")]);
ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]);
@ -318,11 +337,13 @@ QMap<QString, QString> SettingsWindow::getDefault()
settings[QString("LANGUAGE")] = QString("en");
settings[QString("NETCTL_PATH")] = QString("/usr/bin/netctl");
settings[QString("NETCTLAUTO_PATH")] = QString("/usr/bin/netctl-auto");
settings[QString("NETCTLAUTO_SERVICE")] = QString("netctl-auto");
settings[QString("PID_FILE")] = QString("/run/wpa_supplicant_netctl-gui.pid");
settings[QString("PREFERED_IFACE")] = QString("");
settings[QString("PROFILE_DIR")] = QString("/etc/netctl/");
settings[QString("RFKILL_DIR")] = QString("/sys/class/rfkill/");
settings[QString("SUDO_PATH")] = QString("/usr/bin/kdesu");
settings[QString("SYSTEMCTL_PATH")] = QString("/usr/bin/systemctl");
settings[QString("WPAACTIOND_PATH")] = QString("/usr/bin/wpa_actiond");
settings[QString("WPACLI_PATH")] = QString("/usr/bin/wpa_cli");
settings[QString("WPASUP_PATH")] = QString("/usr/bin/wpa_supplicant");

View File

@ -54,6 +54,7 @@ private slots:
void selectProfileDir();
void selectRfkillDir();
void selectSudoPath();
void selectSystemctlPath();
void selectWpaActiondPath();
void selectWpaCliPath();
void selectWpaSupPath();

View File

@ -73,6 +73,37 @@
<string>netctl</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_systemctlPath">
<item>
<widget class="QLabel" name="label_systemctlPath">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>systemctl path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_systemctlPath">
<property name="toolTip">
<string>Path to systemctl</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_systemctlPath">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_netctlPath">
<item>
@ -122,7 +153,7 @@
<item>
<widget class="QLineEdit" name="lineEdit_netctlAutoPath">
<property name="toolTip">
<string>Path to netctl</string>
<string>Path to netctl-auto</string>
</property>
</widget>
</item>
@ -135,6 +166,30 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_netctlAutoService">
<item>
<widget class="QLabel" name="label_netctlAutoService">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>netctl-auto service</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_netctlAutoService">
<property name="toolTip">
<string>Name of netctl-auto systemd service</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_profilePath">
<item>
@ -317,7 +372,7 @@
<item>
<widget class="QLineEdit" name="lineEdit_wpaActiondPath">
<property name="toolTip">
<string>Path to wpa_cli</string>
<string>Path to wpa_actiond</string>
</property>
</widget>
</item>

View File

@ -36,26 +36,48 @@ public:
QList<QStringList> getProfileListFromNetctlAuto();
QString getProfileDescription(const QString profile);
QStringList getProfileDescriptions(const QStringList profileList);
QString getProfileStatus(const QString profile);
QStringList getProfileStatuses(const QStringList profileList);
QString getSsidFromProfile(const QString profile);
bool isProfileActive(const QString profile);
bool isProfileEnabled(const QString profile);
bool autoIsProfileActive(const QString profile);
bool autoIsProfileEnabled(const QString profile);
bool isNetctlAutoEnabled();
bool isNetctlAutoRunning();
public slots:
// functions
// netctl
bool enableProfile(const QString profile);
bool restartProfile(const QString profile);
bool startProfile(const QString profile);
// netctl-auto
bool autoDisableAllProfiles();
bool autoEnableProfile(const QString profile);
bool autoEnableAllProfiles();
bool autoStartProfile(const QString profile);
// netctl-auto service
bool autoEnableService();
bool autoRestartService();
bool autoStartService();
private:
bool debug;
QDir *ifaceDirectory;
QString mainInterface;
QString netctlCommand;
QString netctlAutoCommand;
QString netctlAutoService;
QDir *profileDirectory;
QString sudoCommand;
QString systemctlCommand;
// functions
QString getNetctlOutput(const bool sudo, const QString commandLine, const QString profile);
QString getWifiInterface();
bool netctlCall(const bool sudo, const QString commandLine, const QString profile);
bool netctlAutoCall(const bool sudo, const QString commandLine, const QString profile = 0);
bool systemctlCall(const bool sudo, const QString commandLine);
};

View File

@ -25,10 +25,14 @@
Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> settings)
: debug(debugCmd)
{
ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
mainInterface = settings[QString("PREFERED_IFACE")];
netctlCommand = settings[QString("NETCTL_PATH")];
netctlAutoCommand = settings[QString("NETCTLAUTO_PATH")];
netctlAutoService = settings[QString("NETCTLAUTO_SERVICE")];
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
sudoCommand = settings[QString("SUDO_PATH")];
systemctlCommand = settings[QString("SYSTEMCTL_PATH")];
}
@ -36,6 +40,7 @@ Netctl::~Netctl()
{
if (debug) qDebug() << "[Netctl]" << "[~Netctl]";
delete ifaceDirectory;
delete profileDirectory;
}
@ -60,6 +65,27 @@ QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, cons
}
QString Netctl::getWifiInterface()
{
if (debug) qDebug() << "[Netctl]" << "[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() << "[Netctl]" << "[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[0];
}
bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[netctlCall]";
@ -83,6 +109,55 @@ bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QStrin
}
bool Netctl::netctlAutoCall(const bool sudo, const QString commandLine, const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]";
QProcess command;
QString commandText;
if (sudo)
commandText = sudoCommand + QString(" ") + netctlAutoCommand + QString(" ") + commandLine;
else
commandText = netctlAutoCommand + QString(" ") + commandLine;
if (profile != 0)
commandText = commandText + QString(" ") + profile;
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Cmd returns" << command.exitCode();
if (command.exitCode() == 0)
return true;
else
return false;
}
bool Netctl::systemctlCall(const bool sudo, const QString commandLine)
{
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]";
QString interface = getWifiInterface();
QProcess command;
QString commandText;
if (sudo)
commandText = sudoCommand + QString(" ") + systemctlCommand + QString(" ") + commandLine +
QString(" ") + netctlAutoService + QString("@") + interface + QString(".service");
else
commandText = systemctlCommand + QString(" ") + commandLine + QString(" ") + netctlAutoService +
QString("@") + interface + QString(".service");
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Cmd returns" << command.exitCode();
if (command.exitCode() == 0)
return true;
else
return false;
}
// general information
QList<QStringList> Netctl::getProfileList()
{
@ -191,6 +266,24 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList)
}
QString Netctl::getProfileStatus(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[getProfileStatus]";
QString status;
if (isProfileActive(profile))
status = QString("active");
else
status = QString("inactive");
if (isProfileEnabled(profile))
status = status + QString(" (enabled)");
else
status = status + QString(" (static)");
return status;
}
QStringList Netctl::getProfileStatuses(const QStringList profileList)
{
if (debug) qDebug() << "[Netctl]" << "[getProfileStatuses]";
@ -267,6 +360,78 @@ bool Netctl::isProfileEnabled(const QString profile)
}
bool Netctl::autoIsProfileActive(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileActive]";
bool status = false;
QList<QStringList> profiles = getProfileListFromNetctlAuto();
for (int i=0; i<profiles.count(); i++)
if ((profiles[i][0] == profile) && (profiles[i][2] == QString("*"))) {
status = true;
break;
}
return status;
}
bool Netctl::autoIsProfileEnabled(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]";
bool status = true;
QList<QStringList> profiles = getProfileListFromNetctlAuto();
for (int i=0; i<profiles.count(); i++)
if ((profiles[i][0] == profile) && (profiles[i][2] == QString("!"))) {
status = false;
break;
}
return status;
}
bool Netctl::isNetctlAutoEnabled()
{
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]";
QString interface = getWifiInterface();
QProcess command;
QString commandText = systemctlCommand + QString(" is-enabled ") + netctlAutoService + QString("@") +
interface + QString(".service");
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Cmd returns" << command.exitCode();
QString output = command.readAllStandardOutput().trimmed();
if (output == QString("enabled"))
return true;
else
return false;
}
bool Netctl::isNetctlAutoRunning()
{
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]";
QString interface = getWifiInterface();
QProcess command;
QString commandText = systemctlCommand + QString(" is-active ") + netctlAutoService + QString("@") +
interface + QString(".service");
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Cmd returns" << command.exitCode();
QString output = command.readAllStandardOutput().trimmed();
if (output == QString("active"))
return true;
else
return false;
}
// functions
bool Netctl::enableProfile(const QString profile)
{
@ -296,3 +461,74 @@ bool Netctl::startProfile(const QString profile)
else
return netctlCall(true, QString("start"), profile);
}
bool Netctl::autoDisableAllProfiles()
{
if (debug) qDebug() << "[Netctl]" << "[autoDisableAllProfiles]";
return netctlAutoCall(false, QString("disable-all"));
}
bool Netctl::autoEnableProfile(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[autoEnableProfile]";
if (autoIsProfileEnabled(profile))
return netctlAutoCall(false, QString("disable"), profile);
else
return netctlAutoCall(false, QString("enable"), profile);
}
bool Netctl::autoEnableAllProfiles()
{
if (debug) qDebug() << "[Netctl]" << "[autoEnableAllProfiles]";
return netctlAutoCall(false, QString("enable-all"));
}
bool Netctl::autoStartProfile(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[autoStartProfile]";
if (!autoIsProfileActive(profile))
return true;
else
return netctlAutoCall(false, QString("switch-to"), profile);
}
bool Netctl::autoEnableService()
{
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]";
if (isNetctlAutoEnabled())
return systemctlCall(true, QString("disable"));
else
return systemctlCall(true, QString("enable"));
}
bool Netctl::autoRestartService()
{
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]";
if (isNetctlAutoRunning())
return systemctlCall(true, QString("restart"));
else
return true;
}
bool Netctl::autoStartService()
{
if (debug) qDebug() << "[Netctl]" << "[autoStartService]";
if (isNetctlAutoRunning())
return systemctlCall(true, QString("stop"));
else
return systemctlCall(true, QString("start"));
}