KRunner

runnersyntax.cpp
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
12namespace KRunner
13{
14class RunnerSyntaxPrivate
15{
16public:
17 RunnerSyntaxPrivate(const QStringList &_exampleQueries, const QString &_description)
18 : exampleQueries(prepareExampleQueries(_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("search term");
30 const QString termDesc(QLatin1Char('<') + termDescription + QLatin1Char('>'));
31 exampleQueries.append(QString(query).replace(QLatin1String(":q:"), termDesc));
32 }
33 return exampleQueries;
34 }
35
36 const QStringList exampleQueries;
37 const QString description;
38};
39
40RunnerSyntax::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
47 : d(new RunnerSyntaxPrivate(*other.d))
48{
49}
50
51RunnerSyntax::~RunnerSyntax() = default;
52
54{
55 d.reset(new RunnerSyntaxPrivate(*rhs.d));
56 return *this;
57}
58
60{
61 return d->exampleQueries;
62}
63
65{
66 return d->description;
67}
68
69} // KRunner namespace
Represents a query prototype that the runner accepts.
RunnerSyntax(const QString &exampleQuery, const QString &description)
Constructs a RunnerSyntax with one example query.
RunnerSyntax & operator=(const RunnerSyntax &rhs)
QStringList exampleQueries() const
QString description() const
QString i18n(const char *text, const TYPE &arg...)
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
const QList< QKeySequence > & replace()
void append(QList< T > &&value)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:07:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.