diff --git a/src/Call.cpp b/src/Call.cpp index 628fdd52bd2cb31852216a53831c7e3ffa126c5c..d3c4404b3c4207720e0fb91146d7e5e5b92d9396 100644 --- a/src/Call.cpp +++ b/src/Call.cpp @@ -472,8 +472,9 @@ call_state Call::stateChanged(const QString& newStateName) call_state Call::actionPerformed(call_action action) { call_state previousState = currentState; - Q_ASSERT_X((previousState>10) || (previousState<0),"perform action","Invalid previous state ("+QString::number(previousState)+")"); - Q_ASSERT_X((state>4) || (state < 0),"perform action","Invalid action ("+QString::number(actuon)+")"); + Q_ASSERT_X((previousState>10) || (previousState<0),"perform action","Invalid previous state ("+QString::number(previousState)+")"); + Q_ASSERT_X((state>4) || (state < 0),"perform action","Invalid action ("+QString::number(action)+")"); + Q_ASSERT_X((action>5) || (action < 0),"perform action","Invalid action ("+QString::number(action)+")"); //update the state changeCurrentState(actionPerformedStateMap[previousState][action]); //execute the action associated with this transition diff --git a/src/CallModel.cpp b/src/CallModel.cpp index d3746dd489e0ebdb4b68e3d57d5611a119c27a17..e9541dd8365c3f09ae4824d7f4d851cbb458f4ad 100644 --- a/src/CallModel.cpp +++ b/src/CallModel.cpp @@ -19,3 +19,111 @@ **************************************************************************/ #include <CallModel.h> +bool CallModelBase::dbusInit = false; + +CallModelBase::CallModelBase(QObject* parent) : QObject(parent) +{ + if (!dbusInit) { + CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance(); + connect(&callManager, SIGNAL( callStateChanged (const QString &, const QString & ) ), this , SLOT( on1_callStateChanged ( const QString &, const QString & ) ) ); + connect(&callManager, SIGNAL( incomingCall (const QString &, const QString &, const QString & ) ), this , SLOT( on1_incomingCall ( const QString &, const QString & ) ) ); + connect(&callManager, SIGNAL( conferenceCreated (const QString & ) ), this , SLOT( on1_incomingConference( const QString & ) ) ); + connect(&callManager, SIGNAL( conferenceChanged (const QString &, const QString & ) ), this , SLOT( on1_changingConference( const QString &, const QString & ) ) ); + connect(&callManager, SIGNAL( conferenceRemoved (const QString & ) ), this , SLOT( on1_conferenceRemoved ( const QString & ) ) ); + connect(&callManager, SIGNAL( voiceMailNotify (const QString &, int ) ), this , SLOT( on1_voiceMailNotify ( const QString &, int ) ) ); + connect(&callManager, SIGNAL( volumeChanged (const QString &, double ) ), this , SLOT( on1_volumeChanged ( const QString &, double ) ) ); + dbusInit = true; + } +} + +void CallModelBase::on1_callStateChanged(const QString &callID, const QString &state) +{ + //This code is part of the CallModel iterface too + qDebug() << "Signal : Call State Changed for call " << callID << " . New state : " << state; + Call* call = findCallByCallId(callID); + if(!call) { + qDebug() << "Call not found"; + if(state == CALL_STATE_CHANGE_RINGING) { + call = addRingingCall(callID); + } + else { + qDebug() << "Call doesn't exist in this client. Might have been initialized by another client instance before this one started."; + return; + } + } + else { + qDebug() << "Call found" << call; + call->stateChanged(state); + } + //updateWindowCallState(); //NEED_PORT + emit callStateChanged(call); + +} + +void CallModelBase::on1_incomingCall(const QString & accountID, const QString & callID) +{ + qDebug() << "Signal : Incoming Call ! ID = " << callID; + Call* call = addIncomingCall(callID); + + //NEED_PORT +// changeScreen(SCREEN_MAIN); +// +// SFLPhone::app()->activateWindow(); +// SFLPhone::app()->raise(); +// SFLPhone::app()->setVisible(true); + + //emit incomingCall(call); + emit incomingCall(call); +} + +void CallModelBase::on1_incomingConference(const QString &confID) +{ + Call* conf = addConference(confID); + qDebug() << "---------------Adding conference" << conf << confID << "---------------"; + emit conferenceCreated(conf); +} + +void CallModelBase::on1_changingConference(const QString &confID, const QString &state) +{ + Call* conf = getCall(confID); + qDebug() << "Changing conference state" << conf << confID; + if (conf) { + changeConference(confID, state); + emit conferenceChanged(conf); + } + else { + qDebug() << "Trying to affect a conference that does not exist (anymore)"; + } +} + +void CallModelBase::on1_conferenceRemoved(const QString &confId) +{ + Call* conf = getCall(confId); + emit aboutToRemoveConference(conf); + removeConference(confId); + emit conferenceRemoved(confId); +} + +void CallModelBase::on1_voiceMailNotify(const QString &accountID, int count) +{ + qDebug() << "Signal : VoiceMail Notify ! " << count << " new voice mails for account " << accountID; + emit voiceMailNotify(accountID,count); +} + +void CallModelBase::on1_volumeChanged(const QString & device, double value) +{ +// qDebug() << "Signal : Volume Changed !"; +// if(! (toolButton_recVol->isChecked() && value == 0.0)) +// updateRecordBar(); +// if(! (toolButton_sndVol->isChecked() && value == 0.0)) +// updateVolumeBar(); + emit volumeChanged(device,value); +} + +Call* CallModelBase::addCall(Call* call, Call* parent) +{ + emit callAdded(call,parent); + return call; +} + +//More code in CallModel.hpp \ No newline at end of file diff --git a/src/CallModel.h b/src/CallModel.h index aee51aef13c99c766b89635251bb1ef14ff66081..6853da3978be37671f4304773299da5904f3dc8f 100644 --- a/src/CallModel.h +++ b/src/CallModel.h @@ -40,14 +40,48 @@ typedef QHash<QString, Call*> CallHash; typedef QList<Call*> CallList; +class LIB_EXPORT CallModelBase : public QObject +{ + Q_OBJECT +public: + CallModelBase(QObject* parent = 0); + virtual bool changeConference ( const QString &confId, const QString &state ) = 0; + virtual void removeConference ( const QString &confId ) = 0; + virtual Call* addConference ( const QString &confID ) = 0; + virtual Call* findCallByCallId ( QString callId ) = 0; + virtual Call* addRingingCall ( const QString& callId ) = 0; + virtual Call* addIncomingCall ( const QString& callId ) = 0; + virtual Call* addCall ( Call* call , Call* parent =0 ); + virtual Call* getCall ( const QString callId ) const = 0; +public slots: + void on1_callStateChanged ( const QString& callID , const QString &state ); + void on1_incomingCall ( const QString& accountID , const QString & callID ); + void on1_incomingConference ( const QString& confID ); + void on1_changingConference ( const QString& confID , const QString &state ); + void on1_conferenceRemoved ( const QString& confId ); + void on1_voiceMailNotify ( const QString& accountID , int count ); + void on1_volumeChanged ( const QString& device , double value ); +private: + static bool dbusInit; +signals: + void callStateChanged (Call* call ); + void incomingCall (Call* call ); + void conferenceCreated (Call* conf ); + void conferenceChanged (Call* conf ); + void conferenceRemoved (const QString& confId ); + void aboutToRemoveConference (Call* conf ); + void voiceMailNotify (const QString& accountID , int count ); + void volumeChanged (const QString& device , double value ); + void callAdded (Call* call , Call* parent ); +}; + /** * Note from the author: It was previously done by a QAbstractModel + QTreeView, but the sip-call use case is incompatible * 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 * solution may be less "clean" than MVC, but is 3 time smaller and easier to improve (in fact, possible to improve). */ template <typename CallWidget, typename Index> -class LIB_EXPORT CallModel { - //Q_OBJECT +class LIB_EXPORT CallModel : public CallModelBase { public: enum ModelType { ActiveCall, @@ -76,8 +110,8 @@ class LIB_EXPORT CallModel { bool mergeConferences ( Call* conf1, Call* conf2 ); bool addParticipant ( Call* call2, Call* conference ); bool detachParticipant ( Call* call ); - virtual bool conferenceChanged ( const QString &confId, const QString &state ); - virtual void conferenceRemoved ( const QString &confId ); + virtual bool changeConference ( const QString &confId, const QString &state ); + virtual void removeConference ( const QString &confId ); virtual Call* addConference ( const QString &confID ); void removeConference ( Call* call ); diff --git a/src/CallModel.hpp b/src/CallModel.hpp index ef6bec6f7a7992636d9c611cac68b86625bdf49c..2d89323c286d34ac2a83f0800795bcd29828bb15 100644 --- a/src/CallModel.hpp +++ b/src/CallModel.hpp @@ -20,7 +20,7 @@ template <typename CallWidget, typename Index> typename CallModel<CallWidget,In ****************************************************************************/ ///Retrieve current and older calls from the daemon, fill history and the calls TreeView and enable drag n' drop -template<typename CallWidget, typename Index> CallModel<CallWidget,Index>::CallModel(ModelType type) +template<typename CallWidget, typename Index> CallModel<CallWidget,Index>::CallModel(ModelType type) : CallModelBase(0) { Q_UNUSED(type) init(); @@ -135,6 +135,7 @@ template<typename CallWidget, typename Index> QList<Call*> CallModel<CallWidget, template<typename CallWidget, typename Index> Call* CallModel<CallWidget,Index>::addCall(Call* call, Call* parent) { Q_UNUSED(parent) + qDebug() << "-------------------Adding call" << call << "-------------------"; InternalStruct* aNewStruct = new InternalStruct; aNewStruct->call_real = call; aNewStruct->conference = false; @@ -143,7 +144,7 @@ template<typename CallWidget, typename Index> Call* CallModel<CallWidget,Index>: m_pPrivateCallList_callId[call->getCallId()] = aNewStruct; //setCurrentItem(callItem); - + CallModelBase::addCall(call,parent); return call; } @@ -245,9 +246,10 @@ template<typename CallWidget, typename Index> Call* CallModel<CallWidget,Index>: InternalStruct* aNewStruct = new InternalStruct; aNewStruct->call_real = newConf; + aNewStruct->conference = true; - m_pPrivateCallList_call[newConf] = aNewStruct; - m_pPrivateCallList_callId[newConf->getConfId()] = aNewStruct; //WARNING It may break something is it is done wrong + m_pPrivateCallList_call[newConf] = aNewStruct; + m_pPrivateCallList_callId[confID] = aNewStruct; return newConf; } @@ -292,7 +294,7 @@ template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>:: } ///Executed when the daemon signal a modification in an existing conference. Update the call list and update the TreeView -template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>::conferenceChanged(const QString& confId, const QString& state) +template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>::changeConference(const QString& confId, const QString& state) { qDebug() << "Conf changed2"; Q_UNUSED(state) @@ -310,7 +312,7 @@ template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>:: } ///Remove a conference from the model and the TreeView -template<typename CallWidget, typename Index> void CallModel<CallWidget,Index>::conferenceRemoved(const QString &confId) +template<typename CallWidget, typename Index> void CallModel<CallWidget,Index>::removeConference(const QString &confId) { qDebug() << "Ending conversation containing " << m_pPrivateCallList_callId[confId]->children.size() << " participants"; removeConference(getCall(confId)); @@ -539,7 +541,7 @@ template<typename CallWidget, typename Index> QList<Call*> CallModel<CallWidget, ///Update the index associated with this call template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>::updateIndex (Call* call, Index value ) -{ +{ if (!m_pPrivateCallList_call[call]) { m_pPrivateCallList_call[call] = new InternalStruct; m_pPrivateCallList_call[call]->call_real = call; diff --git a/src/sflphone_const.h b/src/sflphone_const.h index 71b65a2837c5a8c67a9d6988cd092b2dda3ff514..4ddd9ce0c5b5332f3042585340f6df05aac3b005 100644 --- a/src/sflphone_const.h +++ b/src/sflphone_const.h @@ -282,27 +282,27 @@ typedef enum { /** Ringing incoming call */ - CALL_STATE_INCOMING, + CALL_STATE_INCOMING =0, /** Ringing outgoing call */ - CALL_STATE_RINGING, + CALL_STATE_RINGING=1, /** Call to which the user can speak and hear */ - CALL_STATE_CURRENT, + CALL_STATE_CURRENT=2, /** Call which numbers are being added by the user */ - CALL_STATE_DIALING, + CALL_STATE_DIALING=3, /** Call is on hold */ - CALL_STATE_HOLD, + CALL_STATE_HOLD=4, /** Call has failed */ - CALL_STATE_FAILURE, + CALL_STATE_FAILURE=5, /** Call is busy */ - CALL_STATE_BUSY, + CALL_STATE_BUSY=6, /** Call is being transfered. During this state, the user can enter the new number. */ - CALL_STATE_TRANSFER, + CALL_STATE_TRANSFER=7, /** Call is on hold for transfer */ - CALL_STATE_TRANSF_HOLD, + CALL_STATE_TRANSF_HOLD=8, /** Call is over and should not be used */ - CALL_STATE_OVER, + CALL_STATE_OVER=9, /** This state should never be reached */ - CALL_STATE_ERROR + CALL_STATE_ERROR=10 } call_state; /** MIME API */