X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientuserinputhandler.cpp;h=3e7ece3c3226f435463c5b9bb0a94db055e1fd0d;hp=610a70210c7dff290d2bda57205c95fdb2401437;hb=46984aca05b2d5f8dddd0c8739e60a1753078123;hpb=127d1fd9e75d33f1a6a4cd4d30c259b00686c4ff diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp index 610a7021..3e7ece3c 100644 --- a/src/client/clientuserinputhandler.cpp +++ b/src/client/clientuserinputhandler.cpp @@ -18,18 +18,23 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include +#include "clientuserinputhandler.h" +#include "buffermodel.h" #include "client.h" #include "clientaliasmanager.h" -#include "clientuserinputhandler.h" #include "clientsettings.h" #include "execwrapper.h" #include "ircuser.h" #include "network.h" +#include "types.h" +#include "bufferinfo.h" +#include "messagemodel.h" + +#include ClientUserInputHandler::ClientUserInputHandler(QObject *parent) -: QObject(parent) +: BasicHandler(parent) { TabCompletionSettings s; s.notify("CompletionSuffix", this, SLOT(completionSuffixChanged(QVariant))); @@ -45,6 +50,8 @@ void ClientUserInputHandler::completionSuffixChanged(const QVariant &v) { // this would be the place for a client-side hook void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg) { + if(msg.isEmpty()) + return; if(!msg.startsWith('/')) { if(_nickRx.indexIn(msg) == 0) { @@ -59,14 +66,47 @@ void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const for(int i = 0; i < clist.count(); i++) { QString cmd = clist.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper(); - if(cmd == "EXEC") - handleExec(clist.at(i).first, clist.at(i).second.section(' ', 1)); - else - emit sendInput(clist.at(i).first, clist.at(i).second); + QString payload = clist.at(i).second.section(' ', 1); + handle(cmd, Q_ARG(BufferInfo, clist.at(i).first), Q_ARG(QString, payload)); } } +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) { ExecWrapper *exec = new ExecWrapper(this); // gets suicidal when it's done exec->start(bufferInfo, execString); } + +void ClientUserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &text) { + if(text.isEmpty()) { + Client::messageModel()->insertErrorMessage(bufferInfo, tr("/JOIN expects a channel")); + return; + } + switchBuffer(bufferInfo.networkId(), text.section(' ', 0, 0)); + // send to core + defaultHandler("JOIN", bufferInfo, text); +} + +void ClientUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QString &text) { + if(text.isEmpty()) { + Client::messageModel()->insertErrorMessage(bufferInfo, tr("/QUERY expects at least a nick")); + return; + } + switchBuffer(bufferInfo.networkId(), text.section(' ', 0, 0)); + // send to core + defaultHandler("QUERY", bufferInfo, text); +} + +void ClientUserInputHandler::switchBuffer(const NetworkId &networkId, const QString &bufferName) { + BufferId newBufId = Client::networkModel()->bufferId(networkId, bufferName); + if(!newBufId.isValid()) { + Client::bufferModel()->switchToBufferAfterCreation(networkId, bufferName); + } + else { + Client::bufferModel()->switchToBuffer(newBufId); + } +}