mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
pppoe widget has been completed
This commit is contained in:
parent
a56119d0de
commit
13c63163b1
@ -18,12 +18,19 @@
|
||||
#include "pppoewidget.h"
|
||||
#include "ui_pppoewidget.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
PppoeWidget::PppoeWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui(new Ui::PppoeWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
createActions();
|
||||
createFilter();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
@ -31,3 +38,148 @@ PppoeWidget::~PppoeWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::clear()
|
||||
{
|
||||
ui->lineEdit_username->clear();
|
||||
ui->lineEdit_password->clear();
|
||||
ui->comboBox_connection->setCurrentIndex(0);
|
||||
changeMode(ui->comboBox_connection->currentIndex());
|
||||
ui->spinBox_timeout->setValue(300);
|
||||
ui->spinBox_fail->setValue(5);
|
||||
ui->checkBox_route->setCheckState(Qt::Checked);
|
||||
ui->checkBox_dns->setCheckState(Qt::Checked);
|
||||
ui->lineEdit_unit->clear();
|
||||
ui->spinBox_lcpInterval->setValue(30);
|
||||
ui->spinBox_lcpFailure->setValue(4);
|
||||
ui->lineEdit_options->clear();
|
||||
ui->lineEdit_service->clear();
|
||||
ui->lineEdit_ac->clear();
|
||||
ui->lineEdit_session->clear();
|
||||
ui->lineEdit_mac->clear();
|
||||
ui->checkBox_ipv6->setCheckState(Qt::Unchecked);
|
||||
|
||||
ui->pushButton_pppoeAdvanced->setText(QApplication::translate("PppoeWidget", "Hide advanced"));
|
||||
showAdvanced();
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::createFilter()
|
||||
{
|
||||
// session mac
|
||||
ui->lineEdit_session->setInputMask(QString(">99999:HH:HH:HH:HH:HH:HH"));
|
||||
// mac
|
||||
ui->lineEdit_mac->setInputMask(QString(">HH:HH:HH:HH:HH:HH"));
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::createActions()
|
||||
{
|
||||
connect(ui->pushButton_pppoeAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
|
||||
connect(ui->comboBox_connection, SIGNAL(currentIndexChanged(int)), this, SLOT(changeMode(int)));
|
||||
connect(ui->pushButton_options, SIGNAL(clicked(bool)), this, SLOT(selectOptionsFile()));
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::changeMode(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
ui->widget_timeout->setHidden(true);
|
||||
else if (index == 1)
|
||||
ui->widget_timeout->setShown(true);
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::selectOptionsFile()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QApplication::translate("PppoeWidget", "Select options file"),
|
||||
QDir::currentPath(),
|
||||
QApplication::translate("PppoeWidget", "Configuration files (*.conf)"));
|
||||
if (!filename.isEmpty())
|
||||
ui->lineEdit_options->setText(filename);
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::showAdvanced()
|
||||
{
|
||||
if (ui->pushButton_pppoeAdvanced->text().indexOf(QString("Show")) > -1) {
|
||||
ui->widget_pppoeAdvanced->setShown(true);
|
||||
ui->pushButton_pppoeAdvanced->setText(QApplication::translate("PppoeWidget", "Hide advanced"));
|
||||
}
|
||||
else {
|
||||
ui->widget_pppoeAdvanced->setHidden(true);
|
||||
ui->pushButton_pppoeAdvanced->setText(QApplication::translate("PppoeWidget", "Show advanced"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QString> PppoeWidget::getSettings()
|
||||
{
|
||||
QHash<QString, QString> pppoeSettings;
|
||||
|
||||
if (isOk() == 0) {
|
||||
if (!ui->lineEdit_username->text().isEmpty())
|
||||
pppoeSettings[QString("User")] = QString("'") + ui->lineEdit_username->text() + QString("'");
|
||||
if (!ui->lineEdit_password->text().isEmpty())
|
||||
pppoeSettings[QString("Password")] = QString("'") + ui->lineEdit_password->text() + QString("'");
|
||||
pppoeSettings[QString("ConnectionMode")] = QString("'") + ui->comboBox_connection->currentText() + QString("'");
|
||||
if (ui->comboBox_connection->currentIndex() == 1)
|
||||
pppoeSettings[QString("IdleTimeout")] = QString(ui->spinBox_timeout->value());
|
||||
if (ui->spinBox_fail->value() != 5)
|
||||
pppoeSettings[QString("MaxFail")] = QString(ui->spinBox_fail->value());
|
||||
if (ui->checkBox_route->checkState() == Qt::Unchecked)
|
||||
pppoeSettings[QString("DefaultRoute")] = QString("false");
|
||||
if (ui->checkBox_dns->checkState() == Qt::Unchecked)
|
||||
pppoeSettings[QString("UsePeerDNS")] = QString("false");
|
||||
if (!ui->lineEdit_unit->text().isEmpty())
|
||||
pppoeSettings[QString("PPPUnit")] = ui->lineEdit_unit->text();
|
||||
if (ui->spinBox_lcpInterval->value() != 30)
|
||||
pppoeSettings[QString("LCPEchoInterval")] = QString(ui->spinBox_lcpInterval->value());
|
||||
if (ui->spinBox_lcpFailure->value() != 4)
|
||||
pppoeSettings[QString("LCPEchoFailure")] = QString(ui->spinBox_lcpFailure->value());
|
||||
if (!ui->lineEdit_options->text().isEmpty())
|
||||
pppoeSettings[QString("OptionsFile")] = ui->lineEdit_options->text();
|
||||
if (!ui->lineEdit_service->text().isEmpty())
|
||||
pppoeSettings[QString("PPPoEService")] = QString("'") + ui->lineEdit_service->text() + QString("'");
|
||||
if (!ui->lineEdit_ac->text().isEmpty())
|
||||
pppoeSettings[QString("PPPoEAC")] = QString("'") + ui->lineEdit_ac->text() + QString("'");
|
||||
if (!ui->lineEdit_session->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty())
|
||||
pppoeSettings[QString("PPPoESession")] = QString("'") + ui->lineEdit_session->text().remove(QString(" ")) + QString("'");
|
||||
if (!ui->lineEdit_mac->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty())
|
||||
pppoeSettings[QString("PPPoEMAC")] = QString("'") + ui->lineEdit_mac->text() + QString("'");
|
||||
if (ui->checkBox_ipv6->checkState() == Qt::Checked)
|
||||
pppoeSettings[QString("PPPoEIP6")] = QString("yes");
|
||||
}
|
||||
|
||||
clear();
|
||||
return pppoeSettings;
|
||||
}
|
||||
|
||||
|
||||
int PppoeWidget::isOk()
|
||||
{
|
||||
// config file doesn't exist
|
||||
if (!ui->lineEdit_options->text().isEmpty())
|
||||
if (!QFile(ui->lineEdit_options->text()).exists())
|
||||
return 1;
|
||||
// mac address
|
||||
if (!ui->lineEdit_mac->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty())
|
||||
if (ui->lineEdit_mac->text().indexOf(QString(" ")) > -1)
|
||||
return 2;
|
||||
// session id is not set
|
||||
if (!ui->lineEdit_session->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty())
|
||||
if (ui->lineEdit_session->text().split(QString(":"))[0].remove(QString(" ")).isEmpty())
|
||||
return 3;
|
||||
// session mac address
|
||||
if (!ui->lineEdit_session->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty()) {
|
||||
QStringList item = ui->lineEdit_session->text().split(QString(":"));
|
||||
for (int i=1; i<7; i++)
|
||||
if (item[i].indexOf(QString(" ")) > -1)
|
||||
return 4;
|
||||
}
|
||||
// all fine
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,9 +32,21 @@ class PppoeWidget : public QWidget
|
||||
public:
|
||||
explicit PppoeWidget(QWidget *parent = 0);
|
||||
~PppoeWidget();
|
||||
QHash<QString, QString> getSettings();
|
||||
int isOk();
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void changeMode(int index);
|
||||
void selectOptionsFile();
|
||||
void showAdvanced();
|
||||
|
||||
private:
|
||||
Ui::PppoeWidget *ui;
|
||||
void createActions();
|
||||
void createFilter();
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>431</width>
|
||||
<height>549</height>
|
||||
<height>573</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -16,12 +16,6 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QDockWidget" name="dockWidget_pppoe">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>319</width>
|
||||
<height>47</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="features">
|
||||
<set>QDockWidget::NoDockWidgetFeatures</set>
|
||||
</property>
|
||||
@ -113,37 +107,39 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_timeout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_timeout">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Idle timeout</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_timeout">
|
||||
<property name="toolTip">
|
||||
<string>This option specifies the idle time (in seconds) after which ‘pppd’ should disconnect</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>999</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="widget_timeout" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_timeout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_timeout">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Idle timeout</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_timeout">
|
||||
<property name="toolTip">
|
||||
<string>This option specifies the idle time (in seconds) after which ‘pppd’ should disconnect</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>999</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_pppoeAdvanced">
|
||||
@ -410,21 +406,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_sessionId">
|
||||
<property name="toolTip">
|
||||
<string>This option specifies an existing session to attach to, session ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_sessionSep">
|
||||
<property name="text">
|
||||
<string>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_sessionMac">
|
||||
<widget class="QLineEdit" name="lineEdit_session">
|
||||
<property name="toolTip">
|
||||
<string>This option specifies an existing session to attach to, MAC address</string>
|
||||
</property>
|
||||
|
Loading…
Reference in New Issue
Block a user