From 66f1ffbefc6b2f9b9083edeb86069a32d0dc5130 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Thu, 20 May 2010 15:41:27 +0000 Subject: [PATCH] added input_type to plugins: using it automatically creates an action that allows to browse any selected item of that type. move plugin functions in separate file text_plugin reuses current item so that it doesnt flicker while typing use e_fm function for path to uri espace remove duplicated macros in evry_api.h and e_mod_main.h fix set usage of exebuf items SVN revision: 49066 --- src/modules/everything-apps/e_mod_main.c | 13 +- src/modules/everything-files/e_mod_main.c | 31 ++-- src/modules/everything-windows/e_mod_main.c | 4 +- src/modules/everything/Makefile.am | 1 + src/modules/everything/e_mod_main.c | 170 ++-------------------- src/modules/everything/e_mod_main.h | 64 +-------- src/modules/everything/evry.c | 99 +++++++++---- src/modules/everything/evry_api.h | 102 +++++++------ src/modules/everything/evry_plug_actions.c | 16 ++- src/modules/everything/evry_plug_text.c | 30 ++-- src/modules/everything/evry_plugin.c | 212 ++++++++++++++++++++++++++++ src/modules/everything/evry_types.h | 11 +- src/modules/everything/evry_util.c | 75 +++++----- 13 files changed, 436 insertions(+), 392 deletions(-) create mode 100644 src/modules/everything/evry_plugin.c diff --git a/src/modules/everything-apps/e_mod_main.c b/src/modules/everything-apps/e_mod_main.c index bb2a16c..8411f61 100644 --- a/src/modules/everything-apps/e_mod_main.c +++ b/src/modules/everything-apps/e_mod_main.c @@ -222,14 +222,14 @@ _hist_exe_get_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata Eina_List *l; Evry_Item_App *app; int match; - - char *exe = strdup(key); + const char *exe = key; EINA_LIST_FOREACH(he->items, l, hi) { app = NULL; - if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name)) + if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name)) + continue; if (!p->input) @@ -241,12 +241,15 @@ _hist_exe_get_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata app = _item_exe_add(p, exe, match); } - if (app) EVRY_ITEM(app)->hi = hi; + if (app) + { + EVRY_ITEM(app)->hi = hi; + evry->history_item_usage_set(EVRY_ITEM(app), p->input, NULL); + } break; } - free(exe); return EINA_TRUE; } diff --git a/src/modules/everything-files/e_mod_main.c b/src/modules/everything-files/e_mod_main.c index 5639bf1..7c9a446 100644 --- a/src/modules/everything-files/e_mod_main.c +++ b/src/modules/everything-files/e_mod_main.c @@ -591,19 +591,14 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) { Plugin *p = NULL; - if (it && !CHECK_TYPE(it, EVRY_TYPE_ACTION)) - return NULL; - if (it) { - /* provide object */ - const char *dir = NULL; - - GET_ACTION(act, it); - if (!strcmp(act->name, "Browse Folder...")) + /* provide object */ + if ((CHECK_TYPE(it, EVRY_TYPE_FILE)) || + (CHECK_SUBTYPE(it, EVRY_TYPE_FILE))) { - GET_FILE(file, act->it1.item); + GET_FILE(file, it); if (!evry->file_path_get(file)) return NULL; @@ -611,10 +606,10 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) dir = eina_stringshare_add(tmp); E_FREE(tmp); } - else - { - dir = eina_stringshare_add(e_user_homedir_get()); - } + else return NULL; + + if (!dir) + dir = eina_stringshare_add(e_user_homedir_get()); p = E_NEW(Plugin, 1); p->base = *plugin; @@ -1208,12 +1203,6 @@ _open_folder_action(Evry_Action *act) } static int -_browse_folder_action(Evry_Action *act) -{ - return 0; -} - -static int _file_trash_action(Evry_Action *act) { Efreet_Uri *euri; @@ -1303,6 +1292,7 @@ _plugins_init(const Evry_API *api) PLUGIN_NEW(N_("Files"), _module_icon, _begin, _finish, _fetch); p->browse = &_browse; + p->input_type = EVRY_TYPE_FILE; if (evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 2)) p->config->min_query = 1; @@ -1357,9 +1347,6 @@ _plugins_init(const Evry_API *api) * _file_trash_action, NULL); * EVRY_ITEM_DATA_INT_SET(act, ACT_DELETE); */ - ACTION_NEW(N_("Browse Folder..."), EVRY_TYPE_FILE, "folder-open", - _browse_folder_action, NULL); - ACTION_NEW(N_("Open Folder (EFM)"), 0, "folder-open", _open_folder_action, _open_folder_check); act->remember_context = EINA_TRUE; diff --git a/src/modules/everything-windows/e_mod_main.c b/src/modules/everything-windows/e_mod_main.c index ad619c1..5c918a3 100644 --- a/src/modules/everything-windows/e_mod_main.c +++ b/src/modules/everything-windows/e_mod_main.c @@ -379,7 +379,7 @@ _plugins_init(const Evry_API *_api) _actions = eina_list_append(_actions, act); act = EVRY_ACTION_NEW(_("Iconify"), - EVRY_TYPE_BORDER, 0, "iconic", + EVRY_TYPE_BORDER, 0, "go-down", _act_border, _check_border); EVRY_ITEM_DATA_INT_SET(act, BORDER_HIDE); _actions = eina_list_append(_actions, act); @@ -393,7 +393,7 @@ _plugins_init(const Evry_API *_api) evry->action_register(act, 4); act = EVRY_ACTION_NEW(_("Close"), - EVRY_TYPE_BORDER, 0, "view-fullscreen", + EVRY_TYPE_BORDER, 0, "list-remove", _act_border, _check_border); EVRY_ITEM_DATA_INT_SET(act, BORDER_CLOSE); _actions = eina_list_append(_actions, act); diff --git a/src/modules/everything/Makefile.am b/src/modules/everything/Makefile.am index 941d49d..3d90589 100644 --- a/src/modules/everything/Makefile.am +++ b/src/modules/everything/Makefile.am @@ -30,6 +30,7 @@ module_la_SOURCES = $(EVRYHEADERS) \ evry_config.c \ evry_util.c \ evry_history.c \ + evry_plugin.c \ evry_plug_aggregator.c \ evry_plug_actions.c \ evry_view_plugin_tabs.c \ diff --git a/src/modules/everything/e_mod_main.c b/src/modules/everything/e_mod_main.c index 0616490..51faeb7 100644 --- a/src/modules/everything/e_mod_main.c +++ b/src/modules/everything/e_mod_main.c @@ -104,7 +104,7 @@ e_modapi_init(E_Module *m) { Eina_List *l; Evry_Module *em; - + _e_module_evry_log_dom = eina_log_domain_register ("e_module_everything", EINA_LOG_DEFAULT_COLOR); @@ -206,12 +206,12 @@ e_modapi_init(E_Module *m) SET(history_types_get); SET(history_item_usage_set); #undef SET - + e_datastore_set("everything_loaded", _api); EINA_LIST_FOREACH(e_datastore_get("everything_modules"), l, em) em->active = em->init(_api); - + /* cleanup every hour :) */ cleanup_timer = ecore_timer_add(3600, _cleanup_history, NULL); @@ -225,13 +225,13 @@ e_modapi_shutdown(E_Module *m __UNUSED__) const char *t; Eina_List *l; Evry_Module *em; - + EINA_LIST_FOREACH(e_datastore_get("everything_modules"), l, em) em->shutdown(); - + e_datastore_del("everything_loaded"); E_FREE(_api); - + evry_shutdown(); view_thumb_shutdown(); @@ -352,7 +352,7 @@ _config_init() evry_conf = E_NEW(Evry_Config, 1); evry_conf->version = (MOD_CONFIG_FILE_EPOCH << 16); } - + #define IFMODCFG(v) if ((evry_conf->version & 0xffff) < v) { #define IFMODCFGEND } @@ -373,13 +373,13 @@ _config_init() evry_conf->history_sort_mode = 0; evry_conf->first_run = EINA_TRUE; IFMODCFGEND; - + IFMODCFG(0x0002); evry_conf->width = 435; evry_conf->height = 415; evry_conf->rel_y = 0.40; IFMODCFGEND; - + evry_conf->version = MOD_CONFIG_FILE_VERSION; } @@ -387,7 +387,7 @@ static void _plugin_config_free(void) { Plugin_Config *pc; - + EINA_LIST_FREE(evry_conf->conf_subjects, pc) { if (pc->name) eina_stringshare_del(pc->name); @@ -492,156 +492,6 @@ EAPI int evry_api_version_check(int version) return 0; } -static int -_evry_cb_plugin_sort(const void *data1, const void *data2) -{ - const Plugin_Config *pc1 = data1; - const Plugin_Config *pc2 = data2; - - return pc1->priority - pc2->priority; -} - -void -_evry_plugin_free(Evry_Item *it) -{ - GET_EVRY_PLUGIN(p, it); - - evry_plugin_unregister(p); - - DBG("%s", p->name); - if (p->config) p->config->plugin = NULL; - if (p->name) eina_stringshare_del(p->name); - - if (p->free) - p->free(p); - else - E_FREE(p); -} - -EAPI Evry_Plugin * -evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, - const char *icon, Evry_Type item_type, - Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item), - void (*finish) (Evry_Plugin *p), - int (*fetch) (Evry_Plugin *p, const char *input), - void (*cb_free) (Evry_Plugin *p)) -{ - Evry_Plugin *p; - Evry_Item *it; - - if (base) - p = base; - else - p = E_NEW(Evry_Plugin, 1); - - it = evry_item_new(EVRY_ITEM(p), NULL, label, NULL, _evry_plugin_free); - it->plugin = p; - it->browseable = EINA_TRUE; - it->type = EVRY_TYPE_PLUGIN; - if (item_type) - it->subtype = item_type; - if (icon) - it->icon = eina_stringshare_add(icon); - - p->name = eina_stringshare_add(name); - p->begin = begin; - p->finish = finish; - p->fetch = fetch; - - p->async_fetch = EINA_FALSE; - p->history = EINA_TRUE; - - p->free = cb_free; - - return p; -} - -EAPI void -evry_plugin_free(Evry_Plugin *p) -{ - evry_item_free(EVRY_ITEM(p)); -} - -/* TODO make int return */ -EAPI int -evry_plugin_register(Evry_Plugin *p, int type, int priority) -{ - Eina_List *l; - Plugin_Config *pc; - Eina_List *conf[3]; - int i = 0; - int new_conf = 0; - - if (type < 0 || type > 2) - return 0; - - conf[0] = evry_conf->conf_subjects; - conf[1] = evry_conf->conf_actions; - conf[2] = evry_conf->conf_objects; - - EINA_LIST_FOREACH(conf[type], l, pc) - if (pc->name && p->name && !strcmp(pc->name, p->name)) - break; - - if (!pc) - { - new_conf = 1; - pc = E_NEW(Plugin_Config, 1); - pc->name = eina_stringshare_add(p->name); - pc->enabled = 1; - pc->priority = priority ? priority : 100; - pc->view_mode = VIEW_MODE_NONE; - pc->aggregate = EINA_TRUE; - pc->top_level = EINA_TRUE; - - conf[type] = eina_list_append(conf[type], pc); - } - if (pc->trigger && strlen(pc->trigger) == 0) - { - eina_stringshare_del(pc->trigger); - pc->trigger = NULL; - } - - p->config = pc; - pc->plugin = p; - - conf[type] = eina_list_sort(conf[type], -1, _evry_cb_plugin_sort); - - EINA_LIST_FOREACH(conf[type], l, pc) - pc->priority = i++; - - evry_conf->conf_subjects = conf[0]; - evry_conf->conf_actions = conf[1]; - evry_conf->conf_objects = conf[2]; - - if (type == EVRY_PLUGIN_SUBJECT) - { - char buf[256]; - snprintf(buf, sizeof(buf), _("Show %s Plugin"), p->name); - - e_action_predef_name_set(_("Everything Launcher"), buf, - "everything", p->name, NULL, 1); - } - - return new_conf; -} - -EAPI void -evry_plugin_unregister(Evry_Plugin *p) -{ - DBG("%s", p->name); - Eina_List *l = evry_conf->conf_subjects; - - if (l && eina_list_data_find_list(l, p->config)) - { - char buf[256]; - snprintf(buf, sizeof(buf), _("Show %s Plugin"), p->name); - - e_action_predef_name_del(_("Everything"), buf); - } -} - - static int _evry_cb_view_sort(const void *data1, const void *data2) diff --git a/src/modules/everything/e_mod_main.h b/src/modules/everything/e_mod_main.h index 6752fbf..2a426b6 100644 --- a/src/modules/everything/e_mod_main.h +++ b/src/modules/everything/e_mod_main.h @@ -298,48 +298,12 @@ int evry_browse_back(Evry_Selector *sel); void evry_plugin_action(int finished); +int evry_state_push(Evry_Selector *sel, Eina_List *plugins); +void evry_selectors_switch(int dir); + extern Evry_History *evry_hist; extern Evry_Config *evry_conf; -#define EVRY_ITEM(_item) ((Evry_Item *)_item) -#define EVRY_ACTN(_item) ((Evry_Action *) _item) -#define EVRY_PLUGIN(_plugin) ((Evry_Plugin *) _plugin) -#define EVRY_VIEW(_view) ((Evry_View *) _view) -#define EVRY_FILE(_it) ((Evry_Item_File *) _it) - -#define CHECK_TYPE(_item, _type) \ - (((Evry_Item *)_item)->type && ((Evry_Item *)_item)->type == _type) - -#define CHECK_SUBTYPE(_item, _type) \ - (((Evry_Item *)_item)->subtype && ((Evry_Item *)_item)->subtype == _type) - -#define IS_BROWSEABLE(_item) \ - ((Evry_Item *)_item)->browseable - -#define GET_APP(_app, _item) Evry_Item_App *_app = (Evry_Item_App *) _item -#define GET_FILE(_file, _item) Evry_Item_File *_file = (Evry_Item_File *) _item -#define GET_EVRY_PLUGIN(_p, _plugin) Evry_Plugin *_p = (Evry_Plugin*) _plugin -#define GET_VIEW(_v, _view) View *_v = (View*) _view -#define GET_ACTION(_act, _item) Evry_Action *_act = (Evry_Action *) _item -#define GET_PLUGIN(_p, _plugin) Plugin *_p = (Plugin*) _plugin -#define GET_ITEM(_it, _any) Evry_Item *_it = (Evry_Item *) _any - -#define EVRY_ITEM_DATA_INT_SET(_item, _data) ((Evry_Item *)_item)->data = (void*)(long) _data -#define EVRY_ITEM_DATA_INT_GET(_item) (long) ((Evry_Item *)_item)->data -#define EVRY_ITEM_ICON_SET(_item, _icon) ((Evry_Item *)_item)->icon = _icon - -#define EVRY_ITEM_DETAIL_SET(_it, _detail) \ - if (EVRY_ITEM(_it)->detail) eina_stringshare_del(EVRY_ITEM(_it)->detail); \ - EVRY_ITEM(_it)->detail = eina_stringshare_add(_detail); - -#define EVRY_ITEM_LABEL_SET(_it, _label) \ - if (EVRY_ITEM(_it)->label) eina_stringshare_del(EVRY_ITEM(_it)->label); \ - EVRY_ITEM(_it)->label = eina_stringshare_add(_label); - -#define EVRY_ITEM_CONTEXT_SET(_it, _context) \ - if (EVRY_ITEM(_it)->context) eina_stringshare_del(EVRY_ITEM(_it)->context); \ - EVRY_ITEM(_it)->context = eina_stringshare_add(_context); - #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) @@ -351,45 +315,23 @@ extern Evry_Config *evry_conf; evry_plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \ _begin, _cleanup, _fetch, _free) - #define EVRY_ACTION_NEW(_name, _in1, _in2, _icon, _action, _check) \ evry_action_new(_name, _(_name), _in1, _in2, _icon, _action, _check) - #define EVRY_PLUGIN_FREE(_p) \ if (_p) evry_plugin_free(EVRY_PLUGIN(_p)) #define EVRY_PLUGIN_UPDATE(_p, _action) \ if (_p) evry_plugin_update(EVRY_PLUGIN(_p), _action) - -#define EVRY_PLUGIN_ITEMS_CLEAR(_p) { \ - Evry_Item *it; \ - EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \ - it->fuzzy_match = 0; } - #define EVRY_PLUGIN_ITEMS_FREE(_p) { \ Evry_Item *it; \ EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \ evry_item_free(it); } - -#define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \ - EVRY_PLUGIN(_p)->items = eina_list_sort \ - (EVRY_PLUGIN(_p)->items, eina_list_count(EVRY_PLUGIN(_p)->items), _sortcb) - -#define EVRY_PLUGIN_ITEM_APPEND(_p, _item) \ - EVRY_PLUGIN(_p)->items = eina_list_append(EVRY_PLUGIN(_p)->items, EVRY_ITEM(_item)) - #define EVRY_PLUGIN_ITEMS_ADD(_plugin, _items, _input, _match_detail, _set_usage) \ evry_util_plugin_items_add(EVRY_PLUGIN(_plugin), _items, _input, _match_detail, _set_usage) -#define IF_RELEASE(x) do { \ - if (x) { \ - const char *__tmp; __tmp = (x); (x) = NULL; eina_stringshare_del(__tmp); \ - } \ - (x) = NULL; \ - } while (0) /*** Common Logging ***/ extern int _e_module_evry_log_dom; diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index 708fd47..595f571 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -26,11 +26,9 @@ static int _evry_cb_update_timer(void *data); static Evry_State *_evry_state_new(Evry_Selector *sel, Eina_List *plugins); static void _evry_state_pop(Evry_Selector *sel); -static int _evry_selectors_shift(int dir); static Evry_Selector *_evry_selector_new(Evry_Window *win, int type); static void _evry_selector_free(Evry_Selector *sel); static void _evry_selector_activate(Evry_Selector *sel); -static void _evry_selectors_switch(int dir); static void _evry_selector_update(Evry_Selector *sel); static int _evry_selector_subjects_get(const char *plugin_name); static int _evry_selector_actions_get(Evry_Item *it); @@ -40,6 +38,7 @@ static void _evry_selector_item_update(Evry_Selector *sel); static void _evry_selector_item_clear(Evry_Selector *sel); static void _evry_selector_label_set(Evry_Selector *sel, const char *part, const char *label); static void _evry_selector_signal_emit(Evry_Selector *sel, const char *msg); +static int _evry_selectors_shift(int dir);; static Evry_Window *_evry_window_new(E_Zone *zone); static void _evry_window_free(Evry_Window *win); @@ -290,9 +289,9 @@ evry_hide(int clear) if (win->selector != win->selectors[0]) { if (win->selector == win->selectors[1]) - _evry_selectors_switch(-1); + evry_selectors_switch(-1); else if (win->selector == win->selectors[2]) - _evry_selectors_switch(1); + evry_selectors_switch(1); } /* just to be sure */ @@ -663,7 +662,7 @@ evry_plugin_update(Evry_Plugin *p, int action) (!(s->plugin) || !(s->plugin->items)) && (win->selector == win->selectors[1])) { - _evry_selectors_switch(-1); + evry_selectors_switch(-1); _evry_clear(win->selectors[0]); } } @@ -921,11 +920,11 @@ _evry_selector_cb_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info) { /* FIXME dont loose selector 2 state until state 0 changed: */ if (win->selector != win->selectors[2]) - _evry_selectors_switch(1); + evry_selectors_switch(1); } else if (ev->z < 0) { - _evry_selectors_switch(-1); + evry_selectors_switch(-1); } } @@ -947,22 +946,22 @@ _evry_selector_cb_up(void *data, Evas *e, Evas_Object *obj, void *event_info) if (sel == win->selectors[0]) { if (win->selector == win->selectors[1]) - _evry_selectors_switch(-1); + evry_selectors_switch(-1); else - _evry_selectors_switch(1); + evry_selectors_switch(1); } else if (sel == win->selectors[1]) { if (win->selector == win->selectors[0]) - _evry_selectors_switch(1); + evry_selectors_switch(1); else - _evry_selectors_switch(-1); + evry_selectors_switch(-1); } else if (sel == win->selectors[2]) { if (win->selector == win->selectors[1]) - _evry_selectors_switch(1); + evry_selectors_switch(1); } } } @@ -1494,6 +1493,52 @@ _evry_state_pop(Evry_Selector *sel) } int +evry_state_push(Evry_Selector *sel, Eina_List *plugins) +{ + Evry_State *s, *new_state; + Eina_List *l; + Evry_Plugin *p, *pp; + Evry_View *view = NULL; + int browse_aggregator = 0; + + s = sel->state; + + if (!(new_state = _evry_state_new(sel, plugins))) + { + DBG("no new state"); + return 0; + } + + EINA_LIST_FOREACH(plugins, l, p) + p->state = new_state; + + if (s && s->view) + { + _evry_view_hide(s->view, 1); + view = s->view; + } + + _evry_matches_update(sel, 1); + s = new_state; + + _evry_selector_update(sel); + + if (view && win->visible) + { + s->view = view->create(view, s, win->o_main); + if (s->view) + { + _evry_view_show(s->view); + s->view->update(s->view, -1); + } + } + + _evry_update_text_label(sel->state); + + return 1; +} + +int evry_browse_item(Evry_Item *it) { Evry_State *s, *new_state; @@ -1613,6 +1658,8 @@ evry_browse_back(Evry_Selector *sel) s = sel->state; _evry_aggregator_fetch(sel, s->input); _evry_selector_update(sel); + if (sel == win->selectors[0]) + _evry_selector_update_actions(sel); _evry_update_text_label(s); _evry_view_show(s->view); s->view->update(s->view, 1); @@ -1620,8 +1667,8 @@ evry_browse_back(Evry_Selector *sel) return 1; } -static void -_evry_selectors_switch(int dir) +void +evry_selectors_switch(int dir) { Evry_State *s = win->selector->state; @@ -1870,7 +1917,7 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event) !((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) || (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT))) { - _evry_selectors_switch(1); + evry_selectors_switch(1); goto end; } @@ -1934,12 +1981,12 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event) { if (!evry_browse_item(sel->state->cur_item) && (sel != win->selectors[2])) - _evry_selectors_switch(1); + evry_selectors_switch(1); } else if (!strcmp(ev->key, "Left")) { if (!evry_browse_back(sel)) - _evry_selectors_switch(-1); + evry_selectors_switch(-1); } else if (!strcmp(ev->key, "Return")) { @@ -2180,7 +2227,7 @@ _evry_plugin_action(Evry_Selector *sel, int finished) if (!it_obj) { if (win->selectors[1] == win->selector) - _evry_selectors_switch(1); + evry_selectors_switch(1); return; } @@ -2395,8 +2442,8 @@ _evry_matches_update(Evry_Selector *sel, int async) if ((!input || !s->trigger_active) && (!win->plugin_dedicated)) { - EINA_LIST_FREE(s->cur_plugins, p); - s->trigger_active = EINA_FALSE; + EINA_LIST_FREE(s->cur_plugins, p); + s->trigger_active = EINA_FALSE; } if (s->trigger_active) @@ -2456,11 +2503,13 @@ _evry_matches_update(Evry_Selector *sel, int async) { EINA_LIST_FOREACH(s->plugins, l, p) { - if ((p->config->top_level) && (sel == win->selectors[0])) - { - if ((p->config->trigger) && (p->config->trigger_only)) - continue; - } + /* skip plugins in toplevel which trigger-only */ + if ((!(sel->states->next)) && + (sel == win->selectors[0]) && + (p->config->top_level) && + (p->config->trigger) && + (p->config->trigger_only)) + continue; /* dont wait for async plugin. use their current items */ if (!async && p->async_fetch && p->items) diff --git a/src/modules/everything/evry_api.h b/src/modules/everything/evry_api.h index c7dc05e..9076218 100644 --- a/src/modules/everything/evry_api.h +++ b/src/modules/everything/evry_api.h @@ -3,7 +3,7 @@ #include "evry_types.h" -#define EVRY_API_VERSION 21 +#define EVRY_API_VERSION 23 #define EVRY_ACTION_OTHER 0 #define EVRY_ACTION_FINISHED 1 @@ -64,7 +64,7 @@ in e_modapi_init do: in e_modapi_shutdown: _plugins_shutdown(); - + EVRY_MODULE_UNREGISTER(evry_module); E_FREE(evry_module); @@ -81,7 +81,7 @@ struct _Evry_Module struct _Evry_API { int (*api_version_check)(int version); - + 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)); @@ -90,7 +90,7 @@ struct _Evry_API void (*item_ref)(Evry_Item *it); /* send EVRY_EVENT_ITEM_CHANGED event */ void (*item_changed)(Evry_Item *it, int change_icon, int change_selected); - + Evry_Plugin *(*plugin_new)(Evry_Plugin *base, const char *name, const char *label, const char *icon, Evry_Type item_type, @@ -105,7 +105,7 @@ struct _Evry_API int (*plugin_register)(Evry_Plugin *p, int type, int priority); void (*plugin_unregister)(Evry_Plugin *p); void (*plugin_update)(Evry_Plugin *plugin, int state); - + Evry_Action *(*action_new)(const char *name, const char *label, Evry_Type type1, Evry_Type type2, const char *icon, @@ -155,7 +155,6 @@ struct _Evry_Event_Action_Performed const Evry_Item *it2; }; -#ifndef EVRY_H /*** cast default types ***/ @@ -174,16 +173,6 @@ struct _Evry_Event_Action_Performed #define GET_PLUGIN(_p, _plugin) Plugin *_p = (Plugin*) _plugin #define GET_ITEM(_it, _any) Evry_Item *_it = (Evry_Item *) _any - -/*** Evry_Item macros ***/ - -#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) - -#define EVRY_ITEM_FREE(_item) evry->item_free((Evry_Item *)_item) -#define EVRY_ITEM_REF(_item) evry->item_ref((Evry_Item *)_item) - #define EVRY_ITEM_DATA_INT_SET(_item, _data) ((Evry_Item *)_item)->data = (void*)(long) _data #define EVRY_ITEM_DATA_INT_GET(_item) (long) ((Evry_Item *)_item)->data @@ -199,7 +188,7 @@ struct _Evry_Event_Action_Performed if (EVRY_ITEM(_it)->context) eina_stringshare_del(EVRY_ITEM(_it)->context); \ EVRY_ITEM(_it)->context = eina_stringshare_add(_context); -#define EVRY_ITEM_ICON_SET(_it, _icon) \ +#define EVRY_ITEM_ICON_SET(_it, _icon) \ if (EVRY_ITEM(_it)->icon) eina_stringshare_del(EVRY_ITEM(_it)->icon); \ EVRY_ITEM(_it)->icon = eina_stringshare_add(_icon); @@ -211,14 +200,12 @@ struct _Evry_Event_Action_Performed #define IS_BROWSEABLE(_item) ((Evry_Item *)_item)->browseable +#define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \ + EVRY_PLUGIN(_p)->items = eina_list_sort \ + (EVRY_PLUGIN(_p)->items, eina_list_count(EVRY_PLUGIN(_p)->items), _sortcb) -/*** Evry_Plugin macros ***/ - -#define EVRY_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _finish, _fetch, _free) \ - evry->plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \ - _begin, _finish, _fetch, _free) - -#define EVRY_PLUGIN_FREE(_p) if (_p) evry->plugin_free(EVRY_PLUGIN(_p)) +#define EVRY_PLUGIN_ITEM_APPEND(_p, _item) \ + EVRY_PLUGIN(_p)->items = eina_list_append(EVRY_PLUGIN(_p)->items, EVRY_ITEM(_item)) #define EVRY_PLUGIN_INSTANCE(_p, _plugin) { \ _p = E_NEW(Plugin, 1); \ @@ -231,18 +218,50 @@ struct _Evry_Event_Action_Performed EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \ if (it) it->fuzzy_match = 0; } +#define EVRY_MODULE_REGISTER(_module) { \ + Eina_List *l = e_datastore_get("everything_modules"); \ + l = eina_list_append(l, _module); \ + e_datastore_set("everything_modules", l); } + +#define EVRY_MODULE_UNREGISTER(_module) { \ + Eina_List *l = e_datastore_get("everything_modules"); \ + l = eina_list_remove(l, _module); \ + e_datastore_set("everything_modules", l); } + +/*** handy macros ***/ + +#define IF_RELEASE(x) do { \ + if (x) { \ + const char *__tmp; __tmp = (x); (x) = NULL; eina_stringshare_del(__tmp); \ + } \ + (x) = NULL; \ + } while (0) + + + +#ifndef EVRY_H +/*** Evry_Item macros ***/ + +#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) + +#define EVRY_ITEM_FREE(_item) evry->item_free((Evry_Item *)_item) +#define EVRY_ITEM_REF(_item) evry->item_ref((Evry_Item *)_item) + +/*** Evry_Plugin macros ***/ + +#define EVRY_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _finish, _fetch, _free) \ + evry->plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \ + _begin, _finish, _fetch, _free) + +#define EVRY_PLUGIN_FREE(_p) if (_p) evry->plugin_free(EVRY_PLUGIN(_p)) + #define EVRY_PLUGIN_ITEMS_FREE(_p) { \ Evry_Item *it; \ EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \ evry->item_free(it); } -#define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \ - EVRY_PLUGIN(_p)->items = eina_list_sort \ - (EVRY_PLUGIN(_p)->items, eina_list_count(EVRY_PLUGIN(_p)->items), _sortcb) - -#define EVRY_PLUGIN_ITEM_APPEND(_p, _item) \ - EVRY_PLUGIN(_p)->items = eina_list_append(EVRY_PLUGIN(_p)->items, EVRY_ITEM(_item)) - // should be renamed to ITEMS_FILTER #define EVRY_PLUGIN_ITEMS_ADD(_plugin, _items, _input, _match_detail, _set_usage) \ evry->util_plugin_items_add(EVRY_PLUGIN(_plugin), _items, _input, _match_detail, _set_usage) @@ -250,7 +269,6 @@ struct _Evry_Event_Action_Performed #define EVRY_PLUGIN_UPDATE(_p, _action) \ if (_p) evry->plugin_update(EVRY_PLUGIN(_p), _action) - /*** Evry_Action macros ***/ #define EVRY_ACTION_NEW(_name, _in1, _in2, _icon, _action, _check) \ @@ -259,25 +277,6 @@ struct _Evry_Event_Action_Performed #define EVRY_ACTION_FREE(_act) if (_act) evry->action_free(EVRY_ACTN(_act)) -/*** handy macros ***/ - -#define IF_RELEASE(x) do { \ - if (x) { \ - const char *__tmp; __tmp = (x); (x) = NULL; eina_stringshare_del(__tmp); \ - } \ - (x) = NULL; \ - } while (0) - -#define EVRY_MODULE_REGISTER(_module) { \ - Eina_List *l = e_datastore_get("everything_modules"); \ - l = eina_list_append(l, _module); \ - e_datastore_set("everything_modules", l); } - -#define EVRY_MODULE_UNREGISTER(_module) { \ - Eina_List *l = e_datastore_get("everything_modules"); \ - l = eina_list_remove(l, _module); \ - e_datastore_set("everything_modules", l); } - #ifndef EINA_LOG_DEFAULT_COLOR #define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN @@ -295,4 +294,3 @@ struct _Evry_Event_Action_Performed #endif #endif - diff --git a/src/modules/everything/evry_plug_actions.c b/src/modules/everything/evry_plug_actions.c index 664e673..d91bd7c 100644 --- a/src/modules/everything/evry_plug_actions.c +++ b/src/modules/everything/evry_plug_actions.c @@ -193,7 +193,8 @@ evry_plug_actions_new(Evry_Selector *sel, int type) /***************************************************************************/ -int evry_plug_actions_init() +int +evry_plug_actions_init() { _base_plug = evry_plugin_new(NULL, _("Actions"), NULL, NULL, EVRY_TYPE_ACTION, NULL, NULL, NULL, NULL); @@ -201,7 +202,8 @@ int evry_plug_actions_init() return 1; } -void evry_plug_actions_shutdown() +void +evry_plug_actions_shutdown() { Evry_Item *it; @@ -213,7 +215,7 @@ void evry_plug_actions_shutdown() } -EAPI void +void evry_action_register(Evry_Action *act, int priority) { EVRY_ITEM(act)->priority = priority; @@ -222,7 +224,7 @@ evry_action_register(Evry_Action *act, int priority) /* TODO sorting, initialization, etc */ } -EAPI void +void evry_action_unregister(Evry_Action *act) { evry_conf->actions = eina_list_remove(evry_conf->actions, act); @@ -239,7 +241,7 @@ _action_free_cb(Evry_Item *it) E_FREE(act); } -EAPI Evry_Action * +Evry_Action * evry_action_new(const char *name, const char *label, Evry_Type type_in1, Evry_Type type_in2, const char *icon, @@ -262,7 +264,7 @@ evry_action_new(const char *name, const char *label, return act; } -EAPI void +void evry_action_free(Evry_Action *act) { evry_action_unregister(act); @@ -273,7 +275,7 @@ evry_action_free(Evry_Action *act) /* TODO assign actions to plugins othersie there will be too liitle names soon */ -EAPI Evry_Action * +Evry_Action * evry_action_find(const char *name) { Evry_Action *act = NULL; diff --git a/src/modules/everything/evry_plug_text.c b/src/modules/everything/evry_plug_text.c index 9bb5032..8e386f1 100644 --- a/src/modules/everything/evry_plug_text.c +++ b/src/modules/everything/evry_plug_text.c @@ -3,7 +3,6 @@ static Evry_Plugin *p1; static Evry_Plugin *p2; - static void _finish(Evry_Plugin *p) { @@ -15,17 +14,22 @@ _fetch(Evry_Plugin *p, const char *input) { Evry_Item *it; - EVRY_PLUGIN_ITEMS_FREE(p); - if (input) { - it = evry_item_new(NULL, p, input, NULL, NULL); - it->fuzzy_match = 999; - EVRY_PLUGIN_ITEM_APPEND(p, it); - + if (!p->items) + { + it = evry_item_new(NULL, p, input, NULL, NULL); + it->fuzzy_match = 999; + EVRY_PLUGIN_ITEM_APPEND(p, it); + } + else + { + it = p->items->data; + EVRY_ITEM_LABEL_SET(it, input); + evry_item_changed(it, 0, 0); + } return 1; } - return 0; } @@ -43,15 +47,19 @@ evry_plug_text_init(void) if (evry_plugin_register(p1, EVRY_PLUGIN_OBJECT,999)) { p1->config->trigger_only = 1; - p1->config->trigger = eina_stringshare_add(" "); + p1->config->trigger = eina_stringshare_add(" "); + p1->config->aggregate = EINA_FALSE; + p1->config->view_mode = VIEW_MODE_LIST; } - + if (evry_plugin_register(p2, EVRY_PLUGIN_SUBJECT, 999)) { p2->config->trigger_only = 1; p2->config->trigger = eina_stringshare_add(" "); + p2->config->aggregate = EINA_FALSE; + p2->config->view_mode = VIEW_MODE_LIST; } - + return EINA_TRUE; } diff --git a/src/modules/everything/evry_plugin.c b/src/modules/everything/evry_plugin.c new file mode 100644 index 0000000..1f11f9b --- /dev/null +++ b/src/modules/everything/evry_plugin.c @@ -0,0 +1,212 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ + +#include "e_mod_main.h" + +static Eina_List *actions = NULL; + +int +evry_plugins_init(void) +{ +} + +void +evry_plugins_shutdown(void) +{ + Evry_Action *act; + + EINA_LIST_FREE(actions, act) + evry_action_free(act); +} + + +static int +_evry_cb_plugin_sort(const void *data1, const void *data2) +{ + const Plugin_Config *pc1 = data1; + const Plugin_Config *pc2 = data2; + + return pc1->priority - pc2->priority; +} + +void +_evry_plugin_free(Evry_Item *it) +{ + GET_EVRY_PLUGIN(p, it); + + evry_plugin_unregister(p); + + DBG("%s", p->name); + if (p->config) p->config->plugin = NULL; + if (p->name) eina_stringshare_del(p->name); + + if (p->free) + p->free(p); + else + E_FREE(p); +} + +EAPI Evry_Plugin * +evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, + const char *icon, Evry_Type item_type, + Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item), + void (*finish) (Evry_Plugin *p), + int (*fetch) (Evry_Plugin *p, const char *input), + void (*cb_free) (Evry_Plugin *p)) +{ + Evry_Plugin *p; + Evry_Item *it; + + if (base) + p = base; + else + p = E_NEW(Evry_Plugin, 1); + + it = evry_item_new(EVRY_ITEM(p), NULL, label, NULL, _evry_plugin_free); + it->plugin = p; + it->browseable = EINA_TRUE; + it->type = EVRY_TYPE_PLUGIN; + if (item_type) + it->subtype = item_type; + if (icon) + it->icon = eina_stringshare_add(icon); + + p->name = eina_stringshare_add(name); + p->begin = begin; + p->finish = finish; + p->fetch = fetch; + + p->async_fetch = EINA_FALSE; + p->history = EINA_TRUE; + + p->free = cb_free; + + return p; +} + +EAPI void +evry_plugin_free(Evry_Plugin *p) +{ + evry_item_free(EVRY_ITEM(p)); +} + +static int +_evry_plugin_action_browse(Evry_Action *act) +{ + Evry_Plugin *p; + Eina_List *plugins = NULL; + Evry_Selector *sel; + + GET_ITEM(it, act->it1.item); + GET_EVRY_PLUGIN(pp, EVRY_ITEM(act)->data); + + if (!it->plugin || !it->plugin->state) + return 0; + + sel = it->plugin->state->selector; + + evry_selectors_switch(-1); + + if ((p = pp->begin(pp, it))) + { + plugins = eina_list_append(plugins, p); + + if (!evry_state_push(sel, plugins)) + eina_list_free(plugins); + } + + return 0; +} + +/* TODO make int return */ +EAPI int +evry_plugin_register(Evry_Plugin *p, int type, int priority) +{ + Eina_List *l; + Plugin_Config *pc; + Eina_List *conf[3]; + int i = 0; + int new_conf = 0; + + if (type < 0 || type > 2) + return 0; + + conf[0] = evry_conf->conf_subjects; + conf[1] = evry_conf->conf_actions; + conf[2] = evry_conf->conf_objects; + + EINA_LIST_FOREACH(conf[type], l, pc) + if (pc->name && p->name && !strcmp(pc->name, p->name)) + break; + + if (!pc) + { + new_conf = 1; + pc = E_NEW(Plugin_Config, 1); + pc->name = eina_stringshare_add(p->name); + pc->enabled = 1; + pc->priority = priority ? priority : 100; + pc->view_mode = VIEW_MODE_NONE; + pc->aggregate = EINA_TRUE; + pc->top_level = EINA_TRUE; + + conf[type] = eina_list_append(conf[type], pc); + } + if (pc->trigger && strlen(pc->trigger) == 0) + { + eina_stringshare_del(pc->trigger); + pc->trigger = NULL; + } + + p->config = pc; + pc->plugin = p; + + conf[type] = eina_list_sort(conf[type], -1, _evry_cb_plugin_sort); + + EINA_LIST_FOREACH(conf[type], l, pc) + pc->priority = i++; + + evry_conf->conf_subjects = conf[0]; + evry_conf->conf_actions = conf[1]; + evry_conf->conf_objects = conf[2]; + + if (type == EVRY_PLUGIN_SUBJECT) + { + char buf[256]; + snprintf(buf, sizeof(buf), _("Show %s Plugin"), p->name); + + e_action_predef_name_set(_("Everything Launcher"), buf, + "everything", p->name, NULL, 1); + } + + if (p->input_type) + { + Evry_Action *act; + char buf[256]; + snprintf(buf, sizeof(buf), _("Browse %s"), EVRY_ITEM(p)->label); + + act = EVRY_ACTION_NEW(buf, p->input_type, 0, EVRY_ITEM(p)->icon, + _evry_plugin_action_browse, NULL); + EVRY_ITEM(act)->data = p; + evry_action_register(act, 1); + actions = eina_list_append(actions, act); + } + + return new_conf; +} + +EAPI void +evry_plugin_unregister(Evry_Plugin *p) +{ + DBG("%s", p->name); + Eina_List *l = evry_conf->conf_subjects; + + if (l && eina_list_data_find_list(l, p->config)) + { + char buf[256]; + snprintf(buf, sizeof(buf), _("Show %s Plugin"), p->name); + + e_action_predef_name_del(_("Everything"), buf); + } +} diff --git a/src/modules/everything/evry_types.h b/src/modules/everything/evry_types.h index e2b68e3..9a5e5e0 100644 --- a/src/modules/everything/evry_types.h +++ b/src/modules/everything/evry_types.h @@ -50,18 +50,16 @@ struct _Evry_Item /* optional */ Evry_Type subtype; - - /* do not set! */ - Eina_List *items; - + Evas_Object *(*icon_get) (Evry_Item *it, Evas *e); void (*free) (Evry_Item *it); /* do not set by plugin! */ + int ref; + Eina_List *items; Eina_Bool selected; Eina_Bool marked; Evry_Plugin *plugin; - int ref; double usage; History_Item *hi; }; @@ -172,6 +170,9 @@ struct _Evry_Plugin have extended plugin struct */ void (*free) (Evry_Plugin *p); + /* optional: set type which the plugin can handle in begin */ + Evry_Type input_type; + /* optional: whether the plugin uses evry_async_update to add new items */ /* default FALSE */ Eina_Bool async_fetch; diff --git a/src/modules/everything/evry_util.c b/src/modules/everything/evry_util.c index 5129e02..733fd3f 100644 --- a/src/modules/everything/evry_util.c +++ b/src/modules/everything/evry_util.c @@ -750,29 +750,9 @@ _isalnum(unsigned char in) } return EINA_FALSE; } -/* FIXME there seem to be too many ways of not following a standard. - find out which is the most popular */ -static Eina_Bool -_isuric(unsigned char in) -{ - switch (in) - { - case '/': case '.': case '(': case ')': case '-': - case '~': case '\'': case '_': case '@': case '+': - /* case ';': case ':': - * case '&': case '=': case '$': case ',': - * case '.': case '!': - * case '\'': */ - - return EINA_TRUE; - default: - break; - } - return EINA_FALSE; -} char * -_evry_util_url_escape(const char *string, int inlength, int path) +evry_util_url_escape(const char *string, int inlength) { size_t alloc = (inlength?(size_t)inlength:strlen(string))+1; char *ns; @@ -791,8 +771,7 @@ _evry_util_url_escape(const char *string, int inlength, int path) { in = *string; - if (_isalnum(in) || - (path && _isuric(in))) + if (_isalnum(in)) { /* just copy this */ ns[strindex++]=in; @@ -825,14 +804,7 @@ _evry_util_url_escape(const char *string, int inlength, int path) return ns; } -EAPI char * -evry_util_url_escape(const char *string, int inlength) -{ - return _evry_util_url_escape(string, inlength, 0); -} - - -EAPI const char* +const char* evry_file_path_get(Evry_Item_File *file) { const char *tmp; @@ -861,8 +833,9 @@ evry_file_path_get(Evry_Item_File *file) EAPI const char* evry_file_url_get(Evry_Item_File *file) { - char buf[PATH_MAX]; - char *escaped; + char dest[PATH_MAX * 3 + 7]; + const char *p; + int i; if (file->url) return file->url; @@ -870,19 +843,37 @@ evry_file_url_get(Evry_Item_File *file) if (!file->path) return NULL; - escaped = _evry_util_url_escape(file->path, 0, 1); + memset(dest, 0, PATH_MAX * 3 + 7); - if (escaped) - { - snprintf(buf, sizeof(buf), "file://%s", escaped); - E_FREE(escaped); - - file->url = eina_stringshare_add(buf); + snprintf(dest, 8, "file://"); - return file->url; + /* Most app doesn't handle the hostname in the uri so it's put to NULL */ + for (i = 7, p = file->path; *p != '\0'; p++, i++) + { + if (isalnum(*p) || strchr("/$-_.+!*'()", *p)) + dest[i] = *p; + else + { + snprintf(&(dest[i]), 4, "%%%02X", (unsigned char)*p); + i += 2; + } } - return NULL; + file->url = eina_stringshare_add(dest); + + return file->url; + + /* escaped = _evry_util_url_escape(file->path, 0, 1); + * + * if (escaped) + * { + * snprintf(buf, sizeof(buf), "file://%s", escaped); + * E_FREE(escaped); + * + * file->url = eina_stringshare_add(buf); + * + * return file->url; + * } */ } static void -- 2.7.4