Communi  3.4.0
A cross-platform IRC framework written with Qt
irccommand.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2015 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 IRCCOMMAND_H
30 #define IRCCOMMAND_H
31 
32 #include <IrcGlobal>
33 #include <QtCore/qobject.h>
34 #include <QtCore/qmetatype.h>
35 #include <QtCore/qstringlist.h>
36 
37 IRC_BEGIN_NAMESPACE
38 
39 class IrcMessage;
40 class IrcConnection;
41 class IrcCommandPrivate;
42 
43 class IRC_CORE_EXPORT IrcCommand : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY(IrcConnection* connection READ connection)
47  Q_PROPERTY(QStringList parameters READ parameters WRITE setParameters)
48  Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding)
49  Q_PROPERTY(Type type READ type WRITE setType)
50  Q_ENUMS(Type)
51 
52 public:
53  enum Type {
74  Ping,
75  Pong,
84  Who,
87  Monitor
88  };
89 
90  explicit IrcCommand(QObject* parent = 0);
91  virtual ~IrcCommand();
92 
93  IrcConnection* connection() const;
94 
95  Type type() const;
96  void setType(Type type);
97 
98  QStringList parameters() const;
99  void setParameters(const QStringList& parameters);
100 
101  QByteArray encoding() const;
102  void setEncoding(const QByteArray& encoding);
103 
104  virtual QString toString() const;
105 
106  Q_INVOKABLE IrcMessage* toMessage(const QString& prefix, IrcConnection* connection) const;
107 
108  Q_INVOKABLE static IrcCommand* createAdmin(const QString& server = QString());
109  Q_INVOKABLE static IrcCommand* createAway(const QString& reason = QString());
110  Q_INVOKABLE static IrcCommand* createCapability(const QString& subCommand, const QString& capability);
111  Q_INVOKABLE static IrcCommand* createCapability(const QString& subCommand, const QStringList& capabilities = QStringList());
112  Q_INVOKABLE static IrcCommand* createCtcpAction(const QString& target, const QString& action);
113  Q_INVOKABLE static IrcCommand* createCtcpReply(const QString& target, const QString& reply);
114  Q_INVOKABLE static IrcCommand* createCtcpRequest(const QString& target, const QString& request);
115  Q_INVOKABLE static IrcCommand* createInfo(const QString& server = QString());
116  Q_INVOKABLE static IrcCommand* createInvite(const QString& user, const QString& channel);
117  Q_INVOKABLE static IrcCommand* createJoin(const QString& channel, const QString& key = QString());
118  Q_INVOKABLE static IrcCommand* createJoin(const QStringList& channels, const QStringList& keys = QStringList());
119  Q_INVOKABLE static IrcCommand* createKick(const QString& channel, const QString& user, const QString& reason = QString());
120  Q_INVOKABLE static IrcCommand* createKnock(const QString& channel, const QString& message = QString());
121  Q_INVOKABLE static IrcCommand* createList(const QStringList& channels = QStringList(), const QString& server = QString());
122  Q_INVOKABLE static IrcCommand* createMessage(const QString& target, const QString& message);
123  Q_INVOKABLE static IrcCommand* createMode(const QString& target, const QString& mode = QString(), const QString& arg = QString());
124  Q_INVOKABLE static IrcCommand* createMonitor(const QString& command, const QString& target = QString());
125  Q_INVOKABLE static IrcCommand* createMonitor(const QString& command, const QStringList& targets);
126  Q_INVOKABLE static IrcCommand* createMotd(const QString& server = QString());
127  Q_INVOKABLE static IrcCommand* createNames(const QString& channel = QString(), const QString& server = QString());
128  Q_INVOKABLE static IrcCommand* createNames(const QStringList& channels, const QString& server = QString());
129  Q_INVOKABLE static IrcCommand* createNick(const QString& nick);
130  Q_INVOKABLE static IrcCommand* createNotice(const QString& target, const QString& notice);
131  Q_INVOKABLE static IrcCommand* createPart(const QString& channel, const QString& reason = QString());
132  Q_INVOKABLE static IrcCommand* createPart(const QStringList& channels, const QString& reason = QString());
133  Q_INVOKABLE static IrcCommand* createPing(const QString& argument);
134  Q_INVOKABLE static IrcCommand* createPong(const QString& argument);
135  Q_INVOKABLE static IrcCommand* createQuit(const QString& reason = QString());
136  Q_INVOKABLE static IrcCommand* createQuote(const QString& raw);
137  Q_INVOKABLE static IrcCommand* createQuote(const QStringList& parameters);
138  Q_INVOKABLE static IrcCommand* createStats(const QString& query, const QString& server = QString());
139  Q_INVOKABLE static IrcCommand* createTime(const QString& server = QString());
140  Q_INVOKABLE static IrcCommand* createTopic(const QString& channel, const QString& topic = QString());
141  Q_INVOKABLE static IrcCommand* createTrace(const QString& target = QString());
142  Q_INVOKABLE static IrcCommand* createUsers(const QString& server = QString());
143  Q_INVOKABLE static IrcCommand* createVersion(const QString& user = QString());
144  Q_INVOKABLE static IrcCommand* createWho(const QString& mask, bool operators = false);
145  Q_INVOKABLE static IrcCommand* createWhois(const QString& user);
146  Q_INVOKABLE static IrcCommand* createWhowas(const QString& user, int count = 1);
147 
148 private:
150  Q_DECLARE_PRIVATE(IrcCommand)
151  Q_DISABLE_COPY(IrcCommand)
152 };
153 
154 #ifndef QT_NO_DEBUG_STREAM
155 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcCommand::Type type);
156 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, const IrcCommand* command);
157 #endif // QT_NO_DEBUG_STREAM
158 
159 IRC_END_NAMESPACE
160 
161 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCommand*))
162 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCommand::Type))
163 
164 #endif // IRCCOMMAND_H
An info command (INFO) is used to query server info.
Definition: irccommand.h:61
A CTCP action command is used to send an action message to channels and users.
Definition: irccommand.h:57
A names command (NAMES) is used to list all nicknames on a channel.
Definition: irccommand.h:70
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:48
A stats command (STATS) is used to query server statistics.
Definition: irccommand.h:78
A CTCP reply command is used to send a reply to a request.
Definition: irccommand.h:58
An away command (AWAY) is used to set the away status.
Definition: irccommand.h:55
A whowas command (WHOWAS) is used to query information about a user that no longer exists...
Definition: irccommand.h:86
A message command (PRIVMSG) is used to send private messages to channels and users.
Definition: irccommand.h:67
A whois command (WHOIS) is used to query information about a particular user.
Definition: irccommand.h:85
A users command (USERS) is used to query server users.
Definition: irccommand.h:82
An admin command (ADMIN) is used to query server admin info.
Definition: irccommand.h:54
A nick command (NICK) is used to give user a nickname or change the previous one. ...
Definition: irccommand.h:71
A knock command (KNOCK) is used to request channel invitation.
Definition: irccommand.h:65
A kick command (KICK) is used to forcibly remove a user from a channel.
Definition: irccommand.h:64
A quote command is used to send a raw message to the server.
Definition: irccommand.h:77
A CTCP request command is used to send a request.
Definition: irccommand.h:59
An invite command (INVITE) is used to invite users to a channel.
Definition: irccommand.h:62
A notice command (NOTICE) is used to send notice messages to channels and users.
Definition: irccommand.h:72
A message of the day command (MOTD) is used to query the message of the day.
Definition: irccommand.h:69
A topic command (TOPIC) is used to change or view the topic of a channel.
Definition: irccommand.h:80
Type
Definition: irccommand.h:53
Provides the most common commands.
Definition: irccommand.h:43
A trace command (TRACE) is used to trace the connection path to a target.
Definition: irccommand.h:81
A join command (JOIN) is used to start listening a specific channel.
Definition: irccommand.h:63
A part command (PART) causes the client to be removed from the channel.
Definition: irccommand.h:73
A quit command (QUIT) is used to end a client connection.
Definition: irccommand.h:76
The base class of all messages.
Definition: ircmessage.h:47
A custom command.
Definition: irccommand.h:60
A capability command (CAP) is used to manage connection capabilities.
Definition: irccommand.h:56
A version command (VERSION) is used to query user or server version.
Definition: irccommand.h:83
A time command (TIME) is used to query local server time.
Definition: irccommand.h:79
A who command (WHO) is used to generate a query which returns a list of matching users.
Definition: irccommand.h:84
A mode command (MODE) is used to change the mode of users and channels.
Definition: irccommand.h:68
A list command (LIST) is used to list channels and their topics.
Definition: irccommand.h:66