74
75
gpointer user_data;
78
static void cached_dir_add_reference (CachedDir *dir);
79
static void cached_dir_remove_reference (CachedDir *dir);
77
80
static void cached_dir_free (CachedDir *dir);
78
81
static gboolean cached_dir_load_entries_recursive (CachedDir *dir,
79
82
const char *dirname);
267
cached_dir_add_keyfile_entry (CachedDir *dir,
275
entry = desktop_entry_new_from_keyfile (keyfile, group, path);
280
dirsplit = g_strsplit (group, "/", 2);
281
if (dirsplit[1] == NULL)
282
dir->entries = g_slist_prepend (dir->entries, entry);
286
subdir = find_subdir (dir, dirsplit[0]);
289
subdir = cached_dir_new(dirsplit[0]);
290
subdir->parent = dir;
291
dir->subdirs = g_slist_prepend (dir->subdirs, subdir);
294
subdir->entries = g_slist_prepend (subdir->entries, entry);
297
g_strfreev (dirsplit);
264
303
cached_dir_update_entry (CachedDir *dir,
265
304
const char *basename,
266
305
const char *path)
424
/* we explicitly don't invoke monitors of the parent since an
425
* event has been queued for it too */
429
emit_monitors_in_idle (void)
431
GSList *monitors_to_emit;
434
monitors_to_emit = pending_monitors_dirs;
436
pending_monitors_dirs = NULL;
437
monitors_idle_handler = 0;
439
tmp = monitors_to_emit;
442
CachedDir *dir = tmp->data;
444
cached_dir_invoke_monitors (dir);
445
cached_dir_remove_reference (dir);
450
g_slist_free (monitors_to_emit);
456
cached_dir_queue_monitor_event (CachedDir *dir)
460
tmp = pending_monitors_dirs;
463
CachedDir *d = tmp->data;
464
GSList *next = tmp->next;
466
if (dir->parent == d->parent &&
467
g_strcmp0 (dir->name, d->name) == 0)
473
/* not found, so let's queue it */
476
cached_dir_add_reference (dir);
477
pending_monitors_dirs = g_slist_append (pending_monitors_dirs, dir);
384
cached_dir_invoke_monitors (dir->parent);
482
cached_dir_queue_monitor_event (dir->parent);
485
if (monitors_idle_handler == 0)
487
monitors_idle_handler = g_idle_add ((GSourceFunc) emit_monitors_in_idle, NULL);
581
cached_dir_load_entries_from_cache_file (CachedDir *dir,
584
gchar cache_file[PATH_MAX];
590
/* ignore cache if we have $LANGUAGE */
591
locale = g_getenv ("LANGUAGE");
592
if (locale != NULL && *locale != '\0')
594
menu_verbose ("cached_dir_load_entries_from_cache_file(): $LANGUAGE present, not using cache\n");
598
locale = g_strdup (setlocale (LC_MESSAGES, NULL));
601
menu_verbose ("cached_dir_load_entries_from_cache_file(): setlocale() failed, aborting\n");
605
/* canonicalize .UTF-8 to .utf8 (only happens at end of string) */
606
s = strstr (locale, ".UTF-8");
610
g_snprintf (cache_file, sizeof(cache_file), "%s/desktop.%s.cache", dirname, locale);
613
menu_verbose ("Attempting to read entries from cache file %s\n",
616
kf = g_key_file_new ();
617
if (!g_key_file_load_from_file (kf, cache_file, G_KEY_FILE_NONE, NULL))
620
names = g_key_file_get_groups(kf, NULL);
621
for (i = names; *i != NULL; ++i)
622
cached_dir_add_keyfile_entry (dir, kf, *i, dirname);
625
g_key_file_free (kf);
478
631
cached_dir_load_entries_recursive (CachedDir *dir,
479
632
const char *dirname)
491
644
menu_verbose ("Attempting to read entries from %s (full path %s)\n",
492
645
dir->name, dirname);
647
if (cached_dir_load_entries_from_cache_file (dir, dirname))
649
menu_verbose ("Got from file cache\n");
650
cached_dir_ensure_monitor (dir, dirname);
651
dir->have_read_entries = TRUE;
494
655
dp = opendir (dirname);