22 #include "contactcompletionmodel_p.h"
24 #include <akonadi/changerecorder.h>
25 #include <akonadi/entitymimetypefiltermodel.h>
26 #include <akonadi/itemfetchscope.h>
27 #include <akonadi/session.h>
29 #include <kabc/addressee.h>
31 using namespace Akonadi;
41 ChangeRecorder *monitor =
new ChangeRecorder;
42 monitor->fetchCollection(
true );
43 monitor->itemFetchScope().fetchFullPayload();
44 monitor->setCollectionMonitored( Akonadi::Collection::root() );
45 monitor->setMimeTypeMonitored( KABC::Addressee::mimeType() );
47 ContactCompletionModel *model =
new ContactCompletionModel( monitor );
49 EntityMimeTypeFilterModel *
filter =
new Akonadi::EntityMimeTypeFilterModel( model );
50 filter->setSourceModel( model );
51 filter->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
52 filter->addMimeTypeExclusionFilter( Akonadi::Collection::virtualMimeType() );
53 filter->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
60 ContactCompletionModel::ContactCompletionModel( ChangeRecorder *monitor,
QObject *parent )
61 : EntityTreeModel( monitor, parent )
63 setCollectionFetchStrategy( InvisibleCollectionFetch );
66 ContactCompletionModel::~ContactCompletionModel()
70 QVariant ContactCompletionModel::entityData(
const Item &item,
int column,
int role )
const
72 if ( !item.hasPayload<KABC::Addressee>() ) {
74 if ( role == Qt::DisplayRole ) {
75 return item.remoteId();
81 if ( role == Qt::DisplayRole || role == Qt::EditRole ) {
82 const KABC::Addressee contact = item.payload<KABC::Addressee>();
86 if ( !contact.formattedName().isEmpty() ) {
87 return contact.formattedName();
89 return contact.assembledName();
92 case NameAndEmailColumn:
95 .arg( contact.familyName() ).simplified();
112 return contact.preferredEmail();
117 return EntityTreeModel::entityData( item, column, role );
120 QVariant ContactCompletionModel::entityData(
const Collection &collection,
int column,
int role )
const
122 return EntityTreeModel::entityData( collection, column, role );
125 int ContactCompletionModel::columnCount(
const QModelIndex &parent )
const
134 int ContactCompletionModel::entityColumnCount( HeaderGroup )
const
139 #include "moc_contactcompletionmodel_p.cpp"
QString simplified() const
QString fromLatin1(const char *str, int size)
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const