Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / libs / plasma / searchmatch.cpp
bloba8170132a034a85c06dc7a5384d8254c69fce45d
1 /*
2 * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
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.
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
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.
20 #include "searchmatch.h"
22 #include <QVariant>
23 #include <QStringList>
24 #include <QIcon>
26 #include <KDebug>
28 #include "abstractrunner.h"
30 namespace Plasma
33 class SearchMatch::Private
35 public:
36 Private(AbstractRunner *r)
37 : runner(r),
38 type(SearchMatch::ExactMatch),
39 enabled(true),
40 relevance(.7)
44 AbstractRunner *runner;
45 SearchMatch::Type type;
46 QString text;
47 QString subtext;
48 QIcon icon;
49 QVariant data;
50 bool enabled;
51 qreal relevance;
55 SearchMatch::SearchMatch(AbstractRunner *runner)
56 : d(new Private(runner))
60 SearchMatch::~SearchMatch()
62 delete d;
65 void SearchMatch::setType(Type type)
67 d->type = type;
70 SearchMatch::Type SearchMatch::type() const
72 return d->type;
75 void SearchMatch::setRelevance(qreal relevance)
77 d->relevance = qMax(qreal(0.0), qMin(qreal(1.0), relevance));
80 qreal SearchMatch::relevance() const
82 return d->relevance;
85 AbstractRunner* SearchMatch::runner() const
87 return d->runner;
90 void SearchMatch::setText(const QString& text)
92 d->text = text;
95 void SearchMatch::setSubtext(const QString& subtext)
97 d->subtext = subtext;
100 void SearchMatch::setData(const QVariant& data)
102 d->data = data;
105 void SearchMatch::setIcon(const QIcon& icon)
107 d->icon = icon;
110 QVariant SearchMatch::data() const
112 return d->data;
115 QString SearchMatch::text() const
117 return d->text;
120 QString SearchMatch::subtext() const
122 return d->subtext;
125 QIcon SearchMatch::icon() const
127 return d->icon;
130 void SearchMatch::setEnabled( bool enabled )
132 d->enabled = enabled;
135 bool SearchMatch::isEnabled() const
137 return d->enabled;
140 bool SearchMatch::operator<(const SearchMatch& other) const
142 return d->relevance < other.d->relevance;
145 void SearchMatch::exec(const SearchContext *context) const
147 Q_ASSERT(context);
149 //kDebug() << "we have" << context->searchTerm() << context->mimetype();
150 if (d->runner) {
151 //TODO: this could be dangerous if the runner is deleted behind our backs.
152 d->runner->exec(context, this);
156 } // Plasma namespace