~ubuntu-branches/ubuntu/vivid/ofono-qt/vivid

« back to all changes in this revision

Viewing changes to .pc/04-set_errors_on_dial_and_sendMessage.patch/lib/ofonovoicecallmanager.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2013-06-04 06:39:51 UTC
  • Revision ID: package-import@ubuntu.com-20130604063951-2v4g0yyx0pey2sg5
Tags: 1.5+git20120419+bcf0c04-0ubuntu1
Initial release for Ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of ofono-qt
 
3
 *
 
4
 * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
 
7
 *
 
8
 * Portions of this file are Copyright (C) 2011 Intel Corporation
 
9
 * Contact: Shane Bryan <shane.bryan@linux.intel.com>
 
10
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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
 
23
 * 02110-1301 USA
 
24
 *
 
25
 */
 
26
 
 
27
#include <QtDBus/QtDBus>
 
28
#include <QtCore/QObject>
 
29
 
 
30
#include "ofonovoicecallmanager.h"
 
31
#include "ofonointerface.h"
 
32
 
 
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
 
41
 
 
42
QDBusArgument &operator<<(QDBusArgument &argument, const OfonoVoiceCallManagerStruct &call)
 
43
{
 
44
    argument.beginStructure();
 
45
    argument << call.path << call.properties;
 
46
    argument.endStructure();
 
47
    return argument;
 
48
}
 
49
 
 
50
const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoVoiceCallManagerStruct &call)
 
51
{
 
52
    argument.beginStructure();
 
53
    argument >> call.path >> call.properties;
 
54
    argument.endStructure();
 
55
    return argument;
 
56
}
 
57
 
 
58
OfonoVoiceCallManager::OfonoVoiceCallManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
 
59
    : OfonoModemInterface(modemSetting, modemPath, "org.ofono.VoiceCallManager", OfonoGetAllOnStartup, parent)
 
60
{
 
61
    qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
 
62
    qDBusRegisterMetaType<OfonoVoiceCallManagerList>();
 
63
 
 
64
    m_calllist = getCallList();
 
65
 
 
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&)));
 
71
 
 
72
    connectDbusSignals(path());
 
73
}
 
74
 
 
75
OfonoVoiceCallManager::~OfonoVoiceCallManager()
 
76
{
 
77
}
 
78
 
 
79
 
 
80
void OfonoVoiceCallManager::validityChanged(bool /*validity*/)
 
81
{
 
82
    m_calllist = getCallList();
 
83
}
 
84
 
 
85
void OfonoVoiceCallManager::pathChanged(const QString& path)
 
86
{
 
87
    connectDbusSignals(path);
 
88
}
 
89
 
 
90
QStringList OfonoVoiceCallManager::getCallList()
 
91
{
 
92
    QDBusReply<OfonoVoiceCallManagerList> reply;
 
93
    OfonoVoiceCallManagerList calls;
 
94
 
 
95
    QDBusMessage request;
 
96
    QStringList messageList;
 
97
 
 
98
    qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
 
99
    qDBusRegisterMetaType<OfonoVoiceCallManagerList>();
 
100
 
 
101
    request = QDBusMessage::createMethodCall("org.ofono",
 
102
                                             path(), m_if->ifname(),
 
103
                                             "GetCalls");
 
104
    reply = QDBusConnection::systemBus().call(request);
 
105
 
 
106
    calls = reply;
 
107
    foreach(OfonoVoiceCallManagerStruct call, calls) {
 
108
        messageList<< call.path.path();
 
109
    }
 
110
    return messageList;
 
111
}
 
112
 
 
113
void OfonoVoiceCallManager::connectDbusSignals(const QString& path)
 
114
{
 
115
    QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
 
116
                                         "CallAdded", this,
 
117
                                         SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&)));
 
118
    QDBusConnection::systemBus().disconnect("org.ofono", QString(), m_if->ifname(),
 
119
                                         "CallRemoved", this,
 
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(), 
 
125
                                        "Forwarded", this,
 
126
                                        SIGNAL(forwarded(const QString&)));
 
127
 
 
128
    QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
 
129
                                         "CallAdded", this,
 
130
                                         SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&)));
 
