From 49b8176aa50e5d340f8a7ece9fc4053b143f116f Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 17 Apr 2007 15:54:01 +0000 Subject: [PATCH] Allow other applications to open images in GIMP as if they were new images 2007-04-17 Sven Neumann Allow other applications to open images in GIMP as if they were new images (without associating a filename). Fixes bug #423118. * app/file/file-open.[ch]: added parameter 'as_new' to file_open_image() and its variants. * app/actions/data-commands.c * app/actions/documents-commands.c * app/actions/file-commands.c * app/core/gimpimagefile.c * app/dialogs/file-open-dialog.c * app/dialogs/file-open-location-dialog.c * app/widgets/gimptoolbox.c * app/widgets/gimptoolbox-dnd.c: changed accordingly. * app/app.[ch] * app/main.c: added new command-line option '--as-new'. * app/widgets/gimpdbusservice.[ch] * app/widgets/dbus-service.xml: added new method "OpenAsNew" to the D-Bus interface. * docs/gimp.1.in: document the new command-line option. svn path=/trunk/; revision=22264 --- ChangeLog | 26 ++++++++++ app/actions/data-commands.c | 3 +- app/actions/documents-commands.c | 4 +- app/actions/file-commands.c | 4 +- app/app.c | 3 +- app/app.h | 1 + app/core/gimpimagefile.c | 5 +- app/dialogs/file-open-dialog.c | 6 +-- app/dialogs/file-open-location-dialog.c | 2 +- app/file/file-open.c | 64 +++++++++++++++---------- app/file/file-open.h | 6 ++- app/main.c | 16 +++++-- app/widgets/dbus-service.xml | 4 ++ app/widgets/gimpdbusservice.c | 17 ++++++- app/widgets/gimpdbusservice.h | 4 ++ app/widgets/gimptoolbox-dnd.c | 2 +- app/widgets/gimptoolbox.c | 2 +- docs/gimp.1.in | 12 +++-- 18 files changed, 132 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9531e76844..f96da146cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2007-04-17 Sven Neumann + + Allow other applications to open images in GIMP as if they were + new images (without associating a filename). Fixes bug #423118. + + * app/file/file-open.[ch]: added parameter 'as_new' to + file_open_image() and its variants. + + * app/actions/data-commands.c + * app/actions/documents-commands.c + * app/actions/file-commands.c + * app/core/gimpimagefile.c + * app/dialogs/file-open-dialog.c + * app/dialogs/file-open-location-dialog.c + * app/widgets/gimptoolbox.c + * app/widgets/gimptoolbox-dnd.c: changed accordingly. + + * app/app.[ch] + * app/main.c: added new command-line option '--as-new'. + + * app/widgets/gimpdbusservice.[ch] + * app/widgets/dbus-service.xml: added new method "OpenAsNew" to the + D-Bus interface. + + * docs/gimp.1.in: document the new command-line option. + 2007-04-17 Sven Neumann * plug-ins/script-fu/scripts/neon-logo.scm: applied slightly diff --git a/app/actions/data-commands.c b/app/actions/data-commands.c index d24dfd6e72..430fcdc483 100644 --- a/app/actions/data-commands.c +++ b/app/actions/data-commands.c @@ -92,7 +92,8 @@ data_open_as_image_cmd_callback (GtkAction *action, GimpPDBStatusType status; GError *error = NULL; - image = file_open_with_display (context->gimp, context, NULL, uri, + image = file_open_with_display (context->gimp, context, NULL, + uri, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) diff --git a/app/actions/documents-commands.c b/app/actions/documents-commands.c index 245a91960b..262a3f5b0f 100644 --- a/app/actions/documents-commands.c +++ b/app/actions/documents-commands.c @@ -309,8 +309,8 @@ documents_open_image (GimpContext *context, uri = gimp_object_get_name (GIMP_OBJECT (imagefile)); - image = file_open_with_display (context->gimp, context, NULL, - uri, &status, &error); + image = file_open_with_display (context->gimp, context, NULL, uri, FALSE, + &status, &error); if (! image && status != GIMP_PDB_CANCEL) { diff --git a/app/actions/file-commands.c b/app/actions/file-commands.c index bb5097da50..3036402a7c 100644 --- a/app/actions/file-commands.c +++ b/app/actions/file-commands.c @@ -157,7 +157,7 @@ file_last_opened_cmd_callback (GtkAction *action, image = file_open_with_display (gimp, action_data_get_context (data), NULL, - GIMP_OBJECT (imagefile)->name, + GIMP_OBJECT (imagefile)->name, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) @@ -566,7 +566,7 @@ file_revert_confirm_response (GtkWidget *dialog, new_image = file_open_image (gimp, gimp_get_user_context (gimp), GIMP_PROGRESS (display), - uri, uri, NULL, + uri, uri, FALSE, NULL, GIMP_RUN_INTERACTIVE, &status, NULL, &error); diff --git a/app/app.c b/app/app.c index 0a0504759e..ece089c0f4 100644 --- a/app/app.c +++ b/app/app.c @@ -121,6 +121,7 @@ app_run (const gchar *full_prog_name, const gchar *session_name, const gchar *batch_interpreter, const gchar **batch_commands, + gboolean as_new, gboolean no_interface, gboolean no_data, gboolean no_fonts, @@ -224,7 +225,7 @@ app_run (const gchar *full_prog_name, gint i; for (i = 0; filenames[i] != NULL; i++) - file_open_from_command_line (gimp, filenames[i]); + file_open_from_command_line (gimp, filenames[i], as_new); } #ifndef GIMP_CONSOLE_COMPILATION diff --git a/app/app.h b/app/app.h index a35cb14deb..dd9b458a26 100644 --- a/app/app.h +++ b/app/app.h @@ -38,6 +38,7 @@ void app_run (const gchar *full_prog_name, const gchar *session_name, const gchar *batch_interpreter, const gchar **batch_commands, + gboolean as_new, gboolean no_interface, gboolean no_data, gboolean no_fonts, diff --git a/app/core/gimpimagefile.c b/app/core/gimpimagefile.c index 0130e3c44d..38a92bea90 100644 --- a/app/core/gimpimagefile.c +++ b/app/core/gimpimagefile.c @@ -261,8 +261,9 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile, GimpPDBStatusType status; image = file_open_image (imagefile->gimp, context, progress, - thumbnail->image_uri, thumbnail->image_uri, - NULL, GIMP_RUN_NONINTERACTIVE, + thumbnail->image_uri, + thumbnail->image_uri, + FALSE, NULL, GIMP_RUN_NONINTERACTIVE, &status, &mime_type, NULL); if (image) diff --git a/app/dialogs/file-open-dialog.c b/app/dialogs/file-open-dialog.c index 225e9a59e1..5e5ce54874 100644 --- a/app/dialogs/file-open-dialog.c +++ b/app/dialogs/file-open-dialog.c @@ -187,11 +187,9 @@ file_open_dialog_open_image (GtkWidget *open_dialog, image = file_open_with_proc_and_display (gimp, gimp_get_user_context (gimp), GIMP_PROGRESS (open_dialog), - uri, - entered_filename, + uri, entered_filename, FALSE, load_proc, - &status, - &error); + &status, &error); if (image) { diff --git a/app/dialogs/file-open-location-dialog.c b/app/dialogs/file-open-location-dialog.c index c43aa6e355..df86d6c417 100644 --- a/app/dialogs/file-open-location-dialog.c +++ b/app/dialogs/file-open-location-dialog.c @@ -202,7 +202,7 @@ file_open_location_response (GtkDialog *dialog, image = file_open_with_proc_and_display (gimp, gimp_get_user_context (gimp), GIMP_PROGRESS (box), - uri, text, NULL, + uri, text, FALSE, NULL, &status, &error); if (image == NULL && status != GIMP_PDB_CANCEL) diff --git a/app/file/file-open.c b/app/file/file-open.c index ee2ed92ed9..65fa2e3230 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -70,7 +70,8 @@ #include "gimp-intl.h" -static void file_open_sanitize_image (GimpImage *image); +static void file_open_sanitize_image (GimpImage *image, + gboolean as_new); static void file_open_handle_color_profile (GimpImage *image, GimpContext *context, GimpProgress *progress, @@ -85,6 +86,7 @@ file_open_image (Gimp *gimp, GimpProgress *progress, const gchar *uri, const gchar *entered_filename, + gboolean as_new, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, GimpPDBStatusType *status, @@ -158,7 +160,7 @@ file_open_image (Gimp *gimp, if (image) { - file_open_sanitize_image (image); + file_open_sanitize_image (image, as_new); if (mime_type) *mime_type = file_proc->mime_type; @@ -255,7 +257,7 @@ file_open_thumbnail (Gimp *gimp, if (image) { - file_open_sanitize_image (image); + file_open_sanitize_image (image, FALSE); *mime_type = file_proc->mime_type; @@ -279,11 +281,13 @@ file_open_with_display (Gimp *gimp, GimpContext *context, GimpProgress *progress, const gchar *uri, + gboolean as_new, GimpPDBStatusType *status, GError **error) { return file_open_with_proc_and_display (gimp, context, progress, - uri, uri, NULL, status, error); + uri, uri, as_new, NULL, + status, error); } GimpImage * @@ -292,6 +296,7 @@ file_open_with_proc_and_display (Gimp *gimp, GimpProgress *progress, const gchar *uri, const gchar *entered_filename, + gboolean as_new, GimpPlugInProcedure *file_proc, GimpPDBStatusType *status, GError **error) @@ -307,6 +312,7 @@ file_open_with_proc_and_display (Gimp *gimp, image = file_open_image (gimp, context, progress, uri, entered_filename, + as_new, file_proc, GIMP_RUN_INTERACTIVE, status, @@ -315,27 +321,30 @@ file_open_with_proc_and_display (Gimp *gimp, if (image) { - GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents); - GimpImagefile *imagefile; - gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0); - imagefile = gimp_document_list_add_uri (documents, uri, mime_type); - - /* can only create a thumbnail if the passed uri and the - * resulting image's uri match. - */ - if (strcmp (uri, gimp_image_get_uri (image)) == 0) + if (! as_new) { - /* no need to save a thumbnail if there's a good one already */ - if (! gimp_imagefile_check_thumbnail (imagefile)) - { - gimp_imagefile_save_thumbnail (imagefile, mime_type, image); - } - } + GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents); + GimpImagefile *imagefile; - if (gimp->config->save_document_history) - gimp_recent_list_add_uri (uri, mime_type); + imagefile = gimp_document_list_add_uri (documents, uri, mime_type); + + /* can only create a thumbnail if the passed uri and the + * resulting image's uri match. + */ + if (strcmp (uri, gimp_image_get_uri (image)) == 0) + { + /* no need to save a thumbnail if there's a good one already */ + if (! gimp_imagefile_check_thumbnail (imagefile)) + { + gimp_imagefile_save_thumbnail (imagefile, mime_type, image); + } + } + + if (gimp->config->save_document_history) + gimp_recent_list_add_uri (uri, mime_type); + } /* the display owns the image now */ g_object_unref (image); @@ -369,7 +378,7 @@ file_open_layers (Gimp *gimp, g_return_val_if_fail (error == NULL || *error == NULL, NULL); new_image = file_open_image (gimp, context, progress, - uri, uri, + uri, uri, FALSE, file_proc, run_mode, status, &mime_type, error); @@ -464,7 +473,8 @@ file_open_layers (Gimp *gimp, */ gboolean file_open_from_command_line (Gimp *gimp, - const gchar *filename) + const gchar *filename, + gboolean as_new) { GError *error = NULL; gchar *uri; @@ -484,7 +494,7 @@ file_open_from_command_line (Gimp *gimp, image = file_open_with_display (gimp, gimp_get_user_context (gimp), NULL, - uri, + uri, as_new, &status, &error); if (image) @@ -517,8 +527,12 @@ file_open_from_command_line (Gimp *gimp, /* private functions */ static void -file_open_sanitize_image (GimpImage *image) +file_open_sanitize_image (GimpImage *image, + gboolean as_new) { + if (as_new) + gimp_object_set_name (GIMP_OBJECT (image), NULL); + /* clear all undo steps */ gimp_image_undo_free (image); diff --git a/app/file/file-open.h b/app/file/file-open.h index 42c6baee47..1dcfbd08ac 100644 --- a/app/file/file-open.h +++ b/app/file/file-open.h @@ -27,6 +27,7 @@ GimpImage * file_open_image (Gimp *gimp, GimpProgress *progress, const gchar *uri, const gchar *entered_filename, + gboolean as_new, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, GimpPDBStatusType *status, @@ -45,6 +46,7 @@ GimpImage * file_open_with_display (Gimp *gimp, GimpContext *context, GimpProgress *progress, const gchar *uri, + gboolean as_new, GimpPDBStatusType *status, GError **error); @@ -53,6 +55,7 @@ GimpImage * file_open_with_proc_and_display (Gimp *gimp, GimpProgress *progress, const gchar *uri, const gchar *entered_filename, + gboolean as_new, GimpPlugInProcedure *file_proc, GimpPDBStatusType *status, GError **error); @@ -69,7 +72,8 @@ GList * file_open_layers (Gimp *gimp, GError **error); gboolean file_open_from_command_line (Gimp *gimp, - const gchar *filename); + const gchar *filename, + gboolean as_new); #endif /* __FILE_OPEN_H__ */ diff --git a/app/main.c b/app/main.c index 76c8677df0..571e5fc9cf 100644 --- a/app/main.c +++ b/app/main.c @@ -106,6 +106,7 @@ static void gimp_open_console_window (void); #endif static gboolean gimp_dbus_open (const gchar **filenames, + gboolean as_new, gboolean be_verbose); @@ -115,6 +116,7 @@ static const gchar *session_name = NULL; static const gchar *batch_interpreter = NULL; static const gchar **batch_commands = NULL; static const gchar **filenames = NULL; +static gboolean as_new = FALSE; static gboolean no_interface = FALSE; static gboolean no_data = FALSE; static gboolean no_fonts = FALSE; @@ -160,6 +162,11 @@ static const GOptionEntry main_entries[] = G_OPTION_ARG_NONE, &new_instance, N_("Start a new GIMP instance"), NULL }, + { + "as-new", 'a', 0, + G_OPTION_ARG_NONE, &as_new, + N_("Open images as new"), NULL + }, { "no-interface", 'i', 0, G_OPTION_ARG_NONE, &no_interface, @@ -362,7 +369,7 @@ main (int argc, if (! new_instance) { - if (gimp_dbus_open (filenames, be_verbose)) + if (gimp_dbus_open (filenames, as_new, be_verbose)) return EXIT_SUCCESS; } @@ -379,6 +386,7 @@ main (int argc, session_name, batch_interpreter, batch_commands, + as_new, no_interface, no_data, no_fonts, @@ -681,6 +689,7 @@ gimp_sigfatal_handler (gint sig_num) static gboolean gimp_dbus_open (const gchar **filenames, + gboolean as_new, gboolean be_verbose) { #ifndef GIMP_CONSOLE_COMPILATION @@ -700,13 +709,14 @@ gimp_dbus_open (const gchar **filenames, if (filenames) { - gint i; + const gchar *method = as_new ? "OpenAsNew" : "Open"; + gint i; for (i = 0, success = TRUE; filenames[i] && success; i++) { gboolean retval; /* ignored */ - success = dbus_g_proxy_call (proxy, "Open", &error, + success = dbus_g_proxy_call (proxy, method, &error, G_TYPE_STRING, filenames[i], G_TYPE_INVALID, G_TYPE_BOOLEAN, &retval, diff --git a/app/widgets/dbus-service.xml b/app/widgets/dbus-service.xml index 2ca4ce7c3b..4d1697d9c7 100644 --- a/app/widgets/dbus-service.xml +++ b/app/widgets/dbus-service.xml @@ -9,6 +9,10 @@ + + + + diff --git a/app/widgets/gimpdbusservice.c b/app/widgets/gimpdbusservice.c index 3e5b193cef..b734922834 100644 --- a/app/widgets/gimpdbusservice.c +++ b/app/widgets/gimpdbusservice.c @@ -78,7 +78,22 @@ gimp_dbus_service_open (GimpDBusService *service, g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (success != NULL, FALSE); - *success = file_open_from_command_line (service->gimp, filename); + *success = file_open_from_command_line (service->gimp, filename, FALSE); + + return TRUE; +} + +gboolean +gimp_dbus_service_open_as_new (GimpDBusService *service, + const gchar *filename, + gboolean *success, + GError **dbus_error) +{ + g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (success != NULL, FALSE); + + *success = file_open_from_command_line (service->gimp, filename, TRUE); return TRUE; } diff --git a/app/widgets/gimpdbusservice.h b/app/widgets/gimpdbusservice.h index 847e552502..cb95055e7a 100644 --- a/app/widgets/gimpdbusservice.h +++ b/app/widgets/gimpdbusservice.h @@ -62,6 +62,10 @@ gboolean gimp_dbus_service_open (GimpDBusService *service, const gchar *filename, gboolean *success, GError **dbus_error); +gboolean gimp_dbus_service_open_as_new (GimpDBusService *service, + const gchar *filename, + gboolean *success, + GError **dbus_error); gboolean gimp_dbus_service_activate (GimpDBusService *service, GError **dbus_error); diff --git a/app/widgets/gimptoolbox-dnd.c b/app/widgets/gimptoolbox-dnd.c index d865c7b4b7..0a053e2633 100644 --- a/app/widgets/gimptoolbox-dnd.c +++ b/app/widgets/gimptoolbox-dnd.c @@ -148,7 +148,7 @@ gimp_toolbox_drop_uri_list (GtkWidget *widget, GError *error = NULL; image = file_open_with_display (context->gimp, context, NULL, - uri, &status, &error); + uri, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) { diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c index c9e4776bdf..60ff5ab924 100644 --- a/app/widgets/gimptoolbox.c +++ b/app/widgets/gimptoolbox.c @@ -902,7 +902,7 @@ toolbox_paste_received (GtkClipboard *clipboard, GError *error = NULL; image = file_open_with_display (context->gimp, context, NULL, - copy, &status, &error); + copy, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) { diff --git a/docs/gimp.1.in b/docs/gimp.1.in index a77e870a5c..eb106c513b 100644 --- a/docs/gimp.1.in +++ b/docs/gimp.1.in @@ -7,7 +7,7 @@ gimp - an image manipulation and paint program. .SH SYNOPSIS .B gimp [\-h] [\-\-help] [\-\-help-all] [\-\-help-gtk] [-v] [\-\-version] -[\-\-license] [\-\-verbose] [\-n] [\-\-new\-instance] +[\-\-license] [\-\-verbose] [\-n] [\-\-new\-instance] [\-a] [\-\-as\-new] [\-i] [\-\-no\-interface] [\-d] [\-\-no\-data] [\-f] [\-\-no\-fonts] [\-s] [\-\-no\-splash] [\-\-no\-shm] [\-\-no\-cpu\-accel] [\-\-display \fIdisplay\fP] [\-\-session \fI\fP] @@ -69,13 +69,17 @@ Output license information and exit. .B \-\-verbose Be verbose and create information on standard output. .TP 8 -.B \-i, \-\-no\-interface -Run without a user interface. -.TP 8 .B \-n, \-\-new\-instance Do not attempt to reuse an already running GIMP instance. Always start a new one. .TP 8 +.B \-a, \-\-as\-new +Open filenames passed on the command-line as new images, don't set the +filename on them. +.TP 8 +.B \-i, \-\-no\-interface +Run without a user interface. +.TP 8 .B \-d, \-\-no\-data Do not load patterns, gradients, palettes, or brushes. Often useful in non-interactive situations where startup time is to be minimized.