• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
contactcompletionmodel.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "contactcompletionmodel_p.h"
23
24#include <akonadi/changerecorder.h>
25#include <akonadi/entitymimetypefiltermodel.h>
26#include <akonadi/itemfetchscope.h>
27#include <akonadi/session.h>
28
29#include <kabc/addressee.h>
30
31using namespace Akonadi;
32
33QAbstractItemModel* ContactCompletionModel::mSelf = 0;
34
35QAbstractItemModel* ContactCompletionModel::self()
36{
37 if ( mSelf ) {
38 return mSelf;
39 }
40
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() );
46
47 ContactCompletionModel *model = new ContactCompletionModel( monitor );
48
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 );
54
55 mSelf = filter;
56
57 return mSelf;
58}
59
60ContactCompletionModel::ContactCompletionModel( ChangeRecorder *monitor, QObject *parent )
61 : EntityTreeModel( monitor, parent )
62{
63 setCollectionFetchStrategy( InvisibleCollectionFetch );
64}
65
66ContactCompletionModel::~ContactCompletionModel()
67{
68}
69
70QVariant ContactCompletionModel::entityData( const Item &item, int column, int role ) const
71{
72 if ( !item.hasPayload<KABC::Addressee>() ) {
73 // Pass modeltest
74 if ( role == Qt::DisplayRole ) {
75 return item.remoteId();
76 }
77
78 return QVariant();
79 }
80
81 if ( role == Qt::DisplayRole || role == Qt::EditRole ) {
82 const KABC::Addressee contact = item.payload<KABC::Addressee>();
83
84 switch ( column ) {
85 case NameColumn:
86 if ( !contact.formattedName().isEmpty() ) {
87 return contact.formattedName();
88 } else {
89 return contact.assembledName();
90 }
91 break;
92 case NameAndEmailColumn:
93 {
94 QString name = QString::fromLatin1( "%1 %2" ).arg( contact.givenName() )
95 .arg( contact.familyName() ).simplified();
96 if ( name.isEmpty() ) {
97 name = contact.organization().simplified();
98 }
99 if ( name.isEmpty() ) {
100 return QString();
101 }
102
103 const QString email = contact.preferredEmail().simplified();
104 if ( email.isEmpty() ) {
105 return QString();
106 }
107
108 return QString::fromLatin1( "%1 <%2>" ).arg( name ).arg( email );
109 }
110 break;
111 case EmailColumn:
112 return contact.preferredEmail();
113 break;
114 }
115 }
116
117 return EntityTreeModel::entityData( item, column, role );
118}
119
120QVariant ContactCompletionModel::entityData( const Collection &collection, int column, int role ) const
121{
122 return EntityTreeModel::entityData( collection, column, role );
123}
124
125int ContactCompletionModel::columnCount( const QModelIndex &parent ) const
126{
127 if ( !parent.isValid() ) {
128 return 3;
129 } else {
130 return 0;
131 }
132}
133
134int ContactCompletionModel::entityColumnCount( HeaderGroup ) const
135{
136 return 3;
137}
138
139#include "moc_contactcompletionmodel_p.cpp"
Akonadi::ChangeRecorder
Records and replays change notification.
Definition changerecorder.h:48
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::Collection::mimeType
static QString mimeType()
Returns the mimetype used for collections.
Definition collection.cpp:197
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition collection.cpp:192
Akonadi::Collection::virtualMimeType
static QString virtualMimeType()
Returns the mimetype used for virtual collections.
Definition collection.cpp:202
Akonadi::EntityMimeTypeFilterModel
A proxy model that filters entities by mime type.
Definition entitymimetypefiltermodel.h:62
Akonadi::EntityMimeTypeFilterModel::setHeaderGroup
void setHeaderGroup(EntityTreeModel::HeaderGroup headerGroup)
Sets the header set of the filter model.
Definition entitymimetypefiltermodel.cpp:152
Akonadi::EntityMimeTypeFilterModel::addMimeTypeExclusionFilter
void addMimeTypeExclusionFilter(const QString &mimeType)
Add mime type to be excluded by the filter.
Definition entitymimetypefiltermodel.cpp:92
Akonadi::EntityTreeModel
A model for collections and items together.
Definition entitytreemodel.h:319
Akonadi::EntityTreeModel::entityData
virtual QVariant entityData(const Item &item, int column, int role=Qt::DisplayRole) const
Provided for convenience of subclasses.
Definition entitytreemodel.cpp:173
Akonadi::EntityTreeModel::ItemListHeaders
@ ItemListHeaders
Header information for a list of items.
Definition entitytreemodel.h:386
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition itemfetchscope.cpp:70
Akonadi::Monitor::setMimeTypeMonitored
void setMimeTypeMonitored(const QString &mimetype, bool monitored=true)
Sets whether items of the specified mime type shall be monitored for changes.
Definition monitor.cpp:126
Akonadi::Monitor::itemFetchScope
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition monitor.cpp:237
Akonadi::Monitor::setCollectionMonitored
void setCollectionMonitored(const Collection &collection, bool monitored=true)
Sets whether the specified collection shall be monitored for changes.
Definition monitor.cpp:66
Akonadi::Monitor::fetchCollection
void fetchCollection(bool enable)
Enables automatic fetching of changed collections from the Akonadi storage.
Definition monitor.cpp:219
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal