• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/kabc

kabcitembrowser.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "kabcitembrowser.h"
00021 
00022 #include <kabc/addressee.h>
00023 #include <kglobal.h>
00024 #include <kicon.h>
00025 #include <klocale.h>
00026 #include <kstringhandler.h>
00027 
00028 #include <akonadi/item.h>
00029 
00030 static QString addresseeToHtml( const KABC::Addressee& );
00031 
00032 using namespace Akonadi;
00033 
00034 KABCItemBrowser::KABCItemBrowser( QWidget *parent )
00035   : ItemBrowser( parent ), d( 0 )
00036 {
00037 }
00038 
00039 KABCItemBrowser::~KABCItemBrowser()
00040 {
00041 }
00042 
00043 QString KABCItemBrowser::itemToRichText( const Item &item )
00044 {
00045   static QPixmap defaultPixmap = KIcon( QLatin1String( "personal" ) ).pixmap( QSize( 100, 140 ) );
00046 
00047   const KABC::Addressee addr = item.payload<KABC::Addressee>();
00048 
00049   setWindowTitle( i18n( "Contact %1", addr.assembledName() ) );
00050 
00051   if ( addr.photo().isIntern() ) {
00052     document()->addResource( QTextDocument::ImageResource,
00053                              QUrl( QLatin1String( "contact_photo" ) ),
00054                              addr.photo().data() );
00055   } else {
00056     document()->addResource( QTextDocument::ImageResource,
00057                              QUrl( QLatin1String( "contact_photo" ) ),
00058                              defaultPixmap );
00059   }
00060 
00061   return addresseeToHtml( addr );
00062 }
00063 
00064 static QString addresseeToHtml( const KABC::Addressee &addr )
00065 {
00066   // We'll be building a table to display the vCard in.
00067   // Each row of the table will be built using this string for its HTML.
00068 
00069   QString rowFmtStr = QString::fromLatin1(
00070         "<tr>"
00071         "<td align=\"right\" valign=\"top\" width=\"30%\"><b>%1</b></td>\n"
00072         "<td align=\"left\" valign=\"top\" width=\"70%\">%2</td>\n"
00073         "</tr>\n"
00074         );
00075 
00076   // Build the table's rows here
00077   QString dynamicPart;
00078 
00079   // Birthday
00080   const QDate date = addr.birthday().date();
00081 
00082   if ( date.isValid() )
00083     dynamicPart += rowFmtStr
00084       .arg( KABC::Addressee::birthdayLabel() )
00085       .arg( KGlobal::locale()->formatDate( date, KLocale::ShortDate ) );
00086 
00087   // Phone Numbers
00088   foreach( const KABC::PhoneNumber &number, addr.phoneNumbers() ) {
00089       QString url;
00090       if ( number.type() & KABC::PhoneNumber::Fax )
00091         url = QString::fromLatin1( "fax:" ) + number.number();
00092       else
00093         url = QString::fromLatin1( "phone:" ) + number.number();
00094 
00095       dynamicPart += rowFmtStr
00096         .arg( KABC::PhoneNumber::typeLabel( number.type() ).replace( QLatin1String( " " ), QLatin1String( "&nbsp;" ) ) )
00097         .arg( number.number() );
00098   }
00099 
00100   // EMails
00101   foreach ( const QString &email, addr.emails() ) {
00102     QString type = i18nc( "a contact's email address", "Email" );
00103 
00104     const QString fullEmail = QString::fromLatin1( KUrl::toPercentEncoding( addr.fullEmail( email ) ) );
00105 
00106     dynamicPart += rowFmtStr.arg( type )
00107       .arg( QString::fromLatin1( "<a href=\"mailto:%1\">%2</a>" )
00108       .arg( fullEmail, email ) );
00109   }
00110 
00111   // Homepage
00112   if ( addr.url().isValid() ) {
00113     QString url = addr.url().url();
00114     if ( !url.startsWith( QLatin1String( "http://" ) ) && !url.startsWith( QLatin1String( "https://" ) ) )
00115       url = QLatin1String( "http://" ) + url;
00116 
00117     url = KStringHandler::tagUrls( url );
00118     dynamicPart += rowFmtStr.arg( i18n( "Homepage" ) ).arg( url );
00119   }
00120 
00121   // Blog Feed
00122   const QString blog = addr.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "BlogFeed" ) );
00123   if ( !blog.isEmpty() )
00124     dynamicPart += rowFmtStr.arg( i18n( "Blog Feed" ) ).arg( KStringHandler::tagUrls( blog ) );
00125 
00126   // Addresses
00127   foreach ( const KABC::Address &address, addr.addresses() ) {
00128     if ( address.label().isEmpty() ) {
00129       QString formattedAddress;
00130 
00131       formattedAddress = address.formattedAddress().trimmed();
00132       formattedAddress = formattedAddress.replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) );
00133 
00134       dynamicPart += rowFmtStr
00135         .arg( KABC::Address::typeLabel( address.type() ) )
00136         .arg( formattedAddress );
00137     } else {
00138       dynamicPart += rowFmtStr
00139         .arg( KABC::Address::typeLabel( address.type() ) )
00140         .arg( address.label().replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) );
00141     }
00142   }
00143 
00144   // Note
00145   QString notes;
00146   if ( !addr.note().isEmpty() )
00147     notes = rowFmtStr.arg( i18n( "Notes" ) ).arg( addr.note().replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) ) ;
00148 
00149   // Custom Data
00150   QString customData;
00151   static QMap<QString, QString> titleMap;
00152   if ( titleMap.isEmpty() ) {
00153     titleMap.insert( QLatin1String( "Department" ), i18n( "Department" ) );
00154     titleMap.insert( QLatin1String( "Profession" ), i18n( "Profession" ) );
00155     titleMap.insert( QLatin1String( "AssistantsName" ), i18n( "Assistant's Name" ) );
00156     titleMap.insert( QLatin1String( "ManagersName" ), i18n( "Manager's Name" ) );
00157     titleMap.insert( QLatin1String( "SpousesName" ), i18nc( "Wife/Husband/...", "Partner's Name" ) );
00158     titleMap.insert( QLatin1String( "Office" ), i18n( "Office" ) );
00159     titleMap.insert( QLatin1String( "IMAddress" ), i18n( "IM Address" ) );
00160     titleMap.insert( QLatin1String( "Anniversary" ), i18n( "Anniversary" ) );
00161   }
00162 
00163   if ( !addr.customs().empty() ) {
00164     foreach ( QString custom, addr.customs() ) {
00165       if ( custom.startsWith( QLatin1String( "KADDRESSBOOK-" ) ) ) {
00166         custom.remove( QLatin1String( "KADDRESSBOOK-X-" ) );
00167         custom.remove( QLatin1String( "KADDRESSBOOK-" ) );
00168 
00169         int pos = custom.indexOf( QLatin1Char( ':' ) );
00170         QString key = custom.left( pos );
00171         const QString value = custom.mid( pos + 1 );
00172 
00173         // blog is handled separated
00174         if ( key == QLatin1String( "BlogFeed" ) )
00175           continue;
00176 
00177         const QMap<QString, QString>::ConstIterator keyIt = titleMap.find( key );
00178         if ( keyIt != titleMap.end() )
00179           key = keyIt.value();
00180 
00181         customData += rowFmtStr.arg( key ).arg( value ) ;
00182       }
00183     }
00184   }
00185 
00186   // Assemble all parts
00187   QString strAddr = QString::fromLatin1(
00188     "<div align=\"center\">"
00189     "<table cellpadding=\"1\" cellspacing=\"0\">"
00190     "<tr>"
00191     "<td align=\"right\" valign=\"top\" width=\"30%\" rowspan=\"3\">"
00192     "<img src=\"%1\" width=\"75\" height=\"105\" vspace=\"1\">" // image
00193     "</td>"
00194     "<td align=\"left\" width=\"70%\"><font size=\"+2\"><b>%2</b></font></td>" // name
00195     "</tr>"
00196     "<tr>"
00197     "<td align=\"left\" width=\"70%\">%3</td>"  // role
00198     "</tr>"
00199     "<tr>"
00200     "<td align=\"left\" width=\"70%\">%4</td>"  // organization
00201     "</tr>"
00202     "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>")
00203       .arg( QLatin1String( "contact_photo" ) )
00204       .arg( addr.realName() )
00205       .arg( addr.role() )
00206       .arg( addr.organization() );
00207 
00208   strAddr.append( dynamicPart );
00209   strAddr.append( notes );
00210   strAddr.append( customData );
00211   strAddr.append( QString::fromLatin1( "</table></div>\n" ) );
00212 
00213   return strAddr;
00214 }

akonadi/kabc

Skip menu "akonadi/kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal