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:
Use ecore_file (patch from mekius_).
Hide the file filter regex from the user.
Document the widget fields.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- ewl_fileselector.c  6 Jul 2005 13:44:39 -0000       1.17
+++ ewl_fileselector.c  14 Jul 2005 05:59:35 -0000      1.18
@@ -1,6 +1,7 @@
 #include <Ewl.h>
 #include "ewl_debug.h"
 #include "ewl_macros.h"
+#include <Ecore_File.h>
 
 #include <sys/stat.h>
 #include <stdio.h>
@@ -173,7 +174,9 @@
                                           EWL_FLAG_FILL_SHRINK |
                                           EWL_FLAG_FILL_HFILL);
 
-               misc = ewl_text_new("File:");
+               misc = ewl_label_new("File:");
+               ewl_object_fill_policy_set(EWL_OBJECT(misc),
+                                          EWL_FLAG_FILL_NONE);
                ewl_container_child_append(EWL_CONTAINER(hbox), misc);
                ewl_widget_show(misc);
 
@@ -186,32 +189,10 @@
                ewl_widget_show(hbox);
        }
 
-       /* The filter label and entry */
-       hbox = ewl_hbox_new();
-       if (hbox) {
-               ewl_object_fill_policy_set(EWL_OBJECT(hbox),
-                                          EWL_FLAG_FILL_SHRINK |
-                                          EWL_FLAG_FILL_HFILL);
-
-               misc = ewl_text_new("Filter:");
-               ewl_object_size_request(EWL_OBJECT(misc), 10, 50);
-               ewl_container_child_append(EWL_CONTAINER(hbox), misc);
-               ewl_widget_show(misc);
-
-               fs->entry_filter = ewl_entry_new("^[^\\.]");
-               ewl_callback_append(fs->entry_filter,
-                               EWL_CALLBACK_VALUE_CHANGED,
-                               ewl_fileselector_filter_cb,
-                               fs);
-               ewl_container_child_append(EWL_CONTAINER(hbox),
-                                          fs->entry_filter);
-               ewl_widget_show(fs->entry_filter);
-
-               ewl_container_child_append(EWL_CONTAINER(fs), hbox);
-               ewl_widget_show(hbox);
-       }
-
+       /* The default filter values */
+       fs->ffilter = strdup("^[^\\.]");
        fs->dfilter = strdup("^[^\\.][^$]");
+
        tmp = getenv("HOME");
        fs->path = strdup((tmp ? tmp : "/"));
 
