Add an option to sort Grooveshark playlist alphabetically. Fixes issue #3480.
Did it the lazy way for now, but it would have better to refactor Grooveshark code, to add a proper sort model, etc.
This commit is contained in:
parent
d03c1aa241
commit
fddb87ba63
@ -723,7 +723,7 @@ void GroovesharkService::PlaylistSongsRetrieved(QNetworkReply* reply,
|
||||
|
||||
QVariantMap result = ExtractResult(reply);
|
||||
SongList songs = ExtractSongs(result);
|
||||
Song::SortSongsListAlphabetically(&songs);
|
||||
SortSongsAlphabeticallyIfNeeded(&songs);
|
||||
|
||||
for (const Song& song : songs) {
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
@ -764,7 +764,7 @@ void GroovesharkService::UserFavoritesRetrieved(QNetworkReply* reply,
|
||||
|
||||
QVariantMap result = ExtractResult(reply);
|
||||
SongList songs = ExtractSongs(result);
|
||||
Song::SortSongsListAlphabetically(&songs);
|
||||
SortSongsAlphabeticallyIfNeeded(&songs);
|
||||
|
||||
for (const Song& song : songs) {
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
@ -798,7 +798,7 @@ void GroovesharkService::UserLibrarySongsRetrieved(QNetworkReply* reply,
|
||||
|
||||
QVariantMap result = ExtractResult(reply);
|
||||
SongList songs = ExtractSongs(result);
|
||||
Song::SortSongsListAlphabetically(&songs);
|
||||
SortSongsAlphabeticallyIfNeeded(&songs);
|
||||
|
||||
for (const Song& song : songs) {
|
||||
QStandardItem* child = CreateSongItem(song);
|
||||
@ -1704,8 +1704,15 @@ QVariantMap GroovesharkService::ExtractResult(QNetworkReply* reply) {
|
||||
return result["result"].toMap();
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool CompareSongs(const QVariant& song1, const QVariant& song2) {
|
||||
return song1.toMap()["Sort"].toInt() < song1.toMap()["Sort"].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
SongList GroovesharkService::ExtractSongs(const QVariantMap& result) {
|
||||
QVariantList result_songs = result["songs"].toList();
|
||||
qStableSort(result_songs.begin(), result_songs.end(), CompareSongs);
|
||||
SongList songs;
|
||||
for (int i = 0; i < result_songs.size(); ++i) {
|
||||
QVariantMap result_song = result_songs[i].toMap();
|
||||
@ -1805,3 +1812,12 @@ QList<GroovesharkService::PlaylistInfo> GroovesharkService::ExtractPlaylistInfo(
|
||||
|
||||
return playlists;
|
||||
}
|
||||
|
||||
void GroovesharkService::SortSongsAlphabeticallyIfNeeded(SongList* songs) const {
|
||||
QSettings s;
|
||||
s.beginGroup(GroovesharkService::kSettingsGroup);
|
||||
const bool sort_songs_alphabetically = s.value("sort_alphabetically").toBool();
|
||||
if (sort_songs_alphabetically) {
|
||||
Song::SortSongsListAlphabetically(songs);
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,8 @@ signals:
|
||||
public slots:
|
||||
void Search(const QString& text, bool now = false);
|
||||
void ShowConfig();
|
||||
// Refresh all Grooveshark's items, and re-fill them
|
||||
void RefreshItems();
|
||||
|
||||
protected:
|
||||
struct PlaylistInfo {
|
||||
@ -200,8 +202,6 @@ signals:
|
||||
void RequestSslErrors(const QList<QSslError>& errors);
|
||||
|
||||
void Homepage();
|
||||
// Refresh all Grooveshark's items, and re-fill them
|
||||
void RefreshItems();
|
||||
|
||||
private:
|
||||
void EnsureMenuCreated();
|
||||
@ -248,6 +248,10 @@ signals:
|
||||
|
||||
void ResetSessionId();
|
||||
|
||||
// Sort songs alphabetically only if the "sort_alphabetically" option has been
|
||||
// checked in the preferences settings.
|
||||
void SortSongsAlphabeticallyIfNeeded(SongList* songs) const;
|
||||
|
||||
GroovesharkUrlHandler* url_handler_;
|
||||
|
||||
QString pending_search_;
|
||||
|
@ -70,6 +70,8 @@ void GroovesharkSettingsPage::Load() {
|
||||
validated_ = false;
|
||||
|
||||
UpdateLoginState();
|
||||
|
||||
ui_->sort_alphabetically->setChecked(s.value("sort_alphabetically").toBool());
|
||||
}
|
||||
|
||||
void GroovesharkSettingsPage::Save() {
|
||||
@ -78,6 +80,12 @@ void GroovesharkSettingsPage::Save() {
|
||||
|
||||
s.setValue("username", ui_->username->text());
|
||||
s.setValue("sessionid", service_->session_id());
|
||||
const bool old_sort_value = s.value("sort_alphabetically").toBool();
|
||||
const bool new_sort_value = ui_->sort_alphabetically->isChecked();
|
||||
if (old_sort_value != new_sort_value) {
|
||||
s.setValue("sort_alphabetically", new_sort_value);
|
||||
service_->RefreshItems();
|
||||
}
|
||||
}
|
||||
|
||||
void GroovesharkSettingsPage::LoginFinished(bool success) {
|
||||
|
@ -7,12 +7,15 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>141</height>
|
||||
<height>184</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Grooveshark</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>By default, Grooveshark sorts songs on date added</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="LoginStateWidget" name="login_state" native="true"/>
|
||||
@ -69,6 +72,32 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="preferences_group">
|
||||
<property name="title">
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="sort_alphabetically">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sort playlists songs alphabetically</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
x
Reference in New Issue
Block a user