Sort GS playlist by name. Fixes issue 2398.
This commit is contained in:
parent
14cba7e704
commit
aaef0de224
|
@ -648,14 +648,11 @@ void GroovesharkService::UserPlaylistsRetrieved() {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QVariantMap result = ExtractResult(reply);
|
QVariantMap result = ExtractResult(reply);
|
||||||
QVariantList playlists = result["playlists"].toList();
|
QList<PlaylistInfo> playlists = ExtractPlaylistInfo(result);
|
||||||
|
|
||||||
foreach (const QVariant& playlist_variant, playlists) {
|
|
||||||
// Get playlist info
|
|
||||||
QVariantMap playlist = playlist_variant.toMap();
|
|
||||||
int playlist_id = playlist["PlaylistID"].toInt();
|
|
||||||
QString playlist_name = playlist["PlaylistName"].toString();
|
|
||||||
|
|
||||||
|
foreach(const PlaylistInfo& playlist_info, playlists) {
|
||||||
|
int playlist_id = playlist_info.id_;
|
||||||
|
const QString& playlist_name = playlist_info.name_;
|
||||||
QStandardItem* playlist_item =
|
QStandardItem* playlist_item =
|
||||||
CreatePlaylistItem(playlist_name, playlist_id);
|
CreatePlaylistItem(playlist_name, playlist_id);
|
||||||
// Insert this new item just below the favorites list
|
// Insert this new item just below the favorites list
|
||||||
|
@ -811,14 +808,13 @@ void GroovesharkService::RetrieveSubscribedPlaylists() {
|
||||||
|
|
||||||
void GroovesharkService::SubscribedPlaylistsRetrieved(QNetworkReply* reply) {
|
void GroovesharkService::SubscribedPlaylistsRetrieved(QNetworkReply* reply) {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QVariantMap result = ExtractResult(reply);
|
QVariantMap result = ExtractResult(reply);
|
||||||
QVariantList playlists = result["playlists"].toList();
|
QList<PlaylistInfo> playlists = ExtractPlaylistInfo(result);
|
||||||
QVariantList::iterator it;
|
|
||||||
for (it = playlists.begin(); it != playlists.end(); ++it) {
|
foreach(const PlaylistInfo& playlist_info, playlists) {
|
||||||
// Get playlist info
|
int playlist_id = playlist_info.id_;
|
||||||
QVariantMap playlist = (*it).toMap();
|
const QString& playlist_name = playlist_info.name_;
|
||||||
int playlist_id = playlist["PlaylistID"].toInt();
|
|
||||||
QString playlist_name = playlist["PlaylistName"].toString();
|
|
||||||
|
|
||||||
QStandardItem* playlist_item = CreatePlaylistItem(playlist_name, playlist_id);
|
QStandardItem* playlist_item = CreatePlaylistItem(playlist_name, playlist_id);
|
||||||
// Refine some playlist properties that should be different for subscribed
|
// Refine some playlist properties that should be different for subscribed
|
||||||
|
@ -1605,3 +1601,23 @@ int GroovesharkService::ExtractSongId(const QUrl& url) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<GroovesharkService::PlaylistInfo> GroovesharkService::ExtractPlaylistInfo(const QVariantMap& result) {
|
||||||
|
QVariantList playlists_qvariant = result["playlists"].toList();
|
||||||
|
|
||||||
|
QList<PlaylistInfo> playlists;
|
||||||
|
|
||||||
|
// Get playlists info
|
||||||
|
foreach (const QVariant& playlist_qvariant, playlists_qvariant) {
|
||||||
|
QVariantMap playlist = playlist_qvariant.toMap();
|
||||||
|
int playlist_id = playlist["PlaylistID"].toInt();
|
||||||
|
QString playlist_name = playlist["PlaylistName"].toString();
|
||||||
|
|
||||||
|
playlists << PlaylistInfo(playlist_id, playlist_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort playlists by name
|
||||||
|
qSort(playlists.begin(), playlists.end(), qGreater<PlaylistInfo>());
|
||||||
|
|
||||||
|
return playlists;
|
||||||
|
}
|
||||||
|
|
|
@ -134,9 +134,13 @@ class GroovesharkService : public InternetService {
|
||||||
protected:
|
protected:
|
||||||
struct PlaylistInfo {
|
struct PlaylistInfo {
|
||||||
PlaylistInfo() {}
|
PlaylistInfo() {}
|
||||||
PlaylistInfo(int id, QString name, QStandardItem* item)
|
PlaylistInfo(int id, QString name, QStandardItem* item = NULL)
|
||||||
: id_(id), name_(name), item_(item) {}
|
: id_(id), name_(name), item_(item) {}
|
||||||
|
|
||||||
|
bool operator< (const PlaylistInfo other) const {
|
||||||
|
return name_.compare(other.name_, Qt::CaseInsensitive) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
int id_;
|
int id_;
|
||||||
QString name_;
|
QString name_;
|
||||||
QStandardItem* item_;
|
QStandardItem* item_;
|
||||||
|
@ -222,6 +226,9 @@ class GroovesharkService : public InternetService {
|
||||||
QList<int> ExtractSongsIds(const QVariantMap& result);
|
QList<int> ExtractSongsIds(const QVariantMap& result);
|
||||||
QList<int> ExtractSongsIds(const QList<QUrl>& urls);
|
QList<int> ExtractSongsIds(const QList<QUrl>& urls);
|
||||||
int ExtractSongId(const QUrl& url); // Returns 0 if url is not a Grooveshark url
|
int ExtractSongId(const QUrl& url); // Returns 0 if url is not a Grooveshark url
|
||||||
|
// Convenient function for extracting basic playlist info (only 'id' and
|
||||||
|
// 'name': QStandardItem still need to be created), and sort them by name
|
||||||
|
QList<PlaylistInfo> ExtractPlaylistInfo(const QVariantMap& result);
|
||||||
|
|
||||||
void ResetSessionId();
|
void ResetSessionId();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue