TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

headerstyle.cpp 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /* -*- c++ -*-
  2. headerstyle.cpp
  3. This file is part of KMail, the KDE mail client.
  4. Copyright (c) 2003 Marc Mutz <mutz@kde.org>
  5. KMail is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License, version 2, as
  7. published by the Free Software Foundation.
  8. KMail 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. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. In addition, as a special exception, the copyright holders give
  16. permission to link the code of this program with any edition of
  17. the TQt library by Trolltech AS, Norway (or with modified versions
  18. of TQt that use the same license as TQt), and distribute linked
  19. combinations including the two. You must obey the GNU General
  20. Public License in all respects for all of the code used other than
  21. TQt. If you modify this file, you may extend this exception to
  22. your version of the file, but you are not obligated to do so. If
  23. you do not wish to do so, delete this exception statement from
  24. your version.
  25. */
  26. #ifdef HAVE_CONFIG_H
  27. #include <config.h>
  28. #endif
  29. #include "headerstyle.h"
  30. #include "headerstrategy.h"
  31. #include "kmkernel.h"
  32. #include "linklocator.h"
  33. #include "kmmessage.h"
  34. #include "spamheaderanalyzer.h"
  35. #include "globalsettings.h"
  36. #include <libemailfunctions/email.h>
  37. #include <libtdepim/kxface.h>
  38. using namespace KPIM;
  39. #include <mimelib/string.h>
  40. #include <mimelib/field.h>
  41. #include <mimelib/headers.h>
  42. #include <kdebug.h>
  43. #include <tdelocale.h>
  44. #include <tdeglobal.h>
  45. #include <tdeimproxy.h>
  46. #include <tdeabc/stdaddressbook.h>
  47. #include <tdeabc/addresseelist.h>
  48. #include <kmdcodec.h>
  49. #include <tqdatetime.h>
  50. #include <tqbuffer.h>
  51. #include <tqbitmap.h>
  52. #include <tqimage.h>
  53. #include <tqapplication.h>
  54. #include <tqregexp.h>
  55. #include <kstandarddirs.h>
  56. namespace KMail {
  57. //
  58. // Convenience functions:
  59. //
  60. static inline TQString directionOf( const TQString & str ) {
  61. return str.isRightToLeft() ? "rtl" : "ltr" ;
  62. }
  63. #if 0
  64. // Converts to html. Changes URLs into href's, escapes HTML special
  65. // chars and inserts the result into an <div> or <span> tag with
  66. // "dir" set to "rtl" or "ltr" depending on the direction of @p str.
  67. static TQString convertToHtmlBlock( const TQString & str, bool useSpan=false ) {
  68. TQString dir = directionOf( str );
  69. TQString format = "<%1 dir=\"%3\">%4</%2>";
  70. return format.arg( useSpan ? "span" : "div" )
  71. .arg( useSpan ? "span" : "div" )
  72. .arg( dir )
  73. .arg( LinkLocator::convertToHtml( str ) );
  74. }
  75. #endif
  76. // ### tmp wrapper to make kmreaderwin code working:
  77. static TQString strToHtml( const TQString & str,
  78. int flags = LinkLocator::PreserveSpaces ) {
  79. return LinkLocator::convertToHtml( str, flags );
  80. }
  81. //
  82. // BriefHeaderStyle
  83. // Show everything in a single line, don't show header field names.
  84. //
  85. class BriefHeaderStyle : public HeaderStyle {
  86. friend class ::KMail::HeaderStyle;
  87. protected:
  88. BriefHeaderStyle() : HeaderStyle() {}
  89. virtual ~BriefHeaderStyle() {}
  90. public:
  91. const char * name() const { return "brief"; }
  92. const HeaderStyle * next() const { return plain(); }
  93. const HeaderStyle * prev() const { return fancy(); }
  94. TQString format( const KMMessage * message, const HeaderStrategy * strategy,
  95. const TQString & vCardName, bool printing, bool topLevel ) const;
  96. };
  97. TQString BriefHeaderStyle::format( const KMMessage * message,
  98. const HeaderStrategy * strategy,
  99. const TQString & vCardName, bool printing, bool topLevel ) const {
  100. Q_UNUSED( topLevel );
  101. if ( !message ) return TQString();
  102. if ( !strategy )
  103. strategy = HeaderStrategy::brief();
  104. // The direction of the header is determined according to the direction
  105. // of the application layout.
  106. TQString dir = TQApplication::reverseLayout() ? "rtl" : "ltr" ;
  107. // However, the direction of the message subject within the header is
  108. // determined according to the contents of the subject itself. Since
  109. // the "Re:" and "Fwd:" prefixes would always cause the subject to be
  110. // considered left-to-right, they are ignored when determining its
  111. // direction.
  112. TQString subjectDir;
  113. if (!message->subject().isEmpty())
  114. subjectDir = directionOf( message->cleanSubject() );
  115. else
  116. subjectDir = directionOf( i18n("No Subject") );
  117. // Prepare the date string (when printing always use the localized date)
  118. TQString dateString;
  119. if( printing ) {
  120. TQDateTime dateTime;
  121. TDELocale * locale = TDEGlobal::locale();
  122. dateTime.setTime_t( message->date() );
  123. dateString = locale->formatDateTime( dateTime );
  124. } else {
  125. dateString = message->dateStr();
  126. }
  127. TQString headerStr = "<div class=\"header\" dir=\"" + dir + "\">\n";
  128. if ( strategy->showHeader( "subject" ) )
  129. headerStr += "<div dir=\"" + subjectDir + "\">\n"
  130. "<b style=\"font-size:130%\">" +
  131. strToHtml( message->subject() ) +
  132. "</b></div>\n";
  133. TQStringList headerParts;
  134. if ( strategy->showHeader( "from" ) ) {
  135. TQString fromStr = message->from();
  136. if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
  137. fromStr = message->fromStrip(); // let's use that
  138. TQString fromPart = KMMessage::emailAddrAsAnchor( fromStr, true );
  139. if ( !vCardName.isEmpty() )
  140. fromPart += "&nbsp;&nbsp;<a href=\"" + vCardName + "\">" + i18n("[vCard]") + "</a>";
  141. headerParts << fromPart;
  142. }
  143. if ( strategy->showHeader( "cc" ) && !message->cc().isEmpty() )
  144. headerParts << i18n("CC: ") + KMMessage::emailAddrAsAnchor( message->cc(), true );
  145. if ( strategy->showHeader( "bcc" ) && !message->bcc().isEmpty() )
  146. headerParts << i18n("BCC: ") + KMMessage::emailAddrAsAnchor( message->bcc(), true );
  147. if ( strategy->showHeader( "date" ) )
  148. headerParts << strToHtml(message->dateShortStr());
  149. // remove all empty (modulo whitespace) entries and joins them via ", \n"
  150. headerStr += " (" + headerParts.grep( TQRegExp( "\\S" ) ).join( ",\n" ) + ')';
  151. headerStr += "</div>\n";
  152. // ### iterate over the rest of strategy->headerToDisplay() (or
  153. // ### all headers if DefaultPolicy == Display) (elsewhere, too)
  154. return headerStr;
  155. }
  156. //
  157. // PlainHeaderStyle:
  158. // show every header field on a line by itself,
  159. // show subject larger
  160. //
  161. class PlainHeaderStyle : public HeaderStyle {
  162. friend class ::KMail::HeaderStyle;
  163. protected:
  164. PlainHeaderStyle() : HeaderStyle() {}
  165. virtual ~PlainHeaderStyle() {}
  166. public:
  167. const char * name() const { return "plain"; }
  168. const HeaderStyle * next() const { return fancy(); }
  169. const HeaderStyle * prev() const { return brief(); }
  170. TQString format( const KMMessage * message, const HeaderStrategy * strategy,
  171. const TQString & vCardName, bool printing, bool topLevel ) const;
  172. private:
  173. TQString formatAllMessageHeaders( const KMMessage * message ) const;
  174. };
  175. TQString PlainHeaderStyle::format( const KMMessage * message,
  176. const HeaderStrategy * strategy,
  177. const TQString & vCardName, bool printing, bool topLevel ) const {
  178. Q_UNUSED( topLevel );
  179. if ( !message ) return TQString();
  180. if ( !strategy )
  181. strategy = HeaderStrategy::rich();
  182. // The direction of the header is determined according to the direction
  183. // of the application layout.
  184. TQString dir = ( TQApplication::reverseLayout() ? "rtl" : "ltr" );
  185. // However, the direction of the message subject within the header is
  186. // determined according to the contents of the subject itself. Since
  187. // the "Re:" and "Fwd:" prefixes would always cause the subject to be
  188. // considered left-to-right, they are ignored when determining its
  189. // direction.
  190. TQString subjectDir;
  191. if (!message->subject().isEmpty())
  192. subjectDir = directionOf( message->cleanSubject() );
  193. else
  194. subjectDir = directionOf( i18n("No Subject") );
  195. // Prepare the date string (when printing always use the localized date)
  196. TQString dateString;
  197. if( printing ) {
  198. TQDateTime dateTime;
  199. TDELocale* locale = TDEGlobal::locale();
  200. dateTime.setTime_t( message->date() );
  201. dateString = locale->formatDateTime( dateTime );
  202. }
  203. else {
  204. dateString = message->dateStr();
  205. }
  206. TQString headerStr;
  207. if ( strategy->headersToDisplay().isEmpty()
  208. && strategy->defaultPolicy() == HeaderStrategy::Display ) {
  209. // crude way to emulate "all" headers - Note: no strings have
  210. // i18n(), so direction should always be ltr.
  211. headerStr= TQString("<div class=\"header\" dir=\"ltr\">");
  212. headerStr += formatAllMessageHeaders( message );
  213. return headerStr + "</div>";
  214. }
  215. headerStr = TQString("<div class=\"header\" dir=\"%1\">").arg(dir);
  216. //case HdrLong:
  217. if ( strategy->showHeader( "subject" ) )
  218. headerStr += TQString("<div dir=\"%1\"><b style=\"font-size:130%\">" +
  219. strToHtml(message->subject()) + "</b></div>\n")
  220. .arg(subjectDir);
  221. if ( strategy->showHeader( "date" ) )
  222. headerStr.append(i18n("Date: ") + strToHtml(dateString)+"<br>\n");
  223. #if 0
  224. // Get Instant Messaging presence
  225. TQString presence;
  226. TQString tdeabcUid;
  227. if ( strategy->showHeader( "status" ) )
  228. {
  229. TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
  230. TDEABC::AddresseeList addresses = addressBook->findByEmail( KPIM::getFirstEmailAddress( message->from() ) );
  231. ::KIMProxy *imProxy = KMKernel::self()->imProxy();
  232. tdeabcUid = addresses[0].uid();
  233. presence = imProxy->presenceString( tdeabcUid );
  234. }
  235. #endif
  236. if ( strategy->showHeader( "from" ) ) {
  237. TQString fromStr = message->from();
  238. if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
  239. fromStr = message->fromStrip(); // let's use that
  240. headerStr.append(i18n("From: ") +
  241. KMMessage::emailAddrAsAnchor( fromStr, false, "", true ) );
  242. if ( !vCardName.isEmpty() )
  243. headerStr.append("&nbsp;&nbsp;<a href=\"" + vCardName +
  244. "\">" + i18n("[vCard]") + "</a>" );
  245. #if 0
  246. if ( !presence.isEmpty() && strategy->showHeader( "status" ) )
  247. headerStr.append("&nbsp;&nbsp;(<span name=\"presence-" + tdeabcUid + "\">" + presence + "</span>)" );
  248. #endif
  249. if ( strategy->showHeader( "organization" )
  250. && !message->headerField("Organization").isEmpty())
  251. headerStr.append("&nbsp;&nbsp;(" +
  252. strToHtml(message->headerField("Organization")) + ")");
  253. headerStr.append("<br>\n");
  254. }
  255. if ( strategy->showHeader( "to" ) )
  256. headerStr.append(i18n("To: ")+
  257. KMMessage::emailAddrAsAnchor(message->to(),false) + "<br>\n");
  258. if ( strategy->showHeader( "cc" ) && !message->cc().isEmpty() )
  259. headerStr.append(i18n("CC: ")+
  260. KMMessage::emailAddrAsAnchor(message->cc(),false) + "<br>\n");
  261. if ( strategy->showHeader( "bcc" ) && !message->bcc().isEmpty() )
  262. headerStr.append(i18n("BCC: ")+
  263. KMMessage::emailAddrAsAnchor(message->bcc(),false) + "<br>\n");
  264. if ( strategy->showHeader( "reply-to" ) && !message->replyTo().isEmpty())
  265. headerStr.append(i18n("Reply to: ")+
  266. KMMessage::emailAddrAsAnchor(message->replyTo(),false) + "<br>\n");
  267. headerStr += "</div>\n";
  268. return headerStr;
  269. }
  270. TQString PlainHeaderStyle::formatAllMessageHeaders( const KMMessage * message ) const {
  271. const DwHeaders & headers = message->headers();
  272. TQString result;
  273. for ( const DwField * field = headers.FirstField() ; field ; field = field->Next() ) {
  274. result += ( field->FieldNameStr() + ": " ).c_str();
  275. result += strToHtml( field->FieldBodyStr().c_str() );
  276. result += "<br>\n";
  277. }
  278. return result;
  279. }
  280. //
  281. // FancyHeaderStyle:
  282. // Like PlainHeaderStyle, but with slick frames and background colours.
  283. //
  284. class FancyHeaderStyle : public HeaderStyle {
  285. friend class ::KMail::HeaderStyle;
  286. protected:
  287. FancyHeaderStyle() : HeaderStyle() {}
  288. virtual ~FancyHeaderStyle() {}
  289. public:
  290. const char * name() const { return "fancy"; }
  291. const HeaderStyle * next() const { return enterprise(); }
  292. const HeaderStyle * prev() const { return plain(); }
  293. TQString format( const KMMessage * message, const HeaderStrategy * strategy,
  294. const TQString & vCardName, bool printing, bool topLevel ) const;
  295. static TQString imgToDataUrl( const TQImage & image,
  296. const char *fmt = "PNG" );
  297. private:
  298. static TQString drawSpamMeter( double percent, const TQString & filterHeader );
  299. };
  300. TQString FancyHeaderStyle::drawSpamMeter( double percent,
  301. const TQString & filterHeader )
  302. {
  303. TQImage meterBar( 20, 1, 8, 24 );
  304. const unsigned short gradient[20][3] = {
  305. { 0, 255, 0 },
  306. { 27, 254, 0 },
  307. { 54, 252, 0 },
  308. { 80, 250, 0 },
  309. { 107, 249, 0 },
  310. { 135, 247, 0 },
  311. { 161, 246, 0 },
  312. { 187, 244, 0 },
  313. { 214, 242, 0 },
  314. { 241, 241, 0 },
  315. { 255, 228, 0 },
  316. { 255, 202, 0 },
  317. { 255, 177, 0 },
  318. { 255, 151, 0 },
  319. { 255, 126, 0 },
  320. { 255, 101, 0 },
  321. { 255, 76, 0 },
  322. { 255, 51, 0 },
  323. { 255, 25, 0 },
  324. { 255, 0, 0 }
  325. };
  326. meterBar.setColor( 21, tqRgb( 255, 255, 255 ) );
  327. meterBar.setColor( 22, tqRgb( 170, 170, 170 ) );
  328. if ( percent < 0 ) // grey is for errors
  329. meterBar.fill( 22 );
  330. else {
  331. meterBar.fill( 21 );
  332. int max = TQMIN( 20, static_cast<int>( percent ) / 5 );
  333. for ( int i = 0; i < max; ++i ) {
  334. meterBar.setColor( i+1, tqRgb( gradient[i][0], gradient[i][1],
  335. gradient[i][2] ) );
  336. meterBar.setPixel( i, 0, i+1 );
  337. }
  338. }
  339. TQString titleText = i18n("%1% probability of being spam.\n\nFull report:\n%2")
  340. .arg( TQString::number( percent ), filterHeader );
  341. return TQString("<img src=\"%1\" width=\"%2\" height=\"%3\" style=\"border: 1px solid black;\" title=\"%4\"> &nbsp;")
  342. .arg( imgToDataUrl( meterBar, "PPM" ), TQString::number( 20 ),
  343. TQString::number( 5 ), titleText );
  344. }
  345. TQString FancyHeaderStyle::format( const KMMessage * message,
  346. const HeaderStrategy * strategy,
  347. const TQString & vCardName, bool printing, bool topLevel ) const {
  348. Q_UNUSED( topLevel );
  349. if ( !message ) return TQString();
  350. if ( !strategy )
  351. strategy = HeaderStrategy::rich();
  352. TDEConfigGroup configReader( KMKernel::config(), "Reader" );
  353. // ### from kmreaderwin begin
  354. // The direction of the header is determined according to the direction
  355. // of the application layout.
  356. TQString dir = ( TQApplication::reverseLayout() ? "rtl" : "ltr" );
  357. TQString headerStr = TQString("<div class=\"fancy header\" dir=\"%1\">\n").arg(dir);
  358. // However, the direction of the message subject within the header is
  359. // determined according to the contents of the subject itself. Since
  360. // the "Re:" and "Fwd:" prefixes would always cause the subject to be
  361. // considered left-to-right, they are ignored when determining its
  362. // direction.
  363. TQString subjectDir;
  364. if ( !message->subject().isEmpty() )
  365. subjectDir = directionOf( message->cleanSubject() );
  366. else
  367. subjectDir = directionOf( i18n("No Subject") );
  368. // Prepare the date string (when printing always use the localized date)
  369. TQString dateString;
  370. if( printing ) {
  371. TQDateTime dateTime;
  372. TDELocale* locale = TDEGlobal::locale();
  373. dateTime.setTime_t( message->date() );
  374. dateString = locale->formatDateTime( dateTime );
  375. }
  376. else {
  377. dateString = message->dateStr();
  378. }
  379. // Spam header display.
  380. // If the spamSpamStatus config value is true then we look for headers
  381. // from a few spam filters and try to create visually meaningful graphics
  382. // out of the spam scores.
  383. TQString spamHTML;
  384. if ( configReader.readBoolEntry( "showSpamStatus", true ) ) {
  385. SpamScores scores = SpamHeaderAnalyzer::getSpamScores( message );
  386. for ( SpamScoresIterator it = scores.begin(); it != scores.end(); ++it )
  387. spamHTML += (*it).agent() + " " +
  388. drawSpamMeter( (*it).score(), (*it).spamHeader() );
  389. }
  390. TQString userHTML;
  391. TQString presence;
  392. // IM presence and tdeabc photo
  393. ::KIMProxy *imProxy = KMKernel::self()->imProxy();
  394. TQString tdeabcUid;
  395. TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
  396. TDEABC::AddresseeList addresses = addressBook->findByEmail( KPIM::getFirstEmailAddress( message->from() ) );
  397. TQString photoURL;
  398. int photoWidth = 60;
  399. int photoHeight = 60;
  400. if( addresses.count() == 1 )
  401. {
  402. // tdeabcUid is embedded in im: URIs to indicate which IM contact to message
  403. tdeabcUid = addresses[0].uid();
  404. if ( imProxy->initialize() ) {
  405. // im status
  406. presence = imProxy->presenceString( tdeabcUid );
  407. if ( !presence.isEmpty() )
  408. {
  409. TQString presenceIcon = TQString::fromLatin1( " <img src=\"%1\"/>" )
  410. .arg( imgToDataUrl( imProxy->presenceIcon( tdeabcUid ).convertToImage() ) );
  411. presence += presenceIcon;
  412. }
  413. }
  414. // picture
  415. if ( addresses[0].photo().isIntern() )
  416. {
  417. // get photo data and convert to data: url
  418. //kdDebug( 5006 ) << "INTERNAL photo found" << endl;
  419. TQImage photo = addresses[0].photo().data();
  420. if ( !photo.isNull() )
  421. {
  422. photoWidth = photo.width();
  423. photoHeight = photo.height();
  424. // scale below 60, otherwise it can get way too large
  425. if ( photoHeight > 60 ) {
  426. double ratio = ( double )photoHeight / ( double )photoWidth;
  427. photoHeight = 60;
  428. photoWidth = (int)( 60 / ratio );
  429. photo = photo.smoothScale( photoWidth, photoHeight );
  430. }
  431. photoURL = imgToDataUrl( photo );
  432. }
  433. }
  434. else
  435. {
  436. //kdDebug( 5006 ) << "URL found" << endl;
  437. photoURL = addresses[0].photo().url();
  438. if ( photoURL.startsWith("/") )
  439. photoURL.prepend( "file:" );
  440. }
  441. }
  442. else // TODO: find a usable one
  443. {
  444. kdDebug( 5006 ) << "Multiple / No addressees matched email address; Count is " << addresses.count() << endl;
  445. userHTML = "&nbsp;";
  446. }
  447. if( photoURL.isEmpty() ) {
  448. // no photo, look for a Face header
  449. TQString faceheader = message->headerField( "Face" );
  450. if ( !faceheader.isEmpty() ) {
  451. TQImage faceimage;
  452. kdDebug( 5006 ) << "Found Face: header" << endl;
  453. TQCString facestring = faceheader.utf8();
  454. // Spec says header should be less than 998 bytes
  455. // Face: is 5 characters
  456. if ( facestring.length() < 993 ) {
  457. TQByteArray facearray;
  458. KCodecs::base64Decode(facestring, facearray);
  459. TQImage faceimage;
  460. if ( faceimage.loadFromData( facearray, "png" ) ) {
  461. // Spec says image must be 48x48 pixels
  462. if ( (48 == faceimage.width()) && (48 == faceimage.height()) ) {
  463. photoURL = imgToDataUrl( faceimage );
  464. photoWidth = 48;
  465. photoHeight = 48;
  466. } else {
  467. kdDebug( 5006 ) << "Face: header image is" << faceimage.width() << "by" << faceimage.height() <<"not 48x48 Pixels" << endl;
  468. }
  469. } else {
  470. kdDebug( 5006 ) << "Failed to load decoded png from Face: header" << endl;
  471. }
  472. } else {
  473. kdDebug( 5006 ) << "Face: header too long at " << facestring.length() << endl;
  474. }
  475. }
  476. }
  477. if( photoURL.isEmpty() )
  478. {
  479. // no photo, look for a X-Face header
  480. TQString xfaceURL;
  481. TQString xfhead = message->headerField( "X-Face" );
  482. if ( !xfhead.isEmpty() )
  483. {
  484. KXFace xf;
  485. photoURL = imgToDataUrl( xf.toImage( xfhead ) );
  486. photoWidth = 48;
  487. photoHeight = 48;
  488. }
  489. }
  490. if( !photoURL.isEmpty() )
  491. {
  492. //kdDebug( 5006 ) << "Got a photo: " << photoURL << endl;
  493. userHTML = TQString("<img src=\"%1\" width=\"%2\" height=\"%3\">")
  494. .arg( photoURL ).arg( photoWidth ).arg( photoHeight );
  495. if ( presence.isEmpty() ) {
  496. userHTML = TQString("<div class=\"senderpic\">") + userHTML + "</div>";
  497. } else {
  498. userHTML = TQString( "<div class=\"senderpic\">"
  499. "<a href=\"im:%1\">%2<div class=\"senderstatus\">"
  500. "<span name=\"presence-%3\">%4</span></div></a>"
  501. "</div>" ).arg( tdeabcUid )
  502. .arg( userHTML )
  503. .arg( tdeabcUid )
  504. .arg( presence );
  505. }
  506. } else {
  507. // we don't have a photo, just show presence, if we have it
  508. if ( !presence.isEmpty() )
  509. userHTML = TQString( "<a href=\"im:%1\"><div class=\"senderstatus\">"
  510. "<span name=\"presence-%2\">%3</span></div></a>" )
  511. .arg( tdeabcUid )
  512. .arg( tdeabcUid )
  513. .arg( presence );
  514. }
  515. #if 0
  516. // Disabled 'Launch IM' link in headers - Will
  517. if ( imProxy->imAppsAvailable() )
  518. presence = "<a name=\"launchim\" href=\"kmail:startIMApp\">" + i18n("Launch IM") + "</a></span>";
  519. // do nothing - no im apps available, leave presence empty
  520. //presence = i18n( "DCOP/InstantMessenger not installed" );
  521. kdDebug( 5006 ) << "final presence: '" << presence << "'" << endl;
  522. #endif
  523. TQString timeHTML;
  524. if ( GlobalSettings::self()->showCurrentTime() && strategy->showHeader( "date" ) ) {
  525. DwHeaders& header = message->headers();
  526. if ( header.HasDate() ) {
  527. DwDateTime& origDate = header.Date();
  528. int zone = origDate.Zone();
  529. // kdDebug() << "FancyHeaderStyle::format() zone offset (in minutes): " << zone << endl;
  530. // copyed from mimelib -- code to determine local timezone
  531. time_t t_now = time((time_t*) 0);
  532. #if defined(HAVE_GMTIME_R)
  533. struct tm utc;
  534. gmtime_r(&t_now, &utc);
  535. struct tm local;
  536. localtime_r(&t_now, &local);
  537. #else
  538. struct tm utc = *gmtime(&t_now);
  539. struct tm local = *localtime(&t_now);
  540. #endif
  541. DwUint32 t_local = 0;
  542. t_local = 24 * t_local + local.tm_hour;
  543. t_local = 60 * t_local + local.tm_min;
  544. t_local = 60 * t_local + local.tm_sec;
  545. DwUint32 t_utc = 0;
  546. t_utc = 24 * t_utc + utc.tm_hour;
  547. t_utc = 60 * t_utc + utc.tm_min;
  548. t_utc = 60 * t_utc + utc.tm_sec;
  549. // kdDebug() << "FancyHeaderStyle::format() local zone offset (in minutes): " << lzone << endl;
  550. TQTime currTime = TQTime::currentTime( Qt::UTC );
  551. // kdDebug() << "FancyHeaderStyle::format() current time: " << currTime << endl;
  552. // now currTime contain message sender local time
  553. currTime = currTime.addSecs( zone * 60 );
  554. TQString timeofday;
  555. TQString color;
  556. TQString bg_color;
  557. TQString bg_image;
  558. if ( currTime > TQTime( 0, 0, 0 ) && currTime <= TQTime( 6, 0, 0 ) ) {
  559. timeofday = i18n( "Night" );
  560. color = "white";
  561. bg_color = "#000B6B";
  562. bg_image = "url(data:image/png;base64,"
  563. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAyCAIAAAASmSbdAAAAS0lEQVQI11WOsRGAQAzDOG/LHoz9"
  564. "kikIcF+kSBxbPs7LoNGVapAI0Zn+O+8NUwldozn6io7G7kdS/5zi7i+BvUM/5uSXlIfzMHx/bmWR"
  565. "k++yj9rZAAAAAElFTkSuQmCC)";
  566. }
  567. else if ( currTime > TQTime( 6, 0, 0 ) && currTime <= TQTime( 12, 0, 0 ) ) {
  568. timeofday = i18n( "Morning" );
  569. color = "black";
  570. bg_color = "#00A6FF";
  571. bg_image = "url(data:image/png;base64,"
  572. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAyCAYAAACd+7GKAAAAWklEQVQI122OQQ7DMAzDaP3/dfuO"
  573. "pWSHJgva7iZIBk3m/Ew5hexCHVCilewzFHKEbFZqgxJQWyzKhWKl9unqddJj8+L9sl0oR2gUim+o"
  574. "zu4uSh7kn67/DNv+C4tsZOtjAWEHAAAAAElFTkSuQmCC)";
  575. }
  576. else if ( currTime > TQTime( 12, 0, 0 ) && currTime <= TQTime( 18, 0, 0 ) ) {
  577. timeofday = i18n( "Afternoon" );
  578. color = "black";
  579. bg_color = "#00A6FF";
  580. bg_image = "url(data:image/png;base64,"
  581. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAyCAYAAACd+7GKAAAAPUlEQVQI132OwQ0AIAwCSfcfw91c"
  582. "QsCfRm399HFwoWjdDhMICQhxHSWMQPhkTCoqWRZU2h5i9tr4GZfmV5t3wWUI3h+NugAAAABJRU5E"
  583. "rkJggg==)";
  584. }
  585. else {
  586. timeofday = i18n( "Evening" );
  587. color = "white";
  588. bg_color = "#0014CC";
  589. bg_image = "url(data:image/png;base64,"
  590. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAyCAYAAACd+7GKAAAAWklEQVQI11WOyRHAMAgDNQuUlBrS"
  591. "fyFpAfKwje0PwyEt0vN+hVsJpzS6QML2ziWcFI6mZBZNSVDXYehyUgI1XsLI9eimHDH6kW0ddVIO"
  592. "xx7JjrtshlbXlLDSD+WhJ+hwqWo8AAAAAElFTkSuQmCC)";
  593. }
  594. TQString tformat;
  595. if ( TDEGlobal::locale()->use12Clock() ) {
  596. tformat = "h:mm AP";
  597. }
  598. else {
  599. tformat = "h:mm";
  600. }
  601. // kdDebug() << "FancyHeaderStyle::format() current time: " << currTime << " (" << timeofday << ")" << endl;
  602. timeHTML.append( TQString(
  603. "<div id=\"sendersCurrentTime\" style=\""
  604. "border:1px solid %1;"
  605. "color:%2;"
  606. "background-image:%3;"
  607. "background-position:center left;"
  608. "background-repeat:repeat-x;"
  609. "text-align:center;"
  610. "font-size:12px;"
  611. "padding:2px;"
  612. "width:150px;"
  613. "height:45px;"
  614. "margin: 0px 0px 3px 0px;"
  615. "\" class=\"curtime\">%4<br />%5<br />%6</div>"
  616. )
  617. .arg( bg_color )
  618. .arg( color )
  619. .arg( bg_image )
  620. .arg( i18n( "Sender's Current Time:" ) )
  621. .arg( currTime.toString( tformat ) )
  622. .arg( timeofday )
  623. );
  624. }
  625. else {
  626. // kdDebug() << "FancyHeaderStyle::format() no date header to display" << endl;
  627. }
  628. }
  629. //case HdrFancy:
  630. // the subject line and box below for details
  631. if ( strategy->showHeader( "subject" ) ) {
  632. const int flags = LinkLocator::PreserveSpaces |
  633. ( GlobalSettings::self()->showEmoticons() ?
  634. LinkLocator::ReplaceSmileys : 0 );
  635. headerStr += TQString("<div dir=\"%1\">%2</div>\n")
  636. .arg(subjectDir)
  637. .arg(message->subject().isEmpty()?
  638. i18n("No Subject") :
  639. strToHtml( message->subject(), flags ));
  640. }
  641. headerStr += "<table class=\"outer\"><tr><td width=\"100%\"><table>\n";
  642. //headerStr += "<table>\n";
  643. // from line
  644. // the mailto: URLs can contain %3 etc., therefore usage of multiple
  645. // TQString::arg is not possible
  646. if ( strategy->showHeader( "from" ) ) {
  647. TQString fromStr = message->from();
  648. if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
  649. fromStr = message->fromStrip(); // let's use that
  650. headerStr += TQString("<tr><th>%1</th>\n"
  651. "<td>")
  652. .arg(i18n("From: "))
  653. + KMMessage::emailAddrAsAnchor( fromStr, false )
  654. + ( !message->headerField( "Resent-From" ).isEmpty() ? "&nbsp;"
  655. + i18n("(resent from %1)")
  656. .arg( KMMessage::emailAddrAsAnchor(
  657. message->headerField( "Resent-From" ),false) )
  658. : TQString("") )
  659. + ( !vCardName.isEmpty() ? "&nbsp;&nbsp;<a href=\"" + vCardName + "\">"
  660. + i18n("[vCard]") + "</a>"
  661. : TQString("") )
  662. #if 0
  663. + ( ( !presence.isEmpty() )
  664. ? "&nbsp;&nbsp;(<span name=\"presence-" + tdeabcUid + "\">" + presence + "</span>)"
  665. : TQString("") )
  666. #endif
  667. + ( message->headerField("Organization").isEmpty()
  668. ? TQString("")
  669. : "&nbsp;&nbsp;("
  670. + strToHtml(message->headerField("Organization"))
  671. + ")")
  672. + "</td></tr>\n";
  673. }
  674. // to line
  675. if ( strategy->showHeader( "to" ) )
  676. headerStr.append(TQString("<tr><th>%1</th>\n"
  677. "<td>%2</td></tr>\n")
  678. .arg(i18n("To: "))
  679. .arg(KMMessage::emailAddrAsAnchor(message->to(),false)));
  680. // cc line, if any
  681. if ( strategy->showHeader( "cc" ) && !message->cc().isEmpty())
  682. headerStr.append(TQString("<tr><th>%1</th>\n"
  683. "<td>%2</td></tr>\n")
  684. .arg(i18n("CC: "))
  685. .arg(KMMessage::emailAddrAsAnchor(message->cc(),false)));
  686. // Bcc line, if any
  687. if ( strategy->showHeader( "bcc" ) && !message->bcc().isEmpty())
  688. headerStr.append(TQString("<tr><th>%1</th>\n"
  689. "<td>%2</td></tr>\n")
  690. .arg(i18n("BCC: "))
  691. .arg(KMMessage::emailAddrAsAnchor(message->bcc(),false)));
  692. if ( strategy->showHeader( "date" ) )
  693. headerStr.append(TQString("<tr><th>%1</th>\n"
  694. "<td dir=\"%2\">%3</td></tr>\n")
  695. .arg(i18n("Date: "))
  696. .arg( directionOf( message->dateStr() ) )
  697. .arg(strToHtml(dateString)));
  698. if ( GlobalSettings::self()->showUserAgent() ) {
  699. if ( strategy->showHeader( "user-agent" ) ) {
  700. if ( !message->headerField("User-Agent").isEmpty() ) {
  701. headerStr.append(TQString("<tr><th>%1</th>\n"
  702. "<td>%2</td></tr>\n")
  703. .arg(i18n("User-Agent: "))
  704. .arg( strToHtml( message->headerField("User-Agent") ) ) );
  705. }
  706. }
  707. if ( strategy->showHeader( "x-mailer" ) ) {
  708. if ( !message->headerField("X-Mailer").isEmpty() ) {
  709. headerStr.append(TQString("<tr><th>%1</th>\n"
  710. "<td>%2</td></tr>\n")
  711. .arg(i18n("X-Mailer: "))
  712. .arg( strToHtml( message->headerField("X-Mailer") ) ) );
  713. }
  714. }
  715. }
  716. // FIXME: Show status in synthetic header style field. Decide whether this or current in brackets style is best and remove one.
  717. /* if( strategy->showHeader( "status" ) )
  718. headerStr.append( TQString( "<tr><th>%1</th>\n"
  719. "<td dir=\"%2\">%3</td></tr>\n")
  720. .arg(i18n("Sender status: "))
  721. .arg( directionOf( onlineStatus ) )
  722. .arg(onlineStatus));
  723. */
  724. headerStr.append( TQString("<tr><td colspan=\"2\"><div id=\"attachmentInjectionPoint\"></div></td></tr>" ) );
  725. headerStr.append(
  726. TQString( "</table></td><td align=\"center\" valign=\"top\">%1%2</td></tr></table>\n" )
  727. .arg(timeHTML)
  728. .arg(userHTML) );
  729. if ( !spamHTML.isEmpty() )
  730. headerStr.append( TQString( "<div class=\"spamheader\" dir=\"%1\"><b>%2</b>&nbsp;<span style=\"padding-left: 20px;\">%3</span></div>\n")
  731. .arg( subjectDir, i18n("Spam Status:"), spamHTML ) );
  732. headerStr += "</div>\n\n";
  733. return headerStr;
  734. }
  735. TQString FancyHeaderStyle::imgToDataUrl( const TQImage &image, const char* fmt )
  736. {
  737. TQByteArray ba;
  738. TQBuffer buffer( ba );
  739. buffer.open( IO_WriteOnly );
  740. image.save( &buffer, fmt );
  741. return TQString::fromLatin1("data:image/%1;base64,%2")
  742. .arg( fmt, KCodecs::base64Encode( ba ).data() );
  743. }
  744. // #####################
  745. class EnterpriseHeaderStyle : public HeaderStyle {
  746. friend class ::KMail::HeaderStyle;
  747. protected:
  748. EnterpriseHeaderStyle() : HeaderStyle() {}
  749. virtual ~EnterpriseHeaderStyle() {}
  750. public:
  751. const char * name() const { return "enterprise"; }
  752. const HeaderStyle * next() const { return brief(); }
  753. const HeaderStyle * prev() const { return fancy(); }
  754. TQString format( const KMMessage * message, const HeaderStrategy * strategy,
  755. const TQString & vCardName, bool printing, bool topLevel ) const;
  756. };
  757. TQString EnterpriseHeaderStyle::format( const KMMessage * message,
  758. const HeaderStrategy * strategy,
  759. const TQString & vCardName, bool printing, bool topLevel ) const {
  760. if ( !message ) return TQString();
  761. if ( !strategy )
  762. strategy = HeaderStrategy::brief();
  763. // The direction of the header is determined according to the direction
  764. // of the application layout.
  765. TQString dir = TQApplication::reverseLayout() ? "rtl" : "ltr" ;
  766. // However, the direction of the message subject within the header is
  767. // determined according to the contents of the subject itself. Since
  768. // the "Re:" and "Fwd:" prefixes would always cause the subject to be
  769. // considered left-to-right, they are ignored when determining its
  770. // direction.
  771. TQString subjectDir;
  772. if (!message->subject().isEmpty())
  773. subjectDir = directionOf( message->cleanSubject() );
  774. else
  775. subjectDir = directionOf( i18n("No Subject") );
  776. // colors depend on if its encapsulated or not
  777. TQColor fontColor(TQt::white);
  778. TQString linkColor = "class =\"white\"";
  779. const TQColor activeColor = tqApp->palette().active().highlight();
  780. TQColor activeColorDark = activeColor.dark(130);
  781. // reverse colors for encapsulated
  782. if( !topLevel ){
  783. activeColorDark = activeColor.dark(50);
  784. fontColor = TQColor(TQt::black);
  785. linkColor = "class =\"black\"";
  786. }
  787. // Prepare the date string (when printing always use the localized date)
  788. TQString dateString;
  789. if( printing ) {
  790. TQDateTime dateTime;
  791. TDELocale * locale = TDEGlobal::locale();
  792. dateTime.setTime_t( message->date() );
  793. dateString = locale->formatDateTime( dateTime );
  794. } else {
  795. dateString = message->dateStr();
  796. }
  797. TQString imgpath(locate("data","kmail/pics/"));
  798. imgpath.append("enterprise_");
  799. const TQString borderSettings(" padding-top: 0px; padding-bottom: 0px; border-width: 0px ");
  800. TQString headerStr ("");
  801. // 3D borders
  802. if(topLevel)
  803. headerStr +=
  804. "<div style=\"position: fixed; top: 0px; left: 0px; background-color: #606060; "
  805. "width: 10px; min-height: 100%;\">&nbsp;</div>"
  806. "<div style=\"position: fixed; top: 0px; right: 0px; background-color: #606060; "
  807. "width: 10px; min-height: 100%;\">&nbsp;</div>";
  808. headerStr += ""
  809. "<div style=\"margin-left: 10px; top: 0px;\"><span style=\"font-size: 10px; font-weight: bold;\">"+dateString+"</span></div>"
  810. // #0057ae
  811. "<table style=\"background: "+activeColorDark.name()+"; border-collapse:collapse; top: 14px; min-width: 200px; \" cellpadding=0> \n"
  812. " <tr> \n"
  813. " <td style=\"min-width: 6px; background-image: url("+imgpath+"top_left.png); \"></td> \n"
  814. " <td style=\"height: 6px; width: 100%; background: url("+imgpath+"top.png); \"></td> \n"
  815. " <td style=\"min-width: 6px; background: url("+imgpath+"top_right.png); \"></td> </tr> \n"
  816. " <tr> \n"
  817. " <td style=\"min-width: 6px; max-width: 6px; background: url("+imgpath+"left.png); \"></td> \n"
  818. " <td style=\"\"> \n";
  819. headerStr +=
  820. " <div class=\"noprint\" style=\"z-index: 1; float:right; position: relative; top: -35px; right: 20px ;\">\n"
  821. " <img src=\""+imgpath+"icon.png\">\n"
  822. " </div>\n";
  823. headerStr +=
  824. " <table style=\"color: "+fontColor.name()+" ! important; margin: 1px; border-spacing: 0px;\" cellpadding=0> \n";
  825. // subject
  826. //strToHtml( message->subject() )
  827. if ( strategy->showHeader( "subject" ) ){
  828. headerStr +=
  829. " <tr> \n"
  830. " <td style=\"font-size: 6px; text-align: right; padding-left: 5px; padding-right: 24px; "+borderSettings+"\"></td> \n"
  831. " <td style=\"font-weight: bolder; font-size: 120%; padding-right: 91px; "+borderSettings+"\">"+message->subject()+"</td> \n"
  832. " </tr> \n";
  833. }
  834. // from
  835. if ( strategy->showHeader( "from" ) ){
  836. TQString fromStr = message->from();
  837. if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
  838. fromStr = message->fromStrip(); // let's use that
  839. // TODO vcard
  840. TQString fromPart = KMMessage::emailAddrAsAnchor( fromStr, true, linkColor );
  841. if ( !vCardName.isEmpty() )
  842. fromPart += "&nbsp;&nbsp;<a href=\"" + vCardName + "\" "+linkColor+">" + i18n("[vCard]") + "</a>";
  843. //TODO strategy date
  844. //if ( strategy->showHeader( "date" ) )
  845. headerStr +=
  846. " <tr> \n"
  847. " <td style=\"font-size: 6px; padding-left: 5px; padding-right: 24px; text-align: right; "+borderSettings+"\">"+i18n("From: ")+"</td> \n"
  848. " <td style=\""+borderSettings+"\">"+ fromPart +"</td> "
  849. " </tr> ";
  850. }
  851. // to line
  852. if( strategy->showHeader( "to" ) )
  853. headerStr +=
  854. " <tr> "
  855. " <td style=\"font-size: 6px; text-align: right; padding-left: 5px; padding-right: 24px; " + borderSettings + "\">" + i18n("To: ") + "</td> "
  856. " <td style=\"" + borderSettings + "\">" +
  857. KMMessage::emailAddrAsAnchor( message->to(), false, linkColor ) +
  858. " </td> "
  859. " </tr>\n";
  860. // cc line, if any
  861. if ( strategy->showHeader( "cc" ) && !message->cc().isEmpty() )
  862. headerStr +=
  863. " <tr> "
  864. " <td style=\"font-size: 6px; text-align: right; padding-left: 5px; padding-right: 24px; " + borderSettings + "\">" + i18n("CC: ") + "</td> "
  865. " <td style=\"" + borderSettings + "\">" +
  866. KMMessage::emailAddrAsAnchor( message->cc(), false, linkColor ) +
  867. " </td> "
  868. " </tr>\n";
  869. // bcc line, if any
  870. if ( strategy->showHeader( "bcc" ) && !message->bcc().isEmpty() )
  871. headerStr +=
  872. " <tr> "
  873. " <td style=\"font-size: 6px; text-align: right; padding-left: 5px; padding-right: 24px; " + borderSettings + "\">" + i18n("BCC: ") + "</td> "
  874. " <td style=\"" + borderSettings + "\">" +
  875. KMMessage::emailAddrAsAnchor( message->bcc(), false, linkColor ) +
  876. " </td> "
  877. " </tr>\n";
  878. // header-bottom
  879. headerStr +=
  880. " </table> \n"
  881. " </td> \n"
  882. " <td style=\"min-width: 6px; max-height: 15px; background: url("+imgpath+"right.png); \"></td> \n"
  883. " </tr> \n"
  884. " <tr> \n"
  885. " <td style=\"min-width: 6px; background: url("+imgpath+"s_left.png); \"></td> \n"
  886. " <td style=\"height: 35px; width: 80%; background: url("+imgpath+"sbar.png);\"> \n"
  887. " <img src=\""+imgpath+"sw.png\" style=\"margin: 0px; height: 30px; overflow:hidden; \"> \n"
  888. " <img src=\""+imgpath+"sp_right.png\" style=\"float: right; \"> </td> \n"
  889. " <td style=\"min-width: 6px; background: url("+imgpath+"s_right.png); \"></td> \n"
  890. " </tr> \n"
  891. " </table> \n";
  892. // kmail icon
  893. if(topLevel) {
  894. // attachments
  895. headerStr +=
  896. "<div class=\"noprint\" style=\"position: absolute; top: 60px; right: 20px; width: 91px; height: 200px;\">"
  897. "<div id=\"attachmentInjectionPoint\"></div>"
  898. "</div>\n";
  899. }
  900. if ( printing ) {
  901. //provide a bit more left padding when printing
  902. //kolab/issue3254 (printed mail cut at the left side)
  903. headerStr += "<div style=\"padding: 6px; padding-left: 10px;\">";
  904. } else {
  905. headerStr += "<div style=\"padding: 6px;\">";
  906. }
  907. // TODO
  908. // spam status
  909. // ### iterate over the rest of strategy->headerToDisplay() (or
  910. // ### all headers if DefaultPolicy == Display) (elsewhere, too)
  911. return headerStr;
  912. }
  913. // #####################
  914. //
  915. // HeaderStyle abstract base:
  916. //
  917. HeaderStyle::HeaderStyle() {
  918. }
  919. HeaderStyle::~HeaderStyle() {
  920. }
  921. const HeaderStyle * HeaderStyle::create( Type type ) {
  922. switch ( type ) {
  923. case Brief: return brief();
  924. case Plain: return plain();
  925. case Fancy: return fancy();
  926. case Enterprise: return enterprise();
  927. }
  928. kdFatal( 5006 ) << "HeaderStyle::create(): Unknown header style ( type == "
  929. << (int)type << " ) requested!" << endl;
  930. return 0; // make compiler happy
  931. }
  932. const HeaderStyle * HeaderStyle::create( const TQString & type ) {
  933. TQString lowerType = type.lower();
  934. if ( lowerType == "brief" ) return brief();
  935. if ( lowerType == "plain" ) return plain();
  936. if ( lowerType == "enterprise" ) return enterprise();
  937. //if ( lowerType == "fancy" ) return fancy(); // not needed, see below
  938. // don't kdFatal here, b/c the strings are user-provided
  939. // (TDEConfig), so fail gracefully to the default:
  940. return fancy();
  941. }
  942. static const HeaderStyle * briefStyle = 0;
  943. static const HeaderStyle * plainStyle = 0;
  944. static const HeaderStyle * fancyStyle = 0;
  945. static const HeaderStyle * enterpriseStyle = 0;
  946. const HeaderStyle * HeaderStyle::brief() {
  947. if ( !briefStyle )
  948. briefStyle = new BriefHeaderStyle();
  949. return briefStyle;
  950. }
  951. const HeaderStyle * HeaderStyle::plain() {
  952. if ( !plainStyle )
  953. plainStyle = new PlainHeaderStyle();
  954. return plainStyle;
  955. }
  956. const HeaderStyle * HeaderStyle::fancy() {
  957. if ( !fancyStyle )
  958. fancyStyle = new FancyHeaderStyle();
  959. return fancyStyle;
  960. }
  961. const HeaderStyle * HeaderStyle::enterprise() {
  962. if ( !enterpriseStyle )
  963. enterpriseStyle = new EnterpriseHeaderStyle();
  964. return enterpriseStyle;
  965. }
  966. } // namespace KMail