Make sender brackets configurable, on by default
authorShane Synan <digitalcircuit36939@gmail.com>
Tue, 28 Jun 2016 02:32:30 +0000 (22:32 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 6 Sep 2016 20:14:48 +0000 (22:14 +0200)
Add a toggle to Settings -> Interface -> Chat View so sender brackets
can be enabled and disabled as desired.  Keeping with the timestamp
change, brackets are disabled by default but can be easily reenabled.

Revert Chat Monitor to include ':' as a separator between the
network:buffer:sender line, for otherwise it can be hard to read.

src/qtui/chatmonitorfilter.cpp
src/qtui/chatmonitorfilter.h
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatviewsettings.h
src/qtui/qtuistyle.cpp
src/qtui/qtuistyle.h
src/qtui/settingspages/chatviewsettingspage.ui
src/uisupport/uistyle.cpp
src/uisupport/uistyle.h

index 8050653..5cd366e 100644 (file)
 ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
     : MessageFilter(model, parent)
 {
+    // Global configuration
+    ChatViewSettings defaultSettings;
+    _showSenderBrackets = defaultSettings.showSenderBrackets();
+    defaultSettings.notify("ShowSenderBrackets", this, SLOT(showSenderBracketsSettingChanged(const QVariant &)));
+
+    // Chat Monitor specific configuration
     ChatViewSettings viewSettings(idString());
     _showFields = viewSettings.value("ShowFields", AllFields).toInt();
     _showOwnMessages = viewSettings.value("ShowOwnMsgs", true).toBool();
@@ -123,7 +129,10 @@ QVariant ChatMonitorFilter::data(const QModelIndex &index, int role) const
         QString sender = MessageFilter::data(index, ChatLineModel::EditRole).toString();
         fields << sender;
     }
-    return QString("%1").arg(fields.join(" "));
+    if (_showSenderBrackets)
+        return QString("<%1>").arg(fields.join(":"));
+    else
+        return QString("%1").arg(fields.join(":"));
 }
 
 
@@ -204,3 +213,8 @@ void ChatMonitorFilter::showBacklogSettingChanged(const QVariant &newValue) {
 void ChatMonitorFilter::includeReadSettingChanged(const QVariant &newValue) {
     _includeRead = newValue.toBool();
 }
+
+void ChatMonitorFilter::showSenderBracketsSettingChanged(const QVariant &newValue)
+{
+    _showSenderBrackets = newValue.toBool();
+}
index be3ae99..1ffcea9 100644 (file)
@@ -60,6 +60,12 @@ private slots:
     void buffersSettingChanged(const QVariant &newValue);
     void showBacklogSettingChanged(const QVariant &newValue);
     void includeReadSettingChanged(const QVariant &newValue);
+    /**
+     * Updates the local setting cache of whether or not to show sender brackets
+     *
+     * @param[in] newValue  If true, sender brackets are enabled, otherwise false.
+     */
+    void showSenderBracketsSettingChanged(const QVariant &newValue);
 
 private:
     int _showFields;
@@ -69,6 +75,7 @@ private:
     int _operationMode;
     bool _showBacklog;
     bool _includeRead;
+    bool _showSenderBrackets;   /// If true, show brackets around sender names
 };
 
 
index 8a5f7d4..9654626 100644 (file)
@@ -131,6 +131,9 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
     _showWebPreview = defaultSettings.showWebPreview();
     defaultSettings.notify("ShowWebPreview", this, SLOT(showWebPreviewChanged()));
 
+    _showSenderBrackets = defaultSettings.showSenderBrackets();
+    defaultSettings.notify("ShowSenderBrackets", this, SLOT(showSenderBracketsChanged()));
+
     _clickTimer.setInterval(QApplication::doubleClickInterval());
     _clickTimer.setSingleShot(true);
     connect(&_clickTimer, SIGNAL(timeout()), SLOT(clickTimeout()));
