From abcc8f9ad36322f745d489c4463bf5bdffa233e8 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 30 Nov 2011 04:00:51 +0000 Subject: [PATCH] add new functions evry_item_{app,file}_free for freeing standard file/app items SVN revision: 65705 --- src/modules/everything/evry.c | 18 ++++++++++++++++++ src/modules/everything/evry_api.h | 7 +++---- src/modules/everything/evry_plug_apps.c | 17 ++--------------- src/modules/everything/evry_plug_files.c | 20 ++++---------------- src/modules/everything/evry_types.h | 3 +++ 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index 3a4aa48d7..16d190c57 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -3058,3 +3058,21 @@ _evry_cb_selection_notify(void *data, int type __UNUSED__, void *event) return ECORE_CALLBACK_PASS_ON; } +void +evry_item_app_free(Evry_Item_App *app) +{ + efreet_desktop_free(app->desktop); + eina_stringshare_del(app->file); + + free(app); +} + +void +evry_item_file_free(Evry_Item_File *file) +{ + eina_stringshare_del(file->url); + eina_stringshare_del(file->path); + eina_stringshare_del(file->mime); + + free(file); +} diff --git a/src/modules/everything/evry_api.h b/src/modules/everything/evry_api.h index 091e9cf29..8227696ea 100644 --- a/src/modules/everything/evry_api.h +++ b/src/modules/everything/evry_api.h @@ -50,6 +50,7 @@ typedef struct _Evry_Module Evry_Module; typedef struct _Evry_Event_Item_Changed Evry_Event_Item_Changed; typedef struct _Evry_Event_Item_Selected Evry_Event_Item_Selected; typedef struct _Evry_Event_Action_Performed Evry_Event_Action_Performed; +typedef void (*Evry_Item_Free_Cb) (Evry_Item *it); struct _Evry_Module { @@ -65,7 +66,7 @@ struct _Evry_API Evry_Item *(*item_new)(Evry_Item *base, Evry_Plugin *p, const char *label, Evas_Object *(*icon_get) (Evry_Item *it, Evas *e), - void (*cb_free) (Evry_Item *item)); + Evry_Item_Free_Cb item_free); void (*item_free)(Evry_Item *it); void (*item_ref)(Evry_Item *it); @@ -164,7 +165,7 @@ struct _Evry_Event_Action_Performed #define EVRY_ITEM_NEW(_base, _plugin, _label, _icon_get, _free) \ (_base *) evry->item_new(EVRY_ITEM(E_NEW(_base, 1)), \ EVRY_PLUGIN(_plugin), \ - _label, _icon_get, _free) + _label, _icon_get, (Evry_Item_Free_Cb)_free) #define EVRY_ITEM_FREE(_item) evry->item_free((Evry_Item *)_item) #define EVRY_ITEM_REF(_item) evry->item_ref((Evry_Item *)_item) @@ -249,8 +250,6 @@ struct _Evry_Event_Action_Performed if (!(EVRY_PLUGIN(_p)->config->min_query) || \ (_input && (strlen(_input) >= EVRY_PLUGIN(_p)->config->min_query))) -typedef void (*Evry_Item_Free_Cb) (Evry_Item *it); - #define EVRY_PLUGIN_ITEMS_CLEAR(_p) { \ Evry_Item *it; \ EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \ diff --git a/src/modules/everything/evry_plug_apps.c b/src/modules/everything/evry_plug_apps.c index 247025383..6230712fa 100644 --- a/src/modules/everything/evry_plug_apps.c +++ b/src/modules/everything/evry_plug_apps.c @@ -98,25 +98,12 @@ _exec_open_file_action(Evry_Action *act) return evry->util_exec_app(EVRY_ITEM(act), act->it1.item); } -static void -_cb_item_free(Evry_Item *item) -{ - GET_APP(app, item); - - if (app->desktop) - efreet_desktop_free(app->desktop); - if (app->file) - eina_stringshare_del(app->file); - - E_FREE(app); -} - static Evry_Item_App * _item_new(Plugin *p, const char *label, const char *id) { Evry_Item_App *app; - app = EVRY_ITEM_NEW(Evry_Item_App, p, label, NULL, _cb_item_free); + app = EVRY_ITEM_NEW(Evry_Item_App, p, label, NULL, evry_item_app_free); EVRY_ACTN(app)->action = &_exec_open_file_action; EVRY_ACTN(app)->it1.type = EVRY_TYPE_FILE; EVRY_ITEM(app)->id = eina_stringshare_add(id); @@ -330,7 +317,7 @@ _begin_exe(Evry_Plugin *plugin, const Evry_Item *item) p->added = eina_hash_string_small_new(_hash_free); - app = EVRY_ITEM_NEW(Evry_Item_App, p, NULL, NULL, _cb_item_free); + app = EVRY_ITEM_NEW(Evry_Item_App, p, NULL, NULL, evry_item_app_free); EVRY_ACTN(app)->action = &_exec_open_file_action; EVRY_ACTN(app)->remember_context = EINA_TRUE; EVRY_ITEM(app)->subtype = EVRY_TYPE_ACTION; diff --git a/src/modules/everything/evry_plug_files.c b/src/modules/everything/evry_plug_files.c index 8e08bf0ff..f87753478 100644 --- a/src/modules/everything/evry_plug_files.c +++ b/src/modules/everything/evry_plug_files.c @@ -157,18 +157,6 @@ _cb_sort_date(const void *data1, const void *data2) return it2->modified - it1->modified; } -static void -_item_free(Evry_Item *it) -{ - GET_FILE(file, it); - - IF_RELEASE(file->url); - IF_RELEASE(file->path); - IF_RELEASE(file->mime); - - E_FREE(file); -} - static void _scan_func(void *data, Ecore_Thread *thread) { @@ -185,7 +173,7 @@ _scan_func(void *data, Ecore_Thread *thread) if ((d->plugin->show_hidden) != (*(info->path + info->name_start) == '.')) continue; - file = EVRY_ITEM_NEW(Evry_Item_File, d->plugin, NULL, NULL, _item_free); + file = EVRY_ITEM_NEW(Evry_Item_File, d->plugin, NULL, NULL, evry_item_file_free); file->path = strdup(info->path); EVRY_ITEM(file)->label = strdup(info->path + info->name_start); EVRY_ITEM(file)->browseable = (info->type == EINA_FILE_DIR); @@ -464,7 +452,7 @@ _dir_watcher(void *data, Ecore_File_Monitor *em __UNUSED__, Ecore_File_Event eve case ECORE_FILE_EVENT_CREATED_FILE: label = ecore_file_file_get(path); - file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, _item_free); + file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, evry_item_file_free); file->path = eina_stringshare_add(path); if (event == ECORE_FILE_EVENT_CREATED_DIRECTORY) @@ -605,7 +593,7 @@ _folder_item_add(Plugin *p, const char *path, int prio) { Evry_Item_File *file; - file = EVRY_ITEM_NEW(Evry_Item_File, p, path, NULL, _item_free); + file = EVRY_ITEM_NEW(Evry_Item_File, p, path, NULL, evry_item_file_free); file->path = eina_stringshare_add(path); file->mime = eina_stringshare_ref(_mime_dir); EVRY_ITEM(file)->browseable = EINA_TRUE; @@ -1000,7 +988,7 @@ _recentf_items_add_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *d return EINA_TRUE; } - file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, _item_free); + file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, evry_item_file_free); file->path = path; if (hi->data) diff --git a/src/modules/everything/evry_types.h b/src/modules/everything/evry_types.h index d6437f1c1..3d81eeada 100644 --- a/src/modules/everything/evry_types.h +++ b/src/modules/everything/evry_types.h @@ -287,4 +287,7 @@ struct _History_Types Eina_Hash *types; }; +void evry_item_app_free(Evry_Item_App *it); +void evry_item_file_free(Evry_Item_File *it); + #endif