1
/***************************************************************************
2
* Copyright (C) 2009-2012 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Valle <emmanuel.lepage@savoirfairelinux.com >*
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. *
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. *
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
**************************************************************************/
30
class QDragEnterEvent;
40
typedef QHash<QString, Call*> CallHash;
41
typedef QList<Call*> CallList;
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
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;
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 );
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 );
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).
86
///@class CallModel Central model/frontend to deal with sflphoned
87
template <typename CallWidget, typename Index>
88
class LIB_EXPORT CallModel : public CallModelBase {
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 );
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 );
113
virtual bool selectItem(Call* item) { Q_UNUSED(item); return false;}
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 );
127
CallList getCallList ();
128
static const CallHash& getHistory ();
129
static const QStringList getHistoryCallId ();
132
static Account* getCurrentAccount ( );
133
static QString getCurrentAccountId ( );
134
static AccountList* getAccountList ( );
135
static QString getPriorAccoundId ( );
136
static void setPriorAccountId (const QString& value );
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;
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;
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;
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;
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;
169
bool updateIndex ( Call* call, Index value );
170
bool updateWidget ( Call* call, CallWidget value );
175
struct InternalStruct;
176
typedef QList<InternalStruct*> InternalCallList;
177
struct InternalStruct {
181
InternalCallList children ;
184
typedef QHash< Call* , InternalStruct* > InternalCall ;
185
typedef QHash< QString , InternalStruct* > InternalCallId;
186
typedef QHash< CallWidget , InternalStruct* > InternalWidget;
187
typedef QHash< Index , InternalStruct* > InternalIndex ;
190
static CallHash m_sActiveCalls ;
191
static CallHash m_sHistoryCalls;
193
static InternalCall m_sPrivateCallList_call ;
194
static InternalCallId m_sPrivateCallList_callId;
195
static InternalWidget m_sPrivateCallList_widget;
196
static InternalIndex m_sPrivateCallList_index ;
198
static QString m_sPriorAccountId;
199
static AccountList* m_spAccountList ;
200
static bool m_sCallInit ;
201
static bool m_sHistoryInit ;
204
static bool m_sInstanceInit;
207
Call* addCallCommon(Call* call);
208
bool updateCommon (Call* call);
211
class CallModelConvenience : public CallModel<QWidget*,QModelIndex*>
214
CallModelConvenience(ModelType type) : CallModel<QWidget*,QModelIndex*>(type) {}
217
#include "CallModel.hpp"