Add documentation, code cleanups
[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 <alexander.kanavin@nokia.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
29
30 OfonoSimManager::OfonoSimManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
31     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SimManager", OfonoInterface::GetAllOnStartup, parent)
32 {
33     connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
34             this, SLOT(propertyChanged(const QString&, const QVariant&)));
35     connect(this, SIGNAL(setPropertyFailed(const QString&)), 
36             this, SLOT(setPropertyFailed(const QString&)));
37
38 }
39
40 OfonoSimManager::~OfonoSimManager()
41 {
42 }
43
44 void OfonoSimManager::requestChangePin(const QString &pintype, const QString &oldpin, const QString &newpin)
45 {
46     QDBusMessage request;
47
48     request = QDBusMessage::createMethodCall("org.ofono",
49                                              path(), ifname(),
50                                              "ChangePin");
51     request << pintype << oldpin << newpin;
52
53     QDBusConnection::systemBus().callWithCallback(request, this,
54                                         SLOT(changePinResp()),
55                                         SLOT(changePinErr(const QDBusError&)));
56 }
57
58 void OfonoSimManager::requestEnterPin(const QString &pintype, const QString &pin)
59 {
60     QDBusMessage request;
61
62     request = QDBusMessage::createMethodCall("org.ofono",
63                                              path(), ifname(),
64                                              "EnterPin");
65     request << pintype << pin;
66
67     QDBusConnection::systemBus().callWithCallback(request, this,
68                                         SLOT(enterPinResp()),
69                                         SLOT(enterPinErr(const QDBusError&)));
70 }
71
72 void OfonoSimManager::requestResetPin(const QString &pintype, const QString &puk, const QString &newpin)
73 {
74     QDBusMessage request;
75
76     request = QDBusMessage::createMethodCall("org.ofono",
77                                              path(), ifname(),
78                                              "ResetPin");
79     request << pintype << puk << newpin;
80
81     QDBusConnection::systemBus().callWithCallback(request, this,
82                                         SLOT(resetPinResp()),
83                                         SLOT(resetPinErr(const QDBusError&)));
84 }
85
86 void OfonoSimManager::requestLockPin(const QString &pintype, const QString &pin)
87 {
88     QDBusMessage request;
89
90     request = QDBusMessage::createMethodCall("org.ofono",
91                                              path(), ifname(),
92                                              "LockPin");
93     request << pintype << pin;
94
95     QDBusConnection::systemBus().callWithCallback(request, this,
96                                         SLOT(lockPinResp()),
97                                         SLOT(lockPinErr(const QDBusError&)));
98 }
99
100 void OfonoSimManager::requestUnlockPin(const QString &pintype, const QString &pin)
101 {
102     QDBusMessage request;
103
104     request = QDBusMessage::createMethodCall("org.ofono",
105                                              path(), ifname(),
106                                              "UnlockPin");
107     request << pintype << pin;
108
109     QDBusConnection::systemBus().callWithCallback(request, this,
110                                         SLOT(unlockPinResp()),
111                                         SLOT(unlockPinErr(const QDBusError&)));
112 }
113
114 void OfonoSimManager::setSubscriberNumbers(const QStringList &numbers)
115 {
116     setProperty("SubscriberNumbers", qVariantFromValue(numbers));
117 }
118
119 bool OfonoSimManager::present() const
120 {
121     return properties()["Present"].value<bool>();
122 }
123
124 QString OfonoSimManager::subscriberIdentity() const
125 {
126     return properties()["SubscriberIdentity"].value<QString>();
127 }
128
129 QString OfonoSimManager::mobileCountryCode() const
130 {
131     return properties()["MobileCountryCode"].value<QString>();
132 }
133
134 QString OfonoSimManager::mobileNetworkCode() const
135 {
136     return properties()["MobileNetworkCode"].value<QString>();
137 }
138
139 QStringList OfonoSimManager::subscriberNumbers() const
140 {
141     return properties()["SubscriberNumbers"].value<QStringList>();
142 }
143
144 QMap<QString, QString> OfonoSimManager::serviceNumbers() const
145 {
146     QMap<QString, QString> map;
147     properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
148     return map;
149 }
150
151 QString OfonoSimManager::pinRequired() const
152 {
153     return properties()["PinRequired"].value<QString>();
154 }
155
156 QStringList OfonoSimManager::lockedPins() const
157 {
158     return properties()["LockedPins"].value<QStringList>();
159 }
160
161 QString OfonoSimManager::cardIdentifier() const
162 {
163     return properties()["CardIdentifier"].value<QString>();
164 }
165
166 QStringList OfonoSimManager::preferredLanguages() const
167 {
168     return properties()["PreferredLanguages"].value<QStringList>();
169 }
170
171
172 void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
173 {
174     if (property == "Present") {        
175         emit presenceChanged(value.value<bool>());
176     } else if (property == "SubscriberIdentity") {      
177         emit subscriberIdentityChanged(value.value<QString>());
178     } else if (property == "MobileCountryCode") {       
179         emit mobileCountryCodeChanged(value.value<QString>());
180     } else if (property == "MobileNetworkCode") {       
181         emit mobileNetworkCodeChanged(value.value<QString>());
182     } else if (property == "SubscriberNumbers") {       
183         emit subscriberNumbersChanged(value.value<QStringList>());
184     } else if (property == "ServiceNumbers") {  
185         QMap<QString, QString> map;
186         value.value<QDBusArgument>() >> map;
187         emit serviceNumbersChanged(map);
188     } else if (property == "PinRequired") {     
189         emit pinRequiredChanged(value.value<QString>());
190     } else if (property == "LockedPins") {      
191         emit lockedPinsChanged(value.value<QStringList>());
192     } else if (property == "CardIdentifier") {  
193         emit cardIdentifierChanged(value.value<QString>());
194     } else if (property == "PreferredLanguages") {      
195         emit preferredLanguagesChanged(value.value<QStringList>());
196     }
197 }
198
199 void OfonoSimManager::setPropertyFailed(const QString& property)
200 {
201     if (property == "SubscriberNumbers")
202         emit setSubscriberNumbersFailed();
203 }
204
205 void OfonoSimManager::changePinResp()
206 {
207     emit changePinComplete(TRUE);
208 }
209
210 void OfonoSimManager::changePinErr(QDBusError error)
211 {
212     qDebug() << "ChangePin failed" << error;
213     m_errorName = error.name();
214     m_errorMessage = error.message();
215     emit changePinComplete(FALSE);
216 }
217
218 void OfonoSimManager::enterPinResp()
219 {
220     emit enterPinComplete(TRUE);
221 }
222
223 void OfonoSimManager::enterPinErr(QDBusError error)
224 {
225     qDebug() << "EnterPin failed" << error;
226     m_errorName = error.name();
227     m_errorMessage = error.message();
228     emit enterPinComplete(FALSE);
229 }
230
231 void OfonoSimManager::resetPinResp()
232 {
233     emit resetPinComplete(TRUE);
234 }
235
236 void OfonoSimManager::resetPinErr(QDBusError error)
237 {
238     qDebug() << "ResetPin failed" << error;
239     m_errorName = error.name();
240     m_errorMessage = error.message();
241     emit resetPinComplete(FALSE);
242 }
243
244 void OfonoSimManager::lockPinResp()
245 {
246     emit lockPinComplete(TRUE);
247 }
248 void OfonoSimManager::lockPinErr(QDBusError error)
249 {
250     qDebug() << "LockPin failed" << error;
251     m_errorName = error.name();
252     m_errorMessage = error.message();
253     emit lockPinComplete(FALSE);
254 }
255
256 void OfonoSimManager::unlockPinResp()
257 {
258     emit unlockPinComplete(TRUE);
259 }
260 void OfonoSimManager::unlockPinErr(QDBusError error)
261 {
262     qDebug() << "UnlockPin failed" << error;
263     m_errorName = error.name();
264     m_errorMessage = error.message();
265     emit unlockPinComplete(FALSE);
266 }