From 1c9cc33902d8242ec25b4416a1662ee6c9902583 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 28 Jul 2019 12:50:10 +0200 Subject: Try to localise timestamps I'm not sure, if that is the right way, but Qt doesn't really have a way to format custom localised dates, so I tried to find the closest approximations to what we currently have. Relates to #69 --- src/Utils.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index d6b092b1..a3c15c96 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -99,13 +99,13 @@ utils::descriptiveTime(const QDateTime &then) const auto days = then.daysTo(now); if (days == 0) - return then.toString("HH:mm"); + return then.time().toString(Qt::DefaultLocaleShortDate); else if (days < 2) - return QString("Yesterday"); - else if (days < 365) - return then.toString("dd/MM"); + return QString(QCoreApplication::translate("descriptiveTime", "Yesterday")); + else if (days < 7) + return then.toString("dddd"); - return then.toString("dd/MM/yy"); + return then.date().toString(Qt::DefaultLocaleShortDate); } DescInfo @@ -147,7 +147,7 @@ utils::getMessageDescription(const TimelineEvent &event, DescInfo info; if (sender == localUser) - info.username = "You"; + info.username = QCoreApplication::translate("utils", "You"); else info.username = username; @@ -366,16 +366,16 @@ utils::getQuoteBody(const RelatedInfo &related) return markdownToHtml(related.quoted_body); } case MsgType::File: { - return QString("sent a file."); + return QString(QCoreApplication::translate("utils", "sent a file.")); } case MsgType::Image: { - return QString("sent an image."); + return QString(QCoreApplication::translate("utils", "sent an image.")); } case MsgType::Audio: { - return QString("sent an audio file."); + return QString(QCoreApplication::translate("utils", "sent an audio file.")); } case MsgType::Video: { - return QString("sent a video"); + return QString(QCoreApplication::translate("utils", "sent a video")); } default: { return related.quoted_body; -- cgit 1.5.1 From d5bb0936bf8b16dc4a8b505192077576dbe96149 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Sat, 10 Aug 2019 13:14:37 -0400 Subject: Use 'system' theme as default if QT_QPA_PLATFORMTHEME is set On first launch, before the user has configured any settings, check the value of the QT_QPA_PLATFORMTHEME environment var. If it is set, use the system theme as the default instead of the light theme. This fixes #72. --- src/UserSettingsPage.cpp | 4 +++- src/UserSettingsPage.h | 7 ++++++- src/Utils.cpp | 19 +++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 49cb2c1f..30e6ea96 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include "Config.h" @@ -49,7 +51,7 @@ UserSettings::load() isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); - theme_ = settings.value("user/theme", "light").toString(); + theme_ = settings.value("user/theme", defaultTheme_).toString(); font_ = settings.value("user/font_family", "default").toString(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index ffff1e20..dce12315 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -85,7 +85,7 @@ public: save(); } - QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } + QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } @@ -100,6 +100,11 @@ signals: void groupViewStateChanged(bool state); private: + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme_ = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; QString theme_; bool isTrayEnabled_; bool isStartInTrayEnabled_; diff --git a/src/Utils.cpp b/src/Utils.cpp index a3c15c96..5c664b7c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -387,14 +388,20 @@ QString utils::linkColor() { QSettings settings; - const auto theme = settings.value("user/theme", "light").toString(); - - if (theme == "light") + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; + const auto theme = settings.value("user/theme", defaultTheme).toString(); + + if (theme == "light") { return "#0077b5"; - else if (theme == "dark") + } else if (theme == "dark") { return "#38A3D8"; - - return QPalette().color(QPalette::Link).name(); + } else { + return QPalette().color(QPalette::Link).name(); + } } uint32_t -- cgit 1.5.1 From 1659176c0d49c51cb2e20e2a4c1e823ffb2c6446 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 21 Sep 2019 01:38:17 +0200 Subject: escape html before parsing commonmark --- src/Utils.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 5c664b7c..8c02b1c2 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -324,10 +324,25 @@ utils::linkifyMessage(const QString &body) return doc; } +QByteArray escapeRawHtml(const QByteArray &data) { + QByteArray buffer; + const size_t length = data.size(); + buffer.reserve(length); + for(size_t pos = 0; pos != length; ++pos) { + switch(data.at(pos)) { + case '&': buffer.append("&"); break; + case '<': buffer.append("<"); break; + case '>': buffer.append(">"); break; + default: buffer.append(data.at(pos)); break; + } + } + return buffer; +} + QString utils::markdownToHtml(const QString &text) { - const auto str = text.toUtf8(); + const auto str = escapeRawHtml(text.toUtf8()); const char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_DEFAULT); -- cgit 1.5.1