Adding CallVolume interface support in ofono-qt Bindings Signed-off-by: Arun Ravindra...
[profile/ivi/ofono-qt.git] / lib / ofonovoicecall.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 <QtCore/QDebug>
27
28 #include "ofonointerface.h"
29 #include "ofonovoicecall.h"
30
31 #define VOICECALL_TIMEOUT 30000
32
33 OfonoVoiceCall::OfonoVoiceCall(const QString& callId, QObject *parent)
34     : QObject(parent)
35 {
36     m_if = new OfonoInterface(callId, "org.ofono.VoiceCall", OfonoGetAllOnStartup, this);
37
38     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
39             this, SLOT(propertyChanged(const QString&, const QVariant&)));
40
41     QDBusConnection::systemBus().connect("org.ofono",path(),m_if->ifname(),
42                                          "DisconnectReason", this,
43                                          SIGNAL(disconnectReason(const QString&)));
44
45 }
46
47 OfonoVoiceCall::OfonoVoiceCall(const OfonoVoiceCall& call)
48     : QObject(call.parent())
49 {
50     m_if = new OfonoInterface(call.path(), "org.ofono.VoiceCall", OfonoGetAllOnStartup, this);
51
52     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
53             this, SLOT(propertyChanged(const QString&, const QVariant&)));
54
55     QDBusConnection::systemBus().connect("org.ofono",path(),m_if->ifname(),
56                                          "DisconnectReason", this,
57                                          SIGNAL(disconnectReason(const QString&)));
58 }
59
60 bool OfonoVoiceCall::operator==(const OfonoVoiceCall &call)
61 {
62     return path() == call.path();
63 }
64
65 OfonoVoiceCall::~OfonoVoiceCall()
66 {
67 }
68
69 void OfonoVoiceCall::answer()
70 {
71     QDBusMessage request;
72
73     request = QDBusMessage::createMethodCall("org.ofono",
74                                              path(), m_if->ifname(),
75                                              "Answer");
76
77     QDBusConnection::systemBus().callWithCallback(request, this,
78                                         SLOT(answerResp()),
79                                         SLOT(answerErr(const QDBusError&)),
80                                         VOICECALL_TIMEOUT);
81 }
82
83 void OfonoVoiceCall::hangup()
84 {
85     QDBusMessage request;
86
87     request = QDBusMessage::createMethodCall("org.ofono",
88                                              path(), m_if->ifname(),
89                                              "Hangup");
90
91     QDBusConnection::systemBus().callWithCallback(request, this,
92                                         SLOT(hangupResp()),
93                                         SLOT(hangupErr(const QDBusError&)),
94                                         VOICECALL_TIMEOUT);
95 }
96
97 void OfonoVoiceCall::deflect(const QString &number)
98 {
99     QDBusMessage request;
100
101     request = QDBusMessage::createMethodCall("org.ofono",
102                                              path(), m_if->ifname(),
103                                              "Deflect");
104     QList<QVariant>arg;
105     arg.append(QVariant(number));
106     request.setArguments(arg);
107
108     QDBusConnection::systemBus().callWithCallback(request, this,
109                                         SLOT(deflectResp()),
110                                         SLOT(deflectErr(const QDBusError&)),
111                                         VOICECALL_TIMEOUT);
112 }
113
114 void OfonoVoiceCall::answerResp()
115 {
116     emit answerComplete(TRUE);
117 }
118
119 void OfonoVoiceCall::answerErr(const QDBusError &error)
120 {
121     qDebug() << "request failed" << error;
122     m_if->setError(error.name(), error.message());
123     emit answerComplete(FALSE);
124 }
125
126 void OfonoVoiceCall::hangupResp()
127 {
128     emit hangupComplete(TRUE);
129 }
130
131 void OfonoVoiceCall::hangupErr(const QDBusError &error)
132 {
133     qDebug() << "request failed" << error;
134     m_if->setError(error.name(), error.message());
135     emit hangupComplete(FALSE);
136 }
137
138 void OfonoVoiceCall::deflectResp()
139 {
140     emit deflectComplete(TRUE);
141 }
142
143 void OfonoVoiceCall::deflectErr(const QDBusError &error)
144 {
145     qDebug() << "request failed" << error;
146     m_if->setError(error.name(), error.message());
147     emit deflectComplete(FALSE);
148 }
149
150 QString OfonoVoiceCall::incomingLine() const
151 {
152     return m_if->properties()["IncomingLine"].value<QString>();
153 }
154
155 QString OfonoVoiceCall::lineIdentification() const
156 {
157     return m_if->properties()["LineIdentification"].value<QString>();
158 }
159
160 QString OfonoVoiceCall::name() const
161 {
162     return m_if->properties()["Name"].value<QString>();
163 }
164
165 QString OfonoVoiceCall::state() const
166 {
167     return m_if->properties()["State"].value<QString>();
168 }
169
170 QString OfonoVoiceCall::startTime() const
171 {
172     return m_if->properties()["StartTime"].value<QString>();
173 }
174
175 QString OfonoVoiceCall::information() const
176 {
177     return m_if->properties()["Information"].value<QString>();
178 }
179
180 bool OfonoVoiceCall::multiparty() const
181 {
182     return m_if->properties()["Multiparty"].value<bool>();
183 }
184
185 bool OfonoVoiceCall::emergency() const
186 {
187     return m_if->properties()["Emergency"].value<bool>();
188 }
189
190 void OfonoVoiceCall::propertyChanged(const QString &property, const QVariant &value)
191 {
192     if (property == "LineIdentification") {
193         emit lineIdentificationChanged(value.value<QString>());
194     } else if (property == "Name") {
195         emit nameChanged(value.value<QString>());
196     } else if (property == "State") {
197         emit stateChanged(value.value<QString>());
198     } else if (property == "Information") {
199         emit informationChanged(value.value<QString>());
200     } else if (property == "IncomingLine") {
201         emit incomingLineChanged(value.value<QString>());
202     } else if (property == "Multiparty") {
203         emit multipartyChanged(value.value<bool>());
204     } else if (property == "Emergency") {
205         emit emergencyChanged(value.value<bool>());
206     } else if (property == "StartTime") {
207         emit startTimeChanged(value.value<QString>());
208     } else if (property == "Icon") {
209             emit iconChanged(value.value<quint8>());
210     }
211 }
212
213 QString OfonoVoiceCall::path() const
214 {
215     return m_if->path();
216 }
217
218 QString OfonoVoiceCall::errorName() const
219 {
220     return m_if->errorName();
221 }
222
223 QString OfonoVoiceCall::errorMessage() const
224 {
225     return m_if->errorMessage();
226 }