1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 10:48:33 +01:00

emit GS albums songs results as long as we get them, instead of waiting to have all the results available.

This commit is contained in:
Arnaud Bienner 2012-03-05 00:54:24 +01:00
parent 2bc616be0b
commit 0969432820
4 changed files with 58 additions and 52 deletions

View File

@ -39,10 +39,10 @@ void GroovesharkSearchProvider::Init(GroovesharkService* service) {
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
SLOT(SearchDone(int, SongList)));
connect(service_, SIGNAL(AlbumSearchResult(int, QList<SongList>)),
SLOT(AlbumSearchResult(int, QList<SongList>)));
connect(service_, SIGNAL(AlbumSongsLoaded(int, SongList)),
SLOT(AlbumSongsLoaded(int, SongList)));
connect(service_, SIGNAL(AlbumSearchResult(int, QList<quint64>)),
SLOT(AlbumSearchResult(int, QList<quint64>)));
connect(service_, SIGNAL(AlbumSongsLoaded(quint64, SongList)),
SLOT(AlbumSongsLoaded(quint64, SongList)));
cover_loader_options_.desired_height_ = kArtHeight;
cover_loader_options_.pad_output_image_ = true;
@ -83,35 +83,18 @@ void GroovesharkSearchProvider::SearchDone(int id, const SongList& songs) {
MaybeSearchFinished(global_search_id);
}
void GroovesharkSearchProvider::AlbumSearchResult(int id, const QList<SongList>& albums) {
void GroovesharkSearchProvider::AlbumSearchResult(int id, const QList<quint64>& albums_ids) {
// Map back to the original id.
const PendingState state = pending_searches_.take(id);
const int global_search_id = state.orig_id_;
ResultList ret;
foreach (const SongList& a, albums) {
if (a.isEmpty())
continue;
Result result(this);
result.type_ = globalsearch::Type_Album;
const QString& artist = a.last().artist();
const QString& album = a.last().album();
result.metadata_.set_album(album);
result.metadata_.set_artist(artist);
result.metadata_.set_art_automatic(a.last().art_automatic());
result.match_quality_ =
qMin(MatchQuality(state.tokens_, album),
MatchQuality(state.tokens_, artist));
foreach (const Song& s, a) {
result.album_songs_ << s;
}
result.album_size_ = result.album_songs_.size();
ret << result;
if (albums_ids.isEmpty()) {
MaybeSearchFinished(global_search_id);
return;
}
foreach (const quint64 album_id, albums_ids) {
pending_searches_[album_id] = PendingState(global_search_id, QStringList());
}
emit ResultsAvailable(global_search_id, ret);
MaybeSearchFinished(global_search_id);
}
void GroovesharkSearchProvider::MaybeSearchFinished(int id) {
@ -171,10 +154,28 @@ void GroovesharkSearchProvider::ShowConfig() {
service_->ShowConfig();
}
void GroovesharkSearchProvider::AlbumSongsLoaded(int id, const SongList& songs) {
InternetSongMimeData* mime_data = new InternetSongMimeData(service_);
mime_data->songs = songs;
SortSongs(&mime_data->songs);
void GroovesharkSearchProvider::AlbumSongsLoaded(quint64 id, const SongList& songs) {
const PendingState state = pending_searches_.take(id);
const int global_search_id = state.orig_id_;
ResultList ret;
if (!songs.isEmpty()) {
Result result(this);
result.type_ = globalsearch::Type_Album;
const QString& artist = songs.last().artist();
const QString& album = songs.last().album();
result.metadata_.set_album(album);
result.metadata_.set_artist(artist);
result.metadata_.set_art_automatic(songs.last().art_automatic());
result.match_quality_ =
qMin(MatchQuality(state.tokens_, album),
MatchQuality(state.tokens_, artist));
foreach (const Song& s, songs) {
result.album_songs_ << s;
}
result.album_size_ = result.album_songs_.size();
emit TracksLoaded(id, mime_data);
ret << result;
}
emit ResultsAvailable(global_search_id, ret);
MaybeSearchFinished(global_search_id);
}

View File

@ -40,9 +40,9 @@ class GroovesharkSearchProvider : public SearchProvider {
private slots:
void SearchDone(int id, const SongList& songs);
void AlbumSearchResult(int id, const QList<SongList>& songs);
void AlbumSearchResult(int id, const QList<quint64>& albums_ids);
void AlbumArtLoaded(quint64 id, const QImage& image);
void AlbumSongsLoaded(int id, const SongList& songs);
void AlbumSongsLoaded(quint64 id, const SongList& songs);
private:
void MaybeSearchFinished(int id);

View File

@ -229,31 +229,32 @@ void GroovesharkService::SearchAlbumsFinished(QNetworkReply* reply, int id) {
QVariantMap result = ExtractResult(reply);
QVariantList albums = result["albums"].toList();
QList<SongList> ret;
QList<quint64> ret;
foreach (const QVariant& v, albums) {
QVariantMap album = v.toMap();
quint64 album_id = album["AlbumID"].toULongLong();
QString album_name = album["AlbumName"].toString();
QString artist_name = album["ArtistName"].toString();
QString cover_art = album["CoverArtFilename"].toString();
qLog(Debug) << "Found:" << album_name << artist_name;
ret << GetAlbumSongs(album_id);
quint64 album_id = v.toMap()["AlbumID"].toULongLong();
GetAlbumSongs(album_id);
ret << album_id;
}
emit AlbumSearchResult(id, ret);
}
SongList GroovesharkService::GetAlbumSongs(quint64 album_id) {
void GroovesharkService::GetAlbumSongs(quint64 album_id) {
QList<Param> parameters;
parameters << Param("albumID", album_id)
<< Param("country", "");
QNetworkReply* reply = CreateRequest("getAlbumSongs", parameters);
if (!WaitForReply(reply))
return SongList();
NewClosure(reply, SIGNAL(finished()),
this, SLOT(GetAlbumSongsFinished(QNetworkReply*,quint64)),
reply, album_id);
}
void GroovesharkService::GetAlbumSongsFinished(QNetworkReply* reply, quint64 album_id) {
reply->deleteLater();
QVariantMap result = ExtractResult(reply);
return ExtractSongs(result);
SongList songs = ExtractSongs(result);
emit AlbumSongsLoaded(album_id, songs);
}
void GroovesharkService::DoSearch() {

View File

@ -113,7 +113,7 @@ class GroovesharkService : public InternetService {
int SimpleSearch(const QString& query);
int SearchAlbums(const QString& query);
SongList GetAlbumSongs(quint64 album_id);
void GetAlbumSongs(quint64 album_id);
static const char* kServiceName;
static const char* kSettingsGroup;
@ -121,8 +121,11 @@ class GroovesharkService : public InternetService {
signals:
void LoginFinished(bool success);
void SimpleSearchResults(int id, SongList songs);
void AlbumSearchResult(int id, QList<SongList> albums);
void AlbumSongsLoaded(int id, SongList songs);
// AlbumSearchResult emits the search id and the Grooveshark ids of the
// albums found. Albums' songs will be loaded asynchronously and
// AlbumSongsLoaded will be emitted, containing the actual Albums' songs.
void AlbumSearchResult(int id, QList<quint64> albums_ids);
void AlbumSongsLoaded(quint64 id, SongList songs);
public slots:
void ShowConfig();
@ -150,6 +153,7 @@ class GroovesharkService : public InternetService {
void SearchSongsFinished();
void SimpleSearchFinished();
void SearchAlbumsFinished(QNetworkReply* reply, int id);
void GetAlbumSongsFinished(QNetworkReply* reply, quint64 album_id);
void Authenticated();
void UserPlaylistsRetrieved();
void UserFavoritesRetrieved(QNetworkReply* reply, int task_id);