~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 *   Copyright (C) 2009-2013 by Savoir-Faire Linux                          *
 
2
 *   Copyright (C) 2009-2014 by Savoir-Faire Linux                          *
3
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
4
4
 *                                                                          *
5
5
 *   This library is free software; you can redistribute it and/or          *
16
16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
17
17
 ***************************************************************************/
18
18
 
19
 
#ifndef CALL_MODEL_H
20
 
#define CALL_MODEL_H
 
19
#ifndef CALL_MODEL2_H
 
20
#define CALL_MODEL2_H
21
21
 
22
 
#include <QObject>
23
 
#include <QVector>
24
 
#include <QWidget>
25
 
#include <QModelIndex>
 
22
#include <QAbstractItemModel>
26
23
#include <QMap>
27
24
#include "typedefs.h"
28
25
 
29
 
//Qt
30
 
class QModelIndex;
31
 
 
32
26
//SFLPhone
33
 
class Call;
34
 
//class AccountList;
 
27
#include "call.h"
35
28
class Account;
 
29
struct InternalStruct;
 
30
class PhoneNumber;
36
31
 
37
32
//Typedef
38
 
typedef QMap<QString, Call*>  CallMap;
39
 
typedef QList<Call*>          CallList;
 
33
typedef QMap<uint, Call*>  CallMap;
 
34
typedef QList<Call*>       CallList;
40
35
 
41
 
///CallModelBase: Base class for the central model/frontend
42
 
///This class need to exist because template classes can't have signals and
43
 
///slots because Qt MOC generator can't guess the type at precompilation   
44
 
class LIB_EXPORT CallModelBase : public QObject
 
36
///CallModel: Central model/frontend to deal with sflphoned
 
37
class LIB_EXPORT CallModel : public QAbstractItemModel
45
38
{
 
39
   #pragma GCC diagnostic push
 
40
   #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
46
41
   Q_OBJECT
47
 
public:
48
 
   explicit CallModelBase(QObject* parent = nullptr);
49
 
   ~CallModelBase();
50
 
   virtual Call* addCall              ( Call* call           , Call* parent =0      );
51
 
   virtual Call* getCall              ( const QString& callId                       ) const = 0;
52
 
   Call*   addConferenceS             ( Call* conf                                  );
53
 
 
54
 
   bool isValid();
55
 
   
56
 
private Q_SLOTS:
57
 
   void callStateChanged      ( const QString& callID    , const QString &state   );
58
 
   void incomingCall          ( const QString& accountID , const QString & callID );
59
 
   void incomingConference    ( const QString& confID                             );
60
 
   void changingConference    ( const QString& confID    , const QString &state   );
61
 
   void conferenceRemovedSlot ( const QString& confId                             );
62
 
   void voiceMailNotifySlot   ( const QString& accountID , int count              );
63
 
   void volumeChangedSlot     ( const QString& device    , double value           );
64
 
   void removeActiveCall      ( Call* call                                        );
65
 
   void addPrivateCall        ( Call* call                                        );
66
 
   void newRecordingAvail     ( const QString& callId    , const QString& filePath);
67
 
   #ifdef ENABLE_VIDEO
68
 
   void startedDecoding       ( const QString& callId    , const QString& shmKey  );
69
 
   void stoppedDecoding       ( const QString& callId    , const QString& shmKey  );
70
 
   #endif
71
 
 
72
 
protected:
73
 
   virtual Call* findCallByCallId ( const QString& callId                       ) = 0;
74
 
   virtual bool changeConference  ( const QString& confId, const QString &state ) = 0;
75
 
   virtual void removeConference  ( const QString& confId                       ) = 0;
76
 
   virtual Call* addConference    ( const QString& confID                       ) = 0;
77
 
   virtual Call* addRingingCall   ( const QString& callId                       ) = 0;
78
 
   virtual Call* addIncomingCall  ( const QString& callId                       ) = 0;
79
 
 
80
 
   //Attributes
81
 
   static CallMap m_sActiveCalls;
82
 
 
83
 
private:
84
 
   static bool dbusInit;
85
 
   
86
 
Q_SIGNALS:
87
 
   ///Emitted when a call state change
88
 
   void callStateChanged        ( Call* call                              );
89
 
   ///Emitted when a new call is incoming
90
 
   void incomingCall            ( Call* call                              );
91
 
   ///Emitted when a conference is created
92
 
   void conferenceCreated       ( Call* conf                              );
93
 
   ///Emitted when a conference change state or participant
94
 
   void conferenceChanged       ( Call* conf                              );
95
 
   ///Emitted when a conference is removed
96
 
   void conferenceRemoved       ( Call* conf                              );
97
 
   ///Emitted just before a conference is removed
98
 
   void aboutToRemoveConference ( Call* conf                              );
99
 
   ///Emitted when a new voice mail is available
100
 
   void voiceMailNotify         ( const QString& accountID , int    count );
101
 
   ///Emitted when the volume change
102
 
   void volumeChanged           ( const QString& device    , double value );
103
 
   ///Emitted when a call is added
104
 
   void callAdded               ( Call* call               , Call* parent );
105
 
   ///Emitted when an account state change
106
 
   //void accountStateChanged     ( Account* account, QString state         );
107
 
};
108
 
 
109
 
