Optionally include timestamp when entering away
authorMarcin Jabrzyk <marcin.jabrzyk@gmail.com>
Sun, 16 Mar 2014 22:10:01 +0000 (23:10 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 13 Apr 2017 19:56:06 +0000 (21:56 +0200)
- In utils added function to find regexp format
- Added formatting the away message in core
- Tooltip update in client about possible away message format

src/common/util.cpp
src/common/util.h
src/core/coresession.cpp
src/core/coreuserinputhandler.cpp
src/qtui/settingspages/identityeditwidget.ui

index 3953ea0..b8adb36 100644 (file)
@@ -200,3 +200,18 @@ QByteArray prettyDigest(const QByteArray &digest)
     }
     return prettyDigest;
 }
+
+QString formatCurrentDateTimeInString(QString str)
+{
+    /*
+     * Find %%<text>%% in string. Repleace inside text which is format to QDateTime
+     * with current timestamp.
+     */
+    QRegExp rx("\\%%(.*)\\%%");
+    rx.setMinimal(true);
+    int s = rx.indexIn(str);
+    if (s >= 0)
+        str.replace(s, rx.cap(0).length(), QDateTime::currentDateTime().toString(rx.cap(1)));
+
+    return str;
+}
index 97559d9..7719146 100644 (file)
@@ -25,6 +25,7 @@
 #include <QVariant>
 #include <QString>
 #include <QMetaMethod>
+#include <QDateTime>
 
 // TODO Use versions from Network instead
 QString nickFromMask(QString mask);
@@ -75,4 +76,6 @@ QList<T> fromVariantList(const QVariantList &variants)
 
 QByteArray prettyDigest(const QByteArray &digest);
 
+QString formatCurrentDateTimeInString(QString str);
+
 #endif
index 5c377c8..43b2234 100644 (file)
@@ -662,7 +662,7 @@ void CoreSession::clientsDisconnected()
 
         if (identity->detachAwayEnabled() && !me->isAway()) {
             if (!identity->detachAwayReason().isEmpty())
-                awayReason = identity->detachAwayReason();
+                awayReason = formatCurrentDateTimeInString(identity->detachAwayReason());
             net->setAutoAwayActive(true);
             net->userInputHandler()->handleAway(BufferInfo(), awayReason);
         }
index 2eede06..b616a5d 100644 (file)
@@ -89,7 +89,7 @@ void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck)
         if (me && !me->isAway()) {
             Identity *identity = network()->identityPtr();
             if (identity) {
-                awayMsg = identity->awayReason();
+                awayMsg = formatCurrentDateTimeInString(identity->awayReason());
             }
             if (awayMsg.isEmpty()) {
                 awayMsg = tr("away");
index cedcdf0..942f99d 100644 (file)
                <bool>true</bool>
               </property>
               <property name="toolTip">
-               <string>Default away reason</string>
+               <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>
               </property>
              </widget>
             </item>
        <item>
         <widget class="QGroupBox" name="detachAwayEnabled">
          <property name="toolTip">
-          <string>Set away when all clients have detached from the core</string>
+          <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>
          </property>
          <property name="title">
           <string>Away On Detach</string>