diff --git a/searchcontext.cpp b/searchcontext.cpp index 98b75e793..1e8d97720 100644 --- a/searchcontext.cpp +++ b/searchcontext.cpp @@ -141,10 +141,14 @@ SearchContext::~SearchContext() delete d; } -void SearchContext::setSearchTerm(const QString &term) +void SearchContext::resetSearchTerm(const QString &term) { d->resetState(); + setSearchTerm(term); +} +void SearchContext::setSearchTerm(const QString &term) +{ if (term.isEmpty()) { return; } diff --git a/searchcontext.h b/searchcontext.h index 8ee562408..b54481022 100644 --- a/searchcontext.h +++ b/searchcontext.h @@ -58,8 +58,15 @@ class PLASMA_EXPORT SearchContext : public QObject SearchContext(QObject *parent, const SearchContext& other); /** - * Sets the search term for this object. This clears all current - * matches in the process. + * Sets the search term for this object and attempts to determine + * 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&); diff --git a/searchmatch.cpp b/searchmatch.cpp index bb1e2399a..0b3e58527 100644 --- a/searchmatch.cpp +++ b/searchmatch.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include "searchmatch.h" #include "abstractrunner.h" @@ -32,9 +34,8 @@ namespace Plasma class SearchMatch::Private { public: - Private(SearchContext* s, AbstractRunner *r) - : /*search(s),*/ - runner(r), + Private(const SearchContext *s, AbstractRunner *r) + : runner(r), type(SearchMatch::ExactMatch), enabled(true), relevance(1) @@ -42,8 +43,8 @@ class SearchMatch::Private searchTerm = s->searchTerm(); mimetype = s->mimetype(); } + QString searchTerm; - SearchContext *search; AbstractRunner *runner; SearchMatch::Type type; 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)) { } @@ -82,12 +83,12 @@ void SearchMatch::setMimetype(const QString &mimetype) QString SearchMatch::mimetype() const { - return d->mimetype;//.isEmpty() ? d->search->mimetype() : d->mimetype; + return d->mimetype; } QString SearchMatch::searchTerm() const { - return d->searchTerm;//->searchTerm(); + return d->searchTerm; } void SearchMatch::setRelevance(qreal relevance) @@ -150,12 +151,20 @@ bool SearchMatch::operator<(const SearchMatch& other) const 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) { - //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); } } -} +} // Plasma namespace + diff --git a/searchmatch.h b/searchmatch.h index 3f9b57180..477901a87 100644 --- a/searchmatch.h +++ b/searchmatch.h @@ -39,7 +39,7 @@ class PLASMA_EXPORT SearchMatch ExactMatch, PossibleMatch }; - SearchMatch(SearchContext *search, AbstractRunner *runner); + SearchMatch(const SearchContext *search, AbstractRunner *runner); ~SearchMatch(); /** @@ -104,7 +104,7 @@ class PLASMA_EXPORT SearchMatch //Pending a better solution, changing this to public // public Q_SLOTS: - void exec(); + void exec(const SearchContext *context); private: class Private;