22 #include "contactviewer.h" 24 #include "contactmetadata_p.h" 25 #include "contactmetadataattribute_p.h" 26 #include "customfieldmanager_p.h" 27 #include "standardcontactformatter.h" 28 #include "textbrowser_p.h" 30 #include "editor/im/improtocols.h" 32 #include <akonadi/collection.h> 33 #include <akonadi/collectionfetchjob.h> 34 #include <akonadi/entitydisplayattribute.h> 35 #include <akonadi/item.h> 36 #include <akonadi/itemfetchscope.h> 37 #include <kabc/addressee.h> 38 #include <kcolorscheme.h> 39 #include <kconfiggroup.h> 42 #include <klocalizedstring.h> 43 #include <kstringhandler.h> 45 #include <QVBoxLayout> 48 #include <prison/QRCodeBarcode> 49 #include <prison/DataMatrixBarcode> 50 #include <kabc/vcardconverter.h> 55 class ContactViewer::Private
59 : mParent( parent ), mParentCollectionFetchJob( 0 )
62 mContactFormatter = mStandardContactFormatter;
64 mQRCode =
new prison::QRCodeBarcode();
65 mDataMatrix =
new prison::DataMatrixBarcode();
71 delete mStandardContactFormatter;
78 void updateView(
const QVariantList &localCustomFieldDescriptions = QVariantList(),
const QString &addressBookName = QString() )
80 static QPixmap defaultPixmap = KIcon( QLatin1String(
"user-identity" ) ).pixmap( QSize( 100, 100 ) );
82 mParent->setWindowTitle( i18n(
"Contact %1", mCurrentContact.assembledName() ) );
84 if ( mCurrentContact.photo().isIntern() ) {
85 mBrowser->document()->addResource( QTextDocument::ImageResource,
86 QUrl( QLatin1String(
"contact_photo" ) ),
87 mCurrentContact.photo().data() );
89 mBrowser->document()->addResource( QTextDocument::ImageResource,
90 QUrl( QLatin1String(
"contact_photo" ) ),
94 if ( mCurrentContact.logo().isIntern() ) {
95 mBrowser->document()->addResource( QTextDocument::ImageResource,
96 QUrl( QLatin1String(
"contact_logo" ) ),
97 mCurrentContact.logo().data() );
100 mBrowser->document()->addResource( QTextDocument::ImageResource,
101 QUrl( QLatin1String(
"map_icon" ) ),
102 KIcon( QLatin1String(
"document-open-remote" ) ).pixmap( QSize( 16, 16 ) ) );
104 mBrowser->document()->addResource( QTextDocument::ImageResource,
105 QUrl( QLatin1String(
"sms_icon" ) ),
106 KIcon( IMProtocols::self()->icon( QString::fromLatin1(
"messaging/sms" ) ) ).pixmap( QSize( 16, 16 ) ) );
109 KConfig config( QLatin1String(
"akonadi_contactrc" ) );
110 KConfigGroup group( &config, QLatin1String(
"View" ) );
111 if ( group.readEntry(
"QRCodes",
true ) ) {
112 KABC::VCardConverter converter;
113 KABC::Addressee addr( mCurrentContact );
114 addr.setPhoto( KABC::Picture() );
115 addr.setLogo( KABC::Picture() );
116 const QString data = QString::fromUtf8( converter.createVCard( addr ) );
117 mQRCode->setData( data );
118 mDataMatrix->setData( data );
119 mBrowser->document()->addResource( QTextDocument::ImageResource,
120 QUrl( QLatin1String(
"qrcode" ) ),
121 mQRCode->toImage( QSizeF( 50, 50 ) ) );
122 mBrowser->document()->addResource( QTextDocument::ImageResource,
123 QUrl( QLatin1String(
"datamatrix" ) ),
124 mDataMatrix->toImage( QSizeF( 50, 50 ) ) );
126 #endif // HAVE_PRISON 129 QList<QVariantMap> customFieldDescriptions;
130 foreach (
const QVariant &entry, localCustomFieldDescriptions ) {
131 customFieldDescriptions << entry.toMap();
134 const CustomField::List globalCustomFields = CustomFieldManager::globalCustomFieldDescriptions();
135 foreach (
const CustomField &field, globalCustomFields ) {
136 QVariantMap description;
137 description.insert( QLatin1String(
"key" ), field.key() );
138 description.insert( QLatin1String(
"title" ), field.title() );
140 customFieldDescriptions << description;
143 KABC::Addressee
contact( mCurrentContact );
144 if ( !addressBookName.isEmpty() ) {
145 contact.insertCustom( QLatin1String(
"KADDRESSBOOK" ), QLatin1String(
"AddressBook" ), addressBookName );
148 mContactFormatter->setContact(
contact );
149 mContactFormatter->setCustomFieldDescriptions( customFieldDescriptions );
151 mBrowser->setHtml( mContactFormatter->toHtml() );
154 void slotMailClicked(
const QString&,
const QString &email )
156 QString name, address;
159 KABC::Addressee::parseEmailAddress( email.mid( 7 ), name, address );
161 emit mParent->emailClicked( name, address );
164 void slotUrlClicked(
const QString &urlString )
166 KUrl url( urlString );
167 const QString urlScheme( url.scheme() );
168 if ( urlScheme == QLatin1String(
"http" ) ||
169 urlScheme == QLatin1String(
"https" ) ) {
170 emit mParent->urlClicked( url );
171 }
else if ( urlScheme == QLatin1String(
"phone" ) ) {
172 const int pos = url.queryItemValue( QLatin1String(
"index" ) ).toInt();
174 const KABC::PhoneNumber::List numbers = mCurrentContact.phoneNumbers();
175 if ( pos < numbers.count() ) {
176 emit mParent->phoneNumberClicked( numbers.at( pos ) );
178 }
else if ( urlScheme == QLatin1String(
"sms" ) ) {
179 const int pos = url.queryItemValue( QLatin1String(
"index" ) ).toInt();
181 const KABC::PhoneNumber::List numbers = mCurrentContact.phoneNumbers();
182 if ( pos < numbers.count() ) {
183 emit mParent->smsClicked( numbers.at( pos ) );
185 }
else if ( urlScheme == QLatin1String(
"address" ) ) {
186 const int pos = url.queryItemValue( QLatin1String(
"index" ) ).toInt();
188 const KABC::Address::List addresses = mCurrentContact.addresses();
189 if ( pos < addresses.count() ) {
190 emit mParent->addressClicked( addresses.at( pos ) );
195 void slotParentCollectionFetched( KJob *job )
197 mParentCollectionFetchJob = 0;
199 QString addressBookName;
201 if ( !job->error() ) {
211 metaData.
load( mCurrentItem );
218 KABC::Addressee mCurrentContact;
224 prison::AbstractBarcode* mQRCode;
225 prison::AbstractBarcode* mDataMatrix;
226 #endif // HAVE_PRISON 230 : QWidget( parent ), d( new Private( this ) )
232 QVBoxLayout *layout =
new QVBoxLayout(
this );
233 layout->setMargin( 0 );
236 d->mBrowser->setNotifyClick(
true );
238 connect( d->mBrowser, SIGNAL(mailClick(QString,QString)),
239 this, SLOT(slotMailClicked(QString,QString)) );
240 connect( d->mBrowser, SIGNAL(urlClick(QString)),
241 this, SLOT(slotUrlClicked(QString)) );
243 layout->addWidget( d->mBrowser );
263 return d->mCurrentContact;
268 if ( formatter == 0 ) {
269 d->mContactFormatter = d->mStandardContactFormatter;
271 d->mContactFormatter = formatter;
287 void ContactViewer::itemChanged(
const Item &contactItem )
289 if ( !contactItem.hasPayload<KABC::Addressee>() ) {
293 d->mCurrentItem = contactItem;
294 d->mCurrentContact = contactItem.payload<KABC::Addressee>();
297 if ( d->mParentCollectionFetchJob ) {
298 disconnect( d->mParentCollectionFetchJob, SIGNAL(result(KJob*)),
this, SLOT(slotParentCollectionFetched(KJob*)) );
299 delete d->mParentCollectionFetchJob;
300 d->mParentCollectionFetchJob = 0;
304 connect( d->mParentCollectionFetchJob, SIGNAL(result(KJob*)), SLOT(slotParentCollectionFetched(KJob*)) );
307 void ContactViewer::itemRemoved()
309 d->mBrowser->clear();
312 #include "moc_contactviewer.cpp"
A class that represents non-standard contact fields.
void fetchAttribute(const QByteArray &type, bool fetch=true)
Sets whether the attribute of the given type should be fetched.
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Represents a collection of PIM items.
Job that fetches collections from the Akonadi storage.
A convenience class to remove the 'Copy Link Location' action from the context menu of KTextBrowser...
Item item() const
Returns the currently monitored item.
Collection::List collections() const
Returns the list of fetched collection.
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Only fetch the base collection.
Only retrieve the immediate parent collection.
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval. ...
void setItem(const Item &item)
Sets the item that shall be monitored.
FreeBusyManager::Singleton.