diff --git a/src/Call.cpp b/src/Call.cpp index d3c4404b3c4207720e0fb91146d7e5e5b92d9396..30313bfdf476c939c73fc2b12cfed6c5f32ad60e 100644 --- a/src/Call.cpp +++ b/src/Call.cpp @@ -24,6 +24,8 @@ #include "callmanager_interface_singleton.h" #include "configurationmanager_interface_singleton.h" +#include "ContactBackend.h" +#include "Contact.h" const call_state Call::actionPerformedStateMap [11][5] = @@ -94,6 +96,13 @@ const function Call::stateChangedFunctionMap[11][6] = const char * Call::historyIcons[3] = {ICON_HISTORY_INCOMING, ICON_HISTORY_OUTGOING, ICON_HISTORY_MISSED}; +ContactBackend* Call::m_pContactBackend = 0; + +void Call::setContactBackend(ContactBackend* be) +{ + m_pContactBackend = be; +} + ///Constructor Call::Call(call_state startState, QString callId, QString peerName, QString peerNumber, QString account) : conference(false) @@ -318,13 +327,13 @@ QString Call::getStartTimeStamp() const ///Get the number where the call have been transferred QString Call::getTransferNumber() const { - return transferNumber; + return m_pTransferNumber; } ///Get the call / peer number QString Call::getCallNumber() const { - return callNumber; + return m_pCallNumber; } ///Return the call id @@ -416,13 +425,13 @@ bool Call::isSecure() const { ///Set the transfer number void Call::setTransferNumber(QString number) { - transferNumber = number; + m_pTransferNumber = number; } ///Set the call number void Call::setCallNumber(QString number) { - callNumber = number; + m_pCallNumber = number; emit changed(); } @@ -544,9 +553,9 @@ void Call::refuse() void Call::acceptTransf() { CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance(); - qDebug() << "Accepting call and transfering it to number : " << transferNumber << ". callId : " << m_pCallId; + qDebug() << "Accepting call and transfering it to number : " << m_pTransferNumber << ". callId : " << m_pCallId; callManager.accept(m_pCallId); - callManager.transfer(m_pCallId, transferNumber); + callManager.transfer(m_pCallId, m_pTransferNumber); // m_pHistoryState = TRANSFERED; } @@ -595,17 +604,19 @@ void Call::call() this->m_pAccount = CallModelConvenience::getCurrentAccountId(); } if(!m_pAccount.isEmpty()) { - qDebug() << "Calling " << callNumber << " with account " << m_pAccount << ". callId : " << m_pCallId; - callManager.placeCall(m_pAccount, m_pCallId, callNumber); + qDebug() << "Calling " << m_pCallNumber << " with account " << m_pAccount << ". callId : " << m_pCallId; + callManager.placeCall(m_pAccount, m_pCallId, m_pCallNumber); this->m_pAccount = m_pAccount; - this->m_pPeerPhoneNumber = callNumber; -// Contact * contact = findContactForNumberInKAddressBook(peerPhoneNumber); //TODO port -// if(contact) this->m_pPeerName = contact->getNickName(); + this->m_pPeerPhoneNumber = m_pCallNumber; + if (m_pContactBackend) { + Contact* contact = m_pContactBackend->getContactByPhone(m_pPeerPhoneNumber); + m_pPeerName = contact->getFormattedName(); + } this->m_pStartTime = new QDateTime(QDateTime::currentDateTime()); this->m_pHistoryState = OUTGOING; } else { - qDebug() << "Trying to call " << transferNumber << " with no account registered . callId : " << m_pCallId; + qDebug() << "Trying to call " << m_pTransferNumber << " with no account registered . callId : " << m_pCallId; this->m_pHistoryState = NONE; throw "No account registered!"; } @@ -615,8 +626,8 @@ void Call::call() void Call::transfer() { CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance(); - qDebug() << "Transfering call to number : " << transferNumber << ". callId : " << m_pCallId; - callManager.transfer(m_pCallId, transferNumber); + qDebug() << "Transfering call to number : " << m_pTransferNumber << ". callId : " << m_pCallId; + callManager.transfer(m_pCallId, m_pTransferNumber); this->m_pStopTime = new QDateTime(QDateTime::currentDateTime()); } @@ -694,10 +705,10 @@ void Call::appendText(QString str) switch (currentState) { case CALL_STATE_TRANSFER : case CALL_STATE_TRANSF_HOLD : - editNumber = &transferNumber; + editNumber = &m_pTransferNumber; break; case CALL_STATE_DIALING : - editNumber = &callNumber; + editNumber = &m_pCallNumber; break; default : qDebug() << "Backspace on call not editable. Doing nothing."; @@ -717,10 +728,10 @@ void Call::backspaceItemText() switch (currentState) { case CALL_STATE_TRANSFER : case CALL_STATE_TRANSF_HOLD : - editNumber = &transferNumber; + editNumber = &m_pTransferNumber; break; case CALL_STATE_DIALING : - editNumber = &callNumber; + editNumber = &m_pCallNumber; break; default : qDebug() << "Backspace on call not editable. Doing nothing."; diff --git a/src/Call.h b/src/Call.h index 97caa2625042e8afed9e6e235205063931bffe2a..0ad0ee8bb2bb169b724ba80f1010e65e11a09bba 100644 --- a/src/Call.h +++ b/src/Call.h @@ -31,6 +31,8 @@ #include "sflphone_const.h" #include "typedefs.h" +class ContactBackend; + /** @enum daemon_call_state_t * This enum have all the states a call can take for the daemon. @@ -134,8 +136,9 @@ private: QLabel * labelHistoryTime; */ - QString transferNumber; - QString callNumber; + QString m_pTransferNumber; + QString m_pCallNumber; + static ContactBackend* m_pContactBackend; bool conference; @@ -212,6 +215,7 @@ public: static Call* buildRingingCall (const QString & callId ); static Call* buildHistoryCall (const QString & callId, uint startTimeStamp, uint stopTimeStamp, QString account, QString name, QString number, QString type ); static Call* buildExistingCall (QString callId ); + static void setContactBackend (ContactBackend* be ); //Static getters static history_state getHistoryStateFromType ( QString type ); diff --git a/src/CallModel.h b/src/CallModel.h index 6853da3978be37671f4304773299da5904f3dc8f..cdd9c681ae6cb3a641134ed48e1ac93eb282c8d2 100644 --- a/src/CallModel.h +++ b/src/CallModel.h @@ -36,6 +36,7 @@ #include "sflphone_const.h" #include "unistd.h" #include "typedefs.h" +#include "ContactBackend.h" typedef QHash<QString, Call*> CallHash; typedef QList<Call*> CallList; @@ -90,10 +91,11 @@ class LIB_EXPORT CallModel : public CallModelBase { }; //Constructors, initializer and destructors - CallModel ( ModelType type ); - virtual ~CallModel ( ) {} - virtual bool initCall ( ); - virtual bool initHistory ( ); + CallModel ( ModelType type ); + virtual ~CallModel ( ) {} + virtual bool initCall ( ); + virtual bool initHistory ( ); + virtual void initContact ( ContactBackend* be ); //Call related virtual Call* addCall ( Call* call , Call* parent =0 ); diff --git a/src/CallModel.hpp b/src/CallModel.hpp index b81efc9834430ec6c1f88441a412e9fcb6d29086..54c74c2b21511f60d647d4ebfd05db2c74e2c271 100644 --- a/src/CallModel.hpp +++ b/src/CallModel.hpp @@ -65,6 +65,12 @@ template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>:: return true; } +///Set how the call can find more informations about the call it receive +template<typename CallWidget, typename Index> void CallModel<CallWidget,Index>::initContact ( ContactBackend* be ) +{ + Call::setContactBackend(be); +} + ///Fill the history list ///@warning This solution wont scale to multiple call or history model implementation. Some static addCall + foreach for each call would be needed if this case ever become unavoidable template<typename CallWidget, typename Index> bool CallModel<CallWidget,Index>::initHistory()