131
    QDBusConnection::systemBus().connect("org.ofono", path, m_if->ifname(),
 
132
                                         "CallRemoved", this,
 
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(), 
 
138
                                        "Forwarded", this,
 
139
                                        SIGNAL(forwarded(const QString&)));
 
140
}
 
141
 
 
142
QDBusObjectPath OfonoVoiceCallManager::dial(const QString &number, const QString &callerid_hide)
 
143
{
 
144
    QDBusMessage request;
 
145
    QDBusReply<QDBusObjectPath> reply;
 
146
    QDBusObjectPath objpath;
 
147
    request = QDBusMessage::createMethodCall("org.ofono",
 
148
                                             path(), m_if->ifname(),
 
149
                                             "Dial");
 
150
    QList<QVariant>arg;
 
151
    arg.append(QVariant(number));
 
152
    arg.append(QVariant(callerid_hide));
 
153
    request.setArguments(arg);
 
154
 
 
155
    reply = QDBusConnection::systemBus().call(request);
 
156
    if (reply.isValid()) {
 
157
        objpath = reply;
 
158
    }
 
159
    return objpath;
 
160
}
 
161
 
 
162
void OfonoVoiceCallManager::hangupAll()
 
163
{
 
164
    QDBusMessage request;
 
165
    request = QDBusMessage::createMethodCall("org.ofono",
 
166
                                             path(), m_if->ifname(),
 
167
                                             "HangupAll");
 
168
 
 
169
    QDBusConnection::systemBus().callWithCallback(request, this,
 
170
                                        SLOT(hangupAllResp()),
 
171
                                        SLOT(hangupAllErr(const QDBusError&)),
 
172
                                        HANGUP_TIMEOUT);
 
173
}
 
174
 
 
175
void OfonoVoiceCallManager::sendTones(const QString &tonestring)
 
176
{
 
177
    QDBusMessage request;
 
178
    request = QDBusMessage::createMethodCall("org.ofono",
 
179
                                             path(), m_if->ifname(),
 
180
                                             "SendTones");
 
181
    QList<QVariant>arg;
 
182
    arg.append(QVariant(tonestring));
 
183
    request.setArguments(arg);
 
184
 
 
185
    QDBusConnection::systemBus().callWithCallback(request, this,
 
186
                                        SLOT(sendTonesResp()),
 
187
                                        SLOT(sendTonesErr(const QDBusError&)),
 
188
                                        (TONE_TIMEOUT*tonestring.length()));
 
189
}
 
190
 
 
191
void OfonoVoiceCallManager::transfer()
 
192
{
 
193
    QDBusMessage request;
 
194
    request = QDBusMessage::createMethodCall("org.ofono",
 
195
                                             path(), m_if->ifname(),
 
196
                                             "Transfer");
 
197
 
 
198
    QDBusConnection::systemBus().callWithCallback(request, this,
 
199
                                        SLOT(transferResp()),
 
200
                                        SLOT(transferErr(const QDBusError&)),
 
201
                                        TRANSFER_TIMEOUT);
 
202
}
 
203
 
 
204
void OfonoVoiceCallManager::swapCalls()
 
205
{
 
206
    QDBusMessage request;
 
207
    request = QDBusMessage::createMethodCall("org.ofono",
 
208
                                             path(), m_if->ifname(),
 
209
                                             "SwapCalls");
 
210
 
 
211
    QDBusConnection::systemBus().callWithCallback(request, this,
 
212
                                        SLOT(swapCallsResp()),
 
213
                                        SLOT(swapCallsErr(const QDBusError&)),
 
214
                                        SWAP_TIMEOUT);
 
215
}
 
216
 
 
217
void OfonoVoiceCallManager::releaseAndAnswer()
 
218
{
 
219
    QDBusMessage request;
 
220
    request = QDBusMessage::createMethodCall("org.ofono",
 
221
                                             path(), m_if->ifname(),
 
222
                                             "ReleaseAndAnswer");
 
223
 
 
224
    QDBusConnection::systemBus().callWithCallback(request, this,
 
225
                                        SLOT(releaseAndAnswerResp()),
 
226
                                        SLOT(releaseAndAnswerErr(const QDBusError&)),
 
227
                                        HANGUP_TIMEOUT);
 
228
}
 
