ircnetworkadapter.h
1 //------------------------------------------------------------------------------
2 // ircnetworkadapter.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __IRCNETWORKADAPTER_H__
24 #define __IRCNETWORKADAPTER_H__
25 
26 #include "irc/ircadapterbase.h"
27 #include "irc/ircclient.h"
28 #include "irc/ircnetworkconnectioninfo.h"
29 #include "irc/ircrequestparser.h"
30 #include "socketsignalsadapter.h"
31 
32 #include <QHash>
33 
34 class IRCChatAdapter;
35 class IRCISupportParser;
36 class IRCResponseParser;
38 class IRCUserList;
39 class IRCUserPrefix;
40 
45 {
46  Q_OBJECT
47 
48  friend class IRCSocketSignalsAdapter;
49 
50  public:
53 
54  AdapterType adapterType() const { return NetworkAdapter; }
55 
59  bool amIOperator(const QString& channel) const
60  {
61  return this->isOperator(this->myNickname(), channel);
62  }
63 
84  void banUser(const QString& nickname, const QString& reason, const QString& channel);
85 
86  QList<IRCAdapterBase*> childrenAdapters();
87  void connect();
88  const IRCNetworkConnectionInfo &connection() const
89  {
90  return this->connectionInfo;
91  }
92 
97  void detachChatWindow(const IRCChatAdapter* pAdapter);
98 
99  void disconnect(const QString& farewellMessage);
100 
119  void doSendMessage(const QString& message, IRCAdapterBase* pOrigin);
120 
121  bool hasRecipient(const QString& recipient) const;
122 
123  const PatternList &ignoredUsersPatterns() const;
124 
129  bool isAdapterRelated(const IRCAdapterBase* pAdapter) const;
130  bool isConnected() const { return ircClient.isConnected(); }
131  bool isMyNickname(const QString& nickname) const;
132 
141  bool isOperator(const QString& nickname, const QString& channel) const;
142 
143  void killAllChatWindows();
144 
145  const QString& myNickname() const { return connectionInfo.nick; }
146 
148  {
149  return this;
150  }
151 
152  IRCResponseParser *responseParser()
153  {
154  return ircResponseParser;
155  }
156 
165  void setChannelMode(const QString& channel, const QString& nickname, const QString& flag, bool bSet);
166 
167  void sendCtcp(const QString &nickname, const QString &command);
168 
173  {
174  this->bEmitAllIRCMessages = b;
175  }
176 
177  void setNetworkEntity(const IRCNetworkEntity &network);
178 
179  QString title() const;
180 
185  const IRCUserPrefix &userPrefixes() const;
186 
187  public slots:
199  void openNewAdapter(const QString& recipientName);
200 
201  void printMsgLiteral(const QString& recipient, const QString& content,
202  const IRCMessageClass& msgClass);
206  void print(const QString& printWhat, const QString& printWhere);
207  void printWithClass(const QString& printWhat, const QString& printWhere, const IRCMessageClass& msgClass);
208  void printToCurrentChatBox(const QString& printWhat, const IRCMessageClass& msgClass);
209  void reloadNetworkEntityFromConfig();
210  void userPing(const QString &nickname, qint64 ping);
211 
212  signals:
217  void newChatWindowIsOpened(IRCChatAdapter* pWindow);
218 
219  private:
226  bool bIsJoining;
227 
237  bool bEmitAllIRCMessages;
238 
247  QHash<QString, IRCChatAdapter*> chatWindows;
248  IRCNetworkConnectionInfo connectionInfo;
249  IRCClient ircClient;
250  IRCRequestParser ircRequestParser;
251  IRCResponseParser* ircResponseParser;
252  IRCISupportParser* ircISupportParser;
253  IRCSocketSignalsAdapter* pIrcSocketSignalsAdapter;
254 
258  IRCChatAdapter* getChatAdapter(const QString& recipient);
259  const IRCChatAdapter* getChatAdapter(const QString& recipient) const;
260 
270  IRCChatAdapter* getOrCreateNewChatAdapter(const QString& recipient);
271 
272  void killChatWindow(const QString& recipient);
273 
274  private slots:
275  void appendISupportLine(const QString &line);
276  void echoPrivmsg(const QString& recipient, const QString& content);
277  void helloClient(const QString& nickname);
278  void kick(const QString& channel, const QString& byWhom, const QString& whoIsKicked, const QString& reason);
279  void kill(const QString& victim, const QString& comment);
280  void ircServerResponse(const QString& message);
281  void modeInfo(const QString& channel, const QString& whoSetThis, const QString& modeParams);
282  void namesListReceived(const QString& channel, const QStringList& names);
283  void namesListEndReceived(const QString& channel);
284  void nicknameInUse(const QString& nickname);
285  void noSuchNickname(const QString& nickname);
286  void parseError(const QString& error);
287 
288  void privMsgReceived(const QString& recipient, const QString& sender, const QString& content);
289  void sendPong(const QString& toWhom);
290  void userChangesNickname(const QString& oldNickname, const QString& newNickname);
291  void userIdleTime(const QString &nick, int secondsIdle);
292  void userJoinsChannel(const QString& channel, const QString& nickname, const QString& fullSignature);
293  void userModeChanged(const QString& channel, const QString& nickname,
294  const QList<char> &addedFlags, const QList<char> &removedFlags);
295  void userNetworkJoinDateTime(const QString &nick, const QDateTime &timeOfJoin);
296  void userPartsChannel(const QString& channel, const QString& nickname, const QString& farewellMessage);
297  void userQuitsNetwork(const QString& nickname, const QString& farewellMessage);
298  void whoIsUser(const QString& nickname, const QString& user, const QString& hostName, const QString& realName);
299 
300 };
301 
303 {
304  Q_OBJECT
305 
306  public:
307  IRCNetworkAdapter* pParent;
308 
310  {
311  this->pParent = pParent;
312  }
313 
314  public slots:
315  void connected();
316  void disconnected();
317  void errorReceived(QAbstractSocket::SocketError error);
318  void infoMessage(const QString& message);
319 };
320 
321 #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)
QString nick
Original nickname. This variable will always store the current nickname of the client.
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.