X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fuserinputhandler.cpp;h=1cac5aad02a182d81a6e91454cbb85b2fcc09529;hb=ab16c77fe03b73a863d9b52b11919bcbac903f58;hp=722c3fc41bc3a62793670c0eccf76d3b977fc1ee;hpb=befb959043f1acc297609fac40df728b98ed7e28;p=quassel.git diff --git a/src/core/userinputhandler.cpp b/src/core/userinputhandler.cpp index 722c3fc4..1cac5aad 100644 --- a/src/core/userinputhandler.cpp +++ b/src/core/userinputhandler.cpp @@ -33,23 +33,17 @@ UserInputHandler::UserInputHandler(CoreNetwork *parent) { } -void UserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg_) { - if(msg_.isEmpty()) +void UserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &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); + + AliasManager::CommandList list = coreSession()->aliasManager().processInput(bufferInfo, msg); + + for(int i = 0; i < list.count(); i++) { + QString cmd = list.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper(); + QString payload = list.at(i).second.section(' ', 1); + handle(cmd, Q_ARG(BufferInfo, list.at(i).first), Q_ARG(QString, payload)); } - handle(cmd, Q_ARG(BufferInfo, bufferInfo), Q_ARG(QString, msg)); } // ==================== @@ -63,8 +57,12 @@ void UserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &m // if there is no message supplied we have to check if we are already away or not if(msg.isEmpty()) { - if(me && !me->isAway()) + if(me && !me->isAway()) { awayMsg = network()->identityPtr()->awayReason(); + if(awayMsg.isEmpty()) { + awayMsg = tr("away"); + } + } } if(me) me->setAwayMessage(awayMsg); @@ -321,12 +319,7 @@ void UserInputHandler::handleQuit(const BufferInfo &bufferInfo, const QString &m } void UserInputHandler::issueQuit(const QString &reason) { - QString quitReason; - if(reason.isEmpty()) - quitReason = network()->identityPtr()->quitReason(); - else - quitReason = reason; - emit putCmd("QUIT", serverEncode(quitReason)); + emit putCmd("QUIT", serverEncode(reason)); } void UserInputHandler::handleQuote(const BufferInfo &bufferInfo, const QString &msg) { @@ -393,65 +386,10 @@ void UserInputHandler::handleWhowas(const BufferInfo &bufferInfo, const QString } void UserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg) { - for(int i = 0; i < coreSession()->aliasManager().count(); i++) { - if(coreSession()->aliasManager()[i].name.toLower() == cmd.toLower()) { - expand(coreSession()->aliasManager()[i].expansion, bufferInfo, msg); - return; - } - } + Q_UNUSED(bufferInfo); emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: %1 %2").arg(cmd, msg)); } -void UserInputHandler::expand(const QString &alias, const BufferInfo &bufferInfo, const QString &msg) { - 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]; - - // replace ranges like $1..3 - if(!params.isEmpty()) { - int pos; - while((pos = paramRangeR.indexIn(command)) != -1) { - int start = paramRangeR.cap(1).toInt(); - bool ok; - int end = paramRangeR.cap(2).toInt(&ok); - if(!ok) { - end = params.count(); - } - if(end < start) - command = command.replace(pos, paramRangeR.matchedLength(), QString()); - else { - command = command.replace(pos, paramRangeR.matchedLength(), QStringList(params.mid(start - 1, end - start + 1)).join(" ")); - } - } - } - - for(int j = params.count(); j > 0; j--) { - IrcUser *ircUser = network()->ircUser(params[j - 1]); - command = command.replace(QString("$%1:hostname").arg(j), ircUser ? ircUser->host() : QString("*")); - command = command.replace(QString("$%1").arg(j), params[j - 1]); - } - 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); - } -} - - void UserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray &message) { static const char *cmd = "PRIVMSG"; int overrun = lastParamOverrun(cmd, QList() << message);