From 89779e6fb98afd2bcb20231b444f8a56266f1140 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 8 Oct 2009 16:09:45 +0200 Subject: [PATCH] sort files in Browser::GetLocalDirectory() files are read in kinda random order, so if one added local dir to playlist, (s)he would get them not sorted at all. fix that by sorting files that have been read recently from current dir, so that we get files sorted within each read directory (if read recursively), which is nice. --- src/browser.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/browser.cpp b/src/browser.cpp index 588322d2..3d7fd8d9 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -343,7 +343,8 @@ void Browser::GetDirectory(std::string dir, std::string subdir) # else Mpd.GetDirectory(dir, list); # endif // !WIN32 - sort(list.begin(), list.end(), CaseInsensitiveSorting()); + if (!isLocal()) // local directory is already sorted + sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (ItemList::iterator it = list.begin(); it != list.end(); ++it) { @@ -407,6 +408,7 @@ void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool } } + size_t old_size = v.size(); while ((file = readdir(dir))) { if (!Config.local_browser_show_hidden_files && file->d_name[0] == '.') @@ -420,7 +422,10 @@ void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool if (S_ISDIR(file_stat.st_mode)) { if (recursively) + { GetLocalDirectory(v, full_path, 1); + old_size = v.size(); + } else { new_item.type = itDirectory; @@ -441,6 +446,7 @@ void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool } } closedir(dir); + std::sort(v.begin()+old_size, v.end(), CaseInsensitiveSorting()); } void Browser::ClearDirectory(const std::string &path) const