From 7722513648863bde05d13a3656c8938e8f0a7733 Mon Sep 17 00:00:00 2001 From: codewarrior Date: Sun, 14 Oct 2007 12:22:52 +0000 Subject: [PATCH] Skeleton code for upcoming context sensitive menus in EFM. This does nothing and should be disregarded right now. (= SVN revision: 32058 --- src/bin/e_fm_mime.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/e_fm_mime.h | 15 ++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/bin/e_fm_mime.c b/src/bin/e_fm_mime.c index 9030078ce..9a3d4a15c 100644 --- a/src/bin/e_fm_mime.c +++ b/src/bin/e_fm_mime.c @@ -115,6 +115,84 @@ e_fm_mime_icon_cache_flush(void) icon_map = NULL; } +static Evas_Hash *_mime_handlers = NULL; +static Evas_Hash *_glob_handlers = NULL; + +/* create (allocate), set properties, and return a new mime handler */ +EAPI E_Fm_Mime_Handler * +e_fm_mime_handler_new(const char *label, const char *icon_group, void (*action_func) (Evas_Object *obj, const char *path, void *data), int (test_func) (Evas_Object *obj, const char *path, void *data)) +{ + E_Fm_Mime_Handler *handler; + + if (!label || !action_func) + return NULL; + + handler = E_NEW( E_Fm_Mime_Handler, 1); + if (!handler) + return NULL; + + handler->label = strdup(label); + handler->icon_group = icon_group ? strdup(icon_group) : NULL; + handler->action_func = action_func; + handler->test_func = test_func; + + /* TODO: add data for both action_cb and test_cb */ + + return handler; +} + +/* associate a certain mime type with a handler */ +EAPI int +e_fm_mime_handler_mime_add(E_Fm_Mime_Handler *handler, const char *mime) +{ + Evas_List *handlers; + + if (!handler || !mime) + return 0; + + /* if there's an entry for this mime already, then append to its list */ + if ((handlers = evas_hash_find(_mime_handlers, mime))) + { + handlers = evas_list_append(handlers, handler); + _mime_handlers = evas_hash_modify(_mime_handlers, mime, handlers); + } + else + { + /* no previous entry for this mime, lets add one */ + handlers = NULL; + handlers = evas_list_append(handlers, handler); + _mime_handlers = evas_hash_add(_mime_handlers, mime, handlers); + } + + return 1; +} + +/* associate a certain glob with a handler */ +EAPI int +e_fm_mime_handler_glob_add(E_Fm_Mime_Handler *handler, const char *glob) +{ + Evas_List *handlers; + + if (!handler || !glob) + return 0; + + /* if there's an entry for this glob already, then append to its list */ + if ((handlers = evas_hash_find(_glob_handlers, glob))) + { + handlers = evas_list_append(handlers, handler); + _glob_handlers = evas_hash_modify(_glob_handlers, glob, handlers); + } + else + { + /* no previous entry for this mime, lets add one */ + handlers = NULL; + handlers = evas_list_append(handlers, handler); + _glob_handlers = evas_hash_add(_mime_handlers, glob, handlers); + } + + return 1; +} + /* local subsystem functions */ static Evas_Bool _e_fm_mime_icon_foreach(Evas_Hash *hash, const char *key, void *data, void *fdata) diff --git a/src/bin/e_fm_mime.h b/src/bin/e_fm_mime.h index 70e111b2b..d9127bf22 100644 --- a/src/bin/e_fm_mime.h +++ b/src/bin/e_fm_mime.h @@ -7,9 +7,22 @@ #ifndef E_FM_MIME_H #define E_FM_MIME_H +typedef struct _E_Fm_Mime_Handler E_Fm_Mime_Handler; + +struct _E_Fm_Mime_Handler +{ + const char *label, *icon_group; + void (*action_func) (Evas_Object *obj, const char *path, void *data); + int (*test_func) (Evas_Object *obj, const char *path, void *data); +}; + EAPI const char *e_fm_mime_filename_get(const char *fname); EAPI const char *e_fm_mime_icon_get(const char *mime); EAPI void e_fm_mime_icon_cache_flush(void); - + +EAPI E_Fm_Mime_Handler *e_fm_mime_handler_new(const char *label, const char *icon_group, void (*action_func) (Evas_Object *obj, const char *path, void *data), int (test_func) (Evas_Object *obj, const char *path, void *data)); +EAPI int e_fm_mime_handler_mime_add(E_Fm_Mime_Handler *handler, const char *mime); +EAPI int e_fm_mime_handler_glob_add(E_Fm_Mime_Handler *handler, const char *glob); + #endif #endif