1
/* This file is part of the KDE project
2
Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
20
#include "fakenetwork.h"
22
QList<QHostAddress> FakeNetwork::stringlistToKIpAddress( const QStringList & addrStringList) const
24
QList<QHostAddress> ipv4Addrs;
25
foreach (const QString &addrString, addrStringList)
27
QHostAddress addr( addrString);
28
ipv4Addrs.append( addr);
33
QList<QNetworkAddressEntry> FakeNetwork::stringlistsToQNetworkAddressEntries(const QStringList & addrStringList, const QStringList & subnets, const QStringList & bcasts) const
35
if (!(addrStringList.count() == subnets.count() && subnets.count() == bcasts.count()))
36
return QList<QNetworkAddressEntry>();
38
QList<QNetworkAddressEntry> entries;
39
for (int i = 0; i< addrStringList.count(); ++i)
41
QNetworkAddressEntry addr;
42
addr.setIp(QHostAddress(addrStringList[i]));
43
addr.setNetmask(QHostAddress(subnets[i]));
44
addr.setBroadcast(QHostAddress(bcasts[i]));
51
FakeNetwork::FakeNetwork(const QString & uni, const QMap<QString, QVariant> & propertyMap,
53
: QObject(parent), mPropertyMap(propertyMap)
55
mPropertyMap.insert("uni", QVariant(uni));
58
FakeNetwork::~FakeNetwork()
63
QList<QNetworkAddressEntry> FakeNetwork::addressEntries() const
65
return stringlistsToQNetworkAddressEntries(mPropertyMap["addresses"].toStringList(),
66
mPropertyMap["subnet"].toStringList(),
67
mPropertyMap["broadcast"].toStringList()
71
QString FakeNetwork::route() const
73
return mPropertyMap["route"].toString();
76
QList<QHostAddress> FakeNetwork::dnsServers() const
78
return stringlistToKIpAddress(mPropertyMap["dns"].toString().simplified().split(','));
81
void FakeNetwork::setActivated(bool active)
83
mPropertyMap.insert("active", QVariant(active));
86
bool FakeNetwork::isActive() const
88
return mPropertyMap["active"].toBool();
91
QString FakeNetwork::uni() const
93
return mPropertyMap["uni"].toString();
96
#include "fakenetwork.moc"