From 7a0c3cbf9143aaa9293c1048b15dc1cd63c2ce36 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Wed, 11 Oct 2023 23:58:43 +0200 Subject: Allow users to set their own timestamp formats. --- src/defaults.cpp | 1 + src/gui/widgets/tabs/chat/chattab.cpp | 4 +++- src/gui/widgets/tabs/setup_chat.cpp | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/defaults.cpp b/src/defaults.cpp index 3f806f572..f209ec9b2 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -270,6 +270,7 @@ void setConfigDefaults(Configuration &cfg) AddDEF("unsecureChars", "IO0@#$"); AddDEF("currentTip", 0); AddDEF("useLocalTime", false); + AddDEF("chatTimeStampFormat", "[%H:%M]"); AddDEF("enableAdvert", true); AddDEF("enableMapReduce", true); AddDEF("showPlayersStatus", true); diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index f619a881c..8e83d14bc 100644 --- a/src/gui/widgets/tabs/chat/chattab.cpp +++ b/src/gui/widgets/tabs/chat/chattab.cpp @@ -252,8 +252,10 @@ void ChatTab::chatLog(std::string line, if (timeInfo != nullptr) { char timeStamp[64]; // 64 bytes should be enough for everybody?? C.. + // TODO: cache this and useLocalTime somehow, respond to change event. + std::string timeFormat = config.getStringValue("chatTimeStampFormat"); - size_t res = strftime(timeStamp, 64, "[%H:%M]", timeInfo); + size_t res = strftime(timeStamp, 64, timeFormat.c_str(), timeInfo); // strftime returns 0 even in case of success (empty format or %p) // see strftime(3) for further details. if (res > 0) diff --git a/src/gui/widgets/tabs/setup_chat.cpp b/src/gui/widgets/tabs/setup_chat.cpp index 7ac53f38b..c1fa49f92 100644 --- a/src/gui/widgets/tabs/setup_chat.cpp +++ b/src/gui/widgets/tabs/setup_chat.cpp @@ -321,6 +321,14 @@ Setup_Chat::Setup_Chat(const Widget2 *const widget) : "useLocalTime", this, "useLocalTimeEvent", MainConfig_true); + // TRANSLATORS: settings option + new SetupItemTextField(_("Chat time stamp format"), + // TRANSLATORS: settings description + _("Format to use to prefix chat lines. Default [%H:%M]."), + "chatTimeStampFormat", this, "chatTimeStampFormatEvent", + MainConfig_true, UseBase64_false); + + // TRANSLATORS: settings group new SetupItemLabel(_("Other"), "", this, Separator_true); -- cgit v1.2.3-60-g2f50