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:
parent
2bc616be0b
commit
0969432820
|
@ -39,10 +39,10 @@ void GroovesharkSearchProvider::Init(GroovesharkService* service) {
|
||||||
|
|
||||||
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
|
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
|
||||||
SLOT(SearchDone(int, SongList)));
|
SLOT(SearchDone(int, SongList)));
|
||||||
connect(service_, SIGNAL(AlbumSearchResult(int, QList<SongList>)),
|
connect(service_, SIGNAL(AlbumSearchResult(int, QList<quint64>)),
|
||||||
SLOT(AlbumSearchResult(int, QList<SongList>)));
|
SLOT(AlbumSearchResult(int, QList<quint64>)));
|
||||||
connect(service_, SIGNAL(AlbumSongsLoaded(int, SongList)),
|
connect(service_, SIGNAL(AlbumSongsLoaded(quint64, SongList)),
|
||||||
SLOT(AlbumSongsLoaded(int, SongList)));
|
SLOT(AlbumSongsLoaded(quint64, SongList)));
|
||||||
|
|
||||||
cover_loader_options_.desired_height_ = kArtHeight;
|
cover_loader_options_.desired_height_ = kArtHeight;
|
||||||
cover_loader_options_.pad_output_image_ = true;
|
cover_loader_options_.pad_output_image_ = true;
|
||||||
|
@ -83,35 +83,18 @@ void GroovesharkSearchProvider::SearchDone(int id, const SongList& songs) {
|
||||||
MaybeSearchFinished(global_search_id);
|
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.
|
// Map back to the original id.
|
||||||
const PendingState state = pending_searches_.take(id);
|
const PendingState state = pending_searches_.take(id);
|
||||||
const int global_search_id = state.orig_id_;
|
const int global_search_id = state.orig_id_;
|
||||||
|
if (albums_ids.isEmpty()) {
|
||||||
ResultList ret;
|
MaybeSearchFinished(global_search_id);
|
||||||
foreach (const SongList& a, albums) {
|
return;
|
||||||
if (a.isEmpty())
|
}
|
||||||
continue;
|
foreach (const quint64 album_id, albums_ids) {
|
||||||
Result result(this);
|
pending_searches_[album_id] = PendingState(global_search_id, QStringList());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit ResultsAvailable(global_search_id, ret);
|
|
||||||
MaybeSearchFinished(global_search_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroovesharkSearchProvider::MaybeSearchFinished(int id) {
|
void GroovesharkSearchProvider::MaybeSearchFinished(int id) {
|
||||||
|
@ -171,10 +154,28 @@ void GroovesharkSearchProvider::ShowConfig() {
|
||||||
service_->ShowConfig();
|
service_->ShowConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroovesharkSearchProvider::AlbumSongsLoaded(int id, const SongList& songs) {
|
void GroovesharkSearchProvider::AlbumSongsLoaded(quint64 id, const SongList& songs) {
|
||||||
InternetSongMimeData* mime_data = new InternetSongMimeData(service_);
|
const PendingState state = pending_searches_.take(id);
|
||||||
mime_data->songs = songs;
|
const int global_search_id = state.orig_id_;
|
||||||
SortSongs(&mime_data->songs);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ class GroovesharkSearchProvider : public SearchProvider {
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void SearchDone(int id, const SongList& songs);
|
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 AlbumArtLoaded(quint64 id, const QImage& image);
|
||||||
void AlbumSongsLoaded(int id, const SongList& songs);
|
void AlbumSongsLoaded(quint64 id, const SongList& songs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MaybeSearchFinished(int id);
|
void MaybeSearchFinished(int id);
|
||||||
|
|
|
@ -229,31 +229,32 @@ void GroovesharkService::SearchAlbumsFinished(QNetworkReply* reply, int id) {
|
||||||
QVariantMap result = ExtractResult(reply);
|
QVariantMap result = ExtractResult(reply);
|
||||||
QVariantList albums = result["albums"].toList();
|
QVariantList albums = result["albums"].toList();
|
||||||
|
|
||||||
QList<SongList> ret;
|
QList<quint64> ret;
|
||||||
foreach (const QVariant& v, albums) {
|
foreach (const QVariant& v, albums) {
|
||||||
QVariantMap album = v.toMap();
|
quint64 album_id = v.toMap()["AlbumID"].toULongLong();
|
||||||
quint64 album_id = album["AlbumID"].toULongLong();
|
GetAlbumSongs(album_id);
|
||||||
QString album_name = album["AlbumName"].toString();
|
ret << album_id;
|
||||||
QString artist_name = album["ArtistName"].toString();
|
|
||||||
QString cover_art = album["CoverArtFilename"].toString();
|
|
||||||
|
|
||||||
qLog(Debug) << "Found:" << album_name << artist_name;
|
|
||||||
|
|
||||||
ret << GetAlbumSongs(album_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit AlbumSearchResult(id, ret);
|
emit AlbumSearchResult(id, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
SongList GroovesharkService::GetAlbumSongs(quint64 album_id) {
|
void GroovesharkService::GetAlbumSongs(quint64 album_id) {
|
||||||
QList<Param> parameters;
|
QList<Param> parameters;
|
||||||
parameters << Param("albumID", album_id)
|
parameters << Param("albumID", album_id)
|
||||||
<< Param("country", "");
|
<< Param("country", "");
|
||||||
QNetworkReply* reply = CreateRequest("getAlbumSongs", parameters);
|
QNetworkReply* reply = CreateRequest("getAlbumSongs", parameters);
|
||||||
if (!WaitForReply(reply))
|
NewClosure(reply, SIGNAL(finished()),
|
||||||
return SongList();
|
this, SLOT(GetAlbumSongsFinished(QNetworkReply*,quint64)),
|
||||||
|
reply, album_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroovesharkService::GetAlbumSongsFinished(QNetworkReply* reply, quint64 album_id) {
|
||||||
|
reply->deleteLater();
|
||||||
QVariantMap result = ExtractResult(reply);
|
QVariantMap result = ExtractResult(reply);
|
||||||
return ExtractSongs(result);
|
SongList songs = ExtractSongs(result);
|
||||||
|
|
||||||
|
emit AlbumSongsLoaded(album_id, songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroovesharkService::DoSearch() {
|
void GroovesharkService::DoSearch() {
|
||||||
|
|
|
@ -113,7 +113,7 @@ class GroovesharkService : public InternetService {
|
||||||
|
|
||||||
int SimpleSearch(const QString& query);
|
int SimpleSearch(const QString& query);
|
||||||
int SearchAlbums(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* kServiceName;
|
||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
|
@ -121,8 +121,11 @@ class GroovesharkService : public InternetService {
|
||||||
signals:
|
signals:
|
||||||
void LoginFinished(bool success);
|
void LoginFinished(bool success);
|
||||||
void SimpleSearchResults(int id, SongList songs);
|
void SimpleSearchResults(int id, SongList songs);
|
||||||
void AlbumSearchResult(int id, QList<SongList> albums);
|
// AlbumSearchResult emits the search id and the Grooveshark ids of the
|
||||||
void AlbumSongsLoaded(int id, SongList songs);
|
// 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:
|
public slots:
|
||||||
void ShowConfig();
|
void ShowConfig();
|
||||||
|
@ -150,6 +153,7 @@ class GroovesharkService : public InternetService {
|
||||||
void SearchSongsFinished();
|
void SearchSongsFinished();
|
||||||
void SimpleSearchFinished();
|
void SimpleSearchFinished();
|
||||||
void SearchAlbumsFinished(QNetworkReply* reply, int id);
|
void SearchAlbumsFinished(QNetworkReply* reply, int id);
|
||||||
|
void GetAlbumSongsFinished(QNetworkReply* reply, quint64 album_id);
|
||||||
void Authenticated();
|
void Authenticated();
|
||||||
void UserPlaylistsRetrieved();
|
void UserPlaylistsRetrieved();
|
||||||
void UserFavoritesRetrieved(QNetworkReply* reply, int task_id);
|
void UserFavoritesRetrieved(QNetworkReply* reply, int task_id);
|
||||||
|
|
Loading…
Reference in New Issue