/*************************************************************************** * 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 "generalwidget.h" #include "ui_generalwidget.h" #include GeneralWidget::GeneralWidget(QWidget *parent, QString ifaceDir, QString profileDir) : QWidget(parent), ifaceDirectory(new QDir(ifaceDir)), profileDirectory(new QDir(profileDir)), ui(new Ui::GeneralWidget) { ui->setupUi(this); createActions(); clear(); showAdvanced(); } GeneralWidget::~GeneralWidget() { 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->clear(); ui->comboBox_after->clear(); ui->comboBox_after->addItems(profileDirectory->entryList(QDir::Files)); ui->listWidget_after->clear(); ui->lineEdit_execUpPost->clear(); ui->lineEdit_execDownPre->clear(); ui->checkBox_forceConnect->setCheckState(Qt::Unchecked); } 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->pushButton_bindto, SIGNAL(clicked(bool)), 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->text().indexOf(QString("Show")) > -1) { ui->widget_generalAdvanced->setShown(true); ui->pushButton_generalAdvanced->setText(QApplication::translate("GeneralWidget", "Hide advanced")); } else { ui->widget_generalAdvanced->setHidden(true); ui->pushButton_generalAdvanced->setText(QApplication::translate("GeneralWidget", "Show advanced")); } } QHash GeneralWidget::getSettings() { QHash generalSettings; if (isOk() == 0) { generalSettings[QString("Description")] = ui->lineEdit_description->text(); 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; ilistWidget_bindto->count(); i++) interfaces.append(ui->listWidget_bindto->item(i)->text()); generalSettings[QString("BindsToInterfaces")] = interfaces.join(QString(" ")); } if (ui->listWidget_after->count() != 0) { QStringList profiles; for (int i=0; ilistWidget_after->count(); i++) profiles.append(ui->listWidget_after->item(i)->text()); generalSettings[QString("After")] = profiles.join(QString(" ")); } if (!ui->lineEdit_execUpPost->text().isEmpty()) generalSettings[QString("ExecUpPost")] = ui->lineEdit_execUpPost->text(); if (!ui->lineEdit_execDownPre->text().isEmpty()) generalSettings[QString("ExecDownPre")] = ui->lineEdit_execDownPre->text(); if (ui->checkBox_forceConnect->checkState() == Qt::Checked) generalSettings[QString("ForceConnect")] = QString("yes"); } clear(); return generalSettings; } int GeneralWidget::isOk() { // bind interfaces is not set if ((ui->comboBox_connection->currentText() == QString("bond")) || (ui->comboBox_connection->currentText() == QString("bridge"))) if (ui->listWidget_bindto->count() == 0) return 1; // empty description if (ui->lineEdit_description->text().isEmpty()) return 2; // all fine return 0; }