Introduce ClientUserInputHandler
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 25 Feb 2009 17:35:50 +0000 (18:35 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 25 Feb 2009 17:41:14 +0000 (18:41 +0100)
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
src/client/client.cpp
src/client/client.h
src/client/clientuserinputhandler.cpp [new file with mode: 0644]
src/client/clientuserinputhandler.h [new file with mode: 0644]

index 044565b..d021e7e 100644 (file)
@@ -20,6 +20,7 @@ set(SOURCES
     clientirclisthelper.cpp
     clientsettings.cpp
     clientsyncer.cpp
     clientirclisthelper.cpp
     clientsettings.cpp
     clientsyncer.cpp
+    clientuserinputhandler.cpp
     irclistmodel.cpp
     messagefilter.cpp
     messagemodel.cpp
     irclistmodel.cpp
     messagefilter.cpp
     messagemodel.cpp
@@ -38,6 +39,7 @@ set(MOC_HDRS
     clientcoreinfo.h
     clientidentity.h
     clientirclisthelper.h
     clientcoreinfo.h
     clientidentity.h
     clientirclisthelper.h
+    clientuserinputhandler.h
     clientsyncer.h
     irclistmodel.h
     messagefilter.h
     clientsyncer.h
     irclistmodel.h
     messagefilter.h
index 759afcf..d90e7eb 100644 (file)
@@ -31,6 +31,7 @@
 #include "clientbufferviewmanager.h"
 #include "clientirclisthelper.h"
 #include "clientidentity.h"
 #include "clientbufferviewmanager.h"
 #include "clientirclisthelper.h"
 #include "clientidentity.h"
+#include "clientuserinputhandler.h"
 #include "ircchannel.h"
 #include "ircuser.h"
 #include "message.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)),
     _backlogManager(new ClientBacklogManager(this)),
     _bufferViewManager(0),
     _ircListHelper(new ClientIrcListHelper(this)),
+    _inputHandler(new ClientUserInputHandler(this)),
     _messageModel(0),
     _messageProcessor(0),
     _connectedToCore(false),
     _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->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 &)));
   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 ***/
 }
 
 /*** core connection stuff ***/
index 2babb11..3dd5b6a 100644 (file)
@@ -43,9 +43,10 @@ class NetworkModel;
 class BufferModel;
 class BufferSyncer;
 class ClientBacklogManager;
 class BufferModel;
 class BufferSyncer;
 class ClientBacklogManager;
+class ClientBufferViewManager;
 class ClientIrcListHelper;
 class ClientSyncer;
 class ClientIrcListHelper;
 class ClientSyncer;
-class ClientBufferViewManager;
+class ClientUserInputHandler;
 class IrcUser;
 class IrcChannel;
 class SignalProxy;
 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 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();
 
 
   static AccountId currentCoreAccount();
 
@@ -110,7 +112,7 @@ public:
   static bool isSynced();
   static inline bool internalCore() { return instance()->_internalCore; }
 
   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);
 
   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:
   static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
 
 signals:
-  void sendInput(BufferInfo, QString message);
   void requestNetworkStates();
 
   void showConfigWizard(const QVariantMap &coredata);
   void requestNetworkStates();
 
   void showConfigWizard(const QVariantMap &coredata);
@@ -162,8 +163,6 @@ signals:
   void logUpdated(const QString &msg);
 
 public slots:
   void logUpdated(const QString &msg);
 
 public slots:
-  //void selectBuffer(Buffer *);
-
   void disconnectFromCore();
 
   void bufferRemoved(BufferId bufferId);
   void disconnectFromCore();
 
   void bufferRemoved(BufferId bufferId);
@@ -206,6 +205,7 @@ private:
   ClientBacklogManager *_backlogManager;
   ClientBufferViewManager *_bufferViewManager;
   ClientIrcListHelper *_ircListHelper;
   ClientBacklogManager *_backlogManager;
   ClientBufferViewManager *_bufferViewManager;
   ClientIrcListHelper *_ircListHelper;
+  ClientUserInputHandler *_inputHandler;
 
   MessageModel *_messageModel;
   AbstractMessageProcessor *_messageProcessor;
 
   MessageModel *_messageModel;
   AbstractMessageProcessor *_messageProcessor;
diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp
new file mode 100644 (file)
index 0000000..31e8cb3
--- /dev/null
@@ -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 <QDateTime>
+
+#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 (file)
index 0000000..bc1b46c
--- /dev/null
@@ -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