From 6414b2ea5d65a45faa9899fbd97af282cf6725a9 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 22 Jan 2007 21:39:57 +0000 Subject: [PATCH] added utility function that handles opening files passed on the 2007-01-22 Sven Neumann * app/file/file-open.[ch]: added utility function that handles opening files passed on the command-line. * app/app_procs.c * app/widgets/gimpdbusservice.c: use the new function instead of duplicating the code. svn path=/trunk/; revision=21759 --- ChangeLog | 9 ++++++ app/app_procs.c | 42 +-------------------------- app/file/file-open.c | 54 +++++++++++++++++++++++++++++++++++ app/file/file-open.h | 3 ++ app/widgets/gimpdbusservice.c | 31 ++++---------------- 5 files changed, 72 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index b38f0c2dfa..925b113631 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-01-22 Sven Neumann + + * app/file/file-open.[ch]: added utility function that handles + opening files passed on the command-line. + + * app/app_procs.c + * app/widgets/gimpdbusservice.c: use the new function instead of + duplicating the code. + 2007-01-22 Sven Neumann * libgimp/gimppixbuf.c (gimp_pixbuf_from_data): free the thumbnail diff --git a/app/app_procs.c b/app/app_procs.c index f0552aff34..eca4651ab1 100644 --- a/app/app_procs.c +++ b/app/app_procs.c @@ -45,7 +45,6 @@ #include "core/gimp-user-install.h" #include "file/file-open.h" -#include "file/file-utils.h" #ifndef GIMP_CONSOLE_COMPILATION #include "dialogs/user-install-dialog.h" @@ -254,46 +253,7 @@ app_run (const gchar *full_prog_name, /* Load the images given on the command-line. */ if (filenames) - { - for (i = 0; filenames[i]; i++) - { - GError *error = NULL; - gchar *uri; - - uri = file_utils_any_to_uri (gimp, filenames[i], &error); - - if (uri) - { - GimpImage *image; - GimpPDBStatusType status; - - image = file_open_with_display (gimp, - gimp_get_user_context (gimp), - NULL, - uri, - &status, &error); - - if (! image && status != GIMP_PDB_CANCEL) - { - gchar *filename = file_utils_uri_to_utf8_filename (uri); - - g_message (_("Opening '%s' failed: %s"), - filename, error->message); - g_clear_error (&error); - - g_free (filename); - } - - g_free (uri); - } - else - { - g_printerr ("conversion filename -> uri failed: %s\n", - error->message); - g_clear_error (&error); - } - } - } + file_open_from_command_line (gimp, filenames); #ifndef GIMP_CONSOLE_COMPILATION if (! no_interface) diff --git a/app/file/file-open.c b/app/file/file-open.c index e8f607d1b6..90a9c6896f 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -457,6 +457,60 @@ file_open_layers (Gimp *gimp, } +/* This function is called for filenames passed on the command-line + * or from the D-Bus service. + */ +void +file_open_from_command_line (Gimp *gimp, + const gchar **uris) +{ + gint i; + + g_return_if_fail (GIMP_IS_GIMP (gimp)); + g_return_if_fail (uris != NULL); + + for (i = 0; uris[i]; i++) + { + GError *error = NULL; + gchar *uri; + + /* we accept URIs and filenames */ + uri = file_utils_any_to_uri (gimp, uris[i], &error); + + if (uri) + { + GimpImage *image; + GimpPDBStatusType status; + + image = file_open_with_display (gimp, + gimp_get_user_context (gimp), + NULL, + uri, + &status, &error); + + if (! image && status != GIMP_PDB_CANCEL) + { + gchar *filename = file_utils_uri_to_utf8_filename (uri); + + g_message (_("Opening '%s' failed: %s"), + filename, error->message); + g_clear_error (&error); + + g_free (filename); + } + + g_free (uri); + } + else + { + g_printerr ("conversion filename -> uri failed: %s\n", + error->message); + g_clear_error (&error); + } + } +} + + /* private functions */ diff --git a/app/file/file-open.h b/app/file/file-open.h index c0ab2c35ec..e33d1966cc 100644 --- a/app/file/file-open.h +++ b/app/file/file-open.h @@ -68,5 +68,8 @@ GList * file_open_layers (Gimp *gimp, GimpPDBStatusType *status, GError **error); +void file_open_from_command_line (Gimp *gimp, + const gchar **uris); + #endif /* __FILE_OPEN_H__ */ diff --git a/app/widgets/gimpdbusservice.c b/app/widgets/gimpdbusservice.c index 6c2e1f8aa5..adc813d27f 100644 --- a/app/widgets/gimpdbusservice.c +++ b/app/widgets/gimpdbusservice.c @@ -30,7 +30,6 @@ #include "core/gimp.h" #include "file/file-open.h" -#include "file/file-utils.h" #include "gimpdbusservice.h" #include "gimpdbusservice-glue.h" @@ -72,37 +71,17 @@ gimp_dbus_service_new (Gimp *gimp) gboolean gimp_dbus_service_open (GimpDBusService *service, const gchar **uris, - GError **error) + GError **dbus_error) { - gint i; - g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE); - for (i = 0; uris[i]; i++) + if (uris && *uris) { - GimpImage *image; - gchar *uri; - GimpPDBStatusType status; - - /* the method is documented to take URIs but we also accept filenames */ - uri = file_utils_any_to_uri (service->gimp, uris[i], error); - if (! uri) - return FALSE; - - image = file_open_with_display (service->gimp, - gimp_get_user_context (service->gimp), - NULL, - uris[i], - &status, error); - g_free (uri); - - if (! image && status != GIMP_PDB_CANCEL) - return FALSE; + file_open_from_command_line (service->gimp, uris); } - - /* if no URI is passed, raise the toolbox */ - if (i == 0) + else { + /* if no URI is passed, raise the toolbox */ const GList *managers = gimp_ui_managers_from_name (""); if (managers)