corrections for previous commit

This commit is contained in:
Andrzej Rybczak
2012-07-15 21:58:24 +02:00
parent 6c73c3cecf
commit 27a0dc958f
7 changed files with 74 additions and 42 deletions

View File

@@ -179,15 +179,15 @@
#tag_editor_album_format = "{(%y) }%b" #tag_editor_album_format = "{(%y) }%b"
# #
## ##
## Note: Below variables are used for sorting the library browser. ## Note: Below variables are used for sorting songs in browser.
## The sort mode determines how the song library is sorted, and can ## The sort mode determines how songs are sorted, and can be used
## be used in combination with a sort format to specify a custom sorting format. ## in combination with a sort format to specify a custom sorting format.
## Possible values for sort_mode are "name", "mtime" and "format". ## Possible values for browser_sort_mode are "name", "mtime" and "format".
## ##
# #
#sort_mode = "name" #browser_sort_mode = "name"
# #
#sort_format = "{%b~%n}|{~%n}|{~~%t}|{~~%f}" #browser_sort_format = "{%a - }{%t}|{%f} {(%l)}"
# #
## ##
## Note: Below variables are for alternative version of user's interface. ## Note: Below variables are for alternative version of user's interface.

View File

@@ -132,11 +132,11 @@ Format for albums' list in Tag editor.
.B song_window_title_format .B song_window_title_format
Song format for window title. Song format for window title.
.TP .TP
.B sort_mode .B browser_sort_mode
Determines the sort mode for the song library. Possible values are "name", "mtime" and "format". Determines sort mode for browser. Possible values are "name", "mtime" and "format".
.TP .TP
.B sort_format .B browser_sort_format
Format to use for sorting the song library. For this option to be effective, sort_mode must be set to "format". Format to use for sorting songs in browser. For this option to be effective, browser_sort_mode must be set to "format".
.TP .TP
.B external_editor = PATH .B external_editor = PATH
Path to external editor used to edit lyrics. Path to external editor used to edit lyrics.
@@ -301,7 +301,7 @@ If enabled, bitrate of currently playing song will be displayed in statusbar.
If enabled, remaining time of currently playing song will be be displayed in statusbar instead of elapsed time. If enabled, remaining time of currently playing song will be be displayed in statusbar instead of elapsed time.
.TP .TP
.B ignore_leading_the = yes/no .B ignore_leading_the = yes/no
If enabled, word "the" at the beginning of tags/filenames will be ignored while sorting items. Note that this doesn't currently work with custom sorting formats. If enabled, word "the" at the beginning of tags/filenames/sort format will be ignored while sorting items.
.TP .TP
.B use_console_editor = yes/no .B use_console_editor = yes/no
If your external editor is console application, you need to enable it. If your external editor is console application, you need to enable it.

View File

@@ -100,6 +100,9 @@ void Browser::SwitchTo()
if (hasToBeResized || myLockedScreen) if (hasToBeResized || myLockedScreen)
Resize(); Resize();
if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime
Config.browser_sort_mode = smName;
w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList(); w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList();
if (myScreen != this && myScreen->isTabbable()) if (myScreen != this && myScreen->isTabbable())

View File

