1 | /* |
2 | * Copyright 2009 Aaron Seigo <aseigo@kde.org> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Library General Public License as |
6 | * published by the Free Software Foundation; either version 2, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "runnersyntax.h" |
21 | |
22 | #include <klocalizedstring.h> |
23 | |
24 | namespace Plasma |
25 | { |
26 | |
27 | class RunnerSyntaxPrivate |
28 | { |
29 | public: |
30 | RunnerSyntaxPrivate(const QString &s, const QString &d) |
31 | : description(d) |
32 | { |
33 | exampleQueries.append(s); |
34 | } |
35 | |
36 | QStringList exampleQueries; |
37 | QString description; |
38 | QString termDescription; |
39 | }; |
40 | |
41 | RunnerSyntax::RunnerSyntax(const QString &exampleQuery, const QString &description) |
42 | : d(new RunnerSyntaxPrivate(exampleQuery, description)) |
43 | { |
44 | } |
45 | |
46 | RunnerSyntax::RunnerSyntax(const RunnerSyntax &other) |
47 | : d(new RunnerSyntaxPrivate(*other.d)) |
48 | { |
49 | } |
50 | |
51 | RunnerSyntax::~RunnerSyntax() |
52 | { |
53 | delete d; |
54 | } |
55 | |
56 | RunnerSyntax &RunnerSyntax::operator=(const RunnerSyntax &rhs) |
57 | { |
58 | *d = *rhs.d; |
59 | return *this; |
60 | } |
61 | |
62 | void RunnerSyntax::addExampleQuery(const QString &exampleQuery) |
63 | { |
64 | d->exampleQueries.append(exampleQuery); |
65 | } |
66 | |
67 | QStringList RunnerSyntax::exampleQueries() const |
68 | { |
69 | return d->exampleQueries; |
70 | } |
71 | |
72 | QStringList RunnerSyntax::exampleQueriesWithTermDescription() const |
73 | { |
74 | QStringList queries; |
75 | const QString termDesc('<' + searchTermDescription() + '>'); |
76 | foreach (QString query, d->exampleQueries) { |
77 | queries << query.replace(":q:" , termDesc); |
78 | } |
79 | |
80 | return queries; |
81 | } |
82 | |
83 | void RunnerSyntax::setDescription(const QString &description) |
84 | { |
85 | d->description = description; |
86 | } |
87 | |
88 | QString RunnerSyntax::description() const |
89 | { |
90 | QString description = d->description; |
91 | description.replace(":q:" , '<' + searchTermDescription() + '>'); |
92 | return description; |
93 | } |
94 | |
95 | void RunnerSyntax::setSearchTermDescription(const QString &description) |
96 | { |
97 | d->termDescription = description; |
98 | } |
99 | |
100 | QString RunnerSyntax::searchTermDescription() const |
101 | { |
102 | if (d->termDescription.isEmpty()) { |
103 | return i18n("search term" ); |
104 | } |
105 | |
106 | return d->termDescription; |
107 | } |
108 | |
109 | } // Plasma namespace |
110 | |
111 | |