From 294d806d1264a1bfc47c37f63a3814ff55110526 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 22 Nov 2013 05:11:49 +0100 Subject: [PATCH] Refresh the menu as required --- src/applets/main.c | 61 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/applets/main.c b/src/applets/main.c index 797fa50..75d1c72 100644 --- a/src/applets/main.c +++ b/src/applets/main.c @@ -723,17 +723,39 @@ static void _on_suspend(gpointer data) /* on_timeout */ +static gboolean _timeout_path(Main * main, char const * path); + static gboolean _on_timeout(gpointer data) { Main * main = data; - const char path[] = DATADIR "/applications"; - struct stat st; + gboolean ret = TRUE; + char const * path; + char * p; + size_t i; + size_t j; - /* FIXME check each directory in XDG_DATA_DIRS */ - if(stat(path, &st) != 0) - return TRUE; - if(st.st_mtime == main->refresh_mti) - return TRUE; + if((path = getenv("XDG_DATA_DIRS")) != NULL + && strlen(path) > 0 + && (p = strdup(path)) != NULL) + { + for(i = 0, j = 0; ret == TRUE; i++) + if(p[i] == '\0') + { + ret = _timeout_path(main, &p[j]); + break; + } + else if(p[i] == ':') + { + p[i] = '\0'; + ret = _timeout_path(main, &p[j]); + j = i + 1; + } + free(p); + } + else + ret = _timeout_path(main, DATADIR); + if(ret != FALSE) + return ret; #ifdef DEBUG fprintf(stderr, "DEBUG: %s() resetting the menu\n", __func__); #endif @@ -741,5 +763,28 @@ static gboolean _on_timeout(gpointer data) g_slist_free(main->apps); main->apps = NULL; g_idle_add(_on_idle, main); - return FALSE; + return ret; +} + +static gboolean _timeout_path(Main * main, char const * path) +{ + const char applications[] = "/applications"; + char * p; + size_t len; + struct stat st; + + len = strlen(path) + sizeof(applications); + if((p = malloc(len)) == NULL) + { + main->helper->error(NULL, path, 1); + return TRUE; + } + snprintf(p, len, "%s%s", path, applications); + if(stat(p, &st) != 0) + { + free(p); + return TRUE; + } + free(p); + return (st.st_mtime > main->refresh_mti) ? FALSE : TRUE; }