Enlightenment CVS committal
Author : rbdpngn
Project : e17
Module : libs/ewl
Dir : e17/libs/ewl/src/lib
Modified Files:
ewl_fileselector.c ewl_fileselector.h
Log Message:
Add a directory filter field to match separately from files.
Simplified directory and file list building.
Fixed some memleaks in the fileselector.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- ewl_fileselector.c 28 Mar 2005 07:04:28 -0000 1.11
+++ ewl_fileselector.c 27 Apr 2005 14:01:27 -0000 1.12
@@ -19,12 +19,15 @@
static char *ewl_fileselector_path_home_get(void);
static char *ewl_fileselector_size_string_get(off_t st_size);
static char *ewl_fileselector_perm_string_get(mode_t st_mode);
-static void ewl_fileselector_file_list_get(char *path, char *filter,
+static void ewl_fileselector_file_list_get(char *path, char *filter,
+ char *dfilter,
Ecore_List *flist,
Ecore_List *dlist);
static void ewl_fileselector_path_setup(Ewl_Fileselector *fs, char *path);
static void ewl_fileselector_show_cb(Ewl_Widget *entry, void *ev_data,
void *user_data);
+static void ewl_fileselector_destroy_cb(Ewl_Widget *entry, void *ev_data,
+ void *user_data);
static void ewl_fileselector_dir_data_cleanup_cb(Ewl_Widget *entry,
void *ev_data, void *user_data);
static void ewl_fileselector_file_data_cleanup_cb(Ewl_Widget *entry,
@@ -87,6 +90,8 @@
EWL_FLAG_FILL_HFILL);
ewl_callback_append(w, EWL_CALLBACK_SHOW,
ewl_fileselector_show_cb, NULL);
+ ewl_callback_append(w, EWL_CALLBACK_DESTROY,
+ ewl_fileselector_destroy_cb, NULL);
/* The entry for the current directory */
@@ -204,6 +209,7 @@
ewl_widget_show(hbox);
}
+ fs->dfilter = strdup("^[^\\.][^$]");
tmp = getenv("HOME");
fs->path = strdup((tmp ? tmp : "/"));
@@ -405,10 +411,11 @@
return perm;
}
-static void ewl_fileselector_file_list_get(char *path, char *filter,
- Ecore_List * flist, Ecore_List * dlist)
+static void ewl_fileselector_file_list_get(char *path, char *filter,
+ char *dfilter, Ecore_List * flist,
+ Ecore_List * dlist)
{
- regex_t preg;
+ regex_t freg, dreg;
Ewl_Fileselector_Data *d;
struct dirent *lecture;
DIR *rep;
@@ -418,10 +425,15 @@
int len;
if (filter) {
- if (regcomp(&preg, filter, REG_NOSUB | REG_EXTENDED))
+ if (regcomp(&freg, filter, REG_NOSUB | REG_EXTENDED))
filter = NULL;
}
+ if (dfilter) {
+ if (regcomp(&dreg, dfilter, REG_NOSUB | REG_EXTENDED))
+ dfilter = NULL;
+ }
+
/* Check if path is finished by a / and add it if there's none */
if (path[strlen(path) - 1] == '/')
path2 = strdup(path);
@@ -438,49 +450,64 @@
DRETURN(DLEVEL_STABLE);
}
+ /* Loop over all listings in the directory to build both lists */
while ((lecture = readdir(rep))) {
int match = 0;
+ Ecore_List *add = NULL;
+ regex_t *reg;
- if (!(strcmp(lecture->d_name, "..")))
- match = 1;
- else if (strcmp(lecture->d_name, ".")) {
- if (filter && !regexec(&preg, lecture->d_name, 0,
- NULL, 0))
- match = 1;
+ /* Skip over the simple case early */
+ if (!strcmp(lecture->d_name,"..") && !strcmp(path,"/"))
+ continue;
+
+ /* Setup a ful path copy to the listing */
+ len = strlen(path2) + strlen(lecture->d_name) + 1;
+ name = (char *) malloc(sizeof(char) * len);
+ memcpy(name, path2, strlen(path2));
+ memcpy(name + strlen(path2),
+ lecture->d_name, strlen(lecture->d_name));
+ name[len - 1] = '\0';
+
+ /* Set to NULL before determining the type of the listing */
+ reg = NULL;
+ if (stat(name, &buf) == 0) {
+ /* Determine the file or directory match */
+ if (S_ISDIR(buf.st_mode) && dlist) {
+ add = dlist;
+ if (dfilter)
+ reg = &dreg;
+ }
+ else {
+ add = flist;
+ if (filter)
+ reg = &freg;
+ }
}
- if (match) {
- len = strlen(path2) + strlen(lecture->d_name) + 1;
- name = (char *) malloc(sizeof(char) * len);
- memcpy(name, path2, strlen(path2));
- memcpy(name + strlen(path2),
- lecture->d_name, strlen(lecture->d_name));
- name[len - 1] = '\0';
- if(!strcmp(lecture->d_name,"..")&&!strcmp(path,"/"))
- continue;
- if (stat(name, &buf) == 0) {
- if (S_ISDIR(buf.st_mode) && dlist) {
- d =
ewl_fileselector_data_new(lecture->d_name,
- buf.st_size,
- buf.st_mtime,
- buf.st_mode);
- ecore_list_append(dlist, d);
- } else if (flist) {
- d =
ewl_fileselector_data_new(lecture->d_name,
- buf.st_size,
- buf.st_mtime,
- buf.st_mode);
- ecore_list_append(flist, d);
- }
- }
+ /* Determine if this item should be listed */
+ if (!strcmp(lecture->d_name, ".."))
+ match = 1;
+ else if (reg && !regexec(reg, lecture->d_name, 0, NULL, 0))
+ match = 1;
- free(name);
+ /* File matches so add it to the listing */
+ if (match && add) {
+ d = ewl_fileselector_data_new(lecture->d_name,
+ buf.st_size,
+ buf.st_mtime,
+ buf.st_mode);
+ ecore_list_append(add, d);
}
+
+ free(name);
}
- closedir(rep);
+ /* Clean up temporary variables */
+ closedir(rep);
if (filter)
- regfree(&preg);
+ regfree(&freg);
+ if (dfilter)
+ regfree(&dreg);
free(path2);
return;
@@ -498,6 +525,16 @@
}
void
+ewl_fileselector_destroy_cb(Ewl_Widget * w, void *ev_data __UNUSED__,
+ void *user_data __UNUSED__)
+{
+ Ewl_Fileselector *fs = EWL_FILESELECTOR(w);
+ IF_FREE(fs->path);
+ IF_FREE(fs->file);
+ IF_FREE(fs->dfilter);
+}
+
+void
ewl_fileselector_tooltip_destroy_cb(Ewl_Widget *w __UNUSED__,
void *ev_data __UNUSED__,
void *user_data)
@@ -602,7 +639,7 @@
files = ecore_list_new();
dirs = ecore_list_new();
- ewl_fileselector_file_list_get(path2, filter, files, dirs);
+ ewl_fileselector_file_list_get(path2, filter, fs->dfilter, files, dirs);
parent_win = EWL_WIDGET(ewl_embed_widget_find(EWL_WIDGET(fs)));
cont = ewl_container_redirect_get(EWL_CONTAINER(parent_win));
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- ewl_fileselector.h 17 Mar 2005 05:48:09 -0000 1.6
+++ ewl_fileselector.h 27 Apr 2005 14:01:28 -0000 1.7
@@ -45,8 +45,9 @@
Ewl_Widget *entry_file;
Ewl_Widget *entry_filter;
- char *path; /* current fileselector path */
- char *file; /* current selected item in the fileselector */
+ char *path; /* current fileselector path */
+ char *file; /* current selected item in the fileselector */
+ char *dfilter; /* current filter to apply to directories */
};
-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id=105hix
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs