1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 02:08:28 +02:00

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.
This commit is contained in:
Maarten ter Huurne 2014-08-14 04:45:26 +02:00
parent d51fbb8716
commit eb3def19ea
3 changed files with 17 additions and 15 deletions

View File

@ -37,6 +37,7 @@ using namespace std;
FileLister::FileLister() FileLister::FileLister()
: showDirectories(true) : showDirectories(true)
, showUpdir(true)
, showFiles(true) , showFiles(true)
{ {
} }
@ -55,6 +56,11 @@ void FileLister::setShowDirectories(bool showDirectories)
this->showDirectories = showDirectories; this->showDirectories = showDirectories;
} }
void FileLister::setShowUpdir(bool showUpdir)
{
this->showUpdir = showUpdir;
}
void FileLister::setShowFiles(bool showFiles) void FileLister::setShowFiles(bool showFiles)
{ {
this->showFiles = showFiles; this->showFiles = showFiles;
@ -95,11 +101,14 @@ void FileLister::browse(const string& path, bool clean)
set<string, case_less> fileSet; set<string, case_less> fileSet;
while (struct dirent *dptr = readdir(dirp)) { while (struct dirent *dptr = readdir(dirp)) {
string file = dptr->d_name; // Ignore hidden files and optionally "..".
if (dptr->d_name[0] == '.') {
if (file[0] == '.' && file != "..") if (!(dptr->d_name[1] == '.' && showUpdir)) {
continue; continue;
}
}
string file = dptr->d_name;
string filepath = slashedPath + file; string filepath = slashedPath + file;
struct stat st; struct stat st;
int statRet = stat(filepath.c_str(), &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)); ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
continue; continue;
} }
if (find(excludes.begin(), excludes.end(), file) != excludes.end())
continue;
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
if (!showDirectories) if (!showDirectories)
continue; continue;
@ -214,7 +220,3 @@ bool FileLister::isDirectory(unsigned int x)
void FileLister::insertFile(const string &file) { void FileLister::insertFile(const string &file) {
files.insert(files.begin(), file); files.insert(files.begin(), file);
} }
void FileLister::addExclude(const string &exclude) {
excludes.push_back(exclude);
}

View File

@ -27,9 +27,9 @@
class FileLister { class FileLister {
private: private:
std::vector<std::string> filter; std::vector<std::string> filter;
bool showDirectories, showFiles; bool showDirectories, showUpdir, showFiles;
std::vector<std::string> directories, files, excludes; std::vector<std::string> directories, files;
public: public:
FileLister(); FileLister();
@ -46,12 +46,12 @@ public:
void setFilter(const std::string &filter); void setFilter(const std::string &filter);
void setShowDirectories(bool); void setShowDirectories(bool);
void setShowUpdir(bool);
void setShowFiles(bool); void setShowFiles(bool);
const std::vector<std::string> &getDirectories() { return directories; } const std::vector<std::string> &getDirectories() { return directories; }
const std::vector<std::string> &getFiles() { return files; } const std::vector<std::string> &getFiles() { return files; }
void insertFile(const std::string &file); void insertFile(const std::string &file);
void addExclude(const std::string &exclude);
}; };
#endif // FILELISTER_H #endif // FILELISTER_H

View File

@ -725,7 +725,7 @@ void GMenu2X::showSettings() {
void GMenu2X::skinMenu() { void GMenu2X::skinMenu() {
FileLister fl_sk; FileLister fl_sk;
fl_sk.setShowFiles(false); fl_sk.setShowFiles(false);
fl_sk.addExclude(".."); fl_sk.setShowUpdir(false);
fl_sk.browse(getHome() + "/skins"); fl_sk.browse(getHome() + "/skins");
fl_sk.browse(GMENU2X_SYSTEM_DIR "/skins", false); fl_sk.browse(GMENU2X_SYSTEM_DIR "/skins", false);