Mercurial > hg > octave-terminal
changeset 13585:f0d6f2ff45de
Now making correct use of the interface for the IRC Interface.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Wed, 03 Aug 2011 13:09:35 +0200 |
parents | 057ec114ac15 |
children | 689a5c8d8076 |
files | gui/src/IRCWidget.cpp gui/src/IRCWidget.h gui/src/qirc/IRCClientImpl.cpp gui/src/qirc/IRCClientImpl.h gui/src/qirc/IRCClientInterface.h |
diffstat | 5 files changed, 185 insertions(+), 135 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/IRCWidget.cpp +++ b/gui/src/IRCWidget.cpp @@ -24,6 +24,7 @@ #include <QLabel> #include <QSettings> #include <QInputDialog> +#include "IRCClientImpl.h" IRCWidget::IRCWidget (QWidget * parent): QWidget (parent) @@ -73,23 +74,23 @@ font.setFamily ("Courier"); font.setPointSize (11); m_chatWindow->setFont (font); - m_ircClientImpl = new IRCClientImpl (); + m_ircClientInterface = new IRCClientImpl (); - connect (m_ircClientImpl, SIGNAL (connected (QString)), + connect (m_ircClientInterface, SIGNAL (connected (QString)), this, SLOT (handleConnected (QString))); - connect (m_ircClientImpl, SIGNAL(loggedIn(QString)), + connect (m_ircClientInterface, SIGNAL(loggedIn(QString)), this, SLOT (joinOctaveChannel (QString))); - connect (m_ircClientImpl, SIGNAL (error (QString)), + connect (m_ircClientInterface, SIGNAL (error (QString)), this, SLOT (showErrorMessage (QString))); - connect (m_ircClientImpl, SIGNAL (debugMessage (QString)), + connect (m_ircClientInterface, SIGNAL (debugMessage (QString)), this, SLOT (showStatusMessage (QString))); - connect (m_ircClientImpl, SIGNAL (message (QString, QString, QString)), + connect (m_ircClientInterface, SIGNAL (message (QString, QString, QString)), this, SLOT (showMessage (QString, QString, QString ))); - connect (m_ircClientImpl, SIGNAL (nicknameChanged (QString,QString)), + connect (m_ircClientInterface, SIGNAL (nicknameChanged (QString,QString)), this, SLOT (handleNickChange (QString,QString))); - connect (m_ircClientImpl, SIGNAL (notification (QString,QString)), + connect (m_ircClientInterface, SIGNAL (notification (QString,QString)), this, SLOT (showNotification (QString,QString))); - connect (m_ircClientImpl, SIGNAL (loggedIn(QString)), + connect (m_ircClientInterface, SIGNAL (loggedIn(QString)), this, SLOT (handleLoggedIn(QString))); connect (m_nickButton, SIGNAL (clicked ()), this, SLOT (nickPopup ())); connect (m_inputLine, SIGNAL (returnPressed ()), this, @@ -115,7 +116,7 @@ { showStatusMessage (QString ("Attempting to connect to %1.") .arg (hostAddresses.at (0).toString ())); - m_ircClientImpl->connectToHost(hostAddresses.at (0), 6667, m_initialNick); + m_ircClientInterface->connectToHost(hostAddresses.at (0), 6667, m_initialNick); } } @@ -142,7 +143,8 @@ { Q_UNUSED (nick); showStatusMessage (QString ("Joining channel #octave.")); - m_ircClientImpl->sendJoinRequest ("#octave"); + m_ircClientInterface->sendJoinRequest ("#octave"); + m_ircClientInterface->focusChannel ("#octave"); } void @@ -150,7 +152,7 @@ { Q_UNUSED (channel); QString output; - if (message.contains (m_ircClientImpl->nickname ())) + if (message.contains (m_ircClientInterface->nickname ())) { output = QString ("<font color=\"#990000\"><b>%1:</b> %2</font>").arg (sender). @@ -179,10 +181,10 @@ QString newNick = QInputDialog::getText (this, QString ("Nickname"), QString ("Type in your nickname:"), - QLineEdit::Normal, m_ircClientImpl->nickname (), &ok); + QLineEdit::Normal, m_ircClientInterface->nickname (), &ok); if (ok) { - m_ircClientImpl->sendNicknameChangeRequest (newNick); + m_ircClientInterface->sendNicknameChangeRequest (newNick); } } @@ -202,11 +204,11 @@ message.split (QRegExp ("\\s+"), QString::SkipEmptyParts); if (line.at (0) == "/join") { - m_ircClientImpl->sendJoinRequest (line.at (1)); + m_ircClientInterface->sendJoinRequest (line.at (1)); } else if (line.at (0) == "/nick") { - m_ircClientImpl->sendNicknameChangeRequest (line.at (1)); + m_ircClientInterface->sendNicknameChangeRequest (line.at (1)); } else if (line.at (0) == "/msg") { @@ -218,16 +220,16 @@ pmsg += line.at (i); pmsg += " "; } - m_ircClientImpl->sendPrivateMessage(recipient, pmsg); + m_ircClientInterface->sendPrivateMessage(recipient, pmsg); } } else { - m_ircClientImpl->sendPublicMessage (message); + m_ircClientInterface->sendPublicMessage (message); message.replace ("<", "<"); message.replace (">", ">"); m_chatWindow->append (QString ("<b>%1:</b> %2"). - arg (m_ircClientImpl->nickname ()).arg (message)); + arg (m_ircClientInterface->nickname ()).arg (message)); } } @@ -253,7 +255,7 @@ if (m_autoIdentification) { - m_ircClientImpl->sendPrivateMessage("NickServ", QString ("identify %1"). + m_ircClientInterface->sendPrivateMessage("NickServ", QString ("identify %1"). arg (m_nickServPassword)); } }
--- a/gui/src/IRCWidget.h +++ b/gui/src/IRCWidget.h @@ -24,7 +24,7 @@ #include <QPushButton> #include <QLineEdit> #include <QCompleter> -#include "IRCClientImpl.h" +#include "IRCClientInterface.h" class IRCWidget:public QWidget { @@ -52,7 +52,7 @@ void updateNickCompleter (); private: - IRCClientImpl * m_ircClientImpl; + IRCClientInterface * m_ircClientInterface; QTextEdit *m_chatWindow; QPushButton *m_nickButton; QLineEdit *m_inputLine;
--- a/gui/src/qirc/IRCClientImpl.cpp +++ b/gui/src/qirc/IRCClientImpl.cpp @@ -18,17 +18,17 @@ #include "IRCClientImpl.h" -IRCEvent::IRCEvent (const char *serverMessage) +IRCServerMessage::IRCServerMessage (const char *serverMessage) { char prefix[MAX_LINE_LEN]; int index = 0; - nick = ""; - user = ""; - host = ""; + n_nick = ""; + m_user = ""; + m_host = ""; for (int i = 0; i < 15; i++) { - param[i] = ""; + m_parameter[i] = ""; } if (serverMessage[0] == CHR_COLON) @@ -52,26 +52,26 @@ switch (etapa) { case 0: - nick += prefix[i]; + n_nick += prefix[i]; break; case 1: - user += prefix[i]; + m_user += prefix[i]; break; default: - host += prefix[i]; + m_host += prefix[i]; break; } } } } - command = getStringToken (serverMessage, index); - command = command.toUpper (); + m_command = getStringToken (serverMessage, index); + m_command = m_command.toUpper (); - paramCount = 0; + m_parameterCount = 0; while (serverMessage[index] != 0) { - if ((serverMessage[index] == CHR_COLON) || (paramCount == 14)) + if ((serverMessage[index] == CHR_COLON) || (m_parameterCount == 14)) { if (serverMessage[index] == CHR_COLON) @@ -79,43 +79,43 @@ index++; } - param[paramCount] = (const char *) (serverMessage + index); + m_parameter[m_parameterCount] = (const char *) (serverMessage + index); index += strlen (serverMessage + index); } else { - param[paramCount] = getStringToken (serverMessage, index); + m_parameter[m_parameterCount] = getStringToken (serverMessage, index); } - paramCount++; + m_parameterCount++; } - if (strlen (command.toStdString ().c_str ()) == - strspn (command.toStdString ().c_str (), DIGITS)) + if (strlen (m_command.toStdString ().c_str ()) == + strspn (m_command.toStdString ().c_str (), DIGITS)) { - numeric = true; - codeNumber = atoi (command.toStdString ().c_str ()); + n_numeric = true; + m_codeNumber = atoi (m_command.toStdString ().c_str ()); } else { - numeric = false; + n_numeric = false; } } int -IRCEvent::getNumeric () +IRCServerMessage::numericValue () { - if (!numeric) + if (!n_numeric) { return -1; } else { - return codeNumber; + return m_codeNumber; } } QString -IRCEvent::getParam (int index) +IRCServerMessage::parameter (int index) { if ((index < 0) || (index > 14)) { @@ -123,12 +123,12 @@ } else { - return param[index]; + return m_parameter[index]; } } int -IRCEvent::skipSpaces (const char *line, int &index) +IRCServerMessage::skipSpaces (const char *line, int &index) { while (line[index] == CHR_SPACE) { @@ -138,7 +138,7 @@ } QString -IRCEvent::getStringToken (const char *line, int &index) +IRCServerMessage::getStringToken (const char *line, int &index) { QString token (""); skipSpaces (line, index); @@ -153,11 +153,23 @@ } QString -IRCEvent::getStringToken (QString line, int &index) +IRCServerMessage::getStringToken (QString line, int &index) { return getStringToken (line.toStdString ().c_str (), index); } +IRCChannelProxy::IRCChannelProxy () + : IRCChannelProxyInterface () +{ + +} + +QTextDocument * +IRCChannelProxy::conversation () +{ + return &m_conversation; +} + IRCClientImpl::IRCClientImpl () : IRCClientInterface () { @@ -204,11 +216,18 @@ return m_port; } +IRCChannelProxyInterface * +IRCClientImpl::ircChannelProxy (const QString &channel) +{ + if (m_channels.contains (channel)) + return m_channels[channel]; + return 0; +} + void IRCClientImpl::sendJoinRequest (const QString& channel) { sendCommand (1, COMMAND_JOIN, channel.toStdString ().c_str ()); - focusChannel (channel); } void @@ -283,14 +302,32 @@ } void +IRCClientImpl::handleNicknameChanged (const QString &oldNick, const QString &newNick) +{ + emit nicknameChanged (oldNick, newNick); +} + +void +IRCClientImpl::handleUserJoined (const QString &nick, const QString &channel) +{ + emit userJoined (nick, channel); +} + +void +IRCClientImpl::handleUserQuit (const QString &nick, const QString &reason) +{ + emit userQuit (nick, reason); +} + +void IRCClientImpl::handleIncomingLine (const QString &line) { if (m_connected && !line.isEmpty()) { - IRCEvent ircEvent(line.toStdString().c_str()); - if (ircEvent.isNumeric () == true) + IRCServerMessage ircEvent(line.toStdString().c_str()); + if (ircEvent.isNumericValue () == true) { - switch (ircEvent.getNumeric ()) + switch (ircEvent.numericValue ()) { case RPL_WELCOME: emit loggedIn (nickname ()); @@ -311,27 +348,25 @@ case RPL_TOPIC: break; case RPL_NAMREPLY: - /* - m_nickList = - event->getParam (3).split (QRegExp ("\\s+"), QString::SkipEmptyParts); - updateNickCompleter ();*/ + + //m_nickList = event->getParam (3).split (QRegExp ("\\s+"), QString::SkipEmptyParts); break; } } else { - QString command = ircEvent.getCommand (); + QString command = ircEvent.command (); if (command == COMMAND_NICK) { - emit nicknameChanged (ircEvent.getParam(0), ircEvent.getParam(1)); + handleNicknameChanged (ircEvent.parameter (0), ircEvent.parameter (1)); } else if (command == COMMAND_QUIT) { - emit userQuit (ircEvent.getNick (), ircEvent.getParam (0)); + handleUserQuit (ircEvent.nick (), ircEvent.parameter (0)); } else if (command == COMMAND_JOIN) { - emit userJoined (ircEvent.getNick (), ircEvent.getParam (0)); + handleUserJoined(ircEvent.nick (), ircEvent.parameter (0)); } else if (command == COMMAND_PART) { @@ -368,12 +403,12 @@ } else if (command == COMMAND_PRIVMSG) { - emit message (ircEvent.getParam (0), ircEvent.getNick (), ircEvent.getParam (1)); + emit message (ircEvent.parameter (0), ircEvent.nick (), ircEvent.parameter (1)); } else if (command == COMMAND_NOTICE) { - emit notification (ircEvent.getNick ().toStdString ().c_str (), - ircEvent.getParam (1).toStdString ().c_str ()); + emit notification (ircEvent.nick ().toStdString ().c_str (), + ircEvent.parameter (1).toStdString ().c_str ()); } else if (command == COMMAND_PING) { @@ -381,7 +416,7 @@ } else if (command == COMMAND_ERROR) { - emit error (ircEvent.getParam (0)); + emit error (ircEvent.parameter (0)); } else {
--- a/gui/src/qirc/IRCClientImpl.h +++ b/gui/src/qirc/IRCClientImpl.h @@ -21,84 +21,86 @@ #include <QTcpSocket> #include <QHostInfo> +#include <QStringList> +#include <QTextDocument> #include "IRCClientInterface.h" -#define MAX_LINE_LEN 512 -#define PARAM_MAX_COUNT 15 -#define CHR_COLON ':' -#define CHR_SPACE ' ' -#define CHR_ZERO '\0' -#ifdef Q_OS_LINUX -#define CRLF "\n" -#else -#define CRLF "\r\n" -#endif -#define DIGITS "0123456789" +class IRCServerMessage +{ + #define MAX_LINE_LEN 512 + #define PARAM_MAX_COUNT 15 + #define CHR_COLON ':' + #define CHR_SPACE ' ' + #define CHR_ZERO '\0' + #ifdef Q_OS_LINUX + #define CRLF "\n" + #else + #define CRLF "\r\n" + #endif + #define DIGITS "0123456789" + +public: + IRCServerMessage (const char *serverMessage); -class IRCEvent -{ -private: - int codeNumber; - bool numeric; + bool isNumericValue () + { + return n_numeric; + } + + QString nick () + { + return n_nick; + } - QString nick, user, host; - QString command; - int paramCount; - QString param[PARAM_MAX_COUNT]; + QString command () + { + return m_command; + } -protected: + int numericValue (); + QString parameter (int index); + +private: int skipSpaces (const char *linea, int &index); QString getStringToken (const char *linea, int &index); QString getStringToken (QString linea, int &index); -public: - IRCEvent (const char *serverMessage); + int m_codeNumber; + bool n_numeric; - bool isNumeric () - { - return numeric; - } + QString n_nick, m_user, m_host; + QString m_command; + int m_parameterCount; + QString m_parameter[PARAM_MAX_COUNT]; +}; - QString getNick () - { - return nick; - } - QString getUser () - { - return user; - } - QString getHost () - { - return host; - } - QString getCommand () - { - return command; - } - int getNumeric (); - - int getParamCount () - { - return paramCount; - } - QString getParam (int index); +class IRCChannelProxy : public IRCChannelProxyInterface +{ +public: + IRCChannelProxy (); + QTextDocument *conversation (); +private: + QStringList m_userList; + QTextDocument m_conversation; }; class IRCClientImpl : public IRCClientInterface { Q_OBJECT public: - IRCClientImpl(); + IRCClientImpl (); + + const QString& nickname (); + bool isConnected (); + const QHostAddress& host(); + int port(); + IRCChannelProxyInterface *ircChannelProxy(const QString& channel); public slots: void connectToHost (const QHostAddress& host, int port, const QString& initialNick); void disconnect (); void reconnect (); - bool isConnected (); - const QHostAddress& host(); - int port(); - void sendJoinRequest (const QString& channel); void leaveChannel (const QString& channel, const QString& reason); @@ -107,8 +109,6 @@ void sendPublicMessage (const QString& message); void sendPrivateMessage (const QString &recipient, const QString &message); - const QString& nickname (); - signals: void debugMessage (const QString& message); @@ -118,17 +118,21 @@ void handleReadyRead (); private: + void handleNicknameChanged (const QString& oldNick, const QString& newNick); + void handleUserJoined (const QString& nick, const QString& channel); + void handleUserQuit (const QString& nick, const QString& reason); void handleIncomingLine (const QString& line); void sendLine (const QString& line); void sendCommand (int numberOfCommands, const char *command, ...); - QHostAddress m_host; - int m_port; - QString m_nickname; - bool m_connected; - QString m_focussedChannel; + QHostAddress m_host; + int m_port; + QString m_nickname; + bool m_connected; + QString m_focussedChannel; - QTcpSocket m_tcpSocket; + QTcpSocket m_tcpSocket; + QMap<QString, IRCChannelProxyInterface*> m_channels; }; #endif // IRCCLIENTIMPL_H
--- a/gui/src/qirc/IRCClientInterface.h +++ b/gui/src/qirc/IRCClientInterface.h @@ -22,8 +22,15 @@ #include <QString> #include <QObject> #include <QHostAddress> +#include <QTextDocument> +#include "IRCCodes.h" -#include "IRCCodes.h" +class IRCChannelProxyInterface +{ +public: + IRCChannelProxyInterface () { } + virtual QTextDocument *conversation () = 0; +}; /** * \class IRCClientInterface @@ -36,16 +43,18 @@ IRCClientInterface () { } virtual ~IRCClientInterface () { } + virtual const QString& nickname () = 0; + virtual bool isConnected () = 0; + virtual const QHostAddress& host() = 0; + virtual int port() = 0; + virtual IRCChannelProxyInterface *ircChannelProxy(const QString& channel) = 0; + public slots: // Connection state: virtual void connectToHost (const QHostAddress& host, int port, const QString& initialNick) = 0; virtual void disconnect () = 0; virtual void reconnect () = 0; - virtual bool isConnected () = 0; - virtual const QHostAddress& host() = 0; - virtual int port() = 0; - virtual void sendJoinRequest (const QString& channel) = 0; virtual void leaveChannel (const QString& channel, const QString& reason) = 0; @@ -54,7 +63,6 @@ virtual void sendNicknameChangeRequest (const QString& nickname) = 0; virtual void sendPublicMessage (const QString& message) = 0; virtual void sendPrivateMessage (const QString& recipient, const QString& message) = 0; - virtual const QString& nickname () = 0; signals: void newMessage (const QString& channel, const QString& sender, const QString& message); @@ -67,6 +75,7 @@ void userJoined (const QString& nick, const QString& channel); void userQuit (const QString& nick, const QString& reason); void loggedIn (const QString& nick); + void userList (const QString& channel, const QStringList& list); }; #endif // IRCCLIENTINTERFACE_H