# HG changeset patch # User Jacob Dawid # Date 1313357798 -7200 # Node ID a9b96f66202a508487ab4b7dceb459a7064d4739 # Parent 73a9ac1cdbf18bfa5d1edaaf48a8cf5d7fd52491 Further reworked on IRC backend. diff --git a/gui/src/IRCWidget.cpp b/gui/src/IRCWidget.cpp --- 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 ("<", "<"); message.replace (">", ">"); m_chatWindow->append (QString ("%1: %2"). diff --git a/gui/src/qirc/IRCClientImpl.cpp b/gui/src/qirc/IRCClientImpl.cpp --- 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; diff --git a/gui/src/qirc/IRCClientImpl.h b/gui/src/qirc/IRCClientImpl.h --- 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 m_channels; }; diff --git a/gui/src/qirc/IRCClientInterface.h b/gui/src/qirc/IRCClientInterface.h --- a/gui/src/qirc/IRCClientInterface.h +++ b/gui/src/qirc/IRCClientInterface.h @@ -26,10 +26,13 @@ #include 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: