16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
17
***************************************************************************/
25
#include <QModelIndex>
22
#include <QAbstractItemModel>
27
24
#include "typedefs.h"
29
struct InternalStruct;
38
typedef QMap<QString, Call*> CallMap;
39
typedef QList<Call*> CallList;
33
typedef QMap<uint, Call*> CallMap;
34
typedef QList<Call*> CallList;
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
39
#pragma GCC diagnostic push
40
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
48
explicit CallModelBase(QObject* parent = nullptr);
50
virtual Call* addCall ( Call* call , Call* parent =0 );
51
virtual Call* getCall ( const QString& callId ) const = 0;
52
Call* addConferenceS ( Call* conf );
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);
68
void startedDecoding ( const QString& callId , const QString& shmKey );
69
void stoppedDecoding ( const QString& callId , const QString& shmKey );
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;
81
static CallMap m_sActiveCalls;
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 );
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
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
44
///Accepted (mime) payload types
45
enum DropPayloadType {
55
Q_PROPERTY(int size READ size )
56
Q_PROPERTY(bool hasConference READ hasConference)
57
Q_PROPERTY(int callCount READ rowCount )
118
59
//Constructors, initializer and destructors
120
virtual ~CallModel ( );
121
virtual bool initCall ( );
122
static void destroy ( );
60
virtual ~CallModel( );
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 );
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 );
141
CallList getCallList ();
142
CallList getConferenceList ();
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;
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;
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;
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;
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;
174
bool updateIndex ( Call* call, Index value );
175
bool updateWidget ( Call* call, CallWidget value );
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 );
187
struct InternalStruct;
188
typedef QList<InternalStruct*> InternalCallList;
189
///InternalStruct: internal representation of a call
190
struct InternalStruct {
194
InternalCallList children ;
197
typedef QHash< Call* , InternalStruct* > InternalCall ;
198
typedef QHash< QString , InternalStruct* > InternalCallId;
199
typedef QHash< CallWidget , InternalStruct* > InternalWidget;
200
typedef QHash< Index , InternalStruct* > InternalIndex ;
203
static InternalCall m_sPrivateCallList_call ;
204
static InternalCallId m_sPrivateCallList_callId;
205
static InternalWidget m_sPrivateCallList_widget;
206
static InternalIndex m_sPrivateCallList_index ;
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;
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 );
96
static CallModel* instance();
98
Q_INVOKABLE Call* getCall ( const QString& callId ) const;
99
Q_INVOKABLE Call* getCall ( const QModelIndex& idx ) const;
212
static bool m_sInstanceInit;
102
explicit CallModel();
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 );
113
QList<InternalStruct*> m_lInternalModel;
114
QHash< Call* , InternalStruct* > m_sPrivateCallList_call ;
115
QHash< QString , InternalStruct* > m_sPrivateCallList_callId ;
118
static CallModel* m_spInstance;
215
Call* addCallCommon(Call* call);
216
bool updateCommon (Call* call);
121
bool isPartOf(const QModelIndex& confIdx, Call* call);
123
void removeConference ( Call* conf );
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 );
138
void slotStartedDecoding ( const QString& callId , const QString& shmKey );
139
void slotStoppedDecoding ( const QString& callId , const QString& shmKey );
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 );
218
#include "callmodel.hpp"
158
Q_DECLARE_METATYPE(CallModel*)