Remove unnecessary includes
[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 #include <QtCore/QDebug>
27
28 #include "ofononetworkoperator.h"
29
30 #define REGISTER_TIMEOUT 300000
31
32 OfonoNetworkOperator::OfonoNetworkOperator(const QString& operatorId, QObject *parent)
33     : OfonoInterface(operatorId, "org.ofono.NetworkOperator", OfonoInterface::GetAllOnStartup, parent)
34 {
35     connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
36             this, SLOT(propertyChanged(const QString&, const QVariant&)));
37 }
38
39 OfonoNetworkOperator::~OfonoNetworkOperator()
40 {
41 }
42
43 void OfonoNetworkOperator::requestRegister()
44 {
45     QDBusMessage request;
46
47     request = QDBusMessage::createMethodCall("org.ofono",
48                                              path(), ifname(),
49                                              "Register");
50
51     QDBusConnection::systemBus().callWithCallback(request, this,
52                                         SLOT(registerResp()),
53                                         SLOT(registerErr(const QDBusError&)),
54                                         REGISTER_TIMEOUT);
55 }
56
57 void OfonoNetworkOperator::registerResp()
58 {
59     emit registerComplete(TRUE);
60 }
61
62 void OfonoNetworkOperator::registerErr(const QDBusError& error)
63 {
64     qDebug() << "Register failed" << error;
65     m_errorName = error.name();
66     m_errorMessage = error.message();
67     emit registerComplete(FALSE);
68 }
69
70 QString OfonoNetworkOperator::name() const
71 {
72     return properties()["Name"].value<QString>();
73 }
74
75 QString OfonoNetworkOperator::status() const
76 {
77     return properties()["Status"].value<QString>();
78 }
79
80 QString OfonoNetworkOperator::mcc() const
81 {
82     return properties()["MobileCountryCode"].value<QString>();
83 }
84
85 QString OfonoNetworkOperator::mnc() const
86 {
87     return properties()["MobileNetworkCode"].value<QString>();
88 }
89
90 QStringList OfonoNetworkOperator::technologies() const
91 {
92     return properties()["Technologies"].value<QStringList>();
93 }
94
95 QString OfonoNetworkOperator::additionalInfo() const
96 {
97     return properties()["AdditionalInformation"].value<QString>();
98 }
99
100 void OfonoNetworkOperator::propertyChanged(const QString& property, const QVariant& value)
101 {
102     if (property == "Name") {   
103         emit nameChanged(value.value<QString>());
104     } else if (property == "Status") {  
105         emit statusChanged(value.value<QString>());
106     } else if (property == "MobileCountryCode") {       
107         emit mccChanged(value.value<QString>());
108     } else if (property == "MobileNetworkCode") {       
109         emit mncChanged(value.value<QString>());
110     } else if (property == "Technologies") {    
111         emit technologiesChanged(value.value<QStringList>());
112     } else if (property == "AdditionalInformation") {   
113         emit additionalInfoChanged(value.value<QString>());
114     }
115 }