@@ -472,12 +453,13 @@
 {
        regex_t freg, dreg;
        Ewl_Fileselector_Data *d;
-       struct dirent *lecture;
-       DIR *rep;
        struct stat buf;
        char *name;
        char *path2;
        int len;
+       Ecore_List *file_list = NULL;
+       char *listing = NULL;
+       
 
        if (filter) {
                if (regcomp(&freg, filter, REG_NOSUB | REG_EXTENDED))
@@ -498,36 +480,34 @@
                path2[strlen(path)] = '/';
                path2[strlen(path) + 1] = '\0';
        }
-
-       rep = opendir(path2);
-       if (!rep) {
-               free(path2);
-               DRETURN(DLEVEL_STABLE);
-       }
+       
+       /* Get directory listing, store, and move to beginning of list */
+       file_list = ecore_file_ls(path2);
+       ecore_list_goto_first(file_list);
 
        /* Loop over all listings in the directory to build both lists */
-       while ((lecture = readdir(rep))) {
+       while ( (!ecore_list_is_empty(file_list)) &&
+               (!(ecore_list_index(file_list) >= 
(ecore_list_nodes(file_list)))) && 
+               (listing = strdup((char *)ecore_list_next(file_list))) ) {
+               
                int match = 0;
                Ecore_List *add = NULL;
                regex_t *reg;
-
-               /* 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));
+               len = strlen(path2) + strlen(listing) + 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';
+               listing, strlen(listing)); 
+               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) {
+               
+               /* Determine type of listing */
+               if(stat(name, &buf) == 0) {
+                       if(ecore_file_is_dir(name)) {
                                add = dlist;
                                if (dfilter)
                                        reg = &dreg;
@@ -540,14 +520,14 @@
                }
 
                /* Determine if this item should be listed */
-               if (!strcmp(lecture->d_name, ".."))
+               if (!strcmp(listing, ".."))
                        match = 1;
-               else if (reg && !regexec(reg, lecture->d_name, 0, NULL, 0))
+               else if (reg && !regexec(reg, listing, 0, NULL, 0))
                        match = 1;
-
+       
                /* File matches so add it to the listing */
                if (match && add) {
-                       d = ewl_fileselector_data_new(lecture->d_name,
+                       d = ewl_fileselector_data_new(listing,
                                                      buf.st_size,
                                                      buf.st_mtime,
                                                      buf.st_mode);
@@ -555,16 +535,20 @@
                }
 
                free(name);
+               free(listing);
        }
-
+       
        /* Clean up temporary variables */
-       closedir(rep);
        if (filter)
                regfree(&freg);
        if (dfilter)
                regfree(&dreg);
-       free(path2);
-
+       free(path2);    
+       path2 = NULL;
+       
+       ecore_list_destroy(file_list);
+       file_list = NULL;       
+       
        return;
 }
 
@@ -702,7 +686,6 @@
 
 static void ewl_fileselector_path_setup(Ewl_Fileselector * fs, char *path)
 {
-       char *filter;
        Ewl_Fileselector_Data *d;
        Ewl_Widget *parent_win;
        Ewl_Container *cont;
@@ -722,10 +705,8 @@
        ecore_list_clear(fs->files);
 
        /*
-        * Setup a regex for matching files.
+        * Determine if it's an absolute path or relative path.
         */
-       filter = ewl_text_text_get(EWL_TEXT(fs->entry_filter));
-
        if (path[strlen(path) - 1] == '/')
                path2 = strdup(path);
        else {
@@ -740,7 +721,8 @@
 
        files = ecore_list_new();
        dirs = ecore_list_new();
-       ewl_fileselector_file_list_get(path2, filter, fs->dfilter, files, dirs);
+       ewl_fileselector_file_list_get(path2, fs->ffilter, 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.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- ewl_fileselector.h  10 Jun 2005 23:15:56 -0000      1.9
+++ ewl_fileselector.h  14 Jul 2005 05:59:35 -0000      1.10
@@ -38,17 +38,17 @@
  */
 struct Ewl_Fileselector
 {
-       Ewl_Box        box;         /* the box containing the widgets */
-       Ewl_Widget    *list_dirs;   /* directory table */
-       Ewl_Widget    *list_files;  /* file table */
-       Ewl_Widget    *entry_dir;
-       Ewl_Widget    *entry_file;
-       Ewl_Widget    *entry_filter;
+       Ewl_Box        box;          /**< the box containing the widgets */
+       Ewl_Widget    *list_dirs;    /**< directory table */
+       Ewl_Widget    *list_files;   /**< file table */
+       Ewl_Widget    *entry_dir;    /**< current directory selected  */
+       Ewl_Widget    *entry_file;   /**< current file selected or typed */
   
-       char          *path;    /* current fileselector path */
-       Ecore_List    *files;   /* current selected items in the fileselector */
-       char          *dfilter; /* current filter to apply to directories */
-       unsigned int   multi_select; /* is the selector multi select or not */
+       char          *path;         /**< current fileselector path */
+       Ecore_List    *files;        /**< current selection in fileselector */
+       char          *ffilter;      /**< current filter applied to files */
+       char          *dfilter;      /**< current filter for directories */
+       unsigned int   multi_select; /**< is the selector multi select or not */
 };
 
 Ewl_Widget     *ewl_fileselector_new();




-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to