From ce4b7dc190c609520850a94d0a38d87002ff9f12 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 20 Nov 2010 17:18:22 +0000 Subject: Include date for MUC context older than today. Resolves: #641 Release-Notes: MUC context for days other than today is now annotated. diff --git a/Swift/QtUI/ChatSnippet.cpp b/Swift/QtUI/ChatSnippet.cpp index 2218c07..4d23526 100644 --- a/Swift/QtUI/ChatSnippet.cpp +++ b/Swift/QtUI/ChatSnippet.cpp @@ -26,4 +26,23 @@ QString ChatSnippet::escape(const QString& original) { return result; } +QString ChatSnippet::timeToEscapedString(const QDateTime& time) { + QDate now(QDate::currentDate()); + QString date = ""; + if (time.date().daysTo(now) > 0) { + date = "ddd "; + } + if (time.date().month() != now.month()) { + date = date + "MMMM "; + } + if (time.date().daysTo(now) > 6) { + date = date + "d "; + } + if (time.date().year() != now.year()) { + date = date + "yy "; + } + date += "h:mm"; + return escape(time.toString(date)); +} + }; diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h index 69ca5b8..9786518 100644 --- a/Swift/QtUI/ChatSnippet.h +++ b/Swift/QtUI/ChatSnippet.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include "QtChatTheme.h" namespace Swift { @@ -24,6 +25,8 @@ namespace Swift { static QString escape(const QString&); + protected: + static QString timeToEscapedString(const QDateTime& time); private: bool appendToPrevious_; }; diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp index 9330cb1..995a0db 100644 --- a/Swift/QtUI/MessageSnippet.cpp +++ b/Swift/QtUI/MessageSnippet.cpp @@ -31,7 +31,7 @@ MessageSnippet::MessageSnippet(const QString& message, const QString& sender, co content_.replace("%message%", "" + escape(message) + ""); content_.replace("%sender%", escape(sender)); - content_.replace("%time%", "" + escape(time.toString("h:mm")) + ""); + content_.replace("%time%", "" + timeToEscapedString(time) + ""); content_.replace("%userIconPath%", escape(iconURI)); content_ = "
" + content_ + "
"; } diff --git a/Swift/QtUI/SystemMessageSnippet.cpp b/Swift/QtUI/SystemMessageSnippet.cpp index cf70c2e..13919b2 100644 --- a/Swift/QtUI/SystemMessageSnippet.cpp +++ b/Swift/QtUI/SystemMessageSnippet.cpp @@ -15,7 +15,7 @@ SystemMessageSnippet::SystemMessageSnippet(const QString& message, const QDateTi content_.replace("%message%", "" + escape(message) + ""); content_.replace("%shortTime%", escape(time.toString("h:mm"))); - content_.replace("%time%", "" + escape(time.toString("h:mm")) + ""); + content_.replace("%time%", "" + timeToEscapedString(time) + ""); } SystemMessageSnippet::~SystemMessageSnippet() { -- cgit v0.10.2-6-g49f6