File indexing completed on 2024-04-28 15:29:45

0001 /*
0002     SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef PLASMA_RUNNERSYNTAX_H
0008 #define PLASMA_RUNNERSYNTAX_H
0009 
0010 #include <QStringList>
0011 #include <memory>
0012 
0013 #include "krunner_export.h"
0014 
0015 namespace Plasma
0016 {
0017 class RunnerSyntaxPrivate;
0018 /**
0019  * @class RunnerSyntax runnersyntax.h <KRunner/RunnerSyntax>
0020  * @since 4.3
0021  *
0022  * Represents a query prototype that the runner accepts. These can be
0023  * created and registered with AbstractRunner::addSyntax(Syntax &) to
0024  * allow applications to show to the user what the runner is currently
0025  * capable of doing.
0026  *
0027  * Lets say the runner has a trigger word and then the user can type anything after that. In that case you could use
0028  * ":q:" as a placeholder, which will get expanded to i18n("search term") and be put in brackets.
0029  * @code
0030    Plasma::RunnerSyntax syntax(QStringLiteral("sometriggerword :q:"), i18n("Description for this syntax"));
0031    addSyntax(syntax);
0032  * @endcode
0033  *
0034  * But if the query the user has to enter is sth. specific like a program,
0035  * url or file you should use a custom placeholder to make it easier to understand.
0036  * @code
0037    Plasma::RunnerSyntax syntax(QStringLiteral("sometriggereword <%1>").arg(i18n("program name"))), i18n("Description for this syntax"));
0038    addSyntax(syntax);
0039  * @endcode
0040  */
0041 class KRUNNER_EXPORT RunnerSyntax
0042 {
0043 public:
0044     /**
0045      * Constructs a simple syntax object
0046      *
0047      * @param exampleQuery See the class description for examples and placeholder conventions.
0048      * @param description A description of what the described syntax does from
0049      *                    the user's point of view.
0050      */
0051     RunnerSyntax(const QString &exampleQuery, const QString &description);
0052 
0053     /**
0054      * Constructs a syntax object
0055      *
0056      * @param exampleQuery See the class description for examples and placeholder conventions.
0057      * @param description A description of what the described syntax does from the user's point of view.
0058      *
0059      * @since 5.106
0060      */
0061     explicit RunnerSyntax(const QStringList &exampleQueries, const QString &description);
0062 
0063     /**
0064      * Copy constructor
0065      */
0066     RunnerSyntax(const RunnerSyntax &other);
0067 
0068     ~RunnerSyntax();
0069 
0070     /**
0071      * Assignment operator
0072      */
0073     RunnerSyntax &operator=(const RunnerSyntax &rhs);
0074 
0075 #if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 106)
0076     /**
0077      * Adds a synonymous example query to this Syntax. Some runners may
0078      * accept multiple formulations of keywords to trigger the same behaviour.
0079      * This allows the runner to show these relationships by grouping the
0080      * example queries into one Syntax object
0081      *
0082      * @param exampleQuery See the class description for examples and placeholder conventions.
0083      * @deprecated Since 5.106, use constructor taking example query QStringList
0084      */
0085     KRUNNER_DEPRECATED_VERSION(5, 106, "Use constructor taking example query QStringList")
0086     void addExampleQuery(const QString &exampleQuery);
0087 #endif
0088 
0089     /**
0090      * @return the example queries associated with this Syntax object
0091      */
0092     QStringList exampleQueries() const;
0093 
0094 #if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
0095     /**
0096      * @return the example queries associated with this Syntax object, with
0097      * the searchTermDescription replacing instances of :q:. Used for showing
0098      * the queries in the user interface.
0099      * @deprecated Since 5.76, the description should be directly set when creating the example query.
0100      * To display the queries in the user interface. Use exampleQueries() instead.
0101      */
0102     KRUNNER_DEPRECATED_VERSION(5, 76, "The descriptions should be directly set when creating the example query. Use exampleQueries() instead.")
0103     QStringList exampleQueriesWithTermDescription() const;
0104 #endif
0105 
0106 #if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 106)
0107     /**
0108      * Sets the description for the syntax, describing what it does from
0109      * the user's point of view.
0110      * @deprecated Since 5.106, this should only be set when constructing the syntax
0111      */
0112     KRUNNER_DEPRECATED_VERSION(5, 106, "This should only be set when constructing the syntax")
0113     void setDescription(const QString &description);
0114 #endif
0115 
0116     /**
0117      * @return the description of what the syntax does from the user's
0118      *         point of view
0119      */
0120     QString description() const;
0121 
0122 #if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
0123     /**
0124      * Sets the text that should be used to replace instances of :q:
0125      * in the text. By default this is the generic phrase "search term".
0126      * If the syntax expects a specific kind of input, it may be defined
0127      * here. A syntax used by a runner that changes the brightness of the display
0128      * may set this to "brightness" for instance.
0129      * @deprecated Since 5.76, set the description directly when creating the example query. Use <my query description> instead of :q: when creating the string
0130      */
0131     KRUNNER_DEPRECATED_VERSION(
0132         5,
0133         76,
0134         "Set the description directly when creating the example query. Use <my query description> instead of :q: when creating the string")
0135     void setSearchTermDescription(const QString &description);
0136 #endif
0137 
0138 #if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
0139     /**
0140      * @return a description of the search term for this syntax
0141      * @deprecated Since 5.76, the description should be directly set when creating the example query.
0142      */
0143     KRUNNER_DEPRECATED_VERSION(5, 76, "Feature is obsolete, the search term description should be set inside of the example query directly")
0144     QString searchTermDescription() const;
0145 #endif
0146 
0147 private:
0148     std::unique_ptr<RunnerSyntaxPrivate> const d;
0149 };
0150 
0151 } // namespace Plasma
0152 
0153 #if !KRUNNER_ENABLE_DEPRECATED_SINCE(5, 91)
0154 namespace KRunner
0155 {
0156 using RunnerSyntax = Plasma::RunnerSyntax;
0157 }
0158 #endif
0159 
0160 #endif // multiple inclusion guard