From b43e3577f21a1540d71bc1c779c782330264cf58 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Aug 2008 20:40:09 +0200 Subject: [PATCH] make sorting items in browser case insensitive --- src/helpers.cpp | 17 +++++++++++++++++ src/helpers.h | 1 + src/mpdpp.h | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index ebf1db96..e53b3485 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -554,6 +554,20 @@ bool GetSongInfo(Song &s) return true; } +bool SortDirectory(const Item &a, const Item &b) +{ + if (a.type == b.type) + { + string sa = a.type == itSong ? a.song->GetShortFilename() : a.name; + string sb = b.type == itSong ? b.song->GetShortFilename() : b.name; + transform(sa.begin(), sa.end(), sa.begin(), tolower); + transform(sb.begin(), sb.end(), sb.begin(), tolower); + return sa < sb; + } + else + return a.type < b.type; +} + void GetDirectory(string dir) { int highlightme = -1; @@ -571,6 +585,9 @@ void GetDirectory(string dir) vBrowser.push_back(parent); } Mpd->GetDirectory(dir, vBrowser); + + sort(vBrowser.begin(), vBrowser.end(), SortDirectory); + for (ItemList::iterator it = vBrowser.begin()+(dir != "/" ? 1 : 0); it != vBrowser.end(); it++) { switch (it->type) diff --git a/src/helpers.h b/src/helpers.h index 08abd173..372ee884 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -36,6 +36,7 @@ void WindowTitle(const string &); string TotalPlaylistLength(); string DisplaySong(const Song &, const string & = Config.song_list_format); void ShowMessage(const string &, int = Config.message_delay_time); +bool SortDirectory(const Item &a, const Item &b); void GetDirectory(string); bool GetSongInfo(Song &); void PrepareSearchEngine(Song &s); diff --git a/src/mpdpp.h b/src/mpdpp.h index a88cd0b9..4f57bf1c 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -25,7 +25,7 @@ #include "song.h" enum QueueCommandType { qctAdd, qctDelete, qctDeleteID }; -enum ItemType { itSong, itDirectory, itPlaylist }; +enum ItemType { itDirectory, itSong, itPlaylist }; enum PlayerState { psUnknown, psStop, psPlay, psPause }; struct MPDStatusChanges