Commit a941db19 authored by Ilia Kats's avatar Ilia Kats
Browse files

Enable setting of custom routes.

Had to add our own IntValidator, as QIntValidator permits periods
and commas as thousand separator, and we don't want that in
prefix or metric settings.

BUG: 257920
to the reporter: IP != route
(cherry picked from commit b36c20a0)
parent 0e316f70
......@@ -22,7 +22,7 @@ void Ipv4Dbus::fromMap(const QVariantMap & map)
foreach(QString key, map.keys())
kDebug() << key << " : " << map.value(key);
Knm::Ipv4Setting * setting = static_cast<Knm::Ipv4Setting*>(m_setting);
Knm::Ipv4Setting * setting = static_cast<Knm::Ipv4Setting*>(m_setting);
if (map.contains("method")) {
setting->setMethod(methodStringToEnum(map.value("method").value<QString>())); }
......@@ -82,6 +82,35 @@ void Ipv4Dbus::fromMap(const QVariantMap & map)
setting->setAddresses(addresses);
}
if (map.contains("routes"))
{
QDBusArgument routeArg = map.value("routes").value< QDBusArgument>();
QList<Solid::Control::IPv4Route> routes;
routeArg.beginArray();
while(!routeArg.atEnd())
{
QList<uint> uintList;
routeArg >> uintList;
if (uintList.count() != 4)
{
kWarning() << "Invalid route format detected. UInt count is " << uintList.count();
continue;
}
Solid::Control::IPv4Route route((quint32)ntohl(uintList.at(0)), (quint32)uintList.at(1), (quint32)ntohl(uintList.at(2)), (quint32)uintList.at(3));
if (!route.isValid())
{
kWarning() << "Invalid route format detected.";
continue;
}
routes << route;
}
if (!routes.isEmpty())
setting->setRoutes(routes);
}
if (map.contains(QLatin1String(NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS))) {
setting->setIgnoredhcpdns(map.value(QLatin1String(NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)).value<bool>());
}
......
......@@ -70,11 +70,11 @@ void Ipv6Dbus::fromMap(const QVariantMap & map)
continue;
}
Q_IPV6ADDR ip, gateway;
for (int i = 0; i < addressMap.address.size(); i++)
for (int i = 0; i < 16; i++)
{
ip[i] = addressMap.address[i];
}
for (int i = 0; i < addressMap.gateway.size(); i++)
for (int i = 0; i < 16; i++)
{
gateway[i] = addressMap.gateway[i];
}
......@@ -93,6 +93,44 @@ void Ipv6Dbus::fromMap(const QVariantMap & map)
setting->setAddresses(addresses);
}
if (map.contains("routes"))
{
QDBusArgument routeArg = map.value("routes").value< QDBusArgument>();
QList<Solid::Control::IPv6Route> routes;
routeArg.beginArray();
while(!routeArg.atEnd())
{
IpV6RouteMap routeMap;
routeArg >> routeMap;
if (routeMap.route.isEmpty() || !routeMap.prefix || routeMap.nextHop.isEmpty() || !routeMap.metric)
{
kWarning() << "Invalid route format detected.";
continue;
}
Q_IPV6ADDR addr, nexthop;
for (int i = 0; i < 16; i++)
{
addr[i] = routeMap.route[i];
}
for (int i = 0; i < 16; i++)
{
nexthop[i] = routeMap.nextHop[i];
}
Solid::Control::IPv6Route route(addr, routeMap.prefix, nexthop, routeMap.metric);
if (!route.isValid())
{
kWarning() << "Invalid route format detected.";
continue;
}
routes << route;
}
setting->setRoutes(routes);
}
if (map.contains(QLatin1String(NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS))) {
setting->setIgnoredhcpdns(map.value(QLatin1String(NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)).value<bool>());
}
......@@ -200,14 +238,14 @@ QVariantMap Ipv6Dbus::toMap()
QList<quint8> assembledRoute;
for (int i = 0; i < 16; i++)
{
assembledRoute[i] = Route[i];
assembledRoute << Route[i];
}
Q_IPV6ADDR nextHop = route.nextHop();
QList<quint8> assembledNextHop;
for (int i = 0; i < 16; i++)
{
assembledNextHop[i] = nextHop[i];
assembledNextHop << nextHop[i];
}
dbusRoute.route = assembledRoute;
......
......@@ -130,7 +130,7 @@ void Ipv4Persistence::save()
<< QString::number(route.prefix())
<< QHostAddress(route.nextHop()).toString()
<< QString::number(route.metric());
rawRoutes << rawRoute;
rawRoutes << rawRoute.join(";");
}
m_config->writeEntry("routes", rawRoutes);
......
......@@ -129,7 +129,7 @@ void Ipv6Persistence::save()
<< QString::number(route.metric());
rawRoutes << rawRoute;
}
m_config->writeEntry("routes", rawRoutes);
m_config->writeEntry("routes", rawRoutes.join(";"));
m_config->writeEntry("ignoredhcpdns", setting->ignoredhcpdns());
m_config->writeEntry("ignoreautoroute", setting->ignoreautoroute());
......
......@@ -20,8 +20,12 @@ set(knmui_SRCS
connectionwidget.cpp
ipv4widget.cpp
ipv4advancedwidget.cpp
ipv4routeswidget.cpp
ipv4delegate.cpp
ipv6widget.cpp
ipv6advancedwidget.cpp
ipv6routeswidget.cpp
ipv6delegate.cpp
wiredwidget.cpp
802_11_wirelesswidget.cpp
accesspoint.cpp
......@@ -65,11 +69,14 @@ set(knmui_SRCS
wirelesspreferences.cpp
connectioneditor.cpp
connectionsecretsjob.cpp
simpleipv4addressvalidator.cpp
simpleipv6addressvalidator.cpp
listvalidator.cpp
intvalidator.cpp
editlistdialog.cpp
delegate.cpp
intdelegate.cpp
)
kde4_add_ui_files(knmui_SRCS
......@@ -83,8 +90,10 @@ kde4_add_ui_files(knmui_SRCS
wired.ui
ipv4.ui
ipv4advanced.ui
ipv4routes.ui
ipv6.ui
ipv6advanced.ui
ipv6routes.ui
802-11-wireless.ui
# Scan widget for wireless
......
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "delegate.h"
#include <QLineEdit>
#include <QStandardItem>
#include <QStandardItemModel>
Delegate::Delegate(QObject * parent) : QStyledItemDelegate(parent) {}
Delegate::~Delegate() {}
QWidget * Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &) const
{
QLineEdit *editor = new QLineEdit(parent);
return editor;
}
void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QLineEdit *le = static_cast<QLineEdit*>(editor);
le->setText(value);
}
void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *le = static_cast<QLineEdit*>(editor);
model->setData(index, le->text(), Qt::EditRole);
}
void Delegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &) const
{
editor->setGeometry(option.rect);
}
\ No newline at end of file
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DELEGATE_H
#define DELEGATE_H
#include <QWidget>
#include <QStyledItemDelegate>
class Delegate : public QStyledItemDelegate
{
Q_OBJECT
public:
Delegate(QObject * parent = 0);
virtual ~Delegate();
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
virtual void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif
\ No newline at end of file
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "intdelegate.h"
#include "intvalidator.h"
IntDelegate::IntDelegate(QObject * parent) : Delegate(parent), m_boundary(false) {}
IntDelegate::IntDelegate(int min, int max, QObject * parent) : Delegate(parent), m_min(min), m_max(max), m_boundary(true) {}
IntDelegate::~IntDelegate() {}
QWidget * IntDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &) const
{
QLineEdit *editor = new QLineEdit(parent);
if (m_boundary)
editor->setValidator(new IntValidator(m_min, m_max, editor));
else
editor->setValidator(new IntValidator(editor));
return editor;
}
\ No newline at end of file
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INTDELEGATE_H
#define INTDELEGATE_H
#include <QLineEdit>
#include <QStandardItem>
#include <QStandardItemModel>
#include "delegate.h"
class IntDelegate : public Delegate
{
Q_OBJECT
public:
IntDelegate(QObject * parent = 0);
IntDelegate(int min, int max, QObject * parent = 0);
virtual ~IntDelegate();
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
private:
int m_min;
int m_max;
bool m_boundary;
};
#endif
\ No newline at end of file
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <KDebug>
#include <QStringList>
#include "intvalidator.h"
IntValidator::IntValidator(QObject *parent)
: QValidator(parent)
{
m_signed = false;
}
IntValidator::IntValidator(bool isSigned, QObject *parent)
:QValidator(parent), m_signed(isSigned), m_boundary(false)
{
}
IntValidator::IntValidator(int min, int max, QObject *parent)
:QValidator(parent), m_min(min), m_max(max), m_boundary(true)
{
}
IntValidator::~IntValidator()
{
}
QValidator::State IntValidator::validate(QString &value, int &pos) const
{
if (m_boundary)
{
int num = value.toInt();
if (num < m_min || num > m_max)
return QValidator::Invalid;
}
QRegExpValidator *v;
switch (m_signed)
{
case false:
v = new QRegExpValidator(QRegExp("^[0-9]*$"), 0);
break;
case true:
default:
v = new QRegExpValidator(QRegExp("^-?[0-9]*$"), 0);
break;
}
return v->validate(value,pos);
}
\ No newline at end of file
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
This program 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 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INTVALIDATOR_H
#define INTVALIDATOR_H
#include <QValidator>
class IntValidator : public QValidator
{
public:
IntValidator(QObject *parent);
IntValidator(bool isSigned,QObject *parent);
IntValidator(int min, int max, QObject *parent);
virtual ~IntValidator();
virtual State validate(QString &, int &) const;
private:
bool m_signed;
int m_min;
int m_max;
bool m_boundary;
};
#endif // INTVALIDATOR_H
......@@ -374,24 +374,7 @@
<widget class="QWidget" name="pageRoutes">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="cbIgnoreAutoRoutes">
<property name="toolTip">
<string>If checked, only manually configured routes will be used</string>
</property>
<property name="text">
<string>Ignore &amp;automatically obtained routes</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbNeverDefault">
<property name="toolTip">
<string>Determines whether this connection should receive the default route</string>
</property>
<property name="text">
<string>Use &amp;only for resources on this connection</string>
</property>
</widget>
<widget class="IpV4RoutesWidget" name="routesSettings" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
......@@ -444,6 +427,12 @@
<header>ipv4advancedwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>IpV4RoutesWidget</class>
<extends>QWidget</extends>
<header>ipv4routeswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>method</tabstop>
......@@ -456,8 +445,6 @@
<tabstop>dnsSearchMorePushButton</tabstop>
<tabstop>dhcpClientId</tabstop>
<tabstop>cmbSettingsMode</tabstop>
<tabstop>cbIgnoreAutoRoutes</tabstop>
<tabstop>cbNeverDefault</tabstop>
</tabstops>
<resources/>
<connections>
......@@ -468,8 +455,8 @@
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>291</x>
<y>30</y>
<x>294</x>
<y>26</y>
</hint>
<hint type="destinationlabel">
<x>429</x>
......
......@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QLineEdit>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QNetworkAddressEntry>
//#include <QHostAddress>
......@@ -31,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ipv4advancedwidget.h"
#include "simpleipv4addressvalidator.h"
#include "ipv4delegate.h"
class IpV4AdvancedWidget::Private
{
......@@ -48,41 +48,6 @@ public:
QStandardItemModel model;
};
Ipv4Delegate::Ipv4Delegate(QObject * parent) : QStyledItemDelegate(parent) {}
Ipv4Delegate::~Ipv4Delegate() {}
QWidget * Ipv4Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &) const
{
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(new SimpleIpV4AddressValidator(editor));
return editor;
}
void Ipv4Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QLineEdit *le = static_cast<QLineEdit*>(editor);
le->setText(value);
}
void Ipv4Delegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *le = static_cast<QLineEdit*>(editor);
model->setData(index, le->text(), Qt::EditRole);
}
void Ipv4Delegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &) const
{
editor->setGeometry(option.rect);
}
IpV4AdvancedWidget::IpV4AdvancedWidget(QWidget * parent)
: QWidget(parent), d(new IpV4AdvancedWidget::Private())
{
......@@ -92,7 +57,7 @@ IpV4AdvancedWidget::IpV4AdvancedWidget(QWidget * parent)
d->ui.tableViewAddresses->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
d->ui.tableViewAddresses->horizontalHeader()->setStretchLastSection(true);
Ipv4Delegate *ipDelegate = new Ipv4Delegate(this);
IpV4Delegate *ipDelegate = new IpV4Delegate(this);
d->ui.tableViewAddresses->setItemDelegateForColumn(0, ipDelegate);
d->ui.tableViewAddresses->setItemDelegateForColumn(1, ipDelegate);
d->ui.tableViewAddresses->setItemDelegateForColumn(2, ipDelegate);
......
......@@ -23,28 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IPV4ADVANCEDWIDGET_H
#include <QWidget>
#include <QStandardItem>