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

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • header
entrepriseheaderstyle.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 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 "entrepriseheaderstyle.h"
19 #include "header/headerstyle_util.h"
20 
21 #include "header/headerstrategy.h"
22 #include <kpimutils/linklocator.h>
23 using KPIMUtils::LinkLocator;
24 
25 #include <kpimutils/email.h>
26 #include <messagecore/utils/stringutil.h>
27 
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <KColorScheme>
31 #include <KStandardDirs>
32 
33 
34 #include <kmime/kmime_message.h>
35 #include <kmime/kmime_dateformatter.h>
36 
37 using namespace MessageCore;
38 using KPIMUtils::LinkLocator;
39 using namespace MessageViewer;
40 
41 namespace MessageViewer {
42 
43 QString EnterpriseHeaderStyle::format( KMime::Message *message ) const
44 {
45  if ( !message )
46  return QString();
47  const HeaderStrategy *strategy = headerStrategy();
48  if ( !strategy ) {
49  strategy = HeaderStrategy::brief();
50  }
51 
52  // The direction of the header is determined according to the direction
53  // of the application layout.
54  // However, the direction of the message subject within the header is
55  // determined according to the contents of the subject itself. Since
56  // the "Re:" and "Fwd:" prefixes would always cause the subject to be
57  // considered left-to-right, they are ignored when determining its
58  // direction.
59 
60  // colors depend on if it is encapsulated or not
61  QColor fontColor( Qt::white );
62  QString linkColor = QLatin1String("class =\"white\"");
63  const QColor activeColor = KColorScheme( QPalette::Active, KColorScheme::Selection ).
64  background().color();
65  QColor activeColorDark = activeColor.dark(130);
66  // reverse colors for encapsulated
67  if( !isTopLevel() ){
68  activeColorDark = activeColor.dark(50);
69  fontColor = QColor(Qt::black);
70  linkColor = QLatin1String("class =\"black\"");
71  }
72 
73  QString imgpath( KStandardDirs::locate("data",QLatin1String("libmessageviewer/pics/")) );
74  imgpath.prepend( QLatin1String("file:///") );
75  imgpath.append(QLatin1String("enterprise_"));
76  const QString borderSettings( QLatin1String(" padding-top: 0px; padding-bottom: 0px; border-width: 0px ") );
77  QString headerStr;
78 
79  // 3D borders
80  if(isTopLevel())
81  headerStr +=
82  QLatin1String("<div style=\"position: fixed; top: 0px; left: 0px; background-color: #606060; "
83  "width: 10px; min-height: 100%;\">&nbsp;</div>"
84  "<div style=\"position: fixed; top: 0px; right: 0px; background-color: #606060; "
85  "width: 10px; min-height: 100%;\">&nbsp;</div>");
86 
87  headerStr +=
88  QLatin1String("<div style=\"margin-left: 10px; top: 0px;\"><span style=\"font-size: 0.8em; font-weight: bold;\">")
89  + MessageViewer::HeaderStyleUtil::dateString( message, isPrinting(), /* shortDate */ false ) + QLatin1String("</span></div>"
90  // #0057ae
91  "<table style=\"background: ")+activeColorDark.name()+QLatin1String("; border-collapse:collapse; top: 14px; min-width: 200px; \" cellpadding=0> \n"
92  " <tr> \n"
93  " <td style=\"min-width: 6px; background-image: url(")+imgpath+QLatin1String("top_left.png); \"></td> \n"
94  " <td style=\"height: 6px; width: 100%; background: url(")+imgpath+QLatin1String("top.png); \"></td> \n"
95  " <td style=\"min-width: 6px; background: url(")+imgpath+QLatin1String("top_right.png); \"></td> </tr> \n"
96  " <tr> \n"
97  " <td style=\"min-width: 6px; max-width: 6px; background: url(")+imgpath+QLatin1String("left.png); \"></td> \n"
98  " <td style=\"\"> \n");
99  headerStr +=
100  QLatin1String("<div class=\"noprint\" style=\"z-index: 1; float:right; position: relative; top: -35px; right: 20px ; max-height: 65px\">\n"
101  "<img src=\"") + imgpath + QLatin1String("icon.png\">\n"
102  "</div>\n");
103  headerStr +=
104  QLatin1String(" <table style=\"color: ")+fontColor.name()+QLatin1String(" ! important; margin: 1px; border-spacing: 0px;\" cellpadding=0> \n");
105 
106  // subject
107  if ( strategy->showHeader( QLatin1String("subject") ) ) {
108  headerStr +=
109  QLatin1String(" <tr> \n"
110  " <td style=\"font-size: 0.5em; text-align: right; padding-left: 5px; padding-right: 24px; ")+borderSettings+QLatin1String("\"></td> \n"
111  " <td style=\"font-weight: bolder; font-size: 120%; padding-right: 91px; ")+borderSettings+QLatin1String("\">");
112  headerStr += MessageViewer::HeaderStyleUtil::subjectString( message )+ QLatin1String("</td> \n"
113  " </tr> \n");
114  }
115 
116  // from
117  if ( strategy->showHeader( QLatin1String("from") ) ) {
118  // We by design use the stripped mail address here, it is more enterprise-like.
119  QString fromPart = StringUtil::emailAddrAsAnchor( message->from(),
120  StringUtil::DisplayNameOnly, linkColor );
121  if ( !vCardName().isEmpty() )
122  fromPart += QLatin1String("&nbsp;&nbsp;<a href=\"") + vCardName() + QLatin1String("\" ")+linkColor+ QLatin1Char('>') + i18n("[vCard]") + QLatin1String("</a>");
123  //TDDO strategy date
124  //if ( strategy->showHeader( "date" ) )
125  headerStr +=
126  QLatin1String(" <tr> \n"
127  " <td style=\"font-size: 0.8em; padding-left: 5px; padding-right: 24px; text-align: right; vertical-align:top; ")+borderSettings+QLatin1String("\">")+i18n("From: ")+QLatin1String("</td> \n"
128  " <td style=\"")+borderSettings+QLatin1String("\">")+ fromPart +QLatin1String("</td> "
129  " </tr> ");
130  }
131 
132  // to line
133  if ( strategy->showHeader( QLatin1String("to") ) ) {
134  headerStr +=
135  QLatin1String(" <tr> "
136  " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") + borderSettings + QLatin1String("\">") + i18n("To: ") + QLatin1String("</td> "
137  " <td style=\"") + borderSettings + QLatin1String("\">") +
138  StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress, linkColor ) +
139  QLatin1String(" </td> "
140  " </tr>\n");
141  }
142 
143  // cc line, if any
144  if ( strategy->showHeader( QLatin1String("cc") ) && message->cc( false ) ) {
145  headerStr +=
146  QLatin1String(" <tr> "
147  " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") + borderSettings + QLatin1String("\">") + i18n("CC: ") + QLatin1String("</td> "
148  " <td style=\"") + borderSettings + QLatin1String("\">") +
149  StringUtil::emailAddrAsAnchor( message->cc(), StringUtil::DisplayFullAddress, linkColor ) +
150  QLatin1String(" </td> "
151  " </tr>\n");
152  }
153 
154  // bcc line, if any
155  if ( strategy->showHeader( QLatin1String("bcc") ) && message->bcc( false ) ) {
156  headerStr +=
157  QLatin1String(" <tr> "
158  " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") + borderSettings + QLatin1String("\">") + i18n("BCC: ") + QLatin1String("</td> "
159  " <td style=\"") + borderSettings + QLatin1String("\">") +
160  StringUtil::emailAddrAsAnchor( message->bcc(), StringUtil::DisplayFullAddress, linkColor ) +
161  QLatin1String(" </td> "
162  " </tr>\n");
163  }
164 
165  // attachments
166  QString attachment;
167  if( isTopLevel() ) {
168  attachment =
169  QLatin1String("<tr>"
170  "<td style='min-width: 6px; max-width: 6px; background: url(")+imgpath+QLatin1String("left.png);'</td>"
171  "<td style='padding-right:20px;'>"
172  "<div class=\"noprint\" >"
173  "<div id=\"attachmentInjectionPoint\"></div>"
174  "</div>"
175  "</td>"
176  "<td style='min-width: 6px; max-width: 6px; background: url(")+imgpath+QLatin1String("right.png);'</td>"
177  "</tr>");
178  }
179 
180  // header-bottom
181  headerStr +=
182  QLatin1String(" </table> \n"
183  " </td> \n"
184  " <td style=\"min-width: 6px; max-height: 15px; background: url(")+imgpath+QLatin1String("right.png); \"></td> \n"
185  " </tr> \n") + attachment +
186  QLatin1String(" <tr> \n"
187  " <td style=\"min-width: 6px; background: url(")+imgpath+QLatin1String("s_left.png); \"></td> \n"
188  " <td style=\"height: 35px; width: 80%; background: url(")+imgpath+QLatin1String("sbar.png);\"> \n"
189  " <img src=\"")+imgpath+QLatin1String("sw.png\" style=\"margin: 0px; height: 30px; overflow:hidden; \"> \n"
190  " <img src=\"")+imgpath+QLatin1String("sp_right.png\" style=\"float: right; \"> </td> \n"
191  " <td style=\"min-width: 6px; background: url(")+imgpath+QLatin1String("s_right.png); \"></td> \n"
192  " </tr> \n"
193  " </table> \n");
194 
195  if ( isPrinting() ) {
196  //provide a bit more left padding when printing
197  //kolab/issue3254 (printed mail cut at the left side)
198  headerStr += QLatin1String("<div style=\"padding: 6px; padding-left: 10px;\">");
199  } else {
200  headerStr += QLatin1String("<div style=\"padding: 6px;\">");
201  }
202 
203  // TODO
204  // spam status
205  // ### iterate over the rest of strategy->headerToDisplay() (or
206  // ### all headers if DefaultPolicy == Display) (elsewhere, too)
207  return headerStr;
208 }
209 }
QString::append
QString & append(QChar ch)
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
QColor::name
QString name() const
QString::prepend
QString & prepend(QChar ch)
MessageViewer::HeaderStrategy
Definition: headerstrategy.h:42
QColor::dark
QColor dark(int factor) const
QString
QColor
MessageViewer::HeaderStyleUtil::subjectString
QString subjectString(KMime::Message *message, int flags)
Definition: headerstyle_util.cpp:69
QLatin1Char
headerstyle_util.h
MessageViewer::HeaderStrategy::showHeader
virtual bool showHeader(const QString &header) const
Definition: headerstrategy.cpp:62
QLatin1String
headerstrategy.h
entrepriseheaderstyle.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 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
  • pimprint

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