Enlightenment CVS committal
Author : codewarrior
Project : e17
Module : apps/exhibit
Dir : e17/apps/exhibit/src/bin
Modified Files:
exhibit_main.c exhibit_sort.c exhibit_sort.h
Log Message:
Presort the tree entries before adding them to the tree using an array and
quicksort while they are still filenames. This brings back presorted file
listings.
===================================================================
RCS file: /cvs/e/e17/apps/exhibit/src/bin/exhibit_main.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -3 -r1.113 -r1.114
--- exhibit_main.c 8 Jul 2007 22:54:04 -0000 1.113
+++ exhibit_main.c 9 Jul 2007 23:50:41 -0000 1.114
@@ -9,6 +9,9 @@
/* defines the timer tick interval for tree inserts */
#define INSERTS_INTERVAL 0.15
+/* defines the initial size and increment size that file list arrays have */
+#define FILELIST_SIZE 5000
+
extern pid_t pid;
extern Evas_List *thumb_list;
@@ -16,6 +19,8 @@
struct _Ex_Populate_Data
{
+ int num;
+ char **entries;
char *selected_file;
Ex_Tree_Update update;
};
@@ -221,43 +226,33 @@
{
Ex_Populate_Data *data;
int i = 0;
- static DIR *dir = NULL;
- struct dirent *dir_entry;
-
+ static int cur = 0;
+
data = fdata;
- if (!dir)
- {
- if ((dir = opendir(".")) == NULL)
- {
- if (data)
- {
- if (data->selected_file)
- free(data->selected_file);
- free(data);
- }
- return 0;
- }
- }
etk_tree_freeze(ETK_TREE(e->cur_tab->itree));
etk_tree_freeze(ETK_TREE(e->cur_tab->dtree));
- while ((dir_entry = readdir(dir)) != NULL)
+ while (cur < data->num)
{
char image[PATH_MAX];
char imagereal[PATH_MAX];
struct stat st;
+ char *file;
+ file = data->entries[cur];
+
+ ++cur;
++i;
/* Do not include current dir/above dir */
- if ((!strcmp (dir_entry->d_name, ".")) || (!strcmp (dir_entry->d_name,
"..")))
+ if ((!strcmp (file, ".")) || (!strcmp (file, "..")))
continue;
/* Show hidden files and directories? */
- if ((!e->options->list_hidden) && (dir_entry->d_name[0] == '.'))
+ if ((!e->options->list_hidden) && (file[0] == '.'))
continue;
- snprintf(image, PATH_MAX, "%s", dir_entry->d_name);
+ snprintf(image, PATH_MAX, "%s", file);
if (data->update == EX_TREE_UPDATE_ALL || data->update ==
EX_TREE_UPDATE_DIRS)
{
@@ -267,9 +262,9 @@
etk_tree_row_append(ETK_TREE(e->cur_tab->dtree), NULL,
e->cur_tab->dcol,
etk_theme_icon_path_get(),
"places/folder_16",
- dir_entry->d_name, NULL);
-
etk_combobox_entry_item_append(ETK_COMBOBOX_ENTRY(e->combobox_entry),
dir_entry->d_name, NULL);
- e->cur_tab->dirs = evas_list_append(e->cur_tab->dirs,
dir_entry->d_name);
+ file, NULL);
+
etk_combobox_entry_item_append(ETK_COMBOBOX_ENTRY(e->combobox_entry), file,
NULL);
+ e->cur_tab->dirs = evas_list_append(e->cur_tab->dirs, file);
continue;
}
}
@@ -278,7 +273,7 @@
if (data->update == EX_TREE_UPDATE_DIRS)
continue;
- if ((!e->options->show_all_filetypes) &&
(!_ex_file_is_viewable(dir_entry->d_name)))
+ if ((!e->options->show_all_filetypes) && (!_ex_file_is_viewable(file)))
continue;
if(!realpath(image, imagereal))
@@ -296,18 +291,6 @@
}
}
- if (data->update == EX_TREE_UPDATE_FILES || data->update ==
EX_TREE_UPDATE_ALL)
- {
- if (e->options->default_sort == EX_SORT_BY_DATE)
- _ex_sort_date_cb(NULL, NULL);
- else if (e->options->default_sort == EX_SORT_BY_SIZE)
- _ex_sort_size_cb(NULL, NULL);
- else if (e->options->default_sort == EX_SORT_BY_NAME)
- _ex_sort_name_cb(NULL, NULL);
- else if (e->options->default_sort == EX_SORT_BY_RESOLUTION)
- _ex_sort_resol_cb(NULL, NULL);
- }
-
if (data->update == EX_TREE_UPDATE_ALL || data->update ==
EX_TREE_UPDATE_DIRS)
etk_tree_col_sort_full(e->cur_tab->dcol, _ex_main_dtree_compare_cb,
NULL, ETK_TRUE);
@@ -322,8 +305,12 @@
_ex_main_monitor_dir, NULL);
}
- closedir(dir);
- dir = NULL;
+ for (cur = 0; cur < data->num; cur++)
+ if (data->entries[cur])
+ free(data->entries[cur]);
+ if (data->entries)
+ free(data->entries);
+ cur = 0;
free(data->selected_file);
free(data);
return 0;
@@ -334,7 +321,13 @@
{
char back[PATH_MAX];
Ex_Populate_Data *data;
-
+ char **entries;
+ struct dirent *dir_entry;
+ DIR *dir;
+ int j = 1;
+ int i = 0;
+ int (*cmp)(const void *, const void *) = _ex_sort_cmp_name;
+
_ex_main_image_unset();
chdir(e->cur_tab->dir);
@@ -367,6 +360,53 @@
else
data->selected_file = NULL;
data->update = update;
+
+ dir = opendir(".");
+
+ if (!dir)
+ {
+ fprintf(stderr, "Could not open dir!\n");
+ return;
+ }
+
+ entries = calloc(FILELIST_SIZE, sizeof(char *));
+
+ while ((dir_entry = readdir(dir)) != NULL)
+ {
+ if (i == FILELIST_SIZE)
+ {
+ i = 0;
+ ++j;
+ entries = realloc(entries, j * FILELIST_SIZE * sizeof(char *));
+ }
+
+ entries[(j - 1) * FILELIST_SIZE + i] = strdup(dir_entry->d_name);
+ ++i;
+ }
+
+ if (j == 1)
+ j = 0;
+ else
+ j -= 1;
+
+ if (data->update == EX_TREE_UPDATE_FILES || data->update ==
EX_TREE_UPDATE_ALL)
+ {
+ if (e->options->default_sort == EX_SORT_BY_DATE)
+ cmp = _ex_sort_cmp_date;
+ else if (e->options->default_sort == EX_SORT_BY_SIZE)
+ cmp = _ex_sort_cmp_size;
+ else if (e->options->default_sort == EX_SORT_BY_NAME)
+ cmp = _ex_sort_cmp_name;
+ else if (e->options->default_sort == EX_SORT_BY_RESOLUTION)
+ cmp = _ex_sort_cmp_resol;
+ }
+
+ qsort(entries, FILELIST_SIZE * j + i, sizeof(char *), cmp);
+
+ data->entries = entries;
+ data->num = FILELIST_SIZE * j + i;
+ closedir(dir);
+
ecore_timer_add(0.001, _ex_main_populate_files_timer_cb, data);
/* Set the dir to the current dir at the end so we avoid stepdown
===================================================================
RCS file: /cvs/e/e17/apps/exhibit/src/bin/exhibit_sort.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- exhibit_sort.c 5 Apr 2007 09:31:29 -0000 1.12
+++ exhibit_sort.c 9 Jul 2007 23:50:41 -0000 1.13
@@ -6,6 +6,49 @@
static Ecore_Evas *ee_buf;
static Evas *evas_buf;
+static int _ex_sort_resol(char *f1, char *f2)
+{
+ Evas_Object *i1, *i2;
+ int w1, h1, w2, h2;
+
+ if(!ee_buf)
+ {
+ ee_buf = ecore_evas_buffer_new(0, 0);
+ evas_buf = ecore_evas_get(ee_buf);
+ }
+
+ if(_ex_file_is_ebg(f1))
+ {
+ w1 = 800;
+ h1 = 600;
+ }
+ else
+ {
+ i1 = evas_object_image_add(evas_buf);
+ evas_object_image_file_set(i1, f1, NULL);
+ evas_object_image_size_get(i1, &w1, &h1);
+ evas_object_del(i1);
+ }
+
+ if(_ex_file_is_ebg(f2))
+ {
+ w2 = 800;
+ h2 = 600;
+ }
+ else
+ {
+ i2 = evas_object_image_add(evas_buf);
+ evas_object_image_file_set(i2, f2, NULL);
+ evas_object_image_size_get(i2, &w2, &h2);
+ evas_object_del(i2);
+ }
+
+ if(w1 * h1 > w2 * h2)
+ return 1;
+ else
+ return -1;
+}
+
static int
_ex_sort_itree_name_compare_cb(Etk_Tree_Col *col, Etk_Tree_Row *row1,
Etk_Tree_Row *row2, void *data)
{
@@ -67,8 +110,6 @@
_ex_sort_itree_resol_compare_cb(Etk_Tree_Col *col, Etk_Tree_Row *row1,
Etk_Tree_Row *row2, void *data)
{
char *f1, *f2;
- Evas_Object *i1, *i2;
- int w1, h1, w2, h2;
if (!row1 || !row2 || !col)
return 0;
@@ -76,42 +117,48 @@
etk_tree_row_fields_get(row1, col, NULL, NULL, &f1, NULL);
etk_tree_row_fields_get(row2, col, NULL, NULL, &f2, NULL);
- if(!ee_buf)
- {
- ee_buf = ecore_evas_buffer_new(0, 0);
- evas_buf = ecore_evas_get(ee_buf);
- }
+ return _ex_sort_resol(f1, f2);
+}
- if(_ex_file_is_ebg(f1))
- {
- w1 = 800;
- h1 = 600;
- }
- else
- {
- i1 = evas_object_image_add(evas_buf);
- evas_object_image_file_set(i1, f1, NULL);
- evas_object_image_size_get(i1, &w1, &h1);
- evas_object_del(i1);
- }
+int _ex_sort_cmp_name(const void *p1, const void *p2)
+{
+ /* The actual arguments to this function are "pointers to
+ pointers to char", but strcmp() arguments are "pointers
+ to char", hence the following cast plus dereference
+ */
- if(_ex_file_is_ebg(f2))
- {
- w2 = 800;
- h2 = 600;
- }
+ return strcasecmp(* (char * const *) p1, * (char * const *) p2);
+}
+
+int _ex_sort_cmp_size(const void *p1, const void *p2)
+{
+ struct stat s1, s2;
+
+ stat(* (char * const *) p1, &s1);
+ stat(* (char * const *) p2, &s2);
+
+ if(s1.st_size > s2.st_size)
+ return 1;
else
- {
- i2 = evas_object_image_add(evas_buf);
- evas_object_image_file_set(i2, f2, NULL);
- evas_object_image_size_get(i2, &w2, &h2);
- evas_object_del(i2);
- }
+ return -1;
+}
+
+int _ex_sort_cmp_date(const void *p1, const void *p2)
+{
+ struct stat s1, s2;
- if(w1 * h1 > w2 * h2)
+ stat(* (char * const *) p1, &s1);
+ stat(* (char * const *) p2, &s2);
+
+ if(s1.st_mtime > s2.st_mtime)
return 1;
else
- return -1;
+ return -1;
+}
+
+int _ex_sort_cmp_resol(const void *p1, const void *p2)
+{
+ return _ex_sort_resol(* (char * const *) p1, * (char * const *) p2);
}
void
===================================================================
RCS file: /cvs/e/e17/apps/exhibit/src/bin/exhibit_sort.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- exhibit_sort.h 2 Sep 2006 01:43:23 -0000 1.3
+++ exhibit_sort.h 9 Jul 2007 23:50:41 -0000 1.4
@@ -9,5 +9,9 @@
void _ex_sort_size_cb(Etk_Object *obj, void *data);
void _ex_sort_date_cb(Etk_Object *obj, void *data);
void _ex_sort_resol_cb(Etk_Object *obj, void *data);
-
+int _ex_sort_cmp_name(const void *p1, const void *p2);
+int _ex_sort_cmp_date(const void *p1, const void *p2);
+int _ex_sort_cmp_size(const void *p1, const void *p2);
+int _ex_sort_cmp_resol(const void *p1, const void *p2);
+
#endif
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs