* require a SearchContext in exec since the context may have shifted during matching due to multithreading

* differentiate between resetSearchTerm and just setSearchTerm (to be used with the above)
* remove the SearchContext ptr from SearchMatch's dptr as it isn't used; don't want to mislead people or waste memory
* more const correctness

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=764593
This commit is contained in:
Aaron J. Seigo 2008-01-22 04:38:03 +00:00
parent ddadcc6765
commit 2f479c7084
4 changed files with 35 additions and 15 deletions

View File

@ -141,10 +141,14 @@ SearchContext::~SearchContext()
delete d; delete d;
} }
void SearchContext::setSearchTerm(const QString &term) void SearchContext::resetSearchTerm(const QString &term)
{ {
d->resetState(); d->resetState();
setSearchTerm(term);
}
void SearchContext::setSearchTerm(const QString &term)
{
if (term.isEmpty()) { if (term.isEmpty()) {
return; return;
} }

View File

@ -58,8 +58,15 @@ class PLASMA_EXPORT SearchContext : public QObject
SearchContext(QObject *parent, const SearchContext& other); SearchContext(QObject *parent, const SearchContext& other);
/** /**
* Sets the search term for this object. This clears all current * Sets the search term for this object and attempts to determine
* matches in the process. * the type of the search.
* This clears all current matches in the process.
*/
void resetSearchTerm(const QString&);
/**
* Sets the search term for this object and attempts to determine
* the type of the search.
*/ */
void setSearchTerm(const QString&); void setSearchTerm(const QString&);

View File

@ -22,6 +22,8 @@
#include <QStringList> #include <QStringList>
#include <QIcon> #include <QIcon>
#include <KDebug>
#include "searchmatch.h" #include "searchmatch.h"
#include "abstractrunner.h" #include "abstractrunner.h"
@ -32,9 +34,8 @@ namespace Plasma
class SearchMatch::Private class SearchMatch::Private
{ {
public: public:
Private(SearchContext* s, AbstractRunner *r) Private(const SearchContext *s, AbstractRunner *r)
: /*search(s),*/ : runner(r),
runner(r),
type(SearchMatch::ExactMatch), type(SearchMatch::ExactMatch),
enabled(true), enabled(true),
relevance(1) relevance(1)
@ -42,8 +43,8 @@ class SearchMatch::Private
searchTerm = s->searchTerm(); searchTerm = s->searchTerm();
mimetype = s->mimetype(); mimetype = s->mimetype();
} }
QString searchTerm; QString searchTerm;
SearchContext *search;
AbstractRunner *runner; AbstractRunner *runner;
SearchMatch::Type type; SearchMatch::Type type;
QString mimetype; QString mimetype;
@ -55,7 +56,7 @@ class SearchMatch::Private
}; };
SearchMatch::SearchMatch(SearchContext *search, AbstractRunner *runner) SearchMatch::SearchMatch(const SearchContext *search, AbstractRunner *runner)
: d(new Private(search, runner)) : d(new Private(search, runner))
{ {
} }
@ -82,12 +83,12 @@ void SearchMatch::setMimetype(const QString &mimetype)
QString SearchMatch::mimetype() const QString SearchMatch::mimetype() const
{ {
return d->mimetype;//.isEmpty() ? d->search->mimetype() : d->mimetype; return d->mimetype;
} }
QString SearchMatch::searchTerm() const QString SearchMatch::searchTerm() const
{ {
return d->searchTerm;//->searchTerm(); return d->searchTerm;
} }
void SearchMatch::setRelevance(qreal relevance) void SearchMatch::setRelevance(qreal relevance)
@ -150,12 +151,20 @@ bool SearchMatch::operator<(const SearchMatch& other) const
return d->relevance < other.d->relevance; return d->relevance < other.d->relevance;
} }
void SearchMatch::exec() void SearchMatch::exec(const SearchContext *context)
{ {
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;
if (d->runner) { if (d->runner) {
//TODO: this could be dangerous if the runner is deleted behind our backs. //TODO: this could be dangerous if the runner is deleted behind our backs.
d->runner->exec(this); d->runner->exec(this);
} }
} }
} } // Plasma namespace

View File

@ -39,7 +39,7 @@ class PLASMA_EXPORT SearchMatch
ExactMatch, ExactMatch,
PossibleMatch }; PossibleMatch };
SearchMatch(SearchContext *search, AbstractRunner *runner); SearchMatch(const SearchContext *search, AbstractRunner *runner);
~SearchMatch(); ~SearchMatch();
/** /**
@ -104,7 +104,7 @@ class PLASMA_EXPORT SearchMatch
//Pending a better solution, changing this to public //Pending a better solution, changing this to public
// public Q_SLOTS: // public Q_SLOTS:
void exec(); void exec(const SearchContext *context);
private: private:
class Private; class Private;