new feature: allow for files and directories deletion in browser

This commit is contained in:
Andrzej Rybczak
2009-05-23 17:09:41 +02:00
parent ecd4c8cc17
commit 8f5df28e62
7 changed files with 115 additions and 1 deletions

View File

@@ -465,6 +465,41 @@ void Browser::GetDirectory(string dir, string subdir)
w->Highlight(highlightme);
}
void Browser::ClearDirectory(const std::string &path) const
{
DIR *dir = opendir(path.c_str());
if (!dir)
return;
dirent *file;
struct stat file_stat;
string full_path;
// omit . and ..
for (int i = 0; i < 2; i++)
{
file = readdir(dir);
if (!file)
{
closedir(dir);
return;
}
}
while ((file = readdir(dir)))
{
full_path = path;
if (*full_path.rbegin() != '/')
full_path += '/';
full_path += file->d_name;
lstat(full_path.c_str(), &file_stat);
if (S_ISDIR(file_stat.st_mode))
ClearDirectory(full_path);
remove(full_path.c_str());
}
closedir(dir);
}
void Browser::ChangeBrowseMode()
{
if (Mpd->GetHostname()[0] != '/')