/**
110
 
 * Using QAbstractModel resulted in a failure. Managing all corner case bloated the code to the point of no
111
 
 * return. This frontend may not be cleaner from a design point of view, but it is from a code point of view
112
 
 */
113
 
///CallModel: Central model/frontend to deal with sflphoned
114
 
template  <typename CallWidget = QWidget*, typename Index = QModelIndex*>
115
 
class LIB_EXPORT CallModel : public CallModelBase {
 
42
   #pragma GCC diagnostic pop
116
43
   public:
 
44
      ///Accepted (mime) payload types
 
45
      enum DropPayloadType {
 
46
         NONE    = 0   ,
 
47
         CALL    = 1<<0,
 
48
         HISTORY = 1<<1,
 
49
         CONTACT = 1<<2,
 
50
         NUMBER  = 1<<3,
 
51
         TEXT    = 1<<4,
 
52
      };
 
53
 
 
54
      //Properties
 
55
      Q_PROPERTY(int  size          READ size         )
 
56
      Q_PROPERTY(bool hasConference READ hasConference)
 
57
      Q_PROPERTY(int  callCount     READ rowCount     )
117
58
 
118
59
      //Constructors, initializer and destructors
119
 
      CallModel                (                    );
120
 
      virtual ~CallModel       (                    );
121
 
      virtual bool initCall    (                    );
122
 
      static  void destroy     (                    );
 
60
      virtual ~CallModel( );
123
61
 
124
62
      //Call related
125
 
      virtual Call*  addCall          ( Call* call                , Call* parent =0          );
126
 
      Call*          addDialingCall   ( const QString& peerName="", Account* account=nullptr );
127
 
      static QString generateCallId   (                                                      );
128
 
      void           removeCall       ( Call* call                                           );
129
 
      void           attendedTransfer ( Call* toTransfer          , Call* target             );
130
 
      void           transfer         ( Call* toTransfer          , QString target           );
 
63
      Q_INVOKABLE Call* dialingCall      ( const QString& peerName=QString(), Account* account=nullptr );
 
64
      Q_INVOKABLE void  attendedTransfer ( Call* toTransfer , Call* target              );
 
65
      Q_INVOKABLE void  transfer         ( Call* toTransfer , const PhoneNumber* target );
 
66
      QModelIndex getIndex               ( Call* call                                   );
131
67
 
132
68
      //Conference related
133
 
      bool createConferenceFromCall  ( Call* call1, Call* call2                    );
134
 
      bool mergeConferences          ( Call* conf1, Call* conf2                    );
135
 
      bool addParticipant            ( Call* call2, Call* conference               );
136
 
      bool detachParticipant         ( Call* call                                  );
137
 
      void removeConference          ( Call* conf                                  );
 
69
      Q_INVOKABLE bool createConferenceFromCall ( Call* call1, Call* call2      );
 
70
      Q_INVOKABLE bool mergeConferences         ( Call* conf1, Call* conf2      );
 
71
      Q_INVOKABLE bool addParticipant           ( Call* call2, Call* conference );
 
72
      Q_INVOKABLE bool detachParticipant        ( Call* call                    );
138
73
 
139
74
      //Getters
140
 
      int size                                        ();
141
 
      CallList                 getCallList            ();
142
 
      CallList                 getConferenceList      ();
143
 
 
144
 
      //Connection related
145
 
