Commit bdc3f7e7 authored by Michael Natterer's avatar Michael Natterer 😴

Bug 635615 - Embed page setup dialog in the print dialog

Get rid of the antique separate page setup menu item and dialog.
Started with a patch from Bilal Akhtar but massively changed it, and
fixed some undiscovered bugs on the way.
parent 90065a51
......@@ -58,6 +58,10 @@ enum
static void print_page_setup_notify (GtkPrintOperation *operation);
static void update_custom_widget (GtkPrintOperation *operation,
GtkWidget *custom_widget,
GtkPageSetup *page_setup,
GtkPrintSettings *print_settings);
static GtkWidget * print_size_frame (PrintData *data,
GtkSizeGroup *label_group,
......@@ -187,6 +191,9 @@ print_page_layout_gui (PrintData *data,
g_signal_connect_object (data->operation, "notify::default-page-setup",
G_CALLBACK (print_page_setup_notify),
main_hbox, 0);
g_signal_connect_object (data->operation, "update-custom-widget",
G_CALLBACK (update_custom_widget),
main_hbox, 0);
gimp_help_connect (main_hbox, gimp_standard_help_func, help_id, NULL);
......@@ -204,6 +211,15 @@ print_page_setup_notify (GtkPrintOperation *operation)
print_preview_set_page_setup (PRINT_PREVIEW (info.preview), setup);
}
static void
update_custom_widget (GtkPrintOperation *operation,
GtkWidget *custom_widget,
GtkPageSetup *page_setup,
GtkPrintSettings *print_settings)
{
gtk_print_operation_set_default_page_setup (operation, page_setup);
}
#define SB_WIDTH 8
......
......@@ -26,23 +26,6 @@
#define PRINT_PAGE_SETUP_NAME "print-page-setup"
void
print_page_setup_dialog (GtkPrintOperation *operation)
{
GtkPrintSettings *settings;
GtkPageSetup *setup;
g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
setup = gtk_print_operation_get_default_page_setup (operation);
settings = gtk_print_settings_new ();
setup = gtk_print_run_page_setup_dialog (NULL, setup, settings);
g_object_unref (settings);
gtk_print_operation_set_default_page_setup (operation, setup);
}
void
print_page_setup_load (GtkPrintOperation *operation,
gint32 image_ID)
......
......@@ -16,10 +16,9 @@
*/
void print_page_setup_dialog (GtkPrintOperation *operation);
void print_page_setup_load (GtkPrintOperation *operation,
gint32 image_ID);
void print_page_setup_save (GtkPrintOperation *operation,
gint32 image_ID);
void print_page_setup_load (GtkPrintOperation *operation,
gint32 image_ID);
void print_page_setup_save (GtkPrintOperation *operation,
gint32 image_ID);
......@@ -31,12 +31,9 @@
#include "libgimp/stdplugins-intl.h"
#define PLUG_IN_BINARY "print"
#define PLUG_IN_ROLE "gimp-print"
#define PRINT_PROC_NAME "file-print-gtk"
#define PAGE_SETUP_PROC_NAME "file-print-gtk-page-setup"
#define PRINT_TEMP_PROC_NAME "file-print-gtk-page-setup-notify-temp"
#define PLUG_IN_BINARY "print"
#define PLUG_IN_ROLE "gimp-print"
#define PRINT_PROC_NAME "file-print-gtk"
static void query (void);
......@@ -49,7 +46,6 @@ static void run (const gchar *name,
static GimpPDBStatusType print_image (gint32 image_ID,
gboolean interactive,
GError **error);
static GimpPDBStatusType page_setup (gint32 image_ID);
static void print_show_error (const gchar *message);
static void print_operation_set_name (GtkPrintOperation *operation,
......@@ -69,15 +65,6 @@ static void draw_page (GtkPrintOperation *print,
static GtkWidget * create_custom_widget (GtkPrintOperation *operation,
PrintData *data);
static gchar * print_temp_proc_name (gint32 image_ID);
static gchar * print_temp_proc_install (gint32 image_ID);
/* Keep a reference to the current GtkPrintOperation
* for access by the temporary procedure.
*/
static GtkPrintOperation *print_operation = NULL;
const GimpPlugInInfo PLUG_IN_INFO =
{
......@@ -113,23 +100,6 @@ query (void)
gimp_plugin_menu_register (PRINT_PROC_NAME, "<Image>/File/Send");
gimp_plugin_icon_register (PRINT_PROC_NAME, GIMP_ICON_TYPE_STOCK_ID,
(const guint8 *) GTK_STOCK_PRINT);
gimp_install_procedure (PAGE_SETUP_PROC_NAME,
N_("Adjust page size and orientation for printing"),
"Adjust page size and orientation for printing the "
"image using the GTK+ Print API.",
"Bill Skaggs, Sven Neumann, Stefan Röllin",
"Sven Neumann <sven@gimp.org>",
"2008",
N_("Page Set_up"),
"*",
GIMP_PLUGIN,
G_N_ELEMENTS (print_args), 0,
print_args, NULL);
gimp_plugin_menu_register (PAGE_SETUP_PROC_NAME, "<Image>/File/Send");
gimp_plugin_icon_register (PAGE_SETUP_PROC_NAME, GIMP_ICON_TYPE_STOCK_ID,
(const guint8 *) GTK_STOCK_PAGE_SETUP);
}
static void
......@@ -166,18 +136,6 @@ run (const gchar *name,
if (error && run_mode == GIMP_RUN_INTERACTIVE)
{
print_show_error (error->message);
g_clear_error (&error);
}
}
else if (strcmp (name, PAGE_SETUP_PROC_NAME) == 0)
{
if (run_mode == GIMP_RUN_INTERACTIVE)
{
status = page_setup (image_ID);
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
}
else
......@@ -202,7 +160,6 @@ print_image (gint32 image_ID,
{
GtkPrintOperation *operation;
GtkPrintOperationResult result;
gchar *temp_proc;
gint32 layer;
PrintData data;
......@@ -242,11 +199,7 @@ print_image (gint32 image_ID,
&data);
g_signal_connect (operation, "end-print",
G_CALLBACK (end_print),
&image_ID);
print_operation = operation;
temp_proc = print_temp_proc_install (image_ID);
gimp_extension_enable ();
&layer);
if (interactive)
{
......@@ -262,9 +215,17 @@ print_image (gint32 image_ID,
gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));
gtk_print_operation_set_embed_page_setup (operation, TRUE);
result = gtk_print_operation_run (operation,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
NULL, error);
if (result == GTK_PRINT_OPERATION_RESULT_APPLY ||
result == GTK_PRINT_OPERATION_RESULT_IN_PROGRESS)
{
print_page_setup_save (operation, image_ID);
}
}
else
{
......@@ -273,10 +234,6 @@ print_image (gint32 image_ID,
NULL, error);
}
gimp_uninstall_temp_proc (temp_proc);
g_free (temp_proc);
print_operation = NULL;
g_object_unref (operation);
if (gimp_item_is_valid (layer))
......@@ -298,43 +255,6 @@ print_image (gint32 image_ID,
return GIMP_PDB_EXECUTION_ERROR;
}
static GimpPDBStatusType
page_setup (gint32 image_ID)
{
GtkPrintOperation *operation;
GimpParam *return_vals;
gchar *name;
gint n_return_vals;
gimp_ui_init (PLUG_IN_BINARY, FALSE);
operation = gtk_print_operation_new ();
print_page_setup_load (operation, image_ID);
print_page_setup_dialog (operation);
print_page_setup_save (operation, image_ID);
g_object_unref (operation);
/* now notify a running print procedure about this change */
name = print_temp_proc_name (image_ID);
/* we don't want the core to show an error message if the
* temporary procedure does not exist
*/
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
return_vals = gimp_run_procedure (name,
&n_return_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_END);
gimp_destroy_params (return_vals, n_return_vals);
g_free (name);
return GIMP_PDB_SUCCESS;
}
static void
print_show_error (const gchar *message)
{
......@@ -413,54 +333,3 @@ create_custom_widget (GtkPrintOperation *operation,
{
return print_page_layout_gui (data, PRINT_PROC_NAME);
}
static void
print_temp_proc_run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
if (print_operation && nparams == 1)
print_page_setup_load (print_operation, param[0].data.d_int32);
}
static gchar *
print_temp_proc_name (gint32 image_ID)
{
return g_strdup_printf (PRINT_TEMP_PROC_NAME "-%d", image_ID);
}
static gchar *
print_temp_proc_install (gint32 image_ID)
{
static const GimpParamDef args[] =
{
{ GIMP_PDB_IMAGE, "image", "Image to print" }
};
gchar *name = print_temp_proc_name (image_ID);
gimp_install_temp_proc (name,
"DON'T USE THIS ONE",
"Temporary procedure to notify the Print plug-in "
"about changes to the Page Setup.",
"Sven Neumann",
"Sven Neumann",
"2008",
NULL,
"",
GIMP_TEMPORARY,
G_N_ELEMENTS (args), 0, args, NULL,
print_temp_proc_run);
return name;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment