Enlightenment CVS committal Author : kiwi Project : e_modules Module : photo
Dir : e_modules/photo/src/module Modified Files: e_mod_main.c photo_config.c photo_item.h photo_picture.c photo_picture.h photo_picture_local.c Log Message: new loader system and fix a bug * the new picture loader system is much more light and fast :) Its inspirated from the file scan of efm2 * fix a typo * free the config data descriptors * fix a bug when you try to restart loading while thumbnailing =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/e_mod_main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_mod_main.c 7 Jul 2006 18:37:28 -0000 1.2 +++ e_mod_main.c 22 Jul 2006 22:30:52 -0000 1.3 @@ -266,8 +266,5 @@ static void _theme_shutdown(void) { - if (photo->theme) - { - E_FREE(photo->theme); - } + E_FREE(photo->theme); } =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/photo_config.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- photo_config.c 7 Jul 2006 17:15:25 -0000 1.1 +++ photo_config.c 22 Jul 2006 22:30:52 -0000 1.2 @@ -170,6 +170,10 @@ E_FREE(photo->config); + E_CONFIG_DD_FREE(_photo_edd); + E_CONFIG_DD_FREE(_photo_dir_edd); + E_CONFIG_DD_FREE(_photo_item_edd); + return 1; } =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/photo_item.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- photo_item.h 12 Jul 2006 06:11:39 -0000 1.3 +++ photo_item.h 22 Jul 2006 22:30:52 -0000 1.4 @@ -24,8 +24,8 @@ #define ITEM_SHOW_LABEL_PARENT 2 #define ITEM_MOUSE_OVER_ACTION_DEFAULT 1 -#define ITEM_MOUSE_LEFT_ACTION_DEFAULT 2 -#define ITEM_MOUSE_MIDDLE_ACTION_DEFAULT 7 +#define ITEM_MOUSE_LEFT_ACTION_DEFAULT 4 +#define ITEM_MOUSE_MIDDLE_ACTION_DEFAULT 2 #define ITEM_ACTION_NO 0 #define ITEM_ACTION_LABEL 1 =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/photo_picture.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- photo_picture.c 12 Jul 2006 18:39:08 -0000 1.5 +++ photo_picture.c 22 Jul 2006 22:30:52 -0000 1.6 @@ -27,7 +27,7 @@ //photo_picture_net_shutdown(); } -Picture *photo_picture_new(char *path, char *name, int thumb_it, void (*func_done) (void *data, Evas_Object *obj, void *event_info)) +Picture *photo_picture_new(char *path, int thumb_it, void (*func_done) (void *data, Evas_Object *obj, void *event_info)) { Picture *picture; int th_w, th_h; @@ -36,7 +36,7 @@ th_w = photo->config->pictures_thumb_size; th_h = photo->config->pictures_thumb_size; - ext = strrchr(name, '.'); + ext = strrchr(path, '.'); if (!ext) return NULL; if (strcasecmp(ext, ".jpg") && strcasecmp(ext, ".JPG") && @@ -44,11 +44,11 @@ strcasecmp(ext, ".png") && strcasecmp(ext, ".PNG")) return NULL; - DPICL(("New picture : file %s", name)); + DPICL(("New picture : file %s", path)); picture = E_NEW(Picture, 1); picture->path = evas_stringshare_add(path); - picture->infos.name = photo_picture_name_get(name); + picture->infos.name = photo_picture_name_get(path); picture->from = PICTURE_LOCAL; if (thumb_it) =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/photo_picture.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- photo_picture.h 12 Jul 2006 18:39:08 -0000 1.4 +++ photo_picture.h 22 Jul 2006 22:30:52 -0000 1.5 @@ -62,7 +62,7 @@ int photo_picture_init(void); void photo_picture_shutdown(void); -Picture *photo_picture_new(char *path, char *name, int thumb_it, void (*func_done) (void *data, Evas_Object *obj, void *event_info)); +Picture *photo_picture_new(char *path, int thumb_it, void (*func_done) (void *data, Evas_Object *obj, void *event_info)); int photo_picture_free(Picture *p, int force, int force_now); int photo_picture_load(Picture *pic, Evas *evas); =================================================================== RCS file: /cvs/e/e_modules/photo/src/module/photo_picture_local.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- photo_picture_local.c 12 Jul 2006 23:20:54 -0000 1.6 +++ photo_picture_local.c 22 Jul 2006 22:30:52 -0000 1.7 @@ -37,13 +37,16 @@ /* ecore idler to load in background */ struct { + Evas_List *queue; + Ecore_Idler *idler; + Ecore_Timer *timer; Popup_Warn *popup; Picture_Local_Dir *current_dir; Evas_List *dirs; - Ecore_List *file; + DIR *odir; } loader; /* event to warn photo items wich are waiting for pictures */ @@ -60,6 +63,7 @@ static void _pictures_old_del(int force, int force_now); static int _load_idler(void *data); +static int _load_timer(void *data); static void _load_idler_stop(void); static int _load_cb_ev_fill(void *data, int type, void *event); @@ -122,7 +126,9 @@ pictures_local->thumb.popup = NULL; /* initialise and launch loader */ + pictures_local->loader.queue = NULL; pictures_local->loader.idler = ecore_idler_add(_load_idler, NULL); + pictures_local->loader.timer = ecore_timer_add(0.2, _load_timer, NULL); if (photo->config_dialog) photo_config_dialog_refresh_local_load(); @@ -299,9 +305,10 @@ Picture_Local_List *pl; Picture_Local_Dir *d; Evas_List *l; - Picture *picture; - char *name, *file_tmp; + char *file_tmp; char file[200]; + struct dirent *fs; + struct stat fs_stat; pl = pictures_local; @@ -329,9 +336,7 @@ pl->loader.current_dir = d; pl->loader.dirs = evas_list_append(pl->loader.dirs, strdup(d->path)); - if (pl->loader.file && ecore_list_is_empty(pl->loader.file)) - ecore_list_destroy(pl->loader.file); - pl->loader.file = NULL; + pl->loader.odir = NULL; DPICL(("Going to read %s", d->path)); if (photo->config_dialog) photo_config_dialog_refresh_local_dirs(); @@ -341,9 +346,7 @@ /* no more directories to load */ if (!pl->loader.current_dir) { - if (pl->loader.file) - ecore_list_destroy(pl->loader.file); - pl->loader.file = NULL; + pl->loader.odir = NULL; pl->loader.idler = NULL; if (photo->config_dialog) { @@ -359,74 +362,114 @@ evas_list_count(pl->pictures) - pl->pictures_waiting_delete); POPUP_LOADING(pl, buf, 3); } + if (pl->loader.timer) + { + ecore_timer_del(pl->loader.timer); + } + pl->loader.timer = ecore_timer_add(0.0001, _load_timer, NULL); return 0; } } /* first dir list */ - if ( !pl->loader.file ) - pl->loader.file = ecore_file_ls(evas_list_data(pl->loader.dirs)); + if ( !pl->loader.odir ) + pl->loader.odir = opendir((char *)evas_list_data(pl->loader.dirs)); /* no more files in the current loader.dirs item */ - if ( !(name = ecore_list_next(pl->loader.file)) ) + if ( !pl->loader.odir || !(fs = readdir(pl->loader.odir)) ) { DD(("removing %s", (char *)evas_list_data(pl->loader.dirs))); /* go to next dir */ - ecore_list_destroy(pl->loader.file); - pl->loader.file = NULL; + closedir(pl->loader.odir); + pl->loader.odir = NULL; free(evas_list_data(pl->loader.dirs)); pl->loader.dirs = evas_list_remove_list(pl->loader.dirs, pl->loader.dirs); - if (!evas_list_count(pl->loader.dirs)) - return 1; - /* list the new dir */ - pl->loader.file = ecore_file_ls(evas_list_data(pl->loader.dirs)); return 1; } + if ( (!strcmp(fs->d_name, ".")) || (!strcmp(fs->d_name, "..")) || + (!pl->loader.current_dir->read_hidden && (fs->d_name[0] == '.')) ) + return 1; + snprintf(file, sizeof(file), - "%s/%s", (char *)evas_list_data(pl->loader.dirs), name); + "%s/%s", (char *)evas_list_data(pl->loader.dirs), fs->d_name); - if (!pl->loader.current_dir->read_hidden && (name[0] == '.')) - return 1; - if ((file_tmp = ecore_file_readlink(file))) + if (stat(file, &fs_stat) < 0) return 1; + + if ( (S_ISLNK(fs_stat.st_mode)) && + (file_tmp = ecore_file_readlink(file)) ) { - name = strdup(ecore_file_get_file(file_tmp)); strncpy(file, file_tmp, sizeof(file)); + if (stat(file, &fs_stat) < 0) return 0; } - if (pl->loader.current_dir->recursive && - ecore_file_is_dir(file)) + + if ( pl->loader.current_dir->recursive && + (S_ISDIR(fs_stat.st_mode)) ) { pl->loader.dirs = evas_list_append(pl->loader.dirs, strdup(file)); DPICL(("added %s to loader dirs", file)); return 1; } - /* create the picture */ - picture = photo_picture_new(file, name, 1, _thumb_generate_cb); - if (!picture) - return 1; + /* enqueue the file */ + pl->loader.queue = evas_list_append(pl->loader.queue, strdup(file)); + + return 1; +} - pl->thumb.nb++; - pl->pictures = evas_list_append(pl->pictures, picture); +static int +_load_timer(void *data) +{ + Picture_Local_List *pl; + Picture *picture; + char *file; + int rounds; - /* loader popups */ - if (photo->config->local.popup == PICTURE_LOCAL_POPUP_ALWAYS) + pl = pictures_local; + + rounds = 0; + while(pl->loader.queue)// && (rounds < 50)) { - int nb; - - /* loading popup message */ - nb = evas_list_count(pl->pictures) - pl->pictures_waiting_delete; - if (nb && ((nb == 1) || !(nb%PICTURE_LOCAL_POPUP_LOADER_MOD))) + file = pl->loader.queue->data; + + /* create the picture */ + picture = photo_picture_new(file, 1, _thumb_generate_cb); + if (picture) { - char buf[50]; + pl->thumb.nb++; + pl->pictures = evas_list_append(pl->pictures, picture); - if (nb == 1) - snprintf(buf, sizeof(buf), "Scanning for pictures"); - else - snprintf(buf, sizeof(buf), "%d pictures found", nb); - POPUP_LOADING(pl, buf, 0); + /* loader popups */ + if (photo->config->local.popup == PICTURE_LOCAL_POPUP_ALWAYS) + { + int nb; + + /* loading popup message */ + nb = evas_list_count(pl->pictures) - pl->pictures_waiting_delete; + if (nb && ((nb == 1) || !(nb%PICTURE_LOCAL_POPUP_LOADER_MOD))) + { + char buf[50]; + + if (nb == 1) + snprintf(buf, sizeof(buf), "Scanning for pictures"); + else + snprintf(buf, sizeof(buf), "%d pictures found", nb); + POPUP_LOADING(pl, buf, 0); + } + } } + + free(file); + pl->loader.queue = evas_list_remove_list(pl->loader.queue, + pl->loader.queue); + rounds++; + } + + if (!pl->loader.idler) + { + pl->loader.timer = NULL; + return 0; } return 1; @@ -446,6 +489,11 @@ ecore_idler_del(pl->loader.idler); pl->loader.idler = NULL; } + if (pl->loader.timer) + { + ecore_timer_del(pl->loader.timer); + pl->loader.timer = NULL; + } if (pl->loader.popup) { @@ -471,10 +519,9 @@ pl->loader.dirs = NULL; } - if (pl->loader.file) + if (pl->loader.odir) { - ecore_list_destroy(pl->loader.file); - pl->loader.file = NULL; + pl->loader.odir = NULL; } } @@ -516,8 +563,6 @@ pl = pictures_local; picture = data; - DPICL(("back from thumb generation of %s", picture->infos.name)); - pl->thumb.nb--; if (!obj) @@ -531,6 +576,7 @@ evas_object_geometry_get(obj, NULL, NULL, &picture->original_w, &picture->original_h); DPICL(("thumb generated %dx%d", picture->original_w, picture->original_h)); + picture->thumb = PICTURE_THUMB_READY; @@ -544,9 +590,11 @@ e_module_dialog_show(photo->module, _("Photo Module Information"), _("<hilight>Creating thumbs</hilight><br><br>" "Some pictures are being thumbed in a <hilight>background task</hilight>.<br>" - "It can take a while, but after, loading will be faster :)<br><br>" + "It can take a while, but after, loading will be faster and lighter :)<br><br>" "Each time wou will load pictures that haven't been loaded in Photo module before,<br>" - "they will be thumbed")); + "they will be thumbed.<br><br>" + "While creating popups, you will not be able to see any picture in Photo.<br>" + "I hope i'll be able to change that :)")); } /* when still thumbnailing after loading */ @@ -606,21 +654,24 @@ _thumb_generate_stop(void) { Picture_Local_List *pl; - Evas_List *l; - Picture *picture; + Picture *p; + int no = 0; pl = pictures_local; if (pl->thumb.nb) - { - for (l=pl->pictures; l; l=evas_list_next(l)) + { + while ( (p = evas_list_nth(pictures_local->pictures, no)) ) { - picture = evas_list_data(l); - if (picture->thumb != PICTURE_THUMB_WAITING) - continue; - - e_thumb_icon_end(picture->picture); - photo_picture_free(picture, 1, 1); + if (p->thumb == PICTURE_THUMB_WAITING) + { + e_thumb_icon_end(p->picture); + photo_picture_free(p, 1, 1); + pictures_local->pictures = evas_list_remove(pictures_local->pictures, + p); + } + else + no++; } pl->thumb.nb = 0; } ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs