diff --git a/sources/gui/src/errorwindow.cpp b/sources/gui/src/errorwindow.cpp new file mode 100644 index 0000000..a781753 --- /dev/null +++ b/sources/gui/src/errorwindow.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * This file is part of netctl-plasmoid * + * * + * netctl-plasmoid 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-plasmoid 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-plasmoid. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "errorwindow.h" +#include "ui_errorwindow.h" + + +ErrorWindow::ErrorWindow(QWidget *parent, int messageNumber) + : QMainWindow(parent), + ui(new Ui::ErrorWindow) +{ + ui->setupUi(this); + setMessage(messageNumber); +} + +ErrorWindow::~ErrorWindow() +{ + delete ui; +} + +void ErrorWindow::setMessage(int mess) +{ + QString message; + switch(mess) { + case 0: + message = QApplication::translate("ErrorWindow", "Unknown error"); + break; + case 1: + message = QApplication::translate("ErrorWindow", "Could not find components"); + break; + case 2: + message = QApplication::translate("ErrorWindow", "Doesn't support yet"); + break; + default: + message = QApplication::translate("ErrorWindow", "Unknown error"); + break; + } + + ui->label->setText(message); +} diff --git a/sources/gui/src/errorwindow.h b/sources/gui/src/errorwindow.h new file mode 100644 index 0000000..3d26ed3 --- /dev/null +++ b/sources/gui/src/errorwindow.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * This file is part of netctl-plasmoid * + * * + * netctl-plasmoid 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-plasmoid 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-plasmoid. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef ERRORWINDOW_H +#define ERRORWINDOW_H + +#include + + +namespace Ui { +class ErrorWindow; +} + +class ErrorWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit ErrorWindow(QWidget *parent = 0, int messageNumber = 0); + ~ErrorWindow(); + +private: + Ui::ErrorWindow *ui; + void setMessage(int mess); +}; + +#endif /* ERRORWINDOW_H */ diff --git a/sources/gui/src/errorwindow.ui b/sources/gui/src/errorwindow.ui new file mode 100644 index 0000000..2e55c85 --- /dev/null +++ b/sources/gui/src/errorwindow.ui @@ -0,0 +1,123 @@ + + + ErrorWindow + + + + 0 + 0 + 287 + 101 + + + + Error + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + + + + + + 0 + 30 + + + + Error text + + + Qt::AlignCenter + + + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + pushButton + clicked(bool) + ErrorWindow + close() + + + 143 + 83 + + + 252 + 80 + + + + + diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 95ff715..9e38ba0 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -21,7 +21,9 @@ #include #include +#include "errorwindow.h" #include "netctlinteract.h" +#include "passwdwidget.h" #include "wpasupinteract.h" #include @@ -114,6 +116,8 @@ void MainWindow::createActions() // wifi page events connect(ui->pushButton_wifiRefresh, SIGNAL(clicked(bool)), this, SLOT(updateWifiTab())); + connect(ui->pushButton_wifiStart, SIGNAL(clicked(bool)), this, SLOT(wifiTabStart())); + connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart())); connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(wifiTabRefreshButtons(QTableWidgetItem *, QTableWidgetItem *))); } @@ -130,10 +134,13 @@ void MainWindow::updateTabs(const int tab) void MainWindow::updateMainTab() { - if (!checkExternalApps(QString("netctl"))) + if (!checkExternalApps(QString("netctl"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); return; + } - ui->tableWidget_main->setDisabled(true); + ui->tabWidget->setDisabled(true); QList profiles = netctlCommand->getProfileList();; ui->tableWidget_main->setSortingEnabled(false); @@ -160,7 +167,7 @@ void MainWindow::updateMainTab() ui->tableWidget_main->setSortingEnabled(true); ui->tableWidget_main->resizeRowsToContents(); ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - ui->tableWidget_main->setEnabled(true); + ui->tabWidget->setEnabled(true); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); update(); @@ -170,12 +177,15 @@ void MainWindow::updateMainTab() void MainWindow::updateWifiTab() { wifiTabSetEnabled(checkExternalApps(QString("wpasup"))); - if (!checkExternalApps(QString("wpasup"))) + if (!checkExternalApps(QString("wpasup"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); return; + } QList scanResults = wpaCommand->scanWifi(); - ui->tableWidget_wifi->setDisabled(true); + ui->tabWidget->setDisabled(true); ui->tableWidget_wifi->setSortingEnabled(false); ui->tableWidget_wifi->selectRow(-1); ui->tableWidget_wifi->sortByColumn(0, Qt::AscendingOrder); @@ -203,7 +213,7 @@ void MainWindow::updateWifiTab() ui->tableWidget_wifi->setSortingEnabled(true); ui->tableWidget_wifi->resizeRowsToContents(); ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - ui->tableWidget_wifi->setEnabled(true); + ui->tabWidget->setEnabled(true); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); update(); @@ -213,10 +223,15 @@ void MainWindow::updateWifiTab() // main tab slots void MainWindow::mainTabEnableProfile() { - if (!checkExternalApps(QString("netctl"))) + if (!checkExternalApps(QString("netctl"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); + return; + } + if (ui->tableWidget_main->currentItem() == 0) return; - ui->tableWidget_main->setDisabled(true); + ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->enableProfile(profile); if (ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().indexOf(QString("enabled")) > -1) { @@ -231,34 +246,42 @@ void MainWindow::mainTabEnableProfile() else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); } - ui->tableWidget_main->setEnabled(true); updateMainTab(); } void MainWindow::mainTabRestartProfile() { - if (!checkExternalApps(QString("netctl"))) + if (!checkExternalApps(QString("netctl"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); + return; + } + if (ui->tableWidget_main->currentItem() == 0) return; - ui->tableWidget_main->setDisabled(true); + ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->restartProfile(profile); if (netctlCommand->isProfileActive(profile)) ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); - ui->tableWidget_main->setEnabled(true); updateMainTab(); } void MainWindow::mainTabStartProfile() { - if (!checkExternalApps(QString("netctl"))) + if (!checkExternalApps(QString("netctl"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); + return; + } + if (ui->tableWidget_main->currentItem() == 0) return; - ui->tableWidget_main->setDisabled(true); + ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->startProfile(profile); if (ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().indexOf(QString("inactive")) == -1) { @@ -273,7 +296,6 @@ void MainWindow::mainTabStartProfile() else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); } - ui->tableWidget_main->setEnabled(true); updateMainTab(); } @@ -281,10 +303,20 @@ void MainWindow::mainTabStartProfile() void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); - if (current == 0) + if (!checkExternalApps(QString("netctl"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); return; - if (!checkExternalApps(QString("netctl"))) + } + if (current == 0) { + ui->pushButton_mainEnable->setDisabled(true); + ui->pushButton_mainRestart->setDisabled(true); + ui->pushButton_mainStart->setDisabled(true); return; + } + + ui->pushButton_mainEnable->setEnabled(true); + ui->pushButton_mainStart->setEnabled(true); QString item = ui->tableWidget_main->item(current->row(), 2)->text(); if (!checkState(QString("inactive"), item)) { @@ -320,15 +352,105 @@ void MainWindow::wifiTabSetEnabled(bool state) } +void MainWindow::connectToUnknownEssid(QString passwd) +{ + if (!passwd.isEmpty()) + delete passwdwid; + QStringList profileInfo; + profileInfo.append(QString("Automatically generated profile by Netctl GUI")); + profileInfo.append(wpaCommand->getInterfaceList()[0]); + profileInfo.append(QString("wireless")); + QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text(); + if (checkState(QString("WPA"), security)) + profileInfo.append(QString("wpa")); + else if (checkState(QString("wep"), security)) + profileInfo.append(QString("wep")); + else + profileInfo.append(QString("none")); + profileInfo.append(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text()); + profileInfo.append(passwd); + profileInfo.append(QString("dhcp")); + + + + updateWifiTab(); +} + + +void MainWindow::wifiTabStart() +{ + if (!checkExternalApps(QString("wpasup"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); + return; + } + if (ui->tableWidget_wifi->currentItem() == 0) + return; + if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("")) { + ui->pushButton_wifiStart->setDisabled(true); + errorwin = new ErrorWindow(this, 2); + errorwin->show(); + return; + } + + ui->tabWidget->setDisabled(true); + QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); + QString item = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); + if (checkState(QString("exists"), item)) { + QString profileName = wpaCommand->existentProfile(profile); + netctlCommand->startProfile(profileName); + if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text().indexOf(QString("inactive")) == -1) { + if (netctlCommand->isProfileActive(profileName)) + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); + else + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); + } + else { + if (netctlCommand->isProfileActive(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(), 3)->text(); + if (checkState(QString("none"), security)) + return connectToUnknownEssid(QString("")); + else { + passwdwid = new PasswdWidget(this); + int widgetWidth = 270; + int widgetHeight = 86; + int x = (width() - widgetWidth) / 2; + int y = (height() - widgetHeight) / 2; + passwdwid->setGeometry(x, y, widgetWidth, widgetHeight); + passwdwid->show(); + passwdwid->setFocusToLineEdit(); + return; + } + } + updateWifiTab(); +} + + void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); - if (current == 0) + if (!checkExternalApps(QString("wpasup"))) { + errorwin = new ErrorWindow(this, 1); + errorwin->show(); return; - if (!checkExternalApps(QString("wpasup"))) + } + if (current == 0) { + ui->pushButton_wifiStart->setDisabled(true); return; + } + if (ui->tableWidget_wifi->item(current->row(), 0)->text() == QString("")) { + ui->pushButton_wifiStart->setDisabled(true); + return; + } - QString item = ui->tableWidget_wifi->item(current->row(), 3)->text(); + ui->pushButton_wifiStart->setEnabled(true); + QString item = ui->tableWidget_wifi->item(current->row(), 1)->text(); if (checkState(QString("exists"), item)) { if (!checkState(QString("inactive"), item)) ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Stop")); diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index fdaf4c1..75b0c9f 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -24,7 +24,9 @@ #include +class ErrorWindow; class Netctl; +class PasswdWidget; class WpaSup; namespace Ui { @@ -48,9 +50,13 @@ public: wpaConfDir = 4, wpaConfGroup = 5 }; + +public slots: + void updateTabs(const int tab); + // wifi tab slots + void connectToUnknownEssid(QString passwd); private slots: - void updateTabs(const int tab); void updateMainTab(); void updateWifiTab(); // main tab slots @@ -60,10 +66,13 @@ private slots: void mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous); // wifi tab slots void wifiTabSetEnabled(bool state); + void wifiTabStart(); void wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous); private: Ui::MainWindow *ui; + ErrorWindow *errorwin; + PasswdWidget *passwdwid; bool checkExternalApps(QString apps); bool checkState(QString state, QString item); void createActions(); diff --git a/sources/gui/src/mainwindow.ui b/sources/gui/src/mainwindow.ui index ee8561d..8f5af0b 100644 --- a/sources/gui/src/mainwindow.ui +++ b/sources/gui/src/mainwindow.ui @@ -11,7 +11,7 @@ - MainWindow + Netctl GUI @@ -101,6 +101,9 @@ + + false + Enable @@ -111,6 +114,9 @@ + + false + Restart @@ -121,6 +127,9 @@ + + false + Start @@ -225,6 +234,9 @@ + + false + Start diff --git a/sources/gui/src/netctlinteract.h b/sources/gui/src/netctlinteract.h index c968dce..28b4fe7 100644 --- a/sources/gui/src/netctlinteract.h +++ b/sources/gui/src/netctlinteract.h @@ -44,6 +44,7 @@ public slots: bool enableProfile(QString profile); bool restartProfile(QString profile); bool startProfile(QString profile); +// bool createProfile(QStringList profileInfo); private: MainWindow *parent; diff --git a/sources/gui/src/passwdwidget.cpp b/sources/gui/src/passwdwidget.cpp new file mode 100644 index 0000000..d6ed51a --- /dev/null +++ b/sources/gui/src/passwdwidget.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * This file is part of netctl-plasmoid * + * * + * netctl-plasmoid 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-plasmoid 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-plasmoid. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "passwdwidget.h" +#include "ui_passwdwidget.h" + +#include "mainwindow.h" + + +PasswdWidget::PasswdWidget(MainWindow *wid) + : QWidget(wid), + parent(wid), + ui(new Ui::PasswdWidget) +{ + ui->setupUi(this); + createActions(); +} + + +PasswdWidget::~PasswdWidget() +{ + delete ui; +} + + +// ESC press event +void PasswdWidget::keyPressEvent(QKeyEvent *pressedKey) +{ + if (pressedKey->key() == Qt::Key_Escape) { + hide(); + parent->updateTabs(2); + this->~PasswdWidget(); + } +} + + +void PasswdWidget::createActions() +{ + connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(passwdApply())); + connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(passwdApply())); +} + + +void PasswdWidget::setFocusToLineEdit() +{ + ui->lineEdit->setFocus(Qt::ActiveWindowFocusReason); +} + + +void PasswdWidget::passwdApply() +{ + hide(); + return parent->connectToUnknownEssid(ui->lineEdit->text()); +} diff --git a/sources/gui/src/passwdwidget.h b/sources/gui/src/passwdwidget.h new file mode 100644 index 0000000..3516f01 --- /dev/null +++ b/sources/gui/src/passwdwidget.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * This file is part of netctl-plasmoid * + * * + * netctl-plasmoid 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-plasmoid 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-plasmoid. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef PASSWDWIDGET_H +#define PASSWDWIDGET_H + +#include +#include + + +class MainWindow; + +namespace Ui { +class PasswdWidget; +} + +class PasswdWidget : public QWidget +{ + Q_OBJECT + +public: + explicit PasswdWidget(MainWindow *wid = 0); + ~PasswdWidget(); + +public slots: + void setFocusToLineEdit(); + +private slots: + void passwdApply(); + +private: + MainWindow *parent; + Ui::PasswdWidget *ui; + // ESC pressed event + void keyPressEvent(QKeyEvent *pressedKey); + void createActions(); +}; + + +#endif /* PASSWDWIDGET_H */ diff --git a/sources/gui/src/passwdwidget.ui b/sources/gui/src/passwdwidget.ui new file mode 100644 index 0000000..8f46269 --- /dev/null +++ b/sources/gui/src/passwdwidget.ui @@ -0,0 +1,108 @@ + + + PasswdWidget + + + + 0 + 0 + 264 + 86 + + + + + 0 + 0 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + Password + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/sources/gui/src/wpasupinteract.cpp b/sources/gui/src/wpasupinteract.cpp index 37e32a4..89c7bc9 100644 --- a/sources/gui/src/wpasupinteract.cpp +++ b/sources/gui/src/wpasupinteract.cpp @@ -49,7 +49,8 @@ QStringList WpaSup::getInterfaceList() { QStringList interfaces; - interfaces.append(mainInterface); + if (!mainInterface.isEmpty()) + interfaces.append(mainInterface); QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + @@ -110,6 +111,17 @@ bool WpaSup::isProfileExists(QString profile) } +QString WpaSup::existentProfile(QString profile) +{ + QString profileFile = QString(""); + QList profileList = parent->netctlCommand->getProfileList(); + for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) + profileFile = profileList[i][0]; + return profileFile; +} + + bool WpaSup::startWpaSupplicant() { if (!QFile(wpaConf[2]).exists()) { diff --git a/sources/gui/src/wpasupinteract.h b/sources/gui/src/wpasupinteract.h index 22916c9..1d756b0 100644 --- a/sources/gui/src/wpasupinteract.h +++ b/sources/gui/src/wpasupinteract.h @@ -37,6 +37,7 @@ public: bool wpaCliCall(QString commandLine); QString getWpaCliOutput(QString commandLine); bool isProfileExists(QString profile); + QString existentProfile(QString profile); bool isProfileActive(QString profile); public slots: