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