From 03a20917d9b3fe8c7651843b1d3d0ab2f50e90ef Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 25 Feb 2009 18:35:50 +0100 Subject: [PATCH] Introduce ClientUserInputHandler This provides a client-side hook for every input that goes through via input line or Client::userInput(). For now, this checks if we addressed an IrcUser and updates its lastSpokenTo timestamp. --- src/client/CMakeLists.txt | 2 + src/client/client.cpp | 8 ++-- src/client/client.h | 10 ++--- src/client/clientuserinputhandler.cpp | 56 +++++++++++++++++++++++++++ src/client/clientuserinputhandler.h | 45 +++++++++++++++++++++ 5 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 src/client/clientuserinputhandler.cpp create mode 100644 src/client/clientuserinputhandler.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 044565b0..d021e7e3 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -20,6 +20,7 @@ set(SOURCES clientirclisthelper.cpp clientsettings.cpp clientsyncer.cpp + clientuserinputhandler.cpp irclistmodel.cpp messagefilter.cpp messagemodel.cpp @@ -38,6 +39,7 @@ set(MOC_HDRS clientcoreinfo.h clientidentity.h clientirclisthelper.h + clientuserinputhandler.h clientsyncer.h irclistmodel.h messagefilter.h diff --git a/src/client/client.cpp b/src/client/client.cpp index 759afcf9..d90e7eb8 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -31,6 +31,7 @@ #include "clientbufferviewmanager.h" #include "clientirclisthelper.h" #include "clientidentity.h" +#include "clientuserinputhandler.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" @@ -78,6 +79,7 @@ Client::Client(QObject *parent) _backlogManager(new ClientBacklogManager(this)), _bufferViewManager(0), _ircListHelper(new ClientIrcListHelper(this)), + _inputHandler(new ClientUserInputHandler(this)), _messageModel(0), _messageProcessor(0), _connectedToCore(false), @@ -109,7 +111,7 @@ void Client::init() { p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString))); p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), _networkModel, SLOT(bufferUpdated(BufferInfo))); - p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString))); + p->attachSignal(inputHandler(), SIGNAL(sendInput(BufferInfo, QString))); p->attachSignal(this, SIGNAL(requestNetworkStates())); p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &, const QVariantMap &)), SIGNAL(createIdentity(const Identity &, const QVariantMap &))); @@ -264,8 +266,8 @@ void Client::coreIdentityRemoved(IdentityId id) { } /*** ***/ -void Client::userInput(BufferInfo bufferInfo, QString message) { - emit instance()->sendInput(bufferInfo, message); +void Client::userInput(const BufferInfo &bufferInfo, const QString &message) { + inputHandler()->handleUserInput(bufferInfo, message); } /*** core connection stuff ***/ diff --git a/src/client/client.h b/src/client/client.h index 2babb111..3dd5b6ac 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -43,9 +43,10 @@ class NetworkModel; class BufferModel; class BufferSyncer; class ClientBacklogManager; +class ClientBufferViewManager; class ClientIrcListHelper; class ClientSyncer; -class ClientBufferViewManager; +class ClientUserInputHandler; class IrcUser; class IrcChannel; class SignalProxy; @@ -103,6 +104,7 @@ public: static inline ClientBacklogManager *backlogManager() { return instance()->_backlogManager; } static inline ClientIrcListHelper *ircListHelper() { return instance()->_ircListHelper; } static inline ClientBufferViewManager *bufferViewManager() { return instance()->_bufferViewManager; } + static inline ClientUserInputHandler *inputHandler() { return instance()->_inputHandler; } static AccountId currentCoreAccount(); @@ -110,7 +112,7 @@ public: static bool isSynced(); static inline bool internalCore() { return instance()->_internalCore; } - static void userInput(BufferInfo bufferInfo, QString message); + static void userInput(const BufferInfo &bufferInfo, const QString &message); static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients static void removeBuffer(BufferId id); @@ -124,7 +126,6 @@ public: static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); } signals: - void sendInput(BufferInfo, QString message); void requestNetworkStates(); void showConfigWizard(const QVariantMap &coredata); @@ -162,8 +163,6 @@ signals: void logUpdated(const QString &msg); public slots: - //void selectBuffer(Buffer *); - void disconnectFromCore(); void bufferRemoved(BufferId bufferId); @@ -206,6 +205,7 @@ private: ClientBacklogManager *_backlogManager; ClientBufferViewManager *_bufferViewManager; ClientIrcListHelper *_ircListHelper; + ClientUserInputHandler *_inputHandler; MessageModel *_messageModel; AbstractMessageProcessor *_messageProcessor; diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp new file mode 100644 index 00000000..31e8cb35 --- /dev/null +++ b/src/client/clientuserinputhandler.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** +* Copyright (C) 2005-09 by the Quassel Project * +* devel@quassel-irc.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) version 3. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include + +#include "client.h" +#include "clientuserinputhandler.h" +#include "clientsettings.h" +#include "ircuser.h" +#include "network.h" + +ClientUserInputHandler::ClientUserInputHandler(QObject *parent) : QObject(parent) { + NickCompletionSettings s; + s.notify("CompletionSuffix", this, SLOT(completionSuffixChanged(QVariant))); + completionSuffixChanged(s.completionSuffix()); +} + +void ClientUserInputHandler::completionSuffixChanged(const QVariant &v) { + QString suffix = v.toString(); + QString letter = "A-Za-z"; + QString special = "\x5b-\x60\x7b-\x7d"; + _nickRx = QRegExp(QString("^([%1%2][%1%2\\d-]*)%3").arg(letter, special, suffix).trimmed()); +} + +// this would be the place for a client-side hook +void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg) { + // check if we addressed a user and update its timestamp in that case + if(bufferInfo.type() == BufferInfo::ChannelBuffer) { + if(!msg.startsWith('/')) { + if(_nickRx.indexIn(msg) == 0) { + const Network *net = Client::network(bufferInfo.networkId()); + IrcUser *user = net ? net->ircUser(_nickRx.cap(1)) : 0; + if(user) + user->setLastSpokenTo(bufferInfo.bufferId(), QDateTime::currentDateTime().toUTC()); + } + } + } + emit sendInput(bufferInfo, msg); +} diff --git a/src/client/clientuserinputhandler.h b/src/client/clientuserinputhandler.h new file mode 100644 index 00000000..bc1b46cc --- /dev/null +++ b/src/client/clientuserinputhandler.h @@ -0,0 +1,45 @@ +/*************************************************************************** +* Copyright (C) 2005-09 by the Quassel Project * +* devel@quassel-irc.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) version 3. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef CLIENTUSERINPUTHANDLER_H_ +#define CLIENTUSERINPUTHANDLER_H_ + +#include "bufferinfo.h" + +class ClientUserInputHandler : public QObject { + Q_OBJECT + +public: + ClientUserInputHandler(QObject *parent = 0); + +public slots: + void handleUserInput(const BufferInfo &bufferInfo, const QString &msg); + +signals: + void sendInput(const BufferInfo &, const QString &); + +private slots: + void completionSuffixChanged(const QVariant &); + +private: + QRegExp _nickRx; +}; + +#endif -- 2.20.1