@@ -1028,8 +1031,9 @@ QString ChatScene::selection() const
                 result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " ";
             if (_selectionMinCol <= ChatLineModel::SenderColumn) {
                 ChatItem *item = _lines[l]->item(ChatLineModel::SenderColumn);
-                if (item->chatLine()->msgType() == Message::Plain) {
-                    // Copying to plain-text, re-add the sender brackets
+                if (!_showSenderBrackets && item->chatLine()->msgType() == Message::Plain) {
+                    // Copying to plain-text.  Only re-add the sender brackets if they're normally
+                    // hidden.
                     result += QString("<%1> ").arg(item->data(MessageModel::DisplayRole)
                                                    .toString());
                 } else {
@@ -1313,8 +1317,15 @@ void ChatScene::clearWebPreview(ChatItem *parentItem)
 //  end of webkit only
 // ========================================
 
+// Local configuration caching
 void ChatScene::showWebPreviewChanged()
 {
     ChatViewSettings settings;
     _showWebPreview = settings.showWebPreview();
 }
+
+void ChatScene::showSenderBracketsChanged()
+{
+    ChatViewSettings settings;
+    _showSenderBrackets = settings.showSenderBrackets();
+}
index c1e3515..68ef20f 100644 (file)
@@ -180,6 +180,11 @@ private slots:
 #endif
     void showWebPreviewChanged();
 
+    /**
+     * Updates the local setting cache of whether or not to show sender brackets
+     */
+    void showSenderBracketsChanged();
+
     void rowsRemoved();
 
     void clickTimeout();
@@ -226,6 +231,8 @@ private:
 
     bool _showWebPreview;
 
+    bool _showSenderBrackets;  /// If true, show brackets around sender names
+
     static const int _webSearchSelectionTextMaxVisible = 24;
 
 #if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
index fe4e383..286de7c 100644 (file)
@@ -45,13 +45,38 @@ public:
     inline bool showWebPreview() { return localValue("ShowWebPreview", true).toBool(); }
     inline void enableWebPreview(bool enabled) { setLocalValue("ShowWebPreview", enabled); }
 
+    /**
+     * Gets the format string for chat log timestamps
+     *
+     * @returns String representing timestamp format, e.g. "[hh:mm:ss]" or " hh:mm:ss"
+     */
     inline QString timestampFormatString() { return localValue("TimestampFormat", " hh:mm:ss").toString(); }
+    // Include a space in the default TimestampFormat to give the timestamp a small bit of padding
+    // between the border of the chat buffer window and the numbers.  Helps with readability.
+    /**
+     * Sets the format string for chat log timestamps
+     *
+     * @param[in] format String representing timestamp format, e.g. "[hh:mm:ss]" or " hh:mm:ss"
+     */
     inline void setTimestampFormatString(const QString &format) { setLocalValue("TimestampFormat", format); }
 
+    /**
+     * Gets if brackets are shown around sender names
+     *
+     * @returns True if sender brackets enabled, otherwise false
+     */
+    inline bool showSenderBrackets() { return localValue("ShowSenderBrackets", true).toBool(); }
+    /**
+     * Sets whether brackets are shown around around sender names.
+     *
+     * @param[in] enabled True if enabling sender brackets, otherwise false
+     */
+    inline void enableSenderBrackets(bool enabled) { setLocalValue("ShowSenderBrackets", enabled); }
+
     inline QString webSearchUrlFormatString() { return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString(); }
     inline void setWebSearchUrlFormatString(const QString &format) { setLocalValue("WebSearchUrlFormat", format); }
 };
 
 
-Q_DECLARE_METATYPE(ChatViewSettings::OperationMode);
+Q_DECLARE_METATYPE(ChatViewSettings::OperationMode)
 #endif //CHATVIEWSETTINGS_H
index a87af71..f596ab4 100644 (file)
@@ -29,6 +29,8 @@ QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent)
     ChatViewSettings s;
     s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString()));
     updateTimestampFormatString();
+    s.notify("ShowSenderBrackets", this, SLOT(updateShowSenderBrackets()));
+    updateShowSenderBrackets();
 }
 
 
@@ -40,6 +42,12 @@ void QtUiStyle::updateTimestampFormatString()
     setTimestampFormatString(s.timestampFormatString());
 }
 
