remove dep for doxygen
[profile/ivi/ofono-qt.git] / lib / ofonosimmanager.cpp
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
30 OfonoSimManager::OfonoSimManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
31     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SimManager", OfonoGetAllOnStartup, parent)
32 {
33     qRegisterMetaType<OfonoServiceNumbers>("OfonoServiceNumbers");
34     qRegisterMetaType<OfonoPinRetries>("OfonoPinRetries");
35     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
36             this, SLOT(propertyChanged(const QString&, const QVariant&)));
37     connect(m_if, SIGNAL(setPropertyFailed(const QString&)), 
38             this, SLOT(setPropertyFailed(const QString&)));
39
40 }
41
42 OfonoSimManager::~OfonoSimManager()
43 {
44 }
45
46 void OfonoSimManager::changePin(const QString &pintype, const QString &oldpin, const QString &newpin)
47 {
48     QDBusMessage request;
49
50     request = QDBusMessage::createMethodCall("org.ofono",
51                                              path(), m_if->ifname(),
52                                              "ChangePin");
53     request << pintype << oldpin << newpin;
54
55     QDBusConnection::systemBus().callWithCallback(request, this,
56                                         SLOT(changePinResp()),
57                                         SLOT(changePinErr(const QDBusError&)));
58 }
59
60 void OfonoSimManager::enterPin(const QString &pintype, const QString &pin)
61 {
62     QDBusMessage request;
63
64     request = QDBusMessage::createMethodCall("org.ofono",
65                                              path(), m_if->ifname(),
66                                              "EnterPin");
67     request << pintype << pin;
68
69     QDBusConnection::systemBus().callWithCallback(request, this,
70                                         SLOT(enterPinResp()),
71                                         SLOT(enterPinErr(const QDBusError&)));
72 }
73
74 void OfonoSimManager::resetPin(const QString &pintype, const QString &puk, const QString &newpin)
75 {
76     QDBusMessage request;
77
78     request = QDBusMessage::createMethodCall("org.ofono",
79                                              path(), m_if->ifname(),
80                                              "ResetPin");
81     request << pintype << puk << newpin;
82
83     QDBusConnection::systemBus().callWithCallback(request, this,
84                                         SLOT(resetPinResp()),
85                                         SLOT(resetPinErr(const QDBusError&)));
86 }
87
88 void OfonoSimManager::lockPin(const QString &pintype, const QString &pin)
89 {
90     QDBusMessage request;
91
92     request = QDBusMessage::createMethodCall("org.ofono",
93                                              path(), m_if->ifname(),
94                                              "LockPin");
95     request << pintype << pin;
96
97     QDBusConnection::systemBus().callWithCallback(request, this,
98                                         SLOT(lockPinResp()),
99                                         SLOT(lockPinErr(const QDBusError&)));
100 }
101
102 void OfonoSimManager::unlockPin(const QString &pintype, const QString &pin)
103 {
104     QDBusMessage request;
105
106     request = QDBusMessage::createMethodCall("org.ofono",
107                                              path(), m_if->ifname(),
108                                              "UnlockPin");
109     request << pintype << pin;
110
111     QDBusConnection::systemBus().callWithCallback(request, this,
112                                         SLOT(unlockPinResp()),
113                                         SLOT(unlockPinErr(const QDBusError&)));
114 }
115
116 void OfonoSimManager::getIcon(quint8 id)
117 {
118     QDBusMessage request;
119
120     request = QDBusMessage::createMethodCall("org.ofono",
121                                              path(), m_if->ifname(),
122                                              "GetIcon");
123     request << qVariantFromValue(id);
124
125     QDBusConnection::systemBus().callWithCallback(request, this,
126                                         SLOT(getIconResp(QByteArray)),
127                                         SLOT(getIconErr(const QDBusError&)));
128 }
129
130 void OfonoSimManager::setSubscriberNumbers(const QStringList &numbers)
131 {
132     m_if->setProperty("SubscriberNumbers", qVariantFromValue(numbers));
133 }
134
135 bool OfonoSimManager::present() const
136 {
137     return m_if->properties()["Present"].value<bool>();
138 }
139
140 QString OfonoSimManager::subscriberIdentity() const
141 {
142     return m_if->properties()["SubscriberIdentity"].value<QString>();
143 }
144
145 QString OfonoSimManager::mobileCountryCode() const
146 {
147     return m_if->properties()["MobileCountryCode"].value<QString>();
148 }
149
150 QString OfonoSimManager::mobileNetworkCode() const
151 {
152     return m_if->properties()["MobileNetworkCode"].value<QString>();
153 }
154
155 QStringList OfonoSimManager::subscriberNumbers() const
156 {
157     return m_if->properties()["SubscriberNumbers"].value<QStringList>();
158 }
159
160 OfonoServiceNumbers OfonoSimManager::serviceNumbers() const
161 {
162     OfonoServiceNumbers map;
163     m_if->properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
164     return map;
165 }
166
167 QString OfonoSimManager::pinRequired() const
168 {
169     return m_if->properties()["PinRequired"].value<QString>();
170 }
171
172 QStringList OfonoSimManager::lockedPins() const
173 {
174     return m_if->properties()["LockedPins"].value<QStringList>();
175 }
176
177 QString OfonoSimManager::cardIdentifier() const
178 {
179     return m_if->properties()["CardIdentifier"].value<QString>();
180 }
181
182 QStringList OfonoSimManager::preferredLanguages() const
183 {
184     return m_if->properties()["PreferredLanguages"].value<QStringList>();
185 }
186
187 OfonoPinRetries OfonoSimManager::pinRetries() const
188 {
189     OfonoPinRetries retries;
190     m_if->properties()["Retries"].value<QDBusArgument>() >> retries;
191     return retries;
192 }
193
194 bool OfonoSimManager::fixedDialing() const
195 {
196     return m_if->properties()["FixedDialing"].value<bool>();
197 }
198
199 bool OfonoSimManager::barredDialing() const
200 {
201     return m_if->properties()["BarredDialing"].value<bool>();
202 }
203
204 void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
205 {
206     if (property == "Present") {        
207         emit presenceChanged(value.value<bool>());
208     } else if (property == "SubscriberIdentity") {      
209         emit subscriberIdentityChanged(value.value<QString>());
210     } else if (property == "MobileCountryCode") {       
211         emit mobileCountryCodeChanged(value.value<QString>());
212     } else if (property == "MobileNetworkCode") {       
213         emit mobileNetworkCodeChanged(value.value<QString>());
214     } else if (property == "SubscriberNumbers") {       
215         emit subscriberNumbersChanged(value.value<QStringList>());
216     } else if (property == "ServiceNumbers") {  
217         OfonoServiceNumbers map;
218         value.value<QDBusArgument>() >> map;
219         emit serviceNumbersChanged(map);
220     } else if (property == "PinRequired") {     
221         emit pinRequiredChanged(value.value<QString>());
222     } else if (property == "LockedPins") {
223         emit lockedPinsChanged(value.value<QStringList>());
224     } else if (property == "CardIdentifier") {  
225         emit cardIdentifierChanged(value.value<QString>());
226     } else if (property == "PreferredLanguages") {      
227         emit preferredLanguagesChanged(value.value<QStringList>());
228     } else if (property == "Retries") {
229         OfonoPinRetries retries;
230         value.value<QDBusArgument>() >> retries;
231         emit pinRetriesChanged(retries);
232     } else if (property == "FixedDialing") {    
233         emit fixedDialingChanged(value.value<bool>());
234     } else if (property == "BarredDialing") {   
235         emit barredDialingChanged(value.value<bool>());
236     }
237 }
238
239 void OfonoSimManager::setPropertyFailed(const QString& property)
240 {
241     if (property == "SubscriberNumbers")
242         emit setSubscriberNumbersFailed();
243 }
244
245 void OfonoSimManager::changePinResp()
246 {
247     emit changePinComplete(TRUE);
248 }
249
250 void OfonoSimManager::changePinErr(QDBusError error)
251 {
252     m_if->setError(error.name(), error.message());    
253     emit changePinComplete(FALSE);
254 }
255
256 void OfonoSimManager::enterPinResp()
257 {
258     emit enterPinComplete(TRUE);
259 }
260
261 void OfonoSimManager::enterPinErr(QDBusError error)
262 {
263     m_if->setError(error.name(), error.message());
264     emit enterPinComplete(FALSE);
265 }
266
267 void OfonoSimManager::resetPinResp()
268 {
269     emit resetPinComplete(TRUE);
270 }
271
272 void OfonoSimManager::resetPinErr(QDBusError error)
273 {
274     m_if->setError(error.name(), error.message());
275     emit resetPinComplete(FALSE);
276 }
277
278 void OfonoSimManager::lockPinResp()
279 {
280     emit lockPinComplete(TRUE);
281 }
282 void OfonoSimManager::lockPinErr(QDBusError error)
283 {
284     m_if->setError(error.name(), error.message());
285     emit lockPinComplete(FALSE);
286 }
287
288 void OfonoSimManager::unlockPinResp()
289 {
290     emit unlockPinComplete(TRUE);
291 }
292 void OfonoSimManager::unlockPinErr(QDBusError error)
293 {
294     m_if->setError(error.name(), error.message()); 
295     emit unlockPinComplete(FALSE);
296 }
297
298 void OfonoSimManager::getIconResp(QByteArray icon)
299 {
300     emit getIconComplete(TRUE, icon);
301 }
302 void OfonoSimManager::getIconErr(QDBusError error)
303 {
304     m_if->setError(error.name(), error.message()); 
305     emit getIconComplete(FALSE, QByteArray());
306 }