Commit bf3a2174 authored by Laurent Montel's avatar Laurent Montel 😁

Transform as class

parent 394e35f7
......@@ -51,6 +51,7 @@ public:
delete engine;
}
MessageViewer::HeaderStyleUtil headerStyleUtil;
QSharedPointer<Grantlee::FileSystemTemplateLoader> templateLoader;
Grantlee::Engine *engine;
};
......@@ -103,10 +104,10 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
const QString absoluteThemePath = QStringLiteral("file://") + absolutePath + QLatin1Char('/');
headerObject.insert(QStringLiteral("absoluteThemePath"), absoluteThemePath);
headerObject.insert(QStringLiteral("applicationDir"), QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr"));
headerObject.insert(QStringLiteral("subjectDir"), MessageViewer::HeaderStyleUtil::subjectDirectionString(message));
headerObject.insert(QStringLiteral("subjectDir"), d->headerStyleUtil.subjectDirectionString(message));
headerObject.insert(QStringLiteral("subjecti18n"), i18n("Subject:"));
headerObject.insert(QStringLiteral("subject"), MessageViewer::HeaderStyleUtil::subjectString(message));
headerObject.insert(QStringLiteral("subject"), d->headerStyleUtil.subjectString(message));
headerObject.insert(QStringLiteral("toi18n"), i18n("To:"));
headerObject.insert(QStringLiteral("to"), StringUtil::emailAddrAsAnchor(message->to(), StringUtil::DisplayFullAddress));
......@@ -148,41 +149,41 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
headerObject.insert(QStringLiteral("from"), StringUtil::emailAddrAsAnchor(message->from(), StringUtil::DisplayFullAddress));
headerObject.insert(QStringLiteral("fromStr"), message->from()->asUnicodeString());
const QString spamHtml = MessageViewer::HeaderStyleUtil::spamStatus(message);
const QString spamHtml = d->headerStyleUtil.spamStatus(message);
if (!spamHtml.isEmpty()) {
headerObject.insert(QStringLiteral("spamstatusi18n"), i18n("Spam Status:"));
headerObject.insert(QStringLiteral("spamHTML"), spamHtml);
}
headerObject.insert(QStringLiteral("datei18n"), i18n("Date:"));
headerObject.insert(QStringLiteral("dateshort"), MessageViewer::HeaderStyleUtil::strToHtml(MessageViewer::HeaderStyleUtil::dateString(message, isPrinting, true)));
headerObject.insert(QStringLiteral("datelong"), MessageViewer::HeaderStyleUtil::strToHtml(MessageViewer::HeaderStyleUtil::dateString(message, isPrinting, false)));
headerObject.insert(QStringLiteral("date"), MessageViewer::HeaderStyleUtil::dateStr(message->date()->dateTime()));
headerObject.insert(QStringLiteral("dateshort"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, true)));
headerObject.insert(QStringLiteral("datelong"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, false)));
headerObject.insert(QStringLiteral("date"), d->headerStyleUtil.dateStr(message->date()->dateTime()));
if (MessageViewer::MessageViewerSettings::self()->showUserAgent()) {
if (auto hdr = message->userAgent(false)) {
headerObject.insert(QStringLiteral("useragent"), MessageViewer::HeaderStyleUtil::strToHtml(hdr->asUnicodeString()));
headerObject.insert(QStringLiteral("useragent"), d->headerStyleUtil.strToHtml(hdr->asUnicodeString()));
}
if (message->headerByType("X-Mailer")) {
headerObject.insert(QStringLiteral("xmailer"), MessageViewer::HeaderStyleUtil::strToHtml(message->headerByType("X-Mailer")->asUnicodeString()));
headerObject.insert(QStringLiteral("xmailer"), d->headerStyleUtil.strToHtml(message->headerByType("X-Mailer")->asUnicodeString()));
}
}
if (message->headerByType("Resent-From")) {
headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from"));
const QVector<KMime::Types::Mailbox> resentFrom = MessageViewer::HeaderStyleUtil::resentFromList(message);
const QVector<KMime::Types::Mailbox> resentFrom = d->headerStyleUtil.resentFromList(message);
headerObject.insert(QStringLiteral("resentfrom"), StringUtil::emailAddrAsAnchor(resentFrom, StringUtil::DisplayFullAddress));
}
if (message->headerByType("Resent-To")) {
const QVector<KMime::Types::Mailbox> resentTo = MessageViewer::HeaderStyleUtil::resentToList(message);
const QVector<KMime::Types::Mailbox> resentTo = d->headerStyleUtil.resentToList(message);
headerObject.insert(QStringLiteral("resenttoi18n"), i18np("receiver was", "receivers were", resentTo.count()));
headerObject.insert(QStringLiteral("resentto"), StringUtil::emailAddrAsAnchor(resentTo, StringUtil::DisplayFullAddress));
}
if (auto organization = message->organization(false)) {
headerObject.insert(QStringLiteral("organization"), MessageViewer::HeaderStyleUtil::strToHtml(organization->asUnicodeString()));
headerObject.insert(QStringLiteral("organization"), d->headerStyleUtil.strToHtml(organization->asUnicodeString()));
}
if (!style->vCardName().isEmpty()) {
......@@ -213,7 +214,7 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
headerObject.insert(QStringLiteral("fontcolor"), fontColor.name());
headerObject.insert(QStringLiteral("linkcolor"), linkColor);
MessageViewer::HeaderStyleUtil::xfaceSettings xface = MessageViewer::HeaderStyleUtil::xface(style, message);
MessageViewer::HeaderStyleUtil::xfaceSettings xface = d->headerStyleUtil.xface(style, message);
if (!xface.photoURL.isEmpty()) {
headerObject.insert(QStringLiteral("photowidth"), xface.photoWidth);
headerObject.insert(QStringLiteral("photoheight"), xface.photoHeight);
......
......@@ -59,7 +59,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
// considered left-to-right, they are ignored when determining its
// direction.
const QString subjectDir = MessageViewer::HeaderStyleUtil::subjectDirectionString(message);
const QString subjectDir = mHeaderStyleUtil.subjectDirectionString(message);
QString headerStr;
if (strategy->headersToDisplay().isEmpty()
......@@ -76,10 +76,10 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
//case HdrLong:
if (strategy->showHeader(QStringLiteral("subject")))
headerStr += QStringLiteral("<div dir=\"%1\"><b style=\"font-size:130%\">").arg(subjectDir) +
MessageViewer::HeaderStyleUtil::subjectString(message) + QLatin1String("</b></div>\n");
mHeaderStyleUtil.subjectString(message) + QLatin1String("</b></div>\n");
if (strategy->showHeader(QStringLiteral("date"))) {
headerStr.append(i18n("Date: ") + MessageViewer::HeaderStyleUtil::strToHtml(MessageViewer::HeaderStyleUtil::dateString(message, isPrinting(), /* short = */ false)) + QLatin1String("<br/>\n"));
headerStr.append(i18n("Date: ") + mHeaderStyleUtil.strToHtml(mHeaderStyleUtil.dateString(message, isPrinting(), /* short = */ false)) + QLatin1String("<br/>\n"));
}
if (strategy->showHeader(QStringLiteral("from"))) {
......@@ -92,7 +92,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
if (strategy->showHeader(QStringLiteral("organization"))
&& message->organization(false))
headerStr.append(QLatin1String("&nbsp;&nbsp;(") +
MessageViewer::HeaderStyleUtil::strToHtml(message->organization()->asUnicodeString()) + QLatin1Char(')'));
mHeaderStyleUtil.strToHtml(message->organization()->asUnicodeString()) + QLatin1Char(')'));
headerStr.append(QLatin1String("<br/>\n"));
}
......@@ -123,7 +123,7 @@ QString PlainHeaderStyle::formatAllMessageHeaders(KMime::Message *message) const
KMime::Headers::Base *header = KMime::HeaderParsing::extractFirstHeader(head);
QString result;
while (header) {
result += MessageViewer::HeaderStyleUtil::strToHtml(QLatin1String(header->type()) + QLatin1String(": ") + header->asUnicodeString());
result += mHeaderStyleUtil.strToHtml(QLatin1String(header->type()) + QLatin1String(": ") + header->asUnicodeString());
result += QLatin1String("<br />\n");
delete header;
header = KMime::HeaderParsing::extractFirstHeader(head);
......
......@@ -19,10 +19,10 @@
#define PLAINHEADERSTYLE_H
#include "messageviewer/headerstyle.h"
#include "headerstyle_util.h"
#include "messageviewer_export.h"
namespace MessageViewer
{
class MESSAGEVIEWER_EXPORT PlainHeaderStyle : public HeaderStyle
{
public:
......@@ -36,6 +36,7 @@ public:
private:
QString formatAllMessageHeaders(KMime::Message *message) const;
MessageViewer::HeaderStyleUtil mHeaderStyleUtil;
};
}
#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