Skip to content

Latest commit

 

History

History
437 lines (367 loc) · 11.2 KB

voicecallmanager.cpp

File metadata and controls

437 lines (367 loc) · 11.2 KB
 
Jul 19, 2012
Jul 19, 2012
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* This file is a part of the Voice Call Manager project
*
* Copyright (C) 2011-2012 Tom Swindell <t.swindell@rubyx.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "common.h"
#include "voicecallmanager.h"
#include <QHash>
Jul 28, 2012
Jul 28, 2012
25
#include <QUuid>
May 27, 2019
May 27, 2019
26
27
28
#include <QSettings>
#ifdef WITH_NEMO_DEVICELOCK
Feb 21, 2017
Feb 21, 2017
29
#include <nemo-devicelock/devicelock.h>
May 27, 2019
May 27, 2019
30
#endif
Jul 19, 2012
Jul 19, 2012
31
May 27, 2019
May 27, 2019
32
#ifdef WITH_AUDIOPOLICY
Sep 25, 2012
Sep 25, 2012
33
#include "audiocallpolicyproxy.h"
May 27, 2019
May 27, 2019
34
#endif
Sep 25, 2012
Sep 25, 2012
35
Jul 19, 2012
Jul 19, 2012
36
37
class VoiceCallManagerPrivate
{
Aug 8, 2012
Aug 8, 2012
38
39
Q_DECLARE_PUBLIC(VoiceCallManager)
Jul 19, 2012
Jul 19, 2012
40
public:
Aug 8, 2012
Aug 8, 2012
41
VoiceCallManagerPrivate(VoiceCallManager *q)
Aug 9, 2012
Aug 9, 2012
42
: q_ptr(q), activeVoiceCall(NULL),
Jan 10, 2013
Jan 10, 2013
43
audioMode("earpiece"), isAudioRouted(false), isMicrophoneMuted(false), isSpeakerMuted(false)
Jul 19, 2012
Jul 19, 2012
44
45
{/* ... */}
Aug 8, 2012
Aug 8, 2012
46
VoiceCallManager *q_ptr;
Jul 19, 2012
Jul 19, 2012
47
Aug 5, 2012
Aug 5, 2012
48
49
QHash<QString, AbstractVoiceCallProvider*> providers;
Sep 25, 2012
Sep 25, 2012
50
51
QHash<QString, AbstractVoiceCallHandler*> voiceCalls;
Jul 19, 2012
Jul 19, 2012
52
53
AbstractVoiceCallHandler *activeVoiceCall;
May 27, 2019
May 27, 2019
54
#ifdef WITH_NEMO_DEVICELOCK
Feb 21, 2017
Feb 21, 2017
55
NemoDeviceLock::DeviceLock deviceLock;
May 27, 2019
May 27, 2019
56
57
#endif
Aug 9, 2012
Aug 9, 2012
58
59
60
61
QString audioMode;
bool isAudioRouted;
bool isMicrophoneMuted;
bool isSpeakerMuted;
Jul 19, 2012
Jul 19, 2012
62
63
64
65
66
QString errorString;
};
VoiceCallManager::VoiceCallManager(QObject *parent)
Aug 8, 2012
Aug 8, 2012
67
: VoiceCallManagerInterface(parent), d_ptr(new VoiceCallManagerPrivate(this))
Jul 19, 2012
Jul 19, 2012
68
69
70
71
72
73
74
{
TRACE
}
VoiceCallManager::~VoiceCallManager()
{
TRACE
Sep 25, 2012
Sep 25, 2012
75
delete d_ptr;
Jul 19, 2012
Jul 19, 2012
76
77
78
79
80
}
QString VoiceCallManager::errorString() const
{
TRACE
Aug 8, 2012
Aug 8, 2012
81
Q_D(const VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
82
83
84
85
86
return d->errorString;
}
void VoiceCallManager::setError(const QString &errorString)
{
Aug 8, 2012
Aug 8, 2012
87
88
TRACE
Q_D(VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
89
90
91
92
93
94
95
96
d->errorString = errorString;
qDebug() << d->errorString;
emit this->error(d->errorString);
}
AbstractVoiceCallHandler* VoiceCallManager::activeVoiceCall() const
{
TRACE
Aug 8, 2012
Aug 8, 2012
97
Q_D(const VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
98
99
100
101
102
103
return d->activeVoiceCall;
}
QList<AbstractVoiceCallProvider*> VoiceCallManager::providers() const
{
TRACE
Aug 8, 2012
Aug 8, 2012
104
Q_D(const VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
105
106
107
108
109
110
return d->providers.values();
}
void VoiceCallManager::appendProvider(AbstractVoiceCallProvider *provider)
{
TRACE
Aug 8, 2012
Aug 8, 2012
111
Q_D(VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
112
113
if(d->providers.contains(provider->providerId())) return;
Jan 16, 2019
Jan 16, 2019
114
DEBUG_T("VCM: Registering voice call provider: %s", qPrintable(provider->providerId()));
Jul 19, 2012
Jul 19, 2012
115
116
117
118
119
120
QObject::connect(provider,
SIGNAL(voiceCallAdded(AbstractVoiceCallHandler*)),
SLOT(onVoiceCallAdded(AbstractVoiceCallHandler*)));
QObject::connect(provider,
SIGNAL(voiceCallRemoved(QString)),
SLOT(onVoiceCallRemoved(QString)));
Jun 24, 2013
Jun 24, 2013
121
122
123
QObject::connect(provider,
SIGNAL(error(QString)),
SLOT(setError(QString)));
Jul 19, 2012
Jul 19, 2012
124
125
126
127
d->providers.insert(provider->providerId(), provider);
emit this->providersChanged();
emit this->providerAdded(provider);
Aug 9, 2013
Aug 9, 2013
128
129
130
foreach (AbstractVoiceCallHandler *handler, provider->voiceCalls())
onVoiceCallAdded(handler);
Jul 19, 2012
Jul 19, 2012
131
132
133
134
135
}
void VoiceCallManager::removeProvider(AbstractVoiceCallProvider *provider)
{
TRACE
Aug 8, 2012
Aug 8, 2012
136
Q_D(VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
137
138
if(!d->providers.contains(provider->providerId())) return;
Jan 16, 2019
Jan 16, 2019
139
DEBUG_T("VCM: Deregistering voice call provider: %s", qPrintable(provider->providerId()));
Jul 19, 2012
Jul 19, 2012
140
141
142
143
144
145
146
147
QObject::disconnect(provider,
SIGNAL(voiceCallAdded(AbstractVoiceCallHandler*)),
this,
SLOT(onVoiceCallAdded(AbstractVoiceCallHandler*)));
QObject::disconnect(provider,
SIGNAL(voiceCallRemoved(QString)),
this,
SLOT(onVoiceCallRemoved(QString)));
Jun 24, 2013
Jun 24, 2013
148
149
150
151
QObject::disconnect(provider,
SIGNAL(error(QString)),
this,
SLOT(setError(QString)));
Jul 19, 2012
Jul 19, 2012
152
153
154
155
156
157
d->providers.remove(provider->providerId());
emit this->providersChanged();
emit this->providerRemoved(provider->providerId());
}
Jul 28, 2012
Jul 28, 2012
158
159
160
161
162
163
164
QString VoiceCallManager::generateHandlerId()
{
TRACE
QString handlerId = QUuid::createUuid().toString().mid(1, 36); // Remove curly braces.
return handlerId.replace('-', ""); // Remove dashes, (can't have dashes in dbus paths)
}
Jul 19, 2012
Jul 19, 2012
165
166
167
int VoiceCallManager::voiceCallCount() const
{
TRACE
Aug 8, 2012
Aug 8, 2012
168
Q_D(const VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
169
170
171
172
173
174
175
176
177
178
179
180
181
int result = 0;
foreach(AbstractVoiceCallProvider *provider, d->providers.values())
{
result += provider->voiceCalls().length();
}
return result;
}
QList<AbstractVoiceCallHandler*> VoiceCallManager::voiceCalls() const
{
TRACE
Aug 8, 2012
Aug 8, 2012
182
Q_D(const VoiceCallManager);
Jul 28, 2012
Jul 28, 2012
183
184
185
186
187
188
189
190
QList<AbstractVoiceCallHandler*> results;
foreach(AbstractVoiceCallProvider *provider, d->providers)
{
results.append(provider->voiceCalls());
}
return results;
Jul 19, 2012
Jul 19, 2012
191
192
}
Aug 9, 2012
Aug 9, 2012
193
QString VoiceCallManager::audioMode() const
Aug 5, 2012
Aug 5, 2012
194
195
{
TRACE
Aug 8, 2012
Aug 8, 2012
196
Q_D(const VoiceCallManager);
Aug 9, 2012
Aug 9, 2012
197
return d->audioMode;
Aug 5, 2012
Aug 5, 2012
198
199
}
Aug 9, 2012
Aug 9, 2012
200
bool VoiceCallManager::isAudioRouted() const
Aug 5, 2012
Aug 5, 2012
201
202
{
TRACE
Aug 8, 2012
Aug 8, 2012
203
Q_D(const VoiceCallManager);
Aug 9, 2012
Aug 9, 2012
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
return d->isAudioRouted;
}
bool VoiceCallManager::isMicrophoneMuted() const
{
TRACE
Q_D(const VoiceCallManager);
return d->isMicrophoneMuted;
}
bool VoiceCallManager::isSpeakerMuted() const
{
TRACE
Q_D(const VoiceCallManager);
return d->isSpeakerMuted;
}
void VoiceCallManager::setAudioMode(const QString &mode)
{
TRACE
Q_D(VoiceCallManager);
d->audioMode = mode;
emit this->setAudioModeRequested(mode);
Jan 10, 2013
Jan 10, 2013
227
emit this->audioModeChanged();
Aug 9, 2012
Aug 9, 2012
228
229
230
231
232
233
234
235
}
void VoiceCallManager::setAudioRouted(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->isAudioRouted = on;
emit this->setAudioRoutedRequested(on);
Jan 10, 2013
Jan 10, 2013
236
emit this->audioRoutedChanged();
Aug 5, 2012
Aug 5, 2012
237
238
239
240
241
}
void VoiceCallManager::setMuteMicrophone(bool on)
{
TRACE
Aug 8, 2012
Aug 8, 2012
242
Q_D(VoiceCallManager);
Aug 9, 2012
Aug 9, 2012
243
d->isMicrophoneMuted = on;
Aug 5, 2012
Aug 5, 2012
244
emit this->setMuteMicrophoneRequested(on);
Aug 9, 2012
Aug 9, 2012
245
emit this->microphoneMutedChanged();
Aug 5, 2012
Aug 5, 2012
246
247
}
Aug 9, 2012
Aug 9, 2012
248
void VoiceCallManager::setMuteSpeaker(bool on)
Aug 5, 2012
Aug 5, 2012
249
250
{
TRACE
Aug 8, 2012
Aug 8, 2012
251
Q_D(VoiceCallManager);
Aug 9, 2012
Aug 9, 2012
252
253
254
d->isSpeakerMuted = on;
emit this->setMuteSpeakerRequested(on);
emit this->speakerMutedChanged();
Aug 5, 2012
Aug 5, 2012
255
256
}
Jan 10, 2013
Jan 10, 2013
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
void VoiceCallManager::onAudioModeChanged(const QString &mode)
{
TRACE
Q_D(VoiceCallManager);
d->audioMode = mode;
emit this->audioModeChanged();
}
void VoiceCallManager::onAudioRoutedChanged(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->isAudioRouted = on;
emit this->audioRoutedChanged();
}
void VoiceCallManager::onMuteMicrophoneChanged(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->isMicrophoneMuted = on;
emit this->microphoneMutedChanged();
}
void VoiceCallManager::onMuteSpeakerChanged(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->isSpeakerMuted = on;
emit this->speakerMutedChanged();
}
Jul 19, 2012
Jul 19, 2012
289
290
291
bool VoiceCallManager::dial(const QString &providerId, const QString &msisdn)
{
TRACE
Aug 8, 2012
Aug 8, 2012
292
Q_D(VoiceCallManager);
Jul 19, 2012
Jul 19, 2012
293
294
295
296
297
298
299
300
AbstractVoiceCallProvider *provider = d->providers.value(providerId);
if(!provider)
{
this->setError(QString("*** Unable to find voice call provider with id: ") + providerId);
return false;
}
Jun 24, 2013
Jun 24, 2013
301
return provider->dial(msisdn);
Jul 19, 2012
Jul 19, 2012
302
303
}
Nov 14, 2012
Nov 14, 2012
304
305
306
307
308
309
void VoiceCallManager::silenceRingtone()
{
TRACE
emit this->silenceRingtoneRequested();
}
Jul 20, 2012
Jul 20, 2012
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
void VoiceCallManager::startEventTone(ToneType type, int volume)
{
TRACE
emit this->startEventToneRequested(type, volume);
}
void VoiceCallManager::stopEventTone()
{
TRACE
emit this->stopEventToneRequested();
}
void VoiceCallManager::startDtmfTone(const QString &tone, int volume)
{
TRACE
emit this->startDtmfToneRequested(tone, volume);
}
void VoiceCallManager::stopDtmfTone()
{
TRACE
emit this->stopDtmfToneRequested();
}
Jul 19, 2012
Jul 19, 2012
334
335
336
void VoiceCallManager::onVoiceCallAdded(AbstractVoiceCallHandler *handler)
{
TRACE
Aug 8, 2012
Aug 8, 2012
337
338
Q_D(VoiceCallManager);
May 27, 2019
May 27, 2019
339
#ifdef WITH_NEMO_DEVICELOCK
Feb 21, 2017
Feb 21, 2017
340
341
if (!handler->isEmergency()
&& d->deviceLock.state() == NemoDeviceLock::DeviceLock::ManagerLockout) {
May 27, 2019
May 27, 2019
342
343
344
#else
if (!handler->isEmergency()) {
#endif
Feb 21, 2017
Feb 21, 2017
345
346
347
348
349
handler->hangup();
return;
}
Jan 23, 2013
Jan 23, 2013
350
351
//AudioCallPolicyProxy *pHandler = new AudioCallPolicyProxy(handler, this);
d->voiceCalls.insert(handler->handlerId(), handler);
Aug 9, 2012
Aug 9, 2012
352
Jan 23, 2013
Jan 23, 2013
353
emit this->voiceCallAdded(handler);
Jul 19, 2012
Jul 19, 2012
354
emit this->voiceCallsChanged();
Aug 8, 2012
Aug 8, 2012
355
Jul 19, 2012
Jul 19, 2012
356
357
if(!d->activeVoiceCall)
{
Jan 23, 2013
Jan 23, 2013
358
d->activeVoiceCall = handler;
Jul 19, 2012
Jul 19, 2012
359
360
361
362
363
364
365
emit this->activeVoiceCallChanged();
}
}
void VoiceCallManager::onVoiceCallRemoved(const QString &handlerId)
{
TRACE
Aug 8, 2012
Aug 8, 2012
366
Q_D(VoiceCallManager);
Jan 23, 2013
Jan 23, 2013
367
AbstractVoiceCallHandler *handler = d->voiceCalls.value(handlerId);
Aug 5, 2013
Aug 5, 2013
368
if (!handler) {
Jan 16, 2019
Jan 16, 2019
369
DEBUG_T("VCM: attempt to remove unregistered handler: %s", qPrintable(handlerId));
Aug 5, 2013
Aug 5, 2013
370
371
return;
}
Nov 30, 2012
Nov 30, 2012
372
373
d->voiceCalls.remove(handlerId);
Jul 19, 2012
Jul 19, 2012
374
emit this->voiceCallRemoved(handlerId);
Jul 19, 2012
Jul 19, 2012
375
emit this->voiceCallsChanged();
Aug 8, 2012
Aug 8, 2012
376
Jul 11, 2013
Jul 11, 2013
377
if (d->activeVoiceCall && d->activeVoiceCall->handlerId() == handlerId)
Jul 19, 2012
Jul 19, 2012
378
379
380
381
{
d->activeVoiceCall = NULL;
emit this->activeVoiceCallChanged();
}
Sep 25, 2012
Sep 25, 2012
382
Jul 1, 2013
Jul 1, 2013
383
384
385
386
387
388
389
QSettings settings;
settings.beginGroup(QLatin1String("Voice Counters"));
// Update call time statistics
if (handler->isIncoming()) {
int received = settings.value(QLatin1String("Received")).toInt();
received += handler->duration();
Jan 16, 2019
Jan 16, 2019
390
DEBUG_T("Incoming call ended. Total incoming duration is now %d", received);
Jul 1, 2013
Jul 1, 2013
391
392
393
394
395
settings.setValue(QLatin1String("Received"), received);
emit totalIncomingCallDurationChanged();
} else {
int dialled = settings.value(QLatin1String("Dialled")).toInt();
dialled += handler->duration();
Jan 16, 2019
Jan 16, 2019
396
DEBUG_T("Outgoing call ended. Total outgoing duration is now %d", dialled);
Jul 1, 2013
Jul 1, 2013
397
398
399
400
401
402
settings.setValue(QLatin1String("Dialled"), dialled);
emit totalOutgoingCallDurationChanged();
}
settings.endGroup();
Jan 23, 2013
Jan 23, 2013
403
handler->deleteLater();
Jul 19, 2012
Jul 19, 2012
404
}
Nov 30, 2012
Nov 30, 2012
405
Jul 1, 2013
Jul 1, 2013
406
407
408
409
410
int VoiceCallManager::totalOutgoingCallDuration() const
{
QSettings settings;
settings.beginGroup(QLatin1String("Voice Counters"));
int dialled = settings.value(QLatin1String("Dialled")).toInt();
Jan 16, 2019
Jan 16, 2019
411
DEBUG_T("Request for outgoing call duration. Total: %d", dialled);
Jul 1, 2013
Jul 1, 2013
412
413
414
415
416
417
418
419
return dialled;
}
int VoiceCallManager::totalIncomingCallDuration() const
{
QSettings settings;
settings.beginGroup(QLatin1String("Voice Counters"));
int received = settings.value(QLatin1String("Received")).toInt();
Jan 16, 2019
Jan 16, 2019
420
DEBUG_T("Request for incoming call duration. Total: %d", received);
Jul 1, 2013
Jul 1, 2013
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
return received;
}
void VoiceCallManager::resetCallDurationCounters()
{
{
QSettings settings;
settings.beginGroup(QLatin1String("Voice Counters"));
settings.setValue(QLatin1String("Received"), 0);
settings.setValue(QLatin1String("Dialled"), 0);
settings.endGroup();
}
emit totalOutgoingCallDurationChanged();
emit totalIncomingCallDurationChanged();
}