From: Shane Synan Date: Sun, 8 Jan 2017 22:52:38 +0000 (-0600) Subject: Use timestamp format for manual away, not restore X-Git-Tag: travis-deploy-test~310 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=96d275205b16280f8b938ab7f54d62c51fad358c Use timestamp format for manual away, not restore Apply the timestamp formatting to manual /away commands, too. This offers consistency between the auto-away settings and manual away. Add skipFormatting flag to handleAway/issueAway commands to skip applying timestamp formatting. This avoids re-processing timestamp formatting when restarting the core, leaving any '%%' as '%%'. The message should already be processed once stored. More comments! --- diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index fdfc869c..4d1fc015 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -656,8 +656,11 @@ void CoreNetwork::networkInitialized() // restore away state QString awayMsg = Core::awayMessage(userId(), networkId()); - if (!awayMsg.isEmpty()) - userInputHandler()->handleAway(BufferInfo(), Core::awayMessage(userId(), networkId())); + if (!awayMsg.isEmpty()) { + // Don't re-apply any timestamp formatting in order to preserve escaped percent signs, e.g. + // '%%%%%%%%' -> '%%%%' If processed again, it'd result in '%%'. + userInputHandler()->handleAway(BufferInfo(), awayMsg, true); + } sendPerform(); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 43b2234d..39bd69b7 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -670,7 +670,7 @@ void CoreSession::clientsDisconnected() } -void CoreSession::globalAway(const QString &msg) +void CoreSession::globalAway(const QString &msg, const bool skipFormatting) { QHash::iterator netIter = _networks.begin(); CoreNetwork *net = 0; @@ -681,7 +681,7 @@ void CoreSession::globalAway(const QString &msg) if (!net->isConnected()) continue; - net->userInputHandler()->issueAway(msg, false /* no force away */); + net->userInputHandler()->issueAway(msg, false /* no force away */, skipFormatting); } } diff --git a/src/core/coresession.h b/src/core/coresession.h index 950dfb25..849575fe 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -133,8 +133,13 @@ public slots: QHash persistentChannels(NetworkId) const; - //! Marks us away (or unaway) on all networks - void globalAway(const QString &msg = QString()); + /** + * Marks us away (or unaway) on all networks + * + * @param[in] msg Away message, or blank to set unaway + * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done) + */ + void globalAway(const QString &msg = QString(), const bool skipFormatting = false); signals: void initialized(); diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index b616a5d6..755e64a9 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -61,29 +61,38 @@ void CoreUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const Q // ==================== // Public Slots // ==================== -void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg) +void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg, + const bool skipFormatting) { Q_UNUSED(bufferInfo) if (msg.startsWith("-all")) { if (msg.length() == 4) { - coreSession()->globalAway(); + coreSession()->globalAway(QString(), skipFormatting); return; } Q_ASSERT(msg.length() > 4); if (msg[4] == ' ') { - coreSession()->globalAway(msg.mid(5)); + coreSession()->globalAway(msg.mid(5), skipFormatting); return; } } - issueAway(msg); + issueAway(msg, true /* force away */, skipFormatting); } -void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck) +void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck, const bool skipFormatting) { QString awayMsg = msg; IrcUser *me = network()->me(); + // Only apply timestamp formatting when requested + // This avoids re-processing any existing away message when the core restarts, so chained escape + // percent signs won't get down-processed. + if (!skipFormatting) { + // Apply the timestamp formatting to the away message (if empty, nothing will happen) + awayMsg = formatCurrentDateTimeInString(awayMsg); + } + // if there is no message supplied we have to check if we are already away or not if (autoCheck && msg.isEmpty()) { if (me && !me->isAway()) { diff --git a/src/core/coreuserinputhandler.h b/src/core/coreuserinputhandler.h index 821d185b..b13fd394 100644 --- a/src/core/coreuserinputhandler.h +++ b/src/core/coreuserinputhandler.h @@ -39,7 +39,17 @@ public: int lastParamOverrun(const QString &cmd, const QList ¶ms); public slots: - void handleAway(const BufferInfo &bufferInfo, const QString &text); + /** + * Handle the away command, marking as away or unaway + * + * Applies to the current network unless text begins with "-all". + * + * @param[in] bufferInfo Currently active buffer + * @param[in] text Away message, or blank to set unaway + * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done) + */ + void handleAway(const BufferInfo &bufferInfo, const QString &text, + const bool skipFormatting = true); void handleBan(const BufferInfo &bufferInfo, const QString &text); void handleUnban(const BufferInfo &bufferInfo, const QString &text); void handleCtcp(const BufferInfo &bufferInfo, const QString &text); @@ -86,7 +96,15 @@ public slots: * @param forceImmediate Immediately quit, skipping queue of other commands */ void issueQuit(const QString &reason, bool forceImmediate = false); - void issueAway(const QString &msg, bool autoCheck = true); + + /** + * Issues the away command, marking as away or unaway on the current network + * + * @param[in] msg Away message, or blank to set unaway + * @param[in] autoCheck If true, always set away, defaulting to the identity away message + * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done) + */ + void issueAway(const QString &msg, bool autoCheck = true, const bool skipFormatting = false); protected: void timerEvent(QTimerEvent *event);