- for(int i = 0; i < clist.count(); i++) {
- QString cmd = clist.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper();
- QString args = clist.at(i).second.section(' ', 1);
- if(cmd == "EXEC")
- handleExec(clist.at(i).first, args);
- else {
- if(cmd == "JOIN" || cmd == "QUERY") {
- BufferId newBufId = Client::networkModel()->bufferId(bufferInfo.networkId(), args.section(' ', 0, 0));
- if(!newBufId.isValid()) {
- Client::bufferModel()->switchToBufferAfterCreation(bufferInfo.networkId(), args.section(' ', 0, 0));
- }
- else {
- Client::bufferModel()->switchToBuffer(newBufId);
- }
- }
- emit sendInput(clist.at(i).first, clist.at(i).second);
+ for (int i = 0; i < clist.count(); i++) {
+ QString cmd = clist.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper();
+ 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::handleIgnore(const BufferInfo &bufferInfo, const QString &text)
+{
+ if (text.isEmpty()) {
+ emit Client::instance()->displayIgnoreList("");
+ return;