2007-11-02 03:34:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-19 10:12:34 +01:00
|
|
|
#include "searchmatch.h"
|
2007-12-10 19:04:45 +01:00
|
|
|
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QIcon>
|
|
|
|
|
2008-01-22 05:38:03 +01:00
|
|
|
#include <KDebug>
|
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
#include "abstractrunner.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
class SearchMatch::Private
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-02-19 04:59:21 +01:00
|
|
|
Private(AbstractRunner *r)
|
2008-01-22 05:38:03 +01:00
|
|
|
: runner(r),
|
2007-12-03 18:18:28 +01:00
|
|
|
type(SearchMatch::ExactMatch),
|
2007-12-02 08:11:50 +01:00
|
|
|
enabled(true),
|
2008-02-09 05:55:43 +01:00
|
|
|
relevance(.7)
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
}
|
2008-01-22 05:38:03 +01:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
AbstractRunner *runner;
|
2007-12-03 18:18:28 +01:00
|
|
|
SearchMatch::Type type;
|
2007-12-02 08:11:50 +01:00
|
|
|
QString text;
|
2008-02-19 12:24:42 +01:00
|
|
|
QString subtext;
|
2007-12-02 08:11:50 +01:00
|
|
|
QIcon icon;
|
|
|
|
QVariant data;
|
|
|
|
bool enabled;
|
2007-11-02 03:34:46 +01:00
|
|
|
qreal relevance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-19 04:59:21 +01:00
|
|
|
SearchMatch::SearchMatch(AbstractRunner *runner)
|
|
|
|
: d(new Private(runner))
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
SearchMatch::~SearchMatch()
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setType(Type type)
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
d->type = type;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
SearchMatch::Type SearchMatch::type() const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setRelevance(qreal relevance)
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
2007-12-14 02:38:32 +01:00
|
|
|
d->relevance = qMax(qreal(0.0), qMin(qreal(1.0), relevance));
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
qreal SearchMatch::relevance() const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
return d->relevance;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
AbstractRunner* SearchMatch::runner() const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
return d->runner;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setText(const QString& text)
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
d->text = text;
|
|
|
|
}
|
|
|
|
|
2008-02-19 12:24:42 +01:00
|
|
|
void SearchMatch::setSubtext(const QString& subtext)
|
|
|
|
{
|
|
|
|
d->subtext = subtext;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setData(const QVariant& data)
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
d->data = data;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setIcon(const QIcon& icon)
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
d->icon = icon;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QVariant SearchMatch::data() const
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
return d->data;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QString SearchMatch::text() const
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
return d->text;
|
|
|
|
}
|
|
|
|
|
2008-02-19 12:24:42 +01:00
|
|
|
QString SearchMatch::subtext() const
|
|
|
|
{
|
|
|
|
return d->subtext;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QIcon SearchMatch::icon() const
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
return d->icon;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void SearchMatch::setEnabled( bool enabled )
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
|
|
|
d->enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
bool SearchMatch::isEnabled() const
|
2007-12-02 08:11:50 +01:00
|
|
|
{
|
2008-04-11 23:45:59 +02:00
|
|
|
return d->enabled;
|
2007-12-02 08:11:50 +01:00
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
bool SearchMatch::operator<(const SearchMatch& other) const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
return d->relevance < other.d->relevance;
|
|
|
|
}
|
|
|
|
|
2008-02-19 04:59:21 +01:00
|
|
|
void SearchMatch::exec(const SearchContext *context) const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
2008-01-22 05:38:03 +01:00
|
|
|
Q_ASSERT(context);
|
|
|
|
|
2008-02-19 12:24:42 +01:00
|
|
|
//kDebug() << "we have" << context->searchTerm() << context->mimetype();
|
2007-12-03 18:18:28 +01:00
|
|
|
if (d->runner) {
|
2008-01-22 05:38:03 +01:00
|
|
|
//TODO: this could be dangerous if the runner is deleted behind our backs.
|
2008-02-19 04:59:21 +01:00
|
|
|
d->runner->exec(context, this);
|
2007-12-02 08:11:50 +01:00
|
|
|
}
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
|
|
|
|
2008-01-22 05:38:03 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|