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 return contact.realName();
99 return contact.familyName();
102 return contact.givenName();
105 if ( contact.birthday().date().isValid() )
106 return KGlobal::locale()->formatDate( contact.birthday().date(), KLocale::ShortDate );
110 const KABC::Address address = contact.address( KABC::Address::Home );
111 if ( !address.isEmpty() )
112 return address.formattedAddress();
117 const KABC::Address address = contact.address( KABC::Address::Work );
118 if ( !address.isEmpty() )
119 return address.formattedAddress();
126 const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
127 foreach (
const KABC::PhoneNumber &number, numbers )
128 values += number.number();
130 return values.join( QLatin1String(
"\n" ) );
134 return contact.preferredEmail();
137 return contact.emails().join( QLatin1String(
"\n" ) );
140 return contact.organization();
143 return contact.role();
146 return contact.url().url();
149 return contact.note();
153 if ( d->mColumns.at( column ) ==
Birthday )
154 return contact.birthday();
158 }
else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
159 if ( !item.hasPayload<KABC::ContactGroup>() ) {
162 if ( role == Qt::DisplayRole )
163 return item.remoteId();
168 if ( role == Qt::DecorationRole ) {
170 return KIcon( QLatin1String(
"x-mail-distribution-list" ) );
173 }
else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
174 switch ( d->mColumns.at( column ) ) {
177 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
188 return EntityTreeModel::entityData( item, column, role );
191 QVariant ContactsTreeModel::entityData(
const Collection &collection,
int column,
int role )
const
193 if ( role == Qt::DisplayRole ) {
196 return EntityTreeModel::entityData( collection, column, role );
202 return EntityTreeModel::entityData( collection, column, role );
205 int ContactsTreeModel::entityColumnCount( HeaderGroup headerGroup )
const
207 if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) {
209 }
else if ( headerGroup == EntityTreeModel::ItemListHeaders ) {
210 return d->mColumns.count();
212 return EntityTreeModel::entityColumnCount( headerGroup );
216 QVariant ContactsTreeModel::entityHeaderData(
int section, Qt::Orientation orientation,
int role, HeaderGroup headerGroup )
const
218 if ( role == Qt::DisplayRole ) {
219 if ( orientation == Qt::Horizontal ) {
220 if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) {
227 return i18nc(
"@title:column address books overview",
"Address Books" );
230 }
else if ( headerGroup == EntityTreeModel::ItemListHeaders ) {
231 if ( section < 0 || section >= d->mColumns.count() )
234 switch ( d->mColumns.at( section ) ) {
236 return i18nc(
"@title:column name of a person",
"Name" );
239 return i18nc(
"@title:column family name of a person",
"Family Name" );
242 return i18nc(
"@title:column given name of a person",
"Given Name" );
245 return KABC::Addressee::birthdayLabel();
248 return i18nc(
"@title:column home address of a person",
"Home" );
251 return i18nc(
"@title:column work address of a person",
"Work" );
254 return i18nc(
"@title:column phone numbers of a person",
"Phone Numbers" );
257 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" );
263 return KABC::Addressee::organizationLabel();
266 return KABC::Addressee::roleLabel();
269 return KABC::Addressee::urlLabel();
272 return KABC::Addressee::noteLabel();
279 return EntityTreeModel::entityHeaderData( section, orientation, role, headerGroup );
282 #include "contactstreemodel.moc"