Commit 90e28533 authored by Laurent Montel's avatar Laurent Montel 😁

Add private class

parent 13d26538
...@@ -31,12 +31,45 @@ using namespace MessageCore; ...@@ -31,12 +31,45 @@ using namespace MessageCore;
using namespace MessageViewer; using namespace MessageViewer;
class MessageViewer::PlainHeaderStylePrivate
{
public:
PlainHeaderStylePrivate()
{
}
QString formatAllMessageHeaders(KMime::Message *message) const;
MessageViewer::HeaderStyleUtil mHeaderStyleUtil;
};
QString PlainHeaderStylePrivate::formatAllMessageHeaders(KMime::Message *message) const
{
QByteArray head = message->head();
KMime::Headers::Base *header = KMime::HeaderParsing::extractFirstHeader(head);
QString result;
while (header) {
result += mHeaderStyleUtil.strToHtml(QLatin1String(header->type()) + QLatin1String(": ") + header->asUnicodeString());
result += QLatin1String("<br />\n");
delete header;
header = KMime::HeaderParsing::extractFirstHeader(head);
}
return result;
}
PlainHeaderStyle::PlainHeaderStyle() PlainHeaderStyle::PlainHeaderStyle()
: HeaderStyle() : HeaderStyle(),
d(new MessageViewer::PlainHeaderStylePrivate)
{ {
} }
PlainHeaderStyle::~PlainHeaderStyle()
{
delete d;
}
// //
// PlainHeaderStyle: // PlainHeaderStyle:
// show every header field on a line by itself, // show every header field on a line by itself,
...@@ -59,7 +92,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const ...@@ -59,7 +92,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
// considered left-to-right, they are ignored when determining its // considered left-to-right, they are ignored when determining its
// direction. // direction.
const QString subjectDir = mHeaderStyleUtil.subjectDirectionString(message); const QString subjectDir = d->mHeaderStyleUtil.subjectDirectionString(message);
QString headerStr; QString headerStr;
if (strategy->headersToDisplay().isEmpty() if (strategy->headersToDisplay().isEmpty()
...@@ -67,7 +100,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const ...@@ -67,7 +100,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
// crude way to emulate "all" headers - Note: no strings have // crude way to emulate "all" headers - Note: no strings have
// i18n(), so direction should always be ltr. // i18n(), so direction should always be ltr.
headerStr = QStringLiteral("<div class=\"header\" dir=\"ltr\">"); headerStr = QStringLiteral("<div class=\"header\" dir=\"ltr\">");
headerStr += formatAllMessageHeaders(message); headerStr += d->formatAllMessageHeaders(message);
return headerStr + QLatin1String("</div>"); return headerStr + QLatin1String("</div>");
} }
...@@ -76,10 +109,10 @@ QString PlainHeaderStyle::format(KMime::Message *message) const ...@@ -76,10 +109,10 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
//case HdrLong: //case HdrLong:
if (strategy->showHeader(QStringLiteral("subject"))) if (strategy->showHeader(QStringLiteral("subject")))
headerStr += QStringLiteral("<div dir=\"%1\"><b style=\"font-size:130%\">").arg(subjectDir) + headerStr += QStringLiteral("<div dir=\"%1\"><b style=\"font-size:130%\">").arg(subjectDir) +
mHeaderStyleUtil.subjectString(message) + QLatin1String("</b></div>\n"); d->mHeaderStyleUtil.subjectString(message) + QLatin1String("</b></div>\n");
if (strategy->showHeader(QStringLiteral("date"))) { if (strategy->showHeader(QStringLiteral("date"))) {
headerStr.append(i18n("Date: ") + mHeaderStyleUtil.strToHtml(mHeaderStyleUtil.dateString(message, isPrinting(), /* short = */ MessageViewer::HeaderStyleUtil::CustomDate)) + QLatin1String("<br/>\n")); headerStr.append(i18n("Date: ") + d->mHeaderStyleUtil.strToHtml(d->mHeaderStyleUtil.dateString(message, isPrinting(), /* short = */ MessageViewer::HeaderStyleUtil::CustomDate)) + QLatin1String("<br/>\n"));
} }
if (strategy->showHeader(QStringLiteral("from"))) { if (strategy->showHeader(QStringLiteral("from"))) {
...@@ -92,7 +125,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const ...@@ -92,7 +125,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
if (strategy->showHeader(QStringLiteral("organization")) if (strategy->showHeader(QStringLiteral("organization"))
&& message->organization(false)) && message->organization(false))
headerStr.append(QLatin1String("&nbsp;&nbsp;(") + headerStr.append(QLatin1String("&nbsp;&nbsp;(") +
mHeaderStyleUtil.strToHtml(message->organization()->asUnicodeString()) + QLatin1Char(')')); d->mHeaderStyleUtil.strToHtml(message->organization()->asUnicodeString()) + QLatin1Char(')'));
headerStr.append(QLatin1String("<br/>\n")); headerStr.append(QLatin1String("<br/>\n"));
} }
...@@ -117,20 +150,6 @@ QString PlainHeaderStyle::format(KMime::Message *message) const ...@@ -117,20 +150,6 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
return headerStr; return headerStr;
} }
QString PlainHeaderStyle::formatAllMessageHeaders(KMime::Message *message) const
{
QByteArray head = message->head();
KMime::Headers::Base *header = KMime::HeaderParsing::extractFirstHeader(head);
QString result;
while (header) {
result += mHeaderStyleUtil.strToHtml(QLatin1String(header->type()) + QLatin1String(": ") + header->asUnicodeString());
result += QLatin1String("<br />\n");
delete header;
header = KMime::HeaderParsing::extractFirstHeader(head);
}
return result;
}
const char *MessageViewer::PlainHeaderStyle::name() const const char *MessageViewer::PlainHeaderStyle::name() const
{ {
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
#define PLAINHEADERSTYLE_H #define PLAINHEADERSTYLE_H
#include "messageviewer/headerstyle.h" #include "messageviewer/headerstyle.h"
#include "headerstyle_util.h"
#include "messageviewer_export.h" #include "messageviewer_export.h"
namespace MessageViewer namespace MessageViewer
{ {
class PlainHeaderStylePrivate;
class MESSAGEVIEWER_EXPORT PlainHeaderStyle : public HeaderStyle class MESSAGEVIEWER_EXPORT PlainHeaderStyle : public HeaderStyle
{ {
public: public:
PlainHeaderStyle(); PlainHeaderStyle();
~PlainHeaderStyle() {} ~PlainHeaderStyle();
public: public:
const char *name() const Q_DECL_OVERRIDE; const char *name() const Q_DECL_OVERRIDE;
...@@ -35,8 +36,7 @@ public: ...@@ -35,8 +36,7 @@ public:
QString format(KMime::Message *message) const Q_DECL_OVERRIDE; QString format(KMime::Message *message) const Q_DECL_OVERRIDE;
private: private:
QString formatAllMessageHeaders(KMime::Message *message) const; PlainHeaderStylePrivate *const d;
MessageViewer::HeaderStyleUtil mHeaderStyleUtil;
}; };
} }
#endif // PLAINHEADERSTYLE_H #endif // PLAINHEADERSTYLE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment