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

« back to all changes in this revision

Viewing changes to solid/modemmanager-0.4/modeminterface.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
Copyright 2010 Lamarque Souza <lamarque@gmail.com>
 
4
 
 
5
This program is free software; you can redistribute it and/or
 
6
modify it under the terms of the GNU General Public License as
 
7
published by the Free Software Foundation; either version 2 of
 
8
the License or (at your option) version 3 or any later version
 
9
accepted by the membership of KDE e.V. (or its successor approved
 
10
by the membership of KDE e.V.), which shall act as a proxy
 
11
defined in Section 14 of version 3 of the license.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <KDebug>
 
23
 
 
24
#include "manager.h"
 
25
#include "modeminterface.h"
 
26
#include "modeminterface_p.h"
 
27
 
 
28
MMModemInterfacePrivate::MMModemInterfacePrivate( const QString & path, QObject * owner ) : modemIface(MMModemManager::DBUS_SERVICE, path, QDBusConnection::systemBus()), modemSimpleIface(MMModemManager::DBUS_SERVICE, path, QDBusConnection::systemBus()), udi(path), manager(0)
 
29
{
 
30
    Q_UNUSED(owner);
 
31
}
 
32
 
 
33
MMModemInterfacePrivate::~MMModemInterfacePrivate()
 
34
{
 
35
 
 
36
}
 
37
 
 
38
MMModemInterface::MMModemInterface(const QString & path, MMModemManager * manager, QObject * parent) : QObject(parent), d_ptr(new MMModemInterfacePrivate(path, this))
 
39
{
 
40
    Q_D(MMModemInterface);
 
41
    init();
 
42
    d->manager = manager;
 
43
}
 
44
 
 
45
MMModemInterface::MMModemInterface(MMModemInterfacePrivate & dd, MMModemManager * manager, QObject * parent) : QObject(parent), d_ptr(&dd)
 
46
{
 
47
    Q_D(MMModemInterface);
 
48
    init();
 
49
    d->manager = manager;
 
50
}
 
51
 
 
52
MMModemInterface::~MMModemInterface()
 
53
{
 
54
    delete d_ptr;
 
55
}
 
56
 
 
57
void MMModemInterface::init()
 
58
{
 
59
    Q_D(MMModemInterface);
 
60
    d->device = d->modemIface.device();
 
61
    d->masterDevice = d->modemIface.masterDevice();
 
62
    d->driver = d->modemIface.driver();
 
63
    d->type = (Solid::Control::ModemInterface::Type) d->modemIface.type();
 
64
    d->enabled = d->modemIface.enabled();
 
65
    d->unlockRequired = d->modemIface.unlockRequired();
 
66
    d->ipMethod = (Solid::Control::ModemInterface::Method) d->modemIface.ipMethod();
 
67
 
 
68
    d->modemIface.connection().connect(MMModemManager::DBUS_SERVICE,
 
69
                                       d->udi, QLatin1String("org.freedesktop.DBus.Properties"),
 
70
                                       QLatin1String("MmPropertiesChanged"), QLatin1String("sa{sv}"),
 
71
                                       this, SLOT(propertiesChanged(const QString &,const QVariantMap &)));
 
72
}
 
73
 
 
74
QString MMModemInterface::udi() const
 
75
{
 
76
    Q_D(const MMModemInterface);
 
77
    return d->udi;
 
78
}
 
79
 
 
80
 
 
81
/*** From org.freedesktop.ModemManager.Modem ***/
 
82
 
 
83
void MMModemInterface::enable(const bool enable)
 
84
{
 
85
    Q_D(MMModemInterface);
 
86
    d->modemIface.Enable(enable);
 
87
}
 
88
 
 
89
void MMModemInterface::connectModem(const QString & number)
 
90
{
 
91
    Q_D(MMModemInterface);
 
92
    d->modemIface.Connect(number);
 
93
}
 
94
 
 
95
void MMModemInterface::disconnectModem()
 
96
{
 
97
    Q_D(MMModemInterface);
 
98
    d->modemIface.Disconnect();
 
99
}
 
100
 
 
101
Solid::Control::ModemInterface::Ip4ConfigType MMModemInterface::getIp4Config()
 
102
{
 
103
    Q_D(MMModemInterface);
 
104
    QDBusReply<Ip4ConfigType> config = d->modemIface.GetIP4Config();
 
105
 
 
106
    if (config.isValid()) {
 
107
        return config.value();
 
108
    }
 
109
 
 
110
    return Ip4ConfigType();
 
111
}
 
112
 
 
113
Solid::Control::ModemInterface::InfoType MMModemInterface::getInfo()
 
