23 #include "contactstreemodel.h"
25 #include <kabc/addressee.h>
26 #include <kabc/contactgroup.h>
29 #include <kiconloader.h>
31 #include <klocalizedstring.h>
33 using namespace Akonadi;
35 class ContactsTreeModel::Private
40 mIconSize( KIconLoader::global()->currentSize( KIconLoader::Small ) )
49 : EntityTreeModel( monitor, parent ), d( new Private )
60 emit beginResetModel();
70 QVariant ContactsTreeModel::entityData(
const Item &item,
int column,
int role )
const
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 );
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();
143 return contact.preferredEmail();
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 ) {
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 ) {
228 if ( section >= 1 ) {
234 return i18nc(
"@title:column address books overview",
"Address Books" );
237 }
else if ( headerGroup == EntityTreeModel::ItemListHeaders ) {
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();
274 return EntityTreeModel::entityHeaderData( section, orientation, role, headerGroup );
QString join(const QString &separator) const