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