Communi  3.0.0
A cross-platform IRC framework written with Qt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Macros Groups Pages
ircmessage.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008-2013 The Communi Project
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 */
14 
15 #ifndef IRCMESSAGE_H
16 #define IRCMESSAGE_H
17 
18 #include <Irc>
19 #include <IrcGlobal>
20 #include <QtCore/qobject.h>
21 #include <QtCore/qmetatype.h>
22 #include <QtCore/qdatetime.h>
23 #include <QtCore/qstringlist.h>
24 
25 IRC_BEGIN_NAMESPACE
26 
27 class IrcCommand;
28 class IrcNetwork;
29 class IrcConnection;
30 class IrcMessagePrivate;
31 
32 class IRC_CORE_EXPORT IrcMessage : public QObject
33 {
34  Q_OBJECT
35  Q_PROPERTY(IrcConnection* connection READ connection)
36  Q_PROPERTY(IrcNetwork* network READ network)
37  Q_PROPERTY(Type type READ type)
38  Q_PROPERTY(Flags flags READ flags)
39  Q_PROPERTY(bool valid READ isValid)
40  Q_PROPERTY(QString command READ command)
41  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
42  Q_PROPERTY(QString nick READ nick)
43  Q_PROPERTY(QString ident READ ident)
44  Q_PROPERTY(QString host READ host)
45  Q_PROPERTY(QStringList parameters READ parameters WRITE setParameters)
46  Q_PROPERTY(QDateTime timeStamp READ timeStamp WRITE setTimeStamp)
47  Q_ENUMS(Type Flag)
48  Q_FLAGS(Flags)
49 
50 public:
51  enum Type {
69  Topic
70  };
71 
72  enum Flag {
73  None = 0x0,
74  Own = 0x1,
75  Identified = 0x2,
76  Unidentified = 0x4
77  };
78  Q_DECLARE_FLAGS(Flags, Flag)
79 
80  Q_INVOKABLE explicit IrcMessage(IrcConnection* connection);
81  virtual ~IrcMessage();
82 
83  IrcConnection* connection() const;
84  IrcNetwork* network() const;
85 
86  Type type() const;
87  Flags flags() const;
88 
89  QString command() const;
90  void setCommand(const QString& command);
91 
92  QString prefix() const;
93  void setPrefix(const QString& prefix);
94 
95  QString nick() const;
96  QString ident() const;
97  QString host() const;
98 
99  QStringList parameters() const;
100  void setParameters(const QStringList& parameters);
101 
102  virtual bool isValid() const;
103 
104  QDateTime timeStamp() const;
105  void setTimeStamp(const QDateTime& timeStamp);
106 
107  QByteArray encoding() const;
108  void setEncoding(const QByteArray& encoding);
109 
110  Q_INVOKABLE QByteArray toData() const;
111  Q_INVOKABLE static IrcMessage* fromData(const QByteArray& data, IrcConnection* connection);
112  Q_INVOKABLE static IrcMessage* fromParameters(const QString& prefix, const QString& command, const QStringList& parameters, IrcConnection* connection);
113 
114 protected:
115  QScopedPointer<IrcMessagePrivate> d_ptr;
116  Q_DECLARE_PRIVATE(IrcMessage)
117  Q_DISABLE_COPY(IrcMessage)
118 };
119 
120 Q_DECLARE_OPERATORS_FOR_FLAGS(IrcMessage::Flags)
121 
122 class IRC_CORE_EXPORT IrcCapabilityMessage : public IrcMessage
123 {
124  Q_OBJECT
125  Q_PROPERTY(QString subCommand READ subCommand)
126  Q_PROPERTY(QStringList capabilities READ capabilities)
127 
128 public:
129  Q_INVOKABLE explicit IrcCapabilityMessage(IrcConnection* connection);
130 
131  QString subCommand() const;
132  QStringList capabilities() const;
133 
134  bool isValid() const;
135 
136 private:
137  Q_DISABLE_COPY(IrcCapabilityMessage)
138 };
139 
140 class IRC_CORE_EXPORT IrcErrorMessage : public IrcMessage
141 {
142  Q_OBJECT
143  Q_PROPERTY(QString error READ error)
144 
145 public:
146  Q_INVOKABLE explicit IrcErrorMessage(IrcConnection* connection);
147 
148  QString error() const;
149 
150  bool isValid() const;
151 
152 private:
153  Q_DISABLE_COPY(IrcErrorMessage)
154 };
155 
156 class IRC_CORE_EXPORT IrcInviteMessage : public IrcMessage
157 {
158  Q_OBJECT
159  Q_PROPERTY(QString user READ user)
160  Q_PROPERTY(QString channel READ channel)
161 
162 public:
163  Q_INVOKABLE explicit IrcInviteMessage(IrcConnection* connection);
164 
165  QString user() const;
166  QString channel() const;
167 
168  bool isValid() const;
169 
170 private:
171  Q_DISABLE_COPY(IrcInviteMessage)
172 };
173 
174 class IRC_CORE_EXPORT IrcJoinMessage : public IrcMessage
175 {
176  Q_OBJECT
177  Q_PROPERTY(QString channel READ channel)
178 
179 public:
180  Q_INVOKABLE explicit IrcJoinMessage(IrcConnection* connection);
181 
182  QString channel() const;
183 
184  bool isValid() const;
185 
186 private:
187  Q_DISABLE_COPY(IrcJoinMessage)
188 };
189 
190 class IRC_CORE_EXPORT IrcKickMessage : public IrcMessage
191 {
192  Q_OBJECT
193  Q_PROPERTY(QString channel READ channel)
194  Q_PROPERTY(QString user READ user)
195  Q_PROPERTY(QString reason READ reason)
196 
197 public:
198  Q_INVOKABLE explicit IrcKickMessage(IrcConnection* connection);
199 
200  QString channel() const;
201  QString user() const;
202  QString reason() const;
203 
204  bool isValid() const;
205 
206 private:
207  Q_DISABLE_COPY(IrcKickMessage)
208 };
209 
210 class IRC_CORE_EXPORT IrcModeMessage : public IrcMessage
211 {
212  Q_OBJECT
213  Q_PROPERTY(QString target READ target)
214  Q_PROPERTY(QString mode READ mode)
215  Q_PROPERTY(QString argument READ argument)
216  Q_PROPERTY(bool reply READ isReply)
217  Q_PROPERTY(Kind kind READ kind)
218  Q_ENUMS(Kind)
219 
220 public:
221  Q_INVOKABLE explicit IrcModeMessage(IrcConnection* connection);
222 
223  QString target() const;
224  QString mode() const;
225  QString argument() const;
226  bool isReply() const;
227 
228  enum Kind { Channel, User };
229  Kind kind() const;
230 
231  bool isValid() const;
232 
233 private:
234  Q_DISABLE_COPY(IrcModeMessage)
235 };
236 
237 class IRC_CORE_EXPORT IrcMotdMessage : public IrcMessage
238 {
239  Q_OBJECT
240  Q_PROPERTY(QStringList lines READ lines)
241 
242 public:
243  Q_INVOKABLE explicit IrcMotdMessage(IrcConnection* connection);
244 
245  QStringList lines() const;
246 
247  bool isValid() const;
248 
249 private:
250  Q_DISABLE_COPY(IrcMotdMessage)
251 };
252 
253 class IRC_CORE_EXPORT IrcNamesMessage : public IrcMessage
254 {
255  Q_OBJECT
256  Q_PROPERTY(QString channel READ channel)
257  Q_PROPERTY(QStringList names READ names)
258 
259 public:
260  Q_INVOKABLE explicit IrcNamesMessage(IrcConnection* connection);
261 
262  QString channel() const;
263  QStringList names() const;
264 
265  bool isValid() const;
266 
267 private:
268  Q_DISABLE_COPY(IrcNamesMessage)
269 };
270 
271 class IRC_CORE_EXPORT IrcNickMessage : public IrcMessage
272 {
273  Q_OBJECT
274  Q_PROPERTY(QString oldNick READ oldNick)
275  Q_PROPERTY(QString newNick READ newNick)
276 
277 public:
278  Q_INVOKABLE explicit IrcNickMessage(IrcConnection* connection);
279 
280  QString oldNick() const;
281  QString newNick() const;
282 
283  bool isValid() const;
284 
285 private:
286  Q_DISABLE_COPY(IrcNickMessage)
287 };
288 
289 class IRC_CORE_EXPORT IrcNoticeMessage : public IrcMessage
290 {
291  Q_OBJECT
292  Q_PROPERTY(QString target READ target)
293  Q_PROPERTY(QString content READ content)
294  Q_PROPERTY(bool private READ isPrivate)
295  Q_PROPERTY(bool reply READ isReply)
296 
297 public:
298  Q_INVOKABLE explicit IrcNoticeMessage(IrcConnection* connection);
299 
300  QString target() const;
301  QString content() const;
302  bool isPrivate() const;
303  bool isReply() const;
304 
305  bool isValid() const;
306 
307 private:
308  Q_DISABLE_COPY(IrcNoticeMessage)
309 };
310 
311 class IRC_CORE_EXPORT IrcNumericMessage : public IrcMessage
312 {
313  Q_OBJECT
314  Q_PROPERTY(int code READ code)
315 
316 public:
317  Q_INVOKABLE explicit IrcNumericMessage(IrcConnection* connection);
318 
319  int code() const;
320 
321  bool isValid() const;
322 
323 private:
324  Q_DISABLE_COPY(IrcNumericMessage)
325 };
326 
327 class IRC_CORE_EXPORT IrcPartMessage : public IrcMessage
328 {
329  Q_OBJECT
330  Q_PROPERTY(QString channel READ channel)
331  Q_PROPERTY(QString reason READ reason)
332 
333 public:
334  Q_INVOKABLE explicit IrcPartMessage(IrcConnection* connection);
335 
336  QString channel() const;
337  QString reason() const;
338 
339  bool isValid() const;
340 
341 private:
342  Q_DISABLE_COPY(IrcPartMessage)
343 };
344 
345 class IRC_CORE_EXPORT IrcPingMessage : public IrcMessage
346 {
347  Q_OBJECT
348  Q_PROPERTY(QString argument READ argument)
349 
350 public:
351  Q_INVOKABLE explicit IrcPingMessage(IrcConnection* connection);
352 
353  QString argument() const;
354 
355  bool isValid() const;
356 
357 private:
358  Q_DISABLE_COPY(IrcPingMessage)
359 };
360 
361 class IRC_CORE_EXPORT IrcPongMessage : public IrcMessage
362 {
363  Q_OBJECT
364  Q_PROPERTY(QString argument READ argument)
365 
366 public:
367  Q_INVOKABLE explicit IrcPongMessage(IrcConnection* connection);
368 
369  QString argument() const;
370 
371  bool isValid() const;
372 
373 private:
374  Q_DISABLE_COPY(IrcPongMessage)
375 };
376 
377 class IRC_CORE_EXPORT IrcPrivateMessage : public IrcMessage
378 {
379  Q_OBJECT
380  Q_PROPERTY(QString target READ target)
381  Q_PROPERTY(QString content READ content)
382  Q_PROPERTY(bool private READ isPrivate)
383  Q_PROPERTY(bool action READ isAction)
384  Q_PROPERTY(bool request READ isRequest)
385 
386 public:
387  Q_INVOKABLE explicit IrcPrivateMessage(IrcConnection* connection);
388 
389  QString target() const;
390  QString content() const;
391  bool isPrivate() const;
392  bool isAction() const;
393  bool isRequest() const;
394 
395  bool isValid() const;
396 
397 private:
398  Q_DISABLE_COPY(IrcPrivateMessage)
399 };
400 
401 class IRC_CORE_EXPORT IrcQuitMessage : public IrcMessage
402 {
403  Q_OBJECT
404  Q_PROPERTY(QString reason READ reason)
405 
406 public:
407  Q_INVOKABLE explicit IrcQuitMessage(IrcConnection* connection);
408 
409  QString reason() const;
410 
411  bool isValid() const;
412 
413 private:
414  Q_DISABLE_COPY(IrcQuitMessage)
415 };
416 
417 class IRC_CORE_EXPORT IrcTopicMessage : public IrcMessage
418 {
419  Q_OBJECT
420  Q_PROPERTY(QString channel READ channel)
421  Q_PROPERTY(QString topic READ topic)
422  Q_PROPERTY(bool reply READ isReply)
423 
424 public:
425  Q_INVOKABLE explicit IrcTopicMessage(IrcConnection* connection);
426 
427  QString channel() const;
428  QString topic() const;
429  bool isReply() const;
430 
431  bool isValid() const;
432 
433 private:
434  Q_DISABLE_COPY(IrcTopicMessage)
435 };
436 
437 #ifndef QT_NO_DEBUG_STREAM
438 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Type type);
439 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Flag flag);
440 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Flags flags);
441 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcModeMessage::Kind kind);
442 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, const IrcMessage* message);
443 #endif // QT_NO_DEBUG_STREAM
444 
445 IRC_END_NAMESPACE
446 
447 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMessage::Type))
448 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMessage*))
449 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCapabilityMessage*))
450 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcErrorMessage*))
451 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcInviteMessage*))
452 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcJoinMessage*))
453 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcKickMessage*))
454 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcModeMessage*))
455 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMotdMessage*))
456 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNamesMessage*))
457 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNickMessage*))
458 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNoticeMessage*))
459 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNumericMessage*))
460 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPartMessage*))
461 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPingMessage*))
462 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPongMessage*))
463 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPrivateMessage*))
464 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcQuitMessage*))
465 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcTopicMessage*))
466 
467 #endif // IRCMESSAGE_H
A notice message (IrcNoticeMessage).
Definition: ircmessage.h:62
A ping message (IrcPingMessage).
Definition: ircmessage.h:65
A nick message (IrcNickMessage).
Definition: ircmessage.h:61
Represents a join message.
Definition: ircmessage.h:174
An error message (IrcErrorMessage).
Definition: ircmessage.h:54
Provides the most common commands.
Definition: irccommand.h:29
Represents a kick message.
Definition: ircmessage.h:190
Represents a part message.
Definition: ircmessage.h:327
A join message (IrcJoinMessage).
Definition: ircmessage.h:56
Represents a notice message.
Definition: ircmessage.h:289
Represents a names list message.
Definition: ircmessage.h:253
A pong message (IrcPongMessage).
Definition: ircmessage.h:66
A private message (IrcPrivateMessage).
Definition: ircmessage.h:67
A part message (IrcPartMessage).
Definition: ircmessage.h:64
Represents a capability message.
Definition: ircmessage.h:122
A names message (IrcNamesMessage).
Definition: ircmessage.h:60
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:32
A quit message (IrcQuitMessage).
Definition: ircmessage.h:68
Represents a mode message.
Definition: ircmessage.h:210
Represents a ping message.
Definition: ircmessage.h:345
Represents a quit message.
Definition: ircmessage.h:401
The base class of all messages.
Definition: ircmessage.h:32
Represents a pong message.
Definition: ircmessage.h:361
Represents a numeric message.
Definition: ircmessage.h:311
Represents an error message.
Definition: ircmessage.h:140
A capability message (IrcCapabilityMessage).
Definition: ircmessage.h:53
A mode message (IrcModeMessage).
Definition: ircmessage.h:58
Represents a private message.
Definition: ircmessage.h:377
Represents a message of the day.
Definition: ircmessage.h:237
Kind
Definition: ircmessage.h:228
Represents a nick message.
Definition: ircmessage.h:271
Represents a topic message.
Definition: ircmessage.h:417
An invite message (IrcInviteMessage).
Definition: ircmessage.h:55
Flag
Definition: ircmessage.h:72
Represents an invite message.
Definition: ircmessage.h:156
A numeric message (IrcNumericMessage).
Definition: ircmessage.h:63
An unknown message (IrcMessage).
Definition: ircmessage.h:52
Provides network information and capability management.
Definition: ircnetwork.h:29
A kick message (IrcKickMessage).
Definition: ircmessage.h:57
A message of the day (IrcMotdMessage).
Definition: ircmessage.h:59
Type
Definition: ircmessage.h:51