diff --git a/src/modules/everything/evry_plug_apps.c b/src/modules/everything/evry_plug_apps.c index 4b0cec38e..b605e216f 100644 --- a/src/modules/everything/evry_plug_apps.c +++ b/src/modules/everything/evry_plug_apps.c @@ -40,7 +40,8 @@ struct _Plugin struct _E_Exe { - const char *path; + unsigned int len; + const char *path; }; struct _E_Exe_List @@ -61,7 +62,6 @@ struct _Module_Config struct _Item_Menu { Evry_Item base; - Efreet_Menu *menu; }; @@ -74,18 +74,20 @@ static char _module_icon[] = "system-run"; static Eina_List *_plugins = NULL; static Eina_List *_actions = NULL; static Evry_Item *_act_open_with = NULL; + +static Eina_List *exe_list = NULL; +static Eina_List *apps_cache = NULL; + +static char _exebuf_cache_file[] = "evry_exebuf_cache"; +static Eina_Bool update_path; +static char *current_path = NULL; +static Eina_List *dir_monitors = NULL; static Eina_List *exe_path = NULL; static Ecore_Idler *exe_scan_idler = NULL; static E_Config_DD *exelist_exe_edd = NULL; static E_Config_DD *exelist_edd = NULL; static Eina_Iterator *exe_dir = NULL; -static Eina_List *exe_list = NULL; -static Eina_List *exe_list2 = NULL; -static Eina_List *apps_cache = NULL; - -static Eina_Bool update_path; -static char *current_path = NULL; -static Eina_List *dir_monitors = NULL; +static Eina_List *exe_files = NULL; static void _scan_executables(); @@ -243,8 +245,7 @@ _fetch_exe(Evry_Plugin *plugin, const char *input) History_Types *ht; unsigned int input_len = (input ? strlen(input) : 0); double max = 0.0; - const char *tmp, *first_match = NULL; - unsigned int min = 0, cnt = 0, end = input_len; + unsigned int cnt = 0, end = input_len; Eina_Bool query = (input_len >= (unsigned int)plugin->config->min_query); EVRY_PLUGIN_ITEMS_CLEAR(p); @@ -255,49 +256,46 @@ _fetch_exe(Evry_Plugin *plugin, const char *input) if (input) { - const char *cmd; - + const char *tmp; + const E_Exe *ee, *match = NULL; // begin of arguments (end of executable part) if ((tmp = strchr(input, ' '))) end = tmp - input; if ((!exe_list) && (!exe_scan_idler)) _scan_executables(); - - EINA_LIST_FOREACH (exe_list, l, cmd) + EINA_LIST_FOREACH (exe_list, l, ee) { - unsigned int cmd_len = strlen(cmd); - - if ((end < input_len) && (cmd_len > end)) + if ((end < input_len) && (ee->len > end)) continue; - - if (!strncmp(input, cmd, end)) + if (!strncmp(input, ee->path, end)) { - if (query && (cnt++ < MAX_EXE) && (input_len != cmd_len)) - _item_exe_add(p, cmd, DEFAULT_MATCH_PRIORITY); + if (query && (cnt++ < MAX_EXE) && (input_len != ee->len)) + _item_exe_add(p, ee->path, DEFAULT_MATCH_PRIORITY); - if ((!min) || (cmd_len < min)) - { - min = cmd_len; - first_match = cmd; - } - - if ((!query) && (cmd_len == input_len)) + if ((!match) || (ee->len < match->len)) + match = ee; + + if ((!query) && (ee->len == input_len)) break; } } - if (first_match) + if (match) { GET_ITEM(it, p->command); + const char *cmd; - if (strlen(first_match) < input_len) - first_match = input; + if (match->len < input_len) + cmd = input; + else + cmd = match->path; + + EVRY_ITEM_LABEL_SET(it, cmd); - EVRY_ITEM_LABEL_SET(it, first_match); IF_RELEASE(p->command->file); p->command->file = eina_stringshare_ref(it->label); - it->fuzzy_match = PREFIX_MATCH_PRIORITY; + it->fuzzy_match = PREFIX_MATCH_PRIORITY; EVRY_PLUGIN_ITEM_APPEND(p, it); evry->item_changed(it, 0, 0); } @@ -343,6 +341,7 @@ _finish_exe(Evry_Plugin *plugin) { GET_PLUGIN(p, plugin); char *str; + E_Exe *ee; EVRY_PLUGIN_ITEMS_CLEAR(p); EVRY_ITEM_FREE(p->command); @@ -363,10 +362,15 @@ _finish_exe(Evry_Plugin *plugin) ecore_idler_del(exe_scan_idler); exe_scan_idler = NULL; } - EINA_LIST_FREE (exe_list, str) - free(str); - EINA_LIST_FREE (exe_list2, str) - free(str); + + EINA_LIST_FREE (exe_list, ee) + { + eina_stringshare_del(ee->path); + free(ee); + } + + EINA_LIST_FREE (exe_files, str) + eina_stringshare_del(str); E_FREE(p); } @@ -1084,7 +1088,7 @@ _dir_watcher(void *data __UNUSED__, Ecore_File_Monitor *em, Ecore_File_Event ev { case ECORE_FILE_EVENT_DELETED_SELF: ecore_file_monitor_del(em); - dir_monitors = eina_list_remove(dir_monitors, em); + dir_monitors = eina_list_remove(dir_monitors, em); break; default: @@ -1104,7 +1108,7 @@ _dir_monitor_add() Ecore_File_Monitor *dir_mon; dir_mon = ecore_file_monitor_add(dir, _dir_watcher, NULL); if (dir_mon) - dir_monitors = eina_list_append(dir_monitors, dir_mon); + dir_monitors = eina_list_append(dir_monitors, dir_mon); } } @@ -1112,7 +1116,7 @@ static void _dir_monitor_free() { Ecore_File_Monitor *dir_mon; - + EINA_LIST_FREE (dir_monitors, dir_mon) ecore_file_monitor_del(dir_mon); } @@ -1233,7 +1237,7 @@ _plugins_init(const Evry_API *api) eina_stringshare_del(config_path); update_path = EINA_TRUE; - + return EINA_TRUE; } @@ -1459,14 +1463,13 @@ evry_plug_apps_init(E_Module *m) EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown); - /* taken from e_exebuf.c */ exelist_exe_edd = E_CONFIG_DD_NEW("E_Exe", E_Exe); #undef T #undef D #define T E_Exe #define D exelist_exe_edd E_CONFIG_VAL(D, T, path, STR); - + E_CONFIG_VAL(D, T, len, UINT); exelist_edd = E_CONFIG_DD_NEW("E_Exe_List", E_Exe_List); #undef T #undef D @@ -1509,53 +1512,57 @@ _scan_idler(void *data __UNUSED__) int different = 0; /* FIXME: check wheter they match or not */ - for (l = exe_list, l2 = exe_list2; l && l2; l = l->next, l2 = l2->next) + for (l = exe_list, l2 = exe_files; l && l2; l = l->next, l2 = l2->next) { - if (strcmp(l->data, l2->data)) + E_Exe *ee = l->data; + if (ee->path != l2->data) { different = 1; break; } } if ((l) || (l2)) different = 1; - if (exe_list2) - { - void *tmp; - EINA_LIST_FREE(exe_list, tmp) - free(tmp); - exe_list = exe_list2; - exe_list2 = NULL; - } if (different) { + E_Exe *ee; + + EINA_LIST_FREE (exe_list, ee) + { + eina_stringshare_del(ee->path); + free(ee); + } + const char *s; E_Exe_List *el; - E_Exe *ee; el = calloc(1, sizeof(E_Exe_List)); if (!el) return ECORE_CALLBACK_CANCEL; el->list = NULL; - EINA_LIST_FOREACH(exe_list, l, s) + EINA_LIST_FREE(exe_files, s) { ee = malloc(sizeof(E_Exe)); if (!ee) continue ; - ee->path = eina_stringshare_add(s); + ee->path = s; + ee->len = strlen(s); el->list = eina_list_append(el->list, ee); } - e_config_domain_save("exebuf_exelist_cache", exelist_edd, el); + e_config_domain_save(_exebuf_cache_file, exelist_edd, el); - EINA_LIST_FREE(el->list, ee) - { - eina_stringshare_del(ee->path); - free(ee); - } + exe_list = el->list; free(el); } + else + { + const char *str; + EINA_LIST_FREE(exe_files, str) + eina_stringshare_del(str); + } + exe_scan_idler = NULL; return ECORE_CALLBACK_CANCEL; } @@ -1578,9 +1585,7 @@ _scan_idler(void *data __UNUSED__) if (!eina_file_statat(eina_iterator_container_get(exe_dir), info, &st) && (!S_ISDIR(st.mode)) && (!access(info->path, X_OK))) - { - exe_list2 = eina_list_append(exe_list2, strdup(info->path + info->name_start)); - } + exe_files = eina_list_append(exe_files, eina_stringshare_add(info->path + info->name_start)); } else { @@ -1627,7 +1632,7 @@ _exe_path_list() free(current_path); current_path = NULL; } - + if (path) { path = strdup(path); @@ -1661,17 +1666,10 @@ _scan_executables() { E_Exe_List *el; - el = e_config_domain_load("exebuf_exelist_cache", exelist_edd); + el = e_config_domain_load(_exebuf_cache_file, exelist_edd); if (el) { - E_Exe *ee; - - EINA_LIST_FREE (el->list, ee) - { - exe_list = eina_list_append(exe_list, strdup(ee->path)); - eina_stringshare_del(ee->path); - free(ee); - } + exe_list = el->list; free(el); }