[gimp/metadata-browser] Bug 678297 - Cannot find Page Setup in Gimp 2.8



commit 214823874de321c99cf68d256a8e1087fae183db
Author: Michael Natterer <mitch gimp org>
Date:   Tue Aug 7 16:02:43 2012 +0200

    Bug 678297 - Cannot find Page Setup in Gimp 2.8
    
    Embed the page setup dialog only on non-windows systems. This
    effectively reverts bdc3f7e7e0495b599a712c917d6ab17f05f92164 but puts
    the diff in #if[n]def EMBED_PAGE_SETUP which is defined as
    !G_OS_WIN32. Did not revert the bug fixes that were mixed with
    the original embedding patch.

 plug-ins/print/print-page-setup.c |   20 +++++
 plug-ins/print/print-page-setup.h |   11 ++-
 plug-ins/print/print.c            |  165 ++++++++++++++++++++++++++++++++++++-
 plug-ins/print/print.h            |    4 +
 4 files changed, 193 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/print/print-page-setup.c b/plug-ins/print/print-page-setup.c
index 4d74e50..8317411 100644
--- a/plug-ins/print/print-page-setup.c
+++ b/plug-ins/print/print-page-setup.c
@@ -20,12 +20,32 @@
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
+#include "print.h"
 #include "print-page-setup.h"
 #include "print-utils.h"
 
 #define PRINT_PAGE_SETUP_NAME  "print-page-setup"
 
 
+#ifndef EMBED_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);
+}
+#endif
+
 void
 print_page_setup_load (GtkPrintOperation *operation,
                        gint32             image_ID)
diff --git a/plug-ins/print/print-page-setup.h b/plug-ins/print/print-page-setup.h
index 9d4bd5b..c12f874 100644
--- a/plug-ins/print/print-page-setup.h
+++ b/plug-ins/print/print-page-setup.h
@@ -16,9 +16,12 @@
  */
 
 
-void   print_page_setup_load (GtkPrintOperation *operation,
-                              gint32             image_ID);
-void   print_page_setup_save (GtkPrintOperation *operation,
-                              gint32             image_ID);
+#ifndef EMBED_PAGE_SETUP
+void   print_page_setup_dialog (GtkPrintOperation *operation);
+#endif
+void   print_page_setup_load   (GtkPrintOperation *operation,
+                                gint32             image_ID);
+void   print_page_setup_save   (GtkPrintOperation *operation,
+                                gint32             image_ID);
 
 
diff --git a/plug-ins/print/print.c b/plug-ins/print/print.c
index 8df29e9..9553b73 100644
--- a/plug-ins/print/print.c
+++ b/plug-ins/print/print.c
@@ -31,9 +31,14 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-#define PLUG_IN_BINARY  "print"
-#define PLUG_IN_ROLE    "gimp-print"
-#define PRINT_PROC_NAME "file-print-gtk"
+#define PLUG_IN_BINARY       "print"
+#define PLUG_IN_ROLE         "gimp-print"
+#define PRINT_PROC_NAME      "file-print-gtk"
+
+#ifndef EMBED_PAGE_SETUP
+#define PAGE_SETUP_PROC_NAME "file-print-gtk-page-setup"
+#define PRINT_TEMP_PROC_NAME "file-print-gtk-page-setup-notify-temp"
+#endif
 
 
 static void        query (void);
@@ -46,6 +51,9 @@ static void        run   (const gchar       *name,
 static GimpPDBStatusType  print_image       (gint32             image_ID,
                                              gboolean           interactive,
                                              GError           **error);
+#ifndef EMBED_PAGE_SETUP
+static GimpPDBStatusType  page_setup        (gint32             image_ID);
+#endif
 
 static void        print_show_error         (const gchar       *message);
 static void        print_operation_set_name (GtkPrintOperation *operation,
@@ -65,6 +73,16 @@ static void        draw_page                (GtkPrintOperation *print,
 static GtkWidget * create_custom_widget     (GtkPrintOperation *operation,
                                              PrintData         *data);
 
+#ifndef EMBED_PAGE_SETUP
+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;
+#endif
+
 
 const GimpPlugInInfo PLUG_IN_INFO =
 {
@@ -100,6 +118,25 @@ 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);
+
+#ifndef EMBED_PAGE_SETUP
+  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);
+#endif
 }
 
 static void
@@ -136,6 +173,19 @@ run (const gchar      *name,
           print_show_error (error->message);
         }
     }
+#ifndef EMBED_PAGE_SETUP
+  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;
+        }
+    }
+#endif
   else
     {
       status = GIMP_PDB_CALLING_ERROR;
@@ -160,6 +210,9 @@ print_image (gint32     image_ID,
   GtkPrintOperationResult  result;
   gint32                   layer;
   PrintData                data;
+#ifndef EMBED_PAGE_SETUP
+  gchar                   *temp_proc;
+#endif
 
   /*  create a print layer from the projection  */
   layer = gimp_layer_new_from_visible (image_ID, image_ID, PRINT_PROC_NAME);
@@ -199,6 +252,12 @@ print_image (gint32     image_ID,
                     G_CALLBACK (end_print),
                     &layer);
 
+#ifndef EMBED_PAGE_SETUP
+  print_operation = operation;
+  temp_proc = print_temp_proc_install (image_ID);
+  gimp_extension_enable ();
+#endif
+
   if (interactive)
     {
       gimp_ui_init (PLUG_IN_BINARY, FALSE);
@@ -213,7 +272,9 @@ print_image (gint32     image_ID,
 
       gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));
 
+#ifdef EMBED_PAGE_SETUP
       gtk_print_operation_set_embed_page_setup (operation, TRUE);
+#endif
 
       result = gtk_print_operation_run (operation,
                                         GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
@@ -232,6 +293,12 @@ print_image (gint32     image_ID,
                                         NULL, error);
     }
 
+#ifndef EMBED_PAGE_SETUP
+  gimp_uninstall_temp_proc (temp_proc);
+  g_free (temp_proc);
+  print_operation = NULL;
+#endif
+
   g_object_unref (operation);
 
   if (gimp_item_is_valid (layer))
@@ -253,6 +320,45 @@ print_image (gint32     image_ID,
   return GIMP_PDB_EXECUTION_ERROR;
 }
 
+#ifndef EMBED_PAGE_SETUP
+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;
+}
+#endif
+
 static void
 print_show_error (const gchar *message)
 {
@@ -331,3 +437,56 @@ create_custom_widget (GtkPrintOperation *operation,
 {
   return print_page_layout_gui (data, PRINT_PROC_NAME);
 }
+
+#ifndef EMBED_PAGE_SETUP
+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;
+}
+#endif
diff --git a/plug-ins/print/print.h b/plug-ins/print/print.h
index 6806796..2e2cfcd 100644
--- a/plug-ins/print/print.h
+++ b/plug-ins/print/print.h
@@ -16,6 +16,10 @@
  */
 
 
+#ifndef G_OS_WIN32
+#define EMBED_PAGE_SETUP 1
+#endif
+
 typedef enum
 {
   CENTER_NONE         = 0,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]