X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientuserinputhandler.cpp;h=dc21d28aec5b26b91ac9d31f12607bc5e67ce520;hp=6b4668242588ed66d2b622a204a61611c4eda9cb;hb=HEAD;hpb=39328183a6a87c6eb10a9dbbffcd5d65bf154a1f diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp index 6b466824..80794d7f 100644 --- a/src/client/clientuserinputhandler.cpp +++ b/src/client/clientuserinputhandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,8 @@ #include "clientuserinputhandler.h" +#include + #include "bufferinfo.h" #include "buffermodel.h" #include "client.h" @@ -35,36 +37,32 @@ #include "network.h" #include "types.h" -#include - -ClientUserInputHandler::ClientUserInputHandler(QObject *parent) +ClientUserInputHandler::ClientUserInputHandler(QObject* parent) : BasicHandler(parent) { TabCompletionSettings s; - s.notify("CompletionSuffix", this, SLOT(completionSuffixChanged(QVariant))); + s.notify("CompletionSuffix", this, &ClientUserInputHandler::completionSuffixChanged); completionSuffixChanged(s.completionSuffix()); } - -void ClientUserInputHandler::completionSuffixChanged(const QVariant &v) +void ClientUserInputHandler::completionSuffixChanged(const QVariant& v) { QString suffix = v.toString(); QString letter = "A-Za-z"; - QString special = "\x5b-\x60\x7b-\x7d"; + QString special = "\x5b-\x60\x7b-\x7d"; // NOLINT(modernize-raw-string-literal) _nickRx = QRegExp(QString("^([%1%2][%1%2\\d-]*)%3").arg(letter, special, suffix).trimmed()); } - // this would be the place for a client-side hook -void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg) +void ClientUserInputHandler::handleUserInput(const BufferInfo& bufferInfo, const QString& msg) { if (msg.isEmpty()) return; if (!msg.startsWith('/')) { if (_nickRx.indexIn(msg) == 0) { - const Network *net = Client::network(bufferInfo.networkId()); - IrcUser *user = net ? net->ircUser(_nickRx.cap(1)) : nullptr; + const Network* net = Client::network(bufferInfo.networkId()); + IrcUser* user = net ? net->ircUser(_nickRx.cap(1)) : nullptr; if (user) user->setLastSpokenTo(bufferInfo.bufferId(), QDateTime::currentDateTime().toUTC()); } @@ -79,34 +77,35 @@ void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const } } - -void ClientUserInputHandler::defaultHandler(const QString &cmd, const BufferInfo &bufferInfo, const QString &text) +void ClientUserInputHandler::defaultHandler(const QString& cmd, const BufferInfo& bufferInfo, const QString& text) { QString command = QString("/%1 %2").arg(cmd, text); emit sendInput(bufferInfo, command); } - -void ClientUserInputHandler::handleExec(const BufferInfo &bufferInfo, const QString &execString) +void ClientUserInputHandler::handleExec(const BufferInfo& bufferInfo, const QString& execString) { - ExecWrapper *exec = new ExecWrapper(this); // gets suicidal when it's done + auto* exec = new ExecWrapper(this); // gets suicidal when it's done exec->start(bufferInfo, execString); } - -void ClientUserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &text) +void ClientUserInputHandler::handleJoin(const BufferInfo& bufferInfo, const QString& text) { - if (text.isEmpty()) { - Client::messageModel()->insertErrorMessage(bufferInfo, tr("/JOIN expects a channel")); - return; + auto channelName = text; + if (channelName.isEmpty()) { + if (bufferInfo.type() == BufferInfo::ChannelBuffer) { + channelName = bufferInfo.bufferName(); + } else { + Client::messageModel()->insertErrorMessage(bufferInfo, tr("/JOIN expects a channel")); + return; + } } - switchBuffer(bufferInfo.networkId(), text.section(' ', 0, 0)); + switchBuffer(bufferInfo.networkId(), channelName.section(' ', 0, 0)); // send to core - defaultHandler("JOIN", bufferInfo, text); + defaultHandler("JOIN", bufferInfo, channelName); } - -void ClientUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QString &text) +void ClientUserInputHandler::handleQuery(const BufferInfo& bufferInfo, const QString& text) { if (text.isEmpty()) { Client::messageModel()->insertErrorMessage(bufferInfo, tr("/QUERY expects at least a nick")); @@ -117,8 +116,7 @@ void ClientUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QSt defaultHandler("QUERY", bufferInfo, text); } - -void ClientUserInputHandler::handleIgnore(const BufferInfo &bufferInfo, const QString &text) +void ClientUserInputHandler::handleIgnore(const BufferInfo& bufferInfo, const QString& text) { if (text.isEmpty()) { emit Client::instance()->displayIgnoreList(""); @@ -127,27 +125,24 @@ void ClientUserInputHandler::handleIgnore(const BufferInfo &bufferInfo, const QS // If rule contains no ! or @, we assume it is just a nickname, and turn it into an ignore rule for that nick QString rule = (text.contains('!') || text.contains('@')) ? text : text + "!*@*"; - Client::ignoreListManager()->requestAddIgnoreListItem( - IgnoreListManager::IgnoreType::SenderIgnore, - rule, - false, - // Use a dynamic ignore rule, for reversibility - IgnoreListManager::StrictnessType::SoftStrictness, - // Use current network as scope - IgnoreListManager::ScopeType::NetworkScope, - Client::network(bufferInfo.networkId())->networkName(), - true - ); + Client::ignoreListManager()->requestAddIgnoreListItem(IgnoreListManager::IgnoreType::SenderIgnore, + rule, + false, + // Use a dynamic ignore rule, for reversibility + IgnoreListManager::StrictnessType::SoftStrictness, + // Use current network as scope + IgnoreListManager::ScopeType::NetworkScope, + Client::network(bufferInfo.networkId())->networkName(), + true); } -void ClientUserInputHandler::handleList(const BufferInfo &bufferInfo, const QString &text) +void ClientUserInputHandler::handleList(const BufferInfo& bufferInfo, const QString& text) { // Pass along any potential search parameters, list channels immediately Client::instance()->displayChannelList(bufferInfo.networkId(), text, true); } - -void ClientUserInputHandler::switchBuffer(const NetworkId &networkId, const QString &bufferName) +void ClientUserInputHandler::switchBuffer(const NetworkId& networkId, const QString& bufferName) { BufferId newBufId = Client::networkModel()->bufferId(networkId, bufferName); if (!newBufId.isValid()) { @@ -156,15 +151,15 @@ void ClientUserInputHandler::switchBuffer(const NetworkId &networkId, const QStr else { Client::bufferModel()->switchToBuffer(newBufId); // unhide the buffer - ClientBufferViewManager *clientBufferViewManager = Client::bufferViewManager(); - QList bufferViewConfigList = clientBufferViewManager->clientBufferViewConfigs(); - foreach(ClientBufferViewConfig *bufferViewConfig, bufferViewConfigList) { + ClientBufferViewManager* clientBufferViewManager = Client::bufferViewManager(); + QList bufferViewConfigList = clientBufferViewManager->clientBufferViewConfigs(); + foreach (ClientBufferViewConfig* bufferViewConfig, bufferViewConfigList) { if (bufferViewConfig->temporarilyRemovedBuffers().contains(newBufId)) { bufferViewConfig->requestAddBuffer(newBufId, bufferViewConfig->bufferList().length()); - //if (bufferViewConfig->sortAlphabetically()) { + // if (bufferViewConfig->sortAlphabetically()) { // TODO we need to trigger a sort here, but can't reach the model required // to get a bufferviewfilter, as the bufferviewmanager only managers configs - //BufferViewFilter *filter = qobject_cast(model()); + // BufferViewFilter *filter = qobject_cast(model()); //} } }