From 6c97139113e6f918e3008c82b618a38de963543c Mon Sep 17 00:00:00 2001 From: Ayla Date: Thu, 14 Apr 2011 11:16:16 +0200 Subject: [PATCH] The FileLister won't list a file if a previous one has the same file name (without path). This is useful when the files/directories lists are not cleared; then it is possible to define priorities between the files. For instance, the skin "Default" will be shown only once, even if the directory "Default" exists both in the system and the user directories. As the skin and translation loading functions does check both directories, there is no problem in doing that. --- src/filelister.cpp | 12 ++++++++++-- src/gmenu2x.cpp | 8 ++++---- src/wallpaperdialog.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/filelister.cpp b/src/filelister.cpp index cc0d03e..cc3b3b4 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -88,8 +88,8 @@ void FileLister::browse(bool clean) while ((dptr = readdir(dirp))) { file = dptr->d_name; - file_lowercase = file; - std::transform(file_lowercase.begin(), file_lowercase.end(), file_lowercase.begin(), ::tolower); + file_lowercase = file; + std::transform(file_lowercase.begin(), file_lowercase.end(), file_lowercase.begin(), ::tolower); if (file[0] == '.' && file != "..") continue; @@ -106,10 +106,18 @@ void FileLister::browse(bool clean) if (S_ISDIR(st.st_mode)) { if (!showDirectories) continue; + + if (std::find(directories.begin(), directories.end(), file) != directories.end()) + continue; + directories.push_back(file); } else { if (!showFiles) continue; + + if (std::find(files.begin(), files.end(), file) != files.end()) + continue; + for (vector::iterator it = vfilter.begin(); it != vfilter.end(); ++it) { if (it->length() <= file.length()) { if (file_lowercase.compare(file.length() - it->length(), it->length(), *it) == 0) { diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 19c10e7..25c69bd 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -1128,9 +1128,9 @@ void GMenu2X::options() { int prevbacklight = confInt["backlight"]; bool showRootFolder = fileExists(CARD_ROOT); - FileLister fl_tr(GMENU2X_SYSTEM_DIR "/translations"); + FileLister fl_tr(getHome() + "/translations"); fl_tr.browse(); - fl_tr.setPath(getHome() + "/translations", false); + fl_tr.setPath(GMENU2X_SYSTEM_DIR "/translations", false); fl_tr.browse(false); fl_tr.insertFile("English"); @@ -1197,10 +1197,10 @@ void GMenu2X::settingsOpen2x() { } void GMenu2X::skinMenu() { - FileLister fl_sk(GMENU2X_SYSTEM_DIR "/skins", true, false); + FileLister fl_sk(getHome() + "/skins", true, false); fl_sk.addExclude(".."); fl_sk.browse(); - fl_sk.setPath(getHome() + "/skins", false); + fl_sk.setPath(GMENU2X_SYSTEM_DIR "/skins", false); fl_sk.browse(false); string curSkin = confStr["skin"]; diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index b8b0d77..d2be34b 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -38,12 +38,12 @@ bool WallpaperDialog::exec() FileLister fl; fl.setFilter(".png,.jpg,.jpeg,.bmp"); - string filepath = GMENU2X_SYSTEM_DIR "/skins/" + string filepath = GMenu2X::getHome() + "/skins/" + gmenu2x->confStr["skin"] + "/wallpapers"; if (fileExists(filepath)) fl.setPath(filepath, true); - filepath = GMenu2X::getHome() + "/skins/" + filepath = GMENU2X_SYSTEM_DIR "/skins/" + gmenu2x->confStr["skin"] + "/wallpapers"; if (fileExists(filepath)) { fl.setPath(filepath, false); @@ -51,13 +51,13 @@ bool WallpaperDialog::exec() } if (gmenu2x->confStr["skin"] != "Default") { - filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers"; + filepath = GMenu2X::getHome() + "/skins/Default/wallpapers"; if (fileExists(filepath)) { fl.setPath(filepath, false); fl.browse(false); } - filepath = GMenu2X::getHome() + "/skins/Default/wallpapers"; + filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers"; if (fileExists(filepath)) { fl.setPath(filepath, false); fl.browse(false);