ircnetworkadapter.h
1 //------------------------------------------------------------------------------
2 // ircnetworkadapter.h
3 //
4 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
5 //------------------------------------------------------------------------------
6 #ifndef __IRCNETWORKADAPTER_H__
7 #define __IRCNETWORKADAPTER_H__
8 
9 #include "irc/ircadapterbase.h"
10 #include "irc/ircclient.h"
11 #include "irc/ircnetworkconnectioninfo.h"
12 #include "irc/ircrequestparser.h"
13 #include "socketsignalsadapter.h"
14 
15 #include <QHash>
16 
17 class IRCChatAdapter;
18 class IRCISupportParser;
19 class IRCResponseParser;
21 class IRCUserList;
22 class IRCUserPrefix;
23 
28 {
29  Q_OBJECT
30 
31  friend class IRCSocketSignalsAdapter;
32 
33  public:
34  IRCNetworkAdapter(const IRCNetworkConnectionInfo &connectionInfo);
36 
37  AdapterType adapterType() const { return NetworkAdapter; }
38 
42  bool amIOperator(const QString& channel) const
43  {
44  return this->isOperator(this->myNickname(), channel);
45  }
46 
67  void banUser(const QString& nickname, const QString& reason, const QString& channel);
68 
69  QList<IRCAdapterBase*> childrenAdapters();
70  void connect();
71  const IRCNetworkConnectionInfo &connection() const
72  {
73  return this->connectionInfo;
74  }
75 
80  void detachChatWindow(const IRCChatAdapter* pAdapter);
81 
82  void disconnect(const QString& farewellMessage);
83 
102  void doSendMessage(const QString& message, IRCAdapterBase* pOrigin);
103 
104  bool hasRecipient(const QString& recipient) const;
105 
106  const PatternList &ignoredUsersPatterns() const;
107 
112  bool isAdapterRelated(const IRCAdapterBase* pAdapter) const;
113  bool isConnected() const { return ircClient.isConnected(); }
114  bool isMyNickname(const QString& nickname) const;
115 
124  bool isOperator(const QString& nickname, const QString& channel) const;
125 
126  void killAllChatWindows();
127 
128  const QString& myNickname() const { return connectionInfo.nick; }
129 
131  {
132  return this;
133  }
134 
135  IRCResponseParser *responseParser()
136  {
137  return ircResponseParser;
138  }
139 
148  void setChannelMode(const QString& channel, const QString& nickname, const QString& flag, bool bSet);
149 
150  void sendCtcp(const QString &nickname, const QString &command);
151 
156  {
157  this->bEmitAllIRCMessages = b;
158  }
159 
160  void setNetworkEntity(const IRCNetworkEntity &network);
161 
162  QString title() const;
163 
168  const IRCUserPrefix &userPrefixes() const;
169 
170  public slots:
182  void openNewAdapter(const QString& recipientName);
183 
184  void printMsgLiteral(const QString& recipient, const QString& content,
185  const IRCMessageClass& msgClass);
189  void print(const QString& printWhat, const QString& printWhere);
190  void printWithClass(const QString& printWhat, const QString& printWhere, const IRCMessageClass& msgClass);
191  void printToCurrentChatBox(const QString& printWhat, const IRCMessageClass& msgClass);
192  void reloadNetworkEntityFromConfig();
193  void userPing(const QString &nickname, qint64 ping);
194 
195  signals:
200  void newChatWindowIsOpened(IRCChatAdapter* pWindow);
201 
202  private:
209  bool bIsJoining;
210 
220  bool bEmitAllIRCMessages;
221 
230  QHash<QString, IRCChatAdapter*> chatWindows;
231  IRCNetworkConnectionInfo connectionInfo;
232  IRCClient ircClient;
233  IRCRequestParser ircRequestParser;
234  IRCResponseParser* ircResponseParser;
235  IRCISupportParser* ircISupportParser;
236  IRCSocketSignalsAdapter* pIrcSocketSignalsAdapter;
237 
241  IRCChatAdapter* getChatAdapter(const QString& recipient);
242  const IRCChatAdapter* getChatAdapter(const QString& recipient) const;
243 
253  IRCChatAdapter* getOrCreateNewChatAdapter(const QString& recipient);
254 
255  void killChatWindow(const QString& recipient);
256 
257  private slots:
258  void appendISupportLine(const QString &line);
259  void echoPrivmsg(const QString& recipient, const QString& content);
260  void helloClient(const QString& nickname);
261  void kick(const QString& channel, const QString& byWhom, const QString& whoIsKicked, const QString& reason);
262  void kill(const QString& victim, const QString& comment);
263  void ircServerResponse(const QString& message);
264  void modeInfo(const QString& channel, const QString& whoSetThis, const QString& modeParams);
265  void namesListReceived(const QString& channel, const QStringList& names);
266  void namesListEndReceived(const QString& channel);
267  void nicknameInUse(const QString& nickname);
268  void noSuchNickname(const QString& nickname);
269  void parseError(const QString& error);
270 
271  void privMsgReceived(const QString& recipient, const QString& sender, const QString& content);
272  void sendPong(const QString& toWhom);
273  void userChangesNickname(const QString& oldNickname, const QString& newNickname);
274  void userIdleTime(const QString &nick, int secondsIdle);
275  void userJoinsChannel(const QString& channel, const QString& nickname, const QString& fullSignature);
276  void userModeChanged(const QString& channel, const QString& nickname,
277  const QList<char> &addedFlags, const QList<char> &removedFlags);
278  void userNetworkJoinDateTime(const QString &nick, const QDateTime &timeOfJoin);
279  void userPartsChannel(const QString& channel, const QString& nickname, const QString& farewellMessage);
280  void userQuitsNetwork(const QString& nickname, const QString& farewellMessage);
281  void whoIsUser(const QString& nickname, const QString& user, const QString& hostName, const QString& realName);
282 
283 };
284 
286 {
287  Q_OBJECT
288 
289  public:
290  IRCNetworkAdapter* pParent;
291 
293  {
294  this->pParent = pParent;
295  }
296 
297  public slots:
298  void connected();
299  void disconnected();
300  void errorReceived(QAbstractSocket::SocketError error);
301  void infoMessage(const QString& message);
302  void hostLookupError(QHostInfo::HostInfoError errorValue);
303 };
304 
305 #endif
Interprets communication between the client and the IRC server.
Allows to perform operation on a list of users.
Definition: ircuserlist.h:42
Parses request and interprets them in a way that emulates mIRC (or any even slightly sane IRC client ...
void openNewAdapter(const QString &recipientName)
Opens a new chat adapter for specified recipient.
void print(const QString &printWhat, const QString &printWhere)
AdapterType adapterType() const
Gets adapter type for this adapter instance.
QString title() const
Gets title for this adapter.
void banUser(const QString &nickname, const QString &reason, const QString &channel)
Bans specified user from a channel.
Provides an unified communication interface between a client and IRC network entities.
void doSendMessage(const QString &message, IRCAdapterBase *pOrigin)
Implemented to support direct communication between client and server.
void setEmitAllIRCMessagesEnabled(bool b)
Struct containing information about client&#39;s connection to the IRC server.
Handles chatting through IRC.
IRCNetworkAdapter * network()
The idea of the adapter system is that each adapter is either a network or is a child of a network...
bool isOperator(const QString &nickname, const QString &channel) const
Checks if user is an operator on a given channel.
AdapterType
Defines all possible types of IRC adapters.
bool amIOperator(const QString &channel) const
Checks if client is an operator on a specified channel.
void detachChatWindow(const IRCChatAdapter *pAdapter)
Detaches the specified IRCChatAdapter instance from this network without deleting it...
const IRCUserPrefix & userPrefixes() const
All allowed modes with their nickname prefixes for this network.
void setChannelMode(const QString &channel, const QString &nickname, const QString &flag, bool bSet)
Sets channel flags.
One-to-one association of visible prefixes to user mode.
Definition: ircuserprefix.h:37
Data structure that describes and defines a connection to an IRC network or server.
void newChatWindowIsOpened(IRCChatAdapter *pWindow)
Signal emitted when a new chat (priv or channel) is opened from this network.
bool isAdapterRelated(const IRCAdapterBase *pAdapter) const
Checks if pAdapter equals this or is one of chat windows of this network.
QString nick
Original nickname. This variable will always store the current nickname of the client.