2 * This file is part of ofono-qt
4 * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
8 * Portions of this file are Copyright (C) 2011 Intel Corporation
9 * Contact: Shane Bryan <shane.bryan@linux.intel.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * version 2.1 as published by the Free Software Foundation.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <QtDBus/QtDBus>
28 #include <QtCore/QObject>
30 #include "ofonovoicecallmanager.h"
31 #include "ofonointerface.h"
33 #define DIAL_TIMEOUT 30000
34 #define TONE_TIMEOUT 10000
35 #define TRANSFER_TIMEOUT 20000
36 #define SWAP_TIMEOUT 20000
37 #define HANGUP_TIMEOUT 30000
38 #define HOLD_TIMEOUT 30000
39 #define PRIVATE_CHAT_TIMEOUT 30000
40 #define CREATE_MULTIPARTY_TIMEOUT 30000
42 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoVoiceCallManagerStruct &call)
44 argument.beginStructure();
45 argument << call.path << call.properties;
46 argument.endStructure();
50 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoVoiceCallManagerStruct &call)
52 argument.beginStructure();
53 argument >> call.path >> call.properties;
54 argument.endStructure();
58 OfonoVoiceCallManager::OfonoVoiceCallManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
59 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.VoiceCallManager", OfonoGetAllOnStartup, parent)
61 qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
62 qDBusRegisterMetaType<OfonoVoiceCallManagerList>();
64 m_calllist = getCallList();
66 connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)),
67 this, SLOT(propertyChanged(const QString&, const QVariant&)));
68 connect(this, SIGNAL(validityChanged(bool)),
69 this, SLOT(validityChanged(bool)));
70 connect(modem(), SIGNAL(pathChanged(QString)), this, SLOT(pathChanged(const QString&)));
72 connectDbusSignals(path());
75 OfonoVoiceCallManager::~OfonoVoiceCallManager()
80 void OfonoVoiceCallManager::validityChanged(bool /*validity*/)
82 m_calllist = getCallList();
85 void OfonoVoiceCallManager::pathChanged(const QString& path)
87 connectDbusSignals(path);
90 QStringList OfonoVoiceCallManager::getCallList()
92 QDBusReply<OfonoVoiceCallManagerList> reply;
93 OfonoVoiceCallManagerList calls;
96 QStringList messageList;
98 qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
99 qDBusRegisterMetaType<OfonoVoiceCallManagerList>();
101 request = QDBusMessage::createMethodCall("org.ofono",
102 path(), m_if->ifname(),
104 reply = QDBusConnection::systemBus().call(request);
107 foreach(OfonoVoiceCallManagerStruct call, calls) {
108 messageList<< call.path.path();
113 void OfonoVoiceCallManager::connectDbusSignals(const QString& path)
115 QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
117 SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&)));
118 QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
120 SLOT(callRemovedChanged(const QDBusObjectPath&)));
121 QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
122 "BarringActive", this,
123 SIGNAL(barringActive(const QString&)));
124 QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
126 SIGNAL(forwarded(const QString&)));
128 QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
130 SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&)));
131 QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
133 SLOT(callRemovedChanged(const QDBusObjectPath&)));
134 QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
135 "BarringActive", this,
136 SIGNAL(barringActive(const QString&)));
137 QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
139 SIGNAL(forwarded(const QString&)));
142 void OfonoVoiceCallManager::dial(const QString &number, const QString &callerid_hide)
144 QDBusMessage request;
145 request = QDBusMessage::createMethodCall("org.ofono",
146 path(), m_if->ifname(),
149 arg.append(QVariant(number));
150 arg.append(QVariant(callerid_hide));
151 request.setArguments(arg);
152 QDBusConnection::systemBus().callWithCallback(request, this,
154 SLOT(dialErr(const QDBusError&)),
158 void OfonoVoiceCallManager::hangupAll()
160 QDBusMessage request;
161 request = QDBusMessage::createMethodCall("org.ofono",
162 path(), m_if->ifname(),
165 QDBusConnection::systemBus().callWithCallback(request, this,
166 SLOT(hangupAllResp()),
167 SLOT(hangupAllErr(const QDBusError&)),
171 void OfonoVoiceCallManager::sendTones(const QString &tonestring)
173 QDBusMessage request;
174 request = QDBusMessage::createMethodCall("org.ofono",
175 path(), m_if->ifname(),
178 arg.append(QVariant(tonestring));
179 request.setArguments(arg);
181 QDBusConnection::systemBus().callWithCallback(request, this,
182 SLOT(sendTonesResp()),
183 SLOT(sendTonesErr(const QDBusError&)),
184 (TONE_TIMEOUT*tonestring.length()));
187 void OfonoVoiceCallManager::transfer()
189 QDBusMessage request;
190 request = QDBusMessage::createMethodCall("org.ofono",
191 path(), m_if->ifname(),
194 QDBusConnection::systemBus().callWithCallback(request, this,
195 SLOT(transferResp()),
196 SLOT(transferErr(const QDBusError&)),
200 void OfonoVoiceCallManager::swapCalls()
202 QDBusMessage request;
203 request = QDBusMessage::createMethodCall("org.ofono",
204 path(), m_if->ifname(),
207 QDBusConnection::systemBus().callWithCallback(request, this,
208 SLOT(swapCallsResp()),
209 SLOT(swapCallsErr(const QDBusError&)),
213 void OfonoVoiceCallManager::releaseAndAnswer()
215 QDBusMessage request;
216 request = QDBusMessage::createMethodCall("org.ofono",
217 path(), m_if->ifname(),
220 QDBusConnection::systemBus().callWithCallback(request, this,
221 SLOT(releaseAndAnswerResp()),
222 SLOT(releaseAndAnswerErr(const QDBusError&)),
226 void OfonoVoiceCallManager::holdAndAnswer()
228 QDBusMessage request;
229 request = QDBusMessage::createMethodCall("org.ofono",
230 path(), m_if->ifname(),
233 QDBusConnection::systemBus().callWithCallback(request, this,
234 SLOT(holdAndAnswerResp()),
235 SLOT(holdAndAnswerErr(const QDBusError&)),
239 void OfonoVoiceCallManager::privateChat(const QString &call)
241 QDBusMessage request;
242 request = QDBusMessage::createMethodCall("org.ofono",
243 path(), m_if->ifname(),
247 arg.append(qVariantFromValue(QDBusObjectPath(call)));
248 request.setArguments(arg);
249 QDBusConnection::systemBus().callWithCallback(request, this,
250 SLOT(privateChatResp(const QList<QDBusObjectPath>&)),
251 SLOT(privateChatErr(const QDBusError&)),
252 PRIVATE_CHAT_TIMEOUT);
255 void OfonoVoiceCallManager::createMultiparty()
257 QDBusMessage request;
258 request = QDBusMessage::createMethodCall("org.ofono",
259 path(), m_if->ifname(),
262 QDBusConnection::systemBus().callWithCallback(request, this,
263 SLOT(createMultipartyResp(const QList<QDBusObjectPath>&)),
264 SLOT(createMultipartyErr(const QDBusError&)),
265 CREATE_MULTIPARTY_TIMEOUT);
268 void OfonoVoiceCallManager::hangupMultiparty()
270 QDBusMessage request;
271 request = QDBusMessage::createMethodCall("org.ofono",
272 path(), m_if->ifname(),
275 QDBusConnection::systemBus().callWithCallback(request, this,
276 SLOT(hangupMultipartyResp()),
277 SLOT(hangupMultipartyErr(const QDBusError&)),
281 void OfonoVoiceCallManager::hangupMultipartyResp()
283 emit hangupMultipartyComplete(TRUE);
286 void OfonoVoiceCallManager::hangupMultipartyErr(const QDBusError &error)
288 m_if->setError(error.name(), error.message());
289 emit hangupMultipartyComplete(FALSE);
292 void OfonoVoiceCallManager::createMultipartyResp(const QList<QDBusObjectPath> &paths)
295 foreach(QDBusObjectPath path, paths)
296 calls << path.path();
297 emit createMultipartyComplete(TRUE, calls);
300 void OfonoVoiceCallManager::createMultipartyErr(const QDBusError &error)
302 m_if->setError(error.name(), error.message());
303 emit createMultipartyComplete(FALSE, QStringList());
306 void OfonoVoiceCallManager::privateChatResp(const QList<QDBusObjectPath> &paths)
309 foreach(QDBusObjectPath path, paths)
310 calls << path.path();
311 emit privateChatComplete(TRUE, calls);
314 void OfonoVoiceCallManager::privateChatErr(const QDBusError &error)
316 m_if->setError(error.name(), error.message());
317 emit privateChatComplete(FALSE, QStringList());
320 void OfonoVoiceCallManager::holdAndAnswerResp()
322 emit holdAndAnswerComplete(TRUE);
325 void OfonoVoiceCallManager::holdAndAnswerErr(const QDBusError &error)
327 m_if->setError(error.name(), error.message());
328 emit holdAndAnswerComplete(FALSE);
331 void OfonoVoiceCallManager::releaseAndAnswerResp()
333 emit releaseAndAnswerComplete(TRUE);
336 void OfonoVoiceCallManager::releaseAndAnswerErr(const QDBusError &error)
338 m_if->setError(error.name(), error.message());
339 emit releaseAndAnswerComplete(FALSE);
342 void OfonoVoiceCallManager::swapCallsResp()
344 emit swapCallsComplete(TRUE);
347 void OfonoVoiceCallManager::swapCallsErr(const QDBusError &error)
349 m_if->setError(error.name(), error.message());
350 emit swapCallsComplete(FALSE);
353 void OfonoVoiceCallManager::dialResp()
355 emit dialComplete(TRUE);
358 void OfonoVoiceCallManager::dialErr(const QDBusError &error)
360 m_if->setError(error.name(), error.message());
361 emit dialComplete(FALSE);
364 void OfonoVoiceCallManager::hangupAllResp()
366 emit hangupAllComplete(TRUE);
369 void OfonoVoiceCallManager::hangupAllErr(const QDBusError &error)
371 m_if->setError(error.name(), error.message());
372 emit hangupAllComplete(FALSE);
374 void OfonoVoiceCallManager::sendTonesResp()
376 emit sendTonesComplete(TRUE);
379 void OfonoVoiceCallManager::sendTonesErr(const QDBusError &error)
381 m_if->setError(error.name(), error.message());
382 emit sendTonesComplete(FALSE);
385 void OfonoVoiceCallManager::transferResp()
387 emit transferComplete(TRUE);
390 void OfonoVoiceCallManager::transferErr(const QDBusError &error)
392 m_if->setError(error.name(), error.message());
393 emit transferComplete(FALSE);
396 QStringList OfonoVoiceCallManager::emergencyNumbers() const
398 return m_if->properties()["EmergencyNumbers"].value<QStringList>();
401 void OfonoVoiceCallManager::propertyChanged(const QString &property, const QVariant &value)
403 if (property == "EmergencyNumbers") {
404 emit emergencyNumbersChanged(value.value<QStringList>());
408 QStringList OfonoVoiceCallManager::getCalls() const
413 void OfonoVoiceCallManager::callAddedChanged(const QDBusObjectPath &path, const QVariantMap& /*values*/)
415 m_calllist << path.path();
416 emit callAdded(path.path());
419 void OfonoVoiceCallManager::callRemovedChanged(const QDBusObjectPath &path)
421 m_calllist.removeAll(path.path());
422 emit callRemoved(path.path());