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:
52  ~IRCNetworkAdapter() override;
53 
54  AdapterType adapterType() const override
55  {
56  return NetworkAdapter;
57  }
58 
62  bool amIOperator(const QString &channel) const
63  {
64  return this->isOperator(this->myNickname(), channel);
65  }
66 
87  void banUser(const QString &nickname, const QString &reason, const QString &channel);
88 
89  QList<IRCAdapterBase *> childrenAdapters();
90  void connect();
91  const IRCNetworkConnectionInfo &connection() const
92  {
93  return this->connectionInfo;
94  }
95 
100  void detachChatWindow(const IRCChatAdapter *pAdapter);
101 
102  void disconnect(const QString &farewellMessage);
103 
122  void doSendMessage(const QString &message, IRCAdapterBase *pOrigin) override;
123 
124  bool hasRecipient(const QString &recipient) const;
125 
126  const PatternList &ignoredUsersPatterns() const;
127 
132  bool isAdapterRelated(const IRCAdapterBase *pAdapter) const;
133  bool isConnected() const
134  {
135  return ircClient.isConnected();
136  }
137  bool isMyNickname(const QString &nickname) const;
138 
147  bool isOperator(const QString &nickname, const QString &channel) const;
148 
149  void killAllChatWindows();
150 
151  const QString &myNickname() const
152  {
153  return connectionInfo.nick;
154  }
155 
157  {
158  return this;
159  }
160 
161  IRCResponseParser *responseParser()
162  {
163  return ircResponseParser;
164  }
165 
174  void setChannelMode(const QString &channel, const QString &nickname, const QString &flag, bool bSet);
175 
176  void sendCtcp(const QString &nickname, const QString &command);
177 
182  {
183  this->bEmitAllIRCMessages = b;
184  }
185 
186  void setNetworkEntity(const IRCNetworkEntity &network);
187 
188  QString title() const override;
189 
194  const IRCUserPrefix &userPrefixes() const;
195 
196 public slots:
208  void openNewAdapter(const QString &recipientName);
209 
210  void printMsgLiteral(const QString &recipient, const QString &content,
211  const IRCMessageClass &msgClass);
215  void print(const QString &printWhat, const QString &printWhere);
216  void printWithClass(const QString &printWhat, const QString &printWhere, const IRCMessageClass &msgClass);
217  void printToCurrentChatBox(const QString &printWhat, const IRCMessageClass &msgClass);
218  void reloadNetworkEntityFromConfig();
219  void userPing(const QString &nickname, qint64 ping);
220 
221 signals:
226  void newChatWindowIsOpened(IRCChatAdapter *pWindow);
227 
228 private:
235  bool bIsJoining;
236 
246  bool bEmitAllIRCMessages;
247 
256  QHash<QString, IRCChatAdapter *> chatWindows;
257  IRCNetworkConnectionInfo connectionInfo;
258  IRCClient ircClient;
259  IRCRequestParser ircRequestParser;
260  IRCResponseParser *ircResponseParser;
261  IRCISupportParser *ircISupportParser;
262  IRCSocketSignalsAdapter *pIrcSocketSignalsAdapter;
263 
267  IRCChatAdapter *getChatAdapter(const QString &recipient);
268  const IRCChatAdapter *getChatAdapter(const QString &recipient) const;
269 
279  IRCChatAdapter *getOrCreateNewChatAdapter(const QString &recipient);
280 
281  void killChatWindow(const QString &recipient);
282 
283 private slots:
284  void appendISupportLine(const QString &line);
285  void echoPrivmsg(const QString &recipient, const QString &content);
286  void helloClient(const QString &nickname);
287  void kick(const QString &channel, const QString &byWhom, const QString &whoIsKicked, const QString &reason);
288  void kill(const QString &victim, const QString &comment);
289  void ircServerResponse(const QString &message);
290  void modeInfo(const QString &channel, const QString &whoSetThis, const QString &modeParams);
291  void namesListReceived(const QString &channel, const QStringList &names);
292  void namesListEndReceived(const QString &channel);
293  void nicknameInUse(const QString &nickname);
294  void noSuchNickname(const QString &nickname);
295  void parseError(const QString &error);
296 
297  void privMsgReceived(const QString &recipient, const QString &sender, const QString &content);
298  void sendPong(const QString &toWhom);
299  void userChangesNickname(const QString &oldNickname, const QString &newNickname);
300  void userIdleTime(const QString &nick, int secondsIdle);
301  void userJoinsChannel(const QString &channel, const QString &nickname, const QString &fullSignature);
302  void userModeChanged(const QString &channel, const QString &nickname,
303  const QList<char> &addedFlags, const QList<char> &removedFlags);
304  void userNetworkJoinDateTime(const QString &nick, const QDateTime &timeOfJoin);
305  void userPartsChannel(const QString &channel, const QString &nickname, const QString &farewellMessage);
306  void userQuitsNetwork(const QString &nickname, const QString &farewellMessage);
307  void whoIsUser(const QString &nickname, const QString &user, const QString &hostName, const QString &realName);
308 };
309 
311 {
312  Q_OBJECT
313 
314 public:
315  IRCNetworkAdapter *pParent;
316 
318  {
319  this->pParent = pParent;
320  }
321 
322 public slots:
323  void connected() override;
324  void disconnected() override;
325  void errorReceived(QAbstractSocket::SocketError error) override;
326  void infoMessage(const QString &message);
327 };
328 
329 #endif