      static bool init();
146
 
      
147
 
      //Magic dispatcher
148
 
      CallList getCalls     (                         );
149
 
      CallList getCalls     ( const CallWidget widget ) const;
150
 
      CallList getCalls     ( const QString& callId   ) const;
151
 
      CallList getCalls     ( const Call* call        ) const;
152
 
      CallList getCalls     ( const Index idx         ) const;
153
 
      
154
 
      bool isConference     ( const Call* call        ) const;
155
 
      bool isConference     ( const QString& callId   ) const;
156
 
      bool isConference     ( const Index idx         ) const;
157
 
      bool isConference     ( const CallWidget widget ) const;
158
 
      
159
 
      Call* getCall         ( const QString& callId   ) const;
160
 
      Call* getCall         ( const Index idx         ) const;
161
 
      Call* getCall         ( const Call* call        ) const;
162
 
      Call* getCall         ( const CallWidget widget ) const;
163
 
      
164
 
      Index getIndex        ( const Call* call        ) const;
165
 
      Index getIndex        ( const Index idx         ) const;
166
 
      Index getIndex        ( const CallWidget widget ) const;
167
 
      Index getIndex        ( const QString& callId   ) const;
168
 
      
169
 
      CallWidget getWidget  ( const Call* call        ) const;
170
 
      CallWidget getWidget  ( const Index idx         ) const;
171
 
      CallWidget getWidget  ( const CallWidget widget ) const;
172
 
      CallWidget getWidget  ( const QString& getWidget) const;
173
 
      
174
 
      bool updateIndex      ( Call* call, Index value      );
175
 
      bool updateWidget     ( Call* call, CallWidget value );
176
 
      
177
 
      
178
 
   protected:
179
 
      virtual Call* findCallByCallId ( const QString& callId                       );
180
 
      virtual Call* addConference    ( const QString& confID                       );
181
 
      virtual bool  changeConference ( const QString& confId, const QString& state );
182
 
      virtual void  removeConference ( const QString& confId                       );
183
 
      Call*         addIncomingCall  ( const QString& callId                       );
184
 
      Call*         addRingingCall   ( const QString& callId                       );
185
 
      
186
 
      //Struct
187
 
      struct InternalStruct;
188
 
      typedef QList<InternalStruct*> InternalCallList;
189
 
      ///InternalStruct: internal representation of a call
190
 
      struct InternalStruct {
191
 
         CallWidget       call       ;
192
 
         Call*            call_real  ;
193
 
         Index            index      ;
194
 
         InternalCallList children   ;
195
 
         bool             conference ;
196
 
      };
197
 
      typedef QHash< Call*      , InternalStruct* > InternalCall  ;
198
 
      typedef QHash< QString    , InternalStruct* > InternalCallId;
199
 
      typedef QHash< CallWidget , InternalStruct* > InternalWidget;
200
 
      typedef QHash< Index      , InternalStruct* > InternalIndex ;
201
 
 
202
 
      //Static attributes
203
 
      static InternalCall   m_sPrivateCallList_call  ;
204
 
      static InternalCallId m_sPrivateCallList_callId;
205
 
      static InternalWidget m_sPrivateCallList_widget;
206
 
      static InternalIndex  m_sPrivateCallList_index ;
207
 
 
208
 
      static CallMap        m_lConfList;
209
 
