23 #include "contactstreemodel.h"
25 #include <kabc/addressee.h>
26 #include <kabc/contactgroup.h>
29 #include <kiconloader.h>
32 using namespace Akonadi;
34 class ContactsTreeModel::Private
39 mIconSize( KIconLoader::global()->currentSize( KIconLoader::Small ) )
48 : EntityTreeModel( monitor, parent ), d( new Private )
59 emit beginResetModel();
69 QVariant ContactsTreeModel::entityData(
const Item &item,
int column,
int role )
const
71 if ( item.mimeType() == KABC::Addressee::mimeType() ) {
72 if ( !item.hasPayload<KABC::Addressee>() ) {
75 if ( role == Qt::DisplayRole )
76 return item.remoteId();
81 const KABC::Addressee contact = item.payload<KABC::Addressee>();
83 if ( role == Qt::DecorationRole ) {
85 const KABC::Picture picture = contact.photo();
86 if ( picture.isIntern() ) {
87 return picture.data().scaled( QSize( d->mIconSize, d->mIconSize ), Qt::KeepAspectRatio );
89 return KIcon( QLatin1String(
"user-identity" ) );
93 }
else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
94 switch ( d->mColumns.at( column ) ) {
96 if( contact.realName().isEmpty() ) {
97 if( contact.preferredEmail().isEmpty() ) {
98 return contact.familyName();
100 return contact.preferredEmail();
102 return contact.realName();
105 return contact.familyName();
108 return contact.givenName();
111 if ( contact.birthday().date().isValid() )
112 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();
123 const KABC::Address address = contact.address( KABC::Address::Work );
124 if ( !address.isEmpty() )
125 return address.formattedAddress();
132 const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
133 foreach (
const KABC::PhoneNumber &number, numbers )
134 values += number.number();
136 return values.join( QLatin1String(
"\n" ) );
140 return contact.preferredEmail();
143 return contact.emails().join( QLatin1String(
"\n" ) );
146 return contact.organization();
149 return contact.role();
152 return contact.url().url();
155 return contact.note();
159 if ( d->mColumns.at( column ) ==
Birthday )
160 return contact.birthday();
164 }
else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
165 if ( !item.hasPayload<KABC::ContactGroup>() ) {
168 if ( role == Qt::DisplayRole )
169 return item.remoteId();
174 if ( role == Qt::DecorationRole ) {
176 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>();
194 return EntityTreeModel::entityData( item, column, role );
197 QVariant ContactsTreeModel::entityData(
const Collection &collection,
int column,
int role )
const
199 if ( role == Qt::DisplayRole ) {
202 return EntityTreeModel::entityData( collection, column, role );
208 return EntityTreeModel::entityData( collection, column, role );
211 int ContactsTreeModel::entityColumnCount( HeaderGroup headerGroup )
const
213 if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) {
215 }
else if ( headerGroup == EntityTreeModel::ItemListHeaders ) {
216 return d->mColumns.count();
218 return EntityTreeModel::entityColumnCount( headerGroup );
222 QVariant ContactsTreeModel::entityHeaderData(
int section, Qt::Orientation orientation,
int role, HeaderGroup headerGroup )
const
224 if ( role == Qt::DisplayRole ) {
225 if ( orientation == Qt::Horizontal ) {
226 if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) {
233 return i18nc(
"@title:column address books overview",
"Address Books" );
236 }
else if ( headerGroup == EntityTreeModel::ItemListHeaders ) {
237 if ( section < 0 || section >= d->mColumns.count() )
240 switch ( d->mColumns.at( section ) ) {
242 return i18nc(
"@title:column name of a person",
"Name" );
245 return i18nc(
"@title:column family name of a person",
"Family Name" );
248 return i18nc(
"@title:column given name of a person",
"Given Name" );
251 return KABC::Addressee::birthdayLabel();
254 return i18nc(
"@title:column home address of a person",
"Home" );
257 return i18nc(
"@title:column work address of a person",
"Work" );
260 return i18nc(
"@title:column phone numbers of a person",
"Phone Numbers" );
263 return i18nc(
"@title:column the preferred email addresses of a person",
"Preferred EMail" );
266 return i18nc(
"@title:column all email addresses of a person",
"All EMails" );
269 return KABC::Addressee::organizationLabel();
272 return KABC::Addressee::roleLabel();
275 return KABC::Addressee::urlLabel();
278 return KABC::Addressee::noteLabel();
285 return EntityTreeModel::entityHeaderData( section, orientation, role, headerGroup );
288 #include "contactstreemodel.moc"