~boiko/telepathy-ofono/update_tp_qt

« back to all changes in this revision

Viewing changes to tests/mock/ofonosimmanager.cpp

  • Committer: CI bot
  • Author(s): Tiago Salem Herrmann
  • Date: 2014-08-22 13:28:14 UTC
  • mfrom: (95.2.6 telepathy-ofono)
  • Revision ID: ps-jenkins@lists.canonical.com-20140822132814-pmb78w7vncowuyjx
- Report "away" status if there is no network and "offline" if the sim card is not present.
- Remove legacy code
- Expose operator name to apps via presence message. 
Approved by: Gustavo Pichorim Boiko

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of ofono-qt
 
3
 *
 
4
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License
 
10
 * version 2.1 as published by the Free Software Foundation.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
#include <QtDBus/QtDBus>
 
25
#include <QtCore/QObject>
 
26
 
 
27
#include "ofonosimmanager.h"
 
28
#include "ofonointerface.h"
 
29
#include "simmanagerprivate.h"
 
30
 
 
31
OfonoSimManager::OfonoSimManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
 
32
    : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SimManager", OfonoGetAllOnStartup, parent)
 
33
{
 
34
    qRegisterMetaType<OfonoServiceNumbers>("OfonoServiceNumbers");
 
35
    qRegisterMetaType<OfonoPinRetries>("OfonoPinRetries");
 
36
 
 
37
    m_if->setPath(OFONO_MOCK_SIM_MANAGER_OBJECT);
 
38
    if (!simManagerData.keys().contains(modem()->path())) {
 
39
        simManagerData[modem()->path()] = new SimManagerPrivate();
 
40
    }
 
41
 
 
42
    connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
 
43
            this, SLOT(propertyChanged(const QString&, const QVariant&)));
 
44
    connect(m_if, SIGNAL(setPropertyFailed(const QString&)), 
 
45
            this, SLOT(setPropertyFailed(const QString&)));
 
46
 
 
47
}
 
48
 
 
49
OfonoSimManager::~OfonoSimManager()
 
50
{
 
51
}
 
52
 
 
53
void OfonoSimManager::changePin(const QString &pintype, const QString &oldpin, const QString &newpin)
 
54
{
 
55
    QDBusMessage request;
 
56
 
 
57
    request = QDBusMessage::createMethodCall("org.ofono",
 
58
                                             path(), m_if->ifname(),
 
59
                                             "ChangePin");
 
60
    request << pintype << oldpin << newpin;
 
61
 
 
62
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
63
                                        SLOT(changePinResp()),
 
64
                                        SLOT(changePinErr(const QDBusError&)));
 
65
}
 
66
 
 
67
void OfonoSimManager::enterPin(const QString &pintype, const QString &pin)
 
68
{
 
69
    QDBusMessage request;
 
70
 
 
71
    request = QDBusMessage::createMethodCall("org.ofono",
 
72
                                             path(), m_if->ifname(),
 
73
                                             "EnterPin");
 
74
    request << pintype << pin;
 
75
 
 
76
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
77
                                        SLOT(enterPinResp()),
 
78
                                        SLOT(enterPinErr(const QDBusError&)));
 
79
}
 
80
 
 
81
void OfonoSimManager::resetPin(const QString &pintype, const QString &puk, const QString &newpin)
 
82
{
 
83
    QDBusMessage request;
 
84
 
 
85
    request = QDBusMessage::createMethodCall("org.ofono",
 
86
                                             path(), m_if->ifname(),
 
87
                                             "ResetPin");
 
88
    request << pintype << puk << newpin;
 
89
 
 
90
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
91
                                        SLOT(resetPinResp()),
 
92
                                        SLOT(resetPinErr(const QDBusError&)));
 
93
}
 
94
 
 
95
void OfonoSimManager::lockPin(const QString &pintype, const QString &pin)
 
96
{
 
97
    QDBusMessage request;
 
98
 
 
99
    request = QDBusMessage::createMethodCall("org.ofono",
 
100
                                             path(), m_if->ifname(),
 
101
                                             "LockPin");
 
102
    request << pintype << pin;
 
103
 
 
104
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
105
                                        SLOT(lockPinResp()),
 
106
                                        SLOT(lockPinErr(const QDBusError&)));
 
107
}
 
