browser: make sorting optional

This adds a new option, "noop", to browser_sort_mode. If this mode
is selected, no sorting is done in the browser view, and the elements
are shown in the same order as received from the MPD server.
This commit is contained in:
Trygve Aaberge
2014-08-29 17:10:40 +02:00
committed by Andrzej Rybczak
parent 49f53c07bb
commit 9e8dc741e5
7 changed files with 29 additions and 13 deletions

View File

@@ -2060,19 +2060,24 @@ void ToggleBrowserSortMode::run()
{
case SortMode::Name:
Config.browser_sort_mode = SortMode::ModificationTime;
Statusbar::print("Sort songs by: Modification time");
Statusbar::print("Sort songs by: modification time");
break;
case SortMode::ModificationTime:
Config.browser_sort_mode = SortMode::CustomFormat;
Statusbar::print("Sort songs by: Custom format");
Statusbar::print("Sort songs by: custom format");
break;
case SortMode::CustomFormat:
Config.browser_sort_mode = SortMode::Name;
Statusbar::print("Sort songs by: Name");
Config.browser_sort_mode = SortMode::NoOp;
Statusbar::print("Do not sort songs");
break;
case SortMode::NoOp:
Config.browser_sort_mode = SortMode::Name;
Statusbar::print("Sort songs by: name");
}
std::sort(myBrowser->main().begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main().end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
if (Config.browser_sort_mode != SortMode::NoOp)
std::sort(myBrowser->main().begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main().end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
}
bool ToggleLibraryTagType::canBeRun() const

View File

@@ -437,9 +437,10 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
# else
list = Mpd.GetDirectory(dir);
# endif // !WIN32
if (!isLocal()) // local directory is already sorted
if (Config.browser_sort_mode != SortMode::NoOp && !isLocal()) // local directory is already sorted
std::sort(list.begin(), list.end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
for (MPD::ItemList::iterator it = list.begin(); it != list.end(); ++it)
{
@@ -517,8 +518,10 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
}
});
std::sort(v.begin()+start_size, v.end(), LocaleBasedItemSorting(std::locale(),
Config.ignore_leading_the, Config.browser_sort_mode));
if (Config.browser_sort_mode != SortMode::NoOp)
std::sort(v.begin()+start_size, v.end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
}
void Browser::ClearDirectory(const std::string &path) const

View File

@@ -60,6 +60,9 @@ std::ostream &operator<<(std::ostream &os, SortMode sm)
case SortMode::CustomFormat:
os << "format";
break;
case SortMode::NoOp:
os << "noop";
break;
}
return os;
}
@@ -74,6 +77,8 @@ std::istream &operator>>(std::istream &is, SortMode &sm)
sm = SortMode::ModificationTime;
else if (ssm == "format")
sm = SortMode::CustomFormat;
else if (ssm == "noop")
sm = SortMode::NoOp;
else
is.setstate(std::ios::failbit);
return is;

View File

@@ -27,7 +27,7 @@ enum class SpaceAddMode { AddRemove, AlwaysAdd };
std::ostream &operator<<(std::ostream &os, SpaceAddMode sam);
std::istream &operator>>(std::istream &is, SpaceAddMode &sam);
enum class SortMode { Name, ModificationTime, CustomFormat };
enum class SortMode { Name, ModificationTime, CustomFormat, NoOp };
std::ostream &operator<<(std::ostream &os, SortMode sm);
std::istream &operator>>(std::istream &is, SortMode &sm);

View File

@@ -78,6 +78,8 @@ bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b)
result = m_cmp(a.song->toString(Config.browser_sort_format, Config.tags_separator),
b.song->toString(Config.browser_sort_format, Config.tags_separator));
break;
case SortMode::NoOp:
throw std::logic_error("can't sort with NoOp sorting mode");
}
break;
}