diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-11-20 17:18:22 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-11-20 17:18:22 (GMT) |
commit | ce4b7dc190c609520850a94d0a38d87002ff9f12 (patch) | |
tree | 31e25560572f53bc68011bcfb07f4972f15d62e8 /Swift/QtUI | |
parent | 71e3018e19db2ffa9d80d92c4c33e084737d40f4 (diff) | |
download | swift-ce4b7dc190c609520850a94d0a38d87002ff9f12.zip swift-ce4b7dc190c609520850a94d0a38d87002ff9f12.tar.bz2 |
Include date for MUC context older than today.
Resolves: #641
Release-Notes: MUC context for days other than today is now annotated.
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/ChatSnippet.cpp | 19 | ||||
-rw-r--r-- | Swift/QtUI/ChatSnippet.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/MessageSnippet.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/SystemMessageSnippet.cpp | 2 |
4 files changed, 24 insertions, 2 deletions
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 <QString> +#include <QDateTime> #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%", "<span class='swift_message'>" + escape(message) + "</span><span class='swift_ack'></span>"); content_.replace("%sender%", escape(sender)); - content_.replace("%time%", "<span class='swift_time'>" + escape(time.toString("h:mm")) + "</span>"); + content_.replace("%time%", "<span class='swift_time'>" + timeToEscapedString(time) + "</span>"); content_.replace("%userIconPath%", escape(iconURI)); content_ = "<div id='" + id + "'>" + content_ + "</div>"; } 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%", "<span class='swift_message'>" + escape(message) + "</span>"); content_.replace("%shortTime%", escape(time.toString("h:mm"))); - content_.replace("%time%", "<span class='swift_time'>" + escape(time.toString("h:mm")) + "</span>"); + content_.replace("%time%", "<span class='swift_time'>" + timeToEscapedString(time) + "</span>"); } SystemMessageSnippet::~SystemMessageSnippet() { |