X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreuserinputhandler.cpp;h=d060ada286b4bbb160ef98196e6160aedbdba866;hp=ebbaf911550e3609dba54a7470dfd579ad41d0a6;hb=c194ed5fb3d15e14b9364f9796d3521910dc72fe;hpb=97a9b1646bb0d6362cef14bac3a577481cc01e49 diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index ebbaf911..d060ada2 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -30,13 +30,6 @@ # include "cipher.h" #endif -#if QT_VERSION < 0x050000 -// QChar::LineFeed is Qt 5 -static const QChar QCharLF = QChar('\n'); -#else -static const QChar QCharLF = QChar::LineFeed; -#endif - CoreUserInputHandler::CoreUserInputHandler(CoreNetwork *parent) : CoreBasicHandler(parent) { @@ -61,35 +54,44 @@ 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()) { Identity *identity = network()->identityPtr(); if (identity) { - awayMsg = identity->awayReason(); + awayMsg = formatCurrentDateTimeInString(identity->awayReason()); } if (awayMsg.isEmpty()) { awayMsg = tr("away"); @@ -181,7 +183,8 @@ void CoreUserInputHandler::handleCtcp(const BufferInfo &bufferInfo, const QStrin // FIXME make this a proper event coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), nick, ctcpTag, message); - emit displayMsg(Message::Action, BufferInfo::StatusBuffer, "", verboseMessage, network()->myNick()); + emit displayMsg(Message::Action, BufferInfo::StatusBuffer, "", verboseMessage, + network()->myNick(), Message::Flag::Self); } @@ -447,11 +450,10 @@ void CoreUserInputHandler::handleMe(const BufferInfo &bufferInfo, const QString // Split apart messages at line feeds. The IRC protocol uses those to separate commands, so // they need to be split into multiple messages. - QStringList messages = msg.split(QCharLF); + QStringList messages = msg.split(QChar::LineFeed); foreach (auto message, messages) { - // Handle each separated message independently, ignoring any carriage returns - message = message.trimmed(); + // Handle each separated message independently coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), bufferInfo.bufferName(), "ACTION", message); emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), message, @@ -465,17 +467,21 @@ void CoreUserInputHandler::handleMode(const BufferInfo &bufferInfo, const QStrin Q_UNUSED(bufferInfo) QStringList params = msg.split(' ', QString::SkipEmptyParts); - // if the first argument is neither a channel nor us (user modes are only to oneself) the current buffer is assumed to be the target if (!params.isEmpty()) { - if (!network()->isChannelName(params[0]) && !network()->isMyNick(params[0])) - params.prepend(bufferInfo.bufferName()); - if (network()->isMyNick(params[0]) && params.count() == 2) - network()->updateIssuedModes(params[1]); if (params[0] == "-reset" && params.count() == 1) { - // FIXME: give feedback to the user (I don't want to add new strings right now) network()->resetPersistentModes(); + emit displayMsg(Message::Info, BufferInfo::StatusBuffer, "", + tr("Your persistent modes have been reset.")); return; } + if (!network()->isChannelName(params[0]) && !network()->isMyNick(params[0])) + // If the first argument is neither a channel nor us (user modes are only to oneself) + // the current buffer is assumed to be the target. + // If the current buffer returns no name (e.g. status buffer), assume target is us. + params.prepend(!bufferInfo.bufferName().isEmpty() ? + bufferInfo.bufferName() : network()->myNick()); + if (network()->isMyNick(params[0]) && params.count() == 2) + network()->updateIssuedModes(params[1]); } // TODO handle correct encoding for buffer modes (channelEncode()) @@ -519,11 +525,10 @@ void CoreUserInputHandler::handleNotice(const BufferInfo &bufferInfo, const QStr QList params; // Split apart messages at line feeds. The IRC protocol uses those to separate commands, so // they need to be split into multiple messages. - QStringList messages = msg.section(' ', 1).split(QCharLF); + QStringList messages = msg.section(' ', 1).split(QChar::LineFeed); foreach (auto message, messages) { - // Handle each separated message independently, ignoring any carriage returns - message = message.trimmed(); + // Handle each separated message independently params.clear(); params << serverEncode(bufferName) << channelEncode(bufferInfo.bufferName(), message); emit putCmd("NOTICE", params); @@ -594,11 +599,10 @@ void CoreUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QStri QString target = msg.section(' ', 0, 0); // Split apart messages at line feeds. The IRC protocol uses those to separate commands, so // they need to be split into multiple messages. - QStringList messages = msg.section(' ', 1).split(QCharLF); + QStringList messages = msg.section(' ', 1).split(QChar::LineFeed); foreach (auto message, messages) { - // Handle each separated message independently, ignoring any carriage returns - message = message.trimmed(); + // Handle each separated message independently if (message.isEmpty()) { emit displayMsg(Message::Server, BufferInfo::QueryBuffer, target, tr("Starting query with %1").arg(target), network()->myNick(), @@ -646,11 +650,10 @@ void CoreUserInputHandler::handleSay(const BufferInfo &bufferInfo, const QString // Split apart messages at line feeds. The IRC protocol uses those to separate commands, so // they need to be split into multiple messages. - QStringList messages = msg.split(QCharLF); + QStringList messages = msg.split(QChar::LineFeed, QString::SkipEmptyParts); foreach (auto message, messages) { - // Handle each separated message independently, ignoring any carriage returns - message = message.trimmed(); + // Handle each separated message independently #ifdef HAVE_QCA2 putPrivmsg(bufferInfo.bufferName(), message, encodeFunc, network()->cipher(bufferInfo.bufferName()));