108
 
 
109
void OfonoSimManager::unlockPin(const QString &pintype, const QString &pin)
 
110
{
 
111
    QDBusMessage request;
 
112
 
 
113
    request = QDBusMessage::createMethodCall("org.ofono",
 
114
                                             path(), m_if->ifname(),
 
115
                                             "UnlockPin");
 
116
    request << pintype << pin;
 
117
 
 
118
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
119
                                        SLOT(unlockPinResp()),
 
120
                                        SLOT(unlockPinErr(const QDBusError&)));
 
121
}
 
122
 
 
123
void OfonoSimManager::getIcon(quint8 id)
 
124
{
 
125
    QDBusMessage request;
 
126
 
 
127
    request = QDBusMessage::createMethodCall("org.ofono",
 
128
                                             path(), m_if->ifname(),
 
129
                                             "GetIcon");
 
130
    request << qVariantFromValue(id);
 
131
 
 
132
    QDBusConnection::sessionBus().callWithCallback(request, this,
 
133
                                        SLOT(getIconResp(QByteArray)),
 
134
                                        SLOT(getIconErr(const QDBusError&)));
 
135
}
 
136
 
 
137
void OfonoSimManager::setSubscriberNumbers(const QStringList &numbers)
 
138
{
 
139
    m_if->setProperty("SubscriberNumbers", qVariantFromValue(numbers));
 
140
}
 
141
 
 
142
bool OfonoSimManager::present() const
 
143
{
 
144
    return m_if->properties()["Present"].value<bool>();
 
145
}
 
146
 
 
147
QString OfonoSimManager::subscriberIdentity() const
 
148
{
 
149
    return m_if->properties()["SubscriberIdentity"].value<QString>();
 
150
}
 
151
 
 
152
QString OfonoSimManager::mobileCountryCode() const
 
153
{
 
154
    return m_if->properties()["MobileCountryCode"].value<QString>();
 
155
}
 
156
 
 
157
QString OfonoSimManager::mobileNetworkCode() const
 
158
{
 
159
    return m_if->properties()["MobileNetworkCode"].value<QString>();
 
160
}
 
161
 
 
162
QStringList OfonoSimManager::subscriberNumbers() const
 
163
{
 
164
    return m_if->properties()["SubscriberNumbers"].value<QStringList>();
 
165
}
 
166
 
 
167
OfonoServiceNumbers OfonoSimManager::serviceNumbers() const
 
168
{
 
169
    OfonoServiceNumbers map;
 
170
    m_if->properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
 
171
    return map;
 
172
}
 
173
 
 
174
QString OfonoSimManager::pinRequired() const
 
175
{
 
176
    return m_if->properties()["PinRequired"].value<QString>();
 
177
}
 
178
 
 
179
QStringList OfonoSimManager::lockedPins() const
 
180
{
 
181
    return m_if->properties()["LockedPins"].value<QStringList>();
 
182
}
 
183
 
 
184
QString OfonoSimManager::cardIdentifier() const
 
185
{
 
186
    return m_if->properties()["CardIdentifier"].value<QString>();
 
187
}
 
188
 
 
189
QStringList OfonoSimManager::preferredLanguages() const
 
190
{
 
191
    return m_if->properties()["PreferredLanguages"].value<QStringList>();
 
192
}
 
193
 
 
194
OfonoPinRetries OfonoSimManager::pinRetries() const
 
195
{
 
196
    OfonoPinRetries retries;
 
197
    m_if->properties()["Retries"].value<QDBusArgument>() >> retries;
 
198
    return retries;
 
199
}
 
200
 
 
201
bool OfonoSimManager::fixedDialing() const
 
202
{
 
203
    return m_if->properties()["FixedDialing"].value<bool>();
 
204
}
 
205
 
 
206
bool OfonoSimManager::barredDialing() const
 
207
{
 
208
    return m_if->properties()["BarredDialing"].value<bool>();
 
209
}
 
210
 
 
211
void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
 
