Re-using code for XDG menu handling
This commit is contained in:
parent
f7e0a58bb8
commit
57e09baba9
@ -50,6 +50,7 @@ typedef struct _PanelApplet
|
|||||||
PanelAppletHelper * helper;
|
PanelAppletHelper * helper;
|
||||||
GSList * apps;
|
GSList * apps;
|
||||||
guint idle;
|
guint idle;
|
||||||
|
gboolean refresh;
|
||||||
time_t refresh_mti;
|
time_t refresh_mti;
|
||||||
} Main;
|
} Main;
|
||||||
|
|
||||||
@ -769,44 +770,16 @@ static void _on_suspend(gpointer data)
|
|||||||
|
|
||||||
|
|
||||||
/* on_timeout */
|
/* on_timeout */
|
||||||
static gboolean _timeout_path(Main * main, char const * path);
|
static void _timeout_path(Main * main, char const * path);
|
||||||
|
|
||||||
static gboolean _on_timeout(gpointer data)
|
static gboolean _on_timeout(gpointer data)
|
||||||
{
|
{
|
||||||
Main * main = data;
|
Main * main = data;
|
||||||
gboolean ret = TRUE;
|
|
||||||
char const * path;
|
|
||||||
char * p;
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
/* FIXME code duplicated from _on_idle() */
|
main->refresh = FALSE;
|
||||||
if((path = getenv("XDG_DATA_DIRS")) != NULL
|
_main_xdg_dirs(main, _timeout_path);
|
||||||
&& strlen(path) > 0
|
if(main->refresh == FALSE)
|
||||||
&& (p = strdup(path)) != NULL)
|
return TRUE;
|
||||||
{
|
|
||||||
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);
|
|
||||||
/* FIXME fallback to "$HOME/.local/share" if not set */
|
|
||||||
if(ret == TRUE && (path = getenv("XDG_DATA_HOME")) != NULL
|
|
||||||
&& strlen(path) > 0)
|
|
||||||
ret = _timeout_path(main, path);
|
|
||||||
if(ret != FALSE)
|
|
||||||
return ret;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s() resetting the menu\n", __func__);
|
fprintf(stderr, "DEBUG: %s() resetting the menu\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
@ -814,28 +787,14 @@ static gboolean _on_timeout(gpointer data)
|
|||||||
g_slist_free(main->apps);
|
g_slist_free(main->apps);
|
||||||
main->apps = NULL;
|
main->apps = NULL;
|
||||||
g_idle_add(_on_idle, main);
|
g_idle_add(_on_idle, main);
|
||||||
return ret;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean _timeout_path(Main * main, char const * path)
|
static void _timeout_path(Main * main, char const * path)
|
||||||
{
|
{
|
||||||
const char applications[] = "/applications";
|
|
||||||
char * p;
|
|
||||||
size_t len;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
len = strlen(path) + sizeof(applications);
|
if(stat(path, &st) != 0)
|
||||||
if((p = malloc(len)) == NULL)
|
return;
|
||||||
{
|
main->refresh = (st.st_mtime > main->refresh_mti) ? TRUE : FALSE;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user