refactoring of the configuration interface

This commit is contained in:
arcan1s
2014-07-12 22:15:39 +04:00
parent 021a870220
commit 9b01fcd4e1
12 changed files with 1087 additions and 579 deletions

View File

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

View File

@ -44,7 +44,12 @@
#include "wirelesswidget.h"
MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool debugCmd, const bool netctlAuto, const int tabNum)
MainWindow::MainWindow(QWidget *parent,
const bool defaultSettings,
const bool debugCmd,
const bool showNetctlAuto,
const bool showSettings,
const int tabNum)
: QMainWindow(parent),
ui(new Ui::MainWindow),
debug(debugCmd)
@ -97,8 +102,10 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const bool d
updateTabs(ui->tabWidget->currentIndex());
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Ready"));
if (netctlAuto)
if (showNetctlAuto)
netctlAutoWin->showWindow();
if (showSettings)
settingsWin->showWindow();
}
@ -1287,6 +1294,8 @@ void MainWindow::connectToUnknownEssid(const QString passwd)
if (!passwd.isEmpty())
settings[QString("Key")] = QString("'") + passwd + QString("'");
settings[QString("IP")] = QString("dhcp");
if (hiddenNetwork)
settings[QString("Hidden")] = QString("yes");
QString profile = QString("netctl-gui-") + settings[QString("ESSID")];
profile.remove(QString("'"));
@ -1325,6 +1334,7 @@ void MainWindow::wifiTabStart()
if (ui->tableWidget_wifi->currentItem() == 0)
return;
if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("<hidden>")) {
hiddenNetwork = true;
passwdWid = new PasswdWidget(this);
passwdWid->setPassword(false);
int widgetWidth = 270;
@ -1338,6 +1348,7 @@ void MainWindow::wifiTabStart()
}
ui->tabWidget->setDisabled(true);
hiddenNetwork = false;
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)) {

View File

@ -54,7 +54,8 @@ public:
explicit MainWindow(QWidget *parent = 0,
const bool defaultSettings = false,
const bool debugCmd = false,
const bool netctlAuto = false,
const bool showNetctlAuto = false,
const bool showSettings = false,
const int tabNum = 1);
~MainWindow();
@ -123,6 +124,7 @@ private:
void keyPressEvent(QKeyEvent *pressedKey);
void setIconsToButtons();
bool debug;
bool hiddenNetwork;
// configuration
QMap<QString, QString> configuration;
};

View File

@ -52,6 +52,7 @@ void SettingsWindow::createActions()
{
if (debug) qDebug() << "[SettingsWindow]" << "[createActions]";
connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *)));
connect(ui->comboBox_language, SIGNAL(currentIndexChanged(int)), ui->label_info, SLOT(show()));
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked(bool)), this, SLOT(close()));
connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this, SLOT(setDefault()));
@ -90,6 +91,19 @@ void SettingsWindow::addLanguages()
}
void SettingsWindow::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous)
if (debug) qDebug() << "[SettingsWindow]" << "[changePage]";
for (int i=0; i<ui->treeWidget->topLevelItemCount(); i++)
if (current == ui->treeWidget->topLevelItem(i)) {
ui->stackedWidget->setCurrentIndex(i);
break;
}
}
void SettingsWindow::saveSettings()
{
if (debug) qDebug() << "[SettingsWindow]" << "[saveSettings]";

View File

@ -20,6 +20,7 @@
#include <QKeyEvent>
#include <QMainWindow>
#include <QTreeWidgetItem>
class MainWindow;
@ -46,6 +47,7 @@ public slots:
private slots:
void addLanguages();
void changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void saveSettings();
// buttons
void selectIfaceDir();

File diff suppressed because it is too large Load Diff