Show timestamp format tooltips when core supports
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 8 Jan 2017 19:30:38 +0000 (13:30 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 13 Apr 2017 19:56:08 +0000 (21:56 +0200)
Only change tooltip for away messages when supported by the core.
Restore original tooltip and concatenate together to reuse existing
translations (can be split apart if not a good idea).

Add new feature flag "AwayFormatTimestamp" to indicate when the core
supports parsing timestamp formats in away messages.

This isn't strictly required and if needed can be left out.  It just
might be confusing for the UI to say you can do something.. and it
doesn't work.

Resolves GH-270.

src/common/quassel.h
src/qtui/settingspages/identityeditwidget.cpp
src/qtui/settingspages/identityeditwidget.ui

index e9ed0f9..5097bad 100644 (file)
@@ -75,8 +75,9 @@ public:
         VerifyServerSSL = 0x0040,          /// IRC server SSL validation
         CustomRateLimits = 0x0080,         /// IRC server custom message rate limits
         DccFileTransfer = 0x0100,
+        AwayFormatTimestamp = 0x0200,      /// Timestamp formatting in away (e.g. %%hh:mm%%)
 
-        NumFeatures = 0x0100
+        NumFeatures = 0x0200
     };
     Q_DECLARE_FLAGS(Features, Feature)
 
index e165915..9085ae9 100644 (file)
@@ -85,6 +85,52 @@ IdentityEditWidget::IdentityEditWidget(QWidget *parent)
     ui.sslCertGroupBox->setAcceptDrops(true);
     ui.sslCertGroupBox->installEventFilter(this);
 #endif
+
+    if (Client::coreFeatures() & Quassel::AwayFormatTimestamp) {
+        // Core allows formatting %%timestamp%% messages in away strings.  Update tooltips.
+        QString strFormatTooltip;
+        QTextStream formatTooltip( &strFormatTooltip, QIODevice::WriteOnly );
+        formatTooltip << "<qt><style>.bold { font-weight: bold; } "
+                         ".italic { font-style: italic; }</style>";
+
+        // Function to add a row to the tooltip table
+        auto addRow = [&](const QString& key, const QString& value, bool condition) {
+            if (condition) {
+                formatTooltip << "<tr><td class='bold' align='right'>"
+                        << key << "</td><td>" << value << "</td></tr>";
+            }
+        };
+
+        // Original tooltip goes here
+        formatTooltip << "<p>%1</p>";
+        // New timestamp formatting guide here
+        formatTooltip << "<p>" << tr("You can add date/time to this message "
+                               "using the syntax: "
+                               "<br/>%%<span class='italic'>&lt;format&gt;</span>%%, where "
+                               "<span class='italic'>&lt;format&gt;</span> is:") << "</p>";
+        formatTooltip << "<table cellspacing='5' cellpadding='0'>";
+        addRow("hh", tr("the hour"), true);
+        addRow("mm", tr("the minutes"), true);
+        addRow("ss", tr("seconds"), true);
+        addRow("AP", tr("AM/PM"), true);
+        addRow("dd", tr("day"), true);
+        addRow("MM", tr("month"), true);
+#if QT_VERSION > 0x050000
+        // Alas, this was only added in Qt 5.  We don't know what version the core has, just hope
+        // for the best (Qt 4 will soon be dropped).
+        addRow("t", tr("current timezone"), true);
+#endif
+        formatTooltip << "</table>";
+        formatTooltip << "<p>" << tr("Example: Away since %%hh:mm%% on %%dd.MM%%.") << "</p>";
+        formatTooltip << "<p>" << tr("%%%% without anything inside represents %%.  Other format "
+                                     "codes are available.") << "</p>";
+        formatTooltip << "</qt>";
+
+        // Split up the message to allow re-using translations:
+        // [Original tool-tip]  [Timestamp format message]
+        ui.awayReason->setToolTip(strFormatTooltip.arg(ui.awayReason->toolTip()));
+        ui.detachAwayEnabled->setToolTip(strFormatTooltip.arg(ui.detachAwayEnabled->toolTip()));
+    } // else: Do nothing, leave the original translated string
 }
 
 
index 942f99d..cedcdf0 100644 (file)
                <bool>true</bool>
               </property>
               <property name="toolTip">
-               <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default away reason. You can add date/time to this message using syntax: %% &amp;lt;format&amp;gt; %%. Where &amp;lt;format&amp;gt; is: &lt;br/&gt;hh - the hour&lt;br/&gt;mm - the minutes&lt;br/&gt;ss - second&lt;br/&gt;AP - AM/PM&lt;&lt;br/&gt;dd - day&lt;br/&gt;MM - month&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+               <string>Default away reason</string>
               </property>
              </widget>
             </item>
        <item>
         <widget class="QGroupBox" name="detachAwayEnabled">
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set away when all clients have detached from the core. You can add date/time to this message using syntax: %% &amp;lt;format&amp;gt; %%. Where &amp;lt;format&amp;gt; is:&lt;br/&gt;hh - the hour&lt;br/&gt;mm - the minutes&lt;br/&gt;ss - second&lt;br/&gt;AP - AM/PM&lt;br/&gt;dd - day&lt;br/&gt;MM - month&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>Set away when all clients have detached from the core</string>
          </property>
          <property name="title">
           <string>Away On Detach</string>