Use join-and-switch with /join and /query
[quassel.git] / src / client / clientuserinputhandler.cpp
index a02bc18..3ecf3c4 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <QDateTime>
 
+#include "buffermodel.h"
 #include "client.h"
 #include "clientaliasmanager.h"
 #include "clientuserinputhandler.h"
@@ -59,23 +60,25 @@ 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();
+    QString args = clist.at(i).second.section(' ', 1);
     if(cmd == "EXEC")
-      handleExec(clist.at(i).first, clist.at(i).second.section(' ', 1));
-    else
+      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);
+    }
   }
 }
 
 void ClientUserInputHandler::handleExec(const BufferInfo &bufferInfo, const QString &execString) {
-  QString script;
-  QStringList params;
-  if(execString.contains(' ')) {
-    script = execString.section(' ', 0, 0);
-    params = execString.section(' ', 1).trimmed().split(' '); // FIXME handle args properly, including quoted strings etc
-  } else
-    script = execString;
-
-  ExecWrapper *exec = new ExecWrapper(this);
-  exec->start(bufferInfo, script, params);
-
+  ExecWrapper *exec = new ExecWrapper(this); // gets suicidal when it's done
+  exec->start(bufferInfo, execString);
 }