Do not subclass OfonoModemInterface from OfonoInterface
[profile/ivi/ofono-qt.git] / lib / ofonocallbarring.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 <QtCore/QObject>
25 #include <QtDBus/QtDBus>
26 #include "ofonocallbarring.h"
27 #include "ofonointerface.h"
28
29 #define SET_PROPERTY_TIMEOUT 300000
30
31 OfonoCallBarring::OfonoCallBarring(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
32     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.CallBarring", OfonoGetAllOnFirstRequest, parent)
33 {
34     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
35             this, SLOT(propertyChanged(const QString&, const QVariant&)));
36     connect(m_if, SIGNAL(setPropertyFailed(const QString&)), 
37             this, SLOT(setPropertyFailed(const QString&)));
38     connect(m_if, SIGNAL(requestPropertyComplete(bool, const QString&, const QVariant&)),
39             this, SLOT(requestPropertyComplete(bool, const QString&, const QVariant&)));
40     QDBusConnection::systemBus().connect("org.ofono", path(), m_if->ifname(), 
41                                          "IncomingBarringInEffect",
42                                          this,
43                                          SIGNAL(incomingBarringInEffect()));
44     QDBusConnection::systemBus().connect("org.ofono", path(), m_if->ifname(), 
45                                          "OutgoingBarringInEffect",
46                                          this,
47                                          SIGNAL(outgoingBarringInEffect()));
48     m_pendingProperty = QString();
49 }
50
51 OfonoCallBarring::~OfonoCallBarring()
52 {
53 }
54
55 void OfonoCallBarring::setProperty(const QString& name, 
56                                    const QVariant& property, 
57                                    const QString& password)
58 {
59     if (m_pendingProperty.length() > 0) {
60         // FIXME: should indicate that a setProperty is already in progress
61         m_if->setError(QString(), QString("Operation already in progress"));
62         emit setPropertyFailed(name);
63         return;
64     }
65
66
67     QDBusMessage request;
68
69     request = QDBusMessage::createMethodCall("org.ofono",
70                                              path(), m_if->ifname(),
71                                              "SetProperty");
72     request.setArguments(QList<QVariant>() 
73                          << QVariant(name) 
74                          << QVariant::fromValue(QDBusVariant(property))
75                          << QVariant(password));
76
77     bool result = QDBusConnection::systemBus().callWithCallback(request, this,
78                                         SLOT(setPropertyResp()),
79                                         SLOT(setPropertyErr(const QDBusError&)),
80                                         SET_PROPERTY_TIMEOUT);
81     if (!result) {
82         // FIXME: should indicate that sending a message failed
83         m_if->setError(QString(), QString("DBUS sending failed"));
84         emit setPropertyFailed(name);
85         return;
86     }
87     m_pendingProperty = name;
88
89
90 }
91
92 void OfonoCallBarring::setPropertyResp()
93 {
94     m_pendingProperty = QString();
95     // emit nothing; we will get a PropertyChanged signal
96 }
97
98 void OfonoCallBarring::setPropertyErr(const QDBusError& error)
99 {
100     QString prop = m_pendingProperty;
101     m_if->setError(error.name(), error.message());
102     m_pendingProperty = QString();
103     emit setPropertyFailed(prop);
104 }
105
106
107 void OfonoCallBarring::requestChangePassword(const QString &old_password, 
108                                              const QString &new_password)
109 {
110     QDBusMessage request;
111
112     request = QDBusMessage::createMethodCall("org.ofono",
113                                              path(), m_if->ifname(),
114                                              "ChangePassword");
115     request << old_password << new_password;
116
117     QDBusConnection::systemBus().callWithCallback(request, this,
118                                         SLOT(changePasswordResp()),
119                                         SLOT(changePasswordErr(const QDBusError&)));
120 }
121
122 void OfonoCallBarring::requestDisableAll(const QString &password)
123 {
124     QDBusMessage request;
125
126     request = QDBusMessage::createMethodCall("org.ofono",
127                                              path(), m_if->ifname(),
128                                              "DisableAll");
129     request << password;
130
131     QDBusConnection::systemBus().callWithCallback(request, this,
132                                         SLOT(disableAllResp()),
133                                         SLOT(disableAllErr(const QDBusError&)));
134 }
135
136 void OfonoCallBarring::requestDisableAllIncoming(const QString &password)
137 {
138     QDBusMessage request;
139
140     request = QDBusMessage::createMethodCall("org.ofono",
141                                              path(), m_if->ifname(),
142                                              "DisableAllIncoming");
143     request << password;
144
145     QDBusConnection::systemBus().callWithCallback(request, this,
146                                         SLOT(disableAllIncomingResp()),
147                                         SLOT(disableAllIncomingErr(const QDBusError&)));
148 }
149
150 void OfonoCallBarring::requestDisableAllOutgoing(const QString &password)
151 {
152     QDBusMessage request;
153
154     request = QDBusMessage::createMethodCall("org.ofono",
155                                              path(), m_if->ifname(),
156                                              "DisableAllOutgoing");
157     request << password;
158
159     QDBusConnection::systemBus().callWithCallback(request, this,
160                                         SLOT(disableAllOutgoingResp()),
161                                         SLOT(disableAllOutgoingErr(const QDBusError&)));
162 }
163
164
165 void OfonoCallBarring::requestVoiceIncoming()
166 {
167     m_if->requestProperty("VoiceIncoming");
168 }
169
170 void OfonoCallBarring::setVoiceIncoming(const QString &barrings, const QString &password)
171 {
172     setProperty("VoiceIncoming", qVariantFromValue(barrings), password);
173 }
174
175 void OfonoCallBarring::requestVoiceOutgoing()
176 {
177     m_if->requestProperty("VoiceOutgoing");
178 }
179
180 void OfonoCallBarring::setVoiceOutgoing(const QString &barrings, const QString &password)
181 {
182     setProperty("VoiceOutgoing", qVariantFromValue(barrings), password);
183 }
184
185 void OfonoCallBarring::propertyChanged(const QString& property, const QVariant& value)
186 {
187     if (property == "VoiceIncoming") {  
188         emit voiceIncomingChanged(value.value<QString>());
189     } else  if (property == "VoiceOutgoing") {  
190         emit voiceOutgoingChanged(value.value<QString>());
191     }
192 }
193
194 void OfonoCallBarring::setPropertyFailed(const QString& property)
195 {
196     if (property == "VoiceIncoming") {  
197         emit setVoiceIncomingFailed();
198     } else if (property == "VoiceOutgoing") {   
199         emit setVoiceOutgoingFailed();
200     }  
201 }
202
203 void OfonoCallBarring::requestPropertyComplete(bool success, const QString& property, const QVariant& value)
204 {
205     if (property == "VoiceIncoming") {  
206         success ? emit voiceIncomingComplete(true, value.value<QString>()) : emit voiceIncomingComplete(false, QString());
207     } else if (property == "VoiceOutgoing") {   
208         success ? emit voiceOutgoingComplete(true, value.value<QString>()) : emit voiceOutgoingComplete(false, QString());
209     }
210 }
211
212 void OfonoCallBarring::changePasswordResp()
213 {
214     emit changePasswordComplete(TRUE);
215 }
216
217 void OfonoCallBarring::changePasswordErr(QDBusError error)
218 {
219     qDebug() << "ChangePassword failed" << error;
220     m_if->setError(error.name(), error.message());
221     emit changePasswordComplete(FALSE);
222 }
223
224 void OfonoCallBarring::disableAllResp()
225 {
226     emit disableAllComplete(TRUE);
227 }
228
229 void OfonoCallBarring::disableAllErr(QDBusError error)
230 {
231     qDebug() << "DisableAll failed" << error;
232     m_if->setError(error.name(), error.message());
233     emit disableAllComplete(FALSE);
234 }
235
236 void OfonoCallBarring::disableAllIncomingResp()
237 {
238     emit disableAllIncomingComplete(TRUE);
239 }
240
241 void OfonoCallBarring::disableAllIncomingErr(QDBusError error)
242 {
243     qDebug() << "DisableAllIncoming failed" << error;
244     m_if->setError(error.name(), error.message());
245     emit disableAllIncomingComplete(FALSE);
246 }
247
248 void OfonoCallBarring::disableAllOutgoingResp()
249 {
250     emit disableAllOutgoingComplete(TRUE);
251 }
252
253 void OfonoCallBarring::disableAllOutgoingErr(QDBusError error)
254 {
255     qDebug() << "DisableAllOutgoing failed" << error;
256     m_if->setError(error.name(), error.message());
257     emit disableAllOutgoingComplete(FALSE);
258 }