27
27
#include "print-settings.h"
28
28
#include "print-page-layout.h"
29
#include "print-page-setup.h"
29
30
#include "print-draw-page.h"
31
32
#include "libgimp/stdplugins-intl.h"
34
#define PRINT_PROC_NAME "file-print-gtk"
35
#define PLUG_IN_BINARY "print"
35
#define PLUG_IN_BINARY "print"
37
#define PRINT_PROC_NAME "file-print-gtk"
38
#define PAGE_SETUP_PROC_NAME "file-print-gtk-page-setup"
39
#define PRINT_TEMP_PROC_NAME "file-print-gtk-page-setup-notify-temp"
38
42
static void query (void);
42
46
gint *nreturn_vals,
43
47
GimpParam **return_vals);
45
static gboolean print_image (gint32 image_ID,
46
gboolean interactive);
49
static GimpPDBStatusType print_image (gint32 image_ID,
52
static GimpPDBStatusType page_setup (gint32 image_ID);
48
static void print_show_error (const gchar *message,
49
gboolean interactive);
54
static void print_show_error (const gchar *message);
50
55
static void print_operation_set_name (GtkPrintOperation *operation,
101
114
gimp_plugin_icon_register (PRINT_PROC_NAME, GIMP_ICON_TYPE_STOCK_ID,
102
115
(const guint8 *) GTK_STOCK_PRINT);
117
gimp_install_procedure (PAGE_SETUP_PROC_NAME,
118
N_("Adjust page size and orientation for printing"),
119
"Adjust page size and orientation for printing the "
120
"image using the GTK+ Print API.",
121
"Bill Skaggs, Sven Neumann, Stefan Rƶllin",
122
"Sven Neumann <sven@gimp.org>",
127
G_N_ELEMENTS (print_args), 0,
130
gimp_plugin_menu_register (PAGE_SETUP_PROC_NAME, "<Image>/File/Send");
132
#if GTK_CHECK_VERSION(2,13,0)
133
gimp_plugin_icon_register (PAGE_SETUP_PROC_NAME, GIMP_ICON_TYPE_STOCK_ID,
134
(const guint8 *) GTK_STOCK_PAGE_SETUP);
130
165
if (strcmp (name, PRINT_PROC_NAME) == 0)
132
g_thread_init (NULL);
134
gimp_ui_init (PLUG_IN_BINARY, FALSE);
136
if (! print_image (image_ID, run_mode == GIMP_RUN_INTERACTIVE))
138
status = GIMP_PDB_EXECUTION_ERROR;
167
status = print_image (image_ID, run_mode == GIMP_RUN_INTERACTIVE, &error);
169
if (error && run_mode == GIMP_RUN_INTERACTIVE)
171
print_show_error (error->message);
172
g_clear_error (&error);
175
else if (strcmp (name, PAGE_SETUP_PROC_NAME) == 0)
177
if (run_mode == GIMP_RUN_INTERACTIVE)
179
status = page_setup (image_ID);
183
status = GIMP_PDB_CALLING_ERROR;
143
188
status = GIMP_PDB_CALLING_ERROR;
191
if (status != GIMP_PDB_SUCCESS && error)
194
values[1].type = GIMP_PDB_STRING;
195
values[1].data.d_string = error->message;
146
198
values[0].data.d_status = status;
150
print_image (gint32 image_ID,
151
gboolean interactive)
201
static GimpPDBStatusType
202
print_image (gint32 image_ID,
203
gboolean interactive,
153
GtkPrintOperation *operation;
154
GError *error = NULL;
155
gint32 orig_image_ID = image_ID;
156
gint32 drawable_ID = gimp_image_get_active_drawable (image_ID);
158
GimpExportReturn export;
160
/* export the image */
161
export = gimp_export_image (&image_ID, &drawable_ID, NULL,
162
GIMP_EXPORT_CAN_HANDLE_RGB |
163
GIMP_EXPORT_CAN_HANDLE_ALPHA);
165
if (export == GIMP_EXPORT_CANCEL)
206
GtkPrintOperation *operation;
207
GtkPrintOperationResult result;
212
/* create a print layer from the projection */
213
layer = gimp_layer_new_from_visible (image_ID, image_ID, PRINT_PROC_NAME);
168
215
operation = gtk_print_operation_new ();
170
print_operation_set_name (operation, orig_image_ID);
217
gtk_print_operation_set_n_pages (operation, 1);
218
print_operation_set_name (operation, image_ID);
220
print_page_setup_load (operation, image_ID);
172
222
/* fill in the PrintData struct */
174
data.image_id = orig_image_ID;
175
data.drawable_id = drawable_ID;
223
data.image_id = image_ID;
224
data.drawable_id = layer;
176
225
data.unit = gimp_get_default_unit ();
177
226
data.image_unit = gimp_image_get_unit (image_ID);
178
227
data.offset_x = 0;
200
246
G_CALLBACK (end_print),
249
print_operation = operation;
250
temp_proc = print_temp_proc_install (image_ID);
251
gimp_extension_enable ();
255
gimp_ui_init (PLUG_IN_BINARY, FALSE);
205
257
g_signal_connect_swapped (operation, "end-print",
206
G_CALLBACK (save_print_settings),
258
G_CALLBACK (print_settings_save),
209
261
g_signal_connect (operation, "create-custom-widget",
213
265
gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));
215
gtk_print_operation_run (operation,
216
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
267
result = gtk_print_operation_run (operation,
268
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
221
gtk_print_operation_run (operation,
222
GTK_PRINT_OPERATION_ACTION_PRINT,
273
result = gtk_print_operation_run (operation,
274
GTK_PRINT_OPERATION_ACTION_PRINT,
278
gimp_uninstall_temp_proc (temp_proc);
280
print_operation = NULL;
226
282
g_object_unref (operation);
228
if (gimp_image_is_valid (image_ID))
229
gimp_image_delete (image_ID);
284
if (gimp_drawable_is_valid (layer))
285
gimp_drawable_delete (layer);
233
print_show_error (error->message, interactive);
234
g_error_free (error);
289
case GTK_PRINT_OPERATION_RESULT_APPLY:
290
case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
291
return GIMP_PDB_SUCCESS;
293
case GTK_PRINT_OPERATION_RESULT_CANCEL:
294
return GIMP_PDB_CANCEL;
296
case GTK_PRINT_OPERATION_RESULT_ERROR:
297
return GIMP_PDB_EXECUTION_ERROR;
300
return GIMP_PDB_EXECUTION_ERROR;
303
static GimpPDBStatusType
304
page_setup (gint32 image_ID)
306
GtkPrintOperation *operation;
307
GimpParam *return_vals;
311
gimp_ui_init (PLUG_IN_BINARY, FALSE);
313
operation = gtk_print_operation_new ();
315
print_page_setup_load (operation, image_ID);
316
print_page_setup_dialog (operation);
317
print_page_setup_save (operation, image_ID);
319
g_object_unref (operation);
321
/* now notify a running print procedure about this change */
322
name = print_temp_proc_name (image_ID);
324
/* we don't want the core to show an error message if the
325
* temporary procedure does not exist
327
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
329
return_vals = gimp_run_procedure (name,
331
GIMP_PDB_IMAGE, image_ID,
333
gimp_destroy_params (return_vals, n_return_vals);
337
return GIMP_PDB_SUCCESS;
241
print_show_error (const gchar *message,
242
gboolean interactive)
341
print_show_error (const gchar *message)
244
g_printerr ("Print: %s\n", message);
250
dialog = gtk_message_dialog_new (NULL, 0,
253
_("An error occurred "
254
"while trying to print:"));
256
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
259
gtk_dialog_run (GTK_DIALOG (dialog));
260
gtk_widget_destroy (dialog);
345
dialog = gtk_message_dialog_new (NULL, 0,
348
_("An error occurred while trying to print:"));
350
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
353
gtk_dialog_run (GTK_DIALOG (dialog));
354
gtk_widget_destroy (dialog);
287
379
end_print (GtkPrintOperation *operation,
288
380
GtkPrintContext *context,
291
/* we don't need the export image any longer, delete it */
292
if (gimp_image_is_valid (*image_ID))
383
/* we don't need the print layer any longer, delete it */
384
if (gimp_drawable_is_valid (*layer_ID))
294
gimp_image_delete (*image_ID);
386
gimp_drawable_delete (*layer_ID);
298
390
gimp_progress_end ();
300
392
/* generate events to solve the problems described in bug #466928 */
301
g_timeout_add (1000, (GSourceFunc) gtk_true, NULL);
393
g_timeout_add_seconds (1, (GSourceFunc) gtk_true, NULL);
318
412
create_custom_widget (GtkPrintOperation *operation,
321
return print_page_layout_gui (data);
415
return print_page_layout_gui (data, PRINT_PROC_NAME);
419
print_temp_proc_run (const gchar *name,
421
const GimpParam *param,
423
GimpParam **return_vals)
425
static GimpParam values[1];
427
values[0].type = GIMP_PDB_STATUS;
428
values[0].data.d_status = GIMP_PDB_SUCCESS;
431
*return_vals = values;
433
if (print_operation && nparams == 1)
434
print_page_setup_load (print_operation, param[0].data.d_int32);
438
print_temp_proc_name (gint32 image_ID)
440
return g_strdup_printf (PRINT_TEMP_PROC_NAME "-%d", image_ID);
444
print_temp_proc_install (gint32 image_ID)
446
static const GimpParamDef args[] =
448
{ GIMP_PDB_IMAGE, "image", "Image to print" }
451
gchar *name = print_temp_proc_name (image_ID);
453
gimp_install_temp_proc (name,
454
"DON'T USE THIS ONE",
455
"Temporary procedure to notify the Print plug-in "
456
"about changes to the Page Setup.",
463
G_N_ELEMENTS (args), 0, args, NULL,
464
print_temp_proc_run);