Add GS popular playlists

This commit is contained in:
Arnaud Bienner 2011-11-19 18:56:29 +01:00
parent f8ff785932
commit 4dec500c21
3 changed files with 665 additions and 648 deletions

View File

@ -80,6 +80,8 @@ GroovesharkService::GroovesharkService(InternetModel *parent)
next_pending_search_id_(0),
root_(NULL),
search_(NULL),
popular_month_(NULL),
popular_today_(NULL),
favorites_(NULL),
network_(new NetworkAccessManager(this)),
context_menu_(NULL),
@ -402,9 +404,11 @@ void GroovesharkService::Authenticated() {
void GroovesharkService::Logout() {
ResetSessionId();
root_->removeRows(0, root_->rowCount());
// 'search' and 'favorites' items were root's children, and have been deleted:
// we should update these now invalid pointers
// 'search', 'favorites' and 'popular' items were root's children, and have
// been deleted: we should update these now invalid pointers
search_ = NULL;
popular_month_ = NULL;
popular_today_ = NULL;
favorites_ = NULL;
playlists_.clear();
}
@ -487,6 +491,20 @@ void GroovesharkService::EnsureItemsCreated() {
InternetModel::Role_PlayBehaviour);
root_->appendRow(search_);
popular_month_ = new QStandardItem(QIcon(":/star-on.png"), tr("Popular songs of the Month"));
popular_month_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
popular_month_->setData(true, InternetModel::Role_CanLazyLoad);
popular_month_->setData(InternetModel::PlayBehaviour_SingleItem,
InternetModel::Role_PlayBehaviour);
root_->appendRow(popular_month_);
popular_today_ = new QStandardItem(QIcon(":/star-on.png"), tr("Popular songs today"));
popular_today_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
popular_today_->setData(true, InternetModel::Role_CanLazyLoad);
popular_today_->setData(InternetModel::PlayBehaviour_SingleItem,
InternetModel::Role_PlayBehaviour);
root_->appendRow(popular_today_);
favorites_ = new QStandardItem(QIcon(":/last.fm/love.png"), tr("Favorites"));
favorites_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
favorites_->setData(UserFavorites, Role_PlaylistType);
@ -498,6 +516,8 @@ void GroovesharkService::EnsureItemsCreated() {
RetrieveUserFavorites();
RetrieveUserPlaylists();
RetrievePopularSongsMonth();
RetrievePopularSongsToday();
}
}
@ -621,6 +641,52 @@ void GroovesharkService::UserFavoritesRetrieved() {
}
}
void GroovesharkService::RetrievePopularSongsMonth() {
QList<Param> parameters;
parameters << Param("limit", QString::number(kSongSearchLimit));
QNetworkReply* reply = CreateRequest("getPopularSongsMonth", parameters);
NewClosure(reply, SIGNAL(finished()),
this, SLOT(PopularSongsMonthRetrieved(QNetworkReply*)), reply);
}
void GroovesharkService::PopularSongsMonthRetrieved(QNetworkReply* reply) {
reply->deleteLater();
QVariantMap result = ExtractResult(reply);
SongList songs = ExtractSongs(result);
foreach (const Song& song, songs) {
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
child->setData(Type_Track, InternetModel::Role_Type);
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
child->setData(song.url(), InternetModel::Role_Url);
popular_month_->appendRow(child);
}
}
void GroovesharkService::RetrievePopularSongsToday() {
QList<Param> parameters;
parameters << Param("limit", QString::number(kSongSearchLimit));
QNetworkReply* reply = CreateRequest("getPopularSongsToday", parameters);
NewClosure(reply, SIGNAL(finished()),
this, SLOT(PopularSongsTodayRetrieved(QNetworkReply*)), reply);
}
void GroovesharkService::PopularSongsTodayRetrieved(QNetworkReply* reply) {
reply->deleteLater();
QVariantMap result = ExtractResult(reply);
SongList songs = ExtractSongs(result);
foreach (const Song& song, songs) {
QStandardItem* child = new QStandardItem(song.PrettyTitleWithArtist());
child->setData(Type_Track, InternetModel::Role_Type);
child->setData(QVariant::fromValue(song), InternetModel::Role_SongMetadata);
child->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
child->setData(song.url(), InternetModel::Role_Url);
popular_today_->appendRow(child);
}
}
void GroovesharkService::MarkStreamKeyOver30Secs(const QString& stream_key,
const QString& server_id) {
QList<Param> parameters;

View File

@ -78,6 +78,8 @@ class GroovesharkService : public InternetService {
bool IsLoggedIn() const { return !session_id_.isEmpty(); }
void RetrieveUserPlaylists();
void RetrieveUserFavorites();
void RetrievePopularSongsMonth();
void RetrievePopularSongsToday();
void SetPlaylistSongs(int playlist_id, const QList<int>& songs_ids);
void RemoveFromPlaylist(int playlist_id, int song_id);
// Refresh playlist_id playlist , or create it if it doesn't exist
@ -137,6 +139,8 @@ class GroovesharkService : public InternetService {
void Authenticated();
void UserPlaylistsRetrieved();
void UserFavoritesRetrieved();
void PopularSongsMonthRetrieved(QNetworkReply* reply);
void PopularSongsTodayRetrieved(QNetworkReply* reply);
void PlaylistSongsRetrieved();
void PlaylistSongsSet(QNetworkReply* reply, int playlist_id);
void CreateNewPlaylist();
@ -198,6 +202,8 @@ class GroovesharkService : public InternetService {
QStandardItem* root_;
QStandardItem* search_;
QStandardItem* popular_month_;
QStandardItem* popular_today_;
QStandardItem* favorites_;
NetworkAccessManager* network_;

File diff suppressed because it is too large Load Diff