mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-03 04:37:33 +01:00
Support toplists in the ui.
This commit is contained in:
parent
215595bfdb
commit
afd42118f1
@ -148,6 +148,8 @@ void SpotifyServer::MessageArrived(const pb::spotify::Message& message) {
|
|||||||
emit SyncPlaylistProgress(message.sync_playlist_progress());
|
emit SyncPlaylistProgress(message.sync_playlist_progress());
|
||||||
} else if (message.has_browse_album_response()) {
|
} else if (message.has_browse_album_response()) {
|
||||||
emit AlbumBrowseResults(message.browse_album_response());
|
emit AlbumBrowseResults(message.browse_album_response());
|
||||||
|
} else if (message.has_browse_toplist_response()) {
|
||||||
|
emit ToplistBrowseResults(message.browse_toplist_response());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,3 +256,12 @@ void SpotifyServer::AlbumBrowse(const QString& uri) {
|
|||||||
req->set_uri(DataCommaSizeFromQString(uri));
|
req->set_uri(DataCommaSizeFromQString(uri));
|
||||||
SendOrQueueMessage(message);
|
SendOrQueueMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpotifyServer::LoadToplist() {
|
||||||
|
pb::spotify::Message message;
|
||||||
|
pb::spotify::BrowseToplistRequest* req = message.mutable_browse_toplist_request();
|
||||||
|
req->set_type(pb::spotify::BrowseToplistRequest::Tracks);
|
||||||
|
req->set_region(pb::spotify::BrowseToplistRequest::Everywhere);
|
||||||
|
|
||||||
|
SendOrQueueMessage(message);
|
||||||
|
}
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
void LoadImage(const QString& id);
|
void LoadImage(const QString& id);
|
||||||
void AlbumBrowse(const QString& uri);
|
void AlbumBrowse(const QString& uri);
|
||||||
void SetPlaybackSettings(pb::spotify::Bitrate bitrate, bool volume_normalisation);
|
void SetPlaybackSettings(pb::spotify::Bitrate bitrate, bool volume_normalisation);
|
||||||
|
void LoadToplist();
|
||||||
|
|
||||||
int server_port() const;
|
int server_port() const;
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ signals:
|
|||||||
void ImageLoaded(const QString& id, const QImage& image);
|
void ImageLoaded(const QString& id, const QImage& image);
|
||||||
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
||||||
void AlbumBrowseResults(const pb::spotify::BrowseAlbumResponse& response);
|
void AlbumBrowseResults(const pb::spotify::BrowseAlbumResponse& response);
|
||||||
|
void ToplistBrowseResults(const pb::spotify::BrowseToplistResponse& response);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void MessageArrived(const pb::spotify::Message& message);
|
void MessageArrived(const pb::spotify::Message& message);
|
||||||
|
@ -45,6 +45,7 @@ SpotifyService::SpotifyService(Application* app, InternetModel* parent)
|
|||||||
search_(NULL),
|
search_(NULL),
|
||||||
starred_(NULL),
|
starred_(NULL),
|
||||||
inbox_(NULL),
|
inbox_(NULL),
|
||||||
|
toplist_(NULL),
|
||||||
login_task_id_(0),
|
login_task_id_(0),
|
||||||
pending_search_playlist_(NULL),
|
pending_search_playlist_(NULL),
|
||||||
context_menu_(NULL),
|
context_menu_(NULL),
|
||||||
@ -119,6 +120,11 @@ void SpotifyService::LazyPopulate(QStandardItem* item) {
|
|||||||
server_->LoadUserPlaylist(item->data(Role_UserPlaylistIndex).toInt());
|
server_->LoadUserPlaylist(item->data(Role_UserPlaylistIndex).toInt());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Type_Toplist:
|
||||||
|
EnsureServerCreated();
|
||||||
|
server_->LoadToplist();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -237,6 +243,8 @@ void SpotifyService::EnsureServerCreated(const QString& username,
|
|||||||
SIGNAL(ImageLoaded(QString,QImage)));
|
SIGNAL(ImageLoaded(QString,QImage)));
|
||||||
connect(server_, SIGNAL(SyncPlaylistProgress(pb::spotify::SyncPlaylistProgress)),
|
connect(server_, SIGNAL(SyncPlaylistProgress(pb::spotify::SyncPlaylistProgress)),
|
||||||
SLOT(SyncPlaylistProgress(pb::spotify::SyncPlaylistProgress)));
|
SLOT(SyncPlaylistProgress(pb::spotify::SyncPlaylistProgress)));
|
||||||
|
connect(server_, SIGNAL(ToplistBrowseResults(pb::spotify::BrowseToplistResponse)),
|
||||||
|
SLOT(ToplistLoaded(pb::spotify::BrowseToplistResponse)));
|
||||||
|
|
||||||
server_->Init();
|
server_->Init();
|
||||||
|
|
||||||
@ -345,7 +353,12 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
|
|||||||
inbox_->setData(Type_InboxPlaylist, InternetModel::Role_Type);
|
inbox_->setData(Type_InboxPlaylist, InternetModel::Role_Type);
|
||||||
inbox_->setData(true, InternetModel::Role_CanLazyLoad);
|
inbox_->setData(true, InternetModel::Role_CanLazyLoad);
|
||||||
|
|
||||||
|
toplist_ = new QStandardItem(QIcon(), tr("Top tracks"));
|
||||||
|
toplist_->setData(Type_Toplist, InternetModel::Role_Type);
|
||||||
|
toplist_->setData(true, InternetModel::Role_CanLazyLoad);
|
||||||
|
|
||||||
root_->appendRow(search_);
|
root_->appendRow(search_);
|
||||||
|
root_->appendRow(toplist_);
|
||||||
root_->appendRow(starred_);
|
root_->appendRow(starred_);
|
||||||
root_->appendRow(inbox_);
|
root_->appendRow(inbox_);
|
||||||
}
|
}
|
||||||
@ -408,6 +421,10 @@ void SpotifyService::StarredLoaded(const pb::spotify::LoadPlaylistResponse& resp
|
|||||||
FillPlaylist(starred_, response);
|
FillPlaylist(starred_, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpotifyService::ToplistLoaded(const pb::spotify::BrowseToplistResponse& response) {
|
||||||
|
FillPlaylist(toplist_, response.track());
|
||||||
|
}
|
||||||
|
|
||||||
QStandardItem* SpotifyService::PlaylistBySpotifyIndex(int index) const {
|
QStandardItem* SpotifyService::PlaylistBySpotifyIndex(int index) const {
|
||||||
foreach (QStandardItem* item, playlists_) {
|
foreach (QStandardItem* item, playlists_) {
|
||||||
if (item->data(Role_UserPlaylistIndex).toInt() == index) {
|
if (item->data(Role_UserPlaylistIndex).toInt() == index) {
|
||||||
@ -425,14 +442,15 @@ void SpotifyService::UserPlaylistLoaded(const pb::spotify::LoadPlaylistResponse&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpotifyService::FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response) {
|
void SpotifyService::FillPlaylist(
|
||||||
qLog(Debug) << "Filling playlist:" << item->text();
|
QStandardItem* item,
|
||||||
|
const google::protobuf::RepeatedPtrField<pb::spotify::Track>& tracks) {
|
||||||
if (item->hasChildren())
|
if (item->hasChildren())
|
||||||
item->removeRows(0, item->rowCount());
|
item->removeRows(0, item->rowCount());
|
||||||
|
|
||||||
for (int i=0 ; i<response.track_size() ; ++i) {
|
for (int i=0 ; i < tracks.size() ; ++i) {
|
||||||
Song song;
|
Song song;
|
||||||
SongFromProtobuf(response.track(i), &song);
|
SongFromProtobuf(tracks.Get(i), &song);
|
||||||
|
|
||||||
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
|
||||||
child->setData(Type_Track, InternetModel::Role_Type);
|
child->setData(Type_Track, InternetModel::Role_Type);
|
||||||
@ -444,6 +462,11 @@ void SpotifyService::FillPlaylist(QStandardItem* item, const pb::spotify::LoadPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpotifyService::FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response) {
|
||||||
|
qLog(Debug) << "Filling playlist:" << item->text();
|
||||||
|
FillPlaylist(item, response.track());
|
||||||
|
}
|
||||||
|
|
||||||
void SpotifyService::SongFromProtobuf(const pb::spotify::Track& track, Song* song) {
|
void SpotifyService::SongFromProtobuf(const pb::spotify::Track& track, Song* song) {
|
||||||
song->set_rating(track.starred() ? 1.0 : 0.0);
|
song->set_rating(track.starred() ? 1.0 : 0.0);
|
||||||
song->set_title(QStringFromStdString(track.title()));
|
song->set_title(QStringFromStdString(track.title()));
|
||||||
|
@ -27,6 +27,7 @@ public:
|
|||||||
Type_StarredPlaylist,
|
Type_StarredPlaylist,
|
||||||
Type_InboxPlaylist,
|
Type_InboxPlaylist,
|
||||||
Type_Track,
|
Type_Track,
|
||||||
|
Type_Toplist,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Role {
|
enum Role {
|
||||||
@ -83,6 +84,9 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void StartBlobProcess();
|
void StartBlobProcess();
|
||||||
|
void FillPlaylist(
|
||||||
|
QStandardItem* item,
|
||||||
|
const google::protobuf::RepeatedPtrField<pb::spotify::Track>& tracks);
|
||||||
void FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response);
|
void FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response);
|
||||||
void EnsureMenuCreated();
|
void EnsureMenuCreated();
|
||||||
|
|
||||||
@ -101,6 +105,7 @@ private slots:
|
|||||||
void UserPlaylistLoaded(const pb::spotify::LoadPlaylistResponse& response);
|
void UserPlaylistLoaded(const pb::spotify::LoadPlaylistResponse& response);
|
||||||
void SearchResults(const pb::spotify::SearchResponse& response);
|
void SearchResults(const pb::spotify::SearchResponse& response);
|
||||||
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
||||||
|
void ToplistLoaded(const pb::spotify::BrowseToplistResponse& response);
|
||||||
|
|
||||||
void OpenSearchTab();
|
void OpenSearchTab();
|
||||||
void DoSearch();
|
void DoSearch();
|
||||||
@ -120,6 +125,7 @@ private:
|
|||||||
QStandardItem* search_;
|
QStandardItem* search_;
|
||||||
QStandardItem* starred_;
|
QStandardItem* starred_;
|
||||||
QStandardItem* inbox_;
|
QStandardItem* inbox_;
|
||||||
|
QStandardItem* toplist_;
|
||||||
QList<QStandardItem*> playlists_;
|
QList<QStandardItem*> playlists_;
|
||||||
|
|
||||||
int login_task_id_;
|
int login_task_id_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user