2011-08-28 22:33:59 +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 GLOBALSEARCH_H
|
|
|
|
#define GLOBALSEARCH_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2011-08-28 23:52:24 +02:00
|
|
|
#include <QPixmapCache>
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
#include "covers/albumcoverloaderoptions.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "searchprovider.h"
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-11-04 23:31:19 +01:00
|
|
|
class AlbumCoverLoader;
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2011-11-11 23:11:25 +01:00
|
|
|
class UrlSearchProvider;
|
2011-11-04 23:31:19 +01:00
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
class GlobalSearch : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
GlobalSearch(Application* app, QObject* parent = nullptr);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-08-29 01:13:36 +02:00
|
|
|
static const int kDelayedSearchTimeoutMs;
|
2011-10-01 22:22:01 +02:00
|
|
|
static const char* kSettingsGroup;
|
2011-11-08 22:49:20 +01:00
|
|
|
static const int kMaxResultsPerEmission;
|
2011-08-29 01:13:36 +02:00
|
|
|
|
2012-06-10 20:00:51 +02:00
|
|
|
Application* application() const { return app_; }
|
|
|
|
|
2011-11-28 15:18:20 +01:00
|
|
|
void AddProvider(SearchProvider* provider);
|
2011-10-20 15:03:47 +02:00
|
|
|
// Try to change provider state. Returns false if we can't (e.g. we can't
|
|
|
|
// enable a provider because it requires the user to be logged-in)
|
|
|
|
bool SetProviderEnabled(const SearchProvider* provider, bool enabled);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
|
|
|
int SearchAsync(const QString& query);
|
|
|
|
int LoadArtAsync(const SearchProvider::Result& result);
|
2012-06-10 21:55:51 +02:00
|
|
|
MimeData* LoadTracks(const SearchProvider::ResultList& results);
|
2012-06-11 00:05:30 +02:00
|
|
|
QStringList GetSuggestions(int count);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-08-29 01:13:36 +02:00
|
|
|
void CancelSearch(int id);
|
|
|
|
void CancelArt(int id);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool FindCachedPixmap(const SearchProvider::Result& result,
|
|
|
|
QPixmap* pixmap) const;
|
2011-08-28 23:52:24 +02:00
|
|
|
|
2011-11-28 15:18:20 +01:00
|
|
|
// "enabled" is the user preference. "usable" is enabled AND logged in.
|
2011-10-01 22:22:01 +02:00
|
|
|
QList<SearchProvider*> providers() const;
|
|
|
|
bool is_provider_enabled(const SearchProvider* provider) const;
|
2011-11-28 15:18:20 +01:00
|
|
|
bool is_provider_usable(SearchProvider* provider) const;
|
2011-10-01 22:22:01 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2016-01-09 15:45:11 +01:00
|
|
|
|
2011-10-01 22:22:01 +02:00
|
|
|
void ReloadSettings();
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2016-01-09 15:45:11 +01:00
|
|
|
void SearchAsyncSig(int id, const QString& query);
|
2011-08-28 22:33:59 +02:00
|
|
|
void ResultsAvailable(int id, const SearchProvider::ResultList& results);
|
|
|
|
void ProviderSearchFinished(int id, const SearchProvider* provider);
|
|
|
|
void SearchFinished(int id);
|
|
|
|
|
2011-08-28 23:52:24 +02:00
|
|
|
void ArtLoaded(int id, const QPixmap& pixmap);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-10-01 22:22:01 +02:00
|
|
|
void ProviderAdded(const SearchProvider* provider);
|
|
|
|
void ProviderRemoved(const SearchProvider* provider);
|
2012-06-19 22:07:58 +02:00
|
|
|
void ProviderToggled(const SearchProvider* provider, bool enabled);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2011-08-29 01:13:36 +02:00
|
|
|
void timerEvent(QTimerEvent* e);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2016-01-09 15:45:11 +01:00
|
|
|
void DoSearchAsync(int id, const QString& query);
|
2011-08-28 23:52:24 +02:00
|
|
|
void ResultsAvailableSlot(int id, SearchProvider::ResultList results);
|
2011-08-28 22:33:59 +02:00
|
|
|
void SearchFinishedSlot(int id);
|
|
|
|
|
2011-08-28 23:52:24 +02:00
|
|
|
void ArtLoadedSlot(int id, const QImage& image);
|
2011-11-04 23:31:19 +01:00
|
|
|
void AlbumArtLoaded(quint64 id, const QImage& image);
|
2011-08-28 23:52:24 +02:00
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
void ProviderDestroyedSlot(QObject* object);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-11-11 23:11:25 +01:00
|
|
|
void ConnectProvider(SearchProvider* provider);
|
2011-11-04 23:31:19 +01:00
|
|
|
void HandleLoadedArt(int id, const QImage& image, SearchProvider* provider);
|
2011-08-29 01:32:45 +02:00
|
|
|
void TakeNextQueuedArt(SearchProvider* provider);
|
2011-08-28 23:52:24 +02:00
|
|
|
QString PixmapCacheKey(const SearchProvider::Result& result) const;
|
|
|
|
|
2011-10-20 16:36:12 +02:00
|
|
|
void SaveProvidersSettings();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-08-29 01:13:36 +02:00
|
|
|
struct DelayedSearch {
|
2011-08-29 01:18:17 +02:00
|
|
|
int id_;
|
2011-08-29 01:13:36 +02:00
|
|
|
QString query_;
|
|
|
|
QList<SearchProvider*> providers_;
|
|
|
|
};
|
|
|
|
|
2011-08-29 01:32:45 +02:00
|
|
|
struct QueuedArt {
|
|
|
|
int id_;
|
|
|
|
SearchProvider::Result result_;
|
|
|
|
};
|
|
|
|
|
2011-10-01 22:22:01 +02:00
|
|
|
struct ProviderData {
|
|
|
|
QList<QueuedArt> queued_art_;
|
|
|
|
bool enabled_;
|
|
|
|
};
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
|
|
|
|
2011-10-01 22:22:01 +02:00
|
|
|
QMap<SearchProvider*, ProviderData> providers_;
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-08-29 01:13:36 +02:00
|
|
|
QMap<int, DelayedSearch> delayed_searches_;
|
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
int next_id_;
|
|
|
|
QMap<int, int> pending_search_providers_;
|
2011-08-28 23:52:24 +02:00
|
|
|
|
|
|
|
QPixmapCache pixmap_cache_;
|
|
|
|
QMap<int, QString> pending_art_searches_;
|
2011-10-01 22:22:01 +02:00
|
|
|
|
2011-11-04 23:31:19 +01:00
|
|
|
// Used for providers with ArtIsInSongMetadata set.
|
2012-02-13 21:44:04 +01:00
|
|
|
AlbumCoverLoaderOptions cover_loader_options_;
|
2011-11-04 23:31:19 +01:00
|
|
|
QMap<quint64, int> cover_loader_tasks_;
|
2011-11-11 23:11:25 +01:00
|
|
|
|
|
|
|
// Special search provider that's used for queries that look like URLs
|
|
|
|
UrlSearchProvider* url_provider_;
|
2011-08-28 22:33:59 +02:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // GLOBALSEARCH_H
|