2 * This file is part of ofono-qt
4 * Copyright (C) 2010-2011 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"
28 #include "ofonointerface.h"
30 #define REGISTER_TIMEOUT 300000
31 #define SCAN_TIMEOUT 300000
33 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoOperatorStruct &op)
35 argument.beginStructure();
36 argument << op.path << op.properties;
37 argument.endStructure();
41 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoOperatorStruct &op)
43 argument.beginStructure();
44 argument >> op.path >> op.properties;
45 argument.endStructure();
50 OfonoNetworkRegistration::OfonoNetworkRegistration(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
51 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.NetworkRegistration", OfonoGetAllOnStartup, parent)
53 qDBusRegisterMetaType<OfonoOperatorStruct>();
54 qDBusRegisterMetaType<OfonoOperatorList>();
56 connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
57 this, SLOT(propertyChanged(const QString&, const QVariant&)));
60 OfonoNetworkRegistration::~OfonoNetworkRegistration()
64 void OfonoNetworkRegistration::registerOp()
68 request = QDBusMessage::createMethodCall("org.ofono",
69 path(), m_if->ifname(),
72 QDBusConnection::systemBus().callWithCallback(request, this,
74 SLOT(registerErr(const QDBusError&)),
78 void OfonoNetworkRegistration::scan()
82 request = QDBusMessage::createMethodCall("org.ofono",
83 path(), m_if->ifname(),
86 QDBusConnection::systemBus().callWithCallback(request, this,
87 SLOT(scanResp(OfonoOperatorList)),
88 SLOT(scanErr(const QDBusError&)),
92 void OfonoNetworkRegistration::getOperators()
96 request = QDBusMessage::createMethodCall("org.ofono",
97 path(), m_if->ifname(),
100 QDBusConnection::systemBus().callWithCallback(request, this,
101 SLOT(getOperatorsResp(OfonoOperatorList)),
102 SLOT(getOperatorsErr(const QDBusError&)),
106 QString OfonoNetworkRegistration::mode() const
108 return m_if->properties()["Mode"].value<QString>();
111 QString OfonoNetworkRegistration::status() const
113 return m_if->properties()["Status"].value<QString>();
116 uint OfonoNetworkRegistration::locationAreaCode() const
118 return m_if->properties()["LocationAreaCode"].value<uint>();
121 uint OfonoNetworkRegistration::cellId() const
123 return m_if->properties()["CellId"].value<uint>();
126 QString OfonoNetworkRegistration::mcc() const
128 return m_if->properties()["MobileCountryCode"].value<QString>();
131 QString OfonoNetworkRegistration::mnc() const
133 return m_if->properties()["MobileNetworkCode"].value<QString>();
136 QString OfonoNetworkRegistration::technology() const
138 return m_if->properties()["Technology"].value<QString>();
141 QString OfonoNetworkRegistration::name() const
143 return m_if->properties()["Name"].value<QString>();
146 uint OfonoNetworkRegistration::strength() const
148 return m_if->properties()["Strength"].value<uint>();
151 QString OfonoNetworkRegistration::baseStation() const
153 return m_if->properties()["BaseStation"].value<QString>();
156 void OfonoNetworkRegistration::propertyChanged(const QString& property, const QVariant& value)
158 if (property == "Mode") {
159 emit modeChanged(value.value<QString>());
160 } else if (property == "Status") {
161 emit statusChanged(value.value<QString>());
162 } else if (property == "LocationAreaCode") {
163 emit locationAreaCodeChanged(value.value<uint>());
164 } else if (property == "CellId") {
165 emit cellIdChanged(value.value<uint>());
166 } else if (property == "MobileCountryCode") {
167 emit mccChanged(value.value<QString>());
168 } else if (property == "MobileNetworkCode") {
169 emit mncChanged(value.value<QString>());
170 } else if (property == "Technology") {
171 emit technologyChanged(value.value<QString>());
172 } else if (property == "Name") {
173 emit nameChanged(value.value<QString>());
174 } else if (property == "Strength") {
175 emit strengthChanged(value.value<uint>());
176 } else if (property == "BaseStation") {
177 emit baseStationChanged(value.value<QString>());
181 void OfonoNetworkRegistration::registerResp()
183 emit registerComplete(TRUE);
186 void OfonoNetworkRegistration::registerErr(QDBusError error)
188 qDebug() << "Register failed" << error;
189 m_if->setError(error.name(), error.message());
190 emit registerComplete(FALSE);
193 void OfonoNetworkRegistration::getOperatorsResp(OfonoOperatorList list)
196 foreach(OfonoOperatorStruct op, list) {
197 oplist << op.path.path();
199 emit getOperatorsComplete(TRUE, oplist);
202 void OfonoNetworkRegistration::getOperatorsErr(QDBusError error)
204 qDebug() << "GetOperators failed" << error;
205 m_if->setError(error.name(), error.message());
206 emit getOperatorsComplete(FALSE, QStringList());
209 void OfonoNetworkRegistration::scanResp(OfonoOperatorList list)
212 foreach(OfonoOperatorStruct op, list) {
213 oplist << op.path.path();
215 emit scanComplete(TRUE, oplist);
218 void OfonoNetworkRegistration::scanErr(QDBusError error)
220 qDebug() << "Scan failed" << error;
221 m_if->setError(error.name(), error.message());
222 emit scanComplete(FALSE, QStringList());