File indexing completed on 2024-04-14 03:54:32
0001 /* 0002 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org> 0003 SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KRUNNER_RUNNERSYNTAX_H 0009 #define KRUNNER_RUNNERSYNTAX_H 0010 0011 #include <QStringList> 0012 #include <memory> 0013 0014 #include "krunner_export.h" 0015 0016 namespace KRunner 0017 { 0018 class RunnerSyntaxPrivate; 0019 /** 0020 * @class RunnerSyntax runnersyntax.h <KRunner/RunnerSyntax> 0021 * 0022 * Represents a query prototype that the runner accepts. These can be 0023 * created and registered with AbstractRunner::addSyntax to 0024 * allow applications to show to the user what the runner is currently capable of doing. 0025 * 0026 * Lets say the runner has a trigger word and then the user can type anything after that. In that case you could use 0027 * ":q:" as a placeholder, which will get expanded to i18n("search term") and be put in brackets. 0028 * @code 0029 KRunner::RunnerSyntax syntax(QStringLiteral("sometriggerword :q:"), i18n("Description for this syntax")); 0030 addSyntax(syntax); 0031 * @endcode 0032 * 0033 * But if the query the user has to enter is sth. specific like a program, 0034 * url or file you should use a custom placeholder to make it easier to understand. 0035 * @code 0036 KRunner::RunnerSyntax syntax(QStringLiteral("sometriggereword <%1>").arg(i18n("program name"))), i18n("Description for this syntax")); 0037 addSyntax(syntax); 0038 * @endcode 0039 */ 0040 class KRUNNER_EXPORT RunnerSyntax 0041 { 0042 public: 0043 /** 0044 * Constructs a RunnerSyntax with one example query 0045 * 0046 * @param exampleQuery See the class description for examples and placeholder conventions. 0047 * @param description A description of what the described syntax does from the user's point of view. 0048 */ 0049 explicit inline RunnerSyntax(const QString &exampleQuery, const QString &description) 0050 : RunnerSyntax(QStringList(exampleQuery), description) 0051 { 0052 } 0053 0054 /** 0055 * Constructs a RunnerSyntax with multiple example queries 0056 * 0057 * @param exampleQueries See the class description for examples and placeholder conventions. 0058 * @param description A description of what the described syntax does from the user's point of view. 0059 * This description should be true for all example queries. In case they differ, consider using multiple syntaxes. 0060 * 0061 * @since 5.106 0062 */ 0063 explicit RunnerSyntax(const QStringList &exampleQueries, const QString &description); 0064 0065 ~RunnerSyntax(); 0066 0067 /** 0068 * @return the example queries associated with this Syntax object 0069 */ 0070 QStringList exampleQueries() const; 0071 0072 /** 0073 * @return the user visible description of what the syntax does 0074 */ 0075 QString description() const; 0076 0077 /// @internal 0078 RunnerSyntax &operator=(const RunnerSyntax &rhs); 0079 /// @internal 0080 explicit RunnerSyntax(const RunnerSyntax &other); 0081 0082 private: 0083 std::unique_ptr<RunnerSyntaxPrivate> d; 0084 }; 0085 0086 } // namespace KRunner 0087 0088 #endif // multiple inclusion guard