/*
* Geeqie
* (C) 2006 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
#include "filedata.h"
#include "filefilter.h"
#include "misc.h"
+#include "pixbuf_util.h"
#include "ui_fileops.h"
#include "ui_spinner.h"
#include "ui_utildlg.h"
GHashTable *editors = NULL;
GtkListStore *desktop_file_list;
-
+gboolean editors_finished = FALSE;
#ifdef G_KEY_FILE_DESKTOP_GROUP
#define DESKTOP_GROUP G_KEY_FILE_DESKTOP_GROUP
{"image/x-xcf", ".xcf"},
{"image/x-xpixmap", ".xpm"},
{"image/x-x3f", ".x3f"},
+ {"application/x-ptoptimizer-script", ".pto"},
{NULL, NULL}};
gint i, j;
return list;
}
-static gboolean editor_read_desktop_file(const gchar *path)
+gboolean editor_read_desktop_file(const gchar *path)
{
GKeyFile *key_file;
EditorDescription *editor;
*ext = '\0';
}
}
+ if (editor->icon && !register_theme_icon_as_stock(editor->key, editor->icon))
+ {
+ g_free(editor->icon);
+ editor->icon = NULL;
+ }
editor->exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "Exec", NULL);
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);
+ editor->flags |= editor_command_parse(editor, NULL, FALSE, NULL);
if ((editor->flags & EDITOR_NO_PARAM) && !category_geeqie) editor->hidden = TRUE;
gtk_list_store_set(desktop_file_list, &iter,
DESKTOP_FILE_COLUMN_KEY, key,
DESKTOP_FILE_COLUMN_NAME, editor->name,
- DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden,
+ DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden ? _("yes") : _("no"),
DESKTOP_FILE_COLUMN_WRITABLE, access_file(path, W_OK),
DESKTOP_FILE_COLUMN_PATH, path, -1);
return editor->hidden || editor->ignored;
}
-static void editor_read_desktop_dir(const gchar *path)
+void editor_table_finish(void)
+{
+ g_hash_table_foreach_remove(editors, editor_remove_desktop_file_cb, NULL);
+ editors_finished = TRUE;
+}
+
+void editor_table_clear(void)
+{
+ if (desktop_file_list)
+ {
+ gtk_list_store_clear(desktop_file_list);
+ }
+ else
+ {
+ desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
+ }
+ if (editors)
+ {
+ g_hash_table_destroy(editors);
+ }
+ editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free);
+ editors_finished = FALSE;
+}
+
+static GList *editor_add_desktop_dir(GList *list, const gchar *path)
{
DIR *dp;
struct dirent *dir;
if (!dp)
{
/* dir not found */
- return;
+ return list;
}
while ((dir = readdir(dp)) != NULL)
{
{
gchar *name = path_to_utf8(namel);
gchar *dpath = g_build_filename(path, name, NULL);
- editor_read_desktop_file(dpath);
- g_free(dpath);
+ list = g_list_prepend(list, dpath);
g_free(name);
}
}
closedir(dp);
+ return list;
}
-void editor_load_descriptions(void)
+GList *editor_get_desktop_files(void)
{
gchar *path;
gchar *xdg_data_dirs;
gchar *all_dirs;
gchar **split_dirs;
gint i;
+ GList *list = NULL;
- if (desktop_file_list)
- {
- gtk_list_store_clear(desktop_file_list);
- }
- else
- {
- desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING);
- }
- if (editors)
- {
- g_hash_table_destroy(editors);
- }
- editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free);
-
xdg_data_dirs = getenv("XDG_DATA_DIRS");
if (xdg_data_dirs && xdg_data_dirs[0])
xdg_data_dirs = path_to_utf8(xdg_data_dirs);
g_free(all_dirs);
- for (i = 0; split_dirs[i]; i++)
+ for (i = 0; split_dirs[i]; i++);
+ for (--i; i >= 0; i--)
{
path = g_build_filename(split_dirs[i], "applications", NULL);
- editor_read_desktop_dir(path);
+ list = editor_add_desktop_dir(list, path);
g_free(path);
}
g_strfreev(split_dirs);
-
- g_hash_table_foreach_remove(editors, editor_remove_desktop_file_cb, NULL);
+ return list;
}
static void editor_list_add_cb(gpointer key, gpointer value, gpointer data)
GList *editor_list_get(void)
{
GList *editors_list = NULL;
+
+ if (!editors_finished) return NULL;
+
g_hash_table_foreach(editors, editor_list_add_cb, &editors_list);
editors_list = g_list_sort(editors_list, editor_sort);
} PathType;
-static gchar *editor_command_path_parse(const FileData *fd, PathType type, const EditorDescription *editor)
+static gchar *editor_command_path_parse(const FileData *fd, gboolean consider_sidecars, PathType type, const EditorDescription *editor)
{
GString *string;
gchar *pathl;
const gchar *p = NULL;
+ DEBUG_2("editor_command_path_parse: %s %d %d %s", fd->path, consider_sidecars, type, editor->key);
+
string = g_string_new("");
if (type == PATH_FILE || type == PATH_FILE_URL)
break;
}
- work2 = fd->sidecar_files;
+ work2 = consider_sidecars ? fd->sidecar_files : NULL;
while (work2)
{
FileData *sfd = work2->data;
g_free(pathl);
pathl = NULL;
}
-
+
+ DEBUG_2("editor_command_path_parse: return %s", pathl);
return pathl;
}
}
-EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gchar **output)
+EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gboolean consider_sidecars, gchar **output)
{
EditorFlags flags = 0;
const gchar *p;
gboolean single_quotes = FALSE;
gboolean double_quotes = FALSE;
+ DEBUG_2("editor_command_parse: %s %d %d", editor->key, consider_sidecars, !!output);
+
if (output)
result = g_string_new("");
goto err;
}
pathl = editor_command_path_parse((FileData *)list->data,
+ consider_sidecars,
(*p == 'f') ? PATH_FILE : PATH_FILE_URL,
editor);
+ if (!output)
+ {
+ /* just testing, check also the rest of the list (like with F and U)
+ any matching file is OK */
+ GList *work = list->next;
+
+ while (!pathl && work)
+ {
+ FileData *fd = work->data;
+ pathl = editor_command_path_parse(fd,
+ consider_sidecars,
+ (*p == 'f') ? PATH_FILE : PATH_FILE_URL,
+ editor);
+ work = work->next;
+ }
+ }
+
if (!pathl)
{
flags |= EDITOR_ERROR_NO_FILE;
while (work)
{
FileData *fd = work->data;
- pathl = editor_command_path_parse(fd, (*p == 'F') ? PATH_FILE : PATH_FILE_URL, editor);
+ pathl = editor_command_path_parse(fd, consider_sidecars, (*p == 'F') ? PATH_FILE : PATH_FILE_URL, editor);
if (pathl)
{
ok = TRUE;
ed->pid = -1;
ed->flags = editor->flags;
- ed->flags |= editor_command_parse(editor, list, &command);
+ ed->flags |= editor_command_parse(editor, list, TRUE, &command);
ok = !EDITOR_ERRORS(ed->flags);
{
EditorFlags error;
EditorDescription *editor;
- if (!key) return FALSE;
+ if (!key) return EDITOR_ERROR_EMPTY;
editor = g_hash_table_lookup(editors, key);
- if (!editor) return FALSE;
- if (!list && !(editor->flags & EDITOR_NO_PARAM)) return FALSE;
+ if (!editor) return EDITOR_ERROR_EMPTY;
+ if (!list && !(editor->flags & EDITOR_NO_PARAM)) return EDITOR_ERROR_NO_FILE;
- error = editor_command_start(editor, editor->name, list, working_directory, cb, data);
+ error = editor_command_parse(editor, list, TRUE, NULL);
+
+ if (EDITOR_ERRORS(error)) return error;
+
+ error |= editor_command_start(editor, editor->name, list, working_directory, cb, data);
if (EDITOR_ERRORS(error))
{
g_free(text);
}
- return error;
+ return EDITOR_ERRORS(error);
}
EditorFlags start_editor_from_filelist(const gchar *key, GList *list)