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.
|
|
|
|
*/
|
|
|
|
|
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-12-03 18:18:28 +01:00
|
|
|
#include "searchmatch.h"
|
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-01-22 05:38:03 +01:00
|
|
|
Private(const SearchContext *s, AbstractRunner *r)
|
|
|
|
: 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
|
|
|
{
|
2007-12-02 08:11:50 +01:00
|
|
|
searchTerm = s->searchTerm();
|
|
|
|
mimetype = s->mimetype();
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
2008-01-22 05:38:03 +01:00
|
|
|
|
2007-12-02 08:11:50 +01:00
|
|
|
QString searchTerm;
|
2007-11-02 03:34:46 +01:00
|
|
|
AbstractRunner *runner;
|
2007-12-03 18:18:28 +01:00
|
|
|
SearchMatch::Type type;
|
2007-11-02 03:34:46 +01:00
|
|
|
QString mimetype;
|
2007-12-02 08:11:50 +01:00
|
|
|
QString text;
|
|
|
|
QIcon icon;
|
|
|
|
QVariant data;
|
|
|
|
bool enabled;
|
2007-11-02 03:34:46 +01:00
|
|
|
qreal relevance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-22 05:38:03 +01:00
|
|
|
SearchMatch::SearchMatch(const SearchContext *search, AbstractRunner *runner)
|
2007-12-02 08:11:50 +01:00
|
|
|
: d(new Private(search, 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::setMimetype(const QString &mimetype)
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
d->mimetype = mimetype;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QString SearchMatch::mimetype() const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
2008-01-22 05:38:03 +01:00
|
|
|
return d->mimetype;
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QString SearchMatch::searchTerm() const
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
2008-01-22 05:38:03 +01:00
|
|
|
return d->searchTerm;
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return d->enabled;
|
|
|
|
}
|
|
|
|
|
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-01-22 05:38:03 +01:00
|
|
|
void SearchMatch::exec(const SearchContext *context)
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
2008-01-22 05:38:03 +01:00
|
|
|
Q_ASSERT(context);
|
|
|
|
|
|
|
|
//kDebug() << "reseting the terms to the most recent status" << context;
|
|
|
|
d->searchTerm = context->searchTerm();
|
|
|
|
d->mimetype = context->mimetype();
|
|
|
|
|
|
|
|
//kDebug() << "we have" << d->searchTerm << d->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.
|
2007-12-02 08:11:50 +01:00
|
|
|
d->runner->exec(this);
|
|
|
|
}
|
2007-11-02 03:34:46 +01:00
|
|
|
}
|
|
|
|
|
2008-01-22 05:38:03 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|