changeset 13597:73a9ac1cdbf1

Further structured IRC interfaces.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sat, 13 Aug 2011 01:26:40 +0200
parents f6bb48258200
children a9b96f66202a
files gui/src/qirc/IRCClientImpl.cpp gui/src/qirc/IRCClientImpl.h gui/src/qirc/IRCClientInterface.h
diffstat 3 files changed, 48 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/qirc/IRCClientImpl.cpp
+++ b/gui/src/qirc/IRCClientImpl.cpp
@@ -144,10 +144,11 @@
   return getStringToken (line.toStdString ().c_str (), index);
 }
 
-IRCChannelProxy::IRCChannelProxy ()
-  : IRCChannelProxyInterface ()
+IRCChannelProxy::IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName)
+  : IRCChannelProxyInterface (clientInterface, channelName),
+    m_clientInterface (clientInterface)
 {
-
+  m_channelName = channelName;
 }
 
 QTextDocument *
@@ -162,6 +163,32 @@
   return &m_userListModel;
 }
 
+QString
+IRCChannelProxy::channelName ()
+{
+  return m_channelName;
+}
+
+void
+IRCChannelProxy::sendMessage (const QString& message)
+{
+  Q_UNUSED (message);
+  // TODO: implement.
+}
+
+void
+IRCChannelProxy::sendJoinRequest ()
+{
+  //sendIRCCommand (IRCCommand::Join, QStringList (channel));
+}
+
+
+void
+IRCChannelProxy::leave (const QString& reason)
+{
+  Q_UNUSED (reason);
+}
+
 IRCClientImpl::IRCClientImpl ()
   : IRCClientInterface ()
 {
@@ -212,22 +239,9 @@
 IRCChannelProxyInterface *
 IRCClientImpl::ircChannelProxy (const QString &channel)
 {
-  if (m_channels.contains (channel))
-    return m_channels[channel];
-  return 0;
-}
-
-void
-IRCClientImpl::sendJoinRequest (const QString& channel)
-{
-  sendIRCCommand (IRCCommand::Join, QStringList (channel));
-}
-
-void
-IRCClientImpl::leaveChannel (const QString& channel, const QString& reason)
-{
-  Q_UNUSED (channel);
-  Q_UNUSED (reason);
+  if (!m_channels.contains (channel))
+      m_channels[channel] = new IRCChannelProxy(this, channel);
+  return m_channels[channel];
 }
 
 void
--- a/gui/src/qirc/IRCClientImpl.h
+++ b/gui/src/qirc/IRCClientImpl.h
@@ -274,13 +274,21 @@
 class IRCChannelProxy : public IRCChannelProxyInterface
 {
 public:
-  IRCChannelProxy ();
+  IRCChannelProxy (IRCClientInterface *clientInterface, const QString& channelName);
   QTextDocument *conversationModel ();
   QStringListModel *userListModel ();
+  QString channelName ();
+
+  void sendMessage (const QString& message);
+  void sendJoinRequest ();
+  void leave (const QString &reason);
+
 private:
+  QString m_channelName;
   QStringList m_userList;
   QStringListModel m_userListModel;
   QTextDocument m_conversationModel;
+  IRCClientInterface *m_clientInterface;
 };
 
 class IRCClientImpl : public IRCClientInterface
@@ -300,9 +308,6 @@
   void disconnect ();
   void reconnect ();
 
-  void sendJoinRequest (const QString& channel);
-  void leaveChannel (const QString& channel, const QString& reason);
-
   void focusChannel (const QString& channel);
   void sendNicknameChangeRequest (const QString &nickname);
   void sendPublicMessage (const QString& message);
--- a/gui/src/qirc/IRCClientInterface.h
+++ b/gui/src/qirc/IRCClientInterface.h
@@ -25,12 +25,17 @@
 #include <QTextDocument>
 #include <QStringListModel>
 
+class IRCClientInterface;
 class IRCChannelProxyInterface
 {
 public:
-  IRCChannelProxyInterface () { }
+  IRCChannelProxyInterface (IRCClientInterface *, const QString&) { }
   virtual QTextDocument *conversationModel () = 0;
   virtual QStringListModel *userListModel () = 0;
+  virtual QString channelName () = 0;
+  virtual void sendMessage (const QString& message) = 0;
+  virtual void sendJoinRequest () = 0;
+  virtual void leave (const QString& reason) = 0;
 };
 
 /**
@@ -56,9 +61,6 @@
   virtual void disconnect () = 0;
   virtual void reconnect () = 0;
 
-  virtual void sendJoinRequest (const QString& channel) = 0;
-  virtual void leaveChannel (const QString& channel, const QString& reason) = 0;
-
   // Messaging:
   virtual void focusChannel (const QString& channel) = 0;
   virtual void sendNicknameChangeRequest (const QString& nickname) = 0;