c95f062423b34bb6f805715c5cc190af05dac50b
[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::setSubscriberNumbers(const QStringList &numbers)
117 {
118     m_if->setProperty("SubscriberNumbers", qVariantFromValue(numbers));
119 }
120
121 bool OfonoSimManager::present() const
122 {
123     return m_if->properties()["Present"].value<bool>();
124 }
125
126 QString OfonoSimManager::subscriberIdentity() const
127 {
128     return m_if->properties()["SubscriberIdentity"].value<QString>();
129 }
130
131 QString OfonoSimManager::mobileCountryCode() const
132 {
133     return m_if->properties()["MobileCountryCode"].value<QString>();
134 }
135
136 QString OfonoSimManager::mobileNetworkCode() const
137 {
138     return m_if->properties()["MobileNetworkCode"].value<QString>();
139 }
140
141 QStringList OfonoSimManager::subscriberNumbers() const
142 {
143     return m_if->properties()["SubscriberNumbers"].value<QStringList>();
144 }
145
146 OfonoServiceNumbers OfonoSimManager::serviceNumbers() const
147 {
148     OfonoServiceNumbers map;
149     m_if->properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
150     return map;
151 }
152
153 QString OfonoSimManager::pinRequired() const
154 {
155     return m_if->properties()["PinRequired"].value<QString>();
156 }
157
158 QStringList OfonoSimManager::lockedPins() const
159 {
160     return m_if->properties()["LockedPins"].value<QStringList>();
161 }
162
163 QString OfonoSimManager::cardIdentifier() const
164 {
165     return m_if->properties()["CardIdentifier"].value<QString>();
166 }
167
168 QStringList OfonoSimManager::preferredLanguages() const
169 {
170     return m_if->properties()["PreferredLanguages"].value<QStringList>();
171 }
172
173 OfonoPinRetries OfonoSimManager::pinRetries() const
174 {
175     OfonoPinRetries retries;
176     m_if->properties()["Retries"].value<QDBusArgument>() >> retries;
177     return retries;
178 }
179
180 void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
181 {
182     if (property == "Present") {        
183         emit presenceChanged(value.value<bool>());
184     } else if (property == "SubscriberIdentity") {      
185         emit subscriberIdentityChanged(value.value<QString>());
186     } else if (property == "MobileCountryCode") {       
187         emit mobileCountryCodeChanged(value.value<QString>());
188     } else if (property == "MobileNetworkCode") {       
189         emit mobileNetworkCodeChanged(value.value<QString>());
190     } else if (property == "SubscriberNumbers") {       
191         emit subscriberNumbersChanged(value.value<QStringList>());
192     } else if (property == "ServiceNumbers") {  
193         OfonoServiceNumbers map;
194         value.value<QDBusArgument>() >> map;
195         emit serviceNumbersChanged(map);
196     } else if (property == "PinRequired") {     
197         emit pinRequiredChanged(value.value<QString>());
198     } else if (property == "LockedPins") {
199         emit lockedPinsChanged(value.value<QStringList>());
200     } else if (property == "CardIdentifier") {  
201         emit cardIdentifierChanged(value.value<QString>());
202     } else if (property == "PreferredLanguages") {      
203         emit preferredLanguagesChanged(value.value<QStringList>());
204     } else if (property == "Retries") {
205         OfonoPinRetries retries;
206         value.value<QDBusArgument>() >> retries;
207         emit pinRetriesChanged(retries);
208     }
209 }
210
211 void OfonoSimManager::setPropertyFailed(const QString& property)
212 {
213     if (property == "SubscriberNumbers")
214         emit setSubscriberNumbersFailed();
215 }
216
217 void OfonoSimManager::changePinResp()
218 {
219     emit changePinComplete(TRUE);
220 }
221
222 void OfonoSimManager::changePinErr(QDBusError error)
223 {
224     m_if->setError(error.name(), error.message());    
225     emit changePinComplete(FALSE);
226 }
227
228 void OfonoSimManager::enterPinResp()
229 {
230     emit enterPinComplete(TRUE);
231 }
232
233 void OfonoSimManager::enterPinErr(QDBusError error)
234 {
235     m_if->setError(error.name(), error.message());
236     emit enterPinComplete(FALSE);
237 }
238
239 void OfonoSimManager::resetPinResp()
240 {
241     emit resetPinComplete(TRUE);
242 }
243
244 void OfonoSimManager::resetPinErr(QDBusError error)
245 {
246     m_if->setError(error.name(), error.message());
247     emit resetPinComplete(FALSE);
248 }
249
250 void OfonoSimManager::lockPinResp()
251 {
252     emit lockPinComplete(TRUE);
253 }
254 void OfonoSimManager::lockPinErr(QDBusError error)
255 {
256     m_if->setError(error.name(), error.message());
257     emit lockPinComplete(FALSE);
258 }
259
260 void OfonoSimManager::unlockPinResp()
261 {
262     emit unlockPinComplete(TRUE);
263 }
264 void OfonoSimManager::unlockPinErr(QDBusError error)
265 {
266     m_if->setError(error.name(), error.message()); 
267     emit unlockPinComplete(FALSE);
268 }