changeset 13598:a9b96f66202a

Further reworked on IRC backend.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sun, 14 Aug 2011 23:36:38 +0200
parents 73a9ac1cdbf1
children e67616aca5a6
files gui/src/IRCWidget.cpp gui/src/qirc/IRCClientImpl.cpp gui/src/qirc/IRCClientImpl.h gui/src/qirc/IRCClientInterface.h
diffstat 4 files changed, 35 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/IRCWidget.cpp
+++ b/gui/src/IRCWidget.cpp
@@ -74,7 +74,8 @@
   font.setFamily ("Courier");
   font.setPointSize (11);
   m_chatWindow->setFont (font);
-  m_ircClientInterface = new IRCClientImpl ();
+  m_ircClientInterface = new IRCClientImpl (this);
+  m_octaveChannel = m_ircClientInterface->ircChannelProxy ("#octave");
 
   connect (m_ircClientInterface, SIGNAL (connected (QString)),
            this, SLOT (handleConnected (QString)));
@@ -143,8 +144,7 @@
 {
   Q_UNUSED (nick);
   showStatusMessage (QString ("Joining channel #octave."));
-  m_ircClientInterface->sendJoinRequest ("#octave");
-  m_ircClientInterface->focusChannel ("#octave");
+  m_octaveChannel->sendJoinRequest ();
 }
 
 void
@@ -204,7 +204,8 @@
 	message.split (QRegExp ("\\s+"), QString::SkipEmptyParts);
       if (line.at (0) == "/join")
 	{
-          m_ircClientInterface->sendJoinRequest (line.at (1));
+          IRCChannelProxyInterface *ircChannel = m_ircClientInterface->ircChannelProxy (line.at (1));
+          ircChannel->sendJoinRequest ();
 	}
       else if (line.at (0) == "/nick")
 	{
@@ -225,7 +226,7 @@
     }
   else
     {
-      m_ircClientInterface->sendPublicMessage (message);
+      m_octaveChannel->sendMessage (message);
       message.replace ("<", "&lt;");
       message.replace (">", "&gt;");
       m_chatWindow->append (QString ("<b>%1:</b> %2").
--- a/gui/src/qirc/IRCClientImpl.cpp
+++ b/gui/src/qirc/IRCClientImpl.cpp
@@ -144,8 +144,8 @@
   return getStringToken (line.toStdString ().c_str (), index);
 }
 
-IRCChannelProxy::IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName)
-  : IRCChannelProxyInterface (clientInterface, channelName),
+IRCChannelProxy::IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName, QObject *parent)
+  : IRCChannelProxyInterface (clientInterface, channelName, parent),
     m_clientInterface (clientInterface)
 {
   m_channelName = channelName;
@@ -172,14 +172,16 @@
 void
 IRCChannelProxy::sendMessage (const QString& message)
 {
-  Q_UNUSED (message);
-  // TODO: implement.
+  QStringList arguments;
+  arguments << m_channelName;
+  arguments << message;
+  m_clientInterface->sendIRCCommand (IRCCommand::PrivateMessage, arguments);
 }
 
 void
 IRCChannelProxy::sendJoinRequest ()
 {
-  //sendIRCCommand (IRCCommand::Join, QStringList (channel));
+  m_clientInterface->sendIRCCommand (IRCCommand::Join, QStringList (m_channelName));
 }
 
 
@@ -189,14 +191,22 @@
   Q_UNUSED (reason);
 }
 
-IRCClientImpl::IRCClientImpl ()
-  : IRCClientInterface ()
+IRCClientImpl::IRCClientImpl (QObject *parent)
+  : IRCClientInterface (parent)
 {
   connect (&m_tcpSocket, SIGNAL (connected ()), this, SLOT (handleConnected ()));
   connect (&m_tcpSocket, SIGNAL (disconnected ()), this, SLOT (handleDisconnected ()));
   connect (&m_tcpSocket, SIGNAL (readyRead ()), this, SLOT (handleReadyRead ()));
 }
 
+IRCClientImpl::~IRCClientImpl ()
+{
+  foreach (IRCChannelProxyInterface *ircChannelProxy, m_channels)
+    {
+      delete ircChannelProxy;
+    }
+}
+
 void
 IRCClientImpl::connectToHost (const QHostAddress& host, int port, const QString& initialNick)
 {
@@ -245,27 +255,12 @@
 }
 
 void