229
 
 
230
void OfonoVoiceCallManager::holdAndAnswer()
 
231
{
 
232
    QDBusMessage request;
 
233
    request = QDBusMessage::createMethodCall("org.ofono",
 
234
                                             path(), m_if->ifname(),
 
235
                                             "HoldAndAnswer");
 
236
 
 
237
    QDBusConnection::systemBus().callWithCallback(request, this,
 
238
                                        SLOT(holdAndAnswerResp()),
 
239
                                        SLOT(holdAndAnswerErr(const QDBusError&)),
 
240
                                        HOLD_TIMEOUT);
 
241
}
 
242
 
 
243
void OfonoVoiceCallManager::privateChat(const QString &call)
 
244
{
 
245
    QDBusMessage request;
 
246
    request = QDBusMessage::createMethodCall("org.ofono",
 
247
                                             path(), m_if->ifname(),
 
248
                                             "PrivateChat");
 
249
 
 
250
    QList<QVariant>arg;
 
251
    arg.append(qVariantFromValue(QDBusObjectPath(call)));
 
252
    request.setArguments(arg);
 
253
    QDBusConnection::systemBus().callWithCallback(request, this,
 
254
                                        SLOT(privateChatResp(const QList<QDBusObjectPath>&)),
 
255
                                        SLOT(privateChatErr(const QDBusError&)),
 
256
                                        PRIVATE_CHAT_TIMEOUT);
 
257
}
 
258
 
 
259
void OfonoVoiceCallManager::createMultiparty()
 
260
{
 
261
    QDBusMessage request;
 
262
    request = QDBusMessage::createMethodCall("org.ofono",
 
263
                                             path(), m_if->ifname(),
 
264
                                             "CreateMultiparty");
 
265
 
 
266
    QDBusConnection::systemBus().callWithCallback(request, this,
 
267
                                        SLOT(createMultipartyResp(const QList<QDBusObjectPath>&)),
 
268
                                        SLOT(createMultipartyErr(const QDBusError&)),
 
269
                                        CREATE_MULTIPARTY_TIMEOUT);
 
270
}
 
271
 
 
272
void OfonoVoiceCallManager::hangupMultiparty()
 
273
{
 
274
    QDBusMessage request;
 
275
    request = QDBusMessage::createMethodCall("org.ofono",
 
276
                                             path(), m_if->ifname(),
 
277
                                             "HangupMultiparty");
 
278
 
 
279
    QDBusConnection::systemBus().callWithCallback(request, this,
 
280
                                        SLOT(hangupMultipartyResp()),
 
281
                                        SLOT(hangupMultipartyErr(const QDBusError&)),
 
282
                                        HANGUP_TIMEOUT);
 
283
}
 
284
 
 
285
void OfonoVoiceCallManager::hangupMultipartyResp()
 
286
{
 
287
    emit hangupMultipartyComplete(true);
 
288
}
 
289
 
 
290
void OfonoVoiceCallManager::hangupMultipartyErr(const QDBusError &error)
 
291
{
 
292
    m_if->setError(error.name(), error.message());
 
293
    emit hangupMultipartyComplete(false);
 
294
}
 
295
 
 
296
void OfonoVoiceCallManager::createMultipartyResp(const QList<QDBusObjectPath> &paths)
 
297
{
 
298
    QStringList calls;
 
299
    foreach(QDBusObjectPath path, paths)
 
300
        calls << path.path();
 
301
    emit createMultipartyComplete(true, calls);
 
302
}
 
303
 
 
304
void OfonoVoiceCallManager::createMultipartyErr(const QDBusError &error)
 
305
{
 
306
    m_if->setError(error.name(), error.message());
 
307
    emit createMultipartyComplete(false, QStringList());
 
308
}
 
309
 
 
310
void OfonoVoiceCallManager::privateChatResp(const QList<QDBusObjectPath> &paths)
 
311
{
 
312
    QStringList calls;
 
313
    foreach(QDBusObjectPath path, paths)
 
314
        calls << path.path();
 
315
    emit privateChatComplete(true, calls);
 
316
}
 
