fix compilation under mingw32

master
Andrzej Rybczak 17 years ago
parent a4a05aa812
commit 1b2999ef8e
  1. 128
      src/browser.cpp
  2. 2
      src/browser.h
  3. 4
      src/ncmpcpp.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()
{

@ -52,9 +52,11 @@ class Browser : public Screen< Menu<MPD::Item> >
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:

@ -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))
{

Loading…
Cancel
Save