00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "standardcontactgroupformatter.h"
00023
00024 #include <akonadi/contact/contactgroupexpandjob.h>
00025 #include <akonadi/item.h>
00026 #include <kabc/addressee.h>
00027 #include <kcolorscheme.h>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 #include <kstringhandler.h>
00031
00032 using namespace Akonadi;
00033
00034 StandardContactGroupFormatter::StandardContactGroupFormatter()
00035 : d( 0 )
00036 {
00037 }
00038
00039 StandardContactGroupFormatter::~StandardContactGroupFormatter()
00040 {
00041 }
00042
00043 QString StandardContactGroupFormatter::toHtml( HtmlForm form ) const
00044 {
00045 KABC::ContactGroup group;
00046 const Akonadi::Item localItem = item();
00047 if ( localItem.isValid() && localItem.hasPayload<KABC::ContactGroup>() )
00048 group = localItem.payload<KABC::ContactGroup>();
00049 else
00050 group = contactGroup();
00051
00052 if ( group.name().isEmpty() && group.count() == 0 )
00053 return QString();
00054
00055 if ( group.contactReferenceCount() != 0 ) {
00056
00057
00058
00059 ContactGroupExpandJob *job = new ContactGroupExpandJob( group );
00060 if ( job->exec() ) {
00061 group.removeAllContactData();
00062 foreach ( const KABC::Addressee &contact, job->contacts() ) {
00063 group.append( KABC::ContactGroup::Data( contact.realName(), contact.preferredEmail() ) );
00064 }
00065 }
00066 }
00067
00068
00069 QString strGroup = QString::fromLatin1(
00070 "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">"
00071 "<tr>"
00072 "<td align=\"right\" valign=\"top\" width=\"30%\">"
00073 "<img src=\"%1\" width=\"100\" vspace=\"1\">"
00074 "</td>"
00075 "<td align=\"left\" width=\"70%\"><font size=\"+2\"><b>%2</b></font></td>"
00076 "</tr>"
00077 "</table>" )
00078 .arg( QLatin1String( "group_photo" ) )
00079 .arg( group.name() );
00080
00081 strGroup += QLatin1String( "<table width=\"100%\">" );
00082
00083 for ( uint i = 0; i < group.dataCount(); ++i ) {
00084 const KABC::ContactGroup::Data data = group.data( i );
00085
00086 if ( data.email().isEmpty() ) {
00087 strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font size=\"-1\" color=\"grey\">%1</font></b></td>"
00088 "<td width=\"50%\"></td></tr>" )
00089 .arg( data.name() ) );
00090 } else {
00091 KABC::Addressee contact;
00092 contact.setFormattedName( data.name() );
00093 contact.insertEmail( data.email() );
00094
00095 const QString fullEmail = QLatin1String( "<a href=\"mailto:" ) + QString::fromLatin1( KUrl::toPercentEncoding( contact.fullEmail() ) ) + QString::fromLatin1( "\">%1</a>" ).arg( contact.preferredEmail() );
00096
00097 strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font size=\"-1\" color=\"grey\">%1</font></b></td>"
00098 "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font size=\"-1\"><%2></font></td></tr>" )
00099 .arg( contact.realName() )
00100 .arg( fullEmail ) );
00101 }
00102 }
00103
00104 foreach ( const QVariantMap &map, additionalFields() ) {
00105 strGroup.append( QString::fromLatin1( "<tr><td colspan=\"2\"> </td></tr><tr><td align=\"right\" width=\"30%\"><b><font size=\"-1\" color=\"grey\">%1</font></b></td>"
00106 "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font size=\"-1\">%2</font></td></tr>" )
00107 .arg( map.value( QLatin1String( "title" ) ).toString() )
00108 .arg( map.value( QLatin1String( "value" ) ).toString() ) );
00109 }
00110
00111 strGroup.append( QString::fromLatin1( "</table>\n" ) );
00112
00113 QString document = QString::fromLatin1( "<div align=\"center\">%1</div>" ).arg( strGroup );
00114
00115 if ( form == EmbeddableForm )
00116 return document;
00117
00118 document = QString::fromLatin1(
00119 "<html>"
00120 "<head>"
00121 " <style type=\"text/css\">"
00122 " a {text-decoration:none; color:%1}"
00123 " </style>"
00124 "</head>"
00125 "<body text=\"%1\" bgcolor=\"%2\">"
00126 "%3"
00127 "</body>"
00128 "</html>" )
00129 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
00130 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() )
00131 .arg( document );
00132
00133 return document;
00134 }