2
This file is part of KContactManager.
4
Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
5
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License along
18
with this program; if not, write to the Free Software Foundation, Inc.,
19
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include "contactstreemodel.h"
24
#include <kabc/addressee.h>
25
#include <kabc/contactgroup.h>
29
using namespace Akonadi;
31
ContactsTreeModel::ContactsTreeModel( Session *session, Monitor *monitor, QObject *parent )
32
: EntityTreeModel( session, monitor, parent )
36
ContactsTreeModel::~ContactsTreeModel()
40
QVariant ContactsTreeModel::getData( const Item &item, int column, int role ) const
42
if ( item.mimeType() == KABC::Addressee::mimeType() ) {
43
if ( !item.hasPayload<KABC::Addressee>() ) {
46
if ( role == Qt::DisplayRole )
47
return item.remoteId();
52
const KABC::Addressee contact = item.payload<KABC::Addressee>();
54
if ( role == Qt::DecorationRole ) {
56
const KABC::Picture picture = contact.photo();
57
if ( picture.isIntern() ) {
58
return picture.data().scaled( QSize( 16, 16 ) );
60
return KIcon( QLatin1String( "x-office-contact" ) );
64
} else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
67
if ( !contact.formattedName().isEmpty() )
68
return contact.formattedName();
70
return contact.assembledName();
72
return contact.givenName();
75
return contact.familyName();
78
return contact.preferredEmail();
84
} else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
85
if ( !item.hasPayload<KABC::ContactGroup>() ) {
88
if ( role == Qt::DisplayRole )
89
return item.remoteId();
94
if ( role == Qt::DecorationRole ) {
96
return KIcon( QLatin1String( "x-mail-distribution-list" ) );
99
} else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
103
const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
113
return EntityTreeModel::getData( item, column, role );
116
QVariant ContactsTreeModel::getData( const Collection &collection, int column, int role ) const
118
if ( role == Qt::DisplayRole ) {
121
return EntityTreeModel::getData( collection, column, role );
123
return QString(); // pass model test
127
return EntityTreeModel::getData( collection, column, role );
130
int ContactsTreeModel::columnCount( const QModelIndex &index ) const
136
QVariant ContactsTreeModel::getHeaderData( int section, Qt::Orientation orientation, int role, int headerSet ) const
138
if ( role == Qt::DisplayRole ) {
139
if ( orientation == Qt::Horizontal ) {
140
if ( headerSet == EntityTreeModel::CollectionTreeHeaders ) {
147
return i18nc( "@title:column, address books overview", "Address Books" );
150
} else if ( headerSet == EntityTreeModel::ItemListHeaders ) {
156
return i18nc( "@title:column, name of a person", "Name" );
159
return KABC::Addressee::givenNameLabel();
162
return KABC::Addressee::familyNameLabel();
165
return KABC::Addressee::emailLabel();
172
return EntityTreeModel::getHeaderData( section, orientation, role, headerSet );
175
#include "contactstreemodel.moc"