File indexing completed on 2024-04-21 03:56:48
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 #include "runnersyntax.h" 0009 0010 #include <KLocalizedString> 0011 0012 namespace KRunner 0013 { 0014 class RunnerSyntaxPrivate 0015 { 0016 public: 0017 RunnerSyntaxPrivate(const QStringList &_exampleQueries, const QString &_description) 0018 : exampleQueries(prepareExampleQueries(_exampleQueries)) 0019 , description(_description) 0020 { 0021 } 0022 0023 static QStringList prepareExampleQueries(const QStringList &queries) 0024 { 0025 Q_ASSERT_X(!queries.isEmpty(), "KRunner::RunnerSyntax", "List of example queries must not be empty"); 0026 QStringList exampleQueries; 0027 for (const QString &query : queries) { 0028 Q_ASSERT_X(!query.isEmpty(), "KRunner::RunnerSyntax", "Example query must not be empty!"); 0029 const static QString termDescription = i18n("search term"); 0030 const QString termDesc(QLatin1Char('<') + termDescription + QLatin1Char('>')); 0031 exampleQueries.append(QString(query).replace(QLatin1String(":q:"), termDesc)); 0032 } 0033 return exampleQueries; 0034 } 0035 0036 const QStringList exampleQueries; 0037 const QString description; 0038 }; 0039 0040 RunnerSyntax::RunnerSyntax(const QStringList &exampleQueries, const QString &description) 0041 : d(new RunnerSyntaxPrivate(exampleQueries, description)) 0042 { 0043 Q_ASSERT_X(!exampleQueries.isEmpty(), "KRunner::RunnerSyntax", "Example queries must not be empty"); 0044 } 0045 0046 RunnerSyntax::RunnerSyntax(const RunnerSyntax &other) 0047 : d(new RunnerSyntaxPrivate(*other.d)) 0048 { 0049 } 0050 0051 RunnerSyntax::~RunnerSyntax() = default; 0052 0053 RunnerSyntax &RunnerSyntax::operator=(const RunnerSyntax &rhs) 0054 { 0055 d.reset(new RunnerSyntaxPrivate(*rhs.d)); 0056 return *this; 0057 } 0058 0059 QStringList RunnerSyntax::exampleQueries() const 0060 { 0061 return d->exampleQueries; 0062 } 0063 0064 QString RunnerSyntax::description() const 0065 { 0066 return d->description; 0067 } 0068 0069 } // KRunner namespace