Optionally use system locale for chat timestamp
[quassel.git] / src / qtui / chatscene.cpp
index 188eba6..dbe4220 100644 (file)
@@ -134,6 +134,9 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
     _showSenderBrackets = defaultSettings.showSenderBrackets();
     defaultSettings.notify("ShowSenderBrackets", this, SLOT(showSenderBracketsChanged()));
 
+    _useCustomTimestampFormat = defaultSettings.useCustomTimestampFormat();
+    defaultSettings.notify("UseCustomTimestampFormat", this, SLOT(useCustomTimestampFormatChanged()));
+
     _timestampFormatString = defaultSettings.timestampFormatString();
     defaultSettings.notify("TimestampFormat", this, SLOT(timestampFormatStringChanged()));
     updateTimestampHasBrackets();
@@ -1346,6 +1349,13 @@ void ChatScene::showSenderBracketsChanged()
     _showSenderBrackets = settings.showSenderBrackets();
 }
 
+void ChatScene::useCustomTimestampFormatChanged()
+{
+    ChatViewSettings settings;
+    _useCustomTimestampFormat = settings.useCustomTimestampFormat();
+    updateTimestampHasBrackets();
+}
+
 void ChatScene::timestampFormatStringChanged()
 {
     ChatViewSettings settings;
@@ -1357,23 +1367,29 @@ void ChatScene::updateTimestampHasBrackets()
 {
     // Calculate these parameters only as needed, rather than on-demand
 
-    // Does the timestamp format contain brackets?  For example:
-    // Classic: "[hh:mm:ss]"
-    // Modern:  " hh:mm:ss"
-    //
-    // Match groups of any opening or closing brackets - (), {}, [], <>, (>, {], etc:
-    //   ^\s*[({[<].+[)}\]>]\s*$
-    //   [...]    is a character group containing ...
-    //   ^        matches start of string
-    //   \s*      matches any amount of whitespace
-    //   [({[<]   matches (, {, [, or <
-    //   .+       matches one or more characters
-    //   [)}\]>]  matches ), }, ], or >, escaping the ]
-    //   $        matches end of string
-    // Alternatively, if opening and closing brackets must be in pairs, use this:
-    //   (^\s*\(.+\)\s*$)|(^\s*\{.+\}\s*$)|(^\s*\[.+\]\s*$)|(^\s*<.+>\s*$)
-    // Note that '\' must be escaped as '\\'
-    // Helpful interactive website for debugging and explaining:  https://regex101.com/
-    const QRegExp regExpMatchBrackets("^\\s*[({[<].+[)}\\]>]\\s*$");
-    _timestampHasBrackets = regExpMatchBrackets.exactMatch(_timestampFormatString);
+    if (!_useCustomTimestampFormat) {
+        // The default timestamp format string does not have brackets, no need to check.
+        // If UiStyle::updateSystemTimestampFormat() has brackets added, change this, too.
+        _timestampHasBrackets = false;
+    } else {
+        // Does the timestamp format contain brackets?  For example:
+        // Classic: "[hh:mm:ss]"
+        // Modern:  " hh:mm:ss"
+        //
+        // Match groups of any opening or closing brackets - (), {}, [], <>, (>, {], etc:
+        //   ^\s*[({[<].+[)}\]>]\s*$
+        //   [...]    is a character group containing ...
+        //   ^        matches start of string
+        //   \s*      matches any amount of whitespace
+        //   [({[<]   matches (, {, [, or <
+        //   .+       matches one or more characters
+        //   [)}\]>]  matches ), }, ], or >, escaping the ]
+        //   $        matches end of string
+        // Alternatively, if opening and closing brackets must be in pairs, use this:
+        //   (^\s*\(.+\)\s*$)|(^\s*\{.+\}\s*$)|(^\s*\[.+\]\s*$)|(^\s*<.+>\s*$)
+        // Note that '\' must be escaped as '\\'
+        // Helpful interactive website for debugging and explaining:  https://regex101.com/
+        const QRegExp regExpMatchBrackets("^\\s*[({[<].+[)}\\]>]\\s*$");
+        _timestampHasBrackets = regExpMatchBrackets.exactMatch(_timestampFormatString);
+    }
 }