317
 
 
318
void OfonoVoiceCallManager::privateChatErr(const QDBusError &error)
 
319
{
 
320
    m_if->setError(error.name(), error.message());
 
321
    emit privateChatComplete(false, QStringList());
 
322
}
 
323
 
 
324
void OfonoVoiceCallManager::holdAndAnswerResp()
 
325
{
 
326
    emit holdAndAnswerComplete(true);
 
327
}
 
328
 
 
329
void OfonoVoiceCallManager::holdAndAnswerErr(const QDBusError &error)
 
330
{
 
331
    m_if->setError(error.name(), error.message());
 
332
    emit holdAndAnswerComplete(false);
 
333
}
 
334
 
 
335
void OfonoVoiceCallManager::releaseAndAnswerResp()
 
336
{
 
337
    emit releaseAndAnswerComplete(true);
 
338
}
 
339
 
 
340
void OfonoVoiceCallManager::releaseAndAnswerErr(const QDBusError &error)
 
341
{
 
342
    m_if->setError(error.name(), error.message());
 
343
    emit releaseAndAnswerComplete(false);
 
344
}
 
345
 
 
346
void OfonoVoiceCallManager::swapCallsResp()
 
347
{
 
348
    emit swapCallsComplete(true);
 
349
}
 
350
 
 
351
void OfonoVoiceCallManager::swapCallsErr(const QDBusError &error)
 
352
{
 
353
    m_if->setError(error.name(), error.message());
 
354
    emit swapCallsComplete(false);
 
355
}
 
356
 
 
357
void OfonoVoiceCallManager::dialResp()
 
358
{
 
359
    emit dialComplete(true);
 
360
}
 
361
 
 
362
void OfonoVoiceCallManager::dialErr(const QDBusError &error)
 
363
{
 
364
    m_if->setError(error.name(), error.message());
 
365
    emit dialComplete(false);
 
366
}
 
367
 
 
368
void OfonoVoiceCallManager::hangupAllResp()
 
369
{
 
370
    emit hangupAllComplete(true);
 
371
}
 
372
 
 
373
void OfonoVoiceCallManager::hangupAllErr(const QDBusError &error)
 
374
{
 
375
    m_if->setError(error.name(), error.message());
 
376
    emit hangupAllComplete(false);
 
377
}
 
378
void OfonoVoiceCallManager::sendTonesResp()
 
379
{
 
380
    emit sendTonesComplete(true);
 
381
}
 
382
 
 
383
void OfonoVoiceCallManager::sendTonesErr(const QDBusError &error)
 
384
{
 
385
    m_if->setError(error.name(), error.message());
 
386
    emit sendTonesComplete(false);
 
387
}
 
388
 
 
389
void OfonoVoiceCallManager::transferResp()
 
390
{
 
391
    emit transferComplete(true);
 
392
}
 
393
 
 
394
void OfonoVoiceCallManager::transferErr(const QDBusError &error)
 
395
{
 
396
    m_if->setError(error.name(), error.message());
 
397
    emit transferComplete(false);
 
398
}
 
399
 
 
400
QStringList OfonoVoiceCallManager::emergencyNumbers() const
 
401
{
 
402
    return m_if->properties()["EmergencyNumbers"].value<QStringList>();
 
403
}
 
404
 
 
405
void OfonoVoiceCallManager::propertyChanged(const QString &property, const QVariant &value)
 
406
{
 
407
    if (property == "EmergencyNumbers") {       
 
408
        emit emergencyNumbersChanged(value.value<QStringList>());
 
409
    }
 
410
}
 
411
 
 
412
QStringList OfonoVoiceCallManager::getCalls() const
 
413
{
 
414
    return m_calllist;
 
415
}
 
416
 
 
417
void OfonoVoiceCallManager::callAddedChanged(const QDBusObjectPath &path, const QVariantMap& values)
 
418
{
 
419
    m_calllist << path.path();
 
420
    emit callAdded(path.path(), values);
 
421
}
 
422
 
 
423
void OfonoVoiceCallManager::callRemovedChanged(const QDBusObjectPath &path)
 
424
{
 
425
    m_calllist.removeAll(path.path());
 
426
    emit callRemoved(path.path());
 
427
}