KRunner

runnersyntax.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Aaron Seigo <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "runnersyntax.h"
8 
9 #include <KLocalizedString>
10 
11 namespace Plasma
12 {
13 class RunnerSyntaxPrivate
14 {
15 public:
16  RunnerSyntaxPrivate(const QStringList &_exampleQueries, const QString &_description)
17  : description(_description)
18  {
19  for (const QString &query : _exampleQueries) {
20  addExampleQuery(query);
21  }
22  }
23 
24  void addExampleQuery(const QString &s)
25  {
26  Q_ASSERT_X(!s.isEmpty(), "KRunner::RunnerSyntax", "Example queries must not be empty!");
27  const QString termDesc(QLatin1Char('<') + termDescription + QLatin1Char('>'));
28  exampleQueries.append(QString(s).replace(QStringLiteral(":q:"), termDesc));
29  }
30 
31  QStringList exampleQueries;
32  QString description;
33  QString termDescription = i18n("search term");
34 };
35 
36 RunnerSyntax::RunnerSyntax(const QString &exampleQuery, const QString &description)
37  : d(new RunnerSyntaxPrivate({exampleQuery}, description))
38 {
39 }
40 
41 RunnerSyntax::RunnerSyntax(const QStringList &exampleQueries, const QString &description)
42  : d(new RunnerSyntaxPrivate(exampleQueries, description))
43 {
44  Q_ASSERT_X(!exampleQueries.isEmpty(), "KRunner::RunnerSyntax", "Example queries must not be empty");
45 }
46 
48  : d(new RunnerSyntaxPrivate(*other.d))
49 {
50 }
51 
52 RunnerSyntax::~RunnerSyntax() = default;
53 
55 {
56  *d = *rhs.d;
57  return *this;
58 }
59 
60 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 106)
61 void RunnerSyntax::addExampleQuery(const QString &exampleQuery)
62 {
63  d->addExampleQuery(exampleQuery);
64 }
65 #endif
66 
68 {
69  return d->exampleQueries;
70 }
71 
72 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 76)
74 {
75  QStringList queries;
76  const QString termDesc(QLatin1Char('<') + searchTermDescription() + QLatin1Char('>'));
77  for (QString query : std::as_const(d->exampleQueries)) {
78  queries << query.replace(QStringLiteral(":q:"), termDesc);
79  }
80 
81  return queries;
82 }
83 #endif
84 
85 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 106)
86 void RunnerSyntax::setDescription(const QString &description)
87 {
88  d->description = description;
89 }
90 #endif
91 
93 {
94 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 76)
95  QString description = d->description;
97  return description;
98 #else
99  return d->description;
100 #endif
101 }
102 
103 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 76)
105 {
106  d->termDescription = description;
107 }
108 #endif
109 
110 #if KRUNNER_BUILD_DEPRECATED_SINCE(5, 76)
112 {
113  return d->termDescription;
114 }
115 #endif
116 
117 } // Plasma namespace
QStringList exampleQueriesWithTermDescription() const
QString description() const
QString searchTermDescription() const
void setDescription(const QString &description)
Sets the description for the syntax, describing what it does from the user's point of view.
QString i18n(const char *text, const TYPE &arg...)
void addExampleQuery(const QString &exampleQuery)
Adds a synonymous example query to this Syntax.
bool isEmpty() const const
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
RunnerSyntax & operator=(const RunnerSyntax &rhs)
Assignment operator.
bool isEmpty() const const
QString & replace(int position, int n, QChar after)
RunnerSyntax(const QString &exampleQuery, const QString &description)
Constructs a simple syntax object.
void setSearchTermDescription(const QString &description)
Sets the text that should be used to replace instances of :q: in the text.
QStringList exampleQueries() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Dec 2 2023 03:51:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.