@@ -298,30 +298,36 @@ int CaseInsensitiveStringComparison::operator()(const std::string &a, const std:
bool CaseInsensitiveSorting::operator()(const MPD::Item &a, const MPD::Item &b) bool CaseInsensitiveSorting::operator()(const MPD::Item &a, const MPD::Item &b)
{ {
bool result;
if (a.type == b.type) if (a.type == b.type)
{ {
switch (a.type) switch (a.type)
{ {
case MPD::itDirectory: case MPD::itDirectory:
return cmp(ExtractTopName(a.name), ExtractTopName(b.name)) < 0; result = cmp(ExtractTopName(a.name), ExtractTopName(b.name)) < 0;
break;
case MPD::itPlaylist: case MPD::itPlaylist:
return cmp(a.name, b.name) < 0; result = cmp(a.name, b.name) < 0;
case MPD::itSong: { break;
unsigned mode = Config.sort_mode; case MPD::itSong:
if (myBrowser->isLocal() && mode == 1) mode = 0; // local browser doesn't support sorting by mtime. switch (Config.browser_sort_mode)
switch (mode) { {
case 0: return operator()(a.song, b.song); case smName:
case 1: return a.song->GetMTime() > b.song->GetMTime(); result = operator()(a.song, b.song);
case 2: return cmp(a.song->toString(Config.sort_format), b.song->toString(Config.sort_format)) < 0; break;
default: return 0; // no other mode. case smMTime:
result = a.song->GetMTime() > b.song->GetMTime();
break;
case smCustomFormat:
result = cmp(a.song->toString(Config.browser_sort_format), b.song->toString(Config.browser_sort_format)) < 0;
break;
} }
} break;
default: // there's no other type, just silence compiler.
return 0;
} }
} }
else else
return a.type < b.type; result = a.type < b.type;
return result;
} }
std::string Timestamp(time_t t) std::string Timestamp(time_t t)

View File

@@ -2175,15 +2175,28 @@ int main(int argc, char **argv)
if (number && (answer == 's' ? Mpd.AddRandomSongs(number) : Mpd.AddRandomTag(tag_type, number))) if (number && (answer == 's' ? Mpd.AddRandomSongs(number) : Mpd.AddRandomTag(tag_type, number)))
ShowMessage("%zu random %s%s added to playlist!", number, tag_type_str.c_str(), number == 1 ? "" : "s"); ShowMessage("%zu random %s%s added to playlist!", number, tag_type_str.c_str(), number == 1 ? "" : "s");
} }
else if (myScreen == myBrowser && !myBrowser->isLocal()) else if (myScreen == myBrowser)
{ {
Config.sort_mode = (Config.sort_mode + 1) % 3; switch (Config.browser_sort_mode)
myBrowser->Main()->Sort<CaseInsensitiveSorting>(myBrowser->CurrentDir() != "/"); {
switch (Config.sort_mode) { case smName:
case 0: ShowMessage("Sort songs by: Name"); break; if (!myBrowser->isLocal())
case 1: ShowMessage("Sort songs by: Modification time"); break; {
case 2: ShowMessage("Sort songs by: Custom format"); break; Config.browser_sort_mode = smMTime;
ShowMessage("Sort songs by: Modification time");
break;
}
// local browser doesn't support sorting by mtime, so we just skip it.
case smMTime:
Config.browser_sort_mode = smCustomFormat;
ShowMessage("Sort songs by: Custom format");
break;
case smCustomFormat:
Config.browser_sort_mode = smName;
ShowMessage("Sort songs by: Name");
break;
} }
myBrowser->Main()->Sort<CaseInsensitiveSorting>(myBrowser->CurrentDir() != "/");
} }
else if (myScreen->ActiveWindow() == myLibrary->Artists else if (myScreen->ActiveWindow() == myLibrary->Artists
|| (myLibrary->Columns() == 2 && myScreen->ActiveWindow() == myLibrary->Albums)) || (myLibrary->Columns() == 2 && myScreen->ActiveWindow() == myLibrary->Albums))

View File

