Communi  3.4.0
A cross-platform IRC framework written with Qt
irccommandparser.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 IRCCOMMANDPARSER_H
30 #define IRCCOMMANDPARSER_H
31 
32 #include <IrcGlobal>
33 #include <IrcCommand>
34 #include <QtCore/qobject.h>
35 #include <QtCore/qmetatype.h>
36 #include <QtCore/qstringlist.h>
37 
38 IRC_BEGIN_NAMESPACE
39 
40 class IrcCommandParserPrivate;
41 
42 class IRC_UTIL_EXPORT IrcCommandParser : public QObject
43 {
44  Q_OBJECT
45  Q_PROPERTY(QStringList commands READ commands NOTIFY commandsChanged)
46  Q_PROPERTY(QStringList triggers READ triggers WRITE setTriggers NOTIFY triggersChanged)
47  Q_PROPERTY(QStringList channels READ channels WRITE setChannels NOTIFY channelsChanged)
48  Q_PROPERTY(QString target READ target WRITE setTarget NOTIFY targetChanged)
49  Q_PROPERTY(bool tolerant READ isTolerant WRITE setTolerant NOTIFY tolerancyChanged)
50  Q_FLAGS(Details)
51 
52 public:
53  explicit IrcCommandParser(QObject* parent = 0);
54  virtual ~IrcCommandParser();
55 
56  QStringList commands() const;
57 
58  enum Detail {
59  Full = 0x0,
60  NoTarget = 0x1,
61  NoPrefix = 0x2,
62  NoEllipsis = 0x4,
63  NoParentheses = 0x8,
64  NoBrackets = 0x10,
65  NoAngles = 0x20,
66  Visual = NoTarget | NoPrefix | NoEllipsis
67  };
68  Q_DECLARE_FLAGS(Details, Detail)
69 
70  Q_INVOKABLE QString syntax(const QString& command, Details details = Visual) const;
71 
72  Q_INVOKABLE void addCommand(IrcCommand::Type type, const QString& syntax);
73  Q_INVOKABLE void removeCommand(IrcCommand::Type type, const QString& syntax = QString());
74 
75  QStringList triggers() const;
76 
77  QString target() const;
78  QStringList channels() const;
79 
80  bool isTolerant() const;
81  void setTolerant(bool tolerant);
82 
83  Q_INVOKABLE IrcCommand* parse(const QString& input) const;
84 
85 public Q_SLOTS:
86  void clear();
87  void reset();
88 
89  void setTriggers(const QStringList& triggers);
90  void setChannels(const QStringList& channels);
91  void setTarget(const QString& target);
92 
93 Q_SIGNALS:
94  void commandsChanged(const QStringList& commands);
95  void triggersChanged(const QStringList& triggers);
96  void channelsChanged(const QStringList& channels);
97  void targetChanged(const QString& target);
98  void tolerancyChanged(bool tolerant);
99 
100 private:
101  QScopedPointer<IrcCommandParserPrivate> d_ptr;
102  Q_DECLARE_PRIVATE(IrcCommandParser)
103  Q_DISABLE_COPY(IrcCommandParser)
104 };
105 
106 Q_DECLARE_OPERATORS_FOR_FLAGS(IrcCommandParser::Details)
107 
108 IRC_END_NAMESPACE
109 
110 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCommandParser*))
111 
112 #endif // IRCCOMMANDPARSER_H
Detail
Definition: irccommandparser.h:58
Parses commands from user input.
Definition: irccommandparser.h:42
Provides the most common commands.
Definition: irccommand.h:43