ircresponsetype.h
1 //------------------------------------------------------------------------------
2 // ircresponsetype.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) 2011 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __IRCRESPONSETYPE_H__
24 #define __IRCRESPONSETYPE_H__
25 
26 #include <QString>
27 
34 {
35 public:
42  enum MsgType
43  {
44  // === IMPORTANT!!! ===
45  // Remember to fix toRfcString() if values here change!
46  // Also IRCResponseParser::parseMessage() must be
47  // fixed.
48 
56  Invalid = 0,
57 
65 
66  // === Here are types with no text representation ===
67 
72 
79 
82 
85 
88 
91 
97 
105 
108 
111 
114 
117 
120 
123 
133 
136 
139 
142 
145 
148 
151 
154 
157 
160 
163 
166 
169 
172 
175 
176  // === Here are errors with no text representation ===
177 
180 
183 
188 
189  ERRChannelIsFull, // 471
190  ERRInviteOnlyChan, // 473
191  ERRBannedFromChan, // 474
192  ERRBadChannelKey, // 475
193  ERRBadChannelMask, // 476
194  ERRNoChanModes, // 477
195 
198 
201 
202  // === Here are types which convert to their string counterparts
203  // === letter-by-letter
204 
205  Join,
206  Kick,
207  Kill,
208  Mode,
209  Nick,
210  Notice,
211  Part,
212  Ping,
213  PrivMsg,
214  Quit,
215  Topic,
216 
219  };
220 
229  static IRCResponseType fromIntegerResponseValue(int responseType);
230 
246  static int toRfcNumber(MsgType type);
247 
256  static QString toRfcString(MsgType type);
257 
264  static MsgType typeFromRfcString(const QString &typeRepresentation);
265 
269  IRCResponseType();
270 
274  IRCResponseType(MsgType type);
275 
280  IRCResponseType(const QString &typeRepresentation);
281 
287  bool isCommandResponse() const
288  {
289  return d.numericType >= 200 && d.numericType <= 399;
290  }
291 
297  bool isErrorMessage() const
298  {
299  return d.numericType >= 400;
300  }
301 
305  bool isValid() const
306  {
307  return d.type != Invalid;
308  }
309 
310  bool operator==(const IRCResponseType &other) const;
311  bool operator!=(const IRCResponseType &other) const;
312 
320  int numericType() const
321  {
322  return d.numericType;
323  }
324 
330  QString toRfcString() const
331  {
332  return toRfcString(d.type);
333  }
334 
335  MsgType type() const
336  {
337  return d.type;
338  }
339 
340 private:
341  class PrivData
342  {
343  public:
348  int numericType;
349  MsgType type;
350  };
351 
352  PrivData d;
353 };
354 
355 #endif