• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
standardcontactgroupformatter.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "standardcontactgroupformatter.h"
23 
24 #include <akonadi/contact/contactgroupexpandjob.h>
25 #include <akonadi/item.h>
26 #include <kabc/addressee.h>
27 #include <kcolorscheme.h>
28 #include <kglobal.h>
29 #include <klocale.h>
30 #include <kstringhandler.h>
31 
32 using namespace Akonadi;
33 
34 StandardContactGroupFormatter::StandardContactGroupFormatter()
35  : d( 0 )
36 {
37 }
38 
39 StandardContactGroupFormatter::~StandardContactGroupFormatter()
40 {
41 }
42 
43 QString StandardContactGroupFormatter::toHtml( HtmlForm form ) const
44 {
45  KABC::ContactGroup group;
46  const Akonadi::Item localItem = item();
47  if ( localItem.isValid() && localItem.hasPayload<KABC::ContactGroup>() )
48  group = localItem.payload<KABC::ContactGroup>();
49  else
50  group = contactGroup();
51 
52  if ( group.name().isEmpty() && group.count() == 0 ) // empty group
53  return QString();
54 
55  if ( group.contactReferenceCount() != 0 ) {
56  // we got a contact group with unresolved references -> we have to resolve it ourself
57  // this shouldn't be the normal case, actually the calling code should pass in an already resolved
58  // contact group
59  ContactGroupExpandJob *job = new ContactGroupExpandJob( group );
60  if ( job->exec() ) {
61  group.removeAllContactData();
62  foreach ( const KABC::Addressee &contact, job->contacts() ) {
63  group.append( KABC::ContactGroup::Data( contact.realName(), contact.preferredEmail() ) );
64  }
65  }
66  }
67 
68  // Assemble all parts
69  QString strGroup = QString::fromLatin1(
70  "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">"
71  "<tr>"
72  "<td align=\"right\" valign=\"top\" width=\"30%\">"
73  "<img src=\"%1\" width=\"100\" vspace=\"1\">" // image
74  "</td>"
75  "<td align=\"left\" width=\"70%\"><font size=\"+2\"><b>%2</b></font></td>" // name
76  "</tr>"
77  "</table>" )
78  .arg( QLatin1String( "group_photo" ) )
79  .arg( group.name() );
80 
81  strGroup += QLatin1String( "<table width=\"100%\">" );
82 
83  for ( uint i = 0; i < group.dataCount(); ++i ) {
84  const KABC::ContactGroup::Data data = group.data( i );
85 
86  if ( data.email().isEmpty() ) {
87  strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font color=\"grey\">%1</font></b></td>"
88  "<td width=\"50%\"></td></tr>" )
89  .arg( data.name() ) );
90  } else {
91  KABC::Addressee contact;
92  contact.setFormattedName( data.name() );
93  contact.insertEmail( data.email() );
94 
95  const QString fullEmail = QLatin1String( "<a href=\"mailto:" ) + QString::fromLatin1( KUrl::toPercentEncoding( contact.fullEmail() ) ) + QString::fromLatin1( "\">%1</a>" ).arg( contact.preferredEmail() );
96 
97  strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font color=\"grey\">%1</font></b></td>"
98  "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font>&lt;%2&gt;</font></td></tr>" )
99  .arg( contact.realName() )
100  .arg( fullEmail ) );
101  }
102  }
103 
104  foreach ( const QVariantMap &map, additionalFields() ) {
105  strGroup.append( QString::fromLatin1( "<tr><td colspan=\"2\">&nbsp;</td></tr><tr><td align=\"right\" width=\"30%\"><b><font color=\"grey\">%1</font></b></td>"
106  "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font>%2</font></td></tr>" )
107  .arg( map.value( QLatin1String( "title" ) ).toString() )
108  .arg( map.value( QLatin1String( "value" ) ).toString() ) );
109  }
110 
111  strGroup.append( QString::fromLatin1( "</table>\n" ) );
112 
113  QString document = QString::fromLatin1( "<div align=\"center\">%1</div>" ).arg( strGroup );
114 
115  if ( form == EmbeddableForm )
116  return document;
117 
118  document = QString::fromLatin1(
119  "<html>"
120  "<head>"
121  " <style type=\"text/css\">"
122  " a {text-decoration:none; color:%1}"
123  " </style>"
124  "</head>"
125  "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
126  "%3" // contact group part
127  "</body>"
128  "</html>" )
129  .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
130  .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() )
131  .arg( document );
132 
133  return document;
134 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed Nov 28 2012 21:51:44 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal