1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-06-30 21:02:21 +03:00
Commit Graph

36 Commits

Author SHA1 Message Date
Maarten ter Huurne
c7a5b874f1 Don't assume that all non-directories are regular files
Other types are not very likely, but if we do encounter them it is best
to just skip them.
2014-08-20 13:09:49 +02:00
Maarten ter Huurne
3eb3a8ed7a If directory entry is a symbolic link, fall back on stat()
Unlike d_type, stat() will return the type of the target of the link
rather than the link itself.
2014-08-20 13:07:11 +02:00
Maarten ter Huurne
ba09d2599d Avoid out-of-range lookup when FileLister::browse is passed empty string
When the path is the empty string, it is handled as the current working
directory, which is consistent with how relative paths are handled.
2014-08-17 10:22:09 +02:00
Maarten ter Huurne
20725fcdda Do not list ".." as a subdirectory of the root directory
In Linux "/.." exists and loops back onto the root. But for the user
it is confusing to see a ".." entry listed that does nothing when
selected, so hide it.
2014-08-17 10:20:22 +02:00
Maarten ter Huurne
0b0e278459 Deal gracefully with the selector being started on a non-existent dir
If directory browsing is enabled, fall back to the closest existing
parent directory. If directory browsing is disabled, show empty list.
2014-08-17 10:05:21 +02:00
Maarten ter Huurne
47d349f78b Simplified file extension filtering code
Don't create any temporary strings, just use the d_name field and
strcasecmp.
2014-08-14 06:43:37 +02:00
Maarten ter Huurne
404b2a1029 Use proper feature test macro for d_type support 2014-08-14 06:10:55 +02:00
Maarten ter Huurne
56beec0895 Convert file name to C++ string as late as possible
This avoids copying the string if the file is rejected because its
category (directory or regular file) is disabled.
2014-08-14 05:30:31 +02:00
Maarten ter Huurne
b6f6bb387c Skip stat() call when the d_type field can tell us the file type
This is a BSD extension also present in glibc and uClibc. Not all libc
implementations and not all file systems support it, so we keep the
stat-based code as a fallback.
2014-08-14 05:25:26 +02:00
Maarten ter Huurne
a505d3e494 Removed FileLister::insertFile
This was a nasty hack to insert English into the list of translations.
Instead of modifying the scan results, make a copy and modify the copy.
2014-08-14 05:08:36 +02:00
Maarten ter Huurne
85b072ca43 Removed FileLister::at
In the STL, 'at' will perform range checking while operator[] will not.
Since GMenu2X doesn't use exceptions, range checking is not possible,
so 'at' and operator[] were identical.
2014-08-14 05:02:24 +02:00
Maarten ter Huurne
ba47744a52 Put trivial FileLister method implementations in header
This cuts a few hundred bytes off the stripped binary size.
2014-08-14 04:59:07 +02:00
Maarten ter Huurne
eb3def19ea 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.
2014-08-14 04:45:26 +02:00
Maarten ter Huurne
35724170f8 Make FileLister::browse not log a non-existing directory as an error
To avoid unnecessary existence checks, we consider browsing a
non-existing directory to be a normal situation.
2014-08-13 22:59:13 +02:00
Maarten ter Huurne
13f574bfb2 Avoid moving around entries unless new ones were found
When scanning multiple directories in succession, it's possible that
in some of them no matches are found. Avoid moving all pre-existing
entries back and forth in that case.

