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 "ofononetworkregistration.h"
29 #define REGISTER_TIMEOUT 300000
30 #define SCAN_TIMEOUT 300000
32 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoOperatorStruct &op)
34 argument.beginStructure();
35 argument << op.path << op.properties;
36 argument.endStructure();
40 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoOperatorStruct &op)
42 argument.beginStructure();
43 argument >> op.path >> op.properties;
44 argument.endStructure();
49 OfonoNetworkRegistration::OfonoNetworkRegistration(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
50 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.NetworkRegistration", OfonoInterface::GetAllOnStartup, parent)
52 qDBusRegisterMetaType<OfonoOperatorStruct>();
53 qDBusRegisterMetaType<OfonoOperatorList>();
55 connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)),
56 this, SLOT(propertyChanged(const QString&, const QVariant&)));
59 OfonoNetworkRegistration::~OfonoNetworkRegistration()
63 void OfonoNetworkRegistration::requestRegister()
67 request = QDBusMessage::createMethodCall("org.ofono",
71 QDBusConnection::systemBus().callWithCallback(request, this,
73 SLOT(registerErr(const QDBusError&)),
77 void OfonoNetworkRegistration::requestDeregister()
81 request = QDBusMessage::createMethodCall("org.ofono",
85 QDBusConnection::systemBus().callWithCallback(request, this,
86 SLOT(deregisterResp()),
87 SLOT(deregisterErr(const QDBusError&)),
91 void OfonoNetworkRegistration::requestScan()
95 request = QDBusMessage::createMethodCall("org.ofono",
99 QDBusConnection::systemBus().callWithCallback(request, this,
100 SLOT(scanResp(OfonoOperatorList)),
101 SLOT(scanErr(const QDBusError&)),
105 void OfonoNetworkRegistration::requestGetOperators()
107 QDBusMessage request;
109 request = QDBusMessage::createMethodCall("org.ofono",
113 QDBusConnection::systemBus().callWithCallback(request, this,
114 SLOT(getOperatorsResp(OfonoOperatorList)),
115 SLOT(getOperatorsErr(const QDBusError&)),
119 QString OfonoNetworkRegistration::mode() const
121 return properties()["Mode"].value<QString>();
124 QString OfonoNetworkRegistration::status() const
126 return properties()["Status"].value<QString>();
129 uint OfonoNetworkRegistration::locationAreaCode() const
131 return properties()["LocationAreaCode"].value<uint>();
134 uint OfonoNetworkRegistration::cellId() const
136 return properties()["CellId"].value<uint>();
139 QString OfonoNetworkRegistration::mcc() const
141 return properties()["MobileCountryCode"].value<QString>();
144 QString OfonoNetworkRegistration::mnc() const
146 return properties()["MobileNetworkCode"].value<QString>();
149 QString OfonoNetworkRegistration::technology() const
151 return properties()["Technology"].value<QString>();
154 QString OfonoNetworkRegistration::name() const
156 return properties()["Name"].value<QString>();
159 uint OfonoNetworkRegistration::strength() const
161 return properties()["Strength"].value<uint>();
164 QString OfonoNetworkRegistration::baseStation() const
166 return properties()["BaseStation"].value<QString>();
169 void OfonoNetworkRegistration::propertyChanged(const QString& property, const QVariant& value)
171 if (property == "Mode") {
172 emit modeChanged(value.value<QString>());
173 } else if (property == "Status") {
174 emit statusChanged(value.value<QString>());
175 } else if (property == "LocationAreaCode") {
176 emit locationAreaCodeChanged(value.value<uint>());
177 } else if (property == "CellId") {
178 emit cellIdChanged(value.value<uint>());
179 } else if (property == "MobileCountryCode") {
180 emit mccChanged(value.value<QString>());
181 } else if (property == "MobileNetworkCode") {
182 emit mncChanged(value.value<QString>());
183 } else if (property == "Technology") {
184 emit technologyChanged(value.value<QString>());
185 } else if (property == "Name") {
186 emit nameChanged(value.value<QString>());
187 } else if (property == "Strength") {
188 emit strengthChanged(value.value<uint>());
189 } else if (property == "BaseStation") {
190 emit baseStationChanged(value.value<QString>());
194 void OfonoNetworkRegistration::registerResp()
196 emit registerComplete(TRUE);
199 void OfonoNetworkRegistration::registerErr(QDBusError error)
201 qDebug() << "Register failed" << error;
202 m_errorName = error.name();
203 m_errorMessage = error.message();
204 emit registerComplete(FALSE);
207 void OfonoNetworkRegistration::deregisterResp()
209 emit deregisterComplete(TRUE);
212 void OfonoNetworkRegistration::deregisterErr(QDBusError error)
214 qDebug() << "Deregister failed" << error;
215 m_errorName = error.name();
216 m_errorMessage = error.message();
217 emit deregisterComplete(FALSE);
220 void OfonoNetworkRegistration::getOperatorsResp(OfonoOperatorList list)
223 foreach(OfonoOperatorStruct op, list) {
224 oplist << op.path.path();
226 emit getOperatorsComplete(TRUE, oplist);
229 void OfonoNetworkRegistration::getOperatorsErr(QDBusError error)
231 qDebug() << "GetOperators failed" << error;
232 m_errorName = error.name();
233 m_errorMessage = error.message();
234 emit getOperatorsComplete(FALSE, QStringList());
237 void OfonoNetworkRegistration::scanResp(OfonoOperatorList list)
240 foreach(OfonoOperatorStruct op, list) {
241 oplist << op.path.path();
243 emit scanComplete(TRUE, oplist);
246 void OfonoNetworkRegistration::scanErr(QDBusError error)
248 qDebug() << "Scan failed" << error;
249 m_errorName = error.name();
250 m_errorMessage = error.message();
251 emit scanComplete(FALSE, QStringList());