e17/evry: use cached exe list directly, no need to strdup

SVN revision: 78907
This commit is contained in:
Hannes Janetzek 2012-11-05 00:17:26 +00:00
parent 401ad33fe5
commit 34625fa849
1 changed files with 74 additions and 76 deletions

View File

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