~ubuntu-branches/ubuntu/precise/sflphone/precise

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Whoopie
  • Date: 2012-03-22 10:29:10 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120322102910-tb8hugi2su1tguwh
Tags: 1.0.2-1ubuntu1
* Apply some upstream patches to fix FTBFS (LP: #913018):
  - debian/patches/05_glib_includes.patch: fix glib includes.
  - debian/patches/06_use_XkbKeycodeToKeysym.patch: use 
    XkbKeycodeToKeysym instead of (deprecated) XKeycodeToKeysym.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009-2012 by Savoir-Faire Linux                         *
 
3
 *   Author : Emmanuel Lepage Valle <emmanuel.lepage@savoirfairelinux.com >*
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 3 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program 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         *
 
13
 *   GNU 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, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 **************************************************************************/
 
20
 
 
21
#ifndef CALL_MODEL_H
 
22
#define CALL_MODEL_H
 
23
 
 
24
#include <QObject>
 
25
#include <QVector>
 
26
#include <QHash>
 
27
#include "typedefs.h"
 
28
 
 
29
//Qt
 
30
class QDragEnterEvent;
 
31
class QDebug;
 
32
class QModelIndex;
 
33
 
 
34
//SFLPhone
 
35
class Call;
 
36
class AccountList;
 
37
class Account;
 
38
class ContactBackend;
 
39
 
 
40
typedef QHash<QString, Call*> CallHash;
 
41
typedef QList<Call*>          CallList;
 
42
 
 
43
///@class CallModelBase Base class for the central model/frontend
 
44
///This class need to exist because template classes can't have signals ans
 
45
///slots because Qt MOC generator can't guess the type at precompilation
 
46
class LIB_EXPORT CallModelBase : public QObject
 
47
{
 
48
   Q_OBJECT
 
49
public:
 
50
   CallModelBase(QObject* parent = 0);
 
51
   virtual bool changeConference  ( const QString &confId, const QString &state ) = 0;
 
52
   virtual void removeConference  ( const QString &confId                       ) = 0;
 
53
   virtual Call* addConference    ( const QString &confID                       ) = 0;
 
54
   virtual Call* findCallByCallId ( const QString& callId                       ) = 0;
 
55
   virtual Call* addRingingCall   ( const QString& callId                       ) = 0;
 
56
   virtual Call* addIncomingCall  ( const QString& callId                       ) = 0;
 
57
   virtual Call* addCall          ( Call* call           , Call* parent =0      );
 
58
   virtual Call* getCall          ( const QString& callId                       ) const = 0;
 
59
public slots:
 
60
   void on1_callStateChanged   ( const QString& callID    , const QString &state   );
 
61
   void on1_incomingCall       ( const QString& accountID , const QString & callID );
 
62
   void on1_incomingConference ( const QString& confID                             );
 
63
   void on1_changingConference ( const QString& confID    , const QString &state   );
 
64
   void on1_conferenceRemoved  ( const QString& confId                             );
 
65
   void on1_voiceMailNotify    ( const QString& accountID , int count              );
 
66
   void on1_volumeChanged      ( const QString& device    , double value           );
 
67
private:
 
68
   static bool dbusInit;
 
69
signals:
 
70
   void callStateChanged        (Call* call                              );
 
71
   void incomingCall            (Call* call                              );
 
72
   void conferenceCreated       (Call* conf                              );
 
73
   void conferenceChanged       (Call* conf                              );
 
74
   void conferenceRemoved       (const QString& confId                   );
 
75
   void aboutToRemoveConference (Call* conf                              );
 
76
   void voiceMailNotify         (const QString& accountID , int    count );
 
77
   void volumeChanged           (const QString& device    , double value );
 
78
   void callAdded               (Call* call               , Call* parent );
 
79
};
 
80
 
 
81
/**
 
82
 * Note from the author: It was previously done by a QAbstractModel + QTreeView, but the sip-call use case is incompatible  
 
83
 *  with the MVC model. The MVC never got to a point were it was bug-free and the code was getting dirty. The Mirror model  
 
84
 *  solution may be less "clean" than MVC, but is 3 time smaller and easier to improve (in fact, possible to improve).      
 
85
 */
 
86
///@class CallModel Central model/frontend to deal with sflphoned
 
87
template  <typename CallWidget, typename Index>
 
88
class LIB_EXPORT CallModel : public CallModelBase {
 
89
   public:
 
90
      enum ModelType {
 
91
         ActiveCall,
 
92
         History,
 
93
         Address
 
94
      };
 
95
 
 
96
      //Constructors, initializer and destructors
 
97
      CallModel                ( ModelType type     );
 
98
      virtual ~CallModel       (                    ) {}
 
99
      virtual bool initCall    (                    );
 
100
      virtual bool initHistory (                    );
 
101
      virtual void initContact ( ContactBackend* be );
 
102
 
 
103
      //Call related
 
104
      virtual Call*  addCall          ( Call* call                , Call* parent =0    );
 
105
      Call*          addDialingCall   ( const QString& peerName="", QString account="" );
 
106
      Call*          addIncomingCall  ( const QString& callId                          );
 
107
      Call*          addRingingCall   ( const QString& callId                          );
 
108
      static QString generateCallId   (                                                );
 
109
      void           removeCall       ( Call* call                                     );
 
110
      void           attendedTransfer ( Call* toTransfer           , Call* target      );
 
111
      void           transfer         ( Call* toTransfer           , QString target    );
 
112
      
 
113
      virtual bool selectItem(Call* item) { Q_UNUSED(item); return false;}
 
114
 
 
115
      //Comference related
 
116
      bool createConferenceFromCall  ( Call* call1, Call* call2                    );
 
117
      bool mergeConferences          ( Call* conf1, Call* conf2                    );
 
118
      bool addParticipant            ( Call* call2, Call* conference               );
 
119
      bool detachParticipant         ( Call* call                                  );
 
120
      virtual bool changeConference  ( const QString &confId, const QString &state );
 
121
      virtual void removeConference  ( const QString &confId                       );
 
122
      virtual Call* addConference    ( const QString &confID                       );
 
123
      void removeConference          ( Call* call                                  );
 
124
 
 
125
      //Getters
 
126
      int size                                  ();
 
127
      CallList                 getCallList      ();
 
128
      static const CallHash&   getHistory       ();
 
129
      static const QStringList getHistoryCallId ();
 
130
 
 
131
      //Account related
 
132
      static Account* getCurrentAccount  (                     );
 
133
      static QString getCurrentAccountId (                     );
 
134
      static AccountList* getAccountList (                     );
 
135
      static QString getPriorAccoundId   (                     );
 
136
      static void setPriorAccountId      (const QString& value );
 
137
 
 
138
      //Connection related
 
139
      static bool init();
 
140
      
 
141
      //Magic dispatcher
 
142
      Call* findCallByCallId( const QString& callId   );
 
143
      CallList getCalls     (                         );
 
144
      CallList getCalls     ( const CallWidget widget ) const;
 
145
      CallList getCalls     ( const QString& callId   ) const;
 
146
      CallList getCalls     ( const Call* call        ) const;
 
147
      CallList getCalls     ( const Index idx         ) const;
 
148
      
 
149
      bool isConference     ( const Call* call        ) const;
 
150
      bool isConference     ( const QString& callId   ) const;
 
151
      bool isConference     ( const Index idx         ) const;
 
152
      bool isConference     ( const CallWidget widget ) const;
 
153
      
 
154
      Call* getCall         ( const QString& callId   ) const;
 
155
      Call* getCall         ( const Index idx         ) const;
 
156
      Call* getCall         ( const Call* call        ) const;
 
157
      Call* getCall         ( const CallWidget widget ) const;
 
158
      
 
159
      Index getIndex        ( const Call* call        ) const;
 
160
      Index getIndex        ( const Index idx         ) const;
 
161
      Index getIndex        ( const CallWidget widget ) const;
 
162
      Index getIndex        ( const QString& callId   ) const;
 
163
      
 
164
      CallWidget getWidget  ( const Call* call        ) const;
 
165
      CallWidget getWidget  ( const Index idx         ) const;
 
166
      CallWidget getWidget  ( const CallWidget widget ) const;
 
167
      CallWidget getWidget  ( const QString& getWidget) const;
 
168
      
 
169
      bool updateIndex      ( Call* call, Index value      );
 
170
      bool updateWidget     ( Call* call, CallWidget value );
 
171
      
 
172
      
 
173
   protected:
 
174
      //Struct
 
175
      struct InternalStruct;
 
176
      typedef QList<InternalStruct*> InternalCallList;
 
177
      struct InternalStruct {
 
178
         CallWidget       call       ;
 
179
         Call*            call_real  ;
 
180
         Index            index      ;
 
181
         InternalCallList children   ;
 
182
         bool             conference ;
 
183
      };
 
184
      typedef QHash< Call*      , InternalStruct* > InternalCall  ;
 
185
      typedef QHash< QString    , InternalStruct* > InternalCallId;
 
186
      typedef QHash< CallWidget , InternalStruct* > InternalWidget;
 
187
      typedef QHash< Index      , InternalStruct* > InternalIndex ;
 
188
 
 
189
      //Static attributes
 
190
      static CallHash m_sActiveCalls ;
 
191
      static CallHash m_sHistoryCalls;
 
192
      
 
193
      static InternalCall   m_sPrivateCallList_call  ;
 
194
      static InternalCallId m_sPrivateCallList_callId;
 
195
      static InternalWidget m_sPrivateCallList_widget;
 
196
      static InternalIndex  m_sPrivateCallList_index ;
 
197
      
 
198
      static QString      m_sPriorAccountId;
 
199
      static AccountList* m_spAccountList  ;
 
200
      static bool         m_sCallInit      ;
 
201
      static bool         m_sHistoryInit   ;
 
202
 
 
203
   private:
 
204
      static bool m_sInstanceInit;
 
205
 
 
206
      //Helpers
 
207
      Call* addCallCommon(Call* call);
 
208
      bool  updateCommon (Call* call);
 
209
};
 
210
 
 
211
class CallModelConvenience : public CallModel<QWidget*,QModelIndex*>
 
212
{
 
213
   public:
 
214
      CallModelConvenience(ModelType type) : CallModel<QWidget*,QModelIndex*>(type) {}
 
215
};
 
216
 
 
217
#include "CallModel.hpp"
 
218
 
 
219
#endif