~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to solid/networkmanager-0.7/networkgsminterface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

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 "networkgsminterface.h"
 
22
 
 
23
#include <KDebug>
 
24
 
 
25
#include "networkgsminterface_p.h"
 
26
#include "manager.h"
 
27
 
 
28
#include "solid/control/modemmanager.h"
 
29
 
 
30
NMGsmNetworkInterfacePrivate::NMGsmNetworkInterfacePrivate(const QString & path, QObject * owner)
 
31
    : NMSerialNetworkInterfacePrivate(path, owner), gsmIface(NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus())
 
32
{
 
33
}
 
34
 
 
35
NMGsmNetworkInterface::NMGsmNetworkInterface(const QString & path, NMNetworkManager * manager, QObject * parent)
 
36
    : NMSerialNetworkInterface(*new NMGsmNetworkInterfacePrivate(path, this), manager, parent),
 
37
      modemGsmCardIface(0), modemGsmNetworkIface(0)
 
38
{
 
39
    Q_D(NMGsmNetworkInterface);
 
40
    connect( &d->gsmIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
 
41
                this, SLOT(gsmPropertiesChanged(const QVariantMap &)));
 
42
}
 
43
 
 
44
NMGsmNetworkInterface::NMGsmNetworkInterface(NMGsmNetworkInterfacePrivate & dd, NMNetworkManager * manager, QObject * parent) : NMSerialNetworkInterface(dd, manager, parent),
 
45
      modemGsmCardIface(0), modemGsmNetworkIface(0)
 
46
{
 
47
    Q_D(NMGsmNetworkInterface);
 
48
    connect( &d->gsmIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
 
49
                this, SLOT(gsmPropertiesChanged(const QVariantMap &)));
 
50
}
 
51
 
 
52
NMGsmNetworkInterface::~NMGsmNetworkInterface()
 
53
{
 
54
 
 
55
}
 
56
 
 
57
void NMGsmNetworkInterface::gsmPropertiesChanged(const QVariantMap & changedProperties)
 
58
{
 
59
    kDebug(1441) << changedProperties.keys();
 
60
}
 
61
 
 
62
QString NMGsmNetworkInterface::getUdiForModemManager()
 
63
{
 
64
    if (driver() != QLatin1String("bluez")) {
 
65
        return udi();
 
66
    }
 
67
 
 
68
    /* BlueZ knows about the rfcommX string that we could use to find the device in ModemManager
 
69
     * but does not export this info, so let's use the first bluetooth device we find in ModemManager.
 
70
     * Modem will be registered in ModemManager only after someone execute its org.bluez.Serial.Connect method. */
 
71
    foreach(const Solid::Control::ModemInterface *modem, Solid::Control::ModemManager::modemInterfaces()) {
 
72
        if (modem->driver() == QLatin1String("bluetooth")) {
 
73
            return modem->udi();
 
74
        }
 
75
    }
 
76
 
 
77
    modemRemoved(udi());
 
78
    return QString();
 
79
}
 
80
 
 
81
Solid::Control::ModemGsmCardInterface * NMGsmNetworkInterface::getModemCardIface()
 
82
{
 
83
    QString correctUdi = getUdiForModemManager();
 
84
    if (correctUdi.isEmpty()) {
 
85
        return 0;
 
86
    }
 
87
    if (modemGsmCardIface == 0) {
 
88
        modemGsmCardIface = qobject_cast<Solid::Control::ModemGsmCardInterface*> (Solid::Control::ModemManager::findModemInterface(correctUdi, Solid::Control::ModemInterface::GsmCard));
 
89
        connect(Solid::Control::ModemManager::notifier(), SIGNAL(modemInterfaceRemoved(const QString &)), this, SLOT(modemRemoved(const QString &)));
 
90
    }
 
91
 
 
92
    return modemGsmCardIface;
 
93
}
 
94
 
 
95
Solid::Control::ModemGsmNetworkInterface * NMGsmNetworkInterface::getModemNetworkIface()
 
96
{
 
97
    QString correctUdi = getUdiForModemManager();
 
98
    if (correctUdi.isEmpty()) {
 
99
        return 0;
 
100
    }
 
101
    if (modemGsmNetworkIface == 0) {
 
102
        modemGsmNetworkIface = qobject_cast<Solid::Control::ModemGsmNetworkInterface*> (Solid::Control::ModemManager::findModemInterface(correctUdi, Solid::Control::ModemInterface::GsmNetwork));
 
103
        if (modemGsmNetworkIface) {
 
104
            connect(Solid::Control::ModemManager::notifier(), SIGNAL(modemInterfaceRemoved(const QString &)), this, SLOT(modemRemoved(const QString &)));
 
105
        }
 
106
    }
 
107
 
 
108
    return modemGsmNetworkIface;
 
109
}
 
110
 
 
111
void NMGsmNetworkInterface::modemRemoved(const QString & modemUdi)
 
112
{
 
113
    if (modemUdi == udi()) {
 
114
        modemGsmNetworkIface = 0;
 
115
        modemGsmCardIface = 0;
 
116
    }
 
117
}
 
118
 
 
119
void NMGsmNetworkInterface::setModemCardIface(Solid::Control::ModemGsmCardInterface * iface)
 
120
{
 
121
    modemGsmCardIface = iface;
 
122
}
 
123
 
 
124
void NMGsmNetworkInterface::setModemNetworkIface(Solid::Control::ModemGsmNetworkInterface * iface)
 
125
{
 
126
    modemGsmNetworkIface = iface;
 
127
}
 
128
 
 
129
#include "networkgsminterface.moc"
 
130
 
 
131
// vim: sw=4 sts=4 et tw=100