+ if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */
+
+ key_file = g_key_file_new();
+ if (!g_key_file_load_from_file(key_file, path, 0, NULL))
+ {
+ g_key_file_free(key_file);
+ return FALSE;
+ }
+
+ editor = g_new0(EditorDescription, 1);
+
+ editor->key = g_strdup(key);
+ editor->file = g_strdup(path);
+
+ g_hash_table_insert(editors, editor->key, editor);
+
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Hidden", NULL)) editor->hidden = TRUE;
+
+ categories = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "Categories", NULL, NULL);
+ if (categories)
+ {
+ gboolean found = FALSE;
+ gint i;
+ for (i = 0; categories[i]; i++)
+ /* IMHO "Graphics" is exactly the category that we are interested in, so this does not have to be configurable */
+ if (strcmp(categories[i], "Graphics") == 0 ||
+ strcmp(categories[i], "X-Geeqie") == 0)
+ {
+ found = TRUE;
+ break;
+ }
+ if (!found) editor->hidden = TRUE;
+ g_strfreev(categories);
+ }
+ else
+ {
+ editor->hidden = TRUE;
+ }
+
+ only_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "OnlyShowIn", NULL, NULL);
+ if (only_show_in)
+ {
+ gboolean found = FALSE;
+ gint i;
+ for (i = 0; only_show_in[i]; i++)
+ if (strcmp(only_show_in[i], "X-Geeqie") == 0)
+ {
+ found = TRUE;
+ break;
+ }
+ if (!found) editor->hidden = TRUE;
+ g_strfreev(only_show_in);
+ }
+
+ not_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "NotShowIn", NULL, NULL);
+ if (not_show_in)
+ {
+ gboolean found = FALSE;
+ gint i;
+ for (i = 0; not_show_in[i]; i++)
+ if (strcmp(not_show_in[i], "X-Geeqie") == 0)
+ {
+ found = TRUE;
+ break;
+ }
+ if (found) editor->hidden = TRUE;
+ g_strfreev(not_show_in);
+ }
+
+ if (editor->hidden)
+ {
+ /* hidden editors will be deleted, no need to parse the rest */
+ g_key_file_free(key_file);
+ return TRUE;
+ }
+
+ editor->name = g_key_file_get_locale_string(key_file, DESKTOP_GROUP, "Name", NULL, NULL);
+ editor->icon = g_key_file_get_string(key_file, DESKTOP_GROUP, "Icon", NULL);
+
+ editor->exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "Exec", NULL);
+
+ /* we take only editors that accept parameters, FIXME: the test can be improved */
+ if (!strchr(editor->exec, '%')) editor->hidden = TRUE;
+
+ editor->menu_path = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Menu-Path", NULL);
+ if (!editor->menu_path) editor->menu_path = g_strdup("EditMenu/ExternalMenu");
+
+ editor->hotkey = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Hotkey", NULL);
+
+ extensions = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-File-Extensions", NULL);
+ if (extensions)
+ editor->ext_list = filter_to_list(extensions);
+ else
+ {
+ gchar **mime_types = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "MimeType", NULL, NULL);
+ if (mime_types)
+ {
+ editor->ext_list = editor_mime_types_to_extensions(mime_types);
+ g_strfreev(mime_types);
+ if (!editor->ext_list) editor->hidden = TRUE;
+ }
+
+ }
+
+
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Keep-Fullscreen", NULL)) editor->flags |= EDITOR_KEEP_FS;
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose", NULL)) editor->flags |= EDITOR_VERBOSE;
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose-Multi", NULL)) editor->flags |= EDITOR_VERBOSE_MULTI;
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Filter", NULL)) editor->flags |= EDITOR_DEST;
+ if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Terminal", NULL)) editor->flags |= EDITOR_TERMINAL;
+
+
+ editor->flags |= editor_command_parse(editor, NULL, NULL);
+ g_key_file_free(key_file);
+
+ return TRUE;
+}
+
+static gboolean editor_remove_desktop_file_cb(gpointer key, gpointer value, gpointer user_data)
+{
+ EditorDescription *editor = value;
+ return editor->hidden;
+}
+
+static void editor_read_desktop_dir(const gchar *path)
+{
+ DIR *dp;
+ struct dirent *dir;
+ gchar *pathl;
+
+ pathl = path_from_utf8(path);
+ dp = opendir(pathl);
+ g_free(pathl);
+ if (!dp)
+ {
+ /* dir not found */
+ return;
+ }
+ while ((dir = readdir(dp)) != NULL)
+ {
+ gchar *namel = dir->d_name;
+ size_t len = strlen(namel);
+
+ if (len > 8 && strncasecmp(namel + len - 8, ".desktop", 8) == 0)
+ {
+ gchar *name = path_to_utf8(namel);
+ gchar *dpath = g_build_filename(path, name, NULL);
+ editor_read_desktop_file(dpath);
+ g_free(dpath);
+ g_free(name);
+ }
+ }
+ closedir(dp);