Communi  3.2.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-2014 The Communi Project
3 
4  You may use this file under the terms of BSD license as follows:
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the names of its
14  contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef IRCMESSAGE_H
30 #define IRCMESSAGE_H
31 
32 #include <Irc>
33 #include <IrcGlobal>
34 #include <QtCore/qobject.h>
35 #include <QtCore/qvariant.h>
36 #include <QtCore/qmetatype.h>
37 #include <QtCore/qdatetime.h>
38 #include <QtCore/qstringlist.h>
39 
40 IRC_BEGIN_NAMESPACE
41 
42 class IrcCommand;
43 class IrcNetwork;
44 class IrcConnection;
45 class IrcMessagePrivate;
46 
47 class IRC_CORE_EXPORT IrcMessage : public QObject
48 {
49  Q_OBJECT
50  Q_PROPERTY(IrcConnection* connection READ connection)
51  Q_PROPERTY(IrcNetwork* network READ network)
52  Q_PROPERTY(Type type READ type)
53  Q_PROPERTY(bool own READ isOwn)
54  Q_PROPERTY(Flags flags READ flags)
55  Q_PROPERTY(bool valid READ isValid)
56  Q_PROPERTY(QString command READ command)
57  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
58  Q_PROPERTY(QString nick READ nick)
59  Q_PROPERTY(QString ident READ ident)
60  Q_PROPERTY(QString host READ host)
61  Q_PROPERTY(QStringList parameters READ parameters WRITE setParameters)
62  Q_PROPERTY(QDateTime timeStamp READ timeStamp WRITE setTimeStamp)
63  Q_PROPERTY(QVariantMap tags READ tags WRITE setTags)
64  Q_ENUMS(Type Flag)
65  Q_FLAGS(Flags)
66 
67 public:
68  enum Type {
87  WhoReply
88  };
89 
90  enum Flag {
91  None = 0x0,
92  Own = 0x1,
93  Identified = 0x2,
94  Unidentified = 0x4,
95  Playback = 0x8
96  };
97  Q_DECLARE_FLAGS(Flags, Flag)
98 
99  Q_INVOKABLE explicit IrcMessage(IrcConnection* connection);
100  virtual ~IrcMessage();
101 
102  IrcConnection* connection() const;
103  IrcNetwork* network() const;
104 
105  Type type() const;
106  bool isOwn() const;
107 
108  Flags flags() const;
109  void setFlags(Flags flags);
110 
111  QString command() const;
112  void setCommand(const QString& command);
113 
114  QString prefix() const;
115  void setPrefix(const QString& prefix);
116 
117  QString nick() const;
118  QString ident() const;
119  QString host() const;
120 
121  QStringList parameters() const;
122  void setParameters(const QStringList& parameters);
123 
124  virtual bool isValid() const;
125 
126  QDateTime timeStamp() const;
127  void setTimeStamp(const QDateTime& timeStamp);
128 
129  QByteArray encoding() const;
130  void setEncoding(const QByteArray& encoding);
131 
132  QVariantMap tags() const;
133  void setTags(const QVariantMap& tags);
134 
135  Q_INVOKABLE QByteArray toData() const;
136  Q_INVOKABLE static IrcMessage* fromData(const QByteArray& data, IrcConnection* connection);
137  Q_INVOKABLE static IrcMessage* fromParameters(const QString& prefix, const QString& command, const QStringList& parameters, IrcConnection* connection);
138 
139 protected:
140  QScopedPointer<IrcMessagePrivate> d_ptr;
141  Q_DECLARE_PRIVATE(IrcMessage)
142  Q_DISABLE_COPY(IrcMessage)
143 };
144 
145 Q_DECLARE_OPERATORS_FOR_FLAGS(IrcMessage::Flags)
146 
147 class IRC_CORE_EXPORT IrcCapabilityMessage : public IrcMessage
148 {
149  Q_OBJECT
150  Q_PROPERTY(QString subCommand READ subCommand)
151  Q_PROPERTY(QStringList capabilities READ capabilities)
152 
153 public:
154  Q_INVOKABLE explicit IrcCapabilityMessage(IrcConnection* connection);
155 
156  QString subCommand() const;
157  QStringList capabilities() const;
158 
159  bool isValid() const;
160 
161 private:
162  Q_DISABLE_COPY(IrcCapabilityMessage)
163 };
164 
165 class IRC_CORE_EXPORT IrcErrorMessage : public IrcMessage
166 {
167  Q_OBJECT
168  Q_PROPERTY(QString error READ error)
169 
170 public:
171  Q_INVOKABLE explicit IrcErrorMessage(IrcConnection* connection);
172 
173  QString error() const;
174 
175  bool isValid() const;
176 
177 private:
178  Q_DISABLE_COPY(IrcErrorMessage)
179 };
180 
181 class IRC_CORE_EXPORT IrcInviteMessage : public IrcMessage
182 {
183  Q_OBJECT
184  Q_PROPERTY(QString user READ user)
185  Q_PROPERTY(QString channel READ channel)
186 
187 public:
188  Q_INVOKABLE explicit IrcInviteMessage(IrcConnection* connection);
189 
190  QString user() const;
191  QString channel() const;
192 
193  bool isValid() const;
194 
195 private:
196  Q_DISABLE_COPY(IrcInviteMessage)
197 };
198 
199 class IRC_CORE_EXPORT IrcJoinMessage : public IrcMessage
200 {
201  Q_OBJECT
202  Q_PROPERTY(QString channel READ channel)
203 
204 public:
205  Q_INVOKABLE explicit IrcJoinMessage(IrcConnection* connection);
206 
207  QString channel() const;
208 
209  bool isValid() const;
210 
211 private:
212  Q_DISABLE_COPY(IrcJoinMessage)
213 };
214 
215 class IRC_CORE_EXPORT IrcKickMessage : public IrcMessage
216 {
217  Q_OBJECT
218  Q_PROPERTY(QString channel READ channel)
219  Q_PROPERTY(QString user READ user)
220  Q_PROPERTY(QString reason READ reason)
221 
222 public:
223  Q_INVOKABLE explicit IrcKickMessage(IrcConnection* connection);
224 
225  QString channel() const;
226  QString user() const;
227  QString reason() const;
228 
229  bool isValid() const;
230 
231 private:
232  Q_DISABLE_COPY(IrcKickMessage)
233 };
234 
235 class IRC_CORE_EXPORT IrcModeMessage : public IrcMessage
236 {
237  Q_OBJECT
238  Q_PROPERTY(QString target READ target)
239  Q_PROPERTY(QString mode READ mode)
240  Q_PROPERTY(QString argument READ argument)
241  Q_PROPERTY(QStringList arguments READ arguments)
242  Q_PROPERTY(bool reply READ isReply)
243  Q_PROPERTY(Kind kind READ kind)
244  Q_ENUMS(Kind)
245 
246 public:
247  Q_INVOKABLE explicit IrcModeMessage(IrcConnection* connection);
248 
249  QString target() const;
250  QString mode() const;
251  QString argument() const;
252  QStringList arguments() const;
253  bool isReply() const;
254 
255  enum Kind { Channel, User };
256  Kind kind() const;
257 
258  bool isValid() const;
259 
260 private:
261  Q_DISABLE_COPY(IrcModeMessage)
262 };
263 
264 class IRC_CORE_EXPORT IrcMotdMessage : public IrcMessage
265 {
266  Q_OBJECT
267  Q_PROPERTY(QStringList lines READ lines)
268 
269 public:
270  Q_INVOKABLE explicit IrcMotdMessage(IrcConnection* connection);
271 
272  QStringList lines() const;
273 
274  bool isValid() const;
275 
276 private:
277  Q_DISABLE_COPY(IrcMotdMessage)
278 };
279 
280 class IRC_CORE_EXPORT IrcNamesMessage : public IrcMessage
281 {
282  Q_OBJECT
283  Q_PROPERTY(QString channel READ channel)
284  Q_PROPERTY(QStringList names READ names)
285 
286 public:
287  Q_INVOKABLE explicit IrcNamesMessage(IrcConnection* connection);
288 
289  QString channel() const;
290  QStringList names() const;
291 
292  bool isValid() const;
293 
294 private:
295  Q_DISABLE_COPY(IrcNamesMessage)
296 };
297 
298 class IRC_CORE_EXPORT IrcNickMessage : public IrcMessage
299 {
300  Q_OBJECT
301  Q_PROPERTY(QString oldNick READ oldNick)
302  Q_PROPERTY(QString newNick READ newNick)
303 
304 public:
305  Q_INVOKABLE explicit IrcNickMessage(IrcConnection* connection);
306 
307  QString oldNick() const;
308  QString newNick() const;
309 
310  bool isValid() const;
311 
312 private:
313  Q_DISABLE_COPY(IrcNickMessage)
314 };
315 
316 class IRC_CORE_EXPORT IrcNoticeMessage : public IrcMessage
317 {
318  Q_OBJECT
319  Q_PROPERTY(QString target READ target)
320  Q_PROPERTY(QString content READ content)
321  Q_PROPERTY(bool private READ isPrivate)
322  Q_PROPERTY(bool reply READ isReply)
323 
324 public:
325  Q_INVOKABLE explicit IrcNoticeMessage(IrcConnection* connection);
326 
327  QString target() const;
328  QString content() const;
329  bool isPrivate() const;
330  bool isReply() const;
331 
332  bool isValid() const;
333 
334 private:
335  Q_DISABLE_COPY(IrcNoticeMessage)
336 };
337 
338 class IRC_CORE_EXPORT IrcNumericMessage : public IrcMessage
339 {
340  Q_OBJECT
341  Q_PROPERTY(int code READ code)
342 
343 public:
344  Q_INVOKABLE explicit IrcNumericMessage(IrcConnection* connection);
345 
346  int code() const;
347 
348  bool isValid() const;
349 
350 private:
351  Q_DISABLE_COPY(IrcNumericMessage)
352 };
353 
354 class IRC_CORE_EXPORT IrcPartMessage : public IrcMessage
355 {
356  Q_OBJECT
357  Q_PROPERTY(QString channel READ channel)
358  Q_PROPERTY(QString reason READ reason)
359 
360 public:
361  Q_INVOKABLE explicit IrcPartMessage(IrcConnection* connection);
362 
363  QString channel() const;
364  QString reason() const;
365 
366  bool isValid() const;
367 
368 private:
369  Q_DISABLE_COPY(IrcPartMessage)
370 };
371 
372 class IRC_CORE_EXPORT IrcPingMessage : public IrcMessage
373 {
374  Q_OBJECT
375  Q_PROPERTY(QString argument READ argument)
376 
377 public:
378  Q_INVOKABLE explicit IrcPingMessage(IrcConnection* connection);
379 
380  QString argument() const;
381 
382  bool isValid() const;
383 
384 private:
385  Q_DISABLE_COPY(IrcPingMessage)
386 };
387 
388 class IRC_CORE_EXPORT IrcPongMessage : public IrcMessage
389 {
390  Q_OBJECT
391  Q_PROPERTY(QString argument READ argument)
392 
393 public:
394  Q_INVOKABLE explicit IrcPongMessage(IrcConnection* connection);
395 
396  QString argument() const;
397 
398  bool isValid() const;
399 
400 private:
401  Q_DISABLE_COPY(IrcPongMessage)
402 };
403 
404 class IRC_CORE_EXPORT IrcPrivateMessage : public IrcMessage
405 {
406  Q_OBJECT
407  Q_PROPERTY(QString target READ target)
408  Q_PROPERTY(QString content READ content)
409  Q_PROPERTY(bool private READ isPrivate)
410  Q_PROPERTY(bool action READ isAction)
411  Q_PROPERTY(bool request READ isRequest)
412 
413 public:
414  Q_INVOKABLE explicit IrcPrivateMessage(IrcConnection* connection);
415 
416  QString target() const;
417  QString content() const;
418  bool isPrivate() const;
419  bool isAction() const;
420  bool isRequest() const;
421 
422  bool isValid() const;
423 
424 private:
425  Q_DISABLE_COPY(IrcPrivateMessage)
426 };
427 
428 class IRC_CORE_EXPORT IrcQuitMessage : public IrcMessage
429 {
430  Q_OBJECT
431  Q_PROPERTY(QString reason READ reason)
432 
433 public:
434  Q_INVOKABLE explicit IrcQuitMessage(IrcConnection* connection);
435 
436  QString reason() const;
437 
438  bool isValid() const;
439 
440 private:
441  Q_DISABLE_COPY(IrcQuitMessage)
442 };
443 
444 class IRC_CORE_EXPORT IrcTopicMessage : public IrcMessage
445 {
446  Q_OBJECT
447  Q_PROPERTY(QString channel READ channel)
448  Q_PROPERTY(QString topic READ topic)
449  Q_PROPERTY(bool reply READ isReply)
450 
451 public:
452  Q_INVOKABLE explicit IrcTopicMessage(IrcConnection* connection);
453 
454  QString channel() const;
455  QString topic() const;
456  bool isReply() const;
457 
458  bool isValid() const;
459 
460 private:
461  Q_DISABLE_COPY(IrcTopicMessage)
462 };
463 
464 class IRC_CORE_EXPORT IrcWhoReplyMessage : public IrcMessage
465 {
466  Q_OBJECT
467  Q_PROPERTY(QString mask READ mask)
468  Q_PROPERTY(QString server READ server)
469  Q_PROPERTY(bool away READ isAway)
470  Q_PROPERTY(bool servOp READ isServOp)
471  Q_PROPERTY(QString realName READ realName)
472 
473 public:
474  Q_INVOKABLE explicit IrcWhoReplyMessage(IrcConnection* connection);
475 
476  QString mask() const;
477  QString server() const;
478  bool isAway() const;
479  bool isServOp() const;
480  QString realName() const;
481 
482  bool isValid() const;
483 
484 private:
485  Q_DISABLE_COPY(IrcWhoReplyMessage)
486 };
487 
488 #ifndef QT_NO_DEBUG_STREAM
489 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Type type);
490 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Flag flag);
491 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcMessage::Flags flags);
492 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcModeMessage::Kind kind);
493 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, const IrcMessage* message);
494 #endif // QT_NO_DEBUG_STREAM
495 
496 IRC_END_NAMESPACE
497 
498 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMessage::Type))
499 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMessage*))
500 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCapabilityMessage*))
501 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcErrorMessage*))
502 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcInviteMessage*))
503 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcJoinMessage*))
504 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcKickMessage*))
505 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcModeMessage*))
506 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcMotdMessage*))
507 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNamesMessage*))
508 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNickMessage*))
509 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNoticeMessage*))
510 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcNumericMessage*))
511 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPartMessage*))
512 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPingMessage*))
513 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPongMessage*))
514 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcPrivateMessage*))
515 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcQuitMessage*))
516 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcTopicMessage*))
517 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcWhoReplyMessage*))
518 
519 #endif // IRCMESSAGE_H
Represents an invite message.
Definition: ircmessage.h:181
Represents a private message.
Definition: ircmessage.h:404
Represents a names list message.
Definition: ircmessage.h:280
An invite message (IrcInviteMessage).
Definition: ircmessage.h:72
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:47
Flag
Definition: ircmessage.h:90
Provides network information and capability management.
Definition: ircnetwork.h:43
Represents a numeric message.
Definition: ircmessage.h:338
A topic message (IrcTopicMessage).
Definition: ircmessage.h:86
A capability message (IrcCapabilityMessage).
Definition: ircmessage.h:70
Represents an error message.
Definition: ircmessage.h:165
A names message (IrcNamesMessage).
Definition: ircmessage.h:77
Represents a quit message.
Definition: ircmessage.h:428
Represents a join message.
Definition: ircmessage.h:199
Represents a pong message.
Definition: ircmessage.h:388
Represents a nick message.
Definition: ircmessage.h:298
A kick message (IrcKickMessage).
Definition: ircmessage.h:74
Represents a ping message.
Definition: ircmessage.h:372
An error message (IrcErrorMessage).
Definition: ircmessage.h:71
An unknown message (IrcMessage).
Definition: ircmessage.h:69
A message of the day (IrcMotdMessage).
Definition: ircmessage.h:76
A ping message (IrcPingMessage).
Definition: ircmessage.h:82
A private message (IrcPrivateMessage).
Definition: ircmessage.h:84
A numeric message (IrcNumericMessage).
Definition: ircmessage.h:80
A quit message (IrcQuitMessage).
Definition: ircmessage.h:85
Provides the most common commands.
Definition: irccommand.h:43
Kind
Definition: ircmessage.h:255
Represents a kick message.
Definition: ircmessage.h:215
Represents a reply message to a WHO command.
Definition: ircmessage.h:464
Type
Definition: ircmessage.h:68
Represents a capability message.
Definition: ircmessage.h:147
Represents a part message.
Definition: ircmessage.h:354
Represents a topic message.
Definition: ircmessage.h:444
The base class of all messages.
Definition: ircmessage.h:47
A join message (IrcJoinMessage).
Definition: ircmessage.h:73
Represents a mode message.
Definition: ircmessage.h:235
A nick message (IrcNickMessage).
Definition: ircmessage.h:78
Represents a message of the day.
Definition: ircmessage.h:264
A mode message (IrcModeMessage).
Definition: ircmessage.h:75
Represents a notice message.
Definition: ircmessage.h:316
A pong message (IrcPongMessage).
Definition: ircmessage.h:83
A part message (IrcPartMessage).
Definition: ircmessage.h:81
A notice message (IrcNoticeMessage).
Definition: ircmessage.h:79