      static bool           m_sCallInit;
 
75
      Q_INVOKABLE bool     isValid             ();
 
76
      Q_INVOKABLE int      size                ();
 
77
      Q_INVOKABLE CallList getCallList         ();
 
78
      Q_INVOKABLE CallList getConferenceList   ();
 
79
      Q_INVOKABLE int      acceptedPayloadTypes();
 
80
      Q_INVOKABLE bool     hasConference       () const;
 
81
 
 
82
      //Model implementation
 
83
      virtual bool          setData      ( const QModelIndex& index, const QVariant &value, int role   );
 
84
      virtual QVariant      data         ( const QModelIndex& index, int role = Qt::DisplayRole        ) const;
 
85
      virtual int           rowCount     ( const QModelIndex& parent = QModelIndex()                   ) const;
 
86
      virtual Qt::ItemFlags flags        ( const QModelIndex& index                                    ) const;
 
87
      virtual int           columnCount  ( const QModelIndex& parent = QModelIndex()                   ) const __attribute__ ((const));
 
88
      virtual QModelIndex   parent       ( const QModelIndex& index                                    ) const;
 
89
      virtual QModelIndex   index        ( int row, int column, const QModelIndex& parent=QModelIndex()) const;
 
90
      virtual QVariant      headerData   ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
 
91
      virtual QStringList   mimeTypes    (                                                             ) const;
 
92
      virtual QMimeData*    mimeData     ( const QModelIndexList &indexes                              ) const;
 
93
      virtual bool          dropMimeData ( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
 
94
 
 
95
      //Singleton
 
96
      static CallModel* instance();
 
97
 
 
98
      Q_INVOKABLE Call* getCall ( const QString& callId  ) const;
 
99
      Q_INVOKABLE Call* getCall ( const QModelIndex& idx ) const;
210
100
 
211
101
   private:
212
 
      static bool m_sInstanceInit;
 
102
      explicit CallModel();
 
103
      void init();
 
104
      Call* addCall          ( Call* call                , Call* parent = nullptr );
 
105
      Call* addConference    ( const QString& confID                              );
 
106
//       bool  changeConference ( const QString& confId, const QString& state        );
 
107
      void  removeConference ( const QString& confId                              );
 
108
      void  removeCall       ( Call* call       , bool noEmit = false             );
 
109
      Call* addIncomingCall  ( const QString& callId                              );
 
110
      Call* addRingingCall   ( const QString& callId                              );
 
111
 
 
112
      //Attributes
 
113
      QList<InternalStruct*> m_lInternalModel;
 
114
      QHash< Call*       , InternalStruct* > m_sPrivateCallList_call   ;
 
115
      QHash< QString     , InternalStruct* > m_sPrivateCallList_callId ;
 
116
 
 
117
      //Singleton
 
118
      static CallModel* m_spInstance;
213
119
 
214
120
      //Helpers
215
 
      Call* addCallCommon(Call* call);
216
 
      bool  updateCommon (Call* call);
 
121
      bool isPartOf(const QModelIndex& confIdx, Call* call);
 
122
      void initRoles();
 
123
      void removeConference       ( Call* conf                    );
 
124
 
 
125
   private Q_SLOTS:
 
126
      void slotCallStateChanged   ( const QString& callID    , const QString &state   );
 
127
      void slotIncomingCall       ( const QString& accountID , const QString & callID );
 
128
      void slotIncomingConference ( const QString& confID                             );
 
129
      void slotChangingConference ( const QString& confID    , const QString &state   );
 
130
      void slotConferenceRemoved  ( const QString& confId                             );
 
131
      void slotVolumeChanged      ( const QString& device    , double value           );
 
132
      void slotAddPrivateCall     ( Call* call                                        );
 
133
      void slotNewRecordingAvail  ( const QString& callId    , const QString& filePath);
 
134
      void slotCallChanged        ( Call* call                                        );
 
135
      void slotDTMFPlayed         ( const QString& str                                );
 
136
      void slotRecordStateChanged ( const QString& callId    , bool state             );
 
137
      #ifdef ENABLE_VIDEO
 
138
      void slotStartedDecoding    ( const QString& callId    , const QString& shmKey  );
 
139
      void slotStoppedDecoding    ( const QString& callId    , const QString& shmKey  );
 
140
      #endif
 
141
 
 
142
   Q_SIGNALS:
 
143
      ///Emitted when a call state change
 
144
      void callStateChanged        ( Call* call, Call::State previousState   );
 
145
      ///Emitted when a new call is incoming
 
146
      void incomingCall            ( Call* call                              );
 
147
      ///Emitted when a conference is created
 
148
      void conferenceCreated       ( Call* conf                              );
 
149
      ///Emitted when a conference change state or participant
 
150
      void conferenceChanged       ( Call* conf                              );
 
151
      ///Emitted when a conference is removed
 
152
      void conferenceRemoved       ( Call* conf                              );
 
153
      ///Emitted when the volume change
 
154
      void volumeChanged           ( const QString& device    , double value );
 
155
      ///Emitted when a call is added
 
156
      void callAdded               ( Call* call               , Call* parent );
217
157
};
218
 
#include "callmodel.hpp"
 
158
Q_DECLARE_METATYPE(CallModel*)
219
159
 
220
160
#endif