[gimp] app: support invoking file procs that handle URIs directly
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: support invoking file procs that handle URIs directly
- Date: Sat, 17 Nov 2012 20:22:56 +0000 (UTC)
commit 1bf8eef14f7678f77bd905cc1133d0fdf181ce4f
Author: Michael Natterer <mitch gimp org>
Date: Sat Nov 17 21:21:32 2012 +0100
app: support invoking file procs that handle URIs directly
*not* via the file-uri plug-in.
app/file/file-open.c | 6 +++++
app/file/file-procedure.c | 55 +++++++++++++++++++++++++++++++-------------
app/file/file-save.c | 6 +++++
3 files changed, 51 insertions(+), 16 deletions(-)
---
diff --git a/app/file/file-open.c b/app/file/file-open.c
index 7c764e2..82a215a 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -147,6 +147,12 @@ file_open_image (Gimp *gimp,
return NULL;
}
}
+
+ if (file_proc->handles_uri)
+ {
+ g_free (filename);
+ filename = g_strdup (uri);
+ }
}
else
{
diff --git a/app/file/file-procedure.c b/app/file/file-procedure.c
index a09fa37..fe08332 100644
--- a/app/file/file-procedure.c
+++ b/app/file/file-procedure.c
@@ -64,7 +64,8 @@ static GimpPlugInProcedure * file_proc_find_by_prefix (GSList *procs,
gboolean skip_magic);
static GimpPlugInProcedure * file_proc_find_by_extension (GSList *procs,
const gchar *uri,
- gboolean skip_magic);
+ gboolean skip_magic,
+ gboolean uri_procs_only);
static GimpPlugInProcedure * file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic);
@@ -93,15 +94,29 @@ file_procedure_find (GSList *procs,
GError **error)
{
GimpPlugInProcedure *file_proc;
- GSList *all_procs = procs;
gchar *filename;
g_return_val_if_fail (procs != NULL, NULL);
g_return_val_if_fail (uri != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- /* First, check magicless prefixes/suffixes */
- file_proc = file_proc_find_by_name (all_procs, uri, TRUE);
+ /* First, check magicless prefixes/suffixes: */
+
+ if (! file_proc_find_by_extension (procs, uri, FALSE, TRUE))
+ {
+ /* If there is not any (with or without magic) file proc that
+ * can load the URI by extension directly, try to find a proc
+ * that can load the prefix
+ */
+ file_proc = file_proc_find_by_prefix (procs, uri, TRUE);
+ }
+ else
+ {
+ /* Otherwise try to find a magicless file proc that handles the
+ * extension
+ */
+ file_proc = file_proc_find_by_extension (procs, uri, TRUE, FALSE);
+ }
if (file_proc)
return file_proc;
@@ -111,6 +126,7 @@ file_procedure_find (GSList *procs,
/* Then look for magics */
if (filename)
{
+ GSList *list;
GimpPlugInProcedure *size_matched_proc = NULL;
FILE *ifp = NULL;
gboolean opened = FALSE;
@@ -118,10 +134,9 @@ file_procedure_find (GSList *procs,
gint size_match_count = 0;
guchar head[256];
- while (procs)
+ for (list = procs; list; list = g_slist_next (list))
{
file_proc = procs->data;
- procs = procs->next;
if (file_proc->magics_list)
{
@@ -179,8 +194,8 @@ file_procedure_find (GSList *procs,
return size_matched_proc;
}
- /* As a last resort, try matching by name */
- file_proc = file_proc_find_by_name (all_procs, uri, FALSE);
+ /* As a last resort, try matching by name, not skipping magic procs */
+ file_proc = file_proc_find_by_name (procs, uri, FALSE);
if (file_proc)
{
@@ -213,7 +228,7 @@ file_procedure_find_by_extension (GSList *procs,
{
g_return_val_if_fail (uri != NULL, NULL);
- return file_proc_find_by_extension (procs, uri, FALSE);
+ return file_proc_find_by_extension (procs, uri, FALSE, FALSE);
}
gboolean
@@ -285,23 +300,29 @@ file_proc_find_by_prefix (GSList *procs,
static GimpPlugInProcedure *
file_proc_find_by_extension (GSList *procs,
const gchar *uri,
- gboolean skip_magic)
+ gboolean skip_magic,
+ gboolean uri_procs_only)
{
GSList *p;
const gchar *ext;
ext = strrchr (uri, '.');
- if (ext)
- ext++;
+ if (! ext)
+ return NULL;
+
+ ext++;
for (p = procs; p; p = g_slist_next (p))
{
GimpPlugInProcedure *proc = p->data;
GSList *extensions;
+ if (uri_procs_only && ! proc->handles_uri)
+ continue;
+
for (extensions = proc->extensions_list;
- ext && extensions;
+ extensions;
extensions = g_slist_next (extensions))
{
const gchar *p1 = ext;
@@ -334,15 +355,17 @@ file_proc_find_by_name (GSList *procs,
{
GimpPlugInProcedure *proc;
- proc = file_proc_find_by_prefix (procs, uri, skip_magic);
+ proc = file_proc_find_by_extension (procs, uri, skip_magic, TRUE);
if (! proc)
- proc = file_proc_find_by_extension (procs, uri, skip_magic);
+ proc = file_proc_find_by_prefix (procs, uri, skip_magic);
+
+ if (! proc)
+ proc = file_proc_find_by_extension (procs, uri, skip_magic, FALSE);
return proc;
}
-
static void
file_convert_string (const gchar *instr,
gchar *outmem,
diff --git a/app/file/file-save.c b/app/file/file-save.c
index 7336ffd..3e06700 100644
--- a/app/file/file-save.c
+++ b/app/file/file-save.c
@@ -127,6 +127,12 @@ file_save (Gimp *gimp,
goto out;
}
}
+
+ if (file_proc->handles_uri)
+ {
+ g_free (filename);
+ filename = g_strdup (uri);
+ }
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]