@@ -372,7 +372,7 @@ void NcmpcppConfig::SetDefaults()
song_status_format_no_colors = song_status_format; song_status_format_no_colors = song_status_format;
song_window_title_format = "{{%a - }{%t}|{%f}}"; song_window_title_format = "{{%a - }{%t}|{%f}}";
song_library_format = "{{%n - }{%t}|{%f}}"; song_library_format = "{{%n - }{%t}|{%f}}";
sort_format = "{%b~%n}|{~%n}|{~~%t}|{~~%f}"; browser_sort_format = "{{%a - }{%t}|{%f} {(%l)}}";
tag_editor_album_format = "{{(%y) }%b}"; tag_editor_album_format = "{{(%y) }%b}";
new_header_first_line = "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/b}"; new_header_first_line = "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/b}";
new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}"; new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}";
@@ -464,7 +464,6 @@ void NcmpcppConfig::SetDefaults()
lines_scrolled = 2; lines_scrolled = 2;
search_engine_default_search_mode = 0; search_engine_default_search_mode = 0;
visualizer_sync_interval = 30; visualizer_sync_interval = 30;
sort_mode = 0;
locked_screen_width_part = 0.5; locked_screen_width_part = 0.5;
selected_item_suffix_length = 0; selected_item_suffix_length = 0;
now_playing_suffix_length = 0; now_playing_suffix_length = 0;
@@ -474,6 +473,7 @@ void NcmpcppConfig::SetDefaults()
system_encoding.clear(); system_encoding.clear();
# endif // HAVE_LANGINFO_H # endif // HAVE_LANGINFO_H
startup_screen = myPlaylist; startup_screen = myPlaylist;
browser_sort_mode = smName;
// default screens sequence // default screens sequence
screens_seq.push_back(myPlaylist); screens_seq.push_back(myPlaylist);
screens_seq.push_back(myBrowser); screens_seq.push_back(myBrowser);
@@ -854,10 +854,14 @@ void NcmpcppConfig::Read()
tag_editor_album_format += '}'; tag_editor_album_format += '}';
} }
} }
else if (name == "sort_format") else if (name == "browser_sort_format")
{ {
if (!v.empty()) if (!v.empty() && MPD::Song::isFormatOk("browser_sort_format", v))
sort_format = v; {
browser_sort_format = '{';
browser_sort_format += v;
browser_sort_format += '}';
}
} }
else if (name == "external_editor") else if (name == "external_editor")
{ {
@@ -1240,9 +1244,12 @@ void NcmpcppConfig::Read()
} }
else if (name == "sort_mode") else if (name == "sort_mode")
{ {
if (v == "mtime") sort_mode = 1; if (v == "mtime")
else if (v == "format") sort_mode = 2; browser_sort_mode = smMTime;
else sort_mode = 0; // "name" or invalid else if (v == "format")
browser_sort_mode = smCustomFormat;
else
browser_sort_mode = smName; // "name" or invalid
} }
else if (name == "locked_screen_width_part") else if (name == "locked_screen_width_part")
{ {

View File

@@ -29,6 +29,8 @@
class BasicScreen; // forward declaration for screens sequence class BasicScreen; // forward declaration for screens sequence
enum SortMode { smName, smMTime, smCustomFormat };
struct Column struct Column
{ {
Column() : right_alignment(0), display_empty_tag(1) { } Column() : right_alignment(0), display_empty_tag(1) { }
@@ -168,7 +170,7 @@ struct NcmpcppConfig
std::string song_library_format; std::string song_library_format;
std::string tag_editor_album_format; std::string tag_editor_album_format;
std::string song_in_columns_to_string_format; std::string song_in_columns_to_string_format;
std::string sort_format; std::string browser_sort_format;
std::string external_editor; std::string external_editor;
std::string system_encoding; std::string system_encoding;
std::string execute_on_song_change; std::string execute_on_song_change;
@@ -273,7 +275,6 @@ struct NcmpcppConfig
unsigned lines_scrolled; unsigned lines_scrolled;
unsigned search_engine_default_search_mode; unsigned search_engine_default_search_mode;
unsigned visualizer_sync_interval; unsigned visualizer_sync_interval;
unsigned sort_mode;
double locked_screen_width_part; double locked_screen_width_part;
@@ -283,6 +284,8 @@ struct NcmpcppConfig
BasicScreen *startup_screen; BasicScreen *startup_screen;
std::list<BasicScreen *> screens_seq; std::list<BasicScreen *> screens_seq;
SortMode browser_sort_mode;
private: private:
void MakeProperPath(std::string &dir); void MakeProperPath(std::string &dir);