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
|
|
|
|
|
2011-09-24 21:40:50 +02:00
|
|
|
public:
|
|
|
|
SimpleSearchProvider(QObject* parent);
|
|
|
|
|
|
|
|
static const int kDefaultResultLimit;
|
|
|
|
|
|
|
|
// BlockingSearchProvider
|
|
|
|
ResultList Search(int id, const QString& query);
|
|
|
|
|
|
|
|
// SearchProvider
|
|
|
|
void LoadTracksAsync(int id, const Result& result);
|
|
|
|
|
2011-10-01 18:41:28 +02:00
|
|
|
protected slots:
|
|
|
|
// 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();
|
|
|
|
|
2011-09-24 21:40:50 +02:00
|
|
|
protected:
|
|
|
|
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; }
|
|
|
|
QStringList safe_words() const { return safe_words_; }
|
|
|
|
void set_safe_words(const QStringList& safe_words) { safe_words_ = safe_words; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-09-24 21:40:50 +02:00
|
|
|
private:
|
|
|
|
int result_limit_;
|
|
|
|
QStringList safe_words_;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SIMPLESEARCHPROVIDER_H
|