2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.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"
31 OfonoSimManager::OfonoSimManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
32 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SimManager", OfonoGetAllOnStartup, parent)
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&)));
41 OfonoSimManager::~OfonoSimManager()
45 void OfonoSimManager::requestChangePin(const QString &pintype, const QString &oldpin, const QString &newpin)
49 request = QDBusMessage::createMethodCall("org.ofono",
50 path(), m_if->ifname(),
52 request << pintype << oldpin << newpin;
54 QDBusConnection::systemBus().callWithCallback(request, this,
55 SLOT(changePinResp()),
56 SLOT(changePinErr(const QDBusError&)));
59 void OfonoSimManager::requestEnterPin(const QString &pintype, const QString &pin)
63 request = QDBusMessage::createMethodCall("org.ofono",
64 path(), m_if->ifname(),
66 request << pintype << pin;
68 QDBusConnection::systemBus().callWithCallback(request, this,
70 SLOT(enterPinErr(const QDBusError&)));
73 void OfonoSimManager::requestResetPin(const QString &pintype, const QString &puk, const QString &newpin)
77 request = QDBusMessage::createMethodCall("org.ofono",
78 path(), m_if->ifname(),
80 request << pintype << puk << newpin;
82 QDBusConnection::systemBus().callWithCallback(request, this,
84 SLOT(resetPinErr(const QDBusError&)));
87 void OfonoSimManager::requestLockPin(const QString &pintype, const QString &pin)
91 request = QDBusMessage::createMethodCall("org.ofono",
92 path(), m_if->ifname(),
94 request << pintype << pin;
96 QDBusConnection::systemBus().callWithCallback(request, this,
98 SLOT(lockPinErr(const QDBusError&)));
101 void OfonoSimManager::requestUnlockPin(const QString &pintype, const QString &pin)
103 QDBusMessage request;
105 request = QDBusMessage::createMethodCall("org.ofono",
106 path(), m_if->ifname(),
108 request << pintype << pin;
110 QDBusConnection::systemBus().callWithCallback(request, this,
111 SLOT(unlockPinResp()),
112 SLOT(unlockPinErr(const QDBusError&)));
115 void OfonoSimManager::setSubscriberNumbers(const QStringList &numbers)
117 m_if->setProperty("SubscriberNumbers", qVariantFromValue(numbers));
120 bool OfonoSimManager::present() const
122 return m_if->properties()["Present"].value<bool>();
125 QString OfonoSimManager::subscriberIdentity() const
127 return m_if->properties()["SubscriberIdentity"].value<QString>();
130 QString OfonoSimManager::mobileCountryCode() const
132 return m_if->properties()["MobileCountryCode"].value<QString>();
135 QString OfonoSimManager::mobileNetworkCode() const
137 return m_if->properties()["MobileNetworkCode"].value<QString>();
140 QStringList OfonoSimManager::subscriberNumbers() const
142 return m_if->properties()["SubscriberNumbers"].value<QStringList>();
145 QMap<QString, QString> OfonoSimManager::serviceNumbers() const
147 QMap<QString, QString> map;
148 m_if->properties()["ServiceNumbers"].value<QDBusArgument>() >> map;
152 QString OfonoSimManager::pinRequired() const
154 return m_if->properties()["PinRequired"].value<QString>();
157 QStringList OfonoSimManager::lockedPins() const
159 return m_if->properties()["LockedPins"].value<QStringList>();
162 QString OfonoSimManager::cardIdentifier() const
164 return m_if->properties()["CardIdentifier"].value<QString>();
167 QStringList OfonoSimManager::preferredLanguages() const
169 return m_if->properties()["PreferredLanguages"].value<QStringList>();
173 void OfonoSimManager::propertyChanged(const QString& property, const QVariant& value)
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 QMap<QString, QString> 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>());
200 void OfonoSimManager::setPropertyFailed(const QString& property)
202 if (property == "SubscriberNumbers")
203 emit setSubscriberNumbersFailed();
206 void OfonoSimManager::changePinResp()
208 emit changePinComplete(TRUE);
211 void OfonoSimManager::changePinErr(QDBusError error)
213 qDebug() << "ChangePin failed" << error;
214 m_if->setError(error.name(), error.message());
215 emit changePinComplete(FALSE);
218 void OfonoSimManager::enterPinResp()
220 emit enterPinComplete(TRUE);
223 void OfonoSimManager::enterPinErr(QDBusError error)
225 qDebug() << "EnterPin failed" << error;
226 m_if->setError(error.name(), error.message());
227 emit enterPinComplete(FALSE);
230 void OfonoSimManager::resetPinResp()
232 emit resetPinComplete(TRUE);
235 void OfonoSimManager::resetPinErr(QDBusError error)
237 qDebug() << "ResetPin failed" << error;
238 m_if->setError(error.name(), error.message());
239 emit resetPinComplete(FALSE);
242 void OfonoSimManager::lockPinResp()
244 emit lockPinComplete(TRUE);
246 void OfonoSimManager::lockPinErr(QDBusError error)
248 qDebug() << "LockPin failed" << error;
249 m_if->setError(error.name(), error.message());
250 emit lockPinComplete(FALSE);
253 void OfonoSimManager::unlockPinResp()
255 emit unlockPinComplete(TRUE);
257 void OfonoSimManager::unlockPinErr(QDBusError error)
259 qDebug() << "UnlockPin failed" << error;
260 m_if->setError(error.name(), error.message());
261 emit unlockPinComplete(FALSE);