~ubuntu-branches/ubuntu/jaunty/plasma-widget-network-manager/jaunty-updates

« back to all changes in this revision

Viewing changes to libs/dbus/remoteconnection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-02-10 16:33:42 UTC
  • Revision ID: james.westby@ubuntu.com-20090210163342-y22tcldf0fuyqqm9
Tags: upstream-0.0+svn924363
ImportĀ upstreamĀ versionĀ 0.0+svn924363

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
 
3
 
 
4
This program is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU General Public License as
 
6
published by the Free Software Foundation; either version 2 of
 
7
the License or (at your option) version 3 or any later version
 
8
accepted by the membership of KDE e.V. (or its successor approved
 
9
by the membership of KDE e.V.), which shall act as a proxy
 
10
defined in Section 14 of version 3 of the license.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#include "remoteconnection.h"
 
22
 
 
23
#include <NetworkManager.h>
 
24
#include <nm-setting-cdma.h>
 
25
#include <nm-setting-connection.h>
 
26
#include <nm-setting-gsm.h>
 
27
#include <nm-setting-pppoe.h>
 
28
#include <nm-setting-vpn.h>
 
29
#include <nm-setting-wired.h>
 
30
#include <nm-setting-wireless.h>
 
31
 
 
32
#include <QDBusConnection>
 
33
 
 
34
#include <KDebug>
 
35
 
 
36
#include <solid/control/networkmanager.h>
 
37
 
 
38
#include "nm-active-connectioninterface.h"
 
39
 
 
40
RemoteConnection::RemoteConnection(const QString& service, const QString & path, QObject * parent)
 
41
: OrgFreedesktopNetworkManagerSettingsConnectionInterface(service, path, QDBusConnection::systemBus(), parent)
 
42
{
 
43
    qDBusRegisterMetaType<QMap<QString, QVariant> >();
 
44
    qDBusRegisterMetaType<QMap<QString, QMap<QString, QVariant> > >();
 
45
 
 
46
    m_connection = GetSettings();
 
47
    m_path = path;
 
48
    m_type = Solid::Control::NetworkInterface::UnknownType;
 
49
 
 
50
    //kDebug() << m_connection;
 
51
 
 
52
    if ( m_connection.contains(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME))) {
 
53
        QVariantMap connectionSetting = m_connection.value(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME));
 
54
        if (connectionSetting.contains(QLatin1String(NM_SETTING_CONNECTION_ID))) {
 
55
            m_id = connectionSetting.value(QLatin1String(NM_SETTING_CONNECTION_ID)).toString();
 
56
        }
 
57
        QString nmType;
 
58
        if (connectionSetting.contains(QLatin1String(NM_SETTING_CONNECTION_TYPE))) {
 
59
            nmType = connectionSetting.value(QLatin1String(NM_SETTING_CONNECTION_TYPE)).toString();
 
60
        }
 
61
        kDebug() << nmType;
 
62
        if (nmType == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) {
 
63
            m_type = Solid::Control::NetworkInterface::Cdma;
 
64
        } else if (nmType == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) {
 
65
            m_type = Solid::Control::NetworkInterface::Gsm;
 
66
        } else if (nmType == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) {
 
67
            m_type = Solid::Control::NetworkInterface::Serial;
 
68
        } else if (nmType == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) {
 
69
            m_type = Solid::Control::NetworkInterface::Ieee8023;
 
70
        } else if (nmType == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) {
 
71
            m_type = Solid::Control::NetworkInterface::Ieee80211;
 
72
        }
 
73
    }
 
74
}
 
75
 
 
76
RemoteConnection::~RemoteConnection()
 
77
{
 
78
}
 
79
 
 
80
QString RemoteConnection::id() const
 
81
{
 
82
    return m_id;
 
83
}
 
84
 
 
85
Solid::Control::NetworkInterface::Type RemoteConnection::type() const
 
86
{
 
87
    return m_type;
 
88
}
 
89
 
 
90
QVariantMapMap RemoteConnection::settings() const
 
91
{
 
92
    return m_connection;
 
93
}
 
94
 
 
95
bool RemoteConnection::active() const
 
96
{
 
97
    QStringList activeConnections = Solid::Control::NetworkManager::activeConnections();
 
98
    foreach (QString conn, activeConnections) {
 
99
        OrgFreedesktopNetworkManagerConnectionActiveInterface candidate(NM_DBUS_SERVICE,
 
100
                conn, QDBusConnection::systemBus(), 0);
 
101
        if (candidate.serviceName() == service() && candidate.connection().path() == path()) {
 
102
            return true;
 
103
        }
 
104
    }
 
105
    return false;
 
106
}
 
107
 
 
108
QString RemoteConnection::path() const
 
109
{
 
110
    return m_path;
 
111
}
 
112
// vim: sw=4 sts=4 et tw=100