• 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
briefheaderstyle.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  header/headerstyle.h
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6 
7  Copyright (c) 2013 Laurent Montel <montel@kde.org>
8 
9  KMail is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License, version 2, as
11  published by the Free Software Foundation.
12 
13  KMail is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the Qt library by Trolltech AS, Norway (or with modified versions
25  of Qt that use the same license as Qt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  Qt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 */
33 
34 #include "briefheaderstyle.h"
35 #include "header/headerstyle.h"
36 #include "header/headerstyle_util.h"
37 
38 #include "header/headerstrategy.h"
39 #include <kpimutils/linklocator.h>
40 using KPIMUtils::LinkLocator;
41 
42 #include <kpimutils/email.h>
43 #include <messagecore/utils/stringutil.h>
44 #include <kdebug.h>
45 #include <klocale.h>
46 #include <kglobal.h>
47 
48 #include <KDateTime>
49 #include <QRegExp>
50 
51 #include <KApplication>
52 
53 #include <kmime/kmime_message.h>
54 #include <kmime/kmime_dateformatter.h>
55 
56 using namespace MessageCore;
57 using KPIMUtils::LinkLocator;
58 using namespace MessageViewer;
59 //
60 // BriefHeaderStyle
61 // Show everything in a single line, don't show header field names.
62 //
63 
64 QString BriefHeaderStyle::format( KMime::Message *message ) const {
65  if ( !message ) return QString();
66 
67  const HeaderStrategy *strategy = headerStrategy();
68  if ( !strategy )
69  strategy = HeaderStrategy::brief();
70 
71  // The direction of the header is determined according to the direction
72  // of the application layout.
73 
74  const QString dir = QApplication::isRightToLeft() ? QLatin1String("rtl") : QLatin1String("ltr");
75 
76  // However, the direction of the message subject within the header is
77  // determined according to the contents of the subject itself. Since
78  // the "Re:" and "Fwd:" prefixes would always cause the subject to be
79  // considered left-to-right, they are ignored when determining its
80  // direction.
81 
82  const QString subjectDir = MessageViewer::HeaderStyleUtil::subjectDirectionString( message );
83 
84  QString headerStr = QLatin1String("<div class=\"header\" dir=\"") + dir + QLatin1String("\">\n");
85 
86  if ( strategy->showHeader( QLatin1String("subject") ) ) {
87  headerStr += QLatin1String("<div dir=\"") + subjectDir + QLatin1String("\">\n") +
88  QLatin1String("<b style=\"font-size:130%\">");
89 
90  headerStr += MessageViewer::HeaderStyleUtil::subjectString( message ) + QLatin1String("</b></div>\n");
91  }
92  QStringList headerParts;
93 
94  if ( strategy->showHeader( QLatin1String("from") ) ) {
95  /*TODO(Andras) review if it can happen or not
96  if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
97  fromStr = message->fromStrip(); // let's use that
98 */
99  QString fromPart = StringUtil::emailAddrAsAnchor( message->from(), StringUtil::DisplayNameOnly );
100  if ( !vCardName().isEmpty() )
101  fromPart += QLatin1String("&nbsp;&nbsp;<a href=\"") + vCardName() + QLatin1String("\">") + i18n("[vCard]") + QLatin1String("</a>");
102  headerParts << fromPart;
103  }
104 
105  if ( strategy->showHeader( QLatin1String("cc") ) && message->cc(false) )
106  headerParts << i18n("CC: ") + StringUtil::emailAddrAsAnchor( message->cc(), StringUtil::DisplayNameOnly );
107 
108  if ( strategy->showHeader( QLatin1String("bcc") ) && message->bcc(false) )
109  headerParts << i18n("BCC: ") + StringUtil::emailAddrAsAnchor( message->bcc(), StringUtil::DisplayNameOnly );
110 
111  if ( strategy->showHeader( QLatin1String("date") ) )
112  headerParts << MessageViewer::HeaderStyleUtil::strToHtml( MessageViewer::HeaderStyleUtil::dateString( message, isPrinting(), /* shortDate = */ true ) );
113 
114  // remove all empty (modulo whitespace) entries and joins them via ", \n"
115  headerStr += QLatin1String(" (") + headerParts.filter( QRegExp( QLatin1String("\\S") ) ).join( QLatin1String(",\n") ) + QLatin1Char(')');
116 
117  headerStr += QLatin1String("</div>\n");
118 
119  // ### iterate over the rest of strategy->headerToDisplay() (or
120  // ### all headers if DefaultPolicy == Display) (elsewhere, too)
121  return headerStr;
122 }
briefheaderstyle.h
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
MessageViewer::HeaderStrategy
Definition: headerstrategy.h:42
headerstyle.h
MessageViewer::HeaderStyleUtil::subjectDirectionString
QString subjectDirectionString(KMime::Message *message)
Definition: headerstyle_util.cpp:84
MessageViewer::HeaderStyleUtil::subjectString
QString subjectString(KMime::Message *message, int flags)
Definition: headerstyle_util.cpp:69
headerstyle_util.h
MessageViewer::HeaderStrategy::showHeader
virtual bool showHeader(const QString &header) const
Definition: headerstrategy.cpp:62
headerstrategy.h
MessageViewer::HeaderStyleUtil::strToHtml
QString strToHtml(const QString &str, int flags)
Definition: headerstyle_util.cpp:49
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