| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org> |
| 3 | SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include "runnersyntax.h" |
| 9 | |
| 10 | #include <KLocalizedString> |
| 11 | |
| 12 | namespace KRunner |
| 13 | { |
| 14 | class RunnerSyntaxPrivate |
| 15 | { |
| 16 | public: |
| 17 | RunnerSyntaxPrivate(const QStringList &_exampleQueries, const QString &_description) |
| 18 | : exampleQueries(prepareExampleQueries(queries: _exampleQueries)) |
| 19 | , description(_description) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | static QStringList prepareExampleQueries(const QStringList &queries) |
| 24 | { |
| 25 | Q_ASSERT_X(!queries.isEmpty(), "KRunner::RunnerSyntax" , "List of example queries must not be empty" ); |
| 26 | QStringList exampleQueries; |
| 27 | for (const QString &query : queries) { |
| 28 | Q_ASSERT_X(!query.isEmpty(), "KRunner::RunnerSyntax" , "Example query must not be empty!" ); |
| 29 | const static QString termDescription = i18n(text: "search term" ); |
| 30 | const QString termDesc(QLatin1Char('<') + termDescription + QLatin1Char('>')); |
| 31 | exampleQueries.append(t: QString(query).replace(before: QLatin1String(":q:" ), after: termDesc)); |
| 32 | } |
| 33 | return exampleQueries; |
| 34 | } |
| 35 | |
| 36 | const QStringList exampleQueries; |
| 37 | const QString description; |
| 38 | }; |
| 39 | |
| 40 | RunnerSyntax::RunnerSyntax(const QStringList &exampleQueries, const QString &description) |
| 41 | : d(new RunnerSyntaxPrivate(exampleQueries, description)) |
| 42 | { |
| 43 | Q_ASSERT_X(!exampleQueries.isEmpty(), "KRunner::RunnerSyntax" , "Example queries must not be empty" ); |
| 44 | } |
| 45 | |
| 46 | RunnerSyntax::RunnerSyntax(const RunnerSyntax &other) |
| 47 | : d(new RunnerSyntaxPrivate(*other.d)) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | RunnerSyntax::~RunnerSyntax() = default; |
| 52 | |
| 53 | RunnerSyntax &RunnerSyntax::operator=(const RunnerSyntax &rhs) |
| 54 | { |
| 55 | d.reset(p: new RunnerSyntaxPrivate(*rhs.d)); |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | QStringList RunnerSyntax::exampleQueries() const |
| 60 | { |
| 61 | return d->exampleQueries; |
| 62 | } |
| 63 | |
| 64 | QString RunnerSyntax::description() const |
| 65 | { |
| 66 | return d->description; |
| 67 | } |
| 68 | |
| 69 | } // KRunner namespace |
| 70 | |