X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fuserinputhandler.cpp;h=4b4c079659112e4cfd33719181e4399084f147af;hp=8e6896fedb83d471eaaba5fb77d873b8509bc784;hb=0d2e5ff7439fe7bf9f24f1f55763881382ecb12a;hpb=a5dfcc8ecf8b81025d24b3c5c816169e3e030ea4 diff --git a/src/core/userinputhandler.cpp b/src/core/userinputhandler.cpp index 8e6896fe..4b4c0796 100644 --- a/src/core/userinputhandler.cpp +++ b/src/core/userinputhandler.cpp @@ -22,7 +22,7 @@ #include "util.h" #include "ctcphandler.h" -#include "identity.h" +#include "coreidentity.h" #include "ircuser.h" #include @@ -34,26 +34,22 @@ UserInputHandler::UserInputHandler(CoreNetwork *parent) } void UserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg_) { - try { - if(msg_.isEmpty()) - return; - QString cmd; - QString msg = msg_; - // leading slashes indicate there's a command to call unless there is another one in the first section (like a path /proc/cpuinfo) - int secondSlashPos = msg.indexOf('/', 1); - int firstSpacePos = msg.indexOf(' '); - if(!msg.startsWith('/') || (secondSlashPos != -1 && (secondSlashPos < firstSpacePos || firstSpacePos == -1))) { - if(msg.startsWith("//")) - msg.remove(0, 1); // //asdf is transformed to /asdf - cmd = QString("SAY"); - } else { - cmd = msg.section(' ', 0, 0).remove(0, 1).toUpper(); - msg = msg.section(' ', 1); - } - handle(cmd, Q_ARG(BufferInfo, bufferInfo), Q_ARG(QString, msg)); - } catch(Exception e) { - emit displayMsg(Message::Error, bufferInfo.type(), "", e.msg()); + if(msg_.isEmpty()) + return; + QString cmd; + QString msg = msg_; + // leading slashes indicate there's a command to call unless there is another one in the first section (like a path /proc/cpuinfo) + int secondSlashPos = msg.indexOf('/', 1); + int firstSpacePos = msg.indexOf(' '); + if(!msg.startsWith('/') || (secondSlashPos != -1 && (secondSlashPos < firstSpacePos || firstSpacePos == -1))) { + if(msg.startsWith("//")) + msg.remove(0, 1); // //asdf is transformed to /asdf + cmd = QString("SAY"); + } else { + cmd = msg.section(' ', 0, 0).remove(0, 1).toUpper(); + msg = msg.section(' ', 1); } + handle(cmd, Q_ARG(BufferInfo, bufferInfo), Q_ARG(QString, msg)); } // ==================== @@ -358,6 +354,25 @@ void UserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString & emit putCmd("MODE", serverEncode(params)); } +void UserInputHandler::handleWait(const BufferInfo &bufferInfo, const QString &msg) { + int splitPos = msg.indexOf(';'); + if(splitPos <= 0) + return; + + bool ok; + int delay = msg.left(splitPos).trimmed().toInt(&ok); + if(!ok) + return; + + delay *= 1000; + + QString command = msg.mid(splitPos + 1).trimmed(); + if(command.isEmpty()) + return; + + _delayedCommands[startTimer(delay)] = Command(bufferInfo, command); +} + void UserInputHandler::handleWho(const BufferInfo &bufferInfo, const QString &msg) { Q_UNUSED(bufferInfo) emit putCmd("WHO", serverEncode(msg.split(' '))); @@ -387,6 +402,7 @@ void UserInputHandler::expand(const QString &alias, const BufferInfo &bufferInfo QRegExp paramRangeR("\\$(\\d+)\\.\\.(\\d*)"); QStringList commands = alias.split(QRegExp("; ?")); QStringList params = msg.split(' '); + QStringList expandedCommands; for(int i = 0; i < commands.count(); i++) { QString command = commands[i]; @@ -416,6 +432,17 @@ void UserInputHandler::expand(const QString &alias, const BufferInfo &bufferInfo command = command.replace("$0", msg); command = command.replace("$channelname", bufferInfo.bufferName()); command = command.replace("$currentnick", network()->myNick()); + expandedCommands << command; + } + + while(!expandedCommands.isEmpty()) { + QString command; + if(expandedCommands[0].trimmed().toLower().startsWith("/wait")) { + command = expandedCommands.join("; "); + expandedCommands.clear(); + } else { + command = expandedCommands.takeFirst(); + } handleUserInput(bufferInfo, command); } } @@ -471,3 +498,13 @@ int UserInputHandler::lastParamOverrun(const QString &cmd, const QListtimerId())) { + QObject::timerEvent(event); + return; + } + Command command = _delayedCommands.take(event->timerId()); + event->accept(); + handleUserInput(command.bufferInfo, command.command); +}