Added SMS support in ofono-qt
[profile/ivi/ofono-qt.git] / lib / ofononetworkoperator.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 "ofonointerface.h"
28 #include "ofononetworkoperator.h"
29
30 #define REGISTER_TIMEOUT 300000
31
32 OfonoNetworkOperator::OfonoNetworkOperator(const QString& operatorId, QObject *parent)
33     : QObject(parent)
34 {
35     m_if = new OfonoInterface(operatorId, "org.ofono.NetworkOperator", OfonoGetAllOnStartup, this);
36     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
37             this, SLOT(propertyChanged(const QString&, const QVariant&)));
38 }
39
40 OfonoNetworkOperator::OfonoNetworkOperator(const OfonoNetworkOperator& op)
41     : QObject(op.parent())
42 {
43     m_if = new OfonoInterface(op.path(), "org.ofono.NetworkOperator", OfonoGetAllOnStartup, this);
44     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
45             this, SLOT(propertyChanged(const QString&, const QVariant&)));
46 }    
47     
48 bool OfonoNetworkOperator::operator==(const OfonoNetworkOperator &op)
49 {
50     return path() == op.path();
51 }
52
53 OfonoNetworkOperator::~OfonoNetworkOperator()
54 {
55 }
56
57 void OfonoNetworkOperator::registerOp()
58 {
59     QDBusMessage request;
60
61     request = QDBusMessage::createMethodCall("org.ofono",
62                                              path(), m_if->ifname(),
63                                              "Register");
64
65     QDBusConnection::systemBus().callWithCallback(request, this,
66                                         SLOT(registerResp()),
67                                         SLOT(registerErr(const QDBusError&)),
68                                         REGISTER_TIMEOUT);
69 }
70
71 void OfonoNetworkOperator::registerResp()
72 {
73     emit registerComplete(TRUE);
74 }
75
76 void OfonoNetworkOperator::registerErr(const QDBusError& error)
77 {
78     m_if->setError(error.name(), error.message());
79     emit registerComplete(FALSE);
80 }
81
82 QString OfonoNetworkOperator::name() const
83 {
84     return m_if->properties()["Name"].value<QString>();
85 }
86
87 QString OfonoNetworkOperator::status() const
88 {
89     return m_if->properties()["Status"].value<QString>();
90 }
91
92 QString OfonoNetworkOperator::mcc() const
93 {
94     return m_if->properties()["MobileCountryCode"].value<QString>();
95 }
96
97 QString OfonoNetworkOperator::mnc() const
98 {
99     return m_if->properties()["MobileNetworkCode"].value<QString>();
100 }
101
102 QStringList OfonoNetworkOperator::technologies() const
103 {
104     return m_if->properties()["Technologies"].value<QStringList>();
105 }
106
107 QString OfonoNetworkOperator::additionalInfo() const
108 {
109     return m_if->properties()["AdditionalInformation"].value<QString>();
110 }
111
112 void OfonoNetworkOperator::propertyChanged(const QString& property, const QVariant& value)
113 {
114     if (property == "Name") {   
115         emit nameChanged(value.value<QString>());
116     } else if (property == "Status") {  
117         emit statusChanged(value.value<QString>());
118     } else if (property == "MobileCountryCode") {       
119         emit mccChanged(value.value<QString>());
120     } else if (property == "MobileNetworkCode") {       
121         emit mncChanged(value.value<QString>());
122     } else if (property == "Technologies") {    
123         emit technologiesChanged(value.value<QStringList>());
124     } else if (property == "AdditionalInformation") {   
125         emit additionalInfoChanged(value.value<QString>());
126     }
127 }
128
129 QString OfonoNetworkOperator::path() const
130 {
131     return m_if->path();
132 }
133     
134 QString OfonoNetworkOperator::errorName() const
135 {
136     return m_if->errorName();
137 }
138
139 QString OfonoNetworkOperator::errorMessage() const
140 {
141     return m_if->errorMessage();
142 }
143