~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to kde/src/lib/callmodel.hpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2009-2013 by Savoir-Faire Linux                          *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
5
 *   This library is free software; you can redistribute it and/or          *
 
6
 *   modify it under the terms of the GNU Lesser General Public             *
 
7
 *   License as published by the Free Software Foundation; either           *
 
8
 *   version 2.1 of the License, or (at your option) any later version.     *
 
9
 *                                                                          *
 
10
 *   This library is distributed in the hope that it will be useful,        *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 
13
 *   Lesser General Public License for more details.                        *
 
14
 *                                                                          *
 
15
 *   You should have received a copy of the GNU General Public License      *
 
16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 
17
 ***************************************************************************/
 
18
 
 
19
//Qt
 
20
#include <QtCore/QHash>
 
21
#include <QtCore/QDebug>
 
22
#include <QtGui/QDragEnterEvent>
 
23
 
 
24
//SFLPhone library
 
25
#include "call.h"
 
26
#include "accountlist.h"
 
27
#include "dbus/metatypes.h"
 
28
#include "callmanager_interface_singleton.h"
 
29
#include "configurationmanager_interface_singleton.h"
 
30
#include "instance_interface_singleton.h"
 
31
#include "sflphone_const.h"
 
32
#include "typedefs.h"
 
33
#include "contactbackend.h"
 
34
 
 
35
//System
 
36
#include "unistd.h"
 
37
 
 
38
//Define
 
39
#define CALLMODEL_TEMPLATE template<typename CallWidget, typename Index>
 
40
#define CALLMODEL_T CallModel<CallWidget,Index>
 
41
 
 
42
//Static member
 
43
CALLMODEL_TEMPLATE bool         CALLMODEL_T::m_sInstanceInit        = false     ;
 
44
CALLMODEL_TEMPLATE bool         CALLMODEL_T::m_sCallInit            = false     ;
 
45
CALLMODEL_TEMPLATE CallMap      CALLMODEL_T::m_lConfList            = CallMap() ;
 
46
 
 
47
CALLMODEL_TEMPLATE typename CALLMODEL_T::InternalCall   CALLMODEL_T::m_sPrivateCallList_call   ;
 
48
CALLMODEL_TEMPLATE typename CALLMODEL_T::InternalCallId CALLMODEL_T::m_sPrivateCallList_callId ;
 
49
CALLMODEL_TEMPLATE typename CALLMODEL_T::InternalIndex  CALLMODEL_T::m_sPrivateCallList_index  ;
 
50
CALLMODEL_TEMPLATE typename CALLMODEL_T::InternalWidget CALLMODEL_T::m_sPrivateCallList_widget ;
 
51
 
 
52
/*****************************************************************************
 
53
 *                                                                           *
 
54
 *                               Constructor                                 *
 
55
 *                                                                           *
 
56
 ****************************************************************************/
 
57
 
 
58
///Retrieve current and older calls from the daemon, fill history and the calls TreeView and enable drag n' drop
 
59
CALLMODEL_TEMPLATE CALLMODEL_T::CallModel() : CallModelBase(0)
 
60
{
 
61
   init();
 
62
}
 
63
 
 
64
///Static destructor
 
65
CALLMODEL_TEMPLATE void CALLMODEL_T::destroy()
 
66
{
 
67
   foreach (Call* call,  m_sPrivateCallList_call.keys()) {
 
68
      delete call;
 
69
   }
 
70
   foreach (InternalStruct* s,  m_sPrivateCallList_call.values()) {
 
71
      delete s;
 
72
   }
 
73
   m_sPrivateCallList_call.clear  ();
 
74
   m_sPrivateCallList_callId.clear();
 
75
   m_sPrivateCallList_widget.clear();
 
76
   m_sPrivateCallList_index.clear ();
 
77
}
 
78
 
 
79
///Destructor
 
80
CALLMODEL_TEMPLATE CALLMODEL_T::~CallModel()
 
81
{
 
82
   
 
83
}
 
84
 
 
85
///Open the connection to the daemon and register this client
 
86
CALLMODEL_TEMPLATE bool CALLMODEL_T::init()
 
87
{
 
88
   if (!m_sInstanceInit)
 
89
      registerCommTypes();
 
90
   m_sInstanceInit = true;
 
91
   return true;
 
92
} //init
 
93
 
 
94
///Fill the call list
 
95
///@warning This solution wont scale to multiple call or history model implementation. Some static addCall + foreach for each call would be needed if this case ever become unavoidable
 
96
CALLMODEL_TEMPLATE bool CALLMODEL_T::initCall()
 
97
{
 
98
   if (!m_sCallInit) {
 
99
      CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
100
      const QStringList callList = callManager.getCallList();
 
101
      foreach (const QString& callId, callList) {
 
102
         Call* tmpCall = Call::buildExistingCall(callId);
 
103
         m_sActiveCalls[tmpCall->getCallId()] = tmpCall;
 
104
         addCall(tmpCall);
 
105
      }
 
106
 
 
107
      const QStringList confList = callManager.getConferenceList();
 
108
      foreach (const QString& confId, confList) {
 
109
         CallModelBase::addConferenceS(addConference(confId));
 
110
      }
 
111
   }
 
112
   m_sCallInit = true;
 
113
   return true;
 
114
} //initCall
 
115
 
 
116
 
 
117
/*****************************************************************************
 
118
 *                                                                           *
 
119
 *                         Access related functions                          *
 
120
 *                                                                           *
 
121
 ****************************************************************************/
 
122
 
 
123
///Return the active call count
 
124
CALLMODEL_TEMPLATE int CALLMODEL_T::size()
 
125
{
 
126
   return m_sActiveCalls.size();
 
127
}
 
128
 
 
129
///Return a call corresponding to this ID or NULL
 
130
CALLMODEL_TEMPLATE Call* CALLMODEL_T::findCallByCallId(const QString& callId)
 
131
{
 
132
   return m_sActiveCalls[callId];
 
133
}
 
134
 
 
135
///Return the action call list
 
136
CALLMODEL_TEMPLATE CallList CALLMODEL_T::getCallList()
 
137
{
 
138
   CallList callList;
 
139
   foreach(Call* call, m_sActiveCalls) {
 
140
      if (dynamic_cast<Call*>(call) && call->getState() != CALL_STATE_OVER) //Prevent a race
 
141
         callList.push_back(call);
 
142
   }
 
143
   return callList;
 
144
}
 
145
 
 
146
///Return all conferences
 
147
CALLMODEL_TEMPLATE CallList CALLMODEL_T::getConferenceList()
 
148
{
 
149
   CallList confList;
 
150
 
 
151
   //That way it can not be invalid
 
152
   const QStringList confListS = CallManagerInterfaceSingleton::getInstance().getConferenceList();
 
153
   foreach (const QString& confId, confListS) {
 
154
      if (m_lConfList[confId] != nullptr)
 
155
         confList << m_lConfList[confId];
 
156
      else
 
157
         confList << addConference(confId);
 
158
   }
 
159
   return confList;
 
160
}
 
161
 
 
162
 
 
163
/*****************************************************************************
 
164
 *                                                                           *
 
165
 *                            Call related code                              *
 
166
 *                                                                           *
 
167
 ****************************************************************************/
 
168
 
 
169
///Add a call in the model structure, the call must exist before being added to the model
 
170
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addCall(Call* call, Call* parent)
 
171
{
 
172
   Q_UNUSED(parent)
 
173
   if (!call)
 
174
      return new Call("",""); //Invalid, but better than managing NULL everywhere
 
175
 
 
176
   InternalStruct* aNewStruct = new InternalStruct;
 
177
   aNewStruct->call_real  = call;
 
178
   aNewStruct->conference = false;
 
179
   
 
180
   m_sPrivateCallList_call  [ call              ] = aNewStruct;
 
181
   m_sPrivateCallList_callId[ call->getCallId() ] = aNewStruct;
 
182
 
 
183
   //setCurrentItem(callItem);
 
184
   CallModelBase::addCall(call,parent);
 
185
   return call;
 
186
}
 
187
 
 
188
///Common set of instruction shared by all call adder
 
189
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addCallCommon(Call* call)
 
190
{
 
191
   m_sActiveCalls[call->getCallId()] = call;
 
192
   addCall(call);
 
193
   return call;
 
194
} //addCallCommon
 
