forked from enlightenment/enlightenment
there is now a mime type ->? icon mapping that can work in many ways... hooray
SVN revision: 25874
This commit is contained in:
parent
49415b41d1
commit
8c9abfcdc5
1
TODO
1
TODO
|
@ -37,7 +37,6 @@ Some of the things (in very short form) that need to be done to E17...
|
|||
* fm2 needs way to replace or extend the right click menu (disable/enable
|
||||
rename/delete/refresh etc.)
|
||||
* fm2 needs a mime filter
|
||||
* fm2 needs to have a mime & filetype -> icon mapping
|
||||
* middle mouse on gadgets as a quick move/resize thing?
|
||||
* language packs: need to have a tool to load/setup a language pack (which
|
||||
means .mo compiled files from a .po, an optional font and a config file that
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,6 +39,7 @@ static E_Config_DD *_e_config_color_class_edd = NULL;
|
|||
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_init(void)
|
|||
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_init(void)
|
|||
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)
|
||||
{
|
||||
|
@ -1228,6 +1239,29 @@ e_config_init(void)
|
|||
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 */
|
||||
IFCFG(0x0090); /* the version # where this value(s) was introduced */
|
||||
e_config->new_value = 10; /* set the value(s) */
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef struct _E_Config_Desktop_Name E_Config_Desktop_Name;
|
|||
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 @@ typedef Eet_Data_Descriptor E_Config_DD;
|
|||
/* 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 @@ struct _E_Config
|
|||
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
|
||||
|
@ -358,6 +361,12 @@ struct _E_Config_Shelf
|
|||
int size;
|
||||
};
|
||||
|
||||
struct _E_Config_Mime_Icon
|
||||
{
|
||||
char *mime;
|
||||
char *icon;
|
||||
};
|
||||
|
||||
EAPI int e_config_init(void);
|
||||
EAPI int e_config_shutdown(void);
|
||||
|
||||
|
|
|
@ -1575,15 +1575,18 @@ _e_fm2_icon_icon_set(E_Fm2_Icon *ic)
|
|||
{
|
||||
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_fm2_icon_icon_set(E_Fm2_Icon *ic)
|
|||
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 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))
|
||||
{
|
||||
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
|
||||
{
|
||||
/* 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))
|
||||
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);
|
||||
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
|
||||
|
|
|
@ -12,6 +12,7 @@ struct _E_Mime
|
|||
};
|
||||
|
||||
/* 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_mime_types_load(char *file);
|
|||
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 @@ e_fm_mime_filename_get(const char *fname)
|
|||
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 @@ _e_fm_mime_update(void)
|
|||
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 @@ _e_fm_mime_update(void)
|
|||
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 @@ _e_fm_mime_shared_mimeinfo_globs_load(char *file)
|
|||
|
||||
*/
|
||||
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 @@ _e_fm_mime_shared_mimeinfo_globs_load(char *file)
|
|||
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 @@ _e_fm_mime_shared_mimeinfo_globs_load(char *file)
|
|||
}
|
||||
else
|
||||
{
|
||||
_e_fm_mime_glob_remove(buf2);
|
||||
_e_fm_mime_glob_remove(ext);
|
||||
mimes = evas_list_append(mimes, mime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue