Allow other applications to open images in GIMP as if they were new images

2007-04-17  Sven Neumann  <sven@gimp.org>

	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
This commit is contained in:
Sven Neumann 2007-04-17 15:54:01 +00:00 committed by Sven Neumann
parent ef339861d7
commit 49b8176aa5
18 changed files with 132 additions and 49 deletions

View File

@ -1,3 +1,29 @@
2007-04-17 Sven Neumann <sven@gimp.org>
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 <sven@gimp.org> 2007-04-17 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/neon-logo.scm: applied slightly * plug-ins/script-fu/scripts/neon-logo.scm: applied slightly

View File

@ -92,7 +92,8 @@ data_open_as_image_cmd_callback (GtkAction *action,
GimpPDBStatusType status; GimpPDBStatusType status;
GError *error = NULL; 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); &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)

View File

@ -309,8 +309,8 @@ documents_open_image (GimpContext *context,
uri = gimp_object_get_name (GIMP_OBJECT (imagefile)); uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
image = file_open_with_display (context->gimp, context, NULL, image = file_open_with_display (context->gimp, context, NULL, uri, FALSE,
uri, &status, &error); &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)
{ {

View File

@ -157,7 +157,7 @@ file_last_opened_cmd_callback (GtkAction *action,
image = file_open_with_display (gimp, action_data_get_context (data), image = file_open_with_display (gimp, action_data_get_context (data),
NULL, NULL,
GIMP_OBJECT (imagefile)->name, GIMP_OBJECT (imagefile)->name, FALSE,
&status, &error); &status, &error);
if (! image && status != GIMP_PDB_CANCEL) 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), new_image = file_open_image (gimp, gimp_get_user_context (gimp),
GIMP_PROGRESS (display), GIMP_PROGRESS (display),
uri, uri, NULL, uri, uri, FALSE, NULL,
GIMP_RUN_INTERACTIVE, GIMP_RUN_INTERACTIVE,
&status, NULL, &error); &status, NULL, &error);

View File

@ -121,6 +121,7 @@ app_run (const gchar *full_prog_name,
const gchar *session_name, const gchar *session_name,
const gchar *batch_interpreter, const gchar *batch_interpreter,
const gchar **batch_commands, const gchar **batch_commands,
gboolean as_new,
gboolean no_interface, gboolean no_interface,
gboolean no_data, gboolean no_data,
gboolean no_fonts, gboolean no_fonts,
@ -224,7 +225,7 @@ app_run (const gchar *full_prog_name,
gint i; gint i;
for (i = 0; filenames[i] != NULL; 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 #ifndef GIMP_CONSOLE_COMPILATION

View File

@ -38,6 +38,7 @@ void app_run (const gchar *full_prog_name,
const gchar *session_name, const gchar *session_name,
const gchar *batch_interpreter, const gchar *batch_interpreter,
const gchar **batch_commands, const gchar **batch_commands,
gboolean as_new,
gboolean no_interface, gboolean no_interface,
gboolean no_data, gboolean no_data,
gboolean no_fonts, gboolean no_fonts,

View File

@ -261,8 +261,9 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
GimpPDBStatusType status; GimpPDBStatusType status;
image = file_open_image (imagefile->gimp, context, progress, image = file_open_image (imagefile->gimp, context, progress,
thumbnail->image_uri, thumbnail->image_uri, thumbnail->image_uri,
NULL, GIMP_RUN_NONINTERACTIVE, thumbnail->image_uri,
FALSE, NULL, GIMP_RUN_NONINTERACTIVE,
&status, &mime_type, NULL); &status, &mime_type, NULL);
if (image) if (image)

View File

@ -187,11 +187,9 @@ file_open_dialog_open_image (GtkWidget *open_dialog,
image = file_open_with_proc_and_display (gimp, image = file_open_with_proc_and_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
GIMP_PROGRESS (open_dialog), GIMP_PROGRESS (open_dialog),
uri, uri, entered_filename, FALSE,
entered_filename,
load_proc, load_proc,
&status, &status, &error);
&error);
if (image) if (image)
{ {

View File

@ -202,7 +202,7 @@ file_open_location_response (GtkDialog *dialog,
image = file_open_with_proc_and_display (gimp, image = file_open_with_proc_and_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
GIMP_PROGRESS (box), GIMP_PROGRESS (box),
uri, text, NULL, uri, text, FALSE, NULL,
&status, &error); &status, &error);
if (image == NULL && status != GIMP_PDB_CANCEL) if (image == NULL && status != GIMP_PDB_CANCEL)

View File

@ -70,7 +70,8 @@
#include "gimp-intl.h" #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, static void file_open_handle_color_profile (GimpImage *image,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
@ -85,6 +86,7 @@ file_open_image (Gimp *gimp,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
const gchar *entered_filename, const gchar *entered_filename,
gboolean as_new,
GimpPlugInProcedure *file_proc, GimpPlugInProcedure *file_proc,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpPDBStatusType *status, GimpPDBStatusType *status,
@ -158,7 +160,7 @@ file_open_image (Gimp *gimp,
if (image) if (image)
{ {
file_open_sanitize_image (image); file_open_sanitize_image (image, as_new);
if (mime_type) if (mime_type)
*mime_type = file_proc->mime_type; *mime_type = file_proc->mime_type;
@ -255,7 +257,7 @@ file_open_thumbnail (Gimp *gimp,
if (image) if (image)
{ {
file_open_sanitize_image (image); file_open_sanitize_image (image, FALSE);
*mime_type = file_proc->mime_type; *mime_type = file_proc->mime_type;
@ -279,11 +281,13 @@ file_open_with_display (Gimp *gimp,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
gboolean as_new,
GimpPDBStatusType *status, GimpPDBStatusType *status,
GError **error) GError **error)
{ {
return file_open_with_proc_and_display (gimp, context, progress, return file_open_with_proc_and_display (gimp, context, progress,
uri, uri, NULL, status, error); uri, uri, as_new, NULL,
status, error);
} }
GimpImage * GimpImage *
@ -292,6 +296,7 @@ file_open_with_proc_and_display (Gimp *gimp,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
const gchar *entered_filename, const gchar *entered_filename,
gboolean as_new,
GimpPlugInProcedure *file_proc, GimpPlugInProcedure *file_proc,
GimpPDBStatusType *status, GimpPDBStatusType *status,
GError **error) GError **error)
@ -307,6 +312,7 @@ file_open_with_proc_and_display (Gimp *gimp,
image = file_open_image (gimp, context, progress, image = file_open_image (gimp, context, progress,
uri, uri,
entered_filename, entered_filename,
as_new,
file_proc, file_proc,
GIMP_RUN_INTERACTIVE, GIMP_RUN_INTERACTIVE,
status, status,
@ -314,12 +320,14 @@ file_open_with_proc_and_display (Gimp *gimp,
error); error);
if (image) if (image)
{
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
if (! as_new)
{ {
GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents); GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents);
GimpImagefile *imagefile; GimpImagefile *imagefile;
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
imagefile = gimp_document_list_add_uri (documents, uri, mime_type); imagefile = gimp_document_list_add_uri (documents, uri, mime_type);
/* can only create a thumbnail if the passed uri and the /* can only create a thumbnail if the passed uri and the
@ -336,6 +344,7 @@ file_open_with_proc_and_display (Gimp *gimp,
if (gimp->config->save_document_history) if (gimp->config->save_document_history)
gimp_recent_list_add_uri (uri, mime_type); gimp_recent_list_add_uri (uri, mime_type);
}
/* the display owns the image now */ /* the display owns the image now */
g_object_unref (image); g_object_unref (image);
@ -369,7 +378,7 @@ file_open_layers (Gimp *gimp,
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
new_image = file_open_image (gimp, context, progress, new_image = file_open_image (gimp, context, progress,
uri, uri, uri, uri, FALSE,
file_proc, file_proc,
run_mode, run_mode,
status, &mime_type, error); status, &mime_type, error);
@ -464,7 +473,8 @@ file_open_layers (Gimp *gimp,
*/ */
gboolean gboolean
file_open_from_command_line (Gimp *gimp, file_open_from_command_line (Gimp *gimp,
const gchar *filename) const gchar *filename,
gboolean as_new)
{ {
GError *error = NULL; GError *error = NULL;
gchar *uri; gchar *uri;
@ -484,7 +494,7 @@ file_open_from_command_line (Gimp *gimp,
image = file_open_with_display (gimp, image = file_open_with_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
NULL, NULL,
uri, uri, as_new,
&status, &error); &status, &error);
if (image) if (image)
@ -517,8 +527,12 @@ file_open_from_command_line (Gimp *gimp,
/* private functions */ /* private functions */
static void 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 */ /* clear all undo steps */
gimp_image_undo_free (image); gimp_image_undo_free (image);

View File

@ -27,6 +27,7 @@ GimpImage * file_open_image (Gimp *gimp,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
const gchar *entered_filename, const gchar *entered_filename,
gboolean as_new,
GimpPlugInProcedure *file_proc, GimpPlugInProcedure *file_proc,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpPDBStatusType *status, GimpPDBStatusType *status,
@ -45,6 +46,7 @@ GimpImage * file_open_with_display (Gimp *gimp,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
gboolean as_new,
GimpPDBStatusType *status, GimpPDBStatusType *status,
GError **error); GError **error);
@ -53,6 +55,7 @@ GimpImage * file_open_with_proc_and_display (Gimp *gimp,
GimpProgress *progress, GimpProgress *progress,
const gchar *uri, const gchar *uri,
const gchar *entered_filename, const gchar *entered_filename,
gboolean as_new,
GimpPlugInProcedure *file_proc, GimpPlugInProcedure *file_proc,
GimpPDBStatusType *status, GimpPDBStatusType *status,
GError **error); GError **error);
@ -69,7 +72,8 @@ GList * file_open_layers (Gimp *gimp,
GError **error); GError **error);
gboolean file_open_from_command_line (Gimp *gimp, gboolean file_open_from_command_line (Gimp *gimp,
const gchar *filename); const gchar *filename,
gboolean as_new);
#endif /* __FILE_OPEN_H__ */ #endif /* __FILE_OPEN_H__ */

View File

@ -106,6 +106,7 @@ static void gimp_open_console_window (void);
#endif #endif
static gboolean gimp_dbus_open (const gchar **filenames, static gboolean gimp_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose); gboolean be_verbose);
@ -115,6 +116,7 @@ static const gchar *session_name = NULL;
static const gchar *batch_interpreter = NULL; static const gchar *batch_interpreter = NULL;
static const gchar **batch_commands = NULL; static const gchar **batch_commands = NULL;
static const gchar **filenames = NULL; static const gchar **filenames = NULL;
static gboolean as_new = FALSE;
static gboolean no_interface = FALSE; static gboolean no_interface = FALSE;
static gboolean no_data = FALSE; static gboolean no_data = FALSE;
static gboolean no_fonts = FALSE; static gboolean no_fonts = FALSE;
@ -160,6 +162,11 @@ static const GOptionEntry main_entries[] =
G_OPTION_ARG_NONE, &new_instance, G_OPTION_ARG_NONE, &new_instance,
N_("Start a new GIMP instance"), NULL 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, "no-interface", 'i', 0,
G_OPTION_ARG_NONE, &no_interface, G_OPTION_ARG_NONE, &no_interface,
@ -362,7 +369,7 @@ main (int argc,
if (! new_instance) if (! new_instance)
{ {
if (gimp_dbus_open (filenames, be_verbose)) if (gimp_dbus_open (filenames, as_new, be_verbose))
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -379,6 +386,7 @@ main (int argc,
session_name, session_name,
batch_interpreter, batch_interpreter,
batch_commands, batch_commands,
as_new,
no_interface, no_interface,
no_data, no_data,
no_fonts, no_fonts,
@ -681,6 +689,7 @@ gimp_sigfatal_handler (gint sig_num)
static gboolean static gboolean
gimp_dbus_open (const gchar **filenames, gimp_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose) gboolean be_verbose)
{ {
#ifndef GIMP_CONSOLE_COMPILATION #ifndef GIMP_CONSOLE_COMPILATION
@ -700,13 +709,14 @@ gimp_dbus_open (const gchar **filenames,
if (filenames) if (filenames)
{ {
const gchar *method = as_new ? "OpenAsNew" : "Open";
gint i; gint i;
for (i = 0, success = TRUE; filenames[i] && success; i++) for (i = 0, success = TRUE; filenames[i] && success; i++)
{ {
gboolean retval; /* ignored */ 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_STRING, filenames[i],
G_TYPE_INVALID, G_TYPE_INVALID,
G_TYPE_BOOLEAN, &retval, G_TYPE_BOOLEAN, &retval,

View File

@ -9,6 +9,10 @@
<arg type="s" name="filename" direction="in" /> <arg type="s" name="filename" direction="in" />
<arg type="b" name="success" direction="out" /> <arg type="b" name="success" direction="out" />
</method> </method>
<method name="OpenAsNew">
<arg type="s" name="filename" direction="in" />
<arg type="b" name="success" direction="out" />
</method>
<method name="Activate" /> <method name="Activate" />
</interface> </interface>

View File

@ -78,7 +78,22 @@ gimp_dbus_service_open (GimpDBusService *service,
g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (success != 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; return TRUE;
} }

View File

@ -62,6 +62,10 @@ gboolean gimp_dbus_service_open (GimpDBusService *service,
const gchar *filename, const gchar *filename,
gboolean *success, gboolean *success,
GError **dbus_error); 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, gboolean gimp_dbus_service_activate (GimpDBusService *service,
GError **dbus_error); GError **dbus_error);

View File

@ -148,7 +148,7 @@ gimp_toolbox_drop_uri_list (GtkWidget *widget,
GError *error = NULL; GError *error = NULL;
image = file_open_with_display (context->gimp, context, NULL, image = file_open_with_display (context->gimp, context, NULL,
uri, &status, &error); uri, FALSE, &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)
{ {

View File

@ -902,7 +902,7 @@ toolbox_paste_received (GtkClipboard *clipboard,
GError *error = NULL; GError *error = NULL;
image = file_open_with_display (context->gimp, context, NULL, image = file_open_with_display (context->gimp, context, NULL,
copy, &status, &error); copy, FALSE, &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)
{ {

View File

@ -7,7 +7,7 @@ gimp - an image manipulation and paint program.
.SH SYNOPSIS .SH SYNOPSIS
.B gimp .B gimp
[\-h] [\-\-help] [\-\-help-all] [\-\-help-gtk] [-v] [\-\-version] [\-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] [\-i] [\-\-no\-interface] [\-d] [\-\-no\-data] [\-f] [\-\-no\-fonts]
[\-s] [\-\-no\-splash] [\-\-no\-shm] [\-\-no\-cpu\-accel] [\-s] [\-\-no\-splash] [\-\-no\-shm] [\-\-no\-cpu\-accel]
[\-\-display \fIdisplay\fP] [\-\-session \fI<name>\fP] [\-\-display \fIdisplay\fP] [\-\-session \fI<name>\fP]
@ -69,13 +69,17 @@ Output license information and exit.
.B \-\-verbose .B \-\-verbose
Be verbose and create information on standard output. Be verbose and create information on standard output.
.TP 8 .TP 8
.B \-i, \-\-no\-interface
Run without a user interface.
.TP 8
.B \-n, \-\-new\-instance .B \-n, \-\-new\-instance
Do not attempt to reuse an already running GIMP instance. Always start a Do not attempt to reuse an already running GIMP instance. Always start a
new one. new one.
.TP 8 .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 .B \-d, \-\-no\-data
Do not load patterns, gradients, palettes, or brushes. Often useful Do not load patterns, gradients, palettes, or brushes. Often useful
in non-interactive situations where startup time is to be minimized. in non-interactive situations where startup time is to be minimized.