Add GS popular playlists
This commit is contained in:
parent
f8ff785932
commit
4dec500c21
@ -80,6 +80,8 @@ GroovesharkService::GroovesharkService(InternetModel *parent)
|
|||||||
next_pending_search_id_(0),
|
next_pending_search_id_(0),
|
||||||
root_(NULL),
|
root_(NULL),
|
||||||
search_(NULL),
|
search_(NULL),
|
||||||
|
popular_month_(NULL),
|
||||||
|
popular_today_(NULL),
|
||||||
favorites_(NULL),
|
favorites_(NULL),
|
||||||
network_(new NetworkAccessManager(this)),
|
network_(new NetworkAccessManager(this)),
|
||||||
context_menu_(NULL),
|
context_menu_(NULL),
|
||||||
@ -402,9 +404,11 @@ void GroovesharkService::Authenticated() {
|
|||||||
void GroovesharkService::Logout() {
|
void GroovesharkService::Logout() {
|
||||||
ResetSessionId();
|
ResetSessionId();
|
||||||
root_->removeRows(0, root_->rowCount());
|
root_->removeRows(0, root_->rowCount());
|
||||||
// 'search' and 'favorites' items were root's children, and have been deleted:
|
// 'search', 'favorites' and 'popular' items were root's children, and have
|
||||||
// we should update these now invalid pointers
|
// been deleted: we should update these now invalid pointers
|
||||||
search_ = NULL;
|
search_ = NULL;
|
||||||
|
popular_month_ = NULL;
|
||||||
|
popular_today_ = NULL;
|
||||||
favorites_ = NULL;
|
favorites_ = NULL;
|
||||||
playlists_.clear();
|
playlists_.clear();
|
||||||
}
|
}
|
||||||
@ -487,6 +491,20 @@ void GroovesharkService::EnsureItemsCreated() {
|
|||||||
InternetModel::Role_PlayBehaviour);
|
InternetModel::Role_PlayBehaviour);
|
||||||
root_->appendRow(search_);
|
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_ = new QStandardItem(QIcon(":/last.fm/love.png"), tr("Favorites"));
|
||||||
favorites_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
|
favorites_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
|
||||||
favorites_->setData(UserFavorites, Role_PlaylistType);
|
favorites_->setData(UserFavorites, Role_PlaylistType);
|
||||||
@ -498,6 +516,8 @@ void GroovesharkService::EnsureItemsCreated() {
|
|||||||
|
|
||||||
RetrieveUserFavorites();
|
RetrieveUserFavorites();
|
||||||
RetrieveUserPlaylists();
|
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,
|
void GroovesharkService::MarkStreamKeyOver30Secs(const QString& stream_key,
|
||||||
const QString& server_id) {
|
const QString& server_id) {
|
||||||
QList<Param> parameters;
|
QList<Param> parameters;
|
||||||
|
@ -78,6 +78,8 @@ class GroovesharkService : public InternetService {
|
|||||||
bool IsLoggedIn() const { return !session_id_.isEmpty(); }
|
bool IsLoggedIn() const { return !session_id_.isEmpty(); }
|
||||||
void RetrieveUserPlaylists();
|
void RetrieveUserPlaylists();
|
||||||
void RetrieveUserFavorites();
|
void RetrieveUserFavorites();
|
||||||
|
void RetrievePopularSongsMonth();
|
||||||
|
void RetrievePopularSongsToday();
|
||||||
void SetPlaylistSongs(int playlist_id, const QList<int>& songs_ids);
|
void SetPlaylistSongs(int playlist_id, const QList<int>& songs_ids);
|
||||||
void RemoveFromPlaylist(int playlist_id, int song_id);
|
void RemoveFromPlaylist(int playlist_id, int song_id);
|
||||||
// Refresh playlist_id playlist , or create it if it doesn't exist
|
// Refresh playlist_id playlist , or create it if it doesn't exist
|
||||||
@ -137,6 +139,8 @@ class GroovesharkService : public InternetService {
|
|||||||
void Authenticated();
|
void Authenticated();
|
||||||
void UserPlaylistsRetrieved();
|
void UserPlaylistsRetrieved();
|
||||||
void UserFavoritesRetrieved();
|
void UserFavoritesRetrieved();
|
||||||
|
void PopularSongsMonthRetrieved(QNetworkReply* reply);
|
||||||
|
void PopularSongsTodayRetrieved(QNetworkReply* reply);
|
||||||
void PlaylistSongsRetrieved();
|
void PlaylistSongsRetrieved();
|
||||||
void PlaylistSongsSet(QNetworkReply* reply, int playlist_id);
|
void PlaylistSongsSet(QNetworkReply* reply, int playlist_id);
|
||||||
void CreateNewPlaylist();
|
void CreateNewPlaylist();
|
||||||
@ -198,6 +202,8 @@ class GroovesharkService : public InternetService {
|
|||||||
|
|
||||||
QStandardItem* root_;
|
QStandardItem* root_;
|
||||||
QStandardItem* search_;
|
QStandardItem* search_;
|
||||||
|
QStandardItem* popular_month_;
|
||||||
|
QStandardItem* popular_today_;
|
||||||
QStandardItem* favorites_;
|
QStandardItem* favorites_;
|
||||||
|
|
||||||
NetworkAccessManager* network_;
|
NetworkAccessManager* network_;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user