24 static inline int fp_compare_fun (
const void *p1,
const void *p2) {
25 return strcasecmp(*(
const char**) p1, *(
const char**) p2);
28 static inline int fp_compare_hidden_dirs_fun (
const void *p1,
const void *p2) {
32 return strcasecmp(*(
const char**) p1, *(
const char**) p2);
35 static inline int fp_compare_hidden_files_fun (
const void *p1,
const void *p2) {
36 if(strncmp(*(
const char**)p1,
".",1)==0 && strncmp(*(
const char**)p2,
".",1)==0)
return 0;
37 if(strncmp(*(
const char**)p1,
".",1)==0 )
return 1;
38 if(strncmp(*(
const char**)p2,
".",1)==0 )
return -1;
39 return strcasecmp(*(
const char**) p1, *(
const char**) p2);
42 static inline bool fp_show_hidden_files(
FilePicker *filepicker,
char* file) {
43 return (filepicker->
show_hidden) ? strcmp(file,
".")!=0 : (file[0] !=
'.');
46 static inline bool fp_show_filter_files(
FilePicker *filepicker,
char* file) {
50 if(strstr(filepicker->
filter,
"."))
51 return strstr(file, filepicker->
filter);
53 return strstr(xdg_mime_get_mime_type_from_file_name(file), filepicker->
filter);
60 static void fp_sort_buffers(
FilePicker *filepicker,
int get_dirs) {
64 fp_compare_hidden_dirs_fun : fp_compare_fun);
69 fp_compare_hidden_files_fun : fp_compare_fun);
73 static void fp_clear_filebuffer(
FilePicker *filepicker) {
86 static void fp_clear_dirbuffer(
FilePicker *filepicker) {
99 static inline int fp_prefill_dirbuffer(
FilePicker *filepicker,
char *path) {
133 fp_clear_filebuffer(filepicker);
137 if((dirp = opendir(path)) == NULL) {
144 fp_clear_dirbuffer(filepicker);
145 ret = fp_prefill_dirbuffer(filepicker, path);
148 while ((dp = readdir(dirp)) != NULL) {
150 if(dp-> d_type != DT_DIR && strlen(dp->d_name)!=0 && dp->d_type != DT_UNKNOWN
151 && strcmp(dp->d_name,
"..")!=0 && fp_show_hidden_files(filepicker, dp->d_name) &&
152 fp_show_filter_files(filepicker, dp->d_name)) {
160 }
else if(get_dirs && dp -> d_type == DT_DIR && strlen(dp->d_name)!=0
161 && strcmp(dp->d_name,
"..")!=0 && fp_show_hidden_files(filepicker, dp->d_name)) {
172 fp_sort_buffers(filepicker, get_dirs);
177 fp_clear_filebuffer(filepicker);
178 fp_clear_dirbuffer(filepicker);
180 free(filepicker->
path);
192 filepicker->
path = NULL;
193 filepicker->
filter = NULL;
195 assert(filepicker->
path != NULL);