mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-27 01:54:20 +01:00
SoundCloud: retrieve user's playlists
This commit is contained in:
parent
ef01353a0f
commit
67951f64a5
@ -67,6 +67,7 @@ SoundCloudService::SoundCloudService(Application* app, InternetModel* parent)
|
|||||||
root_(nullptr),
|
root_(nullptr),
|
||||||
search_(nullptr),
|
search_(nullptr),
|
||||||
user_tracks_(nullptr),
|
user_tracks_(nullptr),
|
||||||
|
user_playlists_(nullptr),
|
||||||
user_activities_(nullptr),
|
user_activities_(nullptr),
|
||||||
network_(new NetworkAccessManager(this)),
|
network_(new NetworkAccessManager(this)),
|
||||||
context_menu_(nullptr),
|
context_menu_(nullptr),
|
||||||
@ -130,6 +131,10 @@ void SoundCloudService::EnsureItemsCreated() {
|
|||||||
user_activities_->setData(InternetModel::PlayBehaviour_MultipleItems,
|
user_activities_->setData(InternetModel::PlayBehaviour_MultipleItems,
|
||||||
InternetModel::Role_PlayBehaviour);
|
InternetModel::Role_PlayBehaviour);
|
||||||
root_->appendRow(user_activities_);
|
root_->appendRow(user_activities_);
|
||||||
|
|
||||||
|
user_playlists_ =
|
||||||
|
new QStandardItem(tr("Playlists"));
|
||||||
|
root_->appendRow(user_playlists_);
|
||||||
RetrieveUserData(); // at least, try to (this will do nothing if user isn't logged)
|
RetrieveUserData(); // at least, try to (this will do nothing if user isn't logged)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,14 +203,18 @@ void SoundCloudService::Logout() {
|
|||||||
root_->removeRow(user_activities_->row());
|
root_->removeRow(user_activities_->row());
|
||||||
if (user_tracks_)
|
if (user_tracks_)
|
||||||
root_->removeRow(user_tracks_->row());
|
root_->removeRow(user_tracks_->row());
|
||||||
|
if (user_playlists_)
|
||||||
|
root_->removeRow(user_playlists_->row());
|
||||||
user_activities_ = nullptr;
|
user_activities_ = nullptr;
|
||||||
user_tracks_ = nullptr;
|
user_tracks_ = nullptr;
|
||||||
|
user_playlists_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundCloudService::RetrieveUserData() {
|
void SoundCloudService::RetrieveUserData() {
|
||||||
LoadAccessTokenIfEmpty();
|
LoadAccessTokenIfEmpty();
|
||||||
RetrieveUserTracks();
|
RetrieveUserTracks();
|
||||||
RetrieveUserActivities();
|
RetrieveUserActivities();
|
||||||
|
RetrieveUserPlaylists();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundCloudService::RetrieveUserTracks() {
|
void SoundCloudService::RetrieveUserTracks() {
|
||||||
@ -245,6 +254,31 @@ void SoundCloudService::UserActivitiesRetrieved(QNetworkReply* reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundCloudService::RetrieveUserPlaylists() {
|
||||||
|
QList<Param> parameters;
|
||||||
|
parameters << Param("oauth_token", access_token_);
|
||||||
|
QNetworkReply* reply = CreateRequest("me/playlists", parameters);
|
||||||
|
NewClosure(reply, SIGNAL(finished()), this,
|
||||||
|
SLOT(UserPlaylistsRetrieved(QNetworkReply*)), reply);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundCloudService::UserPlaylistsRetrieved(QNetworkReply* reply) {
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
QList<QVariant> playlists = ExtractResult(reply).toList();
|
||||||
|
for (const QVariant& playlist : playlists) {
|
||||||
|
QMap<QString, QVariant> playlist_map = playlist.toMap();
|
||||||
|
|
||||||
|
QStandardItem* playlist_item = CreatePlaylistItem(playlist_map["title"].toString());
|
||||||
|
SongList songs = ExtractSongs(playlist_map["tracks"]);
|
||||||
|
for (const Song& song : songs) {
|
||||||
|
playlist_item->appendRow(CreateSongItem(song));
|
||||||
|
}
|
||||||
|
user_playlists_->appendRow(playlist_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SoundCloudService::Search(const QString& text, bool now) {
|
void SoundCloudService::Search(const QString& text, bool now) {
|
||||||
pending_search_ = text;
|
pending_search_ = text;
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class SoundCloudService : public InternetService {
|
|||||||
void ConnectFinished(OAuthenticator* oauth);
|
void ConnectFinished(OAuthenticator* oauth);
|
||||||
void UserTracksRetrieved(QNetworkReply* reply);
|
void UserTracksRetrieved(QNetworkReply* reply);
|
||||||
void UserActivitiesRetrieved(QNetworkReply* reply);
|
void UserActivitiesRetrieved(QNetworkReply* reply);
|
||||||
|
void UserPlaylistsRetrieved(QNetworkReply* reply);
|
||||||
void PlaylistRetrieved(QNetworkReply* reply, int request_id);
|
void PlaylistRetrieved(QNetworkReply* reply, int request_id);
|
||||||
void Search(const QString& text, bool now = false);
|
void Search(const QString& text, bool now = false);
|
||||||
void DoSearch();
|
void DoSearch();
|
||||||
@ -87,6 +88,7 @@ class SoundCloudService : public InternetService {
|
|||||||
void RetrieveUserData();
|
void RetrieveUserData();
|
||||||
void RetrieveUserTracks();
|
void RetrieveUserTracks();
|
||||||
void RetrieveUserActivities();
|
void RetrieveUserActivities();
|
||||||
|
void RetrieveUserPlaylists();
|
||||||
void RetrievePlaylist(int playlist_id, QStandardItem* playlist_item);
|
void RetrievePlaylist(int playlist_id, QStandardItem* playlist_item);
|
||||||
void ClearSearchResults();
|
void ClearSearchResults();
|
||||||
void EnsureItemsCreated();
|
void EnsureItemsCreated();
|
||||||
@ -106,6 +108,7 @@ class SoundCloudService : public InternetService {
|
|||||||
QStandardItem* root_;
|
QStandardItem* root_;
|
||||||
QStandardItem* search_;
|
QStandardItem* search_;
|
||||||
QStandardItem* user_tracks_;
|
QStandardItem* user_tracks_;
|
||||||
|
QStandardItem* user_playlists_;
|
||||||
QStandardItem* user_activities_;
|
QStandardItem* user_activities_;
|
||||||
|
|
||||||
NetworkAccessManager* network_;
|
NetworkAccessManager* network_;
|
||||||
|
Loading…
Reference in New Issue
Block a user