195
 
 
196
///Create a new dialing call from peer name and the account ID
 
197
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addDialingCall(const QString& peerName, Account* account)
 
198
{
 
199
   Account* acc = (account)?account:AccountList::getCurrentAccount();
 
200
   if (acc) {
 
201
      Call* call = Call::buildDialingCall(generateCallId(), peerName, acc->getAccountId());
 
202
      return addCallCommon(call);
 
203
   }
 
204
   else {
 
205
      return nullptr;
 
206
   }
 
207
}  //addDialingCall
 
208
 
 
209
///Create a new incoming call when the daemon is being called
 
210
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addIncomingCall(const QString& callId)
 
211
{
 
212
   Call* call = Call::buildIncomingCall(callId);
 
213
   Call* call2 = addCallCommon(call);
 
214
   //Call without account is not possible
 
215
   if (dynamic_cast<Account*>(call2->getAccount())) {
 
216
      if (call2 && call2->getAccount()->isAutoAnswer()) {
 
217
         call2->actionPerformed(CALL_ACTION_ACCEPT);
 
218
      }
 
219
   }
 
220
   else {
 
221
      qDebug() << "Incoming call from an invalid account";
 
222
      throw "Invalid account";
 
223
   }
 
224
   return call2;
 
225
}
 
226
 
 
227
///Create a ringing call
 
228
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addRingingCall(const QString& callId)
 
229
{
 
230
   Call* call = Call::buildRingingCall(callId);
 
231
   return addCallCommon(call);
 
232
}
 
233
 
 
234
///Generate a new random call unique identifier (callId)
 
235
CALLMODEL_TEMPLATE QString CALLMODEL_T::generateCallId()
 
236
{
 
237
   int id = qrand();
 
238
   return QString::number(id);
 
239
}
 
240
 
 
241
///Remove a call and update the internal structure
 
242
CALLMODEL_TEMPLATE void CALLMODEL_T::removeCall(Call* call)
 
243
{
 
244
   InternalStruct* internal = m_sPrivateCallList_call[call];
 
245
 
 
246
   if (!internal) {
 
247
      qDebug() << "Cannot remove call: call not found";
 
248
      return;
 
249
   }
 
250
 
 
251
   if (m_sPrivateCallList_call[call] != nullptr) {
 
252
      m_sPrivateCallList_call.remove(call);
 
253
   }
 
254
 
 
255
   if (m_sPrivateCallList_callId[m_sPrivateCallList_callId.key(internal)] == internal) {
 
256
      m_sPrivateCallList_callId.remove(m_sPrivateCallList_callId.key(internal));
 
257
   }
 
258
 
 
259
   if (m_sPrivateCallList_widget[m_sPrivateCallList_widget.key(internal)] == internal) {
 
260
      m_sPrivateCallList_widget.remove(m_sPrivateCallList_widget.key(internal));
 
261
   }
 
262
 
 
263
   if (m_sPrivateCallList_index[m_sPrivateCallList_index.key(internal)] == internal) {
 
264
      m_sPrivateCallList_index.remove(m_sPrivateCallList_index.key(internal));
 
265
   }
 
266
} //removeCall
 
267
 
 
268
///Transfer "toTransfer" to "target" and wait to see it it succeeded
 
269
CALLMODEL_TEMPLATE void CALLMODEL_T::attendedTransfer(Call* toTransfer, Call* target)
 
270
{
 
271
   CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
272
   Q_NOREPLY callManager.attendedTransfer(toTransfer->getCallId(),target->getCallId());
 
273
 
 
274
   //TODO [Daemon] Implement this correctly
 
275
   toTransfer->changeCurrentState(CALL_STATE_OVER);
 
276
   target->changeCurrentState(CALL_STATE_OVER);
 
277
} //attendedTransfer
 
278
 
 
279
///Transfer this call to  "target" number
 
280
CALLMODEL_TEMPLATE void CALLMODEL_T::transfer(Call* toTransfer, QString target)
 
