From dcd6c362d77ab4cb5ea73b7e54ce944a68aa3f06 Mon Sep 17 00:00:00 2001 From: Marcin Jabrzyk Date: Sun, 16 Mar 2014 23:10:01 +0100 Subject: [PATCH] Optionally include timestamp when entering away - 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 | 15 +++++++++++++++ src/common/util.h | 3 +++ src/core/coresession.cpp | 2 +- src/core/coreuserinputhandler.cpp | 2 +- src/qtui/settingspages/identityeditwidget.ui | 4 ++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/common/util.cpp b/src/common/util.cpp index 3953ea0f..b8adb361 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -200,3 +200,18 @@ QByteArray prettyDigest(const QByteArray &digest) } return prettyDigest; } + +QString formatCurrentDateTimeInString(QString str) +{ + /* + * Find %%%% 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; +} diff --git a/src/common/util.h b/src/common/util.h index 97559d99..77191467 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -25,6 +25,7 @@ #include #include #include +#include // TODO Use versions from Network instead QString nickFromMask(QString mask); @@ -75,4 +76,6 @@ QList fromVariantList(const QVariantList &variants) QByteArray prettyDigest(const QByteArray &digest); +QString formatCurrentDateTimeInString(QString str); + #endif diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 5c377c85..43b2234d 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -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); } diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index 2eede06a..b616a5d6 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -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"); diff --git a/src/qtui/settingspages/identityeditwidget.ui b/src/qtui/settingspages/identityeditwidget.ui index cedcdf06..942f99d1 100644 --- a/src/qtui/settingspages/identityeditwidget.ui +++ b/src/qtui/settingspages/identityeditwidget.ui @@ -251,7 +251,7 @@ true - Default away reason + <html><head/><body><p>Default away reason. You can add date/time to this message using syntax: %% &lt;format&gt; %%. Where &lt;format&gt; is: <br/>hh - the hour<br/>mm - the minutes<br/>ss - second<br/>AP - AM/PM<<br/>dd - day<br/>MM - month</p></body></html> @@ -277,7 +277,7 @@ - Set away when all clients have detached from the core + <html><head/><body><p>Set away when all clients have detached from the core. You can add date/time to this message using syntax: %% &lt;format&gt; %%. Where &lt;format&gt; is:<br/>hh - the hour<br/>mm - the minutes<br/>ss - second<br/>AP - AM/PM<br/>dd - day<br/>MM - month</p></body></html> Away On Detach -- 2.20.1