212
{
 
213
    if (property == "Present") {        
 
214
        Q_EMIT presenceChanged(value.value<bool>());
 
215
    } else if (property == "SubscriberIdentity") {      
 
216
        Q_EMIT subscriberIdentityChanged(value.value<QString>());
 
217
    } else if (property == "MobileCountryCode") {       
 
218
        Q_EMIT mobileCountryCodeChanged(value.value<QString>());
 
219
    } else if (property == "MobileNetworkCode") {       
 
220
        Q_EMIT mobileNetworkCodeChanged(value.value<QString>());
 
221
    } else if (property == "SubscriberNumbers") {       
 
222
        Q_EMIT subscriberNumbersChanged(value.value<QStringList>());
 
223
    } else if (property == "ServiceNumbers") {  
 
224
        OfonoServiceNumbers map;
 
225
        value.value<QDBusArgument>() >> map;
 
226
        Q_EMIT serviceNumbersChanged(map);
 
227
    } else if (property == "PinRequired") {     
 
228
        Q_EMIT pinRequiredChanged(value.value<QString>());
 
229
    } else if (property == "LockedPins") {
 
230
        Q_EMIT lockedPinsChanged(value.value<QStringList>());
 
231
    } else if (property == "CardIdentifier") {  
 
232
        Q_EMIT cardIdentifierChanged(value.value<QString>());
 
233
    } else if (property == "PreferredLanguages") {      
 
234
        Q_EMIT preferredLanguagesChanged(value.value<QStringList>());
 
235
    } else if (property == "Retries") {
 
236
        OfonoPinRetries retries;
 
237
        value.value<QDBusArgument>() >> retries;
 
238
        Q_EMIT pinRetriesChanged(retries);
 
239
    } else if (property == "FixedDialing") {    
 
240
        Q_EMIT fixedDialingChanged(value.value<bool>());
 
241
    } else if (property == "BarredDialing") {   
 
242
        Q_EMIT barredDialingChanged(value.value<bool>());
 
243
    }
 
244
}
 
245
 
 
246
void OfonoSimManager::setPropertyFailed(const QString& property)
 
247
{
 
248
    if (property == "SubscriberNumbers")
 
249
        Q_EMIT setSubscriberNumbersFailed();
 
250
}
 
251
 
 
252
void OfonoSimManager::changePinResp()
 
253
{
 
254
    Q_EMIT changePinComplete(true);
 
255
}
 
256
 
 
257
void OfonoSimManager::changePinErr(QDBusError error)
 
258
{
 
259
    m_if->setError(error.name(), error.message());    
 
260
    Q_EMIT changePinComplete(false);
 
261
}
 
262
 
 
263
void OfonoSimManager::enterPinResp()
 
264
{
 
265
    Q_EMIT enterPinComplete(true);
 
266
}
 
267
 
 
268
void OfonoSimManager::enterPinErr(QDBusError error)
 
269
{
 
270
    m_if->setError(error.name(), error.message());
 
271
    Q_EMIT enterPinComplete(false);
 
272
}
 
273
 
 
274
void OfonoSimManager::resetPinResp()
 
275
{
 
276
    Q_EMIT resetPinComplete(true);
 
277
}
 
278
 
 
279
void OfonoSimManager::resetPinErr(QDBusError error)
 
280
{
 
281
    m_if->setError(error.name(), error.message());
 
282
    Q_EMIT resetPinComplete(false);
 
283
}
 
284
 
 
285
void OfonoSimManager::lockPinResp()
 
286
{
 
287
    Q_EMIT lockPinComplete(true);
 
288
}
 
289
void OfonoSimManager::lockPinErr(QDBusError error)
 
290
{
 
291
    m_if->setError(error.name(), error.message());
 
292
    Q_EMIT lockPinComplete(false);
 
293
}
 
294
 
 
295
void OfonoSimManager::unlockPinResp()
 
296
{
 
297
    Q_EMIT unlockPinComplete(true);
 
298
}
 
299
void OfonoSimManager::unlockPinErr(QDBusError error)
 
300
{
 
301
    m_if->setError(error.name(), error.message()); 
 
302
    Q_EMIT unlockPinComplete(false);
 
303
}
 
304
 
 
305
void OfonoSimManager::getIconResp(QByteArray icon)
 
306
{
 
307
    Q_EMIT getIconComplete(true, icon);
 
308
}
 
309
void OfonoSimManager::getIconErr(QDBusError error)
 
310
{
 
311
    m_if->setError(error.name(), error.message()); 
 
312
    Q_EMIT getIconComplete(false, QByteArray());
 
313
}