Enlightenment CVS committal Author : raster Project : e17 Module : apps/e
Dir : e17/apps/e/src/bin Modified Files: e_config.c e_config.h e_fm.c e_fm_mime.c e_fm_mime.h Log Message: there is now a mime type ->? icon mapping that can work in many ways... hooray =================================================================== RCS file: /cvs/e/e17/apps/e/src/bin/e_config.c,v retrieving revision 1.202 retrieving revision 1.203 diff -u -3 -r1.202 -r1.203 --- e_config.c 9 Sep 2006 07:00:14 -0000 1.202 +++ e_config.c 16 Sep 2006 11:35:54 -0000 1.203 @@ -39,6 +39,7 @@ static E_Config_DD *_e_config_gadcon_edd = NULL; static E_Config_DD *_e_config_gadcon_client_edd = NULL; static E_Config_DD *_e_config_shelf_edd = NULL; +static E_Config_DD *_e_config_mime_icon_edd = NULL; /* externally accessible functions */ @@ -309,6 +310,14 @@ E_CONFIG_VAL(D, T, b3, INT); E_CONFIG_VAL(D, T, a3, INT); + _e_config_mime_icon_edd = E_CONFIG_DD_NEW("E_Config_Mime_Icon", E_Config_Mime_Icon); +#undef T +#undef D +#define T E_Config_Mime_Icon +#define D _e_config_mime_icon_edd + E_CONFIG_VAL(D, T, mime, STR); + E_CONFIG_VAL(D, T, icon, STR); + _e_config_edd = E_CONFIG_DD_NEW("E_Config", E_Config); #undef T #undef D @@ -489,6 +498,8 @@ E_CONFIG_VAL(D, T, wallpaper_grad_c2_g, INT); E_CONFIG_VAL(D, T, wallpaper_grad_c2_b, INT); + E_CONFIG_LIST(D, T, mime_icons, _e_config_mime_icon_edd); /**/ + e_config = e_config_domain_load("e", _e_config_edd); if (e_config) { @@ -1226,6 +1237,29 @@ e_config->desk_flip_animate_mode = 1; e_config->desk_flip_animate_interpolation = 0; e_config->desk_flip_animate_time = 0.2; + IFCFGEND; + + IFCFG(0x0102); + { + E_Config_Mime_Icon *mi; + +#define CFG_MIME_ICON(_mime, _icon) \ + mi = E_NEW(E_Config_Mime_Icon, 1); \ + mi->mime = evas_stringshare_add(_mime); \ + mi->icon = evas_stringshare_add(_icon); \ + e_config->mime_icons = evas_list_append(e_config->mime_icons, mi) + + CFG_MIME_ICON("image/jpeg", "THUMB"); + CFG_MIME_ICON("image/png", "THUMB"); + CFG_MIME_ICON("image/x-pixmap", "THUMB"); + CFG_MIME_ICON("image/svg+xml", "THUMB"); + CFG_MIME_ICON("image/gif", "THUMB"); + CFG_MIME_ICON("image/tiff", "THUMB"); + + CFG_MIME_ICON("application/x-desktop", "DESKTOP"); + +// CFG_MIME_ICON("image/*", "e/icons/fileman/mime/image"); + } IFCFGEND; #if 0 /* example of new config */ =================================================================== RCS file: /cvs/e/e17/apps/e/src/bin/e_config.h,v retrieving revision 1.119 retrieving revision 1.120 diff -u -3 -r1.119 -r1.120 --- e_config.h 4 Sep 2006 23:32:03 -0000 1.119 +++ e_config.h 16 Sep 2006 11:35:54 -0000 1.120 @@ -36,6 +36,7 @@ typedef struct _E_Config_Gadcon E_Config_Gadcon; typedef struct _E_Config_Gadcon_Client E_Config_Gadcon_Client; typedef struct _E_Config_Shelf E_Config_Shelf; +typedef struct _E_Config_Mime_Icon E_Config_Mime_Icon; typedef Eet_Data_Descriptor E_Config_DD; @@ -50,7 +51,7 @@ /* increment this whenever a new set of config values are added but the users * config doesn't need top be wiped - simply new values need to be put in */ -#define E_CONFIG_FILE_GENERATION 0x0101 +#define E_CONFIG_FILE_GENERATION 0x0102 #define E_CONFIG_FILE_VERSION ((E_CONFIG_FILE_EPOCH << 16) | E_CONFIG_FILE_GENERATION) #define E_EVAS_ENGINE_DEFAULT 0 @@ -249,6 +250,8 @@ int wallpaper_grad_c2_r; // INTERNAL int wallpaper_grad_c2_g; // INTERNAL int wallpaper_grad_c2_b; // INTERNAL + + Evas_List *mime_icons; }; struct _E_Config_Module @@ -356,6 +359,12 @@ unsigned char fit_size; const char *style; int size; +}; + +struct _E_Config_Mime_Icon +{ + char *mime; + char *icon; }; EAPI int e_config_init(void); =================================================================== RCS file: /cvs/e/e17/apps/e/src/bin/e_fm.c,v retrieving revision 1.56 retrieving revision 1.57 diff -u -3 -r1.56 -r1.57 --- e_fm.c 16 Sep 2006 03:03:25 -0000 1.56 +++ e_fm.c 16 Sep 2006 11:35:54 -0000 1.57 @@ -1575,15 +1575,18 @@ { if (ic->info.mime) { + const char *icon; + + icon = e_fm_mime_icon_get(ic->info.mime); + printf("%s -> %s | %s\n", ic->info.file, ic->info.mime, icon); /* use mime type to select icon */ - if ( - (!strcmp(ic->info.mime, "image/jpeg")) || - (!strcmp(ic->info.mime, "image/png")) || - (!strcmp(ic->info.mime, "image/gif")) || - (!strcmp(ic->info.mime, "image/tiff")) || - (!strcmp(ic->info.mime, "image/x-xpixmap")) || - (!strcmp(ic->info.mime, "image/svg+xml")) - ) + if (!icon) + { + ic->obj_icon = edje_object_add(evas_object_evas_get(ic->sd->obj)); + e_theme_edje_object_set(ic->obj_icon, "base/theme/fileman", + "e/icons/fileman/file"); + } + else if (!strcmp(icon, "THUMB")) { if (ic->info.pseudo_link) snprintf(buf, sizeof(buf), "%s/%s", ic->info.pseudo_dir, ic->info.file); @@ -1594,26 +1597,55 @@ e_thumb_icon_size_set(ic->obj_icon, 128, 128); evas_object_smart_callback_add(ic->obj_icon, "e_thumb_gen", _e_fm2_cb_icon_thumb_gen, ic); _e_fm2_icon_thumb(ic); - edje_object_part_swallow(ic->obj, "e.swallow.icon", ic->obj_icon); - evas_object_show(ic->obj_icon); } - else + else if (!strcmp(icon, "DESKTOP")) + { + E_App *app; + + if (ic->info.pseudo_link) + snprintf(buf, sizeof(buf), "%s/%s", ic->info.pseudo_dir, ic->info.file); + else + snprintf(buf, sizeof(buf), "%s/%s", ic->sd->realpath, ic->info.file); +/* FIXME FIXME FIXME: e_app_new() is SLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOW. it can + * be a complete hog. this destroys performance in fm2. :(:(:( + */ + app = e_app_new(buf, 0); + if (app) + { + ic->obj_icon = e_app_icon_add(evas_object_evas_get(ic->sd->obj), app); + e_object_unref(E_OBJECT(app)); + } + } + else if (!strncmp(icon, "e/icons/fileman/mime/", 21)) { - /* fixme: quick hack to get some icons - need to have a proper - * mime -> icon mapping users can edit - */ - p = strchr(ic->info.mime, '/'); - if (p) p++; - else p = (char *)ic->info.mime; - snprintf(buf, sizeof(buf), "e/icons/fileman/%s", p); ic->obj_icon = edje_object_add(evas_object_evas_get(ic->sd->obj)); - if (!e_theme_edje_object_set(ic->obj_icon, "base/theme/fileman", - buf)) + if (!e_theme_edje_object_set(ic->obj_icon, + "base/theme/fileman", + icon)) e_theme_edje_object_set(ic->obj_icon, "base/theme/fileman", "e/icons/fileman/file"); - edje_object_part_swallow(ic->obj, "e.swallow.icon", ic->obj_icon); - evas_object_show(ic->obj_icon); } + else + { + p = strrchr(icon, '.'); + if ((p) && (!strcmp(p, ".edj"))) + { + ic->obj_icon = edje_object_add(evas_object_evas_get(ic->sd->obj)); + if (!e_theme_edje_object_set(ic->obj_icon, + "base/theme/fileman", + icon)) + e_theme_edje_object_set(ic->obj_icon, "base/theme/fileman", + "e/icons/fileman/file"); + } + else + { + ic->obj_icon = e_icon_add(evas_object_evas_get(ic->sd->obj)); + e_icon_file_set(ic->obj_icon, icon); + } + } + edje_object_part_swallow(ic->obj, "e.swallow.icon", + ic->obj_icon); + evas_object_show(ic->obj_icon); return; } else =================================================================== RCS file: /cvs/e/e17/apps/e/src/bin/e_fm_mime.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- e_fm_mime.c 19 Aug 2006 15:18:00 -0000 1.4 +++ e_fm_mime.c 16 Sep 2006 11:35:54 -0000 1.5 @@ -12,6 +12,7 @@ }; /* local subsystem functions */ +static Evas_Bool _e_fm_mime_icon_foreach(Evas_Hash *hash, const char *key, void *data, void *fdata); static void _e_fm_mime_all_free(void); static void _e_fm_mime_update(void); static int _e_fm_mime_glob_remove(const char *glob); @@ -19,6 +20,7 @@ static void _e_fm_mime_shared_mimeinfo_globs_load(char *file); static Evas_List *mimes = NULL; +static Evas_Hash *icon_map = NULL; /* externally accessible functions */ EAPI const char * @@ -53,7 +55,116 @@ return NULL; } +/* returns: + * NULL == don't know + * "THUMB" == generate a thumb + * "e/icons/fileman/mime/..." == theme icon + * "/path/to/file....edj" = explicit icon edje file + * "/path/to/file..." = explicit image file to use + */ +EAPI const char * +e_fm_mime_icon_get(const char *mime) +{ + char buf[4096], buf2[4096], *homedir = NULL, *val; + Evas_List *l; + E_Config_Mime_Icon *mi; + Evas_List *freelist = NULL; + + /* 0.0 clean out hash cache once it has mroe than 256 entried in it */ + if (evas_hash_size(icon_map) > 256) + { + evas_hash_foreach(icon_map, _e_fm_mime_icon_foreach, &freelist); + while (freelist) + { + evas_stringshare_del(freelist->data); + freelist = evas_list_remove_list(freelist, freelist); + } + evas_hash_free(icon_map); + icon_map = NULL; + } + /* 0. look in mapping cache */ + val = evas_hash_find(icon_map, mime); + if (val) return val; + + strncpy(buf2, mime, sizeof(buf2) - 1); + buf2[sizeof(buf2) - 1] = 0; + val = strchr(buf2, '/'); + if (val) *val = 0; + + /* 1. look up in mapping to file or thumb (thumb has flag)*/ + for (l = e_config->mime_icons; l; l = l->next) + { + mi = l->data; + if (e_util_glob_match(mi->mime, mime)) + { + strncpy(buf, mi->icon, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = 0; + goto ok; + } + } + + /* 2. look up in ~/.e/e/icons */ + homedir = e_user_homedir_get(); + if (!homedir) return NULL; + + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, buf2); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, buf2); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, buf2); + if (ecore_file_exists(buf)) goto ok; + + /* 3. look up icon in theme */ + snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", mime); + val = (char *)e_theme_edje_file_get("base/theme/fileman", buf); + if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok; + snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", buf2); + val = (char *)e_theme_edje_file_get("base/theme/fileman", buf); + if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok; + + /* 4. look up icon in PREFIX/share/enlightent/data/icons */ + snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), mime); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), buf2); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), buf2); + if (ecore_file_exists(buf)) goto ok; + snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), buf2); + if (ecore_file_exists(buf)) goto ok; + + error: + if (homedir) free(homedir); + return NULL; + + ok: + val = (char *)evas_stringshare_add(buf); + icon_map = evas_hash_add(icon_map, mime, val); + if (homedir) free(homedir); + return val; + +} + /* local subsystem functions */ +static Evas_Bool +_e_fm_mime_icon_foreach(Evas_Hash *hash, const char *key, void *data, void *fdata) +{ + Evas_List **freelist; + + freelist = fdata; + *freelist = evas_list_append(*freelist, data); + return 1; +} + static void _e_fm_mime_all_free(void) { @@ -93,7 +204,7 @@ static time_t last_changed = 0; time_t ch; - snprintf(buf, sizeof(buf), "/usr/local/etc/mime.types"); + snprintf(buf, sizeof(buf), "/etc/mime.types"); ch = ecore_file_mod_time(buf); if ((ch != last_changed) || (reload)) { @@ -108,7 +219,7 @@ static time_t last_changed = 0; time_t ch; - snprintf(buf, sizeof(buf), "/etc/mime.types"); + snprintf(buf, sizeof(buf), "/usr/local/etc/mime.types"); ch = ecore_file_mod_time(buf); if ((ch != last_changed) || (reload)) { @@ -272,7 +383,7 @@ */ FILE *f; - char buf[4096], buf2[4096], mimetype[4096], ext[4096], *p, *pp; + char buf[4096], mimetype[4096], ext[4096], *p, *pp; E_Mime *mime; f = fopen(file, "rb"); @@ -302,8 +413,7 @@ if (mime) { mime->mime = evas_stringshare_add(mimetype); - snprintf(buf2, sizeof(buf2), "*.%s", ext); - mime->glob = evas_stringshare_add(buf2); + mime->glob = evas_stringshare_add(ext); if ((!mime->mime) || (!mime->glob)) { if (mime->mime) evas_stringshare_del(mime->mime); @@ -312,7 +422,7 @@ } else { - _e_fm_mime_glob_remove(buf2); + _e_fm_mime_glob_remove(ext); mimes = evas_list_append(mimes, mime); } } =================================================================== RCS file: /cvs/e/e17/apps/e/src/bin/e_fm_mime.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- e_fm_mime.h 30 Jul 2006 16:58:38 -0000 1.1 +++ e_fm_mime.h 16 Sep 2006 11:35:54 -0000 1.2 @@ -8,6 +8,7 @@ #define E_FM_MIME_H EAPI const char *e_fm_mime_filename_get(const char *fname); +EAPI const char *e_fm_mime_icon_get(const char *mime); #endif #endif ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs