2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
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.
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.
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
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
27 #include "ofonosimmanager.h"
28 #include "ofonointerface.h"
30 OfonoSimManager::OfonoSimManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
31 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SimManager", OfonoGetAllOnStartup, parent)
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&)));
42 OfonoSimManager::~OfonoSimManager()
46 void OfonoSimManager::changePin(const QString &pintype, const QString &oldpin, const QString &newpin)
50 request = QDBusMessage::createMethodCall("org.ofono",
51 path(), m_if->ifname(),
53 request << pintype << oldpin << newpin;
55 QDBusConnection::systemBus().callWithCallback(request, this,
56 SLOT(changePinResp()),
57 SLOT(changePinErr(const QDBusError&)));
60 void OfonoSimManager::enterPin(const QString &pintype, const QString &pin)
64 request = QDBusMessage::createMethodCall("org.ofono",
65 path(), m_if->ifname(),
67 request << pintype << pin;
69 QDBusConnection::systemBus().callWithCallback(request, this,
71 SLOT(enterPinErr(const QDBusError&)));
74 void OfonoSimManager::resetPin(const QString &pintype, const QString &puk, const QString &newpin)
78 request = QDBusMessage::createMethodCall("org.ofono",
79 path(), m_if->ifname(),
81 request << pintype << puk << newpin;
83 QDBusConnection::systemBus().callWithCallback(request, this,
85 SLOT(resetPinErr(const QDBusError&)));
88 void OfonoSimManager::lockPin(const QString &pintype, const QString &pin)
92 request = QDBusMessage::createMethodCall("org.ofono",
93 path(), m_if->ifname(),
95 request << pintype << pin;
97 QDBusConnection::systemBus().callWithCallback(request, this,
99 SLOT(lockPinErr(const QDBusError&)));
102 void OfonoSimManager::unlockPin(const QString &pintype, const QString &pin)
104 QDBusMessage request;
106 request = QDBusMessage::createMethodCall("org.ofono",
107 path(), m_if->ifname(),
109 request << pintype << pin;
111 QDBusConnection::systemBus().callWithCallback(request, this,
112 SLOT(unlockPinResp()),
113 SLOT(unlockPinErr(const QDBusError&)));
116 void OfonoSimManager::getIcon(quint8 id)
118 QDBusMessage request;
120 request = QDBusMessage::createMethodCall("org.ofono",
121 path(), m_if->ifname(),
123 request << qVariantFromValue(id);
125 QDBusConnection::systemBus().callWithCallback(request, this,
126 SLOT(getIconResp(QByteArray)),
127 SLOT(getIconErr(const QDBusError&)));
130 void OfonoSimManager::setSubscriberNumbers(const QStringList &numbers)
132 m_if->setProperty("SubscriberNumbers", qVariantFromValue(numbers));
135 bool OfonoSimManager::present() const
137 return m_if->properties()["Present"].value<bool>();
140 QString OfonoSimManager::subscriberIdentity() const
142 return m_if->properties()["SubscriberIdentity"].value<QString>();
145 QString OfonoSimManager::mobileCountryCode() const
147 return m_if->properties()["MobileCountryCode"].value<QString>();
150 QString OfonoSimManager::mobileNetworkCode() const
152 return m_if->properties()["MobileNetworkCode"].value<QString>();
155 QStringList OfonoSimManager::subscriberNumbers() const
157 return m_if->properties()["SubscriberNumbers"].value<QStringList>();
160 OfonoServiceNumbers OfonoSimManager::serviceNumbers() const
162 OfonoServiceNumbers map;
163 m_if->properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
167 QString OfonoSimManager::pinRequired() const
169 return m_if->properties()["PinRequired"].value<QString>();
172 QStringList OfonoSimManager::lockedPins() const
174 return m_if->properties()["LockedPins"].value<QStringList>();
177 QString OfonoSimManager::cardIdentifier() const
179 return m_if->properties()["CardIdentifier"].value<QString>();
182 QStringList OfonoSimManager::preferredLanguages() const
184 return m_if->properties()["PreferredLanguages"].value<QStringList>();
187 OfonoPinRetries OfonoSimManager::pinRetries() const
189 OfonoPinRetries retries;
190 m_if->properties()["Retries"].value<QDBusArgument>() >> retries;
194 bool OfonoSimManager::fixedDialing() const
196 return m_if->properties()["FixedDialing"].value<bool>();
199 bool OfonoSimManager::barredDialing() const
201 return m_if->properties()["BarredDialing"].value<bool>();
204 void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
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>());
239 void OfonoSimManager::setPropertyFailed(const QString& property)
241 if (property == "SubscriberNumbers")
242 emit setSubscriberNumbersFailed();
245 void OfonoSimManager::changePinResp()
247 emit changePinComplete(TRUE);
250 void OfonoSimManager::changePinErr(QDBusError error)
252 m_if->setError(error.name(), error.message());
253 emit changePinComplete(FALSE);
256 void OfonoSimManager::enterPinResp()
258 emit enterPinComplete(TRUE);
261 void OfonoSimManager::enterPinErr(QDBusError error)
263 m_if->setError(error.name(), error.message());
264 emit enterPinComplete(FALSE);
267 void OfonoSimManager::resetPinResp()
269 emit resetPinComplete(TRUE);
272 void OfonoSimManager::resetPinErr(QDBusError error)
274 m_if->setError(error.name(), error.message());
275 emit resetPinComplete(FALSE);
278 void OfonoSimManager::lockPinResp()
280 emit lockPinComplete(TRUE);
282 void OfonoSimManager::lockPinErr(QDBusError error)
284 m_if->setError(error.name(), error.message());
285 emit lockPinComplete(FALSE);
288 void OfonoSimManager::unlockPinResp()
290 emit unlockPinComplete(TRUE);
292 void OfonoSimManager::unlockPinErr(QDBusError error)
294 m_if->setError(error.name(), error.message());
295 emit unlockPinComplete(FALSE);
298 void OfonoSimManager::getIconResp(QByteArray icon)
300 emit getIconComplete(TRUE, icon);
302 void OfonoSimManager::getIconErr(QDBusError error)
304 m_if->setError(error.name(), error.message());
305 emit getIconComplete(FALSE, QByteArray());