From 4d746f5484ea2d5a284d7ff16a414211badc48bb Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Thu, 6 May 2010 13:09:14 +0000 Subject: [PATCH] - splitted files plugin into recent-files/files - added top-level option for plugins to either show the plugins' items or the the plugin in aggregator - added min_query option for plugins. - added 'show in all' plugin option - removed default config curft from plugin struct. plugin_register returns true when a new config was created to set defaults. - reorganized settings plugin. SVN revision: 48642 --- src/modules/everything-apps/e_mod_main.c | 60 +- src/modules/everything-aspell/e_mod_main.c | 21 +- src/modules/everything-calc/e_mod_main.c | 11 +- src/modules/everything-files/e_mod_main.c | 560 ++++++++---------- src/modules/everything-settings/e_mod_main.c | 129 ++-- src/modules/everything-wallpaper/e_mod_main.c | 2 +- src/modules/everything/Evry.h | 94 ++- src/modules/everything/e_mod_main.c | 170 +++--- src/modules/everything/evry.c | 93 ++- src/modules/everything/evry_config.c | 67 ++- src/modules/everything/evry_history.c | 51 +- src/modules/everything/evry_plug_actions.c | 3 + src/modules/everything/evry_plug_aggregator.c | 166 ++---- src/modules/everything/evry_plug_text.c | 17 +- src/modules/everything/evry_plug_view_thumb.c | 59 +- src/modules/everything/evry_util.c | 163 ++++- 16 files changed, 881 insertions(+), 785 deletions(-) diff --git a/src/modules/everything-apps/e_mod_main.c b/src/modules/everything-apps/e_mod_main.c index aa5ab1681..8ac7dccc7 100644 --- a/src/modules/everything-apps/e_mod_main.c +++ b/src/modules/everything-apps/e_mod_main.c @@ -649,7 +649,6 @@ _fetch(Evry_Plugin *plugin, const char *input) Eina_List *l; Efreet_Desktop *desktop; Evry_Item *it; - /* char *file; */ EVRY_PLUGIN_ITEMS_CLEAR(p); @@ -676,31 +675,29 @@ _fetch(Evry_Plugin *plugin, const char *input) p->apps_all = apps; } - /* .desktop files */ - _add_desktop_list(p, p->apps_all, input); + if (input) + { + /* .desktop files */ + _add_desktop_list(p, p->apps_all, input); - /* add executables */ - _add_executables(p, input); + /* add executables */ + _add_executables(p, input); + } + else + { + /* add matching items */ + _add_desktop_list(p, p->apps_mime, input); + } - if (!input) - _add_desktop_list(p, p->apps_mime, input); - - /* FIXME update last used from exehist */ - /* EINA_LIST_FOREACH(e_exehist_list_get(), l, file) - * { - * double last_used = e_exehist_newest_run_get(file); - * History_Item *hi; - * it = (Evry_Item *)_item_add(p, NULL, file, 1); - * if (!eina_hash_find(evry_hist->subjects, it->id)) - * { - * hi = evry_history_add(evry_hist->subjects, it, NULL, NULL); - * if (hi) hi->last_used = last_used; - * } - * } */ + EINA_LIST_FOREACH(plugin->items, l, it) + evry_history_item_usage_set(evry_hist->subjects, it, input, NULL); + + EVRY_PLUGIN_ITEMS_SORT(plugin, _cb_sort); - /* add exe history items */ if (!input && !plugin->items) { + + /* add history items */ if (!p->apps_hist) { History_Types *ht; @@ -711,18 +708,10 @@ _fetch(Evry_Plugin *plugin, const char *input) else _add_desktop_list(p, p->apps_hist, NULL); } - else - { - EINA_LIST_FOREACH(plugin->items, l, it) - evry_history_item_usage_set(evry_hist->subjects, it, input, NULL); - - EVRY_PLUGIN_ITEMS_SORT(plugin, _cb_sort); - } - return 1; + return !!(plugin->items); } - static int _complete(Evry_Plugin *plugin, const Evry_Item *it, char **input) { @@ -749,17 +738,6 @@ _complete(Evry_Plugin *plugin, const Evry_Item *it, char **input) static int _exec_app_check_item(Evry_Action *act, const Evry_Item *it) { - /* if (!CHECK_TYPE(it, EVRY_TYPE_APP, NULL)) return 0; */ - - /* ITEM_APP(app, it); */ - - /* if (app->desktop) - * return 1; */ - - /* run in terminal or do a .desktop entry! it's easy now */ - /* if (app->file && strlen(app->file) > 0) - * return 1; */ - return 1; } diff --git a/src/modules/everything-aspell/e_mod_main.c b/src/modules/everything-aspell/e_mod_main.c index 05af1a4fd..6b940a01b 100644 --- a/src/modules/everything-aspell/e_mod_main.c +++ b/src/modules/everything-aspell/e_mod_main.c @@ -283,6 +283,12 @@ _fetch(Evry_Plugin *plugin, const char *input) if (!input) return 1; + if (strlen(input) < plugin->config->min_query) + { + EVRY_PLUGIN_ITEMS_FREE(p); + return 0; + } + if (!p->handler.data && !_begin(plugin, NULL)) return 0; len = sizeof(LANG_MODIFIER) - 1; @@ -392,13 +398,20 @@ _plugins_init(void) EVRY_TYPE_TEXT, NULL, _cleanup, _fetch, NULL); p->config_path = _config_path; - p->aggregate = EINA_FALSE; p->history = EINA_FALSE; p->async_fetch = EINA_TRUE; - p->trigger = TRIGGER; - p->view_mode = VIEW_MODE_LIST; - evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 100); + if (evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 100)) + { + Plugin_Config *pc = p->config; + pc->view_mode = VIEW_MODE_LIST; + pc->aggregate = EINA_FALSE; + pc->top_level = EINA_FALSE; + pc->trigger = eina_stringshare_add(TRIGGER); + pc->trigger_only = EINA_TRUE; + pc->min_query = 2; + } + _plug = (Plugin *) p; return EINA_TRUE; diff --git a/src/modules/everything-calc/e_mod_main.c b/src/modules/everything-calc/e_mod_main.c index ac7da13ce..0a0e7485a 100644 --- a/src/modules/everything-calc/e_mod_main.c +++ b/src/modules/everything-calc/e_mod_main.c @@ -238,13 +238,16 @@ _plugins_init(void) EVRY_TYPE_TEXT, _begin, _cleanup, _fetch, NULL); - p1->view_mode = VIEW_MODE_LIST; - p1->aggregate = EINA_FALSE; p1->history = EINA_FALSE; p1->async_fetch = EINA_TRUE; - p1->trigger = "="; - evry_plugin_register(p1, EVRY_PLUGIN_SUBJECT, 0); + if (evry_plugin_register(p1, EVRY_PLUGIN_SUBJECT, 0)) + { + Plugin_Config *pc = p1->config; + pc->view_mode = VIEW_MODE_LIST; + pc->aggregate = EINA_FALSE; + pc->trigger = eina_stringshare_add("="); + } return EINA_TRUE; } diff --git a/src/modules/everything-files/e_mod_main.c b/src/modules/everything-files/e_mod_main.c index 0df3dfe07..59e4a55ea 100644 --- a/src/modules/everything-files/e_mod_main.c +++ b/src/modules/everything-files/e_mod_main.c @@ -41,16 +41,15 @@ struct _Plugin const char *directory; const char *input; unsigned int command; + unsigned int min_query; Eina_Bool parent; - Eina_List *hist_added; Eina_Bool show_hidden; Eina_Bool dirs_only; Eina_Bool show_recent; Ecore_Thread *thread; - Ecore_Thread *thread2; Ecore_File_Monitor *dir_mon; - int cleanup; + int wait_finish; }; struct _Data @@ -86,36 +85,39 @@ struct _Module_Config static Module_Config *_conf; static char _module_icon[] = "system-file-manager"; -static Evry_Plugin *p1 = NULL; -static Evry_Plugin *p2 = NULL; +static Eina_List *_plugins = NULL; static Eina_List *_actions = NULL; static const char *_mime_dir; +static const char *_mime_mount; static Eina_Bool clear_cache = EINA_FALSE; -static void _cleanup(Evry_Plugin *plugin); +static void _finish(Evry_Plugin *plugin); static Eina_Bool _hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata); static void _item_fill(Evry_Item_File *file) { - const char *mime; - - if (file->mime) return; - - if ((mime = efreet_mime_type_get(file->path))) + if (!file->mime) { - file->mime = eina_stringshare_add(mime); + const char *mime = efreet_mime_type_get(file->path); - EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime); - - if ((!strcmp(mime, "inode/directory")) || - (!strcmp(mime, "inode/mount-point"))) - EVRY_ITEM(file)->browseable = EINA_TRUE; - - return; + if (mime) + file->mime = eina_stringshare_ref(mime); + else + file->mime = eina_stringshare_add("unknown"); } - file->mime = eina_stringshare_add("unknown"); + if ((file->mime == _mime_dir) || + (file->mime == _mime_mount)) + EVRY_ITEM(file)->browseable = EINA_TRUE; + + EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime); + + if (!EVRY_ITEM(file)->detail) + evry_util_file_detail_set(file); + + + evry_util_file_detail_set(file); } static int @@ -262,13 +264,21 @@ _append_files(Plugin *p) EVRY_PLUGIN_ITEMS_CLEAR(p); + if (!p->command && p->min_query) + { + if (!p->input) + return 0; + if (strlen(p->input) < p->min_query) + return 0; + } + EINA_LIST_FOREACH(p->files, l, it) { if (cnt >= MAX_SHOWN) break; if (p->dirs_only && !it->browseable) continue; - + if (p->input && (match = evry_fuzzy_match(it->label, p->input))) { it->fuzzy_match = match; @@ -324,13 +334,8 @@ _scan_cancel_func(void *data) p->thread = NULL; - if (p->cleanup > 0) - { - p->cleanup--; - - if (!p->cleanup) - E_FREE(p); - } + if (p->wait_finish) + E_FREE(p); } static void @@ -349,7 +354,7 @@ _scan_end_func(void *data) if (_conf->cache_dirs) ht = evry_history_types_get(evry_hist->subjects, EVRY_TYPE_FILE); - + if (!d->run_cnt) { EINA_LIST_FOREACH_SAFE(d->files, l, ll, item) @@ -358,29 +363,15 @@ _scan_end_func(void *data) filename = (char *)item->label; path = (char *) file->path; - mime = (char *) file->mime; + + if (!filename || !path) + goto next; file->path = eina_stringshare_add(path); - /* filter out files that we already have from history */ - EINA_LIST_FOREACH(p->files, lll, f) - { - if (f->path == file->path) - { - free(filename); - free(path); - eina_stringshare_del(file->path); - d->files = eina_list_remove_list(d->files, l); - E_FREE(file); - file = NULL; - break; - } - } - if (!file) continue; - if (item->browseable) file->mime = eina_stringshare_ref(_mime_dir); - + /* check if we can grab the mimetype from history */ if ((_conf->cache_dirs && ht) && (he = eina_hash_find(ht->types, file->path))) @@ -394,7 +385,6 @@ _scan_end_func(void *data) DBG("cached: %s %s", file->mime, file->path); hi->transient = 0; - item->usage = -1; break; } } @@ -412,8 +402,16 @@ _scan_end_func(void *data) item->label = eina_stringshare_add(filename); evry_util_file_detail_set(file); - free(filename); - free(path); + E_FREE(filename); + E_FREE(path); + continue; + + next: + E_FREE(filename); + E_FREE(path); + if (file->path) eina_stringshare_del(file->path); + d->files = eina_list_remove(d->files, file); + E_FREE(file); } if (d->files) @@ -436,8 +434,8 @@ _scan_end_func(void *data) if (!mime) break; - file->mime = eina_stringshare_add(mime); - item->context = eina_stringshare_ref(file->mime); + file->mime = eina_stringshare_ref(mime); + item->context = eina_stringshare_ref(mime); p->files = eina_list_append(p->files, file); } @@ -453,12 +451,12 @@ _scan_end_func(void *data) if (!d->files) { - if (_conf->cache_dirs) + if (!(p->command == CMD_SHOW_HIDDEN) && _conf->cache_dirs) { EINA_LIST_FOREACH(p->files, l, item) { GET_FILE(file, item); - + if (!item->usage && (hi = evry_history_add(evry_hist->subjects, item, NULL, NULL))) { @@ -466,26 +464,23 @@ _scan_end_func(void *data) hi->usage = TIME_FACTOR(hi->last_used); hi->data = eina_stringshare_ref(file->mime); item->hi = hi; - item->usage = -1; } else if (item->hi && (item->hi->count == 1) && (item->hi->last_used < SIX_DAYS_AGO)) { item->hi->last_used = SIX_DAYS_AGO - (0.001 * (double) cnt++); item->hi->usage = TIME_FACTOR(hi->last_used); - item->usage = -1; } - /* item->usage = 0; */ } } - + free(d->directory); E_FREE(d); p->thread = NULL; } - + p->files = eina_list_sort(p->files, -1, _cb_sort); - + _append_files(p); evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD); @@ -515,17 +510,11 @@ _dir_watcher(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const c file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, _item_free); file->path = eina_stringshare_add(path); - evry_util_file_detail_set(file); - if (event == ECORE_FILE_EVENT_CREATED_DIRECTORY) - { - file->mime = eina_stringshare_ref(_mime_dir); - EVRY_ITEM(file)->browseable = EINA_TRUE; - } - else - { - _item_fill(file); - } + file->mime = eina_stringshare_ref(_mime_dir); + + _item_fill(file); + p->files = eina_list_append(p->files, file); break; @@ -540,13 +529,8 @@ _dir_watcher(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const c if (file->path != label) continue; p->files = eina_list_remove_list(p->files, l); - if (eina_list_data_find_list(p->hist_added, file)) - { - p->hist_added = eina_list_remove(p->hist_added, file); - evry_item_free(EVRY_ITEM(file)); - } - evry_item_free(EVRY_ITEM(file)); + EVRY_ITEM_FREE(file); break; } eina_stringshare_del(label); @@ -580,7 +564,7 @@ static Evry_Plugin * _browse(Evry_Plugin *plugin, const Evry_Item *it) { Plugin *p = NULL; - + if (it && CHECK_TYPE(it, EVRY_TYPE_FILE)) { /* browsing */ @@ -628,7 +612,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) p->parent = EINA_FALSE; p->show_recent = EINA_TRUE; _read_directory(p); - + return EVRY_PLUGIN(p); } else if (!it) @@ -642,16 +626,15 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) p->show_recent = EINA_TRUE; p->parent = EINA_FALSE; - + p->min_query = plugin->config->min_query; _read_directory(p); - + if (clear_cache) { History_Types *ht = evry_history_types_get(evry_hist->subjects, EVRY_TYPE_FILE); if (ht) - { - eina_hash_foreach(ht->types, _hist_items_add_cb, p); - } + eina_hash_foreach(ht->types, _hist_items_add_cb, p); + clear_cache = EINA_FALSE; } @@ -661,152 +644,78 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) return NULL; } -static void -_cleanup(Evry_Plugin *plugin) -{ - GET_PLUGIN(p, plugin); - - Evry_Item_File *file; - - if (p->directory) - eina_stringshare_del(p->directory); - - EINA_LIST_FREE(p->files, file) - evry_item_free(EVRY_ITEM(file)); - - EVRY_PLUGIN_ITEMS_CLEAR(p); - - if (p->input) - eina_stringshare_del(p->input); - - if (p->dir_mon) - ecore_file_monitor_del(p->dir_mon); - - if (p->thread2) - { - ecore_thread_cancel(p->thread2); - p->cleanup++; - } - else - EINA_LIST_FREE(p->hist_added, file) - evry_item_free(EVRY_ITEM(file)); - - if (p->thread) - { - ecore_thread_cancel(p->thread); - p->cleanup++; - } - - if (!p->cleanup) - E_FREE(p); -} - /* use thread only to not block ui for ecore_file_exists ... */ static void _hist_func(void *data) { - Plugin *p = data; + Data *d = data; + Plugin *p = d->plugin; Eina_List *l; Evry_Item_File *file; History_Item *hi; - EINA_LIST_FOREACH(p->hist_added, l, file) + EINA_LIST_FOREACH(d->files, l, file) { - if (!evry_file_path_get(file)) - goto clear; - - if (!ecore_file_exists(file->path)) - goto clear; - - continue; - clear: - - hi = EVRY_ITEM(file)->hi; - hi->last_used -= ONE_DAY; - EVRY_ITEM(file)->hi = NULL; + if ((!evry_file_path_get(file)) || + (!ecore_file_exists(file->path))) + { + EVRY_ITEM(file)->hi->last_used -= ONE_DAY; + EVRY_ITEM(file)->hi = NULL; + } } } static void _hist_cancel_func(void *data) { - Plugin *p = data; + Data *d = data; + Plugin *p = d->plugin; Evry_Item_File *file; - EINA_LIST_FREE(p->hist_added, file) + EINA_LIST_FREE(d->files, file) { - /* XXX it cant be in p->files already, no ?*/ - p->files = eina_list_remove(p->files, file); - evry_item_free(EVRY_ITEM(file)); + EVRY_ITEM_FREE(file); } - p->thread2 = NULL; + E_FREE(d); - if (p->cleanup > 0) - { - p->cleanup--; - - if (!p->cleanup) - E_FREE(p); - } + if (p->wait_finish) + E_FREE(p); } static void _hist_end_func(void *data) { - Plugin *p = data; + Data *d = data; + Plugin *p = d->plugin; Eina_List *l, *ll; Evry_Item *it; const char *label; - EINA_LIST_FOREACH_SAFE(p->hist_added, l, ll, it) + EINA_LIST_FREE(d->files, it) { + GET_FILE(file, it); + if (!it->hi) { - p->hist_added = eina_list_remove_list(p->hist_added, l); evry_item_free(it); continue; } - GET_FILE(file, it); + _item_fill(file); - if (!file->mime) - file->mime = eina_stringshare_add(efreet_mime_type_get(file->path)); + it->hi->data = eina_stringshare_ref(file->mime); - if (!file->mime) - file->mime = eina_stringshare_add("unknown"); - - if ((!strcmp(file->mime, "inode/directory")) || - (!strcmp(file->mime, "inode/mount-point"))) - EVRY_ITEM(file)->browseable = EINA_TRUE; - - evry_util_file_detail_set(file); - - /* remember mimetype */ - if (it->data && file->mime) - { - if (!it->hi->data) - it->hi->data = eina_stringshare_ref(file->mime); - } - - label = ecore_file_file_get(file->path); - if (label) - it->label = eina_stringshare_add(label); - else - it->label = eina_stringshare_add(file->path); - - evry_item_ref(it); - p->files = eina_list_append(p->files, it); } - p->thread2 = NULL; - p->files = eina_list_sort(p->files, -1, _cb_sort); - _append_files(p); evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD); + + p->thread = NULL; + E_FREE(d); } static Eina_Bool @@ -814,10 +723,13 @@ _hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fda { History_Entry *he = data; History_Item *hi = NULL, *hi2; - Plugin *p = fdata; Eina_List *l, *ll; Evry_Item_File *file; double last_used = 0.0; + Data *d = fdata; + Plugin *p = d->plugin; + const char *label; + const char *path; EINA_LIST_FOREACH(he->items, l, hi2) { @@ -830,19 +742,19 @@ _hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fda if (clear_cache) { - printf("clear item %s\n", (char *)key); + DBG("clear %s", (char *)key); /* transient marks them for deletion */ - if (hi->count && (hi->last_used < SIX_DAYS_AGO)) + if ((hi->count == 1) && (hi->last_used < SIX_DAYS_AGO)) { + hi->usage = 0; hi->transient = 1; - hi->count--; } - + return EINA_TRUE; } - if (!hi->count) + if (hi->transient) return EINA_TRUE; if (!_conf->search_cache) @@ -850,33 +762,104 @@ _hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fda if ((hi->count == 1) && (hi->last_used < SIX_DAYS_AGO)) return EINA_TRUE; } - - - DBG("add %s", (char *) key); + + path = (const char *) key; + + DBG("add %s", path); + + if (!(label = ecore_file_file_get(path))) + return EINA_TRUE; EINA_LIST_FOREACH(p->files, ll, file) - if (!strcmp(file->path, key)) + if (!strcmp(EVRY_ITEM(file)->label, label) && + !strcmp(file->path, path)) return EINA_TRUE; - file = EVRY_ITEM_NEW(Evry_Item_File, p, NULL, NULL, _item_free); + if (!evry_fuzzy_match(label, p->input)) + return EINA_TRUE; - file->path = eina_stringshare_add(key); + file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, _item_free); + + file->path = eina_stringshare_add(path); if (hi->data) - file->mime = eina_stringshare_add(hi->data); + file->mime = eina_stringshare_ref(hi->data); EVRY_ITEM(file)->hi = hi; - if (file->mime) - EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime); - EVRY_ITEM(file)->id = eina_stringshare_ref(file->path); - p->hist_added = eina_list_append(p->hist_added, file); + d->files = eina_list_append(d->files, file); return EINA_TRUE; } +static void +_free_files(Plugin *p) +{ + Evry_Item_File *file; + + if (p->thread) + ecore_thread_cancel(p->thread); + p->thread = NULL; + + EINA_LIST_FREE(p->files, file) + EVRY_ITEM_FREE(file); + + if (p->dir_mon) + ecore_file_monitor_del(p->dir_mon); + p->dir_mon = NULL; +} + +static void +_finish(Evry_Plugin *plugin) +{ + GET_PLUGIN(p, plugin); + + IF_RELEASE(p->input); + IF_RELEASE(p->directory); + + if (p->thread) + { + ecore_thread_cancel(p->thread); + p->wait_finish = 1; + p->thread = NULL; + } + + EVRY_PLUGIN_ITEMS_CLEAR(p); + + _free_files(p); + + if (!p->wait_finish) + E_FREE(p); +} + +static int +_fetch_recent(Evry_Plugin *plugin, const char *input) +{ + GET_PLUGIN(p, plugin); + Evry_Item_File *file; + History_Types *ht; + int len = (input ? strlen(input) : 0); + + EVRY_PLUGIN_ITEMS_CLEAR(p); + + IF_RELEASE(p->input); + + if (input) p->input = eina_stringshare_add(input); + + if ((ht = evry_history_types_get(evry_hist->subjects, EVRY_TYPE_FILE))) + { + Data *d = E_NEW(Data, 1); + d->plugin = p; + eina_hash_foreach(ht->types, _hist_items_add_cb, d); + p->thread = ecore_thread_run(_hist_func, _hist_end_func, + _hist_cancel_func, d); + } + + return 0; +} + static void _folder_item_add(Plugin *p, const char *path) { @@ -890,42 +873,17 @@ _folder_item_add(Plugin *p, const char *path) EVRY_PLUGIN_ITEM_APPEND(p, file); } -static void -_free_files(Plugin *p) -{ - Evry_Item_File *file; - - if (p->thread) - ecore_thread_cancel(p->thread); - p->thread = NULL; - - if (p->thread2) - ecore_thread_cancel(p->thread2); - p->thread2 = NULL; - - EINA_LIST_FREE(p->files, file) - evry_item_free(EVRY_ITEM(file)); - - EINA_LIST_FREE(p->hist_added, file) - evry_item_free(EVRY_ITEM(file)); - - if (p->dir_mon) - ecore_file_monitor_del(p->dir_mon); - p->dir_mon = NULL; -} - static int _fetch(Evry_Plugin *plugin, const char *input) { GET_PLUGIN(p, plugin); Evry_Item_File *file; + int len = (input ? strlen(input) : 0); if (!p->command) EVRY_PLUGIN_ITEMS_CLEAR(p); - if (p->input) - eina_stringshare_del(p->input); - p->input = NULL; + IF_RELEASE(p->input); if (!p->parent && input && !strncmp(input, "/", 1)) { @@ -958,7 +916,7 @@ _fetch(Evry_Plugin *plugin, const char *input) } int len = strlen(p->directory); len = (len == 1) ? len : len+1; - + p->input = eina_stringshare_add(input + len); } else if (p->directory && input && !strncmp(input, "..", 2)) @@ -1024,45 +982,13 @@ _fetch(Evry_Plugin *plugin, const char *input) p->command = CMD_NONE; } - if (p->show_recent) - { - if ((!p->parent && !p->command && !p->hist_added) && - (((_conf->search_recent || _conf->search_cache) && - (input && strlen(input) > 2)) || - (_conf->show_recent))) - { - History_Types *ht = evry_history_types_get(evry_hist->subjects, EVRY_TYPE_FILE); - if (ht) - { - eina_hash_foreach(ht->types, _hist_items_add_cb, p); - p->thread2 = ecore_thread_run(_hist_func, _hist_end_func, - _hist_cancel_func, p); - } - } - else if ((_conf->search_recent || _conf->search_cache) && - (p->hist_added && (!input || (strlen(input) < 3)))) - { - EINA_LIST_FREE(p->hist_added, file) - { - p->files = eina_list_remove(p->files, file); - evry_item_free(EVRY_ITEM(file)); - evry_item_free(EVRY_ITEM(file)); - } - } - } - if (input && !p->command) p->input = eina_stringshare_add(input); - _append_files(p); + if ((p->command) || (!p->min_query) || (len >= p->min_query)) + _append_files(p); - if (!EVRY_PLUGIN(p)->items) - return 1; - - if (!p->parent && _conf->show_recent) - EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort); - - return 1; + return !!(EVRY_PLUGIN(p)->items); } static int @@ -1207,76 +1133,67 @@ static Eina_Bool _plugins_init(void) { Evry_Action *act; + Evry_Plugin *p; + int prio = 0; if (!evry_api_version_check(EVRY_API_VERSION)) return EINA_FALSE; - p1 = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Files"), NULL, - EVRY_TYPE_FILE, - _begin, _cleanup, _fetch, NULL); - p1->browse = &_browse; - p1->config_path = "extensions/everything-files"; - evry_plugin_register(p1, EVRY_PLUGIN_SUBJECT, 3); - /* p1->complete = &_complete; */ +#define PLUGIN_NEW(_name, _icon, _begin, _finish, _fetch) \ + p = EVRY_PLUGIN_NEW(Evry_Plugin, _name, _icon, EVRY_TYPE_FILE, \ + _begin, _finish, _fetch, NULL); \ + p->config_path = "extensions/everything-files"; \ + _plugins = eina_list_append(_plugins, p); \ - p2 = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Files"), NULL, - EVRY_TYPE_FILE, - _begin, _cleanup, _fetch, NULL); - p2->browse = &_browse; - p2->config_path = "extensions/everything-files"; - evry_plugin_register(p2, EVRY_PLUGIN_OBJECT, 1); - - act = EVRY_ACTION_NEW(N_("Open Folder (EFM)"), - EVRY_TYPE_FILE, 0, - "folder-open", - _open_folder_action, - _open_folder_check); - act->remember_context = EINA_TRUE; - evry_action_register(act, 0); - _actions = eina_list_append(_actions, act); + PLUGIN_NEW(N_("Files"), _module_icon, + _begin, _finish, _fetch); + p->browse = &_browse; + if (evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 2)) + p->config->min_query = 1; - act = EVRY_ACTION_NEW(N_("Open Terminal here"), - EVRY_TYPE_FILE, 0, - "system-run", - _open_term_action, NULL); - evry_action_register(act, 2); - _actions = eina_list_append(_actions, act); + PLUGIN_NEW(N_("Files"), _module_icon, + _begin, _finish, _fetch); + p->browse = &_browse; + evry_plugin_register(p, EVRY_PLUGIN_OBJECT, 2); - act = EVRY_ACTION_NEW(N_("Move to Trash"), - EVRY_TYPE_FILE, 0, - "edit-delete", - _file_trash_action, NULL); - EVRY_ITEM_DATA_INT_SET(act, ACT_TRASH); - evry_action_register(act, 2); - _actions = eina_list_append(_actions, act); + PLUGIN_NEW(N_("Recent Files"), _module_icon, + _begin, _finish, _fetch_recent); + if (evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 3)) + p->config->min_query = 3; - /* TODO ask if really want to delete !*/ - /* act = EVRY_ACTION_NEW(N_("Delete"), - * EVRY_TYPE_FILE, 0, - * "list-remove", - * _file_trash_action, NULL); - * EVRY_ITEM_DATA_INT_SET(act, ACT_DELETE); - * evry_action_register(act, 2); - * _actions = eina_list_append(_actions, act); */ + PLUGIN_NEW(N_("Recent Files"), _module_icon, + _begin, _finish, _fetch_recent); + if (evry_plugin_register(p, EVRY_PLUGIN_OBJECT, 3)) + p->config->min_query = 3; +#undef PLUGIN_NEW - act = EVRY_ACTION_NEW(N_("Copy To ..."), - EVRY_TYPE_FILE, EVRY_TYPE_FILE, - "go-next", - _file_copy_action, NULL); +#define ACTION_NEW(_name, _type2, _icon, _act, _check) \ + act = EVRY_ACTION_NEW(_name, EVRY_TYPE_FILE, _type2, _icon, _act, _check); \ + evry_action_register(act, prio++); \ + _actions = eina_list_append(_actions, act); \ + + ACTION_NEW(N_("Copy To ..."), EVRY_TYPE_FILE, "go-next", + _file_copy_action, NULL); act->it2.subtype = EVRY_TYPE_DIR; EVRY_ITEM_DATA_INT_SET(act, ACT_COPY); - evry_action_register(act, 2); - _actions = eina_list_append(_actions, act); - act = EVRY_ACTION_NEW(N_("Move To ..."), - EVRY_TYPE_FILE, EVRY_TYPE_FILE, - "go-next", - _file_copy_action, NULL); + ACTION_NEW(N_("Move To ..."), EVRY_TYPE_FILE, "go-next", + _file_copy_action, NULL); act->it2.subtype = EVRY_TYPE_DIR; EVRY_ITEM_DATA_INT_SET(act, ACT_MOVE); - evry_action_register(act, 2); - _actions = eina_list_append(_actions, act); + + ACTION_NEW(N_("Move to Trash"), 0, "edit-delete", + _file_trash_action, NULL); + EVRY_ITEM_DATA_INT_SET(act, ACT_TRASH); + + ACTION_NEW(N_("Open Folder (EFM)"), 0, "folder-open", + _open_folder_action, _open_folder_check); + act->remember_context = EINA_TRUE; + + ACTION_NEW(N_("Open Terminal here"), 0, "system-run", + _open_term_action, NULL); +#undef ACTION_NEW return EINA_TRUE; } @@ -1285,9 +1202,10 @@ static void _plugins_shutdown(void) { Evry_Action *act; + Evry_Plugin *p; - EVRY_PLUGIN_FREE(p1); - EVRY_PLUGIN_FREE(p2); + EINA_LIST_FREE(_plugins, p) + evry_plugin_free(p); EINA_LIST_FREE(_actions, act) evry_action_free(act); @@ -1519,6 +1437,7 @@ e_modapi_init(E_Module *m) _conf_init(m); _mime_dir = eina_stringshare_add("inode/directory"); + _mime_mount = eina_stringshare_add("inode/mountpoint"); e_module_delayed_set(m, 1); @@ -1532,6 +1451,7 @@ e_modapi_shutdown(E_Module *m) _plugins_shutdown(); eina_stringshare_del(_mime_dir); + eina_stringshare_del(_mime_mount); _conf_shutdown(); diff --git a/src/modules/everything-settings/e_mod_main.c b/src/modules/everything-settings/e_mod_main.c index 92f55ee57..3cbb84cde 100644 --- a/src/modules/everything-settings/e_mod_main.c +++ b/src/modules/everything-settings/e_mod_main.c @@ -5,55 +5,53 @@ #include "Evry.h" #include "e_mod_main.h" +typedef struct _Settings_Item Settings_Item; + +struct _Settings_Item +{ + Evry_Item base; + + E_Configure_Cat *ecat; + E_Configure_It *eci; +}; + static Evry_Plugin *p; static Evry_Action *act; +static Eina_List *items = NULL; static void -_cleanup(Evry_Plugin *p) +_finish(Evry_Plugin *p) { - EVRY_PLUGIN_ITEMS_FREE(p); + Evry_Item *it; + + EVRY_PLUGIN_ITEMS_CLEAR(p); + + EINA_LIST_FREE(items, it) + evry_item_free(it); } static Evas_Object * -_icon_get(Evry_Item *it, Evas *e) +_icon_get(Evry_Item *item, Evas *e) { - Evas_Object *o = NULL; - E_Configure_It *eci = it->data; + Evas_Object *o; + Settings_Item *it = (Settings_Item *) item; + + if (it->eci->icon && + ((o = evry_icon_theme_get(it->eci->icon, e)) || + (o = e_util_icon_add(it->eci->icon, e)))) + return o; - if (eci->icon) - { - if (!(o = evry_icon_theme_get(eci->icon, e))) - { - o = e_util_icon_add(eci->icon, e); - } - } - - return o; + return NULL; } -static void -_item_add(Evry_Plugin *p, E_Configure_It *eci, int match, int prio) -{ - Evry_Item *it; - - it = EVRY_ITEM_NEW(Evry_Item, p, eci->label, _icon_get, NULL); - it->data = eci; - it->priority = prio; - it->fuzzy_match = match; - - EVRY_PLUGIN_ITEM_APPEND(p, it); -} - -static int -_fetch(Evry_Plugin *p, const char *input) +static Evry_Plugin * +_begin(Evry_Plugin *p, const Evry_Item *item __UNUSED__) { + Settings_Item *it; Eina_List *l, *ll; E_Configure_Cat *ecat; E_Configure_It *eci; - int match; - - _cleanup(p); EINA_LIST_FOREACH(e_configure_registry, l, ecat) { @@ -62,57 +60,40 @@ _fetch(Evry_Plugin *p, const char *input) EINA_LIST_FOREACH(ecat->items, ll, eci) { - if (eci->pri >= 0) - { - if ((match = evry_fuzzy_match(eci->label, input))) - _item_add(p, eci, match, 0); - else if ((match = evry_fuzzy_match(ecat->label, input))) - _item_add(p, eci, match, 1); - } + if (eci->pri < 0) continue; + + it = EVRY_ITEM_NEW(Settings_Item, p, eci->label, _icon_get, NULL); + it->eci = eci; + it->ecat = ecat; + EVRY_ITEM_DETAIL_SET(it, ecat->label); + + items = eina_list_append(items, it); } } + return p; +} - if (eina_list_count(p->items) > 0) - { - p->items = evry_fuzzy_match_sort(p->items); - return 1; - } +static int +_fetch(Evry_Plugin *p, const char *input) +{ + EVRY_PLUGIN_ITEMS_CLEAR(p); - return 0; + if (!input) return 0; + + return EVRY_PLUGIN_ITEMS_ADD(p, items, input, 1, 1); } static int _action(Evry_Action *act) { - E_Configure_It *eci, *eci2; - E_Container *con; - E_Configure_Cat *ecat; - Eina_List *l, *ll; char buf[1024]; - int found = 0; + Settings_Item *it; - eci = act->it1.item->data; - con = e_container_current_get(e_manager_current_get()); + it = (Settings_Item *) act->it1.item; - EINA_LIST_FOREACH(e_configure_registry, l, ecat) - { - if (found) break; + snprintf(buf, sizeof(buf), "%s/%s", it->ecat->cat, it->eci->item); - EINA_LIST_FOREACH(ecat->items, ll, eci2) - { - if (eci == eci2) - { - snprintf(buf, sizeof(buf), "%s/%s", - ecat->cat, - eci->item); - found = 1; - break; - } - } - } - - if (found) - e_configure_registry_call(buf, con, NULL); + e_configure_registry_call(buf, e_container_current_get(e_manager_current_get()), NULL); return EVRY_ACTION_FINISHED; } @@ -123,12 +104,14 @@ _plugins_init(void) if (!evry_api_version_check(EVRY_API_VERSION)) return EINA_FALSE; - p = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Settings"), NULL, evry_type_register("E_SETTINGS"), - NULL, _cleanup, _fetch, NULL); + p = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Settings"), "preferences-desktop", + evry_type_register("E_SETTINGS"), + _begin, _finish, _fetch, NULL); evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 10); - act = EVRY_ACTION_NEW(N_("Show Dialog"), evry_type_register("E_SETTINGS"), 0, + act = EVRY_ACTION_NEW(N_("Show Dialog"), + evry_type_register("E_SETTINGS"), 0, "preferences-advanced", _action, NULL); evry_action_register(act, 0); diff --git a/src/modules/everything-wallpaper/e_mod_main.c b/src/modules/everything-wallpaper/e_mod_main.c index 1ab1e45e8..b2ad5712b 100644 --- a/src/modules/everything-wallpaper/e_mod_main.c +++ b/src/modules/everything-wallpaper/e_mod_main.c @@ -99,7 +99,7 @@ _fetch(Evry_Action *act) return it->items; } - +/* XXX free it->items list! */ static Eina_Bool _plugins_init(void) { diff --git a/src/modules/everything/Evry.h b/src/modules/everything/Evry.h index bceb66872..281d4b7fd 100644 --- a/src/modules/everything/Evry.h +++ b/src/modules/everything/Evry.h @@ -3,7 +3,7 @@ #include "e.h" -#define EVRY_API_VERSION 14 +#define EVRY_API_VERSION 16 #define EVRY_ACTION_OTHER 0 #define EVRY_ACTION_FINISHED 1 @@ -88,11 +88,17 @@ typedef unsigned int Evry_Type; #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_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_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _cleanup, _fetch, _free) \ evry_plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \ @@ -107,15 +113,16 @@ typedef unsigned int Evry_Type; if (_p) evry_plugin_free(EVRY_PLUGIN(_p)) -#define EVRY_PLUGIN_ITEMS_CLEAR(_p) \ - if (EVRY_PLUGIN(_p)->items) \ - eina_list_free(EVRY_PLUGIN(_p)->items); \ - EVRY_PLUGIN(_p)->items = NULL; +#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_FREE(_p) \ - Evry_Item *evryitem; \ - EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, evryitem) \ - evry_item_free(evryitem) #define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \ EVRY_PLUGIN(_p)->items = eina_list_sort \ @@ -124,7 +131,15 @@ typedef unsigned int Evry_Type; #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) struct _Evry_Item { @@ -163,6 +178,7 @@ struct _Evry_Item /* optional */ Evry_Type subtype; + /* do not set! */ Eina_List *items; Evas_Object *(*icon_get) (Evry_Item *it, Evas *e); @@ -185,7 +201,7 @@ struct _Evry_Action const char *name; struct - { + { /* requested type for action */ Evry_Type type; Evry_Type subtype; @@ -208,7 +224,7 @@ struct _Evry_Action Eina_List *items; } it2; - + /* optional: this action is specific for a item 'context'. e.g. 'copy' for file mime-type is not, 'image viewer' is. default is FALSE */ @@ -216,11 +232,11 @@ struct _Evry_Action int (*action) (Evry_Action *act); - /* optional */ + /* optional: check whether action fits to chosen item */ int (*check_item) (Evry_Action *act, const Evry_Item *it); /* optional */ void (*free) (Evry_Action *act); - /* optional: when action is browseable */ + /* optional: must be defined when action is browseable */ Eina_List *(*fetch) (Evry_Action *act); }; @@ -281,17 +297,10 @@ struct _Evry_Plugin have extended plugin struct */ void (*free) (Evry_Plugin *p); - /* optional: show in aggregator */ - /* default TRUE */ - Eina_Bool aggregate; - - /* optinal: whether the plugin uses evry_async_update to add new items */ + /* optional: whether the plugin uses evry_async_update to add new items */ /* default FALSE */ Eina_Bool async_fetch; - /* optional: request VIEW_MODE for plugin */ - int view_mode; - /* optional: request items to be remembered for usage statistic */ /* default TRUE */ Eina_Bool history; @@ -300,12 +309,10 @@ struct _Evry_Plugin /* default FALSE */ Eina_Bool transient; - /* optional: config path registered for the module */ + /* optional: config path registered for the module, to show + 'configure' button in everything config */ const char *config_path; - /* optional: default trigger. show this plugin only when triggered */ - const char *trigger; - /* not to be set by plugin! */ Plugin_Config *config; unsigned int request; @@ -329,11 +336,13 @@ struct _Evry_State /* selected item */ Evry_Item *cur_item; + /* marked items */ Eina_List *sel_items; Eina_Bool plugin_auto_selected; Eina_Bool item_auto_selected; + /* current view instance */ Evry_View *view; Eina_Bool changed; @@ -389,11 +398,13 @@ struct _Config int hide_input; int hide_list; + /* quick navigation mode */ int quick_nav; const char *cmd_terminal; const char *cmd_sudo; + /* default view mode */ int view_mode; int view_zoom; @@ -413,21 +424,45 @@ struct _Config struct _Plugin_Config { + /* do not set! */ const char *name; int enabled; + + /* request initial sort order of this plugin */ int priority; + /* trigger to show plugin exclusively */ const char *trigger; + + /* only show plugin when triggered */ int trigger_only; + /* preffered view mode */ int view_mode; + /* minimum input char to start query items, + this must be handled by plugin */ int min_query; + + /* show items of plugin in aggregator */ int aggregate; + /* if not top-level the plugin is shown in aggregator + instead of the items */ + int top_level; + + /* Eina_Hash *settings; */ + + /* do not set! */ Evry_Plugin *plugin; }; +/* struct _Plugin_Config_Setting + * { + * const char *str; + * double num; + * }; */ + struct _History_Entry { Eina_List *items; @@ -460,7 +495,6 @@ struct _History_Item const char *data; }; - /* evry.c */ EAPI void evry_item_select(const Evry_State *s, Evry_Item *it); EAPI void evry_item_mark(const Evry_State *state, Evry_Item *it, Eina_Bool mark); @@ -487,12 +521,16 @@ EAPI char *evry_util_unescape(const char *string, int length); EAPI void evry_util_file_detail_set(Evry_Item_File *file); EAPI Eina_Bool evry_util_module_config_check(const char *module_name, int conf, int epoch, int version); EAPI Evas_Object *evry_util_icon_get(Evry_Item *it, Evas *e); +EAPI int evry_util_plugin_items_add(Evry_Plugin *p, Eina_List *items, const char *input, int match_detail, int set_usage); +EAPI int evry_items_sort_func(const void *data1, const void *data2); + EAPI const char *evry_file_path_get(Evry_Item_File *file); EAPI const char *evry_file_uri_get(Evry_Item_File *file); /* e_mod_main.c */ -/* set plugin trigger and view mode first before register !*/ -EAPI void evry_plugin_register(Evry_Plugin *p, int type, int priority); +/* returns 1 when a new plugin config was created. in this case you can + set defaults of p->config */ +EAPI int evry_plugin_register(Evry_Plugin *p, int type, int priority); EAPI void evry_plugin_unregister(Evry_Plugin *p); EAPI void evry_action_register(Evry_Action *act, int priority); EAPI void evry_action_unregister(Evry_Action *act); diff --git a/src/modules/everything/e_mod_main.c b/src/modules/everything/e_mod_main.c index 13035b6d2..7a8ea44bf 100644 --- a/src/modules/everything/e_mod_main.c +++ b/src/modules/everything/e_mod_main.c @@ -12,7 +12,7 @@ /* #undef DBG * #define DBG(...) ERR(__VA_ARGS__) */ -#define CONFIG_VERSION 14 +#define CONFIG_VERSION 15 /* actual module specifics */ static void _e_mod_action_cb(E_Object *obj, const char *params); @@ -21,6 +21,7 @@ static void _e_mod_run_cb(void *data, E_Menu *m, E_Menu_Item *mi); static void _e_mod_menu_add(void *data, E_Menu *m); static void _config_init(void); static void _config_free(void); +static void _plugin_config_free(void); static int _cleanup_history(void *data); static E_Int_Menu_Augmentation *maug = NULL; @@ -33,6 +34,9 @@ static E_Config_DD *plugin_setting_edd = NULL; static Ecore_Timer *cleanup_timer; +static int _update = 0; + + EAPI int _e_module_evry_log_dom = -1; @@ -68,7 +72,7 @@ evry_type_register(const char *type) Evry_Type ret = 0; const char *i; Eina_List *l; - + EINA_LIST_FOREACH(_evry_types, l, i) { if (i == t) break; @@ -81,7 +85,7 @@ evry_type_register(const char *type) return ret; } eina_stringshare_del(t); - + return ret; } @@ -90,7 +94,7 @@ evry_type_get(Evry_Type type) { const char *ret = eina_list_nth(_evry_types, type); if (!ret) - return eina_stringshare_add(""); + return eina_stringshare_add(""); return ret; } @@ -163,7 +167,7 @@ e_modapi_init(E_Module *m) e_datastore_set("everything_loaded", ""); /* cleanup every hour :) */ - cleanup_timer = ecore_timer_add(3600, _cleanup_history, NULL); + cleanup_timer = ecore_timer_add(3600, _cleanup_history, NULL); return m; } @@ -173,7 +177,7 @@ e_modapi_shutdown(E_Module *m __UNUSED__) { E_Config_Dialog *cfd; const char *t; - + evry_shutdown(); view_thumb_shutdown(); @@ -187,7 +191,7 @@ e_modapi_shutdown(E_Module *m __UNUSED__) EINA_LIST_FREE(_evry_types, t) eina_stringshare_del(t); - + e_configure_registry_item_del("extensions/run_everything"); e_configure_registry_category_del("extensions"); @@ -215,7 +219,7 @@ e_modapi_shutdown(E_Module *m __UNUSED__) if (cleanup_timer) ecore_timer_del(cleanup_timer); - + return 1; } @@ -250,6 +254,9 @@ _config_init() E_CONFIG_VAL(D, T, trigger, STR); E_CONFIG_VAL(D, T, trigger_only, INT); E_CONFIG_VAL(D, T, view_mode, INT); + E_CONFIG_VAL(D, T, aggregate, INT); + E_CONFIG_VAL(D, T, top_level, INT); + E_CONFIG_VAL(D, T, min_query, INT); #undef T #undef D #define T Evry_Config @@ -280,65 +287,48 @@ _config_init() #undef D evry_conf = e_config_domain_load("module.everything", conf_edd); - if (evry_conf && evry_conf->version == 7) + if (evry_conf) { - evry_conf->scroll_speed = 10.0; - evry_conf->version = 8; + if (evry_conf->version <= 7) + { + evry_conf->scroll_speed = 10.0; + evry_conf->version = 8; + } + + if (evry_conf->version <= 8) + { + evry_conf->width = 445; + evry_conf->height = 310; + evry_conf->rel_y = 0.25; + evry_conf->scroll_animate = 1; + evry_conf->version = 9; + } + + if (evry_conf->version <= 9) + { + evry_conf->first_run = EINA_TRUE; + evry_conf->version = 13; + } + + if (evry_conf->version <= 13) + { + evry_conf->hide_list = 0; + evry_conf->version = 14; + } + + if (evry_conf->version <= 14) + { + _plugin_config_free(); + evry_conf->version = CONFIG_VERSION; + } + + if (evry_conf->version != CONFIG_VERSION) + { + _config_free(); + evry_conf = NULL; + } } - - if (evry_conf && evry_conf->version == 8) - { - evry_conf->width = 445; - evry_conf->height = 310; - evry_conf->rel_y = 0.25; - evry_conf->scroll_animate = 1; - evry_conf->version = 9; - } - - if (evry_conf && evry_conf->version == 9) - { - evry_conf->first_run = EINA_TRUE; - evry_conf->version = 12; - } - - if (evry_conf && evry_conf->version == 12) - { - Plugin_Config *pc; - Eina_List *conf[3]; - int i; - - conf[0] = evry_conf->conf_subjects; - conf[1] = evry_conf->conf_actions; - conf[2] = evry_conf->conf_objects; - - for (i = 0; i < 3; i++) - { - EINA_LIST_FREE(conf[i], pc) - { - if (pc->name) eina_stringshare_del(pc->name); - if (pc->trigger) eina_stringshare_del(pc->trigger); - E_FREE(pc); - } - } - evry_conf->conf_subjects = NULL; - evry_conf->conf_actions = NULL; - evry_conf->conf_objects = NULL; - - evry_conf->version = 13; - } - - if (evry_conf && evry_conf->version == 13) - { - evry_conf->hide_list = 0; - evry_conf->version = CONFIG_VERSION; - } - - if (evry_conf && evry_conf->version != CONFIG_VERSION) - { - _config_free(); - evry_conf = NULL; - } - + if (!evry_conf) { evry_conf = E_NEW(Evry_Config, 1); @@ -362,12 +352,11 @@ _config_init() } } - static void -_config_free(void) +_plugin_config_free(void) { Plugin_Config *pc; - + EINA_LIST_FREE(evry_conf->conf_subjects, pc) { if (pc->name) eina_stringshare_del(pc->name); @@ -389,12 +378,18 @@ _config_free(void) if (pc->plugin) evry_plugin_free(pc->plugin); E_FREE(pc); } +} + +static void +_config_free(void) +{ + _plugin_config_free(); if (evry_conf->cmd_terminal) eina_stringshare_del(evry_conf->cmd_terminal); if (evry_conf->cmd_sudo) eina_stringshare_del(evry_conf->cmd_sudo); - + E_FREE(evry_conf); } @@ -499,7 +494,7 @@ _evry_plugin_free(Evry_Item *it) E_FREE(p); } -Evry_Plugin * +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), @@ -508,13 +503,16 @@ evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, void (*cb_free) (Evry_Plugin *p)) { Evry_Plugin *p; + Evry_Item *it; if (base) p = base; else p = E_NEW(Evry_Plugin, 1); - evry_item_new(EVRY_ITEM(p), NULL, label, NULL, _evry_plugin_free); + it = evry_item_new(EVRY_ITEM(p), NULL, label, NULL, _evry_plugin_free); + it->plugin = p; + it->browseable = EINA_TRUE; p->base.icon = icon; p->base.type = EVRY_TYPE_PLUGIN; @@ -527,33 +525,32 @@ evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, p->finish = finish; p->fetch = fetch; - p->aggregate = EINA_TRUE; p->async_fetch = EINA_FALSE; p->history = EINA_TRUE; - p->view_mode = VIEW_MODE_NONE; p->free = cb_free; return p; } -void +EAPI void evry_plugin_free(Evry_Plugin *p) { evry_item_free(EVRY_ITEM(p)); } /* TODO make int return */ -void +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; + return 0; conf[0] = evry_conf->conf_subjects; conf[1] = evry_conf->conf_actions; @@ -565,16 +562,15 @@ evry_plugin_register(Evry_Plugin *p, int type, int priority) 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 = p->view_mode; - if (p->trigger) - { - pc->trigger = eina_stringshare_add(p->trigger); - pc->trigger_only = 1; - } + 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) @@ -603,9 +599,11 @@ evry_plugin_register(Evry_Plugin *p, int type, int priority) e_action_predef_name_set(_("Everything Launcher"), buf, "everything", p->name, NULL, 1); } + + return new_conf; } -void +EAPI void evry_plugin_unregister(Evry_Plugin *p) { DBG("%s", p->name); @@ -615,7 +613,7 @@ evry_plugin_unregister(Evry_Plugin *p) { char buf[256]; snprintf(buf, sizeof(buf), _("Show %s Plugin"), p->name); - + e_action_predef_name_del(_("Everything"), buf); } } @@ -631,7 +629,7 @@ _evry_cb_view_sort(const void *data1, const void *data2) } -void +EAPI void evry_view_register(Evry_View *view, int priority) { view->priority = priority; @@ -643,7 +641,7 @@ evry_view_register(Evry_View *view, int priority) _evry_cb_view_sort); } -void +EAPI void evry_view_unregister(Evry_View *view) { evry_conf->views = eina_list_remove(evry_conf->views, view); diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index 7dbf45649..aaf37d7fb 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -2,15 +2,13 @@ #include "e_mod_main.h" /* TODO */ -/* - animations - * - mouse handlers - * - show item descriptions +/* - mouse handlers * - keybinding configuration - * - shortcuts for plugins */ + #define INPUTLEN 256 -#define MATCH_LAG 0.15 -#define INITIAL_MATCH_LAG 0.2 +#define MATCH_LAG 0.25 +#define INITIAL_MATCH_LAG 0.3 /* #undef DBG * #define DBG(...) ERR(__VA_ARGS__) */ @@ -1130,6 +1128,9 @@ _evry_selector_subjects_get(const char *plugin_name) if (plugin_name && strcmp(plugin_name, p->name)) continue; + /* if (!p->config->top_level) + * continue; */ + if (p->begin) { if ((pp = p->begin(p, NULL))) @@ -1161,6 +1162,9 @@ _evry_selector_actions_get(Evry_Item *it) EINA_LIST_FOREACH(sel->plugins, l, p) { + /* if (!p->config->top_level) + * continue; */ + if (p->begin) { if ((pp = p->begin(p, it))) @@ -1194,6 +1198,9 @@ _evry_selector_objects_get(Evry_Action *act) { DBG("p %s %d %d\n", p->name, EVRY_ITEM(p)->subtype, act->it2.type); + /* if (!p->config->top_level) + * continue; */ + if (!CHECK_SUBTYPE(p, act->it2.type)) continue; @@ -1237,6 +1244,7 @@ _evry_state_pop(Evry_Selector *sel) { Evry_Plugin *p; Evry_State *s; + Evry_State *prev = NULL; s = sel->state; @@ -1247,33 +1255,40 @@ _evry_state_pop(Evry_Selector *sel) if (s->view) s->view->destroy(s->view); + sel->states = eina_list_remove_list(sel->states, sel->states); + + if (sel->states) + prev = sel->states->data; + EINA_LIST_FREE(s->plugins, p) - p->finish(p); - + { + /* XXX skip non top-level plugins */ + if (prev && eina_list_data_find(prev->plugins, p)) + continue; + + p->finish(p); + } + if (s->sel_items) eina_list_free(s->sel_items); E_FREE(s); - sel->states = eina_list_remove_list(sel->states, sel->states); - - if (sel->states) - sel->state = sel->states->data; - else - sel->state = NULL; + sel->state = prev; } int evry_browse_item(Evry_Selector *sel) { if (!sel) sel = selector; - Evry_State *s = sel->state; + Evry_State *s, *new_state; Evry_Item *it; Eina_List *l, *plugins = NULL; Evry_Plugin *p, *pp; Evry_View *view = NULL; - - if (!s) + int browse_aggregator = 0; + + if (!(s = sel->state)) return 0; it = s->cur_item; @@ -1298,24 +1313,46 @@ evry_browse_item(Evry_Selector *sel) (pp = it->plugin->browse(it->plugin, it))) plugins = eina_list_append(plugins, pp); + if (!plugins && CHECK_TYPE(it, EVRY_TYPE_PLUGIN)) + { + browse_aggregator = 1; + plugins = eina_list_append(plugins, it); + } + if (!plugins) return 0; - if (it->plugin->history) - evry_history_add(sel->history, s->cur_item, NULL, s->input); - + if (!(new_state = _evry_state_new(sel, plugins))) + return 0; + if (s->view) { _evry_view_hide(s->view, 1); view = s->view; } - _evry_state_new(sel, plugins); - _evry_matches_update(sel, 1); - _evry_selector_update(sel); - s = sel->state; + if (browse_aggregator) + { + evry_history_add(sel->history, s->cur_item, NULL, NULL); + snprintf(sel->state->input, INPUTLEN, "%s", s->input); - if (view && list->visible && s) + s = new_state; + /* if (sel->aggregator->fetch(sel->aggregator, input)) + * _evry_plugin_list_insert(s, sel->aggregator); */ + s->cur_plugins = eina_list_append(s->cur_plugins, it); + _evry_plugin_select(s, EVRY_PLUGIN(it)); + } + else if (it->plugin->history) + { + evry_history_add(sel->history, s->cur_item, NULL, s->input); + _evry_matches_update(sel, 1); + s = new_state; + } + + _evry_selector_update(sel); + + + if (view && list->visible) { s->view = view->create(view, s, list->o_main); if (s->view) @@ -1740,8 +1777,8 @@ _evry_update(Evry_Selector *sel, int fetch) sel->update_timer = ecore_timer_add(MATCH_LAG, _evry_cb_update_timer, sel); - if (s->plugin && !s->plugin->trigger) - edje_object_signal_emit(list->o_main, "e,signal,update", "e"); + /* if (s->plugin && !s->plugin->trigger) */ + edje_object_signal_emit(list->o_main, "e,signal,update", "e"); } } @@ -2119,7 +2156,7 @@ _evry_matches_update(Evry_Selector *sel, int async) EINA_LIST_FOREACH(s->plugins, l, p) { - if (sel == selectors[0]) + if ((p->config->top_level) && (sel == selectors[0])) { if ((p->config->trigger) && (p->config->trigger_only)) continue; diff --git a/src/modules/everything/evry_config.c b/src/modules/everything/evry_config.c index 4ab912388..51ef4181b 100644 --- a/src/modules/everything/evry_config.c +++ b/src/modules/everything/evry_config.c @@ -18,15 +18,20 @@ struct _Plugin_Page Evas_Object *o_view_detail; Evas_Object *o_view_thumb; Evas_Object *o_enabled; + Evas_Object *o_aggregate; + Evas_Object *o_top_level; Evas_Object *o_cfg_btn; + Evas_Object *o_min_query; Eina_List *configs; char *trigger; int trigger_only; int view_mode; + int aggregate; + int top_level; int enabled; - + int min_query; Plugin_Config *cur; } ; @@ -152,12 +157,12 @@ _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) #undef C if (evry_conf->conf_subjects) eina_list_free(evry_conf->conf_subjects); - if (evry_conf->conf_actions) eina_list_free(evry_conf->conf_actions); - if (evry_conf->conf_objects) eina_list_free(evry_conf->conf_objects); + if (evry_conf->conf_actions) eina_list_free(evry_conf->conf_actions); + if (evry_conf->conf_objects) eina_list_free(evry_conf->conf_objects); evry_conf->conf_subjects = eina_list_clone(cfdata->page[0].configs); - evry_conf->conf_actions = eina_list_clone(cfdata->page[1].configs); - evry_conf->conf_objects = eina_list_clone(cfdata->page[2].configs); + evry_conf->conf_actions = eina_list_clone(cfdata->page[1].configs); + evry_conf->conf_objects = eina_list_clone(cfdata->page[2].configs); for (i = 0; i < 3; i++) { @@ -174,9 +179,11 @@ _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) pc->trigger = NULL; pc->trigger_only = cfdata->page[i].trigger_only; - - pc->view_mode = cfdata->page[i].view_mode; - pc->enabled = cfdata->page[i].enabled; + pc->view_mode = cfdata->page[i].view_mode; + pc->enabled = cfdata->page[i].enabled; + pc->aggregate = cfdata->page[i].aggregate; + pc->top_level = cfdata->page[i].top_level; + pc->min_query = cfdata->page[i].min_query; } } @@ -213,7 +220,7 @@ _fill_list(Eina_List *plugins, Evas_Object *obj, int enabled __UNUSED__) e_widget_ilist_go(obj); e_widget_size_min_get(obj, &w, NULL); - e_widget_size_min_set(obj, w > 180 ? w : 180, 200); + e_widget_size_min_set(obj, w > 180 ? w : 180, 260); e_widget_ilist_thaw(obj); edje_thaw(); evas_event_thaw(evas); @@ -292,7 +299,13 @@ _list_select_cb (void *data, Evas_Object *obj) e_widget_check_checked_set(page->o_enabled, pc->enabled); e_widget_disabled_set(page->o_enabled, 0); - + e_widget_check_checked_set(page->o_aggregate, pc->aggregate); + e_widget_disabled_set(page->o_aggregate, 0); + e_widget_check_checked_set(page->o_top_level, pc->top_level); + e_widget_disabled_set(page->o_top_level, 0); + e_widget_slider_value_int_set(page->o_min_query, pc->min_query); + e_widget_disabled_set(page->o_min_query, 0); + if (pc->plugin && pc->plugin->config_path) { e_widget_disabled_set(page->o_cfg_btn, 0); @@ -314,7 +327,10 @@ _list_select_cb (void *data, Evas_Object *obj) e_widget_disabled_set(page->o_view_list, 1); e_widget_disabled_set(page->o_view_thumb, 1); e_widget_disabled_set(page->o_enabled, 1); + e_widget_disabled_set(page->o_aggregate, 1); + e_widget_disabled_set(page->o_top_level, 1); e_widget_disabled_set(page->o_cfg_btn, 1); + e_widget_disabled_set(page->o_min_query, 1); page->cur = NULL; } @@ -353,8 +369,9 @@ _create_plugin_page(E_Config_Dialog_Data *cfdata, Evas *e, Plugin_Page *page) _plugin_move_down_cb, page->list, page->configs); e_widget_framelist_object_append(of, o); - ob = e_widget_table_add(e, 1); - e_widget_table_object_append(ob, of, 0, 0, 1, 3, 1, 1, 1, 1); + ob = e_widget_table_add(e, 0); + e_widget_table_object_append(ob, of, 0, 0, 1, 3, 1, 1, 1, 0); + of = e_widget_framelist_add(e, _("General"), 0); o = e_widget_button_add(e, _("Configure"), NULL, _plugin_config_cb, @@ -362,12 +379,32 @@ _create_plugin_page(E_Config_Dialog_Data *cfdata, Evas *e, Plugin_Page *page) e_widget_disabled_set(o, 1); page->o_cfg_btn = o; e_widget_framelist_object_append(of, o); + o = e_widget_check_add(e, _("Enabled"), &(page->enabled)); e_widget_disabled_set(o, 1); page->o_enabled = o; e_widget_framelist_object_append(of, o); - e_widget_table_object_append(ob, of, 1, 0, 1, 1, 1, 0, 1, 0); + + o = e_widget_check_add(e, _("Show in \"All\""), + &(page->aggregate)); + e_widget_disabled_set(o, 1); + page->o_aggregate = o; + e_widget_framelist_object_append(of, o); + + o = e_widget_check_add(e, _("Show in top-level"), + &(page->top_level)); + e_widget_disabled_set(o, 1); + page->o_top_level = o; + e_widget_framelist_object_append(of, o); + + o = e_widget_label_add(e, _("Minimum characters for search")); + e_widget_framelist_object_append(of, o); + o = e_widget_slider_add(e, 1, 0, _("%1.0f"), 0, 5, 1.0, 0, NULL, &(page->min_query), 10); + page->o_min_query = o; + e_widget_framelist_object_append(of, o); + + e_widget_table_object_append(ob, of, 1, 0, 1, 1, 1, 1, 1, 0); of = e_widget_framelist_add(e, _("Plugin Trigger"), 0); o = e_widget_entry_add(e, &(page->trigger), NULL, NULL, NULL); @@ -379,7 +416,7 @@ _create_plugin_page(E_Config_Dialog_Data *cfdata, Evas *e, Plugin_Page *page) e_widget_disabled_set(o, 1); page->o_trigger_only = o; e_widget_framelist_object_append(of, o); - e_widget_table_object_append(ob, of, 1, 1, 1, 1, 1, 1, 1, 1); + e_widget_table_object_append(ob, of, 1, 1, 1, 1, 1, 1, 1, 0); of = e_widget_framelist_add(e, _("Plugin View"), 0); rg = e_widget_radio_group_new(&page->view_mode); @@ -399,7 +436,7 @@ _create_plugin_page(E_Config_Dialog_Data *cfdata, Evas *e, Plugin_Page *page) e_widget_disabled_set(o, 1); page->o_view_thumb = o; e_widget_framelist_object_append(of, o); - e_widget_table_object_append(ob, of, 1, 2, 1, 1, 1, 1, 1, 1); + e_widget_table_object_append(ob, of, 1, 2, 1, 1, 1, 1, 1, 0); return ob; } diff --git a/src/modules/everything/evry_history.c b/src/modules/everything/evry_history.c index 4843752db..c180f26a5 100644 --- a/src/modules/everything/evry_history.c +++ b/src/modules/everything/evry_history.c @@ -95,12 +95,12 @@ _hist_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata) if (ht->types) { - eina_hash_foreach(ht->types, _hist_entry_free_cb, NULL); + eina_hash_foreach(ht->types, _hist_entry_free_cb, NULL); eina_hash_free(ht->types); } - + E_FREE(ht); - + return EINA_TRUE; } @@ -119,7 +119,7 @@ _hist_entry_cleanup_cb(const Eina_Hash *hash, const void *key, void *data, void hi->count--; hi->last_used = d->time - SEVEN_DAYS/2.0; } - + /* item is transient or too old */ if (!hi->count || hi->transient) { @@ -151,12 +151,15 @@ _hist_cleanup_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata { History_Types *ht = data; Cleanup_Data *d = fdata; - - eina_hash_foreach(ht->types, _hist_entry_cleanup_cb, fdata); - EINA_LIST_FREE(d->keys, key) - eina_hash_del_by_key(ht->types, key); - + if (ht->types) + { + eina_hash_foreach(ht->types, _hist_entry_cleanup_cb, fdata); + + EINA_LIST_FREE(d->keys, key) + eina_hash_del_by_key(ht->types, key); + } + return EINA_TRUE; } void @@ -172,14 +175,14 @@ evry_history_free(void) d->time = ecore_time_get(); if (evry_hist->subjects) - { + { eina_hash_foreach(evry_hist->subjects, _hist_cleanup_cb, d); } if (evry_hist->actions) { eina_hash_foreach(evry_hist->actions, _hist_cleanup_cb, d); } - + E_FREE(d); evry_history_unload(); } @@ -194,7 +197,7 @@ EAPI void evry_history_load(void) { if (evry_hist) return; - + evry_hist = e_config_domain_load("module.everything.cache", hist_edd); if (evry_hist && evry_hist->version != HISTORY_VERSION) @@ -245,7 +248,7 @@ evry_history_types_get(Eina_Hash *hist, Evry_Type _type) if (!type) return NULL; - + ht = eina_hash_find(hist, type); if (!ht) @@ -255,8 +258,8 @@ evry_history_types_get(Eina_Hash *hist, Evry_Type _type) } if (!ht->types) - ht->types = eina_hash_string_superfast_new(NULL); - + ht->types = eina_hash_string_superfast_new(NULL); + return ht; } @@ -271,7 +274,7 @@ evry_history_add(Eina_Hash *hist, Evry_Item *it, const char *ctxt, const char *i const char *type; int rem_ctxt = 1; - + if (!it) return NULL; if (it->type == EVRY_TYPE_ACTION) @@ -342,12 +345,12 @@ evry_history_add(Eina_Hash *hist, Evry_Item *it, const char *ctxt, const char *i else if (input) { hi->input = eina_stringshare_add(input); - } + } } /* reset usage */ it->usage = 0.0; - + return hi; } @@ -361,7 +364,7 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, c int rem_ctxt = 1; it->usage = 0.0; const char *type; - + if (!it->plugin->history) return 0; @@ -376,7 +379,7 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, c if (!hi) { ht = evry_history_types_get(hist, it->type); - + if (!(he = eina_hash_find(ht->types, (it->id ? it->id : it->label)))) return 0; @@ -386,7 +389,7 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, c if (!act->remember_context) rem_ctxt = 0; } - + EINA_LIST_FOREACH(he->items, l, hi) { if (hi->plugin != it->plugin->name) @@ -405,7 +408,7 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, c if (!hi) return 0; - + if (evry_conf->history_sort_mode == 0) { if (!input || !hi->input) @@ -444,11 +447,11 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, c if (hi->last_used > it->usage) it->usage = hi->last_used; } - + if (it->usage > 0.0) return 1; it->usage = -1.0; - + return 0; } diff --git a/src/modules/everything/evry_plug_actions.c b/src/modules/everything/evry_plug_actions.c index 0799e2ace..2e63ce3b4 100644 --- a/src/modules/everything/evry_plug_actions.c +++ b/src/modules/everything/evry_plug_actions.c @@ -63,6 +63,9 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) GET_PLUGIN(p, plugin); + if (CHECK_TYPE(it, EVRY_TYPE_PLUGIN)) + return NULL; + EINA_LIST_FOREACH(evry_conf->actions, l, act) { if (((!act->it1.type) || diff --git a/src/modules/everything/evry_plug_aggregator.c b/src/modules/everything/evry_plug_aggregator.c index 18752b963..52fb698fe 100644 --- a/src/modules/everything/evry_plug_aggregator.c +++ b/src/modules/everything/evry_plug_aggregator.c @@ -12,90 +12,6 @@ struct _Plugin Evry_Item *warning; }; -static int -_cb_sort(const void *data1, const void *data2) -{ - const Evry_Item *it1 = data1; - const Evry_Item *it2 = data2; - - if ((it1->type == EVRY_TYPE_ACTION || - it1->subtype == EVRY_TYPE_ACTION) && - (it2->type == EVRY_TYPE_ACTION || - it2->subtype == EVRY_TYPE_ACTION)) - { - const Evry_Action *act1 = data1; - const Evry_Action *act2 = data2; - - /* sort actions that match the specific type before - those matching general type */ - if (act1->it1.item && act2->it1.item) - { - if ((act1->it1.type == act1->it1.item->type) && - (act2->it1.type != act2->it1.item->type)) - return -1; - - if ((act1->it1.type != act1->it1.item->type) && - (act2->it1.type == act2->it1.item->type)) - return 1; - } - - /* sort context specific actions before - general actions */ - if (act1->remember_context || act2->remember_context) - { - if (act1->remember_context && !act2->remember_context) - return -1; - if (!act1->remember_context && act2->remember_context) - return 1; - } - } - - /* sort items which match input or which - match much better first */ - if (it1->fuzzy_match > 0 || it2->fuzzy_match > 0) - { - if (it2->fuzzy_match <= 0) - return -1; - - if (it1->fuzzy_match <= 0) - return 1; - - if (abs (it1->fuzzy_match - it2->fuzzy_match) > 5) - return (it1->fuzzy_match - it2->fuzzy_match); - } - - /* sort recently/most frequently used items first */ - if (it1->usage > 0 || it2->usage > 0) - { - return (it1->usage > it2->usage ? -1 : 1); - } - - /* sort items which match input better first */ - if (it1->fuzzy_match > 0 || it2->fuzzy_match > 0) - { - if (it1->fuzzy_match - it2->fuzzy_match) - return (it1->fuzzy_match - it2->fuzzy_match); - } - - /* sort itemswith higher priority first */ - if ((it1->plugin == it2->plugin) && - (it1->priority - it2->priority)) - return (it1->priority - it2->priority); - - /* sort items with higher plugin priority first */ - if (it1->type != EVRY_TYPE_ACTION && - it2->type != EVRY_TYPE_ACTION) - { - int prio1 = it1->plugin->config->priority; - int prio2 = it2->plugin->config->priority; - - if (prio1 - prio2) - return (prio1 - prio2); - } - - return strcasecmp(it1->label, it2->label); -} - static inline Eina_List * _add_item(Plugin *p, Eina_List *items, Evry_Item *it) { @@ -132,17 +48,20 @@ _fetch(Evry_Plugin *plugin, const char *input) int i, cnt = 0; Eina_List *items = NULL; const char *context = NULL; + char buf[128]; + Evry_Selector *sel = p->selector; + if (input && !input[0]) input = NULL; EVRY_PLUGIN_ITEMS_FREE(p); - s = p->selector->state; + s = sel->state; if (!s) return 0; if (!s->cur_plugins) { /* 'text' and 'actions' are always loaded */ - if ((p->selector == selectors[0]) && + if ((sel == selectors[0]) && (eina_list_count(s->plugins) == 2)) { evry_item_ref(p->warning); @@ -154,7 +73,7 @@ _fetch(Evry_Plugin *plugin, const char *input) /* get current items' context ... */ for (i = 1; i < 3; i++) { - if (p->selector == selectors[i]) + if (sel == selectors[i]) { it = selectors[i-1]->state->cur_item; if (it) context = it->context; @@ -164,24 +83,54 @@ _fetch(Evry_Plugin *plugin, const char *input) /* filter all to be shown in aggregator */ EINA_LIST_FOREACH(s->cur_plugins, l, pp) { - if (!pp->aggregate || pp == plugin) continue; + if (!pp->config->aggregate || pp == plugin) + continue; + if (!sel->states->next && !pp->config->top_level) + continue; lp = eina_list_append(lp, pp); } - if (!lp) return 0; + /* show non-top-level plugins as item */ + if (!s->trigger_active && !sel->states->next) + { + EINA_LIST_FOREACH(s->plugins, l, pp) + { + GET_ITEM(it, pp); + + if (pp->config->top_level || pp == plugin) + continue; + + if (!pp->items) + continue; + + it->fuzzy_match = evry_fuzzy_match(it->label, input); + + it->hi = NULL; + evry_history_item_usage_set(sel->history, it, NULL, NULL); + + snprintf(buf, sizeof(buf), "%d %s", eina_list_count(pp->items), _("Items")); + if (it->detail) + eina_stringshare_del(it->detail); + it->detail = eina_stringshare_add(buf); + + items = _add_item(p, items, it); + } + } + + if (!lp && !items) return 0; /* if there is only one plugin append all items */ - if (!lp->next) + if (lp && !lp->next) { pp = lp->data; EINA_LIST_FOREACH(pp->items, l, it) { if (it->usage >= 0) - evry_history_item_usage_set(p->selector->history, + evry_history_item_usage_set(sel->history, it, input, context); - it->fuzzy_match = evry_fuzzy_match(it->label, input); - + if (it->fuzzy_match == 0) + it->fuzzy_match = evry_fuzzy_match(it->label, input); items = _add_item(p, items, it); } } @@ -196,10 +145,10 @@ _fetch(Evry_Plugin *plugin, const char *input) if (it->fuzzy_match == 0) it->fuzzy_match = evry_fuzzy_match(it->label, input); - if (it->fuzzy_match || p->selector == selectors[2]) + if (it->fuzzy_match || sel == selectors[2]) { if (it->usage >= 0) - evry_history_item_usage_set(p->selector->history, + evry_history_item_usage_set(sel->history, it, input, context); items = _add_item(p, items, it); @@ -209,15 +158,15 @@ _fetch(Evry_Plugin *plugin, const char *input) } /* always append items of action or object selector */ else if ((!input) && - ((p->selector == selectors[1]) || - (p->selector == selectors[2]))) + ((sel == selectors[1]) || + (sel == selectors[2]))) { EINA_LIST_FOREACH(lp, l, pp) { EINA_LIST_FOREACH(pp->items, ll, it) { if (it->usage >= 0) - evry_history_item_usage_set(p->selector->history, + evry_history_item_usage_set(sel->history, it, NULL, context); it->fuzzy_match = 0; items = _add_item(p, items, it); @@ -232,7 +181,7 @@ _fetch(Evry_Plugin *plugin, const char *input) EINA_LIST_FOREACH(pp->items, ll, it) { if ((it->usage >= 0) && - (evry_history_item_usage_set(p->selector->history, + (evry_history_item_usage_set(sel->history, it, input, context)) && (!eina_list_data_find_list(items, it))) { @@ -243,7 +192,7 @@ _fetch(Evry_Plugin *plugin, const char *input) } } - if (eina_list_count(items) < MAX_ITEMS) + if (lp && lp->next && eina_list_count(items) < MAX_ITEMS) { EINA_LIST_FOREACH(lp, l, pp) { @@ -252,17 +201,22 @@ _fetch(Evry_Plugin *plugin, const char *input) if (!eina_list_data_find_list(items, it)) { it->usage = 0; - it->fuzzy_match = 0; + if (it->fuzzy_match == 0) + it->fuzzy_match = evry_fuzzy_match(it->label, input); + items = _add_item(p, items, it); } } } } + /* EINA_LIST_FOREACH(items, l, it) + * printf("%d %1.20f %s\n", it->fuzzy_match, it->usage, it->label); */ if (items) eina_list_free(items); + if (lp) eina_list_free(lp); - EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort); + EVRY_PLUGIN_ITEMS_SORT(p, evry_items_sort_func); EINA_LIST_FOREACH_SAFE(p->base.items, l, ll, it) { @@ -275,14 +229,11 @@ _fetch(Evry_Plugin *plugin, const char *input) } static void -_finish(Evry_Plugin *plugin) +_finish(Evry_Plugin *p) { - Evry_Item *it; - EINA_LIST_FREE(plugin->items, it) - evry_item_free(it); + EVRY_PLUGIN_ITEMS_FREE(p); } - static void _free(Evry_Plugin *plugin) { @@ -301,7 +252,6 @@ evry_plug_aggregator_new(Evry_Selector *sel, int type) Evry_Plugin *p; p = EVRY_PLUGIN_NEW(Plugin, N_("All"), NULL, 0, NULL, _finish, _fetch, _free); - p->history = EINA_FALSE; evry_plugin_register(p, type, -1); diff --git a/src/modules/everything/evry_plug_text.c b/src/modules/everything/evry_plug_text.c index e7f798286..6a4810292 100644 --- a/src/modules/everything/evry_plug_text.c +++ b/src/modules/everything/evry_plug_text.c @@ -39,12 +39,19 @@ evry_plug_text_init(void) p2 = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Text"), "accessories-text-editor", EVRY_TYPE_TEXT, NULL, _cleanup, _fetch, NULL); - p1->trigger = " "; - p2->trigger = " "; - - evry_plugin_register(p1, EVRY_PLUGIN_OBJECT,999); - evry_plugin_register(p2, EVRY_PLUGIN_SUBJECT, 999); + if (evry_plugin_register(p1, EVRY_PLUGIN_OBJECT,999)) + { + p1->config->trigger_only = 1; + p1->config->trigger = eina_stringshare_add(" "); + } + + if (evry_plugin_register(p2, EVRY_PLUGIN_SUBJECT, 999)) + { + p2->config->trigger_only = 1; + p2->config->trigger = eina_stringshare_add(" "); + } + return EINA_TRUE; } diff --git a/src/modules/everything/evry_plug_view_thumb.c b/src/modules/everything/evry_plug_view_thumb.c index 2afd763d3..97392faae 100644 --- a/src/modules/everything/evry_plug_view_thumb.c +++ b/src/modules/everything/evry_plug_view_thumb.c @@ -1137,40 +1137,37 @@ _cb_key_down(Evry_View *view, const Ecore_Event_Key *ev) const char *key = ev->key; - if (s->plugin->view_mode == VIEW_MODE_NONE) + if (((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) && + (!strcmp(key, "2"))) || !strcmp(key, "XF86Back")) { - if (((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) && - (!strcmp(key, "2"))) || !strcmp(key, "XF86Back")) - { - if (v->mode == VIEW_MODE_LIST) - v->mode = VIEW_MODE_DETAIL; - else - v->mode = VIEW_MODE_LIST; + if (v->mode == VIEW_MODE_LIST) + v->mode = VIEW_MODE_DETAIL; + else + v->mode = VIEW_MODE_LIST; - v->zoom = 0; - _clear_items(v->span); - _update_frame(v->span); - goto end; - } - else if (((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) && - (!strcmp(key, "3"))) || !strcmp(key, "XF86Forward")) + v->zoom = 0; + _clear_items(v->span); + _update_frame(v->span); + goto end; + } + else if (((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) && + (!strcmp(key, "3"))) || !strcmp(key, "XF86Forward")) + { + if (v->mode != VIEW_MODE_THUMB) { - if (v->mode != VIEW_MODE_THUMB) - { - v->zoom = 0; - v->mode = VIEW_MODE_THUMB; - _clear_items(v->span); - } - else - { - v->zoom++; - if (v->zoom > 2) v->zoom = 0; - if (v->zoom == 2) - _clear_items(v->span); - } - _update_frame(v->span); - goto end; + v->zoom = 0; + v->mode = VIEW_MODE_THUMB; + _clear_items(v->span); } + else + { + v->zoom++; + if (v->zoom > 2) v->zoom = 0; + if (v->zoom == 2) + _clear_items(v->span); + } + _update_frame(v->span); + goto end; } if (((ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT) || @@ -1211,7 +1208,7 @@ _cb_key_down(Evry_View *view, const Ecore_Event_Key *ev) goto end; } else if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) && - (!strcmp(key, "minus"))) + (!strcmp(key, "minus"))) { EINA_LIST_FOREACH(sd->items, ll, it) { diff --git a/src/modules/everything/evry_util.c b/src/modules/everything/evry_util.c index 69d784849..6abc8ad54 100644 --- a/src/modules/everything/evry_util.c +++ b/src/modules/everything/evry_util.c @@ -12,7 +12,7 @@ evry_util_file_detail_set(Evry_Item_File *file) { char *dir = NULL; const char *tmp; - + if (EVRY_ITEM(file)->detail) return; @@ -24,11 +24,11 @@ evry_util_file_detail_set(Evry_Item_File *file) dir = ecore_file_dir_get(file->path); if (!dir || !home_dir) return; - + if (!strncmp(dir, home_dir, home_dir_len)) { tmp = dir + home_dir_len; - + if (*(tmp) == '\0') snprintf(dir_buf, sizeof(dir_buf), "~%s", tmp); else @@ -104,7 +104,7 @@ evry_fuzzy_match(const char *str, const char *match) min = 1; first = 0; /* m_len = 0; */ - + /* match current word of string against current match */ for (p = next; *next != 0; p++) { @@ -139,7 +139,7 @@ evry_fuzzy_match(const char *str, const char *match) offset += 3; /* m_len++; */ - + if (offset <= m_len * 3) continue; } @@ -245,9 +245,138 @@ _evry_fuzzy_match_sort_cb(const void *data1, const void *data2) EAPI Eina_List * evry_fuzzy_match_sort(Eina_List *items) { - return eina_list_sort(items, eina_list_count(items), _evry_fuzzy_match_sort_cb); + return eina_list_sort(items, -1, _evry_fuzzy_match_sort_cb); } +EAPI int +evry_items_sort_func(const void *data1, const void *data2) +{ + const Evry_Item *it1 = data1; + const Evry_Item *it2 = data2; + + if ((it1->type == EVRY_TYPE_ACTION || + it1->subtype == EVRY_TYPE_ACTION) && + (it2->type == EVRY_TYPE_ACTION || + it2->subtype == EVRY_TYPE_ACTION)) + { + const Evry_Action *act1 = data1; + const Evry_Action *act2 = data2; + + /* sort actions that match the specific type before + those matching general type */ + if (act1->it1.item && act2->it1.item) + { + if ((act1->it1.type == act1->it1.item->type) && + (act2->it1.type != act2->it1.item->type)) + return -1; + + if ((act1->it1.type != act1->it1.item->type) && + (act2->it1.type == act2->it1.item->type)) + return 1; + } + + /* sort context specific actions before + general actions */ + if (act1->remember_context && !act2->remember_context) + return -1; + if (!act1->remember_context && act2->remember_context) + return 1; + } + + /* if (it1->type == EVRY_TYPE_PLUGIN && + * it2->type != EVRY_TYPE_PLUGIN) + * { + * return (it1->usage > it2->usage ? -1 : 1); + * } + * else if (it2->type == EVRY_TYPE_PLUGIN && + * it1->type != EVRY_TYPE_PLUGIN) + * { + * return (it1->usage > it2->usage ? -1 : 1); + * } */ + + /* sort items which match input or which + match much better first */ + if (it1->fuzzy_match > 0 || it2->fuzzy_match > 0) + { + if (it2->fuzzy_match <= 0) + return -1; + + if (it1->fuzzy_match <= 0) + return 1; + + if (abs (it1->fuzzy_match - it2->fuzzy_match) > 5) + return (it1->fuzzy_match - it2->fuzzy_match); + } + + /* sort recently/most frequently used items first */ + if (it1->usage > 0.0 || it2->usage > 0.0) + { + return (it1->usage > it2->usage ? -1 : 1); + } + + /* sort items which match input better first */ + if (it1->fuzzy_match > 0 || it2->fuzzy_match > 0) + { + if (it1->fuzzy_match - it2->fuzzy_match) + return (it1->fuzzy_match - it2->fuzzy_match); + } + + /* sort itemswith higher priority first */ + if ((it1->plugin == it2->plugin) && + (it1->priority - it2->priority)) + return (it1->priority - it2->priority); + + /* sort items with higher plugin priority first */ + if (it1->type != EVRY_TYPE_ACTION && + it2->type != EVRY_TYPE_ACTION) + { + int prio1 = it1->plugin->config->priority; + int prio2 = it2->plugin->config->priority; + + if (prio1 - prio2) + return (prio1 - prio2); + } + + return strcasecmp(it1->label, it2->label); +} + +EAPI int +evry_util_plugin_items_add(Evry_Plugin *p, Eina_List *items, const char *input, + int match_detail, int set_usage) +{ + Eina_List *l, *cur = NULL; + Evry_Item *it; + int match = 0; + + if (p->items) + { + ERR("items not cleared"); + return 1; + } + + EINA_LIST_FOREACH(items, l, it) + { + it->fuzzy_match = evry_fuzzy_match(it->label, input); + + if (match_detail) + match = evry_fuzzy_match(it->detail, input); + + if (match && match < it->fuzzy_match) + it->fuzzy_match = match; + + if (it->fuzzy_match) + { + if (set_usage) + evry_history_item_usage_set(evry_hist->subjects, it, input, NULL); + + p->items = eina_list_append(p->items, it); + } + } + + p->items = eina_list_sort(p->items, -1, evry_items_sort_func); + + return !!(p->items); +} /* taken from e_utils. just changed 48 to 72.. we need evry_icon_theme_set(Evas_Object *obj, const char *icon, @@ -378,7 +507,7 @@ Evas_Object * evry_util_icon_get(Evry_Item *it, Evas *e) { Evas_Object *o = NULL; - + if (it->icon_get) o = it->icon_get(it, e); @@ -387,7 +516,7 @@ evry_util_icon_get(Evry_Item *it, Evas *e) if (CHECK_TYPE(it, EVRY_TYPE_FILE)) o = _file_icon_get(it, e); - + /* TODO default type: files, apps */ return o; @@ -401,11 +530,11 @@ evry_util_exec_app(const Evry_Item *it_app, const Evry_Item *it_file) Eina_List *files = NULL; char *exe = NULL; char *tmp = NULL; - + if (!it_app) return 0; GET_APP(app, it_app); GET_FILE(file, it_file); - + zone = e_util_zone_current_get(e_manager_current_get()); if (app->desktop) @@ -671,7 +800,7 @@ evry_file_path_get(Evry_Item_File *file) { const char *tmp; char *path; - + if (file->path) return file->path; @@ -681,14 +810,14 @@ evry_file_path_get(Evry_Item_File *file) if (!strncmp(file->url, "file://", 7)) tmp = file->url + 7; else return NULL; - + if (!(path = evry_util_unescape(tmp, 0))) return NULL; - + file->path = eina_stringshare_add(path); E_FREE(path); - + return file->path; } @@ -696,17 +825,17 @@ EAPI const char* evry_file_uri_get(Evry_Item_File *file) { char buf[PATH_MAX]; - + if (file->url) return file->url; if (!file->path) return NULL; - + snprintf(buf, sizeof(buf), "file://%s", file->path); /* FIXME escape ? */ - + file->url = eina_stringshare_add(buf); return file->url;