23 #include "emailaddressselectionproxymodel_p.h"
25 #include <akonadi/item.h>
26 #include <kabc/addressee.h>
27 #include <kabc/contactgroup.h>
28 #include <klocalizedstring.h>
30 using namespace Akonadi;
32 static QString createToolTip(
const KABC::ContactGroup &group )
38 const uint groupDataCount( group.dataCount() );
39 for ( uint i = 0; i < groupDataCount; ++i ) {
43 txt += group.
data( i ).email();
59 EmailAddressSelectionProxyModel::EmailAddressSelectionProxyModel(
QObject *parent )
60 : LeafExtensionProxyModel( parent )
64 EmailAddressSelectionProxyModel::~EmailAddressSelectionProxyModel()
70 const QVariant value = LeafExtensionProxyModel::data( index, role );
73 if ( role == NameRole ) {
75 if ( item.hasPayload<KABC::Addressee>() ) {
76 const KABC::Addressee contact = item.payload<KABC::Addressee>();
77 return contact.realName();
78 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
79 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
82 }
else if ( role == EmailAddressRole ) {
84 if ( item.hasPayload<KABC::Addressee>() ) {
85 const KABC::Addressee contact = item.payload<KABC::Addressee>();
86 return contact.preferredEmail();
87 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
88 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
91 }
else if ( role == Qt::ToolTipRole ) {
93 if ( item.hasPayload<KABC::Addressee>() ) {
94 const KABC::Addressee contact = item.payload<KABC::Addressee>();
95 return createToolTip( contact.realName(), contact.preferredEmail() );
96 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
97 return createToolTip( item.payload<KABC::ContactGroup>() );
105 int EmailAddressSelectionProxyModel::leafRowCount(
const QModelIndex &index )
const
108 if ( item.hasPayload<KABC::Addressee>() ) {
109 const KABC::Addressee contact = item.payload<KABC::Addressee>();
110 if ( contact.emails().count() == 1 ) {
113 return contact.emails().count();
115 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
116 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
117 return group.dataCount();
123 int EmailAddressSelectionProxyModel::leafColumnCount(
const QModelIndex &index )
const
126 if ( item.hasPayload<KABC::Addressee>() ) {
128 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
135 QVariant EmailAddressSelectionProxyModel::leafData(
const QModelIndex &index,
int row,
int,
int role )
const
137 if ( role == Qt::DisplayRole ) {
139 if ( item.hasPayload<KABC::Addressee>() ) {
140 const KABC::Addressee contact = item.payload<KABC::Addressee>();
141 if ( row >= 0 && row < contact.emails().count() ) {
142 return contact.emails().at( row );
144 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
145 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
146 if ( row >= 0 && row < (
int)group.dataCount() ) {
147 return i18nc(
"Name and email address of a contact",
"%1 <%2>",
148 group.data( row ).name(), group.data( row ).email() );
151 }
else if ( role == NameRole ) {
153 if ( item.hasPayload<KABC::Addressee>() ) {
154 const KABC::Addressee contact = item.payload<KABC::Addressee>();
155 return contact.realName();
156 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
157 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
158 if ( row >= 0 && row < (
int)group.dataCount() ) {
159 return group.data( row ).name();
162 }
else if ( role == EmailAddressRole ) {
164 if ( item.hasPayload<KABC::Addressee>() ) {
165 const KABC::Addressee contact = item.payload<KABC::Addressee>();
166 if ( row >= 0 && row < contact.emails().count() ) {
167 return contact.emails().at( row );
169 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
170 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
171 if ( row >= 0 && row < (
int)group.dataCount() ) {
172 return group.data( row ).email();
175 }
else if ( role == Qt::ToolTipRole ) {
177 if ( item.hasPayload<KABC::Addressee>() ) {
178 const KABC::Addressee contact = item.payload<KABC::Addressee>();
179 if ( row >= 0 && row < contact.emails().count() ) {
180 return createToolTip( contact.realName(), contact.emails().at( row ) );
182 }
else if ( item.hasPayload<KABC::ContactGroup>() ) {
183 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
184 if ( row >= 0 && row < (
int)group.dataCount() ) {
185 return createToolTip( group.data( row ).name(), group.data( row ).email() );
189 return index.
data( role );
QVariant data(int role) const
QString fromLatin1(const char *str, int size)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const