From 7ef095d0cb30e93a6ce6e297e94e31287d959045 Mon Sep 17 00:00:00 2001 From: Vavooon Date: Wed, 20 Apr 2016 14:03:48 +0200 Subject: [PATCH] Add Favorites support to SoundCloud (#5345) --- src/internet/soundcloud/soundcloudservice.cpp | 24 +++++++++++++++++++ src/internet/soundcloud/soundcloudservice.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/internet/soundcloud/soundcloudservice.cpp b/src/internet/soundcloud/soundcloudservice.cpp index 6d8dd65f4..861979e31 100644 --- a/src/internet/soundcloud/soundcloudservice.cpp +++ b/src/internet/soundcloud/soundcloudservice.cpp @@ -137,6 +137,10 @@ void SoundCloudService::EnsureItemsCreated() { InternetModel::Role_PlayBehaviour); root_->appendRow(user_tracks_); + + user_favorites_ = new QStandardItem(tr("Favorites")); + root_->appendRow(user_favorites_); + RetrieveUserData(); // at least, try to (this will do nothing if user isn't // logged) } @@ -214,6 +218,7 @@ void SoundCloudService::RetrieveUserData() { RetrieveUserActivities(); RetrieveUserTracks(); RetrieveUserPlaylists(); + RetrieveUserFavorites(); } void SoundCloudService::RetrieveUserTracks() { @@ -261,6 +266,14 @@ void SoundCloudService::RetrieveUserPlaylists() { SLOT(UserPlaylistsRetrieved(QNetworkReply*)), reply); } +void SoundCloudService::RetrieveUserFavorites() { + QList parameters; + parameters << Param("oauth_token", access_token_); + QNetworkReply* reply = CreateRequest("me/favorites", parameters); + NewClosure(reply, SIGNAL(finished()), this, + SLOT(UserFavoritesRetrieved(QNetworkReply*)), reply); +} + void SoundCloudService::UserPlaylistsRetrieved(QNetworkReply* reply) { reply->deleteLater(); @@ -277,6 +290,17 @@ void SoundCloudService::UserPlaylistsRetrieved(QNetworkReply* reply) { } } +void SoundCloudService::UserFavoritesRetrieved(QNetworkReply* reply) { + reply->deleteLater(); + + SongList songs = ExtractSongs(ExtractResult(reply)); + // Fill results list + for (const Song& song : songs) { + QStandardItem* child = CreateSongItem(song); + user_favorites_->appendRow(child); + } +} + void SoundCloudService::Search(const QString& text, bool now) { pending_search_ = text; diff --git a/src/internet/soundcloud/soundcloudservice.h b/src/internet/soundcloud/soundcloudservice.h index a806204b4..3ebcb1f96 100644 --- a/src/internet/soundcloud/soundcloudservice.h +++ b/src/internet/soundcloud/soundcloudservice.h @@ -67,6 +67,7 @@ class SoundCloudService : public InternetService { void UserTracksRetrieved(QNetworkReply* reply); void UserActivitiesRetrieved(QNetworkReply* reply); void UserPlaylistsRetrieved(QNetworkReply* reply); + void UserFavoritesRetrieved(QNetworkReply* reply); void PlaylistRetrieved(QNetworkReply* reply, int request_id); void Search(const QString& text, bool now = false); void DoSearch(); @@ -91,6 +92,7 @@ class SoundCloudService : public InternetService { void RetrieveUserTracks(); void RetrieveUserActivities(); void RetrieveUserPlaylists(); + void RetrieveUserFavorites(); void RetrievePlaylist(int playlist_id, QStandardItem* playlist_item); void ClearSearchResults(); void EnsureItemsCreated(); @@ -112,6 +114,7 @@ class SoundCloudService : public InternetService { QStandardItem* user_tracks_; QStandardItem* user_playlists_; QStandardItem* user_activities_; + QStandardItem* user_favorites_; NetworkAccessManager* network_;