281
{
 
282
   qDebug() << "Transferring call " << toTransfer->getCallId() << "to" << target;
 
283
   toTransfer->setTransferNumber ( target                 );
 
284
   toTransfer->changeCurrentState( CALL_STATE_TRANSFERRED );
 
285
   toTransfer->actionPerformed   ( CALL_ACTION_TRANSFER   );
 
286
   toTransfer->changeCurrentState( CALL_STATE_OVER        );
 
287
} //transfer
 
288
 
 
289
/*****************************************************************************
 
290
 *                                                                           *
 
291
 *                         Conference related code                           *
 
292
 *                                                                           *
 
293
 ****************************************************************************/
 
294
 
 
295
///Add a new conference, get the call list and update the interface as needed
 
296
CALLMODEL_TEMPLATE Call* CALLMODEL_T::addConference(const QString & confID)
 
297
{
 
298
   qDebug() << "Notified of a new conference " << confID;
 
299
   CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
300
   const QStringList callList = callManager.getParticipantList(confID);
 
301
   qDebug() << "Paticiapants are:" << callList;
 
302
 
 
303
   if (!callList.size()) {
 
304
      qDebug() << "This conference (" + confID + ") contain no call";
 
305
      return 0;
 
306
   }
 
307
 
 
308
   if (!m_sPrivateCallList_callId[callList[0]]) {
 
309
      qDebug() << "Invalid call";
 
310
      return 0;
 
311
   }
 
312
 
 
313
   Call* newConf = nullptr;
 
314
   if (m_sPrivateCallList_callId[callList[0]]->call_real->getAccount())
 
315
      newConf =  new Call(confID, m_sPrivateCallList_callId[callList[0]]->call_real->getAccount()->getAccountId());
 
316
 
 
317
   if (newConf) {
 
318
      InternalStruct* aNewStruct = new InternalStruct;
 
319
      aNewStruct->call_real  = newConf;
 
320
      aNewStruct->conference = true;
 
321
 
 
322
      m_sPrivateCallList_call[newConf]  = aNewStruct;
 
323
      m_sPrivateCallList_callId[confID] = aNewStruct;
 
324
 
 
325
      m_lConfList[newConf->getConfId()] = newConf   ;
 
326
   }
 
327
   return newConf;
 
328
} //addConference
 
329
 
 
330
///Join two call to create a conference, the conference will be created later (see addConference)
 
331
CALLMODEL_TEMPLATE bool CALLMODEL_T::createConferenceFromCall(Call* call1, Call* call2)
 
332
{
 
333
  qDebug() << "Joining call: " << call1->getCallId() << " and " << call2->getCallId();
 
334
  CallManagerInterface &callManager = CallManagerInterfaceSingleton::getInstance();
 
335
  Q_NOREPLY callManager.joinParticipant(call1->getCallId(),call2->getCallId());
 
336
  return true;
 
337
} //createConferenceFromCall
 
338
 
 
339
///Add a new participant to a conference
 
340
CALLMODEL_TEMPLATE bool CALLMODEL_T::addParticipant(Call* call2, Call* conference)
 
341
{
 
342
   if (conference->isConference()) {
 
343
      CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
344
      Q_NOREPLY callManager.addParticipant(call2->getCallId(), conference->getConfId());
 
345
      return true;
 
346
   }
 
347
   else {
 
348
      qDebug() << "This is not a conference";
 
349
      return false;
 
350
   }
 
351
} //addParticipant
 
352
 
 
353
///Remove a participant from a conference
 
354
CALLMODEL_TEMPLATE bool CALLMODEL_T::detachParticipant(Call* call)
 
355
{
 
356
   CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
357
   Q_NOREPLY callManager.detachParticipant(call->getCallId());
 
358
   return true;
 
359
}
 
360
 
 
361
///Merge two conferences
 
362
CALLMODEL_TEMPLATE bool CALLMODEL_T::mergeConferences(Call* conf1, Call* conf2)
 
363
{
 
364
   CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance();
 
365
   Q_NOREPLY callManager.joinConference(conf1->getConfId(),conf2->getConfId());
 
366
   return true;
 
367
}
 
368
 
 
369
///Executed when the daemon signal a modification in an existing conference. Update the call list and update the TreeView
 
370
CALLMODEL_TEMPLATE bool CALLMODEL_T::changeConference(const QString& confId, const QString& state)
 
