2011-09-24 21:40:50 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SIMPLESEARCHPROVIDER_H
|
|
|
|
#define SIMPLESEARCHPROVIDER_H
|
|
|
|
|
|
|
|
#include "searchprovider.h"
|
|
|
|
|
|
|
|
class SimpleSearchProvider : public BlockingSearchProvider {
|
2011-10-01 18:41:28 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2012-02-13 21:44:04 +01:00
|
|
|
SimpleSearchProvider(Application* app, QObject* parent);
|
2011-09-24 21:40:50 +02:00
|
|
|
|
|
|
|
static const int kDefaultResultLimit;
|
|
|
|
|
|
|
|
// BlockingSearchProvider
|
|
|
|
ResultList Search(int id, const QString& query);
|
|
|
|
|
|
|
|
// SearchProvider
|
2012-06-11 00:05:30 +02:00
|
|
|
QStringList GetSuggestions(int count);
|
2011-09-24 21:40:50 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected slots:
|
2011-10-01 18:41:28 +02:00
|
|
|
// Calls RecreateItems now if the user has done a global search with this
|
|
|
|
// provider at least once before. Otherwise will schedule RecreateItems the
|
|
|
|
// next time the user does a search.
|
|
|
|
void MaybeRecreateItems();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2011-09-24 21:40:50 +02:00
|
|
|
struct Item {
|
|
|
|
Item() {}
|
|
|
|
Item(const QString& title, const QUrl& url,
|
|
|
|
const QString& keyword = QString());
|
2011-09-24 23:49:04 +02:00
|
|
|
Item(const Song& song, const QString& keyword = QString());
|
2011-09-24 21:40:50 +02:00
|
|
|
|
|
|
|
QString keyword_;
|
|
|
|
Song metadata_;
|
|
|
|
};
|
|
|
|
typedef QList<Item> ItemList;
|
|
|
|
|
|
|
|
int result_limit() const { return result_limit_; }
|
|
|
|
void set_result_limit(int result_limit) { result_limit_ = result_limit; }
|
2012-06-11 00:05:30 +02:00
|
|
|
void set_max_suggestion_count(int count) { max_suggestion_count_ = count; }
|
2011-09-24 21:40:50 +02:00
|
|
|
QStringList safe_words() const { return safe_words_; }
|
2014-02-07 16:34:20 +01:00
|
|
|
void set_safe_words(const QStringList& safe_words) {
|
|
|
|
safe_words_ = safe_words;
|
|
|
|
}
|
2011-09-24 21:40:50 +02:00
|
|
|
|
|
|
|
void SetItems(const ItemList& items);
|
|
|
|
|
2011-10-01 18:41:28 +02:00
|
|
|
// Subclasses should fetch the list of items they want to show in results and
|
|
|
|
// call SetItems with the new list.
|
|
|
|
virtual void RecreateItems() = 0;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-09-24 21:40:50 +02:00
|
|
|
int result_limit_;
|
|
|
|
QStringList safe_words_;
|
2012-06-11 00:05:30 +02:00
|
|
|
int max_suggestion_count_;
|
2011-09-24 21:40:50 +02:00
|
|
|
|
|
|
|
QMutex items_mutex_;
|
|
|
|
ItemList items_;
|
2011-10-01 18:41:28 +02:00
|
|
|
|
|
|
|
bool items_dirty_;
|
|
|
|
bool has_searched_before_;
|
2011-09-24 21:40:50 +02:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // SIMPLESEARCHPROVIDER_H
|