From 1b2999ef8e2051de83a2018fa918ab2abb5aa838 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 30 Sep 2009 23:47:38 +0200 Subject: [PATCH] fix compilation under mingw32 --- src/browser.cpp | 128 +++++++++++++++++++++++++----------------------- src/browser.h | 2 + src/ncmpcpp.cpp | 4 ++ 3 files changed, 74 insertions(+), 60 deletions(-) diff --git a/src/browser.cpp b/src/browser.cpp index 3e7680d3..cee3e862 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -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() { diff --git a/src/browser.h b/src/browser.h index 4f73811a..4d3d4f88 100644 --- a/src/browser.h +++ b/src/browser.h @@ -52,9 +52,11 @@ class Browser : public Screen< Menu > void LocateSong(const MPD::Song &); void GetDirectory(std::string, std::string = "/"); +# ifndef WIN32 void GetLocalDirectory(MPD::ItemList &, const std::string & = "", bool = 0) const; void ClearDirectory(const std::string &) const; void ChangeBrowseMode(); +# endif // !WIN32 void UpdateItemList(); protected: diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 38265aaf..4b8eef34 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -616,6 +616,7 @@ int main(int argc, char *argv[]) if (myPlaylistEditor->Main()) // check if initialized myPlaylistEditor->Playlists->Clear(0); // make playlists list update itself } +# ifndef WIN32 else if (myScreen == myBrowser && !myBrowser->Main()->Empty() && myBrowser->Main()->Current().type != itPlaylist) { if (!Config.local_browser) @@ -673,6 +674,7 @@ int main(int argc, char *argv[]) ShowMessage("Aborted!"); } +# endif // !WIN32 else if (myScreen->ActiveWindow() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) { if (myPlaylistEditor->Content->hasSelected()) @@ -1784,10 +1786,12 @@ int main(int argc, char *argv[]) if (number && Mpd.AddRandomSongs(number)) ShowMessage("%zu random song%s added to playlist!", number, number == 1 ? "" : "s"); } +# ifndef WIN32 else if (myScreen == myBrowser) { myBrowser->ChangeBrowseMode(); } +# endif // !WIN32 else if (myScreen->ActiveWindow() == myLibrary->Artists || (myLibrary->Columns() == 2 && myScreen->ActiveWindow() == myLibrary->Albums)) {