371
{
 
372
   qDebug() << "Conf changed";
 
373
   Q_UNUSED(state)
 
374
 
 
375
   if (!m_sPrivateCallList_callId[confId]) {
 
376
      qDebug() << "The conference does not exist";
 
377
      return false;
 
378
   }
 
379
 
 
380
   if (!m_sPrivateCallList_callId[confId]->index) {
 
381
      qDebug() << "The conference item does not exist";
 
382
      return false;
 
383
   }
 
384
   return true;
 
385
} //changeConference
 
386
 
 
387
///Remove a conference from the model and the TreeView
 
388
CALLMODEL_TEMPLATE void CALLMODEL_T::removeConference(const QString &confId)
 
389
{
 
390
   if (m_sPrivateCallList_callId[confId])
 
391
      qDebug() << "Ending conversation containing " << m_sPrivateCallList_callId[confId]->children.size() << " participants";
 
392
   removeConference(getCall(confId));
 
393
}
 
394
 
 
395
///Remove a conference using it's call object
 
396
CALLMODEL_TEMPLATE void CALLMODEL_T::removeConference(Call* call)
 
397
{
 
398
   InternalStruct* internal = m_sPrivateCallList_call[call];
 
399
 
 
400
   if (!internal) {
 
401
      qDebug() << "Cannot remove conference: call not found";
 
402
      return;
 
403
   }
 
404
   removeCall(call);
 
405
 
 
406
   m_lConfList[call->getConfId()] = nullptr;
 
407
}
 
408
 
 
409
 
 
410
/*****************************************************************************
 
411
 *                                                                           *
 
412
 *                             Magic Dispatcher                              *
 
413
 *                                                                           *
 
414
 ****************************************************************************/
 
415
 
 
416
///Get a call from it's widget                                     
 
417
CALLMODEL_TEMPLATE Call* CALLMODEL_T::getCall         ( const CallWidget widget     ) const
 
418
{
 
419
   if (m_sPrivateCallList_widget[widget]) {
 
420
      return m_sPrivateCallList_widget[widget]->call_real;
 
421
   }
 
422
   return nullptr;
 
423
}
 
424
 
 
425
///Get a call list from a conference                               
 
426
CALLMODEL_TEMPLATE QList<Call*> CALLMODEL_T::getCalls ( const CallWidget widget     ) const
 
427
{
 
428
   QList<Call*> toReturn;
 
429
   if (m_sPrivateCallList_widget[widget] && m_sPrivateCallList_widget[widget]->conference) {
 
430
      foreach (InternalStruct* child, m_sPrivateCallList_widget[widget]->children) {
 
431
         toReturn << child.call_real;
 
432
      }
 
433
   }
 
434
   return toReturn;
 
435
}
 
436
 
 
437
///Get a list of every call                                        
 
438
CALLMODEL_TEMPLATE QList<Call*> CALLMODEL_T::getCalls (                             )
 
439
{
 
440
   QList<Call*> toReturn;
 
441
   foreach (InternalStruct* child, m_sPrivateCallList_call) {
 
442
      toReturn << child->call_real;
 
443
   }
 
444
   return toReturn;
 
445
}
 
446
 
 
447
///Is the call associated with that widget a conference            
 
448
CALLMODEL_TEMPLATE bool CALLMODEL_T::isConference     ( const CallWidget widget      ) const
 
449
{
 
450
   if (m_sPrivateCallList_widget[widget]) {
 
451
      return m_sPrivateCallList_widget[widget]->conference;
 
452
   }
 
453
   return false;
 
454
}
 
455
 
 
456
///Is that call a conference                                       
 
457
CALLMODEL_TEMPLATE bool CALLMODEL_T::isConference     ( const Call* call             ) const
 
458
{
 
459
   if (m_sPrivateCallList_call[(Call*)call]) {
 
460
      return m_sPrivateCallList_call[(Call*)call]->conference;
 
461
   }
 
462
   return false;
 
463
}
 
464
 
 
465
///Do nothing, provided for API consistency                        
 
466
CALLMODEL_TEMPLATE Call* CALLMODEL_T::getCall         ( const Call* call             ) const
 
467
 
468
   return call;
 
469
}
 
