23#include "contactstreemodel.h"
25#include <kabc/addressee.h>
26#include <kabc/contactgroup.h>
29#include <kiconloader.h>
31#include <klocalizedstring.h>
35class ContactsTreeModel::Private
40 mIconSize( KIconLoader::global()->currentSize( KIconLoader::Small ) )
60 emit beginResetModel();
72 if ( item.mimeType() == KABC::Addressee::mimeType() ) {
73 if ( !item.hasPayload<KABC::Addressee>() ) {
76 if ( role == Qt::DisplayRole ) {
77 return item.remoteId();
83 const KABC::Addressee contact = item.payload<KABC::Addressee>();
85 if ( role == Qt::DecorationRole ) {
87 const KABC::Picture picture = contact.photo();
88 if ( picture.isIntern() ) {
89 return picture.data().scaled( QSize( d->mIconSize, d->mIconSize ), Qt::KeepAspectRatio );
91 return KIcon( QLatin1String(
"user-identity" ) );
95 }
else if ( ( role == Qt::DisplayRole ) || ( role == Qt::EditRole ) ) {
96 switch ( d->mColumns.at( column ) ) {
98 if ( contact.realName().isEmpty() ) {
99 if ( contact.preferredEmail().isEmpty() ) {
100 return contact.familyName();
102 return contact.preferredEmail();
104 return contact.realName();
106 return contact.familyName();
108 return contact.givenName();
110 if ( contact.birthday().date().isValid() ) {
111 return KGlobal::locale()->formatDate( contact.birthday().date(), KLocale::ShortDate );
116 const KABC::Address address = contact.address( KABC::Address::Home );
117 if ( !address.isEmpty() ) {
118 return address.formattedAddress();
124 const KABC::Address address = contact.address( KABC::Address::Work );
125 if ( !address.isEmpty() ) {
126 return address.formattedAddress();
134 const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
135 foreach (
const KABC::PhoneNumber &number, numbers ) {
136 values += number.number();
139 return values.join( QLatin1String(
"\n" ) );
143 return contact.preferredEmail();
145 return contact.emails().join( QLatin1String(
"\n" ) );
147 return contact.organization();
149 return contact.role();
151 return contact.url().url();
153 return contact.note();
156 if ( d->mColumns.at( column ) ==
Birthday ) {
157 return contact.birthday();
162 }
else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
163 if ( !item.hasPayload<KABC::ContactGroup>() ) {
166 if ( role == Qt::DisplayRole ) {
167 return item.remoteId();
173 if ( role == Qt::DecorationRole ) {
175 return KIcon( QLatin1String(
"x-mail-distribution-list" ) );
179 }
else if ( ( role == Qt::DisplayRole ) || ( role == Qt::EditRole ) ) {
180 switch ( d->mColumns.at( column ) ) {
183 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
199 if ( role == Qt::DisplayRole ) {
211int ContactsTreeModel::entityColumnCount( HeaderGroup headerGroup )
const
216 return d->mColumns.count();
218 return EntityTreeModel::entityColumnCount( headerGroup );
224 if ( role == Qt::DisplayRole ) {
225 if ( orientation == Qt::Horizontal ) {
228 if ( section >= 1 ) {
234 return i18nc(
"@title:column address books overview",
"Address Books" );
238 if ( section < 0 || section >= d->mColumns.count() ) {
242 switch ( d->mColumns.at( section ) ) {
244 return i18nc(
"@title:column name of a person",
"Name" );
246 return i18nc(
"@title:column family name of a person",
"Family Name" );
248 return i18nc(
"@title:column given name of a person",
"Given Name" );
250 return KABC::Addressee::birthdayLabel();
252 return i18nc(
"@title:column home address of a person",
"Home" );
254 return i18nc(
"@title:column work address of a person",
"Work" );
256 return i18nc(
"@title:column phone numbers of a person",
"Phone Numbers" );
258 return i18nc(
"@title:column the preferred email addresses of a person",
"Preferred EMail" );
260 return i18nc(
"@title:column all email addresses of a person",
"All EMails" );
262 return KABC::Addressee::organizationLabel();
264 return KABC::Addressee::roleLabel();
266 return KABC::Addressee::urlLabel();
268 return KABC::Addressee::noteLabel();
Records and replays change notification.
Represents a collection of PIM items.
A model for collections and items together.
virtual QVariant entityData(const Item &item, int column, int role=Qt::DisplayRole) const
Provided for convenience of subclasses.
@ CollectionTreeHeaders
Header information for a collection-only tree.
@ ItemListHeaders
Header information for a list of items.
virtual QVariant entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const
Reimplement this to provide different header data.
FreeBusyManager::Singleton.