1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 extern BuiltinCmd builtins[];
26 recvHandlerType Message::defaultRecvHandler;
27 sendHandlerType Message::defaultSendHandler;
28 QHash<QString, CmdType> Message::cmdTypes;
30 Message::Message(QString _cmd, QStringList args) {
31 cmd = _cmd; qDebug() << "cmd: " << cmd;
35 void Message::init(recvHandlerType _r, sendHandlerType _s) {
36 defaultRecvHandler = _r;
37 defaultSendHandler = _s;
39 // Register builtin commands
40 for(int i = 0; ; i++) {
41 if(builtins[i].cmd.isEmpty()) break;
43 c.cmd = builtins[i].cmd.toLower();
44 c.cmdDescr = builtins[i].cmdDescr;
45 c.args = builtins[i].args;
46 c.argsDescr = builtins[i].argsDescr;
47 c.recvHandler = ( builtins[i].recvHandler ? builtins[i].recvHandler : defaultRecvHandler);
48 c.sendHandler = ( builtins[i].sendHandler ? builtins[i].sendHandler : defaultSendHandler);
49 cmdTypes.insert(c.cmd, c);
54 recvHandlerType Message::getRecvHandler() {
55 CmdType c = cmdTypes[cmd];
56 if(c.recvHandler) return c.recvHandler;
57 qDebug() << "No recvHandler defined for " << cmd << "!";
61 sendHandlerType Message::getSendHandler() {
62 CmdType c = cmdTypes[cmd];
63 if(c.sendHandler) return c.sendHandler;
64 qDebug() << "No sendHandler defined for " << cmd << "!";
69 void Message::parseParams(QString str) {
70 QString left = str.section(':', 0, 0);
71 QString trailing = str.section(':', 1);
73 params << left.split(' ', QString::SkipEmptyParts);