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

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • header
mobileheaderstyle.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "mobileheaderstyle.h"
19 
20 #include "header/headerstyle_util.h"
21 
22 #include "header/headerstrategy.h"
23 #include <kpimutils/linklocator.h>
24 using KPIMUtils::LinkLocator;
25 
26 #include <kpimutils/email.h>
27 #include <messagecore/utils/stringutil.h>
28 
29 #include <kdebug.h>
30 #include <klocale.h>
31 
32 #include <QFontMetrics>
33 
34 #include <kstandarddirs.h>
35 #include <KApplication>
36 
37 #include <kmime/kmime_message.h>
38 #include <kmime/kmime_dateformatter.h>
39 
40 using namespace MessageCore;
41 using KPIMUtils::LinkLocator;
42 using namespace MessageViewer;
43 
44 namespace MessageViewer {
45 
46 static int matchingFontSize( const QString &text, int maximumWidth, int fontPixelSize )
47 {
48  int pixelSize = fontPixelSize;
49  while ( true ) {
50  if ( pixelSize <= 8 )
51  break;
52 
53  QFont font;
54  font.setPixelSize( pixelSize );
55  QFontMetrics fm( font );
56  if ( fm.width( text ) <= maximumWidth )
57  break;
58 
59  pixelSize--;
60  }
61 
62  return pixelSize;
63 }
64 
65 static QString formatMobileHeader( KMime::Message *message, bool extendedFormat, const HeaderStyle *style )
66 {
67  if ( !message )
68  return QString();
69 
70  // From
71  QString linkColor =QLatin1String("style=\"color: #0E49A1; text-decoration: none\"");
72  QString fromPart = StringUtil::emailAddrAsAnchor( message->from(), StringUtil::DisplayFullAddress, linkColor );
73 
74  if ( !style->vCardName().isEmpty() )
75  fromPart += QLatin1String("&nbsp;&nbsp;<a href=\"") + style->vCardName() + QLatin1String("\" ") + linkColor + QLatin1Char('>') + i18n( "[vCard]" ) + QLatin1String("</a>");
76 
77  const QString toPart = StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress, linkColor );
78  const QString ccPart = StringUtil::emailAddrAsAnchor( message->cc(), StringUtil::DisplayFullAddress, linkColor );
79 
80  // Background image
81  const QString imagePath( QLatin1String( "file:///" ) + KStandardDirs::locate( "data", QLatin1String("libmessageviewer/pics/") ) );
82  const QString mobileImagePath( imagePath + QLatin1String( "mobile_" ) );
83  //const QString mobileExtendedImagePath( imagePath + QLatin1String( "mobileextended_" ) );
84 
85  const Akonadi::MessageStatus status = style->messageStatus();
86  QString flagsPart;
87  if ( status.isImportant() )
88  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_important.png\" height=\"22\" width=\"22\"/>");
89  if ( status.hasAttachment() )
90  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_attachment.png\" height=\"22\" width=\"22\"/>");
91  if ( status.isToAct() )
92  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_actionitem.png\" height=\"22\" width=\"22\"/>");
93  if ( status.isReplied() )
94  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_replied.png\" height=\"22\" width=\"22\"/>");
95  if ( status.isForwarded() )
96  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_forwarded.png\" height=\"22\" width=\"22\"/>");
97  if ( status.isSigned() )
98  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_signed.png\" height=\"22\" width=\"22\"/>");
99  if ( status.isEncrypted() )
100  flagsPart += QLatin1String("<img src=\"") + mobileImagePath + QLatin1String("status_encrypted.png\" height=\"22\" width=\"22\"/>");
101 
102 
103  QString headerStr;
104  headerStr += QLatin1String("<div style=\"width: 100%\">\n");
105  headerStr += QLatin1String(" <table width=\"100%\" bgcolor=\"#B4E3F7\">\n");
106  headerStr += QLatin1String(" <tr>\n");
107  headerStr += QLatin1String(" <td valign=\"bottom\" width=\"80%\">\n");
108  headerStr += QLatin1String(" <div style=\"text-align: left; font-size: 20px; color: #0E49A1\">") + fromPart + QLatin1String("</div>\n");
109  headerStr += QLatin1String(" </td>\n");
110  headerStr += QLatin1String(" <td valign=\"bottom\" width=\"20%\" align=\"right\">\n");
111  headerStr += QLatin1String(" <div style=\"text-align: right; color: #0E49A1;\">") + flagsPart + QLatin1String("</div>\n");
112  headerStr += QLatin1String(" </td>\n");
113  headerStr += QLatin1String(" </tr>\n");
114  headerStr += QLatin1String(" </table>\n");
115  headerStr += QLatin1String(" <table width=\"100%\" bgcolor=\"#B4E3F7\">\n");
116  if ( extendedFormat ) {
117  headerStr += QLatin1String(" <tr>\n");
118  headerStr += QLatin1String(" <td valign=\"bottom\" colspan=\"2\">\n");
119  headerStr += QLatin1String(" <div style=\"height: 20px; font-size: 15px; color: #0E49A1\">") + toPart + ccPart + QLatin1String("</div>\n");
120  headerStr += QLatin1String(" </td>\n");
121  headerStr += QLatin1String(" </tr>\n");
122  }
123 
124  const int subjectFontSize = matchingFontSize( message->subject()->asUnicodeString(), 650, 20 );
125  headerStr += QLatin1String(" <tr>\n");
126  headerStr += QLatin1String(" <td valign=\"bottom\" colspan=\"2\">\n");
127  headerStr += QLatin1String(" <div style=\"height: 35px; font-size: ") + QString::number( subjectFontSize ) + QLatin1String("px; color: #24353F;\">") + message->subject()->asUnicodeString() + QLatin1String("</div>\n");
128  headerStr += QLatin1String(" </td>\n");
129  headerStr += QLatin1String(" </tr>\n");
130  headerStr += QLatin1String(" <tr>\n");
131  headerStr += QLatin1String(" <td align=\"left\" width=\"50%\">\n");
132  if ( !style->messagePath().isEmpty() ) {
133  headerStr += QLatin1String(" <div style=\"font-size: 15px; color: #24353F\">") + style->messagePath() + QLatin1String("</div>\n");
134  }
135  headerStr += QLatin1String(" </td>\n");
136  headerStr += QLatin1String(" <td align=\"right\" width=\"50%\">\n");
137  headerStr += QLatin1String(" <div style=\"font-size: 15px; color: #24353F; text-align: right; margin-right: 15px\">") + i18n( "sent: " );
138  headerStr += MessageViewer::HeaderStyleUtil::dateString( message, style->isPrinting(), /* shortDate = */ false ) + QLatin1String("</div>\n");
139  headerStr += QLatin1String(" </td>\n");
140  headerStr += QLatin1String(" </tr>\n");
141  headerStr += QLatin1String(" </table>\n");
142  headerStr += QLatin1String(" <br/>\n");
143  headerStr += QLatin1String("</div>\n");
144 
145  return headerStr;
146 }
147 
148 QString MobileHeaderStyle::format( KMime::Message *message ) const
149 {
150  return formatMobileHeader( message, false, this );
151 }
152 
153 QString MobileExtendedHeaderStyle::format( KMime::Message *message ) const
154 {
155  return formatMobileHeader( message, true, this );
156 }
157 }
MessageViewer::HeaderStyle
This class encapsulates the visual appearance of message headers.
Definition: headerstyle.h:60
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
MessageViewer::HeaderStyle::messageStatus
Akonadi::MessageStatus messageStatus() const
Definition: headerstyle.h:130
MessageViewer::HeaderStyle::messagePath
QString messagePath() const
Definition: headerstyle.h:106
headerstyle_util.h
MessageViewer::HeaderStyle::isPrinting
bool isPrinting() const
Definition: headerstyle.h:115
headerstrategy.h
MessageViewer::matchingFontSize
static int matchingFontSize(const QString &text, int maximumWidth, int fontPixelSize)
Definition: mobileheaderstyle.cpp:46
MessageViewer::formatMobileHeader
static QString formatMobileHeader(KMime::Message *message, bool extendedFormat, const HeaderStyle *style)
Definition: mobileheaderstyle.cpp:65
mobileheaderstyle.h
MessageViewer::HeaderStyle::vCardName
QString vCardName() const
Definition: headerstyle.h:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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