470
 
 
471
///Return the calls from the "call" conference                     
 
472
CALLMODEL_TEMPLATE QList<Call*> CALLMODEL_T::getCalls ( const Call* call             ) const
 
473
 
474
   QList<Call*> toReturn;
 
475
   if (m_sPrivateCallList_call[call] && m_sPrivateCallList_call[call]->conference) {
 
476
      foreach (InternalStruct* child, m_sPrivateCallList_call[call]->children) {
 
477
         toReturn << child.call_real;
 
478
      }
 
479
   }
 
480
   return toReturn;
 
481
}
 
482
 
 
483
///Is the call associated with that Index a conference             
 
484
CALLMODEL_TEMPLATE bool CALLMODEL_T::isConference     ( const Index idx              ) const
 
485
 
486
   if (m_sPrivateCallList_index[idx]) {
 
487
      return m_sPrivateCallList_index[idx]->conference;
 
488
   }
 
489
   return false;
 
490
}
 
491
 
 
492
///Get the call associated with this index                         
 
493
CALLMODEL_TEMPLATE Call* CALLMODEL_T::getCall         ( const Index idx              ) const
 
494
 
495
   if (m_sPrivateCallList_index[idx]) {
 
496
      return m_sPrivateCallList_index[idx]->call_real;
 
497
   }
 
498
   qDebug() << "Call not found";
 
499
   return nullptr;
 
500
}
 
501
 
 
502
///Get the call associated with that conference index              
 
503
CALLMODEL_TEMPLATE QList<Call*> CALLMODEL_T::getCalls ( const Index idx              ) const
 
504
 
505
   QList<Call*> toReturn;
 
506
   if (m_sPrivateCallList_index[idx] && m_sPrivateCallList_index[idx]->conference) {
 
507
      foreach (InternalStruct* child, m_sPrivateCallList_index[idx]->children) {
 
508
         toReturn << child.call_real;
 
509
      }
 
510
   }
 
511
   return toReturn;
 
512
}
 
513
 
 
514
///Is the call associated with that ID a conference                
 
515
CALLMODEL_TEMPLATE bool CALLMODEL_T::isConference     ( const QString& callId        ) const
 
516
 
517
   if (m_sPrivateCallList_callId[callId]) {
 
518
      return m_sPrivateCallList_callId[callId]->conference;
 
519
   }
 
520
   return false;
 
521
}
 
522
 
 
523
///Get the call associated with this ID                            
 
524
CALLMODEL_TEMPLATE Call* CALLMODEL_T::getCall         ( const QString& callId        ) const
 
525
 
526
   if (m_sPrivateCallList_callId[callId]) {
 
527
      return m_sPrivateCallList_callId[callId]->call_real;
 
528
   }
 
529
   return nullptr;
 
530
}
 
531
 
 
532
///Get the calls associated with this ID                           
 
533
CALLMODEL_TEMPLATE QList<Call*> CALLMODEL_T::getCalls ( const QString& callId        ) const
 
534
{
 
535
   QList<Call*> toReturn;
 
536
   if (m_sPrivateCallList_callId[callId] && m_sPrivateCallList_callId[callId]->conference) {
 
537
      foreach (InternalStruct* child, m_sPrivateCallList_callId[callId]->children) {
 
538
         toReturn << child.callId_real;
 
539
      }
 
540
   }
 
541
   return toReturn;
 
542
}
 
543
 
 
544
///Get the index associated with this call                         
 
545
CALLMODEL_TEMPLATE Index CALLMODEL_T::getIndex        ( const Call* call             ) const
 
546
{
 
547
   if (m_sPrivateCallList_call[(Call*)call]) {
 
548
      return m_sPrivateCallList_call[(Call*)call]->index;
 
549
   }
 
550
   return nullptr;
 
551
}
 
552
 
 
553
///Get the index associated with this index (dummy implementation) 
 
554
CALLMODEL_TEMPLATE Index CALLMODEL_T::getIndex        ( const Index idx              ) const
 
555
{
 
556
   if (m_sPrivateCallList_index[idx]) {
 
557
      return m_sPrivateCallList_index[idx]->index;
 
558
   }
 
559
   return nullptr;
 
560
}
 
561
 
 
562
///Get the index associated with this call                         
 
563
CALLMODEL_TEMPLATE Index CALLMODEL_T::getIndex        ( const CallWidget widget      ) const
 
564
{
 
565
   if (m_sPrivateCallList_widget[widget]) {
 
566
      return m_sPrivateCallList_widget[widget]->index;
 
567
   }
 
568
   return nullptr;
 
569
}
 
570
 
 
571
///Get the index associated with this ID                           
 
572
CALLMODEL_TEMPLATE Index CALLMODEL_T::getIndex        ( const QString& callId        ) const
 
573
{
 
574
   if (m_sPrivateCallList_callId[callId]) {
 
575
      return m_sPrivateCallList_callId[callId]->index;
 
576
   }
 
577
   return nullptr;
 
578
}
 
579
 
 
580
///Get the widget associated with this call                        
 
581
CALLMODEL_TEMPLATE CallWidget CALLMODEL_T::getWidget  ( const Call* call             ) const
 
582
{
 
583
   if (m_sPrivateCallList_call[call]) {
 
584
      return m_sPrivateCallList_call[call]->call;
 
585
   }
 
586
   return nullptr;
 
587
}
 
588
 
 
589
///Get the widget associated with this ID                          
 
590
CALLMODEL_TEMPLATE CallWidget CALLMODEL_T::getWidget  ( const Index idx              ) const
 
591
{
 
592
   if (m_sPrivateCallList_index[idx]) {
 
593
      return m_sPrivateCallList_index[idx]->call;
 
594
   }
 
595
   return nullptr;
 
596
}
 
597
 
 
598
///Get the widget associated with this widget (dummy)              
 
599
CALLMODEL_TEMPLATE CallWidget CALLMODEL_T::getWidget  ( const CallWidget widget      ) const
 
600
{
 
601
   if (m_sPrivateCallList_widget[widget]) {
 
602
      return m_sPrivateCallList_widget[widget]->call;
 
603
   }
 
604
   return nullptr;
 
605
}
 
606
 
 
607
///Get the widget associated with this ID                          
 
608
CALLMODEL_TEMPLATE CallWidget CALLMODEL_T::getWidget  ( const QString& widget        ) const
 
609
{
 
610
   if (m_sPrivateCallList_widget[widget]) {
 
611
      return m_sPrivateCallList_widget[widget]->call;
 
612
   }
 
613
   return nullptr;
 
614
}
 
615
 
 
616
///Common set of instruction shared by all gui updater
 
617
CALLMODEL_TEMPLATE bool CALLMODEL_T::updateCommon(Call* call)
 
618
{
 
619
   if (!m_sPrivateCallList_call[call] && dynamic_cast<Call*>(call)) {
 
620
      m_sPrivateCallList_call   [ call              ]             = new InternalStruct            ;
 
621
      m_sPrivateCallList_call   [ call              ]->call_real  = call                          ;
 
622
      m_sPrivateCallList_call   [ call              ]->conference = false                         ;
 
623
      m_sPrivateCallList_callId [ call->getCallId() ]             = m_sPrivateCallList_call[call] ;
 
624
   }
 
625
   else
 
626
      return false;
 
627
   return true;
 
628
}
 
629
 
 
630
///Update the widget associated with this call                     
 
631
CALLMODEL_TEMPLATE bool CALLMODEL_T::updateWidget     (Call* call, CallWidget value )
 
632
{
 
633
   if (!updateCommon(call)) return false;
 
634
   m_sPrivateCallList_call[call]->call = value                         ;
 
635
   m_sPrivateCallList_widget[value]    = m_sPrivateCallList_call[call] ;
 
636
   return true;
 
637
}
 
638
 
 
639
///Update the index associated with this call
 
640
CALLMODEL_TEMPLATE bool CALLMODEL_T::updateIndex      (Call* call, Index value      )
 
641
{
 
642
   updateCommon(call);
 
643
   if (!m_sPrivateCallList_call[call])
 
644
      return false;
 
645
   m_sPrivateCallList_call[call]->index = value                         ;
 
646
   m_sPrivateCallList_index[value]      = m_sPrivateCallList_call[call] ;
 
647
   return true;
 
648
}