Commit d5893eb8 authored by Emmanuel Lepage's avatar Emmanuel Lepage

Complete contact support is back

parent 39764571
...@@ -31,7 +31,6 @@ ActionSetAccountFirst::ActionSetAccountFirst(Account* account, QObject *parent) ...@@ -31,7 +31,6 @@ ActionSetAccountFirst::ActionSetAccountFirst(Account* account, QObject *parent)
this, SLOT(emitSetFirst())); this, SLOT(emitSetFirst()));
} }
ActionSetAccountFirst::~ActionSetAccountFirst() ActionSetAccountFirst::~ActionSetAccountFirst()
{ {
} }
......
...@@ -4,44 +4,109 @@ ...@@ -4,44 +4,109 @@
#include <akonadi/collectionfilterproxymodel.h> #include <akonadi/collectionfilterproxymodel.h>
#include <akonadi/collectionmodel.h> #include <akonadi/collectionmodel.h>
#include <akonadi/kmime/messagemodel.h> #include <akonadi/kmime/messagemodel.h>
#include <contactgroupsearchjob.h> #include <kabc/contactgroup.h>
#include <kabc/phonenumber.h>
#include <akonadi/recursiveitemfetchjob.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/collectionfetchjob.h>
#include <akonadi/collectionfetchscope.h>
#include "lib/Contact.h"
AkonadiBackend* AkonadiBackend::m_pInstance = 0;
AkonadiBackend::AkonadiBackend(QObject* parent) : QObject(parent) AkonadiBackend::AkonadiBackend(QObject* parent) : QObject(parent)
{ {
QTimer::singleShot( 0, this, SLOT( delayedInit() ) ); //QTimer::singleShot( 0, this, SLOT( delayedInit() ) );
m_pSession = new Akonadi::Session( "SFLPhone::instance" );
// fetching all collections containing emails recursively, starting at the root collection
Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive, this );
job->fetchScope().setContentMimeTypes( QStringList() << "text/directory" );
connect( job, SIGNAL( collectionsReceived( const Akonadi::Collection::List& ) ), this, SLOT( collectionsReceived( const Akonadi::Collection::List& ) ) );
} }
virtual AkonadiBackend::~AkonadiBackend() AkonadiBackend::~AkonadiBackend()
{ {
} }
AkonadiBackend* AkonadiBackend::getInstance() AkonadiBackend* AkonadiBackend::getInstance()
{ {
if (m_pInstance == NULL) {
m_pInstance = new AkonadiBackend(0);
}
return m_pInstance;
} }
static bool AkonadiBackend::init() ContactList AkonadiBackend::update(Akonadi::Collection collection)
{ {
if ( !Akonadi::Control::start( this ) ) { m_pCollection = collection;
return false; ContactList contacts;
if ( !collection.isValid() ) {
qDebug() << "The current collection is not valid";
return contacts;
}
Akonadi::RecursiveItemFetchJob *job = new Akonadi::RecursiveItemFetchJob( collection, QStringList() << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType());
job->fetchScope().fetchFullPayload();
if ( job->exec() ) {
const Akonadi::Item::List items = job->items();
foreach ( const Akonadi::Item &item, items ) {
if ( item.hasPayload<KABC::ContactGroup>() ) {
qDebug() << "Group:" << item.payload<KABC::ContactGroup>().name();
}
if ( item.hasPayload<KABC::Addressee>() ) {
KABC::Addressee tmp = item.payload<KABC::Addressee>();
Contact* aContact = new Contact();
KABC::PhoneNumber::List numbers = tmp.phoneNumbers();
PhoneNumbers newNumbers;
foreach (KABC::PhoneNumber number, numbers) {
newNumbers << new Contact::PhoneNumber(number.number(),number.typeLabel());
m_pContactByPhone[number.number()] = aContact;
}
aContact->setNickName (tmp.nickName() );
aContact->setFormattedName (tmp.formattedName() );
aContact->setFirstName (tmp.givenName() );
aContact->setFamilyName (tmp.familyName() );
aContact->setOrganization (tmp.organization() );
aContact->setPreferredEmail (tmp.preferredEmail() );
aContact->setPhoneNumbers (newNumbers );
if (!tmp.photo().data().isNull())
aContact->setPhoto(new QPixmap(QPixmap::fromImage( tmp.photo().data()).scaled(QSize(48,48))));
else
aContact->setPhoto(0);
contacts << aContact;
}
}
} }
return true;
qDebug() << "End collect "<< contacts.size() << "\n\n\n";
return contacts;
} }
void AkonadiBackend::createModels() ContactList AkonadiBackend::update()
{
return update(m_pCollection);
}
Contact* AkonadiBackend::getContactByPhone(QString phoneNumber)
{ {
Akonadi::CollectionModel *collectionModel = new Akonadi::CollectionModel( this ); return m_pContactByPhone[phoneNumber];
}
Akonadi::CollectionFilterProxyModel *filterModel = new Akonadi::CollectionFilterProxyModel( this );
filterModel->setSourceModel( collectionModel ); void AkonadiBackend::collectionsReceived( const Akonadi::Collection::List& list)
filterModel->addMimeTypeFilter( QLatin1String( "message/rfc822" ) ); {
foreach (Akonadi::Collection coll, list) {
Akonadi::ItemModel *itemModel = new Akonadi::MessageModel( this ); qDebug() << "\n\n\n\n\n\nLoading collection" << coll.name();
update(coll);
ui_detacherview_base.folderView->setModel( filterModel ); emit collectionChanged();
ui_detacherview_base.messageView->setModel( itemModel ); }
connect( ui_detacherview_base.folderView, SIGNAL( currentChanged( Akonadi::Collection ) ),
itemModel, SLOT( setCollection( Akonadi::Collection ) ) );
} }
\ No newline at end of file
...@@ -2,17 +2,37 @@ ...@@ -2,17 +2,37 @@
#define AKONADI_BACKEND_H #define AKONADI_BACKEND_H
#include <QObject> #include <QObject>
#include <akonadi/session.h>
#include <akonadi/collectionmodel.h>
#include <kabc/addressee.h>
#include <kabc/addresseelist.h>
class Contact;
typedef QList<Contact*> ContactList;
class AkonadiBackend : public QObject { class AkonadiBackend : public QObject {
Q_OBJECT
public: public:
AkonadiBackend* getInstance(); static AkonadiBackend* getInstance();
Contact* getContactByPhone(QString phoneNumber);
private: private:
AkonadiBackend(QObject* parent); AkonadiBackend(QObject* parent);
virtual ~AkonadiBackend(); virtual ~AkonadiBackend();
static bool init();
//Attributes //Attributes
AkonadiBackend* instance; static AkonadiBackend* m_pInstance;
Akonadi::Session* m_pSession;
Akonadi::Collection m_pCollection;
QHash<QString,Contact*> m_pContactByPhone;
public slots:
ContactList update();
ContactList update(Akonadi::Collection collection);
void collectionsReceived( const Akonadi::Collection::List& );
signals:
void collectionChanged();
}; };
#endif #endif
\ No newline at end of file
...@@ -45,6 +45,7 @@ SET( sflphone_client_kde_SRCS ...@@ -45,6 +45,7 @@ SET( sflphone_client_kde_SRCS
widgets/BookmarkDock.cpp widgets/BookmarkDock.cpp
Codec.cpp Codec.cpp
AccountListModel.cpp AccountListModel.cpp
AkonadiBackend.cpp
CallView.cpp CallView.cpp
AccountView.cpp AccountView.cpp
) )
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "lib/sflphone_const.h" #include "lib/sflphone_const.h"
#include "lib/instance_interface_singleton.h" #include "lib/instance_interface_singleton.h"
#include "lib/configurationmanager_interface_singleton.h" #include "lib/configurationmanager_interface_singleton.h"
#include "lib/Contact.h"
#include "AkonadiBackend.h"
SFLPhone* SFLPhone::m_sApp = NULL; SFLPhone* SFLPhone::m_sApp = NULL;
...@@ -278,24 +280,6 @@ void SFLPhone::quitButton() ...@@ -278,24 +280,6 @@ void SFLPhone::quitButton()
qApp->quit(); qApp->quit();
} }
void SFLPhone::sendNotif(QString caller)
{
// notification = new KNotification ( QString("test_notification"), this );
// notification->setText("messageText") ;
// notification->setPixmap( QPixmap( this->windowIcon().pixmap(32, 32) ));
// notification->setActions( QStringList( i18n( "Open chat" ) ) );
// notification->addContext( QString::fromLatin1("call") , "caller" ) ;
// notification->sendEvent();
// KNotification::event(QString("test_notification"),
// QString("Allo"),
// this->windowIcon().pixmap(32, 32),
// parentWidget(),
// KNotification::CloseOnTimeout,
// KGlobal::mainComponent());
KNotification::event(KNotification::Notification, "New incomming call", "New call from: \n" + caller);
}
void SFLPhone::changeEvent(QEvent* event) void SFLPhone::changeEvent(QEvent* event)
{ {
if (event->type() == QEvent::ActivationChange && iconChanged && isActiveWindow()) { if (event->type() == QEvent::ActivationChange && iconChanged && isActiveWindow()) {
...@@ -397,7 +381,11 @@ void SFLPhone::on_m_pView_incomingCall(const Call * call) ...@@ -397,7 +381,11 @@ void SFLPhone::on_m_pView_incomingCall(const Call * call)
putForeground(); putForeground();
}*/ }*/
//if(configurationManager.getNotify()) { //if(configurationManager.getNotify()) {
sendNotif(call->getPeerName().isEmpty() ? call->getPeerPhoneNumber() : call->getPeerName()); Contact* contact = AkonadiBackend::getInstance()->getContactByPhone(call->getPeerPhoneNumber());
if (contact) {
KNotification::event(KNotification::Notification, "New incomming call", "New call from: \n" + call->getPeerName().isEmpty() ? call->getPeerPhoneNumber() : call->getPeerName(),*contact->getPhoto());
}
KNotification::event(KNotification::Notification, "New incomming call", "New call from: \n" + call->getPeerName().isEmpty() ? call->getPeerPhoneNumber() : call->getPeerName());
//} //}
} }
......
...@@ -121,7 +121,6 @@ public: ...@@ -121,7 +121,6 @@ public:
~SFLPhone(); ~SFLPhone();
bool initialize(); bool initialize();
void setupActions(); void setupActions();
void sendNotif(QString caller);
void trayIconSignal(); void trayIconSignal();
SFLPhoneView * getView(); SFLPhoneView * getView();
QList<QAction *> getCallActions(); QList<QAction *> getCallActions();
......
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
<entry name="displayDataRange" type="Bool"> <entry name="displayDataRange" type="Bool">
<label>Defines whether call history is restricted to a specific date range</label> <label>Defines whether call history is restricted to a specific date range</label>
</entry> </entry>
<entry name="displayContactCallHistory" type="Bool">
<label>Defines if the individual contact history list is visible</label>
</entry>
<!-- Audio Settings --> <!-- Audio Settings -->
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
const call_state Call::actionPerformedStateMap [11][5] = const call_state Call::actionPerformedStateMap [11][5] =
{ {
// ACCEPT REFUSE TRANSFER HOLD RECORD // ACCEPT REFUSE TRANSFER HOLD RECORD
/*INCOMING */ {CALL_STATE_INCOMING , CALL_STATE_INCOMING , CALL_STATE_ERROR , CALL_STATE_INCOMING , CALL_STATE_INCOMING }, /*INCOMING */ {CALL_STATE_INCOMING , CALL_STATE_INCOMING , CALL_STATE_ERROR , CALL_STATE_INCOMING , CALL_STATE_INCOMING },
/*RINGING */ {CALL_STATE_ERROR , CALL_STATE_RINGING , CALL_STATE_ERROR , CALL_STATE_ERROR , CALL_STATE_RINGING }, /*RINGING */ {CALL_STATE_ERROR , CALL_STATE_RINGING , CALL_STATE_ERROR , CALL_STATE_ERROR , CALL_STATE_RINGING },
/*CURRENT */ {CALL_STATE_ERROR , CALL_STATE_CURRENT , CALL_STATE_TRANSFER , CALL_STATE_CURRENT , CALL_STATE_CURRENT }, /*CURRENT */ {CALL_STATE_ERROR , CALL_STATE_CURRENT , CALL_STATE_TRANSFER , CALL_STATE_CURRENT , CALL_STATE_CURRENT },
...@@ -45,7 +45,7 @@ const call_state Call::actionPerformedStateMap [11][5] = ...@@ -45,7 +45,7 @@ const call_state Call::actionPerformedStateMap [11][5] =
const function Call::actionPerformedFunctionMap[11][5] = const function Call::actionPerformedFunctionMap[11][5] =
{ {
// ACCEPT REFUSE TRANSFER HOLD RECORD // ACCEPT REFUSE TRANSFER HOLD RECORD
/*INCOMING */ {&Call::accept , &Call::refuse , &Call::acceptTransf , &Call::acceptHold , &Call::setRecord }, /*INCOMING */ {&Call::accept , &Call::refuse , &Call::acceptTransf , &Call::acceptHold , &Call::setRecord },
/*RINGING */ {&Call::nothing , &Call::hangUp , &Call::nothing , &Call::nothing , &Call::setRecord }, /*RINGING */ {&Call::nothing , &Call::hangUp , &Call::nothing , &Call::nothing , &Call::setRecord },
/*CURRENT */ {&Call::nothing , &Call::hangUp , &Call::nothing , &Call::hold , &Call::setRecord }, /*CURRENT */ {&Call::nothing , &Call::hangUp , &Call::nothing , &Call::hold , &Call::setRecord },
...@@ -62,7 +62,7 @@ const function Call::actionPerformedFunctionMap[11][5] = ...@@ -62,7 +62,7 @@ const function Call::actionPerformedFunctionMap[11][5] =
const call_state Call::stateChangedStateMap [11][6] = const call_state Call::stateChangedStateMap [11][6] =
{ {
// RINGING CURRENT BUSY HOLD HUNGUP FAILURE // RINGING CURRENT BUSY HOLD HUNGUP FAILURE
/*INCOMING */ {CALL_STATE_INCOMING , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE }, /*INCOMING */ {CALL_STATE_INCOMING , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE },
/*RINGING */ {CALL_STATE_RINGING , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE }, /*RINGING */ {CALL_STATE_RINGING , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE },
/*CURRENT */ {CALL_STATE_CURRENT , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE }, /*CURRENT */ {CALL_STATE_CURRENT , CALL_STATE_CURRENT , CALL_STATE_BUSY , CALL_STATE_HOLD , CALL_STATE_OVER , CALL_STATE_FAILURE },
...@@ -78,9 +78,9 @@ const call_state Call::stateChangedStateMap [11][6] = ...@@ -78,9 +78,9 @@ const call_state Call::stateChangedStateMap [11][6] =
const function Call::stateChangedFunctionMap[11][6] = const function Call::stateChangedFunctionMap[11][6] =
{ {
// RINGING CURRENT BUSY HOLD HUNGUP FAILURE // RINGING CURRENT BUSY HOLD HUNGUP FAILURE
/*INCOMING */ {&Call::nothing , &Call::start , &Call::startWeird , &Call::startWeird , &Call::startStop , &Call::start }, /*INCOMING */ {&Call::nothing , &Call::start , &Call::startWeird , &Call::startWeird , &Call::startStop , &Call::start },
/*RINGING */ {&Call::nothing , &Call::start , &Call::start , &Call::start , &Call::startStop , &Call::start }, /*RINGING */ {&Call::nothing , &Call::start , &Call::start , &Call::start , &Call::startStop , &Call::start },
/*CURRENT */ {&Call::nothing , &Call::nothing , &Call::warning , &Call::nothing , &Call::stop , &Call::nothing }, /*CURRENT */ {&Call::nothing , &Call::nothing , &Call::warning , &Call::nothing , &Call::stop , &Call::nothing },
/*DIALING */ {&Call::nothing , &Call::warning , &Call::warning , &Call::warning , &Call::stop , &Call::warning }, /*DIALING */ {&Call::nothing , &Call::warning , &Call::warning , &Call::warning , &Call::stop , &Call::warning },
/*HOLD */ {&Call::nothing , &Call::nothing , &Call::warning , &Call::nothing , &Call::stop , &Call::nothing }, /*HOLD */ {&Call::nothing , &Call::nothing , &Call::warning , &Call::nothing , &Call::stop , &Call::nothing },
......
...@@ -46,7 +46,7 @@ Contact::Contact() ...@@ -46,7 +46,7 @@ Contact::Contact()
Contact::~Contact() Contact::~Contact()
{ {
delete photo; delete m_pPhoto;
} }
void Contact::initItem() void Contact::initItem()
...@@ -59,34 +59,88 @@ void Contact::initItemWidget() ...@@ -59,34 +59,88 @@ void Contact::initItemWidget()
} }
QString Contact::getPhoneNumber() const PhoneNumbers Contact::getPhoneNumbers() const
{ {
return phoneNumber; return m_pNumbers;
} }
QString Contact::getNickName() const QString Contact::getNickName() const
{ {
return nickName; return m_pNickName;
} }
QString Contact::getFirstName() const QString Contact::getFirstName() const
{ {
return firstName; return m_pFirstName;
} }
QString Contact::getSecondName() const QString Contact::getSecondName() const
{ {
return secondName; return m_pSecondName;
} }
const QPixmap* Contact::getPhoto() const const QPixmap* Contact::getPhoto() const
{ {
return photo; return m_pPhoto;
}
QString Contact::getFormattedName() const
{
return m_pFormattedName;
}
QString Contact::getOrganization() const
{
return m_pOrganization;
}
QString Contact::getPreferredEmail() const
{
return m_pPreferredEmail;
} }
QString Contact::getType() const QString Contact::getType() const
{ {
return type; return m_pType;
}
void Contact::setPhoneNumbers(PhoneNumbers numbers)
{
m_pNumbers = numbers;
} }
void Contact::setNickName(QString name)
{
m_pNickName = name;
}
void Contact::setFirstName(QString name)
{
m_pFirstName = name;
}
void Contact::setFamilyName(QString name)
{
m_pSecondName = name;
}
void Contact::setPhoto(QPixmap* photo)
{
m_pPhoto = photo;
}
void Contact::setFormattedName(QString name)
{
m_pFormattedName = name;
}
void Contact::setOrganization(QString name)
{
m_pOrganization = name;
}
void Contact::setPreferredEmail(QString name)
{
m_pPreferredEmail = name;
}
\ No newline at end of file
...@@ -36,33 +36,65 @@ ...@@ -36,33 +36,65 @@
@author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> @author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>
*/ */
class LIB_EXPORT Contact : public QObject{ class LIB_EXPORT Contact : public QObject{
private: Q_OBJECT
QString firstName; public:
QString secondName; class PhoneNumber {
QString nickName; public:
QString phoneNumber; PhoneNumber(QString number, QString type)
QPixmap* photo; : m_pNumber(number),m_pType(type){}
QString type; QString& getNumber() {
bool displayPhoto; return m_pNumber ;
}
QString& getType() {
return m_pType ;
}
private:
QString m_pNumber ;
QString m_pType ;
};
typedef QList<Contact::PhoneNumber*> PhoneNumbers;
private:
QString m_pFirstName ;
QString m_pSecondName ;
QString m_pNickName ;
QPixmap* m_pPhoto ;
QString m_pType ;
QString m_pFormattedName ;
QString m_pPreferredEmail ;
QString m_pOrganization ;
bool displayPhoto ;
PhoneNumbers m_pNumbers ;
public: public:
//Constructors & Destructors //Constructors & Destructors
explicit Contact(); explicit Contact();
virtual ~Contact(); virtual ~Contact();
//Getters //Getters
virtual QString getPhoneNumber() const; virtual PhoneNumbers getPhoneNumbers() const;
virtual QString getNickName() const; virtual QString getNickName() const;
virtual QString getFirstName() const; virtual QString getFirstName() const;
virtual QString getSecondName() const; virtual QString getSecondName() const;
virtual const QPixmap* getPhoto() const; virtual QString getFormattedName() const;
virtual QString getType() const; virtual QString getOrganization() const;
virtual void initItem(); virtual QString getPreferredEmail() const;
virtual const QPixmap* getPhoto() const;
virtual QString getType() const;
virtual void initItem();
virtual void setPhoneNumbers (PhoneNumbers );
virtual void setFormattedName (QString name );
virtual void setNickName (QString name );
virtual void setFirstName (QString name );
virtual void setFamilyName (QString name );
virtual void setOrganization (QString name );
virtual void setPreferredEmail (QString name );
virtual void setPhoto (QPixmap* photo );
protected: protected:
virtual void initItemWidget(); virtual void initItemWidget();
}; };
typedef Contact::PhoneNumbers PhoneNumbers;
#endif #endif
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "lib/sflphone_const.h" #include "lib/sflphone_const.h"
#include "CallTreeItem.h" #include "CallTreeItem.h"
#include "lib/Contact.h"
#include "AkonadiBackend.h"
const char * CallTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE}; const char * CallTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE};
...@@ -65,10 +67,11 @@ void CallTreeItem::setCall(Call *call) ...@@ -65,10 +67,11 @@ void CallTreeItem::setCall(Call *call)
return; return;