/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel Project *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include "util.h"
#include "ctcphandler.h"
-#include "identity.h"
+#include "coreidentity.h"
#include "ircuser.h"
#include <QDebug>
}
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));
}
// ====================
return;
}
- if(generalizedHost.lastIndexOf(".") != -1 && generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1) != -1) {
+ static QRegExp ipAddress("\\d+\\.\\d+\\.\\d+\\.\\d+");
+ if(ipAddress.exactMatch(generalizedHost)) {
+ int lastDotPos = generalizedHost.lastIndexOf('.') + 1;
+ generalizedHost.replace(lastDotPos, generalizedHost.length() - lastDotPos, '*');
+ } else if(generalizedHost.lastIndexOf(".") != -1 && generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1) != -1) {
int secondLastPeriodPosition = generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1);
generalizedHost.replace(0, secondLastPeriodPosition, "*");
}
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(' ')));
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];
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::timerEvent(QTimerEvent *event) {
+ if(!_delayedCommands.contains(event->timerId())) {
+ QObject::timerEvent(event);
+ return;
+ }
+ BufferInfo bufferInfo = _delayedCommands[event->timerId()].bufferInfo;
+ QString rawCommand = _delayedCommands[event->timerId()].command;
+ _delayedCommands.remove(event->timerId());
+ event->accept();
+
+ // the stored command might be the result of an alias expansion, so we need to split it up again
+ QStringList commands = rawCommand.split(QRegExp("; ?"));
+ foreach(QString command, commands) {
+ handleUserInput(bufferInfo, command);
+ }
+}