-IRCClientImpl::focusChannel (const QString& channel)
-{
-  m_focussedChannel = channel;
-}
-
-void
 IRCClientImpl::sendNicknameChangeRequest (const QString &nickname)
 {
   sendIRCCommand (IRCCommand::Nick, QStringList (nickname));
 }
 
 void
-IRCClientImpl::sendPublicMessage (const QString& message)
-{
-  QStringList arguments;
-  arguments << m_focussedChannel;
-  arguments << message;
-  sendIRCCommand (IRCCommand::PrivateMessage, arguments);
-}
-
-void
 IRCClientImpl::sendPrivateMessage (const QString &recipient, const QString &message)
 {
   QStringList arguments;
--- a/gui/src/qirc/IRCClientImpl.h
+++ b/gui/src/qirc/IRCClientImpl.h
@@ -273,8 +273,9 @@
 
 class IRCChannelProxy : public IRCChannelProxyInterface
 {
+  Q_OBJECT
 public:
-  IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName);
+  IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName, QObject *parent = 0);
   QTextDocument *conversationModel ();
   QStringListModel *userListModel ();
   QString channelName ();
@@ -295,22 +296,22 @@
 {
   Q_OBJECT
 public:
-  IRCClientImpl ();
+  IRCClientImpl (QObject *parent = 0);
+  ~IRCClientImpl ();
 
   const QString& nickname ();
   bool isConnected ();
   const QHostAddress& host();
   int port();
   IRCChannelProxyInterface *ircChannelProxy(const QString& channel);
+  void sendIRCCommand (const QString& command, const QStringList& arguments);
 
 public slots:
   void connectToHost (const QHostAddress& host, int port, const QString& initialNick);
   void disconnect ();
   void reconnect ();
 
-  void focusChannel (const QString& channel);
   void sendNicknameChangeRequest (const QString &nickname);
-  void sendPublicMessage (const QString& message);
   void sendPrivateMessage (const QString &recipient, const QString &message);
 
 signals:
@@ -327,14 +328,11 @@
   void handleUserQuit (const QString& nick, const QString& reason);
   void handleIncomingLine (const QString& line);
   void sendLine (const QString& line);
-  void sendIRCCommand (const QString& command, const QStringList& arguments);
 
   QHostAddress                    m_host;
   int                             m_port;
   QString                         m_nickname;
   bool                            m_connected;
-  QString                         m_focussedChannel;
-
   QTcpSocket                      m_tcpSocket;
   QMap<QString, IRCChannelProxyInterface*> m_channels;
 };
--- a/gui/src/qirc/IRCClientInterface.h
+++ b/gui/src/qirc/IRCClientInterface.h
@@ -26,10 +26,13 @@
 #include <QStringListModel>
 
 class IRCClientInterface;
-class IRCChannelProxyInterface
+class IRCChannelProxyInterface : public QObject
 {
+  Q_OBJECT
 public:
-  IRCChannelProxyInterface (IRCClientInterface *, const QString&) { }
+  IRCChannelProxyInterface (IRCClientInterface *, const QString&, QObject *parent = 0) : QObject (parent) { }
+  virtual ~IRCChannelProxyInterface () { }
+
   virtual QTextDocument *conversationModel () = 0;
   virtual QStringListModel *userListModel () = 0;
   virtual QString channelName () = 0;
@@ -46,7 +49,7 @@
 {
   Q_OBJECT
 public:
-  IRCClientInterface () { }
+  IRCClientInterface (QObject *parent = 0) : QObject (parent) { }
   virtual ~IRCClientInterface () { }
 
   virtual const QString& nickname () = 0;
@@ -54,6 +57,7 @@
   virtual const QHostAddress& host() = 0;
   virtual int port() = 0;
   virtual IRCChannelProxyInterface *ircChannelProxy(const QString& channel) = 0;
+  virtual void sendIRCCommand (const QString& command, const QStringList& arguments) = 0;
 
 public slots:
   // Connection state:
@@ -61,10 +65,7 @@
   virtual void disconnect () = 0;
   virtual void reconnect () = 0;
 
-  // Messaging:
-  virtual void focusChannel (const QString& channel) = 0;
   virtual void sendNicknameChangeRequest (const QString& nickname) = 0;
-  virtual void sendPublicMessage (const QString& message) = 0;
   virtual void sendPrivateMessage (const QString& recipient, const QString& message) = 0;
 
 signals: