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