114
{
 
115
    Q_D(MMModemInterface);
 
116
    QDBusReply<InfoType> info = d->modemIface.GetInfo();
 
117
 
 
118
    if (info.isValid()) {
 
119
        return info.value();
 
120
    }
 
121
 
 
122
    return InfoType();
 
123
}
 
124
 
 
125
QString MMModemInterface::device() const
 
126
{
 
127
    Q_D(const MMModemInterface);
 
128
    return d->device;
 
129
}
 
130
 
 
131
QString MMModemInterface::masterDevice() const
 
132
{
 
133
    Q_D(const MMModemInterface);
 
134
    return d->masterDevice;
 
135
}
 
136
 
 
137
QString MMModemInterface::driver() const
 
138
{
 
139
    Q_D(const MMModemInterface);
 
140
    return d->driver;
 
141
}
 
142
 
 
143
Solid::Control::ModemInterface::Type MMModemInterface::type() const
 
144
{
 
145
    Q_D(const MMModemInterface);
 
146
    return d->type;
 
147
}
 
148
 
 
149
bool MMModemInterface::enabled() const
 
150
{
 
151
    Q_D(const MMModemInterface);
 
152
    return d->enabled;
 
153
}
 
154
 
 
155
QString MMModemInterface::unlockRequired() const
 
156
{
 
157
    Q_D(const MMModemInterface);
 
158
    return d->unlockRequired;
 
159
}
 
160
 
 
161
Solid::Control::ModemInterface::Method MMModemInterface::ipMethod() const
 
162
{
 
163
    Q_D(const MMModemInterface);
 
164
    return d->ipMethod;
 
165
}
 
166
 
 
167
void MMModemInterface::propertiesChanged(const QString & interface, const QVariantMap & properties)
 
168
{
 
169
    Q_D(MMModemInterface);
 
170
    kDebug(1441) << interface << properties.keys();
 
171
 
 
172
    if (interface == QString("org.freedesktop.ModemManager.Modem")) {
 
173
        QLatin1String device("Device");
 
174
        QLatin1String masterDevice("MasterDevice");
 
175
        QLatin1String driver("Driver");
 
176
        QLatin1String type("Type");
 
177
        QLatin1String enabled("Enabled");
 
178
        QLatin1String unlockRequired("UnlockRequired");
 
179
        QLatin1String ipMethod("IpMethod");
 
180
 
 
181
        QVariantMap::const_iterator it = properties.find(device);
 
182
        if ( it != properties.end()) {
 
183
            d->device = it->toString();
 
184
            emit deviceChanged(d->device);
 
185
        }
 
186
        it = properties.find(masterDevice);
 
187
        if ( it != properties.end()) {
 
188
            d->masterDevice = it->toString();
 
189
            emit masterDeviceChanged(d->masterDevice);
 
190
        }
 
191
        it = properties.find(driver);
 
192
        if ( it != properties.end()) {
 
193
            d->driver = it->toString();
 
194
            emit driverChanged(d->driver);
 
195
        }
 
196
        it = properties.find(type);
 
197
        if ( it != properties.end()) {
 
198
            d->type = (Solid::Control::ModemInterface::Type) it->toInt();
 
199
            emit typeChanged(d->type);
 
200
        }
 
201
        it = properties.find(enabled);
 
202
        if ( it != properties.end()) {
 
203
            d->enabled = it->toBool();
 
204
            emit enabledChanged(d->enabled);
 
205
        }
 
206
        it = properties.find(unlockRequired);
 
207
        if ( it != properties.end()) {
 
208
            d->unlockRequired = it->toString();
 
209
            emit unlockRequiredChanged(d->unlockRequired);
 
210
        }
 
211
        it = properties.find(ipMethod);
 
212
        if ( it != properties.end()) {
 
213
            d->ipMethod = (Solid::Control::ModemInterface::Method) it->toInt();
 
214
            emit ipMethodChanged(d->ipMethod);
 
215
        }
 
216
    }
 
217
}
 
218
 
 
219
 
 
220
/*** From org.freedesktop.ModemManager.Modem.Simple ***/
 
221
 
 
222
void MMModemInterface::connectModem(const QVariantMap & properties)
 
223
{
 
224
    Q_D(MMModemInterface);
 
225
    d->modemSimpleIface.Connect(properties);
 
226
}
 
227
 
 
228
QVariantMap MMModemInterface::getStatus()
 
229
{
 
230
    Q_D(MMModemInterface);
 
231
 
 
232
    QDBusReply<QVariantMap> status = d->modemSimpleIface.GetStatus();
 
233
 
 
234
    if (status.isValid()) {
 
235
        return status.value();
 
236
    }
 
237
 
 
238
    return QVariantMap();
 
239
}
 
240
 
 
241
#include "modeminterface.moc"
 
242