add optional 'ignore leading "The" word' function while sorting
This commit is contained in:
@@ -144,6 +144,13 @@
|
|||||||
#
|
#
|
||||||
#clock_display_seconds = "no"
|
#clock_display_seconds = "no"
|
||||||
#
|
#
|
||||||
|
##
|
||||||
|
## Note: If below is enabled, ncmpcpp will ignore leading
|
||||||
|
## "The" word while sorting items in browser, tags in
|
||||||
|
## media library, etc.
|
||||||
|
##
|
||||||
|
#ignore_leading_the = "no"
|
||||||
|
#
|
||||||
#enable_window_title = "yes"
|
#enable_window_title = "yes"
|
||||||
#
|
#
|
||||||
##### lyrics support #####
|
##### lyrics support #####
|
||||||
|
|||||||
@@ -40,6 +40,22 @@ extern bool search_match_to_pattern;
|
|||||||
|
|
||||||
const string term_type = getenv("TERM") ? getenv("TERM") : "";
|
const string term_type = getenv("TERM") ? getenv("TERM") : "";
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
inline void remove_the_word(string &s)
|
||||||
|
{
|
||||||
|
size_t the_pos = s.find("the ");
|
||||||
|
if (the_pos == 0 && the_pos != string::npos)
|
||||||
|
s = s.substr(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline string extract_top_directory(const string &s)
|
||||||
|
{
|
||||||
|
size_t slash = s.rfind("/");
|
||||||
|
return slash != string::npos ? s.substr(++slash) : s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ConnectToMPD()
|
bool ConnectToMPD()
|
||||||
{
|
{
|
||||||
if (!Mpd->Connect())
|
if (!Mpd->Connect())
|
||||||
@@ -169,6 +185,11 @@ bool CaseInsensitiveSorting::operator()(string a, string b)
|
|||||||
{
|
{
|
||||||
ToLower(a);
|
ToLower(a);
|
||||||
ToLower(b);
|
ToLower(b);
|
||||||
|
if (Config.ignore_leading_the)
|
||||||
|
{
|
||||||
|
remove_the_word(a);
|
||||||
|
remove_the_word(b);
|
||||||
|
}
|
||||||
return a < b;
|
return a < b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +199,11 @@ bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb)
|
|||||||
string b = sb->GetName();
|
string b = sb->GetName();
|
||||||
ToLower(a);
|
ToLower(a);
|
||||||
ToLower(b);
|
ToLower(b);
|
||||||
|
if (Config.ignore_leading_the)
|
||||||
|
{
|
||||||
|
remove_the_word(a);
|
||||||
|
remove_the_word(b);
|
||||||
|
}
|
||||||
return a < b;
|
return a < b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,11 +211,17 @@ bool CaseInsensitiveSorting::operator()(const Item &a, const Item &b)
|
|||||||
{
|
{
|
||||||
if (a.type == b.type)
|
if (a.type == b.type)
|
||||||
{
|
{
|
||||||
string sa = a.type == itSong ? a.song->GetName() : a.name;
|
switch (a.type)
|
||||||
string sb = b.type == itSong ? b.song->GetName() : b.name;
|
{
|
||||||
ToLower(sa);
|
case itDirectory:
|
||||||
ToLower(sb);
|
return operator()(extract_top_directory(a.name), extract_top_directory(b.name));
|
||||||
return sa < sb;
|
case itPlaylist:
|
||||||
|
return operator()(a.name, b.name);
|
||||||
|
case itSong:
|
||||||
|
return operator()(a.song, b.song);
|
||||||
|
default: // there's no other type, just silence compiler.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return a.type < b.type;
|
return a.type < b.type;
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
|
|||||||
conf.search_in_db = true;
|
conf.search_in_db = true;
|
||||||
conf.display_screens_numbers_on_start = true;
|
conf.display_screens_numbers_on_start = true;
|
||||||
conf.clock_display_seconds = false;
|
conf.clock_display_seconds = false;
|
||||||
|
conf.ignore_leading_the = false;
|
||||||
conf.set_window_title = true;
|
conf.set_window_title = true;
|
||||||
conf.mpd_port = 6600;
|
conf.mpd_port = 6600;
|
||||||
conf.mpd_connection_timeout = 15;
|
conf.mpd_connection_timeout = 15;
|
||||||
@@ -700,6 +701,10 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
|||||||
{
|
{
|
||||||
conf.clock_display_seconds = v == "yes";
|
conf.clock_display_seconds = v == "yes";
|
||||||
}
|
}
|
||||||
|
else if (cl.find("ignore_leading_the") != string::npos)
|
||||||
|
{
|
||||||
|
conf.ignore_leading_the = v == "yes";
|
||||||
|
}
|
||||||
else if (cl.find("enable_window_title") != string::npos)
|
else if (cl.find("enable_window_title") != string::npos)
|
||||||
{
|
{
|
||||||
conf.set_window_title = v == "yes";
|
conf.set_window_title = v == "yes";
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ struct ncmpcpp_config
|
|||||||
bool search_in_db;
|
bool search_in_db;
|
||||||
bool display_screens_numbers_on_start;
|
bool display_screens_numbers_on_start;
|
||||||
bool clock_display_seconds;
|
bool clock_display_seconds;
|
||||||
|
bool ignore_leading_the;
|
||||||
|
|
||||||
int mpd_port;
|
int mpd_port;
|
||||||
int mpd_connection_timeout;
|
int mpd_connection_timeout;
|
||||||
|
|||||||
Reference in New Issue
Block a user