1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 04:51:53 +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()
: 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<string, case_less> 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);
}

View File

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

View File

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