summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/ChatSnippet.cpp19
-rw-r--r--Swift/QtUI/ChatSnippet.h3
-rw-r--r--Swift/QtUI/MessageSnippet.cpp2
-rw-r--r--Swift/QtUI/SystemMessageSnippet.cpp2
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() {