1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
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) version 3. *
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 #include "clientuserinputhandler.h"
25 #include "clientsettings.h"
29 ClientUserInputHandler::ClientUserInputHandler(QObject *parent)
33 TabCompletionSettings s;
34 s.notify("CompletionSuffix", this, SLOT(completionSuffixChanged(QVariant)));
35 completionSuffixChanged(s.completionSuffix());
37 // we need this signal for future connects to reset the data;
38 connect(Client::instance(), SIGNAL(connected()), SLOT(clientConnected()));
39 connect(Client::instance(), SIGNAL(disconnected()), SLOT(clientDisconnected()));
40 if(Client::isConnected())
44 void ClientUserInputHandler::clientConnected() {
45 _aliasManager = ClientAliasManager();
46 Client::signalProxy()->synchronize(&_aliasManager);
47 connect(&_aliasManager, SIGNAL(initDone()), SLOT(initDone()));
50 void ClientUserInputHandler::clientDisconnected() {
51 // clear alias manager
52 _aliasManager = ClientAliasManager();
56 void ClientUserInputHandler::initDone() {
58 for(int i = 0; i < _inputBuffer.count(); i++)
59 handleUserInput(_inputBuffer.at(i).first, _inputBuffer.at(i).second);
63 void ClientUserInputHandler::completionSuffixChanged(const QVariant &v) {
64 QString suffix = v.toString();
65 QString letter = "A-Za-z";
66 QString special = "\x5b-\x60\x7b-\x7d";
67 _nickRx = QRegExp(QString("^([%1%2][%1%2\\d-]*)%3").arg(letter, special, suffix).trimmed());
70 // this would be the place for a client-side hook
71 void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg) {
72 if(!_initialized) { // aliases not yet synced
73 _inputBuffer.append(qMakePair(bufferInfo, msg));
77 if(!msg.startsWith('/')) {
78 if(_nickRx.indexIn(msg) == 0) {
79 const Network *net = Client::network(bufferInfo.networkId());
80 IrcUser *user = net ? net->ircUser(_nickRx.cap(1)) : 0;
82 user->setLastSpokenTo(bufferInfo.bufferId(), QDateTime::currentDateTime().toUTC());
86 AliasManager::CommandList clist = _aliasManager.processInput(bufferInfo, msg);
88 for(int i = 0; i < clist.count(); i++)
89 emit sendInput(clist.at(i).first, clist.at(i).second);