Also use move instead of copy for transferring the pre-existing
entries from the vector to the set.
2014-08-13 07:35:29 +02:00
Maarten ter Huurne
90a5f82b92 In FileLister::browse, declare variables when they are needed 2014-08-13 07:14:30 +02:00
Maarten ter Huurne
2c76ddae50 Removed special case handling for !(showDirectories || showFiles)
The special case is not necessary for correctness. It would help
performance in theory, but it seems very unlikely that any code would
request a directory scan when it interested in neither the subdirs nor
the files in that directory.
2014-08-13 07:08:04 +02:00
Maarten ter Huurne
46c64ea984 Move instead of copy strings at the end of FileLister::browse
This takes a little trickery, which I wrapped and documented.
2014-08-13 07:06:07 +02:00
Nebuleon Fumika
f1e92425ac Optimise duplicate checking and sorting in FileLister::browse
Using a std::set makes both duplicate checking and sorting run in
O(n log n).
2014-08-13 07:06:07 +02:00
Nebuleon Fumika
bd7eac32ba Pre-process the filter string in FileLister::setFilter
Instead of splitting the filter for every file in FileLister::browse,
the filter is split immediately in FileLister::setFilter, improving
performance.

getFilter is removed because it was unused. This also removes the need
to update the return type to 'const std::vector&' in the method and
rewrite its callers.
2014-08-13 07:06:07 +02:00
Nebuleon Fumika
1dec6f6f11 Split creation, configuration and use of FileLister objects
The constructor now has zero arguments. showDirectories and showFiles
are now set using setter methods.

FileLister::browse is now the sole way to start a scan for files and
directories, replacing the initial path in the constructor and the
setPath method. It allows merging results from multiple directories
as before.

This is all to make explicit how many times the costly task of browsing
a directory is actually carried out.
2014-08-13 04:50:22 +02:00
Paul Cercueil
6d44fb3a75 Use the "*" filter to match all files
The empty "" filter was previously matching all the files; since
a few commits it now matches the files without extensions. The
new "*" filter allows again to match all files.
2013-07-08 02:21:42 -04:00
Paul Cercueil
dad8d1bad5 Fix extension filter in file selection dialog
This fixes commit eb63294231
2013-07-05 14:42:55 -04:00
Paul Cercueil
eb63294231 Don't call tolower() on the whole filenames, only on extensions
tolower() will trigger an assertion failure in the case where the
string contains UTF-8 codes. This is not a problem as only the
file extension needs to be processed, and that one should contain
only ASCII.
2013-07-05 14:00:46 -04:00
Maarten ter Huurne
a01d892eb6 More header cleanups.
This time the focus was on removing namespace imports from headers.
2011-10-23 16:43:56 +02:00
Ayla
6c97139113 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.
2011-04-14 11:16:16 +02:00
Ayla
d8204706d7 The method FileLister::browse() now takes an optional boolean argument.
If set to "false", the previous list of files/directories won't be cleared when browsing another directory.
It will allow us to have file choosers that list files contained on different directories.
2011-04-03 11:30:25 +02:00
Ayla
ec000e0214 Changed an error message, that was displaying "Error:" twice. Plus, it now more meaningful. 2011-03-30 15:44:32 +02:00
Ayla
5cd92b76ae The selector filters will now match also the files with an extension in uppercase.
Please note that the selector filters have to be entered in lowercase.
2010-10-13 22:09:43 +02:00
Ayla
7c9364780b Replaced every message output by calls to the log macros. 2010-09-17 22:31:09 +02:00
Maarten ter Huurne
8032d96a17 Converted public fields of FileLister to private. 2010-07-27 21:41:35 +02:00
Maarten ter Huurne
660b4f01aa In "utilities.h", only include those headers that are needed by the definitions in "utilities.h". 2010-06-19 04:44:03 +02:00
Maarten ter Huurne
9f21df7fed Replaced "hash_map" by "unordered_map" to get rid of deprecation warnings. 2010-06-18 00:45:16 +02:00
Lars-Peter Clausen
2a6a1f0041 filelister.cpp: Small cleanup 2010-05-03 21:14:11 +02:00
Lars-Peter Clausen
40a26e1a9c pass strings by reference where possible 2010-05-02 14:38:16 +02:00
Mirko Lindner
cddcd72e33 initial commit - needs clean-up
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
2010-02-04 12:33:47 +01:00