From eb3def19ea6233c485ade4dd0ac9f437744d91ba Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 14 Aug 2014 04:45:26 +0200 Subject: [PATCH] Replaced generic exclude mechanism by updir filter in FileLister The exclude mechanism was only used to filter out ".." for the skins lister, so this lighter filter does all we need. --- src/filelister.cpp | 24 +++++++++++++----------- src/filelister.h | 6 +++--- src/gmenu2x.cpp | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/filelister.cpp b/src/filelister.cpp index 5c6eb2f..7961781 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -37,6 +37,7 @@ using namespace std; FileLister::FileLister() : showDirectories(true) + , showUpdir(true) , showFiles(true) { } @@ -55,6 +56,11 @@ void FileLister::setShowDirectories(bool showDirectories) this->showDirectories = showDirectories; } +void FileLister::setShowUpdir(bool showUpdir) +{ + this->showUpdir = showUpdir; +} + void FileLister::setShowFiles(bool showFiles) { this->showFiles = showFiles; @@ -95,11 +101,14 @@ void FileLister::browse(const string& path, bool clean) set fileSet; while (struct dirent *dptr = readdir(dirp)) { + // Ignore hidden files and optionally "..". + if (dptr->d_name[0] == '.') { + if (!(dptr->d_name[1] == '.' && showUpdir)) { + continue; + } + } + string file = dptr->d_name; - - if (file[0] == '.' && file != "..") - continue; - string filepath = slashedPath + file; struct stat st; int statRet = stat(filepath.c_str(), &st); @@ -107,9 +116,6 @@ void FileLister::browse(const string& path, bool clean) ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno)); continue; } - if (find(excludes.begin(), excludes.end(), file) != excludes.end()) - continue; - if (S_ISDIR(st.st_mode)) { if (!showDirectories) continue; @@ -214,7 +220,3 @@ bool FileLister::isDirectory(unsigned int x) void FileLister::insertFile(const string &file) { files.insert(files.begin(), file); } - -void FileLister::addExclude(const string &exclude) { - excludes.push_back(exclude); -} diff --git a/src/filelister.h b/src/filelister.h index a9d94b5..4e39df7 100644 --- a/src/filelister.h +++ b/src/filelister.h @@ -27,9 +27,9 @@ class FileLister { private: std::vector filter; - bool showDirectories, showFiles; + bool showDirectories, showUpdir, showFiles; - std::vector directories, files, excludes; + std::vector directories, files; public: FileLister(); @@ -46,12 +46,12 @@ public: void setFilter(const std::string &filter); void setShowDirectories(bool); + void setShowUpdir(bool); void setShowFiles(bool); const std::vector &getDirectories() { return directories; } const std::vector &getFiles() { return files; } void insertFile(const std::string &file); - void addExclude(const std::string &exclude); }; #endif // FILELISTER_H diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index b07ab51..cb96043 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -725,7 +725,7 @@ void GMenu2X::showSettings() { void GMenu2X::skinMenu() { FileLister fl_sk; fl_sk.setShowFiles(false); - fl_sk.addExclude(".."); + fl_sk.setShowUpdir(false); fl_sk.browse(getHome() + "/skins"); fl_sk.browse(GMENU2X_SYSTEM_DIR "/skins", false);