aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHannes Janetzek <hannes.janetzek@gmail.com>2012-11-04 22:11:02 +0000
committerHannes Janetzek <hannes.janetzek@gmail.com>2012-11-04 22:11:02 +0000
commite885e76f12781811d5870d72c5f89c2b8cc46d94 (patch)
treea487744f517c3e9ce6aa75430db516c202f24be6 /src
parente17/evry> this look like nonsense (diff)
downloadenlightenment-e885e76f12781811d5870d72c5f89c2b8cc46d94.tar.gz
e17/evry: add monitors for PATH, avoid scanning each time.
- maybe something like this could go into e_exec? SVN revision: 78904
Diffstat (limited to 'src')
-rw-r--r--src/modules/everything/evry_plug_apps.c123
1 files changed, 105 insertions, 18 deletions
diff --git a/src/modules/everything/evry_plug_apps.c b/src/modules/everything/evry_plug_apps.c
index 0b85b1dc2..4b0cec38e 100644
--- a/src/modules/everything/evry_plug_apps.c
+++ b/src/modules/everything/evry_plug_apps.c
@@ -82,6 +82,11 @@ 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 void _scan_executables();
#define GET_MENU(_m, _it) Item_Menu * _m = (Item_Menu *)_it
@@ -1071,6 +1076,46 @@ _desktop_cache_update(void *data __UNUSED__, int type __UNUSED__, void *event __
return EINA_TRUE;
}
+static void
+_dir_watcher(void *data __UNUSED__, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path __UNUSED__)
+{
+ //printf("exebuf path changed\n");
+ switch (event)
+ {
+ case ECORE_FILE_EVENT_DELETED_SELF:
+ ecore_file_monitor_del(em);
+ dir_monitors = eina_list_remove(dir_monitors, em);
+ break;
+
+ default:
+ break;
+ }
+ update_path = EINA_TRUE;
+}
+
+static void
+_dir_monitor_add()
+{
+ Eina_List *l;
+ const char *dir;
+
+ EINA_LIST_FOREACH(exe_path, l, dir)
+ {
+ 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);
+ }
+}
+
+static void
+_dir_monitor_free()
+{
+ Ecore_File_Monitor *dir_mon;
+
+ EINA_LIST_FREE (dir_monitors, dir_mon)
+ ecore_file_monitor_del(dir_mon);
+}
static int
_plugins_init(const Evry_API *api)
@@ -1186,6 +1231,9 @@ _plugins_init(const Evry_API *api)
(EFREET_EVENT_DESKTOP_CACHE_UPDATE, _desktop_cache_update, NULL));
eina_stringshare_del(config_path);
+
+ update_path = EINA_TRUE;
+
return EINA_TRUE;
}
@@ -1208,6 +1256,12 @@ _plugins_shutdown(void)
EINA_LIST_FREE (handlers, h)
ecore_event_handler_del(h);
+
+ _dir_monitor_free();
+
+ if (current_path)
+ free(current_path);
+ current_path = NULL;
}
/***************************************************************************/
@@ -1510,6 +1564,7 @@ _scan_idler(void *data __UNUSED__)
{
dir = exe_path->data;
exe_dir = eina_file_direct_ls(dir);
+ //printf("scan dir: %s\n", dir);
}
/* if we have an opened dir - scan the next item */
if (exe_dir)
@@ -1552,30 +1607,32 @@ _scan_idler(void *data __UNUSED__)
return ECORE_CALLBACK_RENEW;
}
-static void
-_scan_executables()
+
+static Eina_Bool
+_exe_path_list()
{
- /* taken from exebuf module */
char *path, *pp, *last;
- E_Exe_List *el;
+ Eina_Bool changed;
- el = e_config_domain_load("exebuf_exelist_cache", exelist_edd);
- if (el)
- {
- E_Exe *ee;
+ path = getenv("PATH");
- 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);
+ // nothing changed
+ if (!update_path && (current_path && path) && !strcmp(current_path, path))
+ return EINA_FALSE;
+
+ changed = (path && (!current_path || !strcmp(current_path, path)));
+
+ if (current_path)
+ {
+ free(current_path);
+ current_path = NULL;
}
- path = getenv("PATH");
+
if (path)
{
path = strdup(path);
+ current_path = strdup(path);
+
last = path;
for (pp = path; pp[0]; pp++)
{
@@ -1588,9 +1645,39 @@ _scan_executables()
}
if (pp > last)
exe_path = eina_list_append(exe_path, strdup(last));
- free(path);
}
- exe_scan_idler = ecore_idler_add(_scan_idler, NULL);
+ if (changed)
+ {
+ _dir_monitor_free();
+ _dir_monitor_add();
+ }
+
+ return EINA_TRUE;
}
+static void
+_scan_executables()
+{
+ E_Exe_List *el;
+
+ el = e_config_domain_load("exebuf_exelist_cache", 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);
+ }
+ free(el);
+ }
+
+ if (_exe_path_list())
+ {
+ exe_scan_idler = ecore_idler_add(_scan_idler, NULL);
+ update_path = EINA_FALSE;
+ }
+}