+void QtUiStyle::updateShowSenderBrackets()
+{
+    ChatViewSettings s;
+    enableSenderBrackets(s.showSenderBrackets());
+}
+
 
 void QtUiStyle::generateSettingsQss() const
 {
index 629d4ff..03dac9a 100644 (file)
@@ -40,6 +40,10 @@ public slots:
 
 private slots:
     void updateTimestampFormatString();
+    /**
+     * Updates knowledge of whether or not to show sender brackets
+     */
+    void updateShowSenderBrackets();
 
 private:
     QString fontDescription(const QFont &font) const;
index 208e7a5..75ccc81 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>486</width>
-    <height>492</height>
+    <height>582</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -39,7 +39,7 @@
         <string/>
        </property>
        <property name="defaultValue" stdset="0">
-        <string>[hh:mm:ss]</string>
+        <string> hh:mm:ss</string>
        </property>
        <property name="settingsKey" stdset="0">
         <string notr="true">TimestampFormat</string>
      </item>
     </layout>
    </item>
+   <item>
+    <widget class="QCheckBox" name="showSenderBrackets">
+     <property name="toolTip">
+      <string>Shows &lt;brackets&gt; around the names of senders</string>
+     </property>
+     <property name="text">
+      <string>Show brackets around sender names</string>
+     </property>
+     <property name="checked">
+      <bool>false</bool>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>false</bool>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string notr="true">ShowSenderBrackets</string>
+     </property>
+    </widget>
+   </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_3">
      <item>
  </customwidgets>
  <tabstops>
   <tabstop>timestampFormat</tabstop>
+  <tabstop>showSenderBrackets</tabstop>
   <tabstop>customChatViewFont</tabstop>
   <tabstop>allowMircColors</tabstop>
   <tabstop>showWebPreview</tabstop>
index bee1f4b..cba2eda 100644 (file)
@@ -29,7 +29,8 @@
 #include "util.h"
 
 QHash<QString, UiStyle::FormatType> UiStyle::_formatCodes;
-QString UiStyle::_timestampFormatString;
+QString UiStyle::_timestampFormatString; /// Timestamp format
+bool UiStyle::_showSenderBrackets;       /// If true, show brackets around sender names
 
 UiStyle::UiStyle(QObject *parent)
     : QObject(parent),
@@ -66,7 +67,11 @@ UiStyle::UiStyle(QObject *parent)
     _formatCodes["%DM"] = ModeFlags;
     _formatCodes["%DU"] = Url;
 
-    setTimestampFormatString("[hh:mm:ss]");
+    // Initialize fallback defaults
+    // NOTE: If you change this, update qtui/chatviewsettings.h, too.  More explanations available
+    // in there.
+    setTimestampFormatString(" hh:mm:ss");
+    enableSenderBrackets(true);
 
     // BufferView / NickView settings
     UiStyleSettings s;
@@ -163,12 +168,18 @@ QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist)
     return ss;
 }
 
-
+// FIXME The following should trigger a reload/refresh of the chat view.
 void UiStyle::setTimestampFormatString(const QString &format)
 {
     if (_timestampFormatString != format) {
         _timestampFormatString = format;
-        // FIXME reload
+    }
+}
+
+void UiStyle::enableSenderBrackets(bool enabled)
+{
+    if (_showSenderBrackets != enabled) {
+        _showSenderBrackets = enabled;
     }
 }
 
@@ -813,7 +824,11 @@ QString UiStyle::StyledMessage::decoratedSender() const
 {
     switch (type()) {
     case Message::Plain:
-        return QString("%1").arg(plainSender()); break;
+        if (_showSenderBrackets)
+            return QString("<%1>").arg(plainSender());
+        else
+            return QString("%1").arg(plainSender());
+        break;
     case Message::Notice:
         return QString("[%1]").arg(plainSender()); break;
     case Message::Action:
index a4ea543..c4dda11 100644 (file)
@@ -169,6 +169,12 @@ protected:
     static FormatType formatType(const QString &code);
     static QString formatCode(FormatType);
     static void setTimestampFormatString(const QString &format);
+    /**
+     * Updates the local setting cache of whether or not to show sender brackets
+     *
+     * @param[in] enabled  If true, sender brackets are enabled, otherwise false.
+     */
+    static void enableSenderBrackets(bool enabled);
 
     QVariant itemData(int role, const QTextCharFormat &format) const;
 
@@ -185,6 +191,7 @@ private:
     QHash<quint32, QTextCharFormat> _listItemFormats;
     static QHash<QString, FormatType> _formatCodes;
     static QString _timestampFormatString;
+    static bool _showSenderBrackets;  /// If true, show brackets around sender names
 
     QIcon _channelJoinedIcon;
     QIcon _channelPartedIcon;