2012-08-08 23:23:49 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2011, 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "soundcloudsearchprovider.h"
|
|
|
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "covers/albumcoverloader.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/soundcloud/soundcloudservice.h"
|
2012-08-08 23:23:49 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SoundCloudSearchProvider::SoundCloudSearchProvider(Application* app,
|
|
|
|
QObject* parent)
|
|
|
|
: SearchProvider(app, parent), service_(nullptr) {}
|
2012-08-08 23:23:49 +02:00
|
|
|
|
|
|
|
void SoundCloudSearchProvider::Init(SoundCloudService* service) {
|
|
|
|
service_ = service;
|
2014-02-07 16:34:20 +01:00
|
|
|
SearchProvider::Init(
|
|
|
|
"SoundCloud", "soundcloud", QIcon(":providers/soundcloud.png"),
|
|
|
|
WantsDelayedQueries | ArtIsProbablyRemote | CanShowConfig);
|
2012-08-08 23:23:49 +02:00
|
|
|
|
|
|
|
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
|
|
|
|
SLOT(SearchDone(int, SongList)));
|
|
|
|
|
|
|
|
cover_loader_options_.desired_height_ = kArtHeight;
|
|
|
|
cover_loader_options_.pad_output_image_ = true;
|
|
|
|
cover_loader_options_.scale_output_image_ = true;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)),
|
2012-08-08 23:23:49 +02:00
|
|
|
SLOT(AlbumArtLoaded(quint64, QImage)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCloudSearchProvider::SearchAsync(int id, const QString& query) {
|
|
|
|
const int service_id = service_->SimpleSearch(query);
|
2014-02-07 16:34:20 +01:00
|
|
|
pending_searches_[service_id] = PendingState(id, TokenizeQuery(query));
|
|
|
|
;
|
2012-08-08 23:23:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCloudSearchProvider::SearchDone(int id, const SongList& songs) {
|
|
|
|
// Map back to the original id.
|
|
|
|
const PendingState state = pending_searches_.take(id);
|
|
|
|
const int global_search_id = state.orig_id_;
|
|
|
|
|
|
|
|
ResultList ret;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : songs) {
|
2012-08-08 23:23:49 +02:00
|
|
|
Result result(this);
|
|
|
|
result.metadata_ = song;
|
|
|
|
|
|
|
|
ret << result;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit ResultsAvailable(global_search_id, ret);
|
|
|
|
MaybeSearchFinished(global_search_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCloudSearchProvider::MaybeSearchFinished(int id) {
|
|
|
|
if (pending_searches_.keys(PendingState(id, QStringList())).isEmpty()) {
|
|
|
|
emit SearchFinished(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCloudSearchProvider::LoadArtAsync(int id, const Result& result) {
|
|
|
|
quint64 loader_id = app_->album_cover_loader()->LoadImageAsync(
|
2014-02-07 16:34:20 +01:00
|
|
|
cover_loader_options_, result.metadata_);
|
2012-08-08 23:23:49 +02:00
|
|
|
cover_loader_tasks_[loader_id] = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCloudSearchProvider::AlbumArtLoaded(quint64 id, const QImage& image) {
|
|
|
|
if (!cover_loader_tasks_.contains(id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int original_id = cover_loader_tasks_.take(id);
|
|
|
|
emit ArtLoaded(original_id, image);
|
|
|
|
}
|