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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 <klocalizedstring.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 
53  if ( group.name().isEmpty() && group.count() == 0 ) { // empty group
54  return QString();
55  }
56 
57  if ( group.contactReferenceCount() != 0 ) {
58  // we got a contact group with unresolved references -> we have to resolve it ourself
59  // this shouldn't be the normal case, actually the calling code should pass in an already resolved
60  // contact group
61  ContactGroupExpandJob *job = new ContactGroupExpandJob( group );
62  if ( job->exec() ) {
63  group.removeAllContactData();
64  foreach ( const KABC::Addressee &contact, job->contacts() ) {
65  group.append( KABC::ContactGroup::Data( contact.realName(), contact.preferredEmail() ) );
66  }
67  }
68  }
69 
70  // Assemble all parts
71  QString strGroup = QString::fromLatin1(
72  "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">"
73  "<tr>"
74  "<td align=\"right\" valign=\"top\" width=\"30%\">"
75  "<img src=\"%1\" width=\"100\" vspace=\"1\">" // image
76  "</td>"
77  "<td align=\"left\" width=\"70%\"><font size=\"+2\"><b>%2</b></font></td>" // name
78  "</tr>"
79  "</table>" )
80  .arg( QLatin1String( "group_photo" ) )
81  .arg( group.name() );
82 
83  strGroup += QLatin1String( "<table width=\"100%\">" );
84 
85  for ( uint i = 0; i < group.dataCount(); ++i ) {
86  const KABC::ContactGroup::Data data = group.data( i );
87 
88  if ( data.email().isEmpty() ) {
89  strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font color=\"grey\">%1</font></b></td>"
90  "<td width=\"50%\"></td></tr>" )
91  .arg( data.name() ) );
92  } else {
93  KABC::Addressee contact;
94  contact.setFormattedName( data.name() );
95  contact.insertEmail( data.email() );
96 
97  const QString fullEmail = QLatin1String( "<a href=\"mailto:" ) + QString::fromLatin1( KUrl::toPercentEncoding( contact.fullEmail() ) ) + QString::fromLatin1( "\">%1</a>" ).arg( contact.preferredEmail() );
98 
99  strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font color=\"grey\">%1</font></b></td>"
100  "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font>&lt;%2&gt;</font></td></tr>" )
101  .arg( contact.realName() )
102  .arg( fullEmail ) );
103  }
104  }
105 
106  foreach ( const QVariantMap &map, additionalFields() ) {
107  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>"
108  "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font>%2</font></td></tr>" )
109  .arg( map.value( QLatin1String( "title" ) ).toString() )
110  .arg( map.value( QLatin1String( "value" ) ).toString() ) );
111  }
112 
113  strGroup.append( QString::fromLatin1( "</table>\n" ) );
114 
115  QString document = QString::fromLatin1( "<div align=\"center\">%1</div>" ).arg( strGroup );
116 
117  if ( form == EmbeddableForm ) {
118  return document;
119  }
120 
121  document = QString::fromLatin1(
122  "<html>"
123  "<head>"
124  " <style type=\"text/css\">"
125  " a {text-decoration:none; color:%1}"
126  " </style>"
127  "</head>"
128  "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
129  "%3" // contact group part
130  "</body>"
131  "</html>" )
132  .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
133  .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() )
134  .arg( document );
135 
136  return document;
137 }
Akonadi::AbstractContactGroupFormatter::contactGroup
KABC::ContactGroup contactGroup() const
Returns the contact group that will be formatted.
Definition: abstractcontactgroupformatter.cpp:52
Akonadi::ContactGroupExpandJob::contacts
KABC::Addressee::List contacts() const
Returns the list of contacts.
Definition: contactgroupexpandjob.cpp:162
Akonadi::AbstractContactGroupFormatter::item
Akonadi::Item item() const
Returns the item who's payload will be formatted.
Definition: abstractcontactgroupformatter.cpp:62
Akonadi::AbstractContactGroupFormatter::additionalFields
QList< QVariantMap > additionalFields() const
Returns the additional fields that will be shown.
Definition: abstractcontactgroupformatter.cpp:72
Akonadi::StandardContactGroupFormatter::~StandardContactGroupFormatter
virtual ~StandardContactGroupFormatter()
Destroys the standard contact group formatter.
Definition: standardcontactgroupformatter.cpp:39
Akonadi::StandardContactGroupFormatter::StandardContactGroupFormatter
StandardContactGroupFormatter()
Creates a new standard contact group formatter.
Definition: standardcontactgroupformatter.cpp:34
Akonadi::StandardContactGroupFormatter::toHtml
virtual QString toHtml(HtmlForm form=SelfcontainedForm) const
Returns the contact group formatted as HTML.
Definition: standardcontactgroupformatter.cpp:43
Akonadi::AbstractContactGroupFormatter::EmbeddableForm
Creates a div HTML element that can be embedded.
Definition: abstractcontactgroupformatter.h:54
Akonadi::ContactGroupExpandJob
Job that expands a ContactGroup to a list of contacts.
Definition: contactgroupexpandjob.h:64
Akonadi::AbstractContactGroupFormatter::HtmlForm
HtmlForm
Describes the form of the HTML that is created.
Definition: abstractcontactgroupformatter.h:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:28 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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