Use locale aware sorting for the lists of artists and albums in the album cover manager. Fixes issue 1952

This commit is contained in:
David Sansome 2011-08-28 00:25:41 +01:00
parent 195f618bf2
commit 7e1b6ef6c4
1 changed files with 18 additions and 1 deletions

View File

@ -19,6 +19,7 @@
#include "albumcoversearcher.h"
#include "iconloader.h"
#include "ui_albumcovermanager.h"
#include "core/logging.h"
#include "core/utilities.h"
#include "covers/albumcoverfetcher.h"
#include "covers/coverproviders.h"
@ -243,6 +244,15 @@ void AlbumCoverManager::CancelRequests() {
ResetFetchCoversButton();
}
static bool CompareNocase(const QString& left, const QString& right) {
return QString::localeAwareCompare(left, right) < 0;
}
static bool CompareAlbumNameNocase(const LibraryBackend::Album& left,
const LibraryBackend::Album& right) {
return CompareNocase(left.album_name, right.album_name);
}
void AlbumCoverManager::Reset() {
ResetFetchCoversButton();
@ -253,7 +263,10 @@ void AlbumCoverManager::Reset() {
new QListWidgetItem(all_artists_icon_, tr("All artists"), ui_->artists, All_Artists);
new QListWidgetItem(artist_icon_, tr("Various artists"), ui_->artists, Various_Artists);
foreach (const QString& artist, backend_->GetAllArtistsWithAlbums()) {
QStringList artists(backend_->GetAllArtistsWithAlbums());
qStableSort(artists.begin(), artists.end(), CompareNocase);
foreach (const QString& artist, artists) {
if (artist.isEmpty())
continue;
@ -289,6 +302,10 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem* current) {
default: albums = backend_->GetAllAlbums(); break;
}
// Sort by album name. The list is already sorted by sqlite but it was done
// case sensitively.
qStableSort(albums.begin(), albums.end(), CompareAlbumNameNocase);
foreach (const LibraryBackend::Album& info, albums) {
// Don't show songs without an album, obviously
if (info.album_name.isEmpty())