mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
+ add signals to lineEdits * rewrite errorwindow class to static methods * replace mask in ip lineedits to validators (fix #34) * fix advanced lines * move AdHoc and Hidden options to advanced (#28) * fix default wpa_supplicant conf path (#28) * update toolbars to #2 * replace General settings section to Common (see http://doc.qt.io/qt-5/qsettings.html#Format-enum)
209 lines
8.4 KiB
C++
209 lines
8.4 KiB
C++
/***************************************************************************
|
|
* 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 "generalwidget.h"
|
|
#include "ui_generalwidget.h"
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
GeneralWidget::GeneralWidget(QWidget *parent, const QMap<QString, QString> settings)
|
|
: QWidget(parent),
|
|
ui(new Ui::GeneralWidget)
|
|
{
|
|
ui->setupUi(this);
|
|
connectionType = ui->comboBox_connection;
|
|
ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
|
|
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
|
createActions();
|
|
clear();
|
|
}
|
|
|
|
|
|
GeneralWidget::~GeneralWidget()
|
|
{
|
|
delete connectionType;
|
|
delete ifaceDirectory;
|
|
delete profileDirectory;
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void GeneralWidget::clear()
|
|
{
|
|
ui->lineEdit_description->setText(QString("Generated by Netctl GUI"));
|
|
ui->comboBox_connection->setCurrentIndex(0);
|
|
ui->comboBox_interface->clear();
|
|
ui->comboBox_interface->addItems(ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
|
ui->comboBox_bindto->clear();
|
|
ui->comboBox_bindto->addItems(ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
|
ui->listWidget_bindto->setCurrentRow(-1);
|
|
ui->listWidget_bindto->clear();
|
|
ui->comboBox_after->clear();
|
|
ui->comboBox_after->addItems(profileDirectory->entryList(QDir::Files));
|
|
ui->listWidget_after->setCurrentRow(-1);
|
|
ui->listWidget_after->clear();
|
|
ui->lineEdit_execUpPost->clear();
|
|
ui->lineEdit_execDownPre->clear();
|
|
ui->checkBox_forceConnect->setCheckState(Qt::Unchecked);
|
|
ui->checkBox_debug->setCheckState(Qt::Unchecked);
|
|
|
|
ui->pushButton_generalAdvanced->setChecked(false);
|
|
showAdvanced();
|
|
}
|
|
|
|
|
|
void GeneralWidget::setShown(const bool state)
|
|
{
|
|
if (state)
|
|
show();
|
|
else
|
|
hide();
|
|
}
|
|
|
|
|
|
void GeneralWidget::createActions()
|
|
{
|
|
connect(ui->pushButton_generalAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
|
|
connect(ui->pushButton_after, SIGNAL(clicked(bool)), this, SLOT(addAfter()));
|
|
connect(ui->comboBox_after->lineEdit(), SIGNAL(returnPressed()), this, SLOT(addAfter()));
|
|
connect(ui->pushButton_bindto, SIGNAL(clicked(bool)), this, SLOT(addBindTo()));
|
|
connect(ui->comboBox_bindto->lineEdit(), SIGNAL(returnPressed()), this, SLOT(addBindTo()));
|
|
}
|
|
|
|
|
|
void GeneralWidget::addAfter()
|
|
{
|
|
ui->listWidget_after->addItem(ui->comboBox_after->currentText());
|
|
}
|
|
|
|
|
|
void GeneralWidget::addBindTo()
|
|
{
|
|
ui->listWidget_bindto->addItem(ui->comboBox_bindto->currentText());
|
|
}
|
|
|
|
|
|
void GeneralWidget::keyPressEvent(QKeyEvent *pressedKey)
|
|
{
|
|
if (pressedKey->key() == Qt::Key_Delete) {
|
|
if (ui->listWidget_bindto->hasFocus() &&
|
|
(ui->listWidget_bindto->currentItem() != 0))
|
|
delete ui->listWidget_bindto->currentItem();
|
|
else if (ui->listWidget_after->hasFocus() &&
|
|
(ui->listWidget_after->currentItem() != 0))
|
|
delete ui->listWidget_after->currentItem();
|
|
}
|
|
}
|
|
|
|
|
|
void GeneralWidget::showAdvanced()
|
|
{
|
|
if (ui->pushButton_generalAdvanced->isChecked()) {
|
|
ui->widget_generalAdvanced->setHidden(false);
|
|
ui->pushButton_generalAdvanced->setText(QApplication::translate("GeneralWidget", "Hide advanced"));
|
|
} else {
|
|
ui->widget_generalAdvanced->setHidden(true);
|
|
ui->pushButton_generalAdvanced->setText(QApplication::translate("GeneralWidget", "Show advanced"));
|
|
}
|
|
}
|
|
|
|
|
|
QMap<QString, QString> GeneralWidget::getSettings()
|
|
{
|
|
QMap<QString, QString> generalSettings;
|
|
|
|
if (isOk() != 0)
|
|
return generalSettings;
|
|
|
|
generalSettings[QString("Description")] = QString("'") + ui->lineEdit_description->text() + QString("'");
|
|
generalSettings[QString("Connection")] = ui->comboBox_connection->currentText();
|
|
generalSettings[QString("Interface")] = ui->comboBox_interface->currentText();
|
|
if (ui->listWidget_bindto->count() != 0) {
|
|
QStringList interfaces;
|
|
for (int i=0; i<ui->listWidget_bindto->count(); i++)
|
|
interfaces.append(ui->listWidget_bindto->item(i)->text());
|
|
generalSettings[QString("BindsToInterfaces")] = interfaces.join(QChar(' '));
|
|
}
|
|
if (ui->listWidget_after->count() != 0) {
|
|
QStringList profiles;
|
|
for (int i=0; i<ui->listWidget_after->count(); i++)
|
|
profiles.append(ui->listWidget_after->item(i)->text());
|
|
generalSettings[QString("After")] = profiles.join(QChar(' '));
|
|
}
|
|
if (!ui->lineEdit_execUpPost->text().isEmpty())
|
|
generalSettings[QString("ExecUpPost")] = QString("'") + ui->lineEdit_execUpPost->text() + QString("'");
|
|
if (!ui->lineEdit_execDownPre->text().isEmpty())
|
|
generalSettings[QString("ExecDownPre")] = QString("'") + ui->lineEdit_execDownPre->text() + QString("'");
|
|
if (ui->checkBox_forceConnect->checkState() == Qt::Checked)
|
|
generalSettings[QString("ForceConnect")] = QString("yes");
|
|
if (ui->checkBox_debug->checkState() == Qt::Checked)
|
|
generalSettings[QString("NETCTL_DEBUG")] = QString("yes");
|
|
|
|
return generalSettings;
|
|
}
|
|
|
|
|
|
int GeneralWidget::isOk()
|
|
{
|
|
// bind interfaces is not set
|
|
if ((ui->comboBox_connection->currentText() == QString("bond")) ||
|
|
(ui->comboBox_connection->currentText() == QString("bridge")) ||
|
|
(ui->comboBox_connection->currentText() == QString("vlan")) ||
|
|
(ui->comboBox_connection->currentText() == QString("macvlan")) ||
|
|
(ui->comboBox_connection->currentText() == QString("openvswitch")))
|
|
if (ui->listWidget_bindto->count() == 0)
|
|
return 1;
|
|
// empty description
|
|
if (ui->lineEdit_description->text().isEmpty())
|
|
return 2;
|
|
// all fine
|
|
return 0;
|
|
}
|
|
|
|
|
|
void GeneralWidget::setSettings(const QMap<QString, QString> settings)
|
|
{
|
|
clear();
|
|
QMap<QString, QString> generalSettings = settings;
|
|
|
|
if (generalSettings.contains(QString("Description")))
|
|
ui->lineEdit_description->setText(generalSettings[QString("Description")]);
|
|
if (generalSettings.contains(QString("Connection")))
|
|
for (int i=0; i<ui->comboBox_connection->count(); i++)
|
|
if (generalSettings[QString("Connection")] == ui->comboBox_connection->itemText(i))
|
|
ui->comboBox_connection->setCurrentIndex(i);
|
|
if (generalSettings.contains(QString("Interface"))) {
|
|
ui->comboBox_interface->addItem(generalSettings[QString("Interface")]);
|
|
ui->comboBox_interface->setCurrentIndex(ui->comboBox_interface->count()-1);
|
|
}
|
|
if (generalSettings.contains(QString("BindsToInterfaces")))
|
|
ui->listWidget_bindto->addItems(generalSettings[QString("BindsToInterfaces")].split(QChar('\n')));
|
|
if (generalSettings.contains(QString("After")))
|
|
ui->listWidget_after->addItems(generalSettings[QString("After")].split(QChar('\n')));
|
|
if (generalSettings.contains(QString("ExecUpPost")))
|
|
ui->lineEdit_execUpPost->setText(generalSettings[QString("ExecUpPost")]);
|
|
if (generalSettings.contains(QString("ExecDownPre")))
|
|
ui->lineEdit_execDownPre->setText(generalSettings[QString("ExecDownPre")]);
|
|
if (generalSettings.contains(QString("ForceConnect")))
|
|
if (generalSettings[QString("ForceConnect")] == QString("yes"))
|
|
ui->checkBox_forceConnect->setCheckState(Qt::Checked);
|
|
if (generalSettings.contains(QString("NETCTL_DEBUG")))
|
|
if (generalSettings[QString("NETCTL_DEBUG")] == QString("yes"))
|
|
ui->checkBox_debug->setCheckState(Qt::Checked);
|
|
}
|