diff --git a/sources/.kdev4/sources.kdev4 b/sources/.kdev4/sources.kdev4 index d7d83c5..587b19d 100644 --- a/sources/.kdev4/sources.kdev4 +++ b/sources/.kdev4/sources.kdev4 @@ -8,7 +8,7 @@ ProjectRootRelative=./ [CMake][CMake Build Directory 0] Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build -Build Type=Release +Build Type=Debug CMake Binary=file:///usr/bin/cmake Environment Profile= Extra Arguments= diff --git a/sources/gui/src/commonfunctions.cpp b/sources/gui/src/commonfunctions.cpp new file mode 100644 index 0000000..8d82ec6 --- /dev/null +++ b/sources/gui/src/commonfunctions.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 "commonfunctions.h" + +#include +#include + +#include +#include + + +bool checkExternalApps(const QString apps, const QMap configuration, + const bool debug) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps; + + if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true; + QStringList cmd; + cmd.append("which"); + // avoid null-lines arguments + cmd.append("true"); + if ((apps == QString("helper")) || (apps == QString("all"))) { + cmd.append(configuration[QString("HELPER_PATH")]); + } + if ((apps == QString("netctl")) || (apps == QString("all"))) { + cmd.append(configuration[QString("NETCTL_PATH")]); + cmd.append(configuration[QString("NETCTLAUTO_PATH")]); + cmd.append(configuration[QString("SUDO_PATH")]); + } + if ((apps == QString("sudo")) || (apps == QString("wpasup")) || (apps == QString("all"))) { + cmd.append(configuration[QString("SUDO_PATH")]); + } + if ((apps == QString("systemctl")) || (apps == QString("all"))) { + cmd.append(configuration[QString("SYSTEMCTL_PATH")]); + cmd.append(configuration[QString("SUDO_PATH")]); + } + if ((apps == QString("wpasup")) || (apps == QString("wpasup-only")) || (apps == QString("all"))) { + cmd.append(configuration[QString("WPACLI_PATH")]); + cmd.append(configuration[QString("WPASUP_PATH")]); + } + + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' ')); + TaskResult process = runTask(cmd.join(QChar(' ')), false); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + if (process.exitCode != 0) + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; + + return (process.exitCode == 0); +} + + +QString checkStatus(const bool statusBool, const bool nullFalse) +{ + if (statusBool) return QApplication::translate("MainWindow", "yes"); + if (!nullFalse) return QApplication::translate("MainWindow", "no"); + + return QString(""); +} diff --git a/sources/gui/src/commonfunctions.h b/sources/gui/src/commonfunctions.h new file mode 100644 index 0000000..e6fa0a5 --- /dev/null +++ b/sources/gui/src/commonfunctions.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * 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 COMMONFUNCTIONS_H +#define COMMONFUNCTIONS_H + +#include +#include + + +bool checkExternalApps(const QString apps = QString("all"), + const QMap configuration = QMap(), + const bool debug = false); +QString checkStatus(const bool statusBool, const bool nullFalse = false); + + +#endif /* COMMONFUNCTIONS_H */ diff --git a/sources/gui/src/mainprivateslots.cpp b/sources/gui/src/mainprivateslots.cpp deleted file mode 100644 index 1df7f86..0000000 --- a/sources/gui/src/mainprivateslots.cpp +++ /dev/null @@ -1,1026 +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 "mainwindow.h" -#include "ui_mainwindow.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include "bridgewidget.h" -#include "dbusoperation.h" -#include "errorwindow.h" -#include "ethernetwidget.h" -#include "generalwidget.h" -#include "ipwidget.h" -#include "macvlanwidget.h" -#include "mobilewidget.h" -#include "passwdwidget.h" -#include "pppoewidget.h" -#include "tunnelwidget.h" -#include "tuntapwidget.h" -#include "version.h" -#include "vlanwidget.h" -#include "wirelesswidget.h" - - -void MainWindow::reportABug() -{ - if (debug) qDebug() << PDEBUG; - - if (QDesktopServices::openUrl(QUrl(QString(BUGTRACKER)))) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); -} - - -// menu update slots -void MainWindow::setMenuActionsShown(const bool state) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "State" << state; - - QStringList keys = toolBarActions.keys(); - for (int i=0; isetVisible(state); -} - - -void MainWindow::updateMenuMain() -{ - if (debug) qDebug() << PDEBUG; - actionMenu->setDefaultAction(toolBarActions[QString("mainStart")]); - - toolBarActions[QString("netctlAuto")]->setVisible(true); - toolBarActions[QString("mainRefresh")]->setVisible(true); - if (ui->tableWidget_main->currentItem() == nullptr) return; - if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) { - toolBarActions[QString("mainRestart")]->setVisible(true); - toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWindow", "Stop")); - toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("process-stop")); - } else { - toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWindow", "Start")); - toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("system-run")); - } - if (!mainTabGetActiveProfiles().isEmpty()) { - if (!mainTabGetActiveProfiles().contains(ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text())) - toolBarActions[QString("mainSwitch")]->setVisible(true); - toolBarActions[QString("mainStopAll")]->setVisible(true); - } - toolBarActions[QString("mainStart")]->setVisible(true); - if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) { - toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWindow", "Disable")); - toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("edit-remove")); - } else { - toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWindow", "Enable")); - toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("list-add")); - } - toolBarActions[QString("mainEnable")]->setVisible(true); - toolBarActions[QString("mainEdit")]->setVisible(true); - toolBarActions[QString("mainRemove")]->setVisible(true); -} - - -void MainWindow::updateMenuProfile() -{ - if (debug) qDebug() << PDEBUG; - actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]); - - toolBarActions[QString("profileClear")]->setVisible(true); - toolBarActions[QString("profileLoad")]->setVisible(!ui->comboBox_profile->currentText().isEmpty()); - toolBarActions[QString("profileRemove")]->setVisible(!ui->comboBox_profile->currentText().isEmpty()); - toolBarActions[QString("profileSave")]->setVisible(!ui->comboBox_profile->currentText().isEmpty()); -} - - -void MainWindow::updateMenuWifi() -{ - if (debug) qDebug() << PDEBUG; - actionMenu->setDefaultAction(toolBarActions[QString("wifiStart")]); - - toolBarActions[QString("wifiRefresh")]->setVisible(true); - if (ui->tableWidget_wifi->currentItem() == nullptr) return; - if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) { - toolBarActions[QString("wifiStart")]->setText(QApplication::translate("MainWindow", "Start")); - toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("system-run")); - } else { - toolBarActions[QString("wifiStart")]->setText(QApplication::translate("MainWindow", "Stop")); - toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("process-stop")); - } - toolBarActions[QString("wifiStart")]->setVisible(true); -} - - -// tab update slots -void MainWindow::updateMainTab() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - - ui->tabWidget->setDisabled(true); - QList profiles; - bool netctlAutoStatus = false; - if (useHelper) { - QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return updateMainTab(); - } - netctlAutoStatus = responce[0].toBool(); - profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); - } else { - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - profiles = netctlCommand->getProfileList(); - } - ui->widget_netctlAuto->setHidden(!netctlAutoStatus); - - ui->tableWidget_main->setSortingEnabled(false); - ui->tableWidget_main->selectRow(-1); - ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder); - ui->tableWidget_main->clear(); - ui->tableWidget_main->setRowCount(profiles.count()); - - // create header - QStringList headerList; - headerList.append(QApplication::translate("MainWindow", "Name")); - headerList.append(QApplication::translate("MainWindow", "Description")); - headerList.append(QApplication::translate("MainWindow", "Active")); - headerList.append(QApplication::translate("MainWindow", "Enabled")); - ui->tableWidget_main->setHorizontalHeaderLabels(headerList); - // create items - for (int i=0; itableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name)); - ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget_main->item(i, 0)->setToolTip(toolTip); - ui->tableWidget_main->item(i, 0)->setFont(font); - // description - ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(profiles[i].description)); - ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter); - ui->tableWidget_main->item(i, 1)->setToolTip(toolTip); - // active - ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(profiles[i].active, true))); - ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - // enabled - ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(profiles[i].enabled, true))); - ui->tableWidget_main->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - } - - ui->tableWidget_main->setSortingEnabled(true); - - ui->tableWidget_main->resizeRowsToContents(); - ui->tableWidget_main->resizeColumnsToContents(); - ui->tableWidget_main->resizeRowsToContents(); -#if QT_VERSION >= 0x050000 - ui->tableWidget_main->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); -#else - ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); -#endif - - ui->tabWidget->setEnabled(true); - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); - - update(); -} - - -void MainWindow::updateProfileTab() -{ - if (debug) qDebug() << PDEBUG; - - ui->tabWidget->setDisabled(true); - profileTabClear(); - ui->tabWidget->setEnabled(true); - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); - - update(); -} - - -void MainWindow::updateWifiTab() -{ - if (debug) qDebug() << PDEBUG; - wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"))); - if (!checkExternalApps(QString("wpasup"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - - ui->tabWidget->setDisabled(true); - QList scanResults; - if (useHelper) - scanResults = parseOutputWifi(sendRequestToCtrl(QString("VerboseWiFi"), debug)); - else - scanResults = wpaCommand->scanWifi(); - - ui->tableWidget_wifi->setSortingEnabled(false); - ui->tableWidget_wifi->selectRow(-1); - ui->tableWidget_wifi->sortByColumn(3, Qt::AscendingOrder); - ui->tableWidget_wifi->clear(); - ui->tableWidget_wifi->setRowCount(scanResults.count()); - - // create header - QStringList headerList; - headerList.append(QApplication::translate("MainWindow", "Name")); - headerList.append(QApplication::translate("MainWindow", "Type")); - headerList.append(QApplication::translate("MainWindow", "# of points")); - headerList.append(QApplication::translate("MainWindow", "Signal")); - headerList.append(QApplication::translate("MainWindow", "Security")); - headerList.append(QApplication::translate("MainWindow", "Active")); - headerList.append(QApplication::translate("MainWindow", "Exists")); - ui->tableWidget_wifi->setHorizontalHeaderLabels(headerList); - // create items - for (int i=0; itableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name)); - ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget_wifi->item(i, 0)->setToolTip(toolTip); - ui->tableWidget_wifi->item(i, 0)->setFont(font); - // type - ui->tableWidget_wifi->setItem(i, 1, new QTableWidgetItem(type)); - ui->tableWidget_wifi->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - ui->tableWidget_wifi->item(i, 1)->setToolTip(toolTip); - // count - ui->tableWidget_wifi->setItem(i, 2, new QTableWidgetItem(QString::number(scanResults[i].frequencies.count()))); - ui->tableWidget_wifi->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - ui->tableWidget_wifi->item(i, 2)->setToolTip(toolTip); - // signal - ui->tableWidget_wifi->setItem(i, 3, new QTableWidgetItem(QString::number(scanResults[i].signal))); - ui->tableWidget_wifi->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - ui->tableWidget_wifi->item(i, 3)->setToolTip(toolTip); - // security - ui->tableWidget_wifi->setItem(i, 4, new QTableWidgetItem(scanResults[i].security)); - ui->tableWidget_wifi->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - ui->tableWidget_wifi->item(i, 4)->setToolTip(toolTip); - // active - ui->tableWidget_wifi->setItem(i, 5, new QTableWidgetItem(checkStatus(scanResults[i].active, true))); - ui->tableWidget_wifi->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - // exists - ui->tableWidget_wifi->setItem(i, 6, new QTableWidgetItem(checkStatus(scanResults[i].exists, true))); - ui->tableWidget_wifi->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - } - - ui->tableWidget_wifi->setSortingEnabled(true); - - ui->tableWidget_wifi->resizeRowsToContents(); - ui->tableWidget_wifi->resizeColumnsToContents(); - ui->tableWidget_wifi->resizeRowsToContents(); -#if QT_VERSION >= 0x050000 - ui->tableWidget_wifi->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); -#else - ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); -#endif - - ui->tabWidget->setEnabled(true); - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); - - update(); -} - - -// main tab slots -void MainWindow::mainTabContextualMenu(const QPoint &pos) -{ - if (debug) qDebug() << PDEBUG; - if (ui->tableWidget_main->currentItem() == nullptr) return; - - // create menu - QMenu menu(this); - QAction *refreshTable = menu.addAction(QApplication::translate("MainWindow", "Refresh")); - refreshTable->setIcon(QIcon::fromTheme("view-refresh")); - menu.addSeparator(); - QAction *startProfile = menu.addAction(QApplication::translate("MainWindow", "Start profile")); - QAction *restartProfile = menu.addAction(QApplication::translate("MainWindow", "Restart profile")); - restartProfile->setIcon(QIcon::fromTheme("view-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("document-edit")); - QAction *removeProfile = menu.addAction(QApplication::translate("MainWindow", "Remove profile")); - removeProfile->setIcon(QIcon::fromTheme("edit-delete")); - - // set text - if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) { - restartProfile->setVisible(true); - startProfile->setText(QApplication::translate("MainWindow", "Stop profile")); - startProfile->setIcon(QIcon::fromTheme("process-stop")); - } else { - restartProfile->setVisible(false); - startProfile->setText(QApplication::translate("MainWindow", "Start profile")); - startProfile->setIcon(QIcon::fromTheme("system-run")); - } - if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) { - enableProfile->setText(QApplication::translate("MainWindow", "Disable profile")); - enableProfile->setIcon(QIcon::fromTheme("edit-remove")); - } else { - enableProfile->setText(QApplication::translate("MainWindow", "Enable profile")); - enableProfile->setIcon(QIcon::fromTheme("list-add")); - } - - // actions - QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos)); - if (action == refreshTable) { - if (debug) qDebug() << PDEBUG << ":" << "Refresh table"; - updateMainTab(); - } else if (action == startProfile) { - if (debug) qDebug() << PDEBUG << ":" << "Start profile"; - mainTabStartProfile(); - } else if (action == restartProfile) { - if (debug) qDebug() << PDEBUG << ":" << "Restart profile"; - mainTabRestartProfile(); - } else if (action == enableProfile) { - if (debug) qDebug() << PDEBUG << ":" << "Enable profile"; - mainTabEnableProfile(); - } else if (action == editProfile) { - if (debug) qDebug() << PDEBUG << ":" << "Edit profile"; - mainTabEditProfile(); - } else if (action == removeProfile) { - if (debug) qDebug() << PDEBUG << ":" << "Remove profile"; - mainTabRemoveProfile(); - } -} - - -void MainWindow::mainTabEditProfile() -{ - if (debug) qDebug() << PDEBUG; - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - ui->tabWidget->setCurrentIndex(1); - ui->comboBox_profile->addItem(profile); - ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count() - 1); -} - - -void MainWindow::mainTabEnableProfile() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - if (enableProfileSlot(profile)) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -QStringList MainWindow::mainTabGetActiveProfiles() -{ - if (debug) qDebug() << PDEBUG; - - QStringList profiles; - for (int i=0; itableWidget_main->rowCount(); i++) { - if (ui->tableWidget_main->item(i, 2)->text().isEmpty()) continue; - profiles.append(ui->tableWidget_main->item(i, 0)->text()); - } - - return profiles; -} - - -void MainWindow::mainTabRemoveProfile() -{ - if (debug) qDebug() << PDEBUG; - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - bool status = false; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return mainTabRemoveProfile(); - } - status = responce[0].toBool(); - } else - status = netctlProfile->removeProfile(profile); - if (status) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -void MainWindow::mainTabRestartProfile() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - if (restartProfileSlot(profile)) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -void MainWindow::mainTabStartProfile() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - if (startProfileSlot(profile)) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -void MainWindow::mainTabStopAllProfiles() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - - ui->tabWidget->setDisabled(true); - bool status = false; - if (useHelper) { - QList responce = sendRequestToCtrl(QString("StolAll"), debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return mainTabStopAllProfiles(); - } - status = responce[0].toBool(); - } else - status = netctlCommand->stopAllProfiles(); - if (status) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -void MainWindow::mainTabSwitchToProfile() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("netctl"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - if (ui->tableWidget_main->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); - if (switchToProfileSlot(profile)) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateMainTab(); -} - - -// profile tab slots -void MainWindow::profileTabChangeState(const QString current) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Current type" << current; - - generalWid->setVisible(true); - ipWid->setVisible((current != QString("pppoe")) && (current != QString("mobile_ppp"))); - bridgeWid->setVisible(current == QString("bridge")); - ethernetWid->setVisible((current == QString("ethernet")) || - (current == QString("vlan")) || - (current == QString("macvlan"))); - macvlanWid->setVisible(current == QString("macvlan")); - mobileWid->setVisible(current == QString("mobile_ppp")); - pppoeWid->setVisible(current == QString("pppoe")); - tunnelWid->setVisible(current == QString("tunnel")); - tuntapWid->setVisible(current == QString("tuntap")); - vlanWid->setVisible(current == QString("vlan")); - wirelessWid->setVisible(current == QString("wireless")); -} - - -void MainWindow::profileTabClear() -{ - if (debug) qDebug() << PDEBUG; - - ui->comboBox_profile->clear(); - QList profiles; - if (useHelper) - profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); - else - profiles = netctlCommand->getProfileList(); - for (int i=0; icomboBox_profile->addItem(profiles[i].name); - ui->comboBox_profile->setCurrentIndex(-1); - - generalWid->clear(); - ipWid->clear(); - bridgeWid->clear(); - ethernetWid->clear(); - macvlanWid->clear(); - mobileWid->clear(); - pppoeWid->clear(); - tunnelWid->clear(); - tuntapWid->clear(); - vlanWid->clear(); - wirelessWid->clear(); - - profileTabChangeState(generalWid->connectionType->currentText()); -} - - -void MainWindow::profileTabCreateProfile() -{ - if (debug) qDebug() << PDEBUG; - - // error checking - if (ui->comboBox_profile->currentText().isEmpty()) - return ErrorWindow::showWindow(3, QString(PDEBUG), debug); - if (generalWid->isOk() == 1) - return ErrorWindow::showWindow(4, QString(PDEBUG), debug); - else if (generalWid->isOk() == 2) - return ErrorWindow::showWindow(5, QString(PDEBUG), debug); - if ((generalWid->connectionType->currentText() == QString("ethernet")) || - (generalWid->connectionType->currentText() == QString("wireless")) || - (generalWid->connectionType->currentText() == QString("bond")) || - (generalWid->connectionType->currentText() == QString("dummy")) || - (generalWid->connectionType->currentText() == QString("bridge")) || - (generalWid->connectionType->currentText() == QString("tunnel")) || - (generalWid->connectionType->currentText() == QString("tuntap")) || - (generalWid->connectionType->currentText() == QString("vlan")) || - (generalWid->connectionType->currentText() == QString("macvlan")) || - (generalWid->connectionType->currentText() == QString("openvswitch"))) { - if (ipWid->isOk() == 1) - return ErrorWindow::showWindow(6, QString(PDEBUG), debug); - else if (ipWid->isOk() == 2) - return ErrorWindow::showWindow(6, QString(PDEBUG), debug); - } - if (generalWid->connectionType->currentText() == QString("ethernet")) { - if (ethernetWid->isOk() == 1) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - } else if (generalWid->connectionType->currentText() == QString("wireless")) { - if (wirelessWid->isOk() == 1) - return ErrorWindow::showWindow(8, QString(PDEBUG), debug); - else if (wirelessWid->isOk() == 2) - return ErrorWindow::showWindow(9, QString(PDEBUG), debug); - else if (wirelessWid->isOk() == 3) - return ErrorWindow::showWindow(10, QString(PDEBUG), debug); - else if (wirelessWid->isOk() == 4) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - else if (wirelessWid->isOk() == 5) - return ErrorWindow::showWindow(11, QString(PDEBUG), debug); - } else if (generalWid->connectionType->currentText() == QString("bridge")) { - } else if (generalWid->connectionType->currentText() == QString("pppoe")) { - if (pppoeWid->isOk() == 1) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - else if (pppoeWid->isOk() == 2) - return ErrorWindow::showWindow(12, QString(PDEBUG), debug); - else if (pppoeWid->isOk() == 3) - return ErrorWindow::showWindow(13, QString(PDEBUG), debug); - else if (pppoeWid->isOk() == 4) - return ErrorWindow::showWindow(12, QString(PDEBUG), debug); - } else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) { - if (mobileWid->isOk() == 1) - return ErrorWindow::showWindow(15, QString(PDEBUG), debug); - if (mobileWid->isOk() == 2) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - } - else if (generalWid->connectionType->currentText() == QString("tunnel")) { - if (tunnelWid->isOk() == 1) - return ErrorWindow::showWindow(20, QString(PDEBUG), debug); - } - else if (generalWid->connectionType->currentText() == QString("tuntap")) { - if (tuntapWid->isOk() == 1) - return ErrorWindow::showWindow(15, QString(PDEBUG), debug); - if (tuntapWid->isOk() == 2) - return ErrorWindow::showWindow(15, QString(PDEBUG), debug); - } - else if (generalWid->connectionType->currentText() == QString("vlan")) { - if (ethernetWid->isOk() == 1) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - } - else if (generalWid->connectionType->currentText() == QString("macvlan")) { - if (ethernetWid->isOk() == 1) - return ErrorWindow::showWindow(7, QString(PDEBUG), debug); - } - - ui->tabWidget->setDisabled(true); - // read settings - QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); - QMap settings; - settings = generalWid->getSettings(); - if (generalWid->connectionType->currentText() == QString("ethernet")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("wireless")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("bond")) || - (generalWid->connectionType->currentText() == QString("dummy")) || - (generalWid->connectionType->currentText() == QString("openvswitch"))) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; iconnectionType->currentText() == QString("bridge")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("pppoe")) { - QMap addSettings = pppoeWid->getSettings(); - for (int i=0; iconnectionType->currentText() == QString("mobile_ppp")) { - QMap addSettings = mobileWid->getSettings(); - for (int i=0; iconnectionType->currentText() == QString("tunnel")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("tuntap")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("vlan")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; igetSettings(); - for (int i=0; iconnectionType->currentText() == QString("macvlan")) { - QMap addSettings = ipWid->getSettings(); - for (int i=0; igetSettings(); - for (int i=0; igetSettings(); - for (int i=0; i args; - args.append(profile); - args.append(settingsList); - QList responce = sendRequestToCtrlWithArgs(QString("Create"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabCreateProfile(); - } - status = responce[0].toBool(); - - } else { - QString profileTempName = netctlProfile->createProfile(profile, settings); - status = netctlProfile->copyProfile(profileTempName); - } - if (status) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - - updateProfileTab(); -} - - -void MainWindow::profileTabLoadProfile() -{ - if (debug) qDebug() << PDEBUG; - - QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); - if (profile.isEmpty()) return; - QMap settings; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLibWithArgs(QString("Profile"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabLoadProfile(); - } - QStringList settingsList = responce[0].toStringList(); - for (int i=0; igetSettingsFromProfile(profile); - - if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); - - generalWid->setSettings(settings); - if (generalWid->connectionType->currentText() == QString("ethernet")) { - ipWid->setSettings(settings); - ethernetWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("wireless")) { - ipWid->setSettings(settings); - wirelessWid->setSettings(settings); - } else if ((generalWid->connectionType->currentText() == QString("bond")) || - (generalWid->connectionType->currentText() == QString("dummy")) || - (generalWid->connectionType->currentText() == QString("openvswitch"))) { - ipWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("bridge")) { - ipWid->setSettings(settings); - bridgeWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("pppoe")) { - pppoeWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) { - mobileWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("tunnel")) { - ipWid->setSettings(settings); - tunnelWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("tuntap")) { - ipWid->setSettings(settings); - tuntapWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("vlan")) { - ipWid->setSettings(settings); - ethernetWid->setSettings(settings); - vlanWid->setSettings(settings); - } else if (generalWid->connectionType->currentText() == QString("macvlan")) { - ipWid->setSettings(settings); - ethernetWid->setSettings(settings); - macvlanWid->setSettings(settings); - } -} - - -void MainWindow::profileTabRemoveProfile() -{ - if (debug) qDebug() << PDEBUG; - - ui->tabWidget->setDisabled(true); - QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); - if (profile.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); - bool status = false; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return profileTabLoadProfile(); - } - status = responce[0].toBool(); - } else - status = netctlProfile->removeProfile(profile); - if (status) - 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() << PDEBUG; - if (ui->tableWidget_wifi->currentItem() == nullptr) return; - - // create menu - QMenu menu(this); - QAction *refreshTable = menu.addAction(QApplication::translate("MainWindow", "Refresh")); - refreshTable->setIcon(QIcon::fromTheme("view-refresh")); - menu.addSeparator(); - QAction *startWifi = menu.addAction(QApplication::translate("MainWindow", "Start WiFi")); - - // set text - if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) { - startWifi->setText(QApplication::translate("MainWindow", "Start WiFi")); - startWifi->setIcon(QIcon::fromTheme("system-run")); - - } else { - startWifi->setText(QApplication::translate("MainWindow", "Stop WiFi")); - startWifi->setIcon(QIcon::fromTheme("process-stop")); - } - - // actions - QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos)); - if (action == refreshTable) { - if (debug) qDebug() << PDEBUG << ":" << "Refresh WiFi"; - updateWifiTab(); - } else if (action == startWifi) { - if (debug) qDebug() << PDEBUG << ":" << "Start WiFi"; - wifiTabStart(); - } -} - - -void MainWindow::wifiTabSetEnabled(const bool state) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "State" << state; - - ui->tableWidget_wifi->setHidden(!state); - ui->label_wifi->setHidden(state); -} - - -void MainWindow::wifiTabStart() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("wpasup"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return; - } - if (ui->tableWidget_wifi->currentItem() == nullptr) return; - - ui->tabWidget->setDisabled(true); - // name is hidden - if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("")) { - hiddenNetwork = true; - passwdWid = new PasswdWidget(this); - passwdWid->setPassword(false); - int widgetWidth = 2 * width() / 3; - int widgetHeight = 110; - int x = (width() - widgetWidth) / 2; - int y = (height() - widgetHeight) / 2; - passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); - passwdWid->show(); - passwdWid->setFocusToLineEdit(); - return; - } - - // name isn't hidden - hiddenNetwork = false; - QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); - QString profileName = QString(""); - if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 6)->text().isEmpty()) { - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLibWithArgs(QString("ProfileByEssid"), args, debug); - if (responce.isEmpty()) { - if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; - useHelper = false; - return wifiTabStart(); - } - profileName = responce[0].toString(); - } else - profileName = wpaCommand->existentProfile(profile); - if (startProfileSlot(profileName)) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - } else { - QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); - if (security == QString("none")) return connectToUnknownEssid(QString("")); - else { - passwdWid = new PasswdWidget(this); - passwdWid->setPassword(true); - int widgetWidth = 2 * width() / 3; - int widgetHeight = 110; - int x = (width() - widgetWidth) / 2; - int y = (height() - widgetHeight) / 2; - passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); - passwdWid->show(); - passwdWid->setFocusToLineEdit(); - return; - } - } - - updateWifiTab(); -} diff --git a/sources/gui/src/mainpublicslots.cpp b/sources/gui/src/mainpublicslots.cpp deleted file mode 100644 index ea5aba3..0000000 --- a/sources/gui/src/mainpublicslots.cpp +++ /dev/null @@ -1,495 +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 "mainwindow.h" -#include "ui_mainwindow.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "aboutwindow.h" -#include "dbusoperation.h" -#include "errorwindow.h" -#include "netctlautowindow.h" -#include "passwdwidget.h" -#include "settingswindow.h" -#include "trayicon.h" -#include "version.h" - - -void MainWindow::closeMainWindow() -{ - if (debug) qDebug() << PDEBUG; - - qApp->quit(); -} - - -void MainWindow::showAboutWindow() -{ - if (debug) qDebug() << PDEBUG; - - aboutWin->show(); -} - - -void MainWindow::showMainWindow() -{ - if (debug) qDebug() << PDEBUG; - - if (isHidden()) { - updateTabs(ui->tabWidget->currentIndex()); - show(); - } else - hide(); -} - - -void MainWindow::showNetctlAutoWindow() -{ - if (debug) qDebug() << PDEBUG; - - netctlAutoWin->showWindow(); -} - - -void MainWindow::showSettingsWindow() -{ - if (debug) qDebug() << PDEBUG; - - settingsWin->showWindow(); -} - - -bool MainWindow::enableProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Enable"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileEnabled(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->enableProfile(profile); - current = netctlCommand->isProfileEnabled(profile); - } - - return current; -} - - -bool MainWindow::restartProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Restart"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->restartProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - - return current; -} - - -bool MainWindow::startProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool current; - if (useHelper) { - QList args; - args.append(profile); - QList responce = sendRequestToLib(QString("ActiveProfile"), debug); - QStringList currentProfile; - if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - sendRequestToCtrlWithArgs(QString("Start"), args, debug); - else - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - QStringList currentProfile = netctlCommand->getActiveProfile(); - if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) - netctlCommand->startProfile(profile); - else - netctlCommand->switchToProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - - return current; -} - - -bool MainWindow::stopAllProfilesSlot() -{ - if (debug) qDebug() << PDEBUG; - - if (useHelper) - sendRequestToCtrl(QString("StolAll"), debug); - else - netctlCommand->stopAllProfiles(); - - return true; -} - - -bool MainWindow::switchToProfileSlot(const QString profile) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; - - bool netctlAutoStatus = false; - if (useHelper) { - QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); - if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); - } else - netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); - - bool current; - if (netctlAutoStatus) { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->autoIsProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->autoStartProfile(profile); - current = netctlCommand->autoIsProfileActive(profile); - } - } else { - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); - QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); - if (responce.isEmpty()) - current = netctlCommand->isProfileActive(profile); - else - current = responce[0].toBool(); - } else { - netctlCommand->switchToProfile(profile); - current = netctlCommand->isProfileActive(profile); - } - } - - return current; -} - - -void MainWindow::showApi() -{ - if (debug) qDebug() << PDEBUG; - - if (QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-dbus-api.html").arg(QString(DOCS_PATH))))) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); -} - - -void MainWindow::showLibrary() -{ - if (debug) qDebug() << PDEBUG; - - if (QDesktopServices::openUrl(QUrl(QString("%1html/index.html").arg(QString(DOCS_PATH))))) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); -} - - -void MainWindow::showSecurityNotes() -{ - if (debug) qDebug() << PDEBUG; - - if (QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-security-notes.html").arg(QString(DOCS_PATH))))) - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - else - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); -} - - -bool MainWindow::forceStartHelper() -{ - if (debug) qDebug() << PDEBUG; - if (!checkExternalApps(QString("helper"))) { - ErrorWindow::showWindow(1, QString(PDEBUG), debug); - emit(needToBeConfigured()); - return false; - } - - QString cmd = QString("%1 -c %2").arg(configuration[QString("HELPER_PATH")]).arg(configPath); - if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; - TaskResult process = runTask(cmd, false); - if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; - if (process.exitCode != 0) - if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; - - return (process.exitCode == 0); -} - - -bool MainWindow::forceStopHelper() -{ - if (debug) qDebug() << PDEBUG; - - QList responce = sendRequestToCtrl(QString("Close"), debug); - - return !responce.isEmpty(); -} - - -bool MainWindow::startHelper() -{ - if (debug) qDebug() << PDEBUG; - - if (isHelperActive()) - return forceStopHelper(); - else - return forceStartHelper(); -} - - -void MainWindow::setTab(int tab) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Set tab" << tab; - - if ((tab > 2) || (tab < 0)) tab = 0; - if (tab == ui->tabWidget->currentIndex()) - updateTabs(tab); - else - ui->tabWidget->setCurrentIndex(tab); -} - - -void MainWindow::updateConfiguration(const QMap args) -{ - if (debug) qDebug() << PDEBUG; - - deleteObjects(); - - settingsWin = new SettingsWindow(this, debug, configPath); - if (args[QString("default")].toBool()) - settingsWin->setDefault(); - configuration = settingsWin->getSettings(); - delete settingsWin; - QMap optionsDict = parseOptions(args[QString("options")].toString()); - for (int i=0; iremoveTranslator(translator); - QString language = Language::defineLanguage(configPath, args[QString("options")].toString()); - if (debug) qDebug() << PDEBUG << ":" << "Language is" << language; - qtTranslator->load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - qApp->installTranslator(qtTranslator); - translator->load(QString(":/translations/%1").arg(language)); - qApp->installTranslator(translator); - - createObjects(); - createActions(); - createToolBars(); - - // tray - trayIcon->setVisible(QSystemTrayIcon::isSystemTrayAvailable() && (configuration[QString("SYSTRAY")] == QString("true"))); - if (trayIcon->isVisible()) { - setHidden(configuration[QString("STARTTOTRAY")] == QString("true")); - if (args[QString("minimized")].toInt() == 1) - show(); - else if (args[QString("minimized")].toInt() == 2) - hide(); - } - else - show(); - - // update ui - setTab(args[QString("tab")].toInt() - 1); -} - - -void MainWindow::updateMenu() -{ - if (debug) qDebug() << PDEBUG; - - int tab = ui->tabWidget->currentIndex(); - setMenuActionsShown(false); - - switch (tab) { - case 1: - updateMenuProfile(); - break; - case 2: - updateMenuWifi(); - break; - case 0: - default: - updateMenuMain(); - break; - } -} - - -void MainWindow::updateTabs(const int tab) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab; - - switch (tab) { - case 1: - updateProfileTab(); - break; - case 2: - updateWifiTab(); - break; - case 0: - default: - updateMainTab(); - break; - } - updateMenu(); -} - - -void MainWindow::connectToUnknownEssid(const QString passwd) -{ - if (debug) qDebug() << PDEBUG; - - if (passwdWid != nullptr) delete passwdWid; - QStringList interfaces; - if (useHelper) { - QList responce = sendRequestToLib(QString("WirelessInterfaces"), debug); - if (responce.isEmpty()) - interfaces = netctlCommand->getWirelessInterfaceList(); - else - interfaces = responce[0].toStringList(); - } else - interfaces = netctlCommand->getWirelessInterfaceList(); - if (interfaces.isEmpty()) return; - - QMap settings; - settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); - settings[QString("Interface")] = interfaces[0]; - settings[QString("Connection")] = QString("wireless"); - QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text(); - if (security.contains(QString("WPA"))) - settings[QString("Security")] = QString("wpa"); - else if (security.contains(QString("WEP"))) - settings[QString("Security")] = QString("wep"); - else - settings[QString("Security")] = QString("none"); - settings[QString("ESSID")] = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text()); - if (!passwd.isEmpty()) - settings[QString("Key")] = QString("'%1'").arg(passwd); - settings[QString("IP")] = QString("dhcp"); - if (hiddenNetwork) - settings[QString("Hidden")] = QString("yes"); - - QString profile = QString("netctl-gui-%1").arg(settings[QString("ESSID")]); - profile.remove(QChar('"')).remove(QChar('\'')); - if (useHelper) { - QStringList settingsList; - for (int i=0; i args; - args.append(profile); - args.append(settingsList); - sendRequestToCtrlWithArgs(QString("Create"), args, debug); - } else { - QString profileTempName = netctlProfile->createProfile(profile, settings); - netctlProfile->copyProfile(profileTempName); - } - QString message; - if (startProfileSlot(profile)) { - message = QApplication::translate("MainWindow", "Connection is successfully."); - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); - } else { - message = QApplication::translate("MainWindow", "Connection failed."); - ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - } - message += QString("\n"); - message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile); - int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"), - message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save); - switch (select) { - case QMessageBox::Save: - break; - case QMessageBox::Discard: - default: - if (useHelper) { - QList args; - args.append(profile); - sendRequestToCtrlWithArgs(QString("Remove"), args, debug); - } else - netctlProfile->removeProfile(profile); - break; - } - - updateWifiTab(); -} - - -void MainWindow::setHiddenName(const QString name) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Set name" << name; - - ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name); - - wifiTabStart(); -} diff --git a/sources/gui/src/mainwidget.cpp b/sources/gui/src/mainwidget.cpp new file mode 100644 index 0000000..3c19386 --- /dev/null +++ b/sources/gui/src/mainwidget.cpp @@ -0,0 +1,502 @@ +/*************************************************************************** + * 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 "mainwidget.h" +#include "ui_mainwidget.h" + +#include +#include + +#include + +#include "commonfunctions.h" +#include "dbusoperation.h" +#include "errorwindow.h" +#include "mainwindow.h" +#include "netctlautowindow.h" + + +MainWidget::MainWidget(QWidget *parent, const QMap settings, const bool debugCmd) + : QWidget(parent), + debug(debugCmd), + configuration(settings) +{ + mainWindow = dynamic_cast(parent); + useHelper = (configuration[QString("USE_HELPER")] == QString("true")); + + createObjects(); + createToolBars(); + createActions(); +} + + +MainWidget::~MainWidget() +{ + if (debug) qDebug() << PDEBUG; + + deleteObjects(); +} + + +void MainWidget::showNetctlAutoWindow() +{ + if (debug) qDebug() << PDEBUG; + + netctlAutoWin->showWindow(); +} + + +void MainWidget::update() +{ + if (debug) qDebug() << PDEBUG; + + updateMainTab(); + updateMenuMain(); +} + + +void MainWidget::updateMenuMain() +{ + if (debug) qDebug() << PDEBUG; + + bool selected = (ui->tableWidget_main->currentItem() != nullptr); + toolBarActions[QString("mainStart")]->setVisible(selected); + toolBarActions[QString("mainEnable")]->setVisible(selected); + toolBarActions[QString("mainEdit")]->setVisible(selected); + toolBarActions[QString("mainRemove")]->setVisible(selected); + toolBarActions[QString("mainStopAll")]->setVisible(!mainTabGetActiveProfiles().isEmpty()); + + if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) { + // visible + toolBarActions[QString("mainRestart")]->setVisible(true); + toolBarActions[QString("mainSwitch")]->setVisible(true); + // text + toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWidget", "Stop")); + toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("process-stop")); + } else { + // visible + toolBarActions[QString("mainRestart")]->setVisible(false); + toolBarActions[QString("mainSwitch")]->setVisible(false); + // text + toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWidget", "Start")); + toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("system-run")); + } + if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) { + toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWidget", "Disable")); + toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("edit-remove")); + } else { + toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWidget", "Enable")); + toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("list-add")); + } +} + + +void MainWidget::updateMainTab() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + + mainWindow->setDisabled(true); + QList profiles; + bool netctlAutoStatus = false; + if (useHelper) { + QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return updateMainTab(); + } + netctlAutoStatus = responce[0].toBool(); + profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); + } else { + netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); + profiles = netctlCommand->getProfileList(); + } + ui->widget_netctlAuto->setHidden(!netctlAutoStatus); + + ui->tableWidget_main->setSortingEnabled(false); + ui->tableWidget_main->selectRow(-1); + ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder); + ui->tableWidget_main->clear(); + ui->tableWidget_main->setRowCount(profiles.count()); + + // create header + QStringList headerList; + headerList.append(QApplication::translate("MainWidget", "Name")); + headerList.append(QApplication::translate("MainWidget", "Description")); + headerList.append(QApplication::translate("MainWidget", "Active")); + headerList.append(QApplication::translate("MainWidget", "Enabled")); + ui->tableWidget_main->setHorizontalHeaderLabels(headerList); + // create items + for (int i=0; itableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name)); + ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget_main->item(i, 0)->setToolTip(toolTip); + ui->tableWidget_main->item(i, 0)->setFont(font); + // description + ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(profiles[i].description)); + ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter); + ui->tableWidget_main->item(i, 1)->setToolTip(toolTip); + // active + ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(profiles[i].active, true))); + ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + // enabled + ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(profiles[i].enabled, true))); + ui->tableWidget_main->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + } + + ui->tableWidget_main->setSortingEnabled(true); + + ui->tableWidget_main->resizeRowsToContents(); + ui->tableWidget_main->resizeColumnsToContents(); + ui->tableWidget_main->resizeRowsToContents(); +#if QT_VERSION >= 0x050000 + ui->tableWidget_main->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); +#else + ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); +#endif + + mainWindow->setDisabled(false); + mainWindow->showMessage(true); +} + + +void MainWidget::mainTabContextualMenu(const QPoint &pos) +{ + if (debug) qDebug() << PDEBUG; + if (ui->tableWidget_main->currentItem() == nullptr) return; + + // create menu + QMenu menu(this); + QAction *refreshTable = menu.addAction(QApplication::translate("MainWidget", "Refresh")); + refreshTable->setIcon(QIcon::fromTheme("view-refresh")); + menu.addSeparator(); + QAction *startProfile = menu.addAction(QApplication::translate("MainWidget", "Start profile")); + QAction *restartProfile = menu.addAction(QApplication::translate("MainWidget", "Restart profile")); + restartProfile->setIcon(QIcon::fromTheme("view-refresh")); + QAction *enableProfile = menu.addAction(QApplication::translate("MainWidget", "Enable profile")); + menu.addSeparator(); + QAction *editProfile = menu.addAction(QApplication::translate("MainWidget", "Edit profile")); + editProfile->setIcon(QIcon::fromTheme("document-edit")); + QAction *removeProfile = menu.addAction(QApplication::translate("MainWidget", "Remove profile")); + removeProfile->setIcon(QIcon::fromTheme("edit-delete")); + + // set text + if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) { + restartProfile->setVisible(true); + startProfile->setText(QApplication::translate("MainWidget", "Stop profile")); + startProfile->setIcon(QIcon::fromTheme("process-stop")); + } else { + restartProfile->setVisible(false); + startProfile->setText(QApplication::translate("MainWidget", "Start profile")); + startProfile->setIcon(QIcon::fromTheme("system-run")); + } + if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) { + enableProfile->setText(QApplication::translate("MainWidget", "Disable profile")); + enableProfile->setIcon(QIcon::fromTheme("edit-remove")); + } else { + enableProfile->setText(QApplication::translate("MainWidget", "Enable profile")); + enableProfile->setIcon(QIcon::fromTheme("list-add")); + } + + // actions + QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos)); + if (action == refreshTable) { + if (debug) qDebug() << PDEBUG << ":" << "Refresh table"; + updateMainTab(); + } else if (action == startProfile) { + if (debug) qDebug() << PDEBUG << ":" << "Start profile"; + mainTabStartProfile(); + } else if (action == restartProfile) { + if (debug) qDebug() << PDEBUG << ":" << "Restart profile"; + mainTabRestartProfile(); + } else if (action == enableProfile) { + if (debug) qDebug() << PDEBUG << ":" << "Enable profile"; + mainTabEnableProfile(); + } else if (action == editProfile) { + if (debug) qDebug() << PDEBUG << ":" << "Edit profile"; + mainTabEditProfile(); + } else if (action == removeProfile) { + if (debug) qDebug() << PDEBUG << ":" << "Remove profile"; + mainTabRemoveProfile(); + } +} + + +void MainWidget::mainTabEditProfile() +{ + if (debug) qDebug() << PDEBUG; + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + mainWindow->setTab(1); + mainWindow->openProfileSlot(profile); +} + + +void MainWidget::mainTabEnableProfile() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + mainWindow->showMessage(mainWindow->enableProfileSlot(profile)); + + updateMainTab(); +} + + +QStringList MainWidget::mainTabGetActiveProfiles() +{ + if (debug) qDebug() << PDEBUG; + + QStringList profiles; + for (int i=0; itableWidget_main->rowCount(); i++) { + if (ui->tableWidget_main->item(i, 2)->text().isEmpty()) continue; + profiles.append(ui->tableWidget_main->item(i, 0)->text()); + } + + return profiles; +} + + +void MainWidget::mainTabRemoveProfile() +{ + if (debug) qDebug() << PDEBUG; + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + bool status = false; + if (useHelper) { + QList args; + args.append(profile); + QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return mainTabRemoveProfile(); + } + status = responce[0].toBool(); + } else + status = netctlProfile->removeProfile(profile); + mainWindow->showMessage(status); + + updateMainTab(); +} + + +void MainWidget::mainTabRestartProfile() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + mainWindow->showMessage(mainWindow->restartProfileSlot(profile)); + + updateMainTab(); +} + + +void MainWidget::mainTabStartProfile() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + mainWindow->showMessage(mainWindow->startProfileSlot(profile)); + + updateMainTab(); +} + + +void MainWidget::mainTabStopAllProfiles() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + + mainWindow->setDisabled(true); + bool status = false; + if (useHelper) { + QList responce = sendRequestToCtrl(QString("StolAll"), debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return mainTabStopAllProfiles(); + } + status = responce[0].toBool(); + } else + status = netctlCommand->stopAllProfiles(); + mainWindow->showMessage(status); + + updateMainTab(); +} + + +void MainWidget::mainTabSwitchToProfile() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("netctl"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + if (ui->tableWidget_main->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); + mainWindow->showMessage(mainWindow->switchToProfileSlot(profile)); + + updateMainTab(); +} + + +void MainWidget::createActions() +{ + if (debug) qDebug() << PDEBUG; + + // main tab events + connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow())); + connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); + connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), + this, SLOT(updateMenuMain())); + connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint))); +} + + +void MainWidget::createObjects() +{ + if (debug) qDebug() << PDEBUG; + + // backend + netctlCommand = new Netctl(debug, configuration); + netctlProfile = new NetctlProfile(debug, configuration); + // windows + ui = new Ui::MainWidget; + ui->setupUi(this); + ui->tableWidget_main->setColumnHidden(2, true); + ui->tableWidget_main->setColumnHidden(3, true); + netctlAutoWin = new NetctlAutoWindow(this, debug, configuration); +} + + +void MainWidget::createToolBars() +{ + if (debug) qDebug() << PDEBUG; + + actionToolBar = new QToolBar(this); + actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); + toolBarActions[QString("netctlAuto")] = actionToolBar->addAction(QApplication::translate("MainWidget", "netctl-auto"), + this, SLOT(showNetctlAutoWindow())); + toolBarActions[QString("mainRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")), + QApplication::translate("MainWidget", "Refresh"), + this, SLOT(updateMainTab())); + + actionMenu = new QToolButton(this); + actionMenu->setPopupMode(QToolButton::DelayedPopup); + actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle); + QMenu *menu = new QMenu(actionMenu); + toolBarActions[QString("mainStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")), + QApplication::translate("MainWidget", "Start"), + this, SLOT(mainTabStartProfile())); + toolBarActions[QString("mainSwitch")] = menu->addAction(QIcon::fromTheme(QString("system-run")), + QApplication::translate("MainWidget", "Switch"), + this, SLOT(mainTabSwitchToProfile())); + toolBarActions[QString("mainRestart")] = menu->addAction(QIcon::fromTheme(QString("view-refresh")), + QApplication::translate("MainWidget", "Restart"), + this, SLOT(mainTabRestartProfile())); + toolBarActions[QString("mainEnable")] = menu->addAction(QIcon::fromTheme(QString("list-add")), + QApplication::translate("MainWidget", "Enable"), + this, SLOT(mainTabEnableProfile())); + toolBarActions[QString("mainStopAll")] = menu->addAction(QIcon::fromTheme(QString("process-stop")), + QApplication::translate("MainWidget", "Stop all"), + this, SLOT(mainTabStopAllProfiles())); + actionMenu->setMenu(menu); + actionToolBar->addWidget(actionMenu); + + toolBarActions[QString("mainEdit")] = actionToolBar->addAction(QIcon::fromTheme(QString("document-edit")), + QApplication::translate("MainWidget", "Edit"), + this, SLOT(mainTabEditProfile())); + toolBarActions[QString("mainRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")), + QApplication::translate("MainWidget", "Remove"), + this, SLOT(mainTabRemoveProfile())); + + actionMenu->setDefaultAction(toolBarActions[QString("mainStart")]); + ui->verticalLayout->insertWidget(0, actionToolBar); +} + + +void MainWidget::deleteObjects() +{ + if (debug) qDebug() << PDEBUG; + + if (netctlCommand != nullptr) delete netctlCommand; + if (netctlProfile != nullptr) delete netctlProfile; + + if (netctlAutoWin != nullptr) delete netctlAutoWin; + if (actionMenu != nullptr) { + actionMenu->menu()->clear(); + delete actionMenu; + } + if (actionToolBar != nullptr) { + actionToolBar->clear(); + delete actionToolBar; + } + if (ui != nullptr) delete ui; +} diff --git a/sources/gui/src/mainwidget.h b/sources/gui/src/mainwidget.h new file mode 100644 index 0000000..7c40e78 --- /dev/null +++ b/sources/gui/src/mainwidget.h @@ -0,0 +1,88 @@ +/*************************************************************************** + * 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 MAINWIDGET_H +#define MAINWIDGET_H + +#include +#include +#include +#include + +#include + + +class MainWindow; +class NetctlAutoWindow; + +namespace Ui { +class MainWidget; +} + +class MainWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MainWidget(QWidget *parent = 0, + const QMap settings = QMap(), + const bool debugCmd = false); + ~MainWidget(); + +public slots: + void showNetctlAutoWindow(); + void update(); + +private slots: + // update slots + void updateMenuMain(); + void updateMainTab(); + // main tab slots + void mainTabContextualMenu(const QPoint &pos); + void mainTabEditProfile(); + void mainTabEnableProfile(); + QStringList mainTabGetActiveProfiles(); + void mainTabRemoveProfile(); + void mainTabRestartProfile(); + void mainTabStartProfile(); + void mainTabStopAllProfiles(); + void mainTabSwitchToProfile(); + +private: + // ui + QMap toolBarActions; + QToolButton *actionMenu = nullptr; + QToolBar *actionToolBar = nullptr; + MainWindow *mainWindow = nullptr; + Ui::MainWidget *ui = nullptr; + NetctlAutoWindow *netctlAutoWin = nullptr; + // backend + Netctl *netctlCommand = nullptr; + NetctlProfile *netctlProfile = nullptr; + void createActions(); + void createObjects(); + void createToolBars(); + void deleteObjects(); + QString configPath; + bool debug = false; + bool useHelper = true; + // configuration + QMap configuration; +}; + + +#endif /* MAINWIDGET_H */ diff --git a/sources/gui/src/mainwidget.ui b/sources/gui/src/mainwidget.ui new file mode 100644 index 0000000..286ef00 --- /dev/null +++ b/sources/gui/src/mainwidget.ui @@ -0,0 +1,93 @@ + + + MainWidget + + + + 0 + 0 + 516 + 477 + + + + Form + + + + + + + + + + 0 + 0 + + + + netctl-auto is running + + + + + + + Show + + + + + + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + 4 + + + true + + + false + + + + Name + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + Description + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + + + + + + + diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 2a22935..2fdf57a 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -21,32 +21,29 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include "aboutwindow.h" -#include "bridgewidget.h" +#include "commonfunctions.h" #include "dbusoperation.h" #include "errorwindow.h" -#include "ethernetwidget.h" -#include "generalwidget.h" -#include "ipwidget.h" -#include "macvlanwidget.h" -#include "mobilewidget.h" -#include "netctlautowindow.h" +#include "mainwidget.h" #include "netctlguiadaptor.h" +#include "newprofilewidget.h" #include "passwdwidget.h" -#include "pppoewidget.h" #include "settingswindow.h" #include "trayicon.h" -#include "tunnelwidget.h" -#include "tuntapwidget.h" #include "version.h" -#include "vlanwidget.h" -#include "wirelesswidget.h" +#include "wifimenuwidget.h" MainWindow::MainWindow(QWidget *parent, @@ -76,22 +73,22 @@ MainWindow::MainWindow(QWidget *parent, updateConfiguration(args); // main actions - if (args[QString("essid")].toString() != QString("ESSID")) { - for (int i=0; itableWidget_wifi->rowCount(); i++) - if (ui->tableWidget_wifi->item(i, 0)->text() == args[QString("essid")].toString()) - ui->tableWidget_wifi->setCurrentCell(i, 0); - if (ui->tableWidget_wifi->currentItem() == nullptr) - ErrorWindow::showWindow(18, QString(PDEBUG), debug); - } else if (args[QString("open")].toString() != QString("PROFILE")) { - ui->comboBox_profile->addItem(args[QString("open")].toString()); - ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1); - } else if (args[QString("select")].toString() != QString("PROFILE")) { - for (int i=0; itableWidget_main->rowCount(); i++) - if (ui->tableWidget_main->item(i, 0)->text() == args[QString("select")].toString()) - ui->tableWidget_main->setCurrentCell(i, 0); - if (ui->tableWidget_main->currentItem() == nullptr) - ErrorWindow::showWindow(17, QString(PDEBUG), debug); - } +// if (args[QString("essid")].toString() != QString("ESSID")) { +// for (int i=0; itableWidget_wifi->rowCount(); i++) +// if (ui->tableWidget_wifi->item(i, 0)->text() == args[QString("essid")].toString()) +// ui->tableWidget_wifi->setCurrentCell(i, 0); +// if (ui->tableWidget_wifi->currentItem() == nullptr) +// ErrorWindow::showWindow(18, QString(PDEBUG), debug); +// } else if (args[QString("open")].toString() != QString("PROFILE")) { +// ui->comboBox_profile->addItem(args[QString("open")].toString()); +// ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1); +// } else if (args[QString("select")].toString() != QString("PROFILE")) { +// for (int i=0; itableWidget_main->rowCount(); i++) +// if (ui->tableWidget_main->item(i, 0)->text() == args[QString("select")].toString()) +// ui->tableWidget_main->setCurrentCell(i, 0); +// if (ui->tableWidget_main->currentItem() == nullptr) +// ErrorWindow::showWindow(17, QString(PDEBUG), debug); +// } // show windows if (args[QString("about")].toBool()) @@ -271,38 +268,237 @@ void MainWindow::closeEvent(QCloseEvent *event) } -bool MainWindow::checkExternalApps(const QString apps = QString("all")) +// tray icon +void MainWindow::closeMainWindow() { if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps; - if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true; - QStringList cmd; - cmd.append("which"); - // avoid null-lines arguments - cmd.append("true"); - if ((apps == QString("helper")) || (apps == QString("all"))) { - cmd.append(configuration[QString("HELPER_PATH")]); - } - if ((apps == QString("netctl")) || (apps == QString("all"))) { - cmd.append(configuration[QString("NETCTL_PATH")]); - cmd.append(configuration[QString("NETCTLAUTO_PATH")]); - cmd.append(configuration[QString("SUDO_PATH")]); - } - if ((apps == QString("sudo")) || (apps == QString("wpasup")) || (apps == QString("all"))) { - cmd.append(configuration[QString("SUDO_PATH")]); - } - if ((apps == QString("systemctl")) || (apps == QString("all"))) { - cmd.append(configuration[QString("SYSTEMCTL_PATH")]); - cmd.append(configuration[QString("SUDO_PATH")]); - } - if ((apps == QString("wpasup")) || (apps == QString("wpasup-only")) || (apps == QString("all"))) { - cmd.append(configuration[QString("WPACLI_PATH")]); - cmd.append(configuration[QString("WPASUP_PATH")]); + qApp->quit(); +} + + +void MainWindow::showAboutWindow() +{ + if (debug) qDebug() << PDEBUG; + + aboutWin->show(); +} + + +void MainWindow::showMainWindow() +{ + if (debug) qDebug() << PDEBUG; + + if (isHidden()) { + updateTabs(ui->stackedWidget->currentIndex()); + show(); + } else + hide(); +} + + +void MainWindow::showNetctlAutoWindow() +{ + if (debug) qDebug() << PDEBUG; + + mainWidget->showNetctlAutoWindow(); +} + + +void MainWindow::showSettingsWindow() +{ + if (debug) qDebug() << PDEBUG; + + settingsWin->showWindow(); +} + + +bool MainWindow::enableProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("Enable"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileEnabled(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->enableProfile(profile); + current = netctlCommand->isProfileEnabled(profile); } - if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' ')); - TaskResult process = runTask(cmd.join(QChar(' ')), false); + return current; +} + + +void MainWindow::openProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + + newProfileWidget->profileTabOpenProfile(profile); +} + + +bool MainWindow::restartProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("Restart"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->restartProfile(profile); + current = netctlCommand->isProfileActive(profile); + } + + return current; +} + + +bool MainWindow::startProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool current; + if (useHelper) { + QList args; + args.append(profile); + QList responce = sendRequestToLib(QString("ActiveProfile"), debug); + QStringList currentProfile; + if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|')); + if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) + sendRequestToCtrlWithArgs(QString("Start"), args, debug); + else + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + QStringList currentProfile = netctlCommand->getActiveProfile(); + if ((currentProfile.isEmpty()) || (currentProfile.contains(profile))) + netctlCommand->startProfile(profile); + else + netctlCommand->switchToProfile(profile); + current = netctlCommand->isProfileActive(profile); + } + + return current; +} + + +bool MainWindow::stopAllProfilesSlot() +{ + if (debug) qDebug() << PDEBUG; + + if (useHelper) + sendRequestToCtrl(QString("StolAll"), debug); + else + netctlCommand->stopAllProfiles(); + + return true; +} + + +bool MainWindow::switchToProfileSlot(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + + bool netctlAutoStatus = false; + if (useHelper) { + QList responce = sendRequestToLib(QString("isNetctlAutoActive"), debug); + if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool(); + } else + netctlAutoStatus = netctlCommand->isNetctlAutoRunning(); + + bool current; + if (netctlAutoStatus) { + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("autoStart"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->autoIsProfileActive(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->autoStartProfile(profile); + current = netctlCommand->autoIsProfileActive(profile); + } + } else { + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug); + QList responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug); + if (responce.isEmpty()) + current = netctlCommand->isProfileActive(profile); + else + current = responce[0].toBool(); + } else { + netctlCommand->switchToProfile(profile); + current = netctlCommand->isProfileActive(profile); + } + } + + return current; +} + + +void MainWindow::showApi() +{ + if (debug) qDebug() << PDEBUG; + + showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-dbus-api.html").arg(QString(DOCS_PATH))))); +} + + +void MainWindow::showLibrary() +{ + if (debug) qDebug() << PDEBUG; + + showMessage(QDesktopServices::openUrl(QUrl(QString("%1html/index.html").arg(QString(DOCS_PATH))))); +} + + +void MainWindow::showSecurityNotes() +{ + if (debug) qDebug() << PDEBUG; + + showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-security-notes.html").arg(QString(DOCS_PATH))))); +} + + +bool MainWindow::forceStartHelper() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("helper"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(needToBeConfigured()); + return false; + } + + QString cmd = QString("%1 -c %2").arg(configuration[QString("HELPER_PATH")]).arg(configPath); + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; + TaskResult process = runTask(cmd, false); if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; @@ -311,6 +507,166 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all")) } +bool MainWindow::forceStopHelper() +{ + if (debug) qDebug() << PDEBUG; + + QList responce = sendRequestToCtrl(QString("Close"), debug); + + return !responce.isEmpty(); +} + + +bool MainWindow::startHelper() +{ + if (debug) qDebug() << PDEBUG; + + if (isHelperActive()) + return forceStopHelper(); + else + return forceStartHelper(); +} + + +void MainWindow::setDisabled(const bool disabled) +{ + if (debug) qDebug() << PDEBUG; + + ui->toolBar->setDisabled(disabled); + ui->stackedWidget->setDisabled(disabled); +} + + +void MainWindow::setTab(int tab) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Set tab" << tab; + + if ((tab > 2) || (tab < 0)) tab = 0; + if (tab == ui->stackedWidget->currentIndex()) + updateTabs(tab); + else + ui->stackedWidget->setCurrentIndex(tab); +} + + +void MainWindow::showMessage(const bool status) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Status" << status; + + if (status) + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); + else + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); +} + + +void MainWindow::updateConfiguration(const QMap args) +{ + if (debug) qDebug() << PDEBUG; + + deleteObjects(); + + settingsWin = new SettingsWindow(this, debug, configPath); + if (args[QString("default")].toBool()) + settingsWin->setDefault(); + configuration = settingsWin->getSettings(); + delete settingsWin; + QMap optionsDict = parseOptions(args[QString("options")].toString()); + for (int i=0; iremoveTranslator(translator); + QString language = Language::defineLanguage(configPath, args[QString("options")].toString()); + if (debug) qDebug() << PDEBUG << ":" << "Language is" << language; + qtTranslator->load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + qApp->installTranslator(qtTranslator); + translator->load(QString(":/translations/%1").arg(language)); + qApp->installTranslator(translator); + + createObjects(); + createActions(); + + // tray + trayIcon->setVisible(QSystemTrayIcon::isSystemTrayAvailable() && (configuration[QString("SYSTRAY")] == QString("true"))); + if (trayIcon->isVisible()) { + setHidden(configuration[QString("STARTTOTRAY")] == QString("true")); + if (args[QString("minimized")].toInt() == 1) + show(); + else if (args[QString("minimized")].toInt() == 2) + hide(); + } + else + show(); + + // update ui + setTab(args[QString("tab")].toInt() - 1); +} + + +void MainWindow::updateTabs(const int tab) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab; + + switch (tab) { + case 1: + newProfileWidget->update(); + break; + case 2: + wifiMenuWidget->update(); + break; + case 0: + default: + mainWidget->update(); + break; + } +} + + +// private slots +void MainWindow::setMainTab() +{ + if (debug) qDebug() << PDEBUG; + + return setTab(0); +} + + +void MainWindow::setProfileTab() +{ + if (debug) qDebug() << PDEBUG; + + return setTab(1); +} + + +void MainWindow::setWifiTab() +{ + if (debug) qDebug() << PDEBUG; + + return setTab(2); +} + + +void MainWindow::reportABug() +{ + if (debug) qDebug() << PDEBUG; + + showMessage(QDesktopServices::openUrl(QUrl(QString(BUGTRACKER)))); +} + + +// window signals bool MainWindow::checkHelperStatus() { if (debug) qDebug() << PDEBUG; @@ -327,25 +683,14 @@ bool MainWindow::checkHelperStatus() } -QString MainWindow::checkStatus(const bool statusBool, const bool nullFalse) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Status" << statusBool; - if (debug) qDebug() << PDEBUG << ":" << "Return null on false" << nullFalse; - - if (statusBool) return QApplication::translate("MainWindow", "yes"); - if (!nullFalse) return QApplication::translate("MainWindow", "no"); - - return QString(""); -} - - -// window signals void MainWindow::createActions() { if (debug) qDebug() << PDEBUG; - connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int))); + connect(ui->actionConnect_to_profile, SIGNAL(triggered()), this, SLOT(setMainTab())); + connect(ui->actionCreate_a_new_profile, SIGNAL(triggered()), this, SLOT(setProfileTab())); + connect(ui->actionWiFi_menu, SIGNAL(triggered()), this, SLOT(setWifiTab())); + connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(setTab(int))); connect(this, SIGNAL(needToBeConfigured()), this, SLOT(showSettingsWindow())); // menu @@ -356,25 +701,6 @@ void MainWindow::createActions() connect(ui->actionReport_a_bug, SIGNAL(triggered()), this, SLOT(reportABug())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutWindow())); connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(closeMainWindow())); - - // main tab events - connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow())); - connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); - connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), - this, SLOT(updateMenuMain())); - connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint))); - - // profile tab events - connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile())); - connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile())); - connect(ui->comboBox_profile->lineEdit(), SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile())); - connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString))); - - // wifi tab events - connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart())); - connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), - this, SLOT(updateMenuWifi())); - connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint))); } @@ -409,107 +735,19 @@ void MainWindow::createObjects() checkHelperStatus(); netctlCommand = new Netctl(debug, configuration); - netctlProfile = new NetctlProfile(debug, configuration); - wpaCommand = new WpaSup(debug, configuration); // frontend + mainWidget = new MainWidget(this, configuration, debug); + newProfileWidget = new NewProfileWidget(this, configuration, debug); + wifiMenuWidget = new WiFiMenuWidget(this, configuration, debug); trayIcon = new TrayIcon(this, debug); // windows ui = new Ui::MainWindow; ui->setupUi(this); - ui->tableWidget_main->setColumnHidden(2, true); - ui->tableWidget_main->setColumnHidden(3, true); - ui->tableWidget_wifi->setColumnHidden(5, true); - ui->tableWidget_wifi->setColumnHidden(6, true); + ui->layout_main->addWidget(mainWidget); + ui->layout_new->addWidget(newProfileWidget); + ui->layout_wifi->addWidget(wifiMenuWidget); aboutWin = new AboutWindow(this, debug); - netctlAutoWin = new NetctlAutoWindow(this, debug, configuration); settingsWin = new SettingsWindow(this, debug, configPath); - // profile widgets - generalWid = new GeneralWidget(this, configuration); - ui->scrollAreaWidgetContents->layout()->addWidget(generalWid); - ipWid = new IpWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(ipWid); - bridgeWid = new BridgeWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid); - ethernetWid = new EthernetWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid); - macvlanWid = new MacvlanWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid); - mobileWid = new MobileWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid); - pppoeWid = new PppoeWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid); - tunnelWid = new TunnelWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid); - tuntapWid = new TuntapWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid); - vlanWid = new VlanWidget(this); - ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid); - wirelessWid = new WirelessWidget(this, configuration); - ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid); -} - - -void MainWindow::createToolBars() -{ - if (debug) qDebug() << PDEBUG; - - actionToolBar = new QToolBar(this); - actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); - toolBarActions[QString("netctlAuto")] = actionToolBar->addAction(QApplication::translate("MainWindow", "netctl-auto"), - this, SLOT(showNetctlAutoWindow())); - toolBarActions[QString("mainRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")), - QApplication::translate("MainWindow", "Refresh"), - this, SLOT(updateMainTab())); - toolBarActions[QString("profileClear")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-clear")), - QApplication::translate("MainWindow", "Clear"), - this, SLOT(profileTabClear())); - toolBarActions[QString("wifiRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")), - QApplication::translate("MainWindow", "Refresh"), - this, SLOT(updateWifiTab())); - - actionMenu = new QToolButton(this); - actionMenu->setPopupMode(QToolButton::DelayedPopup); - actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle); - QMenu *menu = new QMenu(actionMenu); - toolBarActions[QString("mainStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")), - QApplication::translate("MainWindow", "Start"), - this, SLOT(mainTabStartProfile())); - toolBarActions[QString("mainSwitch")] = menu->addAction(QIcon::fromTheme(QString("system-run")), - QApplication::translate("MainWindow", "Switch"), - this, SLOT(mainTabSwitchToProfile())); - toolBarActions[QString("mainRestart")] = menu->addAction(QIcon::fromTheme(QString("view-refresh")), - QApplication::translate("MainWindow", "Restart"), - this, SLOT(mainTabRestartProfile())); - toolBarActions[QString("mainEnable")] = menu->addAction(QIcon::fromTheme(QString("list-add")), - QApplication::translate("MainWindow", "Enable"), - this, SLOT(mainTabEnableProfile())); - toolBarActions[QString("mainStopAll")] = menu->addAction(QIcon::fromTheme(QString("process-stop")), - QApplication::translate("MainWindow", "Stop all"), - this, SLOT(mainTabStopAllProfiles())); - toolBarActions[QString("profileLoad")] = menu->addAction(QIcon::fromTheme(QString("document-open")), - QApplication::translate("MainWindow", "Load"), - this, SLOT(profileTabLoadProfile())); - toolBarActions[QString("profileSave")] = menu->addAction(QIcon::fromTheme(QString("document-save")), - QApplication::translate("MainWindow", "Save"), - this, SLOT(profileTabCreateProfile())); - toolBarActions[QString("wifiStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")), - QApplication::translate("MainWindow", "Start"), - this, SLOT(wifiTabStart())); - actionMenu->setMenu(menu); - actionToolBar->addWidget(actionMenu); - - toolBarActions[QString("mainEdit")] = actionToolBar->addAction(QIcon::fromTheme(QString("document-edit")), - QApplication::translate("MainWindow", "Edit"), - this, SLOT(mainTabEditProfile())); - toolBarActions[QString("mainRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")), - QApplication::translate("MainWindow", "Remove"), - this, SLOT(mainTabRemoveProfile())); - toolBarActions[QString("profileRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")), - QApplication::translate("MainWindow", "Remove"), - this, SLOT(profileTabRemoveProfile())); - - setMenuActionsShown(false); - ui->centralLayout->insertWidget(0, actionToolBar); } @@ -520,33 +758,13 @@ void MainWindow::deleteObjects() QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH); QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE); if (netctlCommand != nullptr) delete netctlCommand; - if (netctlProfile != nullptr) delete netctlProfile; - if (wpaCommand != nullptr) delete wpaCommand; - - if (bridgeWid != nullptr) delete bridgeWid; - if (ethernetWid != nullptr) delete ethernetWid; - if (generalWid != nullptr) delete generalWid; - if (ipWid != nullptr) delete ipWid; - if (macvlanWid != nullptr) delete macvlanWid; - if (mobileWid != nullptr) delete mobileWid; - if (pppoeWid != nullptr) delete pppoeWid; - if (tunnelWid != nullptr) delete tunnelWid; - if (tuntapWid != nullptr) delete tuntapWid; - if (vlanWid != nullptr) delete vlanWid; - if (wirelessWid != nullptr) delete wirelessWid; if (aboutWin != nullptr) delete aboutWin; - if (netctlAutoWin != nullptr) delete netctlAutoWin; if (settingsWin != nullptr) delete settingsWin; - if (actionMenu != nullptr) { - actionMenu->menu()->clear(); - delete actionMenu; - } - if (actionToolBar != nullptr) { - actionToolBar->clear(); - delete actionToolBar; - } if (trayIcon != nullptr) delete trayIcon; + if (mainWidget != nullptr) delete mainWidget; + if (newProfileWidget != nullptr) delete newProfileWidget; + if (wifiMenuWidget != nullptr) delete wifiMenuWidget; if (ui != nullptr) delete ui; } diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 2f1ee0f..4086cfe 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -20,29 +20,17 @@ #include #include -#include -#include -#include +#include #include class AboutWindow; -class BridgeWidget; -class EthernetWidget; -class GeneralWidget; -class IpWidget; -class MacvlanWidget; -class MobileWidget; -class NetctlAutoWindow; -class PasswdWidget; -class PppoeWidget; +class MainWidget; +class NewProfileWidget; class SettingsWindow; class TrayIcon; -class TunnelWidget; -class TuntapWidget; -class VlanWidget; -class WirelessWidget; +class WiFiMenuWidget; namespace Ui { class MainWindow; @@ -76,6 +64,7 @@ public slots: void showSettingsWindow(); // trayicon control slots bool enableProfileSlot(const QString profile); + void openProfileSlot(const QString profile); bool startProfileSlot(const QString profile); bool stopAllProfilesSlot(); bool switchToProfileSlot(const QString profile); @@ -89,86 +78,39 @@ public slots: bool forceStopHelper(); bool startHelper(); // main + void setDisabled(const bool disabled = true); void setTab(int tab); + void showMessage(const bool status); void updateConfiguration(const QMap args = QMap()); - void updateMenu(); void updateTabs(const int tab); - // wifi tab slots - void connectToUnknownEssid(const QString passwd); - void setHiddenName(const QString name); signals: void needToBeConfigured(); private slots: + void setMainTab(); + void setProfileTab(); + void setWifiTab(); void reportABug(); - // menu update slots - void setMenuActionsShown(const bool state = true); - 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 mainTabEnableProfile(); - QStringList mainTabGetActiveProfiles(); - void mainTabRemoveProfile(); - void mainTabRestartProfile(); - void mainTabStartProfile(); - void mainTabStopAllProfiles(); - void mainTabSwitchToProfile(); - // profile tab slots - void profileTabChangeState(const QString current); - void profileTabClear(); - void profileTabCreateProfile(); - void profileTabLoadProfile(); - void profileTabRemoveProfile(); - // wifi tab slots - void wifiTabContextualMenu(const QPoint &pos); - void wifiTabSetEnabled(const bool state); - void wifiTabStart(); private: // ui TrayIcon *trayIcon = nullptr; - QMap toolBarActions; - QToolButton *actionMenu = nullptr; - QToolBar *actionToolBar = nullptr; Ui::MainWindow *ui = nullptr; AboutWindow *aboutWin = nullptr; - NetctlAutoWindow *netctlAutoWin = nullptr; - PasswdWidget *passwdWid = nullptr; + MainWidget *mainWidget = nullptr; + NewProfileWidget *newProfileWidget = nullptr; SettingsWindow *settingsWin = nullptr; - BridgeWidget *bridgeWid = nullptr; - EthernetWidget *ethernetWid = nullptr; - GeneralWidget *generalWid = nullptr; - IpWidget *ipWid = nullptr; - MacvlanWidget *macvlanWid = nullptr; - MobileWidget *mobileWid = nullptr; - PppoeWidget *pppoeWid = nullptr; - TunnelWidget *tunnelWid = nullptr; - TuntapWidget *tuntapWid = nullptr; - VlanWidget *vlanWid = nullptr; - WirelessWidget *wirelessWid = nullptr; + WiFiMenuWidget *wifiMenuWidget = nullptr; // backend Netctl *netctlCommand = nullptr; - NetctlProfile *netctlProfile = nullptr; - WpaSup *wpaCommand = nullptr; - bool checkExternalApps(const QString apps); bool checkHelperStatus(); - QString checkStatus(const bool statusBool, const bool nullFalse = false); void createActions(); void createDBusSession(); void createObjects(); - void createToolBars(); void deleteObjects(); QString configPath; bool debug = false; - bool hiddenNetwork; bool useHelper = true; QTranslator *qtTranslator = nullptr; QTranslator *translator = nullptr; diff --git a/sources/gui/src/mainwindow.ui b/sources/gui/src/mainwindow.ui index 80af7d2..37b84c7 100644 --- a/sources/gui/src/mainwindow.ui +++ b/sources/gui/src/mainwindow.ui @@ -16,261 +16,21 @@ - - - 0 + + + + 0 + 0 + - - - - :/icon.png:/icon.png - - - Connect to profile - - - - - - - - - - 0 - 0 - - - - netctl-auto is running - - - - - - - Show - - - - - - - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - 4 - - - true - - - false - - - - Name - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - Description - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - - - + + - - - - 0 - 0 - - - - - - - - - Create a new profile - - - - - - - - - 1 - 0 - - - - Profile - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 2 - 0 - - - - true - - - true - - - - - - - - - true - - - - - 0 - 0 - 518 - 369 - - - - - 0 - 0 - - - - - - - + + - - - - :/wifi.png:/wifi.png - - - WiFi menu - - - - - - Please install 'wpa_supplicant' before using it - - - Qt::AlignCenter - - - - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - 7 - - - true - - - false - - - - Name - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - Type - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - # of points - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - Signal - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - Security - - - AlignHCenter|AlignVCenter|AlignCenter - - - - - - - + + @@ -303,6 +63,23 @@ + + + false + + + Qt::ToolButtonFollowStyle + + + TopToolBarArea + + + false + + + + + @@ -369,13 +146,45 @@ Ctrl+S + + + + :/icon.png:/icon.png + + + Connect to profile + + + Ctrl+P + + + + + + + + Create a new profile + + + Create a new profile + + + Ctrl+N + + + + + + :/wifi.png:/wifi.png + + + WiFi menu + + + Ctrl+W + + - - tabWidget - tableWidget_main - scrollArea - tableWidget_wifi - diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index bae4f39..f601ec1 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -24,7 +24,6 @@ #include #include "dbusoperation.h" -// #include "version.h" NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap settings) @@ -38,7 +37,6 @@ NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const Q ui->tableWidget->setColumnHidden(3, true); netctlCommand = new Netctl(debug, settings); - createToolBars(); createActions(); ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready")); } @@ -50,14 +48,6 @@ NetctlAutoWindow::~NetctlAutoWindow() delete netctlCommand; - if (actionMenu != nullptr) { - actionMenu->menu()->clear(); - delete actionMenu; - } - if (actionToolBar != nullptr) { - actionToolBar->clear(); - delete actionToolBar; - } delete ui; } @@ -85,6 +75,7 @@ void NetctlAutoWindow::createActions() connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile())); connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles())); connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile())); + connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoUpdateTable())); // service connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService())); connect(ui->actionRestartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoRestartService())); @@ -97,32 +88,6 @@ void NetctlAutoWindow::createActions() } -void NetctlAutoWindow::createToolBars() -{ - if (debug) qDebug() << PDEBUG; - - actionToolBar = new QToolBar(this); - actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); - toolBarActions[QString("refresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")), - QApplication::translate("NetctlAutoWindow", "Refresh"), - this, SLOT(netctlAutoUpdateTable())); - - actionMenu = new QToolButton(this); - actionMenu->setPopupMode(QToolButton::DelayedPopup); - actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle); - QMenu *menu = new QMenu(actionMenu); - toolBarActions[QString("enable")] = menu->addAction(QApplication::translate("NetctlAutoWindow", "Enable"), - this, SLOT(netctlAutoEnableProfile())); - toolBarActions[QString("switch")] = menu->addAction(QIcon::fromTheme(QString("system-run")), - QApplication::translate("NetctlAutoWindow", "Switch"), - this, SLOT(netctlAutoStartProfile())); - actionMenu->setDefaultAction(toolBarActions[QString("switch")]); - actionMenu->setMenu(menu); - actionToolBar->addWidget(actionMenu); - ui->centralLayout->insertWidget(0, actionToolBar); -} - - void NetctlAutoWindow::showWindow() { if (debug) qDebug() << PDEBUG; @@ -477,31 +442,18 @@ void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTabl if (debug) qDebug() << PDEBUG; if (current == nullptr) { - // buttons - toolBarActions[QString("enable")]->setDisabled(true); - toolBarActions[QString("switch")]->setDisabled(true); // menu - ui->actionEnable->setVisible(false); - ui->actionSwitch->setVisible(false); + ui->actionEnable->setEnabled(false); + ui->actionSwitch->setEnabled(false); return; } - toolBarActions[QString("switch")]->setEnabled(ui->tableWidget->item(current->row(), 2)->text().isEmpty()); - ui->actionSwitch->setVisible(ui->tableWidget->item(current->row(), 2)->text().isEmpty()); - toolBarActions[QString("enable")]->setEnabled(true); - ui->actionEnable->setVisible(true); + ui->actionSwitch->setEnabled(ui->tableWidget->item(current->row(), 2)->text().isEmpty()); + ui->actionEnable->setEnabled(true); if (!ui->tableWidget->item(current->row(), 3)->text().isEmpty()) { - // buttons - toolBarActions[QString("enable")]->setText(QApplication::translate("NetctlAutoWindow", "Enable")); - toolBarActions[QString("enable")]->setIcon(QIcon::fromTheme("list-add")); - // menu - ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable profile")); + ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable")); ui->actionEnable->setIcon(QIcon::fromTheme("list-add")); } else { - // buttons - toolBarActions[QString("enable")]->setText(QApplication::translate("NetctlAutoWindow", "Disable")); - toolBarActions[QString("enable")]->setIcon(QIcon::fromTheme("edit-delete")); - // menu - ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable profile")); + ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable")); ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete")); } } diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index f6f7691..15ffd77 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -18,11 +18,8 @@ #ifndef NETCTLAUTOWINDOW_H #define NETCTLAUTOWINDOW_H -#include #include #include -#include -#include class Netctl; @@ -61,15 +58,11 @@ private slots: private: // ui - QMap toolBarActions; - QToolButton *actionMenu = nullptr; - QToolBar *actionToolBar = nullptr; Ui::NetctlAutoWindow *ui = nullptr; // backend Netctl *netctlCommand = nullptr; QString checkStatus(const bool statusBool, const bool nullFalse = false); void createActions(); - void createToolBars(); bool debug = false; bool useHelper = true; }; diff --git a/sources/gui/src/netctlautowindow.ui b/sources/gui/src/netctlautowindow.ui index b3e3907..11cd457 100644 --- a/sources/gui/src/netctlautowindow.ui +++ b/sources/gui/src/netctlautowindow.ui @@ -64,6 +64,24 @@ + + + + false + + + Qt::ToolButtonFollowStyle + + + TopToolBarArea + + + false + + + + + @@ -77,9 +95,6 @@ Menu - - - @@ -91,27 +106,6 @@ - - - - - - - - - Enable profile - - - - - - - - - - Switch to profile - - @@ -160,6 +154,39 @@ Enable service + + + + + + + + Refresh + + + Ctrl+R + + + + + + + + + + Enable + + + + + + + + + + Switch + + diff --git a/sources/gui/src/newprofilewidget.cpp b/sources/gui/src/newprofilewidget.cpp new file mode 100644 index 0000000..7c24dd5 --- /dev/null +++ b/sources/gui/src/newprofilewidget.cpp @@ -0,0 +1,534 @@ +/*************************************************************************** + * 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 "newprofilewidget.h" +#include "ui_newprofilewidget.h" + +#include +#include +#include + +#include + +#include "bridgewidget.h" +#include "commonfunctions.h" +#include "dbusoperation.h" +#include "errorwindow.h" +#include "ethernetwidget.h" +#include "generalwidget.h" +#include "ipwidget.h" +#include "mainwindow.h" +#include "macvlanwidget.h" +#include "mobilewidget.h" +#include "pppoewidget.h" +#include "tunnelwidget.h" +#include "tuntapwidget.h" +#include "vlanwidget.h" +#include "wirelesswidget.h" + + +NewProfileWidget::NewProfileWidget(QWidget *parent, const QMap settings, const bool debugCmd) + : QWidget(parent), + debug(debugCmd), + configuration(settings) +{ + mainWindow = dynamic_cast(parent); + useHelper = (configuration[QString("USE_HELPER")] == QString("true")); + + createObjects(); + createToolBars(); + createActions(); +} + + +NewProfileWidget::~NewProfileWidget() +{ + if (debug) qDebug() << PDEBUG; + + deleteObjects(); +} + + +void NewProfileWidget::profileTabOpenProfile(const QString profile) +{ + if (debug) qDebug() << PDEBUG; + + ui->comboBox_profile->addItem(profile); + ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count() - 1); +} + + +void NewProfileWidget::update() +{ + if (debug) qDebug() << PDEBUG; + + updateProfileTab(); + updateMenuProfile(); +} + + +void NewProfileWidget::updateMenuProfile() +{ + if (debug) qDebug() << PDEBUG; + actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]); + + bool selected = !ui->comboBox_profile->currentText().isEmpty(); + toolBarActions[QString("profileLoad")]->setVisible(selected); + toolBarActions[QString("profileRemove")]->setVisible(selected); + toolBarActions[QString("profileSave")]->setVisible(selected); +} + + +void NewProfileWidget::updateProfileTab() +{ + if (debug) qDebug() << PDEBUG; + + mainWindow->setDisabled(true); + profileTabClear(); + mainWindow->setDisabled(false); + mainWindow->showMessage(true); +} + + +void NewProfileWidget::profileTabChangeState(const QString current) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Current type" << current; + + generalWid->setVisible(true); + ipWid->setVisible((current != QString("pppoe")) && (current != QString("mobile_ppp"))); + bridgeWid->setVisible(current == QString("bridge")); + ethernetWid->setVisible((current == QString("ethernet")) || + (current == QString("vlan")) || + (current == QString("macvlan"))); + macvlanWid->setVisible(current == QString("macvlan")); + mobileWid->setVisible(current == QString("mobile_ppp")); + pppoeWid->setVisible(current == QString("pppoe")); + tunnelWid->setVisible(current == QString("tunnel")); + tuntapWid->setVisible(current == QString("tuntap")); + vlanWid->setVisible(current == QString("vlan")); + wirelessWid->setVisible(current == QString("wireless")); +} + + +void NewProfileWidget::profileTabClear() +{ + if (debug) qDebug() << PDEBUG; + + ui->comboBox_profile->clear(); + QList profiles; + if (useHelper) + profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug)); + else + profiles = netctlCommand->getProfileList(); + for (int i=0; icomboBox_profile->addItem(profiles[i].name); + ui->comboBox_profile->setCurrentIndex(-1); + + generalWid->clear(); + ipWid->clear(); + bridgeWid->clear(); + ethernetWid->clear(); + macvlanWid->clear(); + mobileWid->clear(); + pppoeWid->clear(); + tunnelWid->clear(); + tuntapWid->clear(); + vlanWid->clear(); + wirelessWid->clear(); + + profileTabChangeState(generalWid->connectionType->currentText()); +} + + +void NewProfileWidget::profileTabCreateProfile() +{ + if (debug) qDebug() << PDEBUG; + + // error checking + if (ui->comboBox_profile->currentText().isEmpty()) + return ErrorWindow::showWindow(3, QString(PDEBUG), debug); + if (generalWid->isOk() == 1) + return ErrorWindow::showWindow(4, QString(PDEBUG), debug); + else if (generalWid->isOk() == 2) + return ErrorWindow::showWindow(5, QString(PDEBUG), debug); + if ((generalWid->connectionType->currentText() == QString("ethernet")) || + (generalWid->connectionType->currentText() == QString("wireless")) || + (generalWid->connectionType->currentText() == QString("bond")) || + (generalWid->connectionType->currentText() == QString("dummy")) || + (generalWid->connectionType->currentText() == QString("bridge")) || + (generalWid->connectionType->currentText() == QString("tunnel")) || + (generalWid->connectionType->currentText() == QString("tuntap")) || + (generalWid->connectionType->currentText() == QString("vlan")) || + (generalWid->connectionType->currentText() == QString("macvlan")) || + (generalWid->connectionType->currentText() == QString("openvswitch"))) { + if (ipWid->isOk() == 1) + return ErrorWindow::showWindow(6, QString(PDEBUG), debug); + else if (ipWid->isOk() == 2) + return ErrorWindow::showWindow(6, QString(PDEBUG), debug); + } + if (generalWid->connectionType->currentText() == QString("ethernet")) { + if (ethernetWid->isOk() == 1) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + } else if (generalWid->connectionType->currentText() == QString("wireless")) { + if (wirelessWid->isOk() == 1) + return ErrorWindow::showWindow(8, QString(PDEBUG), debug); + else if (wirelessWid->isOk() == 2) + return ErrorWindow::showWindow(9, QString(PDEBUG), debug); + else if (wirelessWid->isOk() == 3) + return ErrorWindow::showWindow(10, QString(PDEBUG), debug); + else if (wirelessWid->isOk() == 4) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + else if (wirelessWid->isOk() == 5) + return ErrorWindow::showWindow(11, QString(PDEBUG), debug); + } else if (generalWid->connectionType->currentText() == QString("bridge")) { + } else if (generalWid->connectionType->currentText() == QString("pppoe")) { + if (pppoeWid->isOk() == 1) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + else if (pppoeWid->isOk() == 2) + return ErrorWindow::showWindow(12, QString(PDEBUG), debug); + else if (pppoeWid->isOk() == 3) + return ErrorWindow::showWindow(13, QString(PDEBUG), debug); + else if (pppoeWid->isOk() == 4) + return ErrorWindow::showWindow(12, QString(PDEBUG), debug); + } else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) { + if (mobileWid->isOk() == 1) + return ErrorWindow::showWindow(15, QString(PDEBUG), debug); + if (mobileWid->isOk() == 2) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + } + else if (generalWid->connectionType->currentText() == QString("tunnel")) { + if (tunnelWid->isOk() == 1) + return ErrorWindow::showWindow(20, QString(PDEBUG), debug); + } + else if (generalWid->connectionType->currentText() == QString("tuntap")) { + if (tuntapWid->isOk() == 1) + return ErrorWindow::showWindow(15, QString(PDEBUG), debug); + if (tuntapWid->isOk() == 2) + return ErrorWindow::showWindow(15, QString(PDEBUG), debug); + } + else if (generalWid->connectionType->currentText() == QString("vlan")) { + if (ethernetWid->isOk() == 1) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + } + else if (generalWid->connectionType->currentText() == QString("macvlan")) { + if (ethernetWid->isOk() == 1) + return ErrorWindow::showWindow(7, QString(PDEBUG), debug); + } + + mainWindow->setDisabled(true); + // read settings + QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); + QMap settings; + settings = generalWid->getSettings(); + if (generalWid->connectionType->currentText() == QString("ethernet")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("wireless")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("bond")) || + (generalWid->connectionType->currentText() == QString("dummy")) || + (generalWid->connectionType->currentText() == QString("openvswitch"))) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; iconnectionType->currentText() == QString("bridge")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("pppoe")) { + QMap addSettings = pppoeWid->getSettings(); + for (int i=0; iconnectionType->currentText() == QString("mobile_ppp")) { + QMap addSettings = mobileWid->getSettings(); + for (int i=0; iconnectionType->currentText() == QString("tunnel")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("tuntap")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("vlan")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; igetSettings(); + for (int i=0; iconnectionType->currentText() == QString("macvlan")) { + QMap addSettings = ipWid->getSettings(); + for (int i=0; igetSettings(); + for (int i=0; igetSettings(); + for (int i=0; i args; + args.append(profile); + args.append(settingsList); + QList responce = sendRequestToCtrlWithArgs(QString("Create"), args, debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return profileTabCreateProfile(); + } + status = responce[0].toBool(); + + } else { + QString profileTempName = netctlProfile->createProfile(profile, settings); + status = netctlProfile->copyProfile(profileTempName); + } + mainWindow->showMessage(status); + + updateProfileTab(); +} + + +void NewProfileWidget::profileTabLoadProfile() +{ + if (debug) qDebug() << PDEBUG; + + QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); + if (profile.isEmpty()) return; + QMap settings; + if (useHelper) { + QList args; + args.append(profile); + QList responce = sendRequestToLibWithArgs(QString("Profile"), args, debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return profileTabLoadProfile(); + } + QStringList settingsList = responce[0].toStringList(); + for (int i=0; igetSettingsFromProfile(profile); + + if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); + + generalWid->setSettings(settings); + if (generalWid->connectionType->currentText() == QString("ethernet")) { + ipWid->setSettings(settings); + ethernetWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("wireless")) { + ipWid->setSettings(settings); + wirelessWid->setSettings(settings); + } else if ((generalWid->connectionType->currentText() == QString("bond")) || + (generalWid->connectionType->currentText() == QString("dummy")) || + (generalWid->connectionType->currentText() == QString("openvswitch"))) { + ipWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("bridge")) { + ipWid->setSettings(settings); + bridgeWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("pppoe")) { + pppoeWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) { + mobileWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("tunnel")) { + ipWid->setSettings(settings); + tunnelWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("tuntap")) { + ipWid->setSettings(settings); + tuntapWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("vlan")) { + ipWid->setSettings(settings); + ethernetWid->setSettings(settings); + vlanWid->setSettings(settings); + } else if (generalWid->connectionType->currentText() == QString("macvlan")) { + ipWid->setSettings(settings); + ethernetWid->setSettings(settings); + macvlanWid->setSettings(settings); + } +} + + +void NewProfileWidget::profileTabRemoveProfile() +{ + if (debug) qDebug() << PDEBUG; + + mainWindow->setDisabled(true); + QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); + if (profile.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug); + bool status = false; + if (useHelper) { + QList args; + args.append(profile); + QList responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return profileTabLoadProfile(); + } + status = responce[0].toBool(); + } else + status = netctlProfile->removeProfile(profile); + mainWindow->showMessage(status); + + updateProfileTab(); +} + + +void NewProfileWidget::createActions() +{ + if (debug) qDebug() << PDEBUG; + + // main tab events + connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile())); + connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile())); + connect(ui->comboBox_profile->lineEdit(), SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile())); + connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString))); +} + + +void NewProfileWidget::createObjects() +{ + if (debug) qDebug() << PDEBUG; + + // backend + netctlCommand = new Netctl(debug, configuration); + netctlProfile = new NetctlProfile(debug, configuration); + // windows + ui = new Ui::NewProfileWidget; + ui->setupUi(this); + // profile widgets + generalWid = new GeneralWidget(this, configuration); + ui->scrollAreaWidgetContents->layout()->addWidget(generalWid); + ipWid = new IpWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(ipWid); + bridgeWid = new BridgeWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid); + ethernetWid = new EthernetWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid); + macvlanWid = new MacvlanWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid); + mobileWid = new MobileWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid); + pppoeWid = new PppoeWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid); + tunnelWid = new TunnelWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid); + tuntapWid = new TuntapWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid); + vlanWid = new VlanWidget(this); + ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid); + wirelessWid = new WirelessWidget(this, configuration); + ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid); +} + + +void NewProfileWidget::createToolBars() +{ + if (debug) qDebug() << PDEBUG; + + actionToolBar = new QToolBar(this); + actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); + toolBarActions[QString("profileClear")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-clear")), + QApplication::translate("NewProfileWidget", "Clear"), + this, SLOT(profileTabClear())); + + actionMenu = new QToolButton(this); + actionMenu->setPopupMode(QToolButton::DelayedPopup); + actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle); + QMenu *menu = new QMenu(actionMenu); + toolBarActions[QString("profileLoad")] = menu->addAction(QIcon::fromTheme(QString("document-open")), + QApplication::translate("NewProfileWidget", "Load"), + this, SLOT(profileTabLoadProfile())); + toolBarActions[QString("profileSave")] = menu->addAction(QIcon::fromTheme(QString("document-save")), + QApplication::translate("NewProfileWidget", "Save"), + this, SLOT(profileTabCreateProfile())); + actionMenu->setMenu(menu); + actionToolBar->addWidget(actionMenu); + + toolBarActions[QString("profileRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")), + QApplication::translate("NewProfileWidget", "Remove"), + this, SLOT(profileTabRemoveProfile())); + + actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]); + ui->verticalLayout->insertWidget(0, actionToolBar); +} + + +void NewProfileWidget::deleteObjects() +{ + if (debug) qDebug() << PDEBUG; + + if (netctlCommand != nullptr) delete netctlCommand; + if (netctlProfile != nullptr) delete netctlProfile; + + if (bridgeWid != nullptr) delete bridgeWid; + if (ethernetWid != nullptr) delete ethernetWid; + if (generalWid != nullptr) delete generalWid; + if (ipWid != nullptr) delete ipWid; + if (macvlanWid != nullptr) delete macvlanWid; + if (mobileWid != nullptr) delete mobileWid; + if (pppoeWid != nullptr) delete pppoeWid; + if (tunnelWid != nullptr) delete tunnelWid; + if (tuntapWid != nullptr) delete tuntapWid; + if (vlanWid != nullptr) delete vlanWid; + if (wirelessWid != nullptr) delete wirelessWid; + + if (actionMenu != nullptr) { + actionMenu->menu()->clear(); + delete actionMenu; + } + if (actionToolBar != nullptr) { + actionToolBar->clear(); + delete actionToolBar; + } + if (ui != nullptr) delete ui; +} diff --git a/sources/gui/src/newprofilewidget.h b/sources/gui/src/newprofilewidget.h new file mode 100644 index 0000000..8e180df --- /dev/null +++ b/sources/gui/src/newprofilewidget.h @@ -0,0 +1,102 @@ +/*************************************************************************** + * 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 NEWPROFILEWIDGET_H +#define NEWPROFILEWIDGET_H + +#include +#include +#include + +#include + + +class BridgeWidget; +class EthernetWidget; +class GeneralWidget; +class IpWidget; +class MainWindow; +class MacvlanWidget; +class MobileWidget; +class PppoeWidget; +class TunnelWidget; +class TuntapWidget; +class VlanWidget; +class WirelessWidget; + +namespace Ui { +class NewProfileWidget; +} + +class NewProfileWidget : public QWidget +{ + Q_OBJECT + +public: + explicit NewProfileWidget(QWidget *parent = 0, + const QMap settings = QMap(), + const bool debugCmd = false); + ~NewProfileWidget(); + +public slots: + void profileTabOpenProfile(const QString profile); + void update(); + +private slots: + // update slots + void updateMenuProfile(); + void updateProfileTab(); + // profile tab slots + void profileTabChangeState(const QString current); + void profileTabClear(); + void profileTabCreateProfile(); + void profileTabLoadProfile(); + void profileTabRemoveProfile(); + +private: + // ui + QMap toolBarActions; + QToolButton *actionMenu = nullptr; + QToolBar *actionToolBar = nullptr; + MainWindow *mainWindow; + Ui::NewProfileWidget *ui = nullptr; + BridgeWidget *bridgeWid = nullptr; + EthernetWidget *ethernetWid = nullptr; + GeneralWidget *generalWid = nullptr; + IpWidget *ipWid = nullptr; + MacvlanWidget *macvlanWid = nullptr; + MobileWidget *mobileWid = nullptr; + PppoeWidget *pppoeWid = nullptr; + TunnelWidget *tunnelWid = nullptr; + TuntapWidget *tuntapWid = nullptr; + VlanWidget *vlanWid = nullptr; + WirelessWidget *wirelessWid = nullptr; + // backend + Netctl *netctlCommand = nullptr; + NetctlProfile *netctlProfile = nullptr; + void createActions(); + void createObjects(); + void createToolBars(); + void deleteObjects(); + bool debug = false; + bool useHelper = true; + // configuration + QMap configuration; +}; + + +#endif /* NEWPROFILEWIDGET_H */ diff --git a/sources/gui/src/newprofilewidget.ui b/sources/gui/src/newprofilewidget.ui new file mode 100644 index 0000000..032cddf --- /dev/null +++ b/sources/gui/src/newprofilewidget.ui @@ -0,0 +1,81 @@ + + + NewProfileWidget + + + + 0 + 0 + 473 + 410 + + + + Form + + + + + + + + + 1 + 0 + + + + Profile + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 2 + 0 + + + + true + + + true + + + + + + + + + true + + + + + 0 + 0 + 457 + 363 + + + + + 0 + 0 + + + + + + + + + + + diff --git a/sources/gui/src/passwdwidget.cpp b/sources/gui/src/passwdwidget.cpp index 991a03d..b3db5b3 100644 --- a/sources/gui/src/passwdwidget.cpp +++ b/sources/gui/src/passwdwidget.cpp @@ -20,10 +20,10 @@ #include -#include "mainwindow.h" +#include "wifimenuwidget.h" -PasswdWidget::PasswdWidget(MainWindow *wid) +PasswdWidget::PasswdWidget(WiFiMenuWidget *wid) : QWidget(wid), parent(wid), ui(new Ui::PasswdWidget) @@ -79,7 +79,7 @@ void PasswdWidget::setPassword(const bool mode) void PasswdWidget::cancel() { hide(); - parent->updateTabs(2); + parent->update(); this->~PasswdWidget(); } diff --git a/sources/gui/src/passwdwidget.h b/sources/gui/src/passwdwidget.h index df49c3f..adef952 100644 --- a/sources/gui/src/passwdwidget.h +++ b/sources/gui/src/passwdwidget.h @@ -23,7 +23,7 @@ #include -class MainWindow; +class WiFiMenuWidget; namespace Ui { class PasswdWidget; @@ -34,7 +34,7 @@ class PasswdWidget : public QWidget Q_OBJECT public: - explicit PasswdWidget(MainWindow *wid = 0); + explicit PasswdWidget(WiFiMenuWidget *wid = 0); ~PasswdWidget(); public slots: @@ -47,7 +47,7 @@ private slots: void setEchoMode(const int mode); private: - MainWindow *parent; + WiFiMenuWidget *parent; Ui::PasswdWidget *ui; // ESC pressed event void keyPressEvent(QKeyEvent *pressedKey); diff --git a/sources/gui/src/trayicon.cpp b/sources/gui/src/trayicon.cpp index 1b7dcc4..87c3e60 100644 --- a/sources/gui/src/trayicon.cpp +++ b/sources/gui/src/trayicon.cpp @@ -112,7 +112,7 @@ void TrayIcon::updateMenu() } QStringList profiles; for (int i=0; isetText(profiles.join(QString(" | "))); } diff --git a/sources/gui/src/wifimenuwidget.cpp b/sources/gui/src/wifimenuwidget.cpp new file mode 100644 index 0000000..420ce07 --- /dev/null +++ b/sources/gui/src/wifimenuwidget.cpp @@ -0,0 +1,451 @@ +/*************************************************************************** + * 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 "wifimenuwidget.h" +#include "ui_wifimenuwidget.h" + +#include +#include + +#include + +#include "commonfunctions.h" +#include "dbusoperation.h" +#include "errorwindow.h" +#include "mainwindow.h" +#include "passwdwidget.h" + + +WiFiMenuWidget::WiFiMenuWidget(QWidget *parent, const QMap settings, const bool debugCmd) + : QWidget(parent), + debug(debugCmd), + configuration(settings) +{ + mainWindow = dynamic_cast(parent); + useHelper = (configuration[QString("USE_HELPER")] == QString("true")); + + createObjects(); + createToolBars(); + createActions(); +} + + +WiFiMenuWidget::~WiFiMenuWidget() +{ + if (debug) qDebug() << PDEBUG; + + deleteObjects(); +} + + +void WiFiMenuWidget::update() +{ + if (debug) qDebug() << PDEBUG; + + updateWifiTab(); + updateMenuWifi(); +} + + +void WiFiMenuWidget::connectToUnknownEssid(const QString passwd) +{ + if (debug) qDebug() << PDEBUG; + + if (passwdWid != nullptr) delete passwdWid; + QStringList interfaces; + if (useHelper) { + QList responce = sendRequestToLib(QString("WirelessInterfaces"), debug); + if (responce.isEmpty()) + interfaces = netctlCommand->getWirelessInterfaceList(); + else + interfaces = responce[0].toStringList(); + } else + interfaces = netctlCommand->getWirelessInterfaceList(); + if (interfaces.isEmpty()) return; + + QMap settings; + settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); + settings[QString("Interface")] = interfaces[0]; + settings[QString("Connection")] = QString("wireless"); + QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text(); + if (security.contains(QString("WPA"))) + settings[QString("Security")] = QString("wpa"); + else if (security.contains(QString("WEP"))) + settings[QString("Security")] = QString("wep"); + else + settings[QString("Security")] = QString("none"); + settings[QString("ESSID")] = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text()); + if (!passwd.isEmpty()) + settings[QString("Key")] = QString("'%1'").arg(passwd); + settings[QString("IP")] = QString("dhcp"); + if (hiddenNetwork) + settings[QString("Hidden")] = QString("yes"); + + QString profile = QString("netctl-gui-%1").arg(settings[QString("ESSID")]); + profile.remove(QChar('"')).remove(QChar('\'')); + if (useHelper) { + QStringList settingsList; + for (int i=0; i args; + args.append(profile); + args.append(settingsList); + sendRequestToCtrlWithArgs(QString("Create"), args, debug); + } else { + QString profileTempName = netctlProfile->createProfile(profile, settings); + netctlProfile->copyProfile(profileTempName); + } + QString message; + if (mainWindow->startProfileSlot(profile)) { + message = QApplication::translate("MainWindow", "Connection is successfully."); + mainWindow->showMessage(true); + } else { + message = QApplication::translate("MainWindow", "Connection failed."); + mainWindow->showMessage(false); + } + message += QString("\n"); + message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile); + int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"), + message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save); + switch (select) { + case QMessageBox::Save: + break; + case QMessageBox::Discard: + default: + if (useHelper) { + QList args; + args.append(profile); + sendRequestToCtrlWithArgs(QString("Remove"), args, debug); + } else + netctlProfile->removeProfile(profile); + break; + } + + updateWifiTab(); +} + + +void WiFiMenuWidget::setHiddenName(const QString name) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Set name" << name; + + ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name); + + wifiTabStart(); +} + + +void WiFiMenuWidget::updateMenuWifi() +{ + if (debug) qDebug() << PDEBUG; + + bool selected = (ui->tableWidget_wifi->currentItem() != nullptr); + toolBarActions[QString("wifiStart")]->setVisible(selected); + if (selected && ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) { + toolBarActions[QString("wifiStart")]->setText(QApplication::translate("WiFiMenuWidget", "Start")); + toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("system-run")); + } else { + toolBarActions[QString("wifiStart")]->setText(QApplication::translate("WiFiMenuWidget", "Stop")); + toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("process-stop")); + } +} + + +void WiFiMenuWidget::updateWifiTab() +{ + if (debug) qDebug() << PDEBUG; + wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug)); + if (!checkExternalApps(QString("wpasup"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + + mainWindow->setDisabled(true); + QList scanResults; + if (useHelper) + scanResults = parseOutputWifi(sendRequestToCtrl(QString("VerboseWiFi"), debug)); + else + scanResults = wpaCommand->scanWifi(); + + ui->tableWidget_wifi->setSortingEnabled(false); + ui->tableWidget_wifi->selectRow(-1); + ui->tableWidget_wifi->sortByColumn(3, Qt::AscendingOrder); + ui->tableWidget_wifi->clear(); + ui->tableWidget_wifi->setRowCount(scanResults.count()); + + // create header + QStringList headerList; + headerList.append(QApplication::translate("WiFiMenuWidget", "Name")); + headerList.append(QApplication::translate("WiFiMenuWidget", "Type")); + headerList.append(QApplication::translate("WiFiMenuWidget", "# of points")); + headerList.append(QApplication::translate("WiFiMenuWidget", "Signal")); + headerList.append(QApplication::translate("WiFiMenuWidget", "Security")); + headerList.append(QApplication::translate("WiFiMenuWidget", "Active")); + headerList.append(QApplication::translate("WiFiMenuWidget", "Exists")); + ui->tableWidget_wifi->setHorizontalHeaderLabels(headerList); + // create items + for (int i=0; itableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name)); + ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget_wifi->item(i, 0)->setToolTip(toolTip); + ui->tableWidget_wifi->item(i, 0)->setFont(font); + // type + ui->tableWidget_wifi->setItem(i, 1, new QTableWidgetItem(type)); + ui->tableWidget_wifi->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidget_wifi->item(i, 1)->setToolTip(toolTip); + // count + ui->tableWidget_wifi->setItem(i, 2, new QTableWidgetItem(QString::number(scanResults[i].frequencies.count()))); + ui->tableWidget_wifi->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidget_wifi->item(i, 2)->setToolTip(toolTip); + // signal + ui->tableWidget_wifi->setItem(i, 3, new QTableWidgetItem(QString::number(scanResults[i].signal))); + ui->tableWidget_wifi->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidget_wifi->item(i, 3)->setToolTip(toolTip); + // security + ui->tableWidget_wifi->setItem(i, 4, new QTableWidgetItem(scanResults[i].security)); + ui->tableWidget_wifi->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidget_wifi->item(i, 4)->setToolTip(toolTip); + // active + ui->tableWidget_wifi->setItem(i, 5, new QTableWidgetItem(checkStatus(scanResults[i].active, true))); + ui->tableWidget_wifi->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + // exists + ui->tableWidget_wifi->setItem(i, 6, new QTableWidgetItem(checkStatus(scanResults[i].exists, true))); + ui->tableWidget_wifi->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + } + + ui->tableWidget_wifi->setSortingEnabled(true); + + ui->tableWidget_wifi->resizeRowsToContents(); + ui->tableWidget_wifi->resizeColumnsToContents(); + ui->tableWidget_wifi->resizeRowsToContents(); +#if QT_VERSION >= 0x050000 + ui->tableWidget_wifi->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); +#else + ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); +#endif + + mainWindow->setDisabled(false); + mainWindow->showMessage(true); +} + + +void WiFiMenuWidget::wifiTabContextualMenu(const QPoint &pos) +{ + if (debug) qDebug() << PDEBUG; + if (ui->tableWidget_wifi->currentItem() == nullptr) return; + + // create menu + QMenu menu(this); + QAction *refreshTable = menu.addAction(QApplication::translate("WiFiMenuWidget", "Refresh")); + refreshTable->setIcon(QIcon::fromTheme("view-refresh")); + menu.addSeparator(); + QAction *startWifi = menu.addAction(QApplication::translate("WiFiMenuWidget", "Start WiFi")); + + // set text + if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) { + startWifi->setText(QApplication::translate("WiFiMenuWidget", "Start WiFi")); + startWifi->setIcon(QIcon::fromTheme("system-run")); + + } else { + startWifi->setText(QApplication::translate("WiFiMenuWidget", "Stop WiFi")); + startWifi->setIcon(QIcon::fromTheme("process-stop")); + } + + // actions + QAction *action = menu.exec(ui->tableWidget_wifi->viewport()->mapToGlobal(pos)); + if (action == refreshTable) { + if (debug) qDebug() << PDEBUG << ":" << "Refresh WiFi"; + updateWifiTab(); + } else if (action == startWifi) { + if (debug) qDebug() << PDEBUG << ":" << "Start WiFi"; + wifiTabStart(); + } +} + + +void WiFiMenuWidget::wifiTabSetEnabled(const bool state) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "State" << state; + + ui->tableWidget_wifi->setHidden(!state); + ui->label_wifi->setHidden(state); +} + + +void WiFiMenuWidget::wifiTabStart() +{ + if (debug) qDebug() << PDEBUG; + if (!checkExternalApps(QString("wpasup"), configuration, debug)) { + ErrorWindow::showWindow(1, QString(PDEBUG), debug); + emit(mainWindow->needToBeConfigured()); + return; + } + if (ui->tableWidget_wifi->currentItem() == nullptr) return; + + mainWindow->setDisabled(true); + // name is hidden + if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("")) { + hiddenNetwork = true; + passwdWid = new PasswdWidget(this); + passwdWid->setPassword(false); + int widgetWidth = 2 * width() / 3; + int widgetHeight = 110; + int x = (width() - widgetWidth) / 2; + int y = (height() - widgetHeight) / 2; + passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); + passwdWid->show(); + passwdWid->setFocusToLineEdit(); + return; + } + + // name isn't hidden + hiddenNetwork = false; + QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); + QString profileName = QString(""); + if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 6)->text().isEmpty()) { + if (useHelper) { + QList args; + args.append(profile); + QList responce = sendRequestToLibWithArgs(QString("ProfileByEssid"), args, debug); + if (responce.isEmpty()) { + if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it"; + useHelper = false; + return wifiTabStart(); + } + profileName = responce[0].toString(); + } else + profileName = wpaCommand->existentProfile(profile); + mainWindow->showMessage(mainWindow->startProfileSlot(profileName)); + } else { + QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); + if (security == QString("none")) return connectToUnknownEssid(QString("")); + else { + passwdWid = new PasswdWidget(this); + passwdWid->setPassword(true); + int widgetWidth = 2 * width() / 3; + int widgetHeight = 110; + int x = (width() - widgetWidth) / 2; + int y = (height() - widgetHeight) / 2; + passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); + passwdWid->show(); + passwdWid->setFocusToLineEdit(); + return; + } + } + + updateWifiTab(); +} + + +void WiFiMenuWidget::createActions() +{ + if (debug) qDebug() << PDEBUG; + + // wifi tab events + connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart())); + connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), + this, SLOT(updateMenuWifi())); + connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint))); +} + + +void WiFiMenuWidget::createObjects() +{ + if (debug) qDebug() << PDEBUG; + + // backend + netctlCommand = new Netctl(debug, configuration); + netctlProfile = new NetctlProfile(debug, configuration); + wpaCommand = new WpaSup(debug, configuration); + // windows + ui = new Ui::WiFiMenuWidget; + ui->setupUi(this); + ui->tableWidget_wifi->setColumnHidden(5, true); + ui->tableWidget_wifi->setColumnHidden(6, true); +} + + +void WiFiMenuWidget::createToolBars() +{ + if (debug) qDebug() << PDEBUG; + + actionToolBar = new QToolBar(this); + actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); + toolBarActions[QString("wifiRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")), + QApplication::translate("WiFiMenuWidget", "Refresh"), + this, SLOT(updateWifiTab())); + toolBarActions[QString("wifiStart")] = actionToolBar->addAction(QIcon::fromTheme(QString("system-run")), + QApplication::translate("WiFiMenuWidget", "Start"), + this, SLOT(wifiTabStart())); + + ui->verticalLayout->insertWidget(0, actionToolBar); +} + + +void WiFiMenuWidget::deleteObjects() +{ + if (debug) qDebug() << PDEBUG; + + if (netctlCommand != nullptr) delete netctlCommand; + if (netctlProfile != nullptr) delete netctlProfile; + if (wpaCommand != nullptr) delete wpaCommand; + + if (actionToolBar != nullptr) { + actionToolBar->clear(); + delete actionToolBar; + } + if (ui != nullptr) delete ui; +} diff --git a/sources/gui/src/wifimenuwidget.h b/sources/gui/src/wifimenuwidget.h new file mode 100644 index 0000000..8ee6ba6 --- /dev/null +++ b/sources/gui/src/wifimenuwidget.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * 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 WIFIMENUWIDGET_H +#define WIFIMENUWIDGET_H + +#include +#include +#include +#include + +#include + + +class MainWindow; +class PasswdWidget; + +namespace Ui { +class WiFiMenuWidget; +} + +class WiFiMenuWidget : public QWidget +{ + Q_OBJECT + +public: + explicit WiFiMenuWidget(QWidget *parent = 0, + const QMap settings = QMap(), + const bool debugCmd = false); + ~WiFiMenuWidget(); + +public slots: + void update(); + // wifi tab slots + void connectToUnknownEssid(const QString passwd); + void setHiddenName(const QString name); + +private slots: + // update slots + void updateMenuWifi(); + void updateWifiTab(); + // wifi tab slots + void wifiTabContextualMenu(const QPoint &pos); + void wifiTabSetEnabled(const bool state); + void wifiTabStart(); + +private: + // ui + QMap toolBarActions; + QToolBar *actionToolBar = nullptr; + MainWindow *mainWindow = nullptr; + Ui::WiFiMenuWidget *ui = nullptr; + PasswdWidget *passwdWid = nullptr; + // backend + Netctl *netctlCommand = nullptr; + NetctlProfile *netctlProfile = nullptr; + WpaSup *wpaCommand = nullptr; + void createActions(); + void createObjects(); + void createToolBars(); + void deleteObjects(); + bool debug = false; + bool hiddenNetwork; + bool useHelper = true; + // configuration + QMap configuration; +}; + + +#endif /* WIFIMENUWIDGET_H */ diff --git a/sources/gui/src/wifimenuwidget.ui b/sources/gui/src/wifimenuwidget.ui new file mode 100644 index 0000000..86b75be --- /dev/null +++ b/sources/gui/src/wifimenuwidget.ui @@ -0,0 +1,101 @@ + + + WiFiMenuWidget + + + + 0 + 0 + 571 + 467 + + + + Form + + + + + + Please install 'wpa_supplicant' before using it + + + Qt::AlignCenter + + + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + 7 + + + true + + + false + + + + Name + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + Type + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + # of points + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + Signal + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + Security + + + AlignHCenter|AlignVCenter|AlignCenter + + + + + + + + + + + diff --git a/sources/helper/src/netctladaptor.cpp b/sources/helper/src/netctladaptor.cpp index 9b1f725..93269fa 100644 --- a/sources/helper/src/netctladaptor.cpp +++ b/sources/helper/src/netctladaptor.cpp @@ -182,6 +182,8 @@ QStringList NetctlAdaptor::VerboseProfileList() QStringList profileInfo; profileInfo.append(profilesInfo[i].name); profileInfo.append(profilesInfo[i].description); + profileInfo.append(profilesInfo[i].type); + profileInfo.append(profilesInfo[i].interface); profileInfo.append(profilesInfo[i].essid); profileInfo.append(QString::number(profilesInfo[i].active)); profileInfo.append(QString::number(profilesInfo[i].enabled));