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

Add support for more date format

parent 6eda8621
......@@ -18,7 +18,7 @@ include(KDEFrameworkCompilerSettings)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
set(MESSAGELIB_LIB_VERSION "5.1.60")
set(MESSAGELIB_LIB_VERSION "5.1.61")
set(KF5_VERSION "5.17.0")
set(KDEPIMLIBS_LIB_VERSION "5.1.42")
......
......@@ -155,9 +155,12 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
}
headerObject.insert(QStringLiteral("datei18n"), i18n("Date:"));
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("dateshort"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, MessageViewer::HeaderStyleUtil::ShortDate)));
headerObject.insert(QStringLiteral("datelong"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, MessageViewer::HeaderStyleUtil::CustomDate)));
headerObject.insert(QStringLiteral("date"), d->headerStyleUtil.dateStr(message->date()->dateTime()));
headerObject.insert(QStringLiteral("datefancylong"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, MessageViewer::HeaderStyleUtil::FancyLongDate)));
headerObject.insert(QStringLiteral("datefancyshort"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, MessageViewer::HeaderStyleUtil::FancyShortDate)));
headerObject.insert(QStringLiteral("datelocalelong"), d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, isPrinting, MessageViewer::HeaderStyleUtil::LongDate)));
if (MessageViewer::MessageViewerSettings::self()->showUserAgent()) {
if (auto hdr = message->userAgent(false)) {
......
......@@ -52,7 +52,7 @@ QString HeaderStyleUtil::strToHtml(const QString &str, KTextToHTML::Options flag
}
// Prepare the date string (when printing always use the localized date)
QString HeaderStyleUtil::dateString(KMime::Message *message, bool printing, bool shortDate) const
QString HeaderStyleUtil::dateString(KMime::Message *message, bool printing, HeaderStyleUtilDateFormat dateFormat) const
{
const QDateTime dateTime = message->date()->dateTime();
if (!dateTime.isValid()) {
......@@ -61,10 +61,19 @@ QString HeaderStyleUtil::dateString(KMime::Message *message, bool printing, bool
if (printing) {
return QLocale::system().toString(dateTime, QLocale::ShortFormat);
} else {
if (shortDate) {
switch(dateFormat) {
case ShortDate:
return QLocale::system().toString(dateTime, QLocale::ShortFormat);
case LongDate:
return QLocale::system().toString(dateTime, QLocale::LongFormat);
case FancyShortDate:
return dateShortStr(dateTime);
} else {
return dateStr(dateTime);
case FancyLongDate:
//Laurent fix me
//TODO return QLocale::system().toString(dateTime, QLocale::LongFormat);
case CustomDate:
default:
return dateStr( dateTime );
}
}
}
......
......@@ -45,13 +45,23 @@ public:
int photoWidth;
int photoHeight;
};
enum HeaderStyleUtilDateFormat {
ShortDate, /**< Locale Short date format, e.g. 08-04-2007 */
LongDate, /**< Locale Long date format, e.g. Sunday 08 April 2007 */
FancyShortDate, /**< Same as ShortDate for dates a week or more ago. For more
recent dates, it is represented as Today, Yesterday, or
the weekday name. */
FancyLongDate, /**< Same as LongDate for dates a week or more ago. For more
recent dates, it is represented as Today, Yesterday, or
the weekday name. */
CustomDate
};
QString directionOf(const QString &str) const;
QString strToHtml(const QString &str, KTextToHTML::Options flags = KTextToHTML::PreserveSpaces) const;
QString dateString(KMime::Message *message, bool printing, bool shortDate) const;
QString dateString(KMime::Message *message, bool printing, HeaderStyleUtilDateFormat dateFormat) const;
QString subjectString(KMime::Message *message, KTextToHTML::Options flags = KTextToHTML::PreserveSpaces) const;
......
......@@ -79,7 +79,7 @@ QString PlainHeaderStyle::format(KMime::Message *message) const
mHeaderStyleUtil.subjectString(message) + QLatin1String("</b></div>\n");
if (strategy->showHeader(QStringLiteral("date"))) {
headerStr.append(i18n("Date: ") + mHeaderStyleUtil.strToHtml(mHeaderStyleUtil.dateString(message, isPrinting(), /* short = */ false)) + QLatin1String("<br/>\n"));
headerStr.append(i18n("Date: ") + mHeaderStyleUtil.strToHtml(mHeaderStyleUtil.dateString(message, isPrinting(), /* short = */ MessageViewer::HeaderStyleUtil::CustomDate)) + QLatin1String("<br/>\n"));
}
if (strategy->showHeader(QStringLiteral("from"))) {
......
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