Adding connmancontext API support to libofono-qt Signed-off-by: Arun Ravindran <ext...
[profile/ivi/ofono-qt.git] / lib / ofonoconnmancontext.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2011 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 <QDBusArgument>
27
28 #include "ofonointerface.h"
29 #include "ofonoconnman.h"
30 #include "ofonoconnmancontext.h"
31
32
33 OfonoConnmanContext::OfonoConnmanContext(const QString& contextId, QObject *parent)
34     : QObject(parent)
35 {
36     m_if = new OfonoInterface(contextId, "org.ofono.ConnectionContext", OfonoGetAllOnStartup, this);
37
38     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
39             this, SLOT(propertyChanged(const QString&, const QVariant&)));
40
41 }
42
43 OfonoConnmanContext::OfonoConnmanContext(const OfonoConnmanContext& context)
44     : QObject(context.parent())
45 {
46     m_if = new OfonoInterface(context.path(), "org.ofono.ConnectionContext", OfonoGetAllOnStartup, this);
47
48     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
49             this, SLOT(propertyChanged(const QString&, const QVariant&)));
50
51 }
52
53 bool OfonoConnmanContext::operator==(const OfonoConnmanContext &context)
54 {
55     return path() == context.path();
56 }
57
58 OfonoConnmanContext::~OfonoConnmanContext()
59 {
60 }
61
62 bool OfonoConnmanContext::active() const
63 {
64     return m_if->properties()["Active"].value<bool>();
65 }
66
67 QString OfonoConnmanContext::accessPointName() const
68 {
69     return m_if->properties()["AccessPointName"].value<QString>();
70 }
71
72 QString OfonoConnmanContext::name() const
73 {
74     return m_if->properties()["Name"].value<QString>();
75 }
76
77 QString OfonoConnmanContext::type() const
78 {
79     return m_if->properties()["Type"].value<QString>();
80 }
81
82 QString OfonoConnmanContext::username() const
83 {
84     return m_if->properties()["Username"].value<QString>();
85 }
86
87 QString OfonoConnmanContext::password() const
88 {
89     return m_if->properties()["Password"].value<QString>();
90 }
91
92 QString OfonoConnmanContext::protocol() const
93 {
94     return m_if->properties()["Protocol"].value<QString>();
95 }
96
97 QString OfonoConnmanContext::messageProxy() const
98 {
99     return m_if->properties()["MessageProxy"].value<QString>();
100 }
101
102 QString OfonoConnmanContext::messageCenter() const
103 {
104     return m_if->properties()["MessageCenter"].value<QString>();
105 }
106
107 void OfonoConnmanContext::propertyChanged(const QString &property, const QVariant &value)
108 {
109     if (property == "Active") {
110         emit activeChanged(value.value<bool>());
111     } else if (property == "Name") {
112         emit nameChanged(value.value<QString>());
113     } else if (property == "AccessPointName") {
114         emit accessPointNameChanged(value.value<QString>());
115     } else if (property == "Type") {
116         emit typeChanged(value.value<QString>());
117     } else if (property == "Username") {
118         emit userNameChanged(value.value<QString>());
119     } else if (property == "Password") {
120         emit passwordChanged(value.value<QString>());
121     } else if (property == "Protocol") {
122         emit protocolChanged(value.value<QString>());
123     } else if (property == "MessageProxy") {
124         emit messageProxyChanged(value.value<QString>());
125     } else if (property == "MessageCenter") {
126             emit messageCenterChanged(value.value<QString>());
127
128     } else if (property == "Settings") {
129
130         QVariantMap map;
131         value.value<QDBusArgument>()>>map;
132         emit settingsChanged(map);
133     }
134 }
135
136 QVariantMap OfonoConnmanContext::settings() const
137 {
138     QVariantMap map;
139     m_if->properties()["Settings"].value<QDBusArgument>()>>map;
140     return map;
141 }
142
143 QString OfonoConnmanContext::path() const
144 {
145     return m_if->path();
146 }
147
148 QString OfonoConnmanContext::errorName() const
149 {
150     return m_if->errorName();
151 }
152
153 QString OfonoConnmanContext::errorMessage() const
154 {
155     return m_if->errorMessage();
156 }
157
158 /* Set Property*/
159 void OfonoConnmanContext::setActive(const bool value)
160 {
161     m_if->setProperty("Active",QVariant(value));
162 }
163
164 void OfonoConnmanContext::setAccessPointName(const QString& value)
165 {
166     m_if->setProperty("AccessPointName",QVariant(value));
167 }
168
169 void OfonoConnmanContext::setType(const QString& value)
170 {
171     m_if->setProperty("Type",QVariant(value));
172 }
173
174 void OfonoConnmanContext::setUsername(const QString& value)
175 {
176     m_if->setProperty("Username",QVariant(value));
177 }
178
179 void OfonoConnmanContext::setPassword(const QString& value)
180 {
181     m_if->setProperty("Password",QVariant(value));
182 }
183
184 void OfonoConnmanContext::setProtocol(const QString& value)
185 {
186     m_if->setProperty("Protocol",QVariant(value));
187 }
188
189 void OfonoConnmanContext::setName(const QString& value)
190 {
191     m_if->setProperty("Name",QVariant(value));
192 }
193
194 void OfonoConnmanContext::setMessageProxy(const QString& value)
195 {
196     m_if->setProperty("MessageProxy",QVariant(value));
197 }
198
199 void OfonoConnmanContext::setMessageCenter(const QString& value)
200 {
201     m_if->setProperty("MessageCenter",QVariant(value));
202 }
203
204 void OfonoConnmanContext::setPropertyFailed(const QString &property)
205 {
206     if (property == "Active") {
207         emit setActiveFailed();
208     } else if (property == "AccessPointName") {
209         emit setAccessPointNameFailed();
210     } else if (property == "Type") {
211         emit setTypeFailed();
212     } else if (property == "Username") {
213         emit setUsernameFailed();
214     } else if (property == "Password") {
215         emit setPasswordFailed();
216     } else if (property == "Protocol") {
217         emit setProtocolFailed();
218     } else if (property == "Name") {
219         emit setNameFailed();
220     } else if (property == "MessageProxy") {
221         emit setMessageProxyFailed();
222     } else if (property == "MessageCenter") {
223         emit setMessageCenterFailed();
224     }
225 }