~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to solid/control/backends/fakenet/fakenetwork.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE project
 
2
    Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
 
 
18
*/
 
19
 
 
20
#include "fakenetwork.h"
 
21
 
 
22
QList<QHostAddress> FakeNetwork::stringlistToKIpAddress( const QStringList  & addrStringList) const
 
23
{
 
24
    QList<QHostAddress> ipv4Addrs;
 
25
    foreach (const QString &addrString, addrStringList)
 
26
    {
 
27
        QHostAddress addr( addrString);
 
28
        ipv4Addrs.append( addr);
 
29
    }
 
30
    return ipv4Addrs;
 
31
}
 
32
 
 
33
QList<QNetworkAddressEntry> FakeNetwork::stringlistsToQNetworkAddressEntries(const QStringList  & addrStringList, const QStringList  & subnets, const QStringList  & bcasts) const
 
34
{
 
35
    if (!(addrStringList.count() == subnets.count() && subnets.count() == bcasts.count()))
 
36
        return QList<QNetworkAddressEntry>();
 
37
 
 
38
    QList<QNetworkAddressEntry> entries;
 
39
    for (int i = 0; i< addrStringList.count(); ++i)
 
40
    {
 
41
        QNetworkAddressEntry addr;
 
42
        addr.setIp(QHostAddress(addrStringList[i]));
 
43
        addr.setNetmask(QHostAddress(subnets[i]));
 
44
        addr.setBroadcast(QHostAddress(bcasts[i]));
 
45
        entries.append(addr);
 
46
    }
 
47
    return entries;
 
48
 
 
49
}
 
50
 
 
51
FakeNetwork::FakeNetwork(const QString  & uni, const QMap<QString, QVariant>  & propertyMap,
 
52
                          QObject * parent)
 
53
: QObject(parent), mPropertyMap(propertyMap)
 
54
{
 
55
    mPropertyMap.insert("uni", QVariant(uni));
 
56
}
 
57
 
 
58
FakeNetwork::~FakeNetwork()
 
59
{
 
60
 
 
61
}
 
62
 
 
63
QList<QNetworkAddressEntry> FakeNetwork::addressEntries() const
 
64
{
 
65
    return stringlistsToQNetworkAddressEntries(mPropertyMap["addresses"].toStringList(),
 
66
                                   mPropertyMap["subnet"].toStringList(),
 
67
                                   mPropertyMap["broadcast"].toStringList()
 
68
                                );
 
69
}
 
70
 
 
71
QString FakeNetwork::route() const
 
72
{
 
73
    return mPropertyMap["route"].toString();
 
74
}
 
75
 
 
76
QList<QHostAddress> FakeNetwork::dnsServers() const
 
77
{
 
78
        return stringlistToKIpAddress(mPropertyMap["dns"].toString().simplified().split(','));
 
79
}
 
80
 
 
81
void FakeNetwork::setActivated(bool active)
 
82
{
 
83
    mPropertyMap.insert("active", QVariant(active));
 
84
}
 
85
 
 
86
bool FakeNetwork::isActive() const
 
87
{
 
88
    return mPropertyMap["active"].toBool();
 
89
}
 
90
 
 
91
QString FakeNetwork::uni() const
 
92
{
 
93
    return mPropertyMap["uni"].toString();
 
94
}
 
95
 
 
96
#include "fakenetwork.moc"