Integrate custom callbarring setProperty() into 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 }
49
50 OfonoCallBarring::~OfonoCallBarring()
51 {
52 }
53
54 void OfonoCallBarring::changePassword(const QString &old_password, 
55                                              const QString &new_password)
56 {
57     QDBusMessage request;
58
59     request = QDBusMessage::createMethodCall("org.ofono",
60                                              path(), m_if->ifname(),
61                                              "ChangePassword");
62     request << old_password << new_password;
63
64     QDBusConnection::systemBus().callWithCallback(request, this,
65                                         SLOT(changePasswordResp()),
66                                         SLOT(changePasswordErr(const QDBusError&)));
67 }
68
69 void OfonoCallBarring::disableAll(const QString &password)
70 {
71     QDBusMessage request;
72
73     request = QDBusMessage::createMethodCall("org.ofono",
74                                              path(), m_if->ifname(),
75                                              "DisableAll");
76     request << password;
77
78     QDBusConnection::systemBus().callWithCallback(request, this,
79                                         SLOT(disableAllResp()),
80                                         SLOT(disableAllErr(const QDBusError&)));
81 }
82
83 void OfonoCallBarring::disableAllIncoming(const QString &password)
84 {
85     QDBusMessage request;
86
87     request = QDBusMessage::createMethodCall("org.ofono",
88                                              path(), m_if->ifname(),
89                                              "DisableAllIncoming");
90     request << password;
91
92     QDBusConnection::systemBus().callWithCallback(request, this,
93                                         SLOT(disableAllIncomingResp()),
94                                         SLOT(disableAllIncomingErr(const QDBusError&)));
95 }
96
97 void OfonoCallBarring::disableAllOutgoing(const QString &password)
98 {
99     QDBusMessage request;
100
101     request = QDBusMessage::createMethodCall("org.ofono",
102                                              path(), m_if->ifname(),
103                                              "DisableAllOutgoing");
104     request << password;
105
106     QDBusConnection::systemBus().callWithCallback(request, this,
107                                         SLOT(disableAllOutgoingResp()),
108                                         SLOT(disableAllOutgoingErr(const QDBusError&)));
109 }
110
111
112 void OfonoCallBarring::requestVoiceIncoming()
113 {
114     m_if->requestProperty("VoiceIncoming");
115 }
116
117 void OfonoCallBarring::setVoiceIncoming(const QString &barrings, const QString &password)
118 {
119     m_if->setProperty("VoiceIncoming", qVariantFromValue(barrings), password);
120 }
121
122 void OfonoCallBarring::requestVoiceOutgoing()
123 {
124     m_if->requestProperty("VoiceOutgoing");
125 }
126
127 void OfonoCallBarring::setVoiceOutgoing(const QString &barrings, const QString &password)
128 {
129     m_if->setProperty("VoiceOutgoing", qVariantFromValue(barrings), password);
130 }
131
132 void OfonoCallBarring::propertyChanged(const QString& property, const QVariant& value)
133 {
134     if (property == "VoiceIncoming") {  
135         emit voiceIncomingChanged(value.value<QString>());
136     } else  if (property == "VoiceOutgoing") {  
137         emit voiceOutgoingChanged(value.value<QString>());
138     }
139 }
140
141 void OfonoCallBarring::setPropertyFailed(const QString& property)
142 {
143     if (property == "VoiceIncoming") {  
144         emit setVoiceIncomingFailed();
145     } else if (property == "VoiceOutgoing") {   
146         emit setVoiceOutgoingFailed();
147     }  
148 }
149
150 void OfonoCallBarring::requestPropertyComplete(bool success, const QString& property, const QVariant& value)
151 {
152     if (property == "VoiceIncoming") {  
153         success ? emit voiceIncomingComplete(true, value.value<QString>()) : emit voiceIncomingComplete(false, QString());
154     } else if (property == "VoiceOutgoing") {   
155         success ? emit voiceOutgoingComplete(true, value.value<QString>()) : emit voiceOutgoingComplete(false, QString());
156     }
157 }
158
159 void OfonoCallBarring::changePasswordResp()
160 {
161     emit changePasswordComplete(TRUE);
162 }
163
164 void OfonoCallBarring::changePasswordErr(QDBusError error)
165 {
166     qDebug() << "ChangePassword failed" << error;
167     m_if->setError(error.name(), error.message());
168     emit changePasswordComplete(FALSE);
169 }
170
171 void OfonoCallBarring::disableAllResp()
172 {
173     emit disableAllComplete(TRUE);
174 }
175
176 void OfonoCallBarring::disableAllErr(QDBusError error)
177 {
178     qDebug() << "DisableAll failed" << error;
179     m_if->setError(error.name(), error.message());
180     emit disableAllComplete(FALSE);
181 }
182
183 void OfonoCallBarring::disableAllIncomingResp()
184 {
185     emit disableAllIncomingComplete(TRUE);
186 }
187
188 void OfonoCallBarring::disableAllIncomingErr(QDBusError error)
189 {
190     qDebug() << "DisableAllIncoming failed" << error;
191     m_if->setError(error.name(), error.message());
192     emit disableAllIncomingComplete(FALSE);
193 }
194
195 void OfonoCallBarring::disableAllOutgoingResp()
196 {
197     emit disableAllOutgoingComplete(TRUE);
198 }
199
200 void OfonoCallBarring::disableAllOutgoingErr(QDBusError error)
201 {
202     qDebug() << "DisableAllOutgoing failed" << error;
203     m_if->setError(error.name(), error.message());
204     emit disableAllOutgoingComplete(FALSE);
205 }