diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 0f94fc5..0d909c5 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -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; itabWidget->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")]); diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index f9bd81f..556597f 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -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(); diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index 228e2c5..f6aa7a7 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -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 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; itableWidget->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")); + } } } diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index 0ee3453..b79c451 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -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; diff --git a/sources/gui/src/netctlautowindow.ui b/sources/gui/src/netctlautowindow.ui index c822d09..fbc61f4 100644 --- a/sources/gui/src/netctlautowindow.ui +++ b/sources/gui/src/netctlautowindow.ui @@ -15,6 +15,16 @@ + + + + + + + Qt::AlignCenter + + + @@ -40,7 +50,7 @@ - Profile + Name @@ -63,9 +73,12 @@ - + - Enable + Refresh + + + @@ -82,8 +95,21 @@ + + + + false + + + Enable + + + + + false + Switch @@ -109,16 +135,23 @@ Menu + + + + + + + @@ -168,6 +201,29 @@ Disable all profiles + + + Start service + + + + + Restart service + + + + + Enable service + + + + + + + + Refresh + + diff --git a/sources/gui/src/settingswindow.cpp b/sources/gui/src/settingswindow.cpp index 82f0b59..4c9c976 100644 --- a/sources/gui/src/settingswindow.cpp +++ b/sources/gui/src/settingswindow.cpp @@ -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 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 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 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"); diff --git a/sources/gui/src/settingswindow.h b/sources/gui/src/settingswindow.h index 13e994b..6b75cc9 100644 --- a/sources/gui/src/settingswindow.h +++ b/sources/gui/src/settingswindow.h @@ -54,6 +54,7 @@ private slots: void selectProfileDir(); void selectRfkillDir(); void selectSudoPath(); + void selectSystemctlPath(); void selectWpaActiondPath(); void selectWpaCliPath(); void selectWpaSupPath(); diff --git a/sources/gui/src/settingswindow.ui b/sources/gui/src/settingswindow.ui index b125944..46630bc 100644 --- a/sources/gui/src/settingswindow.ui +++ b/sources/gui/src/settingswindow.ui @@ -73,6 +73,37 @@ netctl + + + + + + + 150 + 0 + + + + systemctl path + + + + + + + Path to systemctl + + + + + + + Browse + + + + + @@ -122,7 +153,7 @@ - Path to netctl + Path to netctl-auto @@ -135,6 +166,30 @@ + + + + + + + 150 + 0 + + + + netctl-auto service + + + + + + + Name of netctl-auto systemd service + + + + + @@ -317,7 +372,7 @@ - Path to wpa_cli + Path to wpa_actiond diff --git a/sources/netctlgui/include/netctlgui/netctlinteract.h b/sources/netctlgui/include/netctlgui/netctlinteract.h index f7fa244..37d61e0 100644 --- a/sources/netctlgui/include/netctlgui/netctlinteract.h +++ b/sources/netctlgui/include/netctlgui/netctlinteract.h @@ -36,26 +36,48 @@ public: QList 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); }; diff --git a/sources/netctlgui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp index 1c10f32..1d15160 100644 --- a/sources/netctlgui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -25,10 +25,14 @@ Netctl::Netctl(const bool debugCmd, const QMap 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; ipath() + 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 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 profiles = getProfileListFromNetctlAuto(); + for (int i=0; i profiles = getProfileListFromNetctlAuto(); + for (int i=0; i