Plasma
runnersyntax.cpp
Go to the documentation of this file.00001 /* 00002 * Copyright 2009 Aaron Seigo <aseigo@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "runnersyntax.h" 00021 00022 #include <klocalizedstring.h> 00023 00024 namespace Plasma 00025 { 00026 00027 class RunnerSyntaxPrivate 00028 { 00029 public: 00030 RunnerSyntaxPrivate(const QString &s, const QString &d) 00031 : description(d) 00032 { 00033 exampleQueries.append(s); 00034 } 00035 00036 QStringList exampleQueries; 00037 QString description; 00038 QString termDescription; 00039 }; 00040 00041 RunnerSyntax::RunnerSyntax(const QString &exampleQuery, const QString &description) 00042 : d(new RunnerSyntaxPrivate(exampleQuery, description)) 00043 { 00044 } 00045 00046 RunnerSyntax::RunnerSyntax(const RunnerSyntax &other) 00047 : d(new RunnerSyntaxPrivate(*other.d)) 00048 { 00049 } 00050 00051 RunnerSyntax::~RunnerSyntax() 00052 { 00053 delete d; 00054 } 00055 00056 RunnerSyntax &RunnerSyntax::operator=(const RunnerSyntax &rhs) 00057 { 00058 *d = *rhs.d; 00059 return *this; 00060 } 00061 00062 void RunnerSyntax::addExampleQuery(const QString &exampleQuery) 00063 { 00064 d->exampleQueries.append(exampleQuery); 00065 } 00066 00067 QStringList RunnerSyntax::exampleQueries() const 00068 { 00069 return d->exampleQueries; 00070 } 00071 00072 QStringList RunnerSyntax::exampleQueriesWithTermDescription() const 00073 { 00074 QStringList queries; 00075 const QString termDesc("<" + searchTermDescription() + ">"); 00076 foreach (QString query, d->exampleQueries) { 00077 queries << query.replace(":q:", termDesc); 00078 } 00079 00080 return queries; 00081 } 00082 00083 void RunnerSyntax::setDescription(const QString &description) 00084 { 00085 d->description = description; 00086 } 00087 00088 QString RunnerSyntax::description() const 00089 { 00090 QString description = d->description; 00091 description.replace(":q:", "<" + searchTermDescription() + ">"); 00092 return description; 00093 } 00094 00095 void RunnerSyntax::setSearchTermDescription(const QString &description) 00096 { 00097 d->termDescription = description; 00098 } 00099 00100 QString RunnerSyntax::searchTermDescription() const 00101 { 00102 if (d->termDescription.isEmpty()) { 00103 return i18n("search term"); 00104 } 00105 00106 return d->termDescription; 00107 } 00108 00109 } // Plasma namespace 00110