ircresponseparser.h
1 //------------------------------------------------------------------------------
2 // ircresponseparser.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 __IRCRESPONSEPARSER_H__
24 #define __IRCRESPONSEPARSER_H__
25 
26 #include "dptr.h"
27 #include "irc/entities/ircresponseparseresult.h"
28 
29 #include <QDateTime>
30 #include <QObject>
31 #include <QString>
32 
33 class IRCMessageClass;
34 class IRCNetworkAdapter;
35 
36 class IRCResponseParser : public QObject
37 {
38  Q_OBJECT
39 
40 public:
42  ~IRCResponseParser() override;
43 
54  IRCResponseParseResult parse(const QString &message);
55 
56 signals:
63  void helloClient(const QString &nickname);
64 
65  void kick(const QString &channel, const QString &byWhom, const QString &whoIsKicked, const QString &reason);
66  void kill(const QString &victim, const QString &comment);
67 
68  void iSupportReceived(const QString &line);
69 
73  void modeInfo(const QString &channel, const QString &whoSetThis, const QString &modeParams);
74  void namesListReceived(const QString &channel, const QStringList &names);
75  void namesListEndReceived(const QString &channel);
76  void nicknameInUse(const QString &nickname);
77  void noSuchNickname(const QString &nickname);
78  void parseError(const QString &error);
79 
90  void print(const QString &printWhat, const QString &printWhere);
94  void printWithClass(const QString &printWhat, const QString &printWhere, const IRCMessageClass &msgClass);
95  void printToNetworksCurrentChatBox(const QString &printWhat, const IRCMessageClass &msgClass);
96 
97  void privMsgReceived(const QString &recipient, const QString &sender, const QString &content);
102  void privMsgLiteralReceived(const QString &recipient, const QString &content, const IRCMessageClass &msgClass);
103  void sendPongMessage(const QString &sendWhere);
104  void userChangesNickname(const QString &oldNickname, const QString &newNickname);
105  void userIdleTime(const QString &nick, int secondsIdle);
106  void userJoinsChannel(const QString &channel, const QString &nickname, const QString &fullSignature);
107  void userNetworkJoinDateTime(const QString &nick, const QDateTime &timeOfJoin);
108  void userModeChanged(const QString &channel, const QString &nickname,
109  const QList<char> &flagsAdded, const QList<char> &flagsRemoved);
110  void userPartsChannel(const QString &channel, const QString &nickname, const QString &farewellMessage);
111  void userQuitsNetwork(const QString &nickname, const QString &farewellMessage);
112 
116  void whoIsUser(const QString &nickname, const QString &user, const QString &hostName, const QString &realName);
117 
118 private:
119  enum FlagModes
120  {
121  FlagModeAdd,
122  FlagModeRemove,
123  FlagModeError
124  };
125 
127 
128  bool isPrefixIgnored() const;
129  QString joinAndTrimColonIfNecessary(const QStringList &strList) const;
130 
135  FlagModes getFlagMode(char c);
136 
137  IRCResponseParseResult parseMessage();
138 
139  void parsePrivMsgOrNotice();
146  void parseUserModeMessage(const QString &channel, QString flagsString, QStringList &nicknames);
147 
148  QString &trimColonIfNecessary(QString &str) const;
149 };
150 
151 #endif