|
|
|
|
@ -147,6 +147,7 @@ void Browser::SpacePressed() |
|
|
|
|
break; // do not let add parent dir.
|
|
|
|
|
|
|
|
|
|
SongList list; |
|
|
|
|
# ifndef WIN32 |
|
|
|
|
if (Config.local_browser) |
|
|
|
|
{ |
|
|
|
|
ItemList items; |
|
|
|
|
@ -157,6 +158,7 @@ void Browser::SpacePressed() |
|
|
|
|
list.push_back(it->song); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
# endif // !WIN32
|
|
|
|
|
Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), list); |
|
|
|
|
|
|
|
|
|
if (myPlaylist->Add(list, 0)) |
|
|
|
|
@ -282,66 +284,6 @@ bool Browser::hasSupportedExtension(const std::string &file) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool recursively) const |
|
|
|
|
{ |
|
|
|
|
DIR *dir = opendir((directory.empty() ? itsBrowsedDir : directory).c_str()); |
|
|
|
|
|
|
|
|
|
if (!dir) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
dirent *file; |
|
|
|
|
|
|
|
|
|
struct stat file_stat; |
|
|
|
|
std::string full_path; |
|
|
|
|
|
|
|
|
|
// omit . and ..
|
|
|
|
|
for (int i = 0; i < 2; ++i) |
|
|
|
|
{ |
|
|
|
|
file = readdir(dir); |
|
|
|
|
if (!file) |
|
|
|
|
{ |
|
|
|
|
closedir(dir); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while ((file = readdir(dir))) |
|
|
|
|
{ |
|
|
|
|
if (!Config.local_browser_show_hidden_files && file->d_name[0] == '.') |
|
|
|
|
continue; |
|
|
|
|
Item new_item; |
|
|
|
|
full_path = directory.empty() ? itsBrowsedDir : directory; |
|
|
|
|
if (itsBrowsedDir != "/") |
|
|
|
|
full_path += "/"; |
|
|
|
|
full_path += file->d_name; |
|
|
|
|
stat(full_path.c_str(), &file_stat); |
|
|
|
|
if (S_ISDIR(file_stat.st_mode)) |
|
|
|
|
{ |
|
|
|
|
if (recursively) |
|
|
|
|
GetLocalDirectory(v, full_path, 1); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
new_item.type = itDirectory; |
|
|
|
|
new_item.name = full_path; |
|
|
|
|
v.push_back(new_item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (hasSupportedExtension(file->d_name)) |
|
|
|
|
{ |
|
|
|
|
new_item.type = itSong; |
|
|
|
|
mpd_Song *s = mpd_newSong(); |
|
|
|
|
s->file = str_pool_get(full_path.c_str()); |
|
|
|
|
# ifdef HAVE_TAGLIB_H |
|
|
|
|
if (!recursively) |
|
|
|
|
TagEditor::ReadTags(s); |
|
|
|
|
# endif // HAVE_TAGLIB_H
|
|
|
|
|
new_item.song = new Song(s); |
|
|
|
|
v.push_back(new_item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
closedir(dir); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::LocateSong(const MPD::Song &s) |
|
|
|
|
{ |
|
|
|
|
if (s.GetDirectory().empty()) |
|
|
|
|
@ -396,7 +338,11 @@ void Browser::GetDirectory(std::string dir, std::string subdir) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ItemList list; |
|
|
|
|
# ifndef WIN32 |
|
|
|
|
Config.local_browser ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list); |
|
|
|
|
# else |
|
|
|
|
Mpd.GetDirectory(dir, list); |
|
|
|
|
# endif // !WIN32
|
|
|
|
|
sort(list.begin(), list.end(), CaseInsensitiveSorting()); |
|
|
|
|
|
|
|
|
|
for (ItemList::iterator it = list.begin(); it != list.end(); ++it) |
|
|
|
|
@ -437,6 +383,67 @@ void Browser::GetDirectory(std::string dir, std::string subdir) |
|
|
|
|
w->Highlight(highlightme); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
|
|
void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool recursively) const |
|
|
|
|
{ |
|
|
|
|
DIR *dir = opendir((directory.empty() ? itsBrowsedDir : directory).c_str()); |
|
|
|
|
|
|
|
|
|
if (!dir) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
dirent *file; |
|
|
|
|
|
|
|
|
|
struct stat file_stat; |
|
|
|
|
std::string full_path; |
|
|
|
|
|
|
|
|
|
// omit . and ..
|
|
|
|
|
for (int i = 0; i < 2; ++i) |
|
|
|
|
{ |
|
|
|
|
file = readdir(dir); |
|
|
|
|
if (!file) |
|
|
|
|
{ |
|
|
|
|
closedir(dir); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while ((file = readdir(dir))) |
|
|
|
|
{ |
|
|
|
|
if (!Config.local_browser_show_hidden_files && file->d_name[0] == '.') |
|
|
|
|
continue; |
|
|
|
|
Item new_item; |
|
|
|
|
full_path = directory.empty() ? itsBrowsedDir : directory; |
|
|
|
|
if (itsBrowsedDir != "/") |
|
|
|
|
full_path += "/"; |
|
|
|
|
full_path += file->d_name; |
|
|
|
|
stat(full_path.c_str(), &file_stat); |
|
|
|
|
if (S_ISDIR(file_stat.st_mode)) |
|
|
|
|
{ |
|
|
|
|
if (recursively) |
|
|
|
|
GetLocalDirectory(v, full_path, 1); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
new_item.type = itDirectory; |
|
|
|
|
new_item.name = full_path; |
|
|
|
|
v.push_back(new_item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (hasSupportedExtension(file->d_name)) |
|
|
|
|
{ |
|
|
|
|
new_item.type = itSong; |
|
|
|
|
mpd_Song *s = mpd_newSong(); |
|
|
|
|
s->file = str_pool_get(full_path.c_str()); |
|
|
|
|
# ifdef HAVE_TAGLIB_H |
|
|
|
|
if (!recursively) |
|
|
|
|
TagEditor::ReadTags(s); |
|
|
|
|
# endif // HAVE_TAGLIB_H
|
|
|
|
|
new_item.song = new Song(s); |
|
|
|
|
v.push_back(new_item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
closedir(dir); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Browser::ClearDirectory(const std::string &path) const |
|
|
|
|
{ |
|
|
|
|
DIR *dir = opendir(path.c_str()); |
|
|
|
|
@ -487,6 +494,7 @@ void Browser::ChangeBrowseMode() |
|
|
|
|
GetDirectory(itsBrowsedDir); |
|
|
|
|
RedrawHeader = 1; |
|
|
|
|
} |
|
|
|
|
#endif // !WIN32
|
|
|
|
|
|
|
|
|
|
void Browser::UpdateItemList() |
|
|
|
|
{ |
|
|
|
|
|