]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprintoperation-unix.c
Use gdk_threads_add_timeout to popup the selection window
[~andy/gtk] / gtk / gtkprintoperation-unix.c
index 5eb770ec3c528f670b99f8b66cdc6210801606ee..6b24217987798535f9636196d08673ac633f97e6 100644 (file)
@@ -14,9 +14,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -108,6 +106,11 @@ unix_start_page (GtkPrintOperation *op,
          }
       else if (type == CAIRO_SURFACE_TYPE_PDF)
         {
+          if (!op->priv->manual_orientation)
+            {
+              w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+              h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
+            }
           cairo_pdf_surface_set_size (op_unix->surface, w, h);
         }
     }
@@ -201,8 +204,8 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
                                                      GtkWindow         *parent,
                                                      const gchar       *filename)
 {
-  gint argc;
-  gchar **argv;
+  GAppInfo *appinfo;
+  GdkAppLaunchContext *context;
   gchar *cmd;
   gchar *preview_cmd;
   GtkSettings *settings;
@@ -276,7 +279,11 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
   quoted_filename = g_shell_quote (filename);
   quoted_settings_filename = g_shell_quote (settings_filename);
   cmd = shell_command_substitute_file (preview_cmd, quoted_filename, quoted_settings_filename, &filename_used, &settings_used);
-  g_shell_parse_argv (cmd, &argc, &argv, &error);
+
+  appinfo = g_app_info_create_from_commandline (cmd,
+                                                "Print Preview",
+                                                G_APP_INFO_CREATE_NONE,
+                                                &error);
 
   g_free (preview_cmd);
   g_free (quoted_filename);
@@ -286,9 +293,12 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
   if (error != NULL)
     goto out;
 
-  gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
+  context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
+  gdk_app_launch_context_set_screen (context, screen);
+  g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), &error);
 
-  g_strfreev (argv);
+  g_object_unref (context);
+  g_object_unref (appinfo);
 
   if (error != NULL)
     {
@@ -311,9 +321,9 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
       else
         g_error_free (error);
 
-      filename_used = FALSE; 
+      filename_used = FALSE;
       settings_used = FALSE;
-   } 
+   }
 
   if (!filename_used)
     g_unlink (filename);
@@ -323,7 +333,7 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
 
   if (fd > 0)
     close (fd);
-  
+
   if (key_file)
     g_key_file_free (key_file);
   g_free (data);
@@ -378,9 +388,9 @@ unix_end_run (GtkPrintOperation *op,
       g_object_ref (op);
       if (!op_unix->data_sent)
        {
-         GDK_THREADS_LEAVE ();  
+         gdk_threads_leave ();  
          g_main_loop_run (op_unix->loop);
-         GDK_THREADS_ENTER ();  
+         gdk_threads_enter ();  
        }
       g_main_loop_unref (op_unix->loop);
       op_unix->loop = NULL;
@@ -633,7 +643,11 @@ handle_print_response (GtkWidget *dialog,
       settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd));
       page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (pd));
       page_setup_set = gtk_print_unix_dialog_get_page_setup_set (GTK_PRINT_UNIX_DIALOG (pd));
-      
+
+      /* Set new print settings now so that custom-widget options
+       * can be added to the settings in the callback
+       */
+      gtk_print_operation_set_print_settings (rdata->op, settings);
       g_signal_emit_by_name (rdata->op, "custom-widget-apply", rdata->op->priv->custom_widget);
     }
   
@@ -820,12 +834,10 @@ _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation
                                                              GtkPageSetup      *page_setup,
                                                              cairo_surface_t   *surface)
 {
-  GtkPaperSize *paper_size;
   gdouble w, h;
   
-  paper_size = gtk_page_setup_get_paper_size (page_setup);
-  w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
-  h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
+  w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+  h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
   cairo_pdf_surface_set_size (surface, w, h);
 }
 
@@ -867,9 +879,9 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
       find_printer (printer_name,
                    (GFunc) found_printer, &rdata);
 
-      GDK_THREADS_LEAVE ();  
+      gdk_threads_leave ();  
       g_main_loop_run (rdata.loop);
-      GDK_THREADS_ENTER ();  
+      gdk_threads_enter ();  
 
       g_main_loop_unref (rdata.loop);
       rdata.loop = NULL;
@@ -953,7 +965,7 @@ get_page_setup_dialog (GtkWindow        *parent,
  * setup dialog. See gtk_print_run_page_setup_dialog_async() if this is 
  * a problem.
  * 
- * Return value: a new #GtkPageSetup
+ * Return value: (transfer full): a new #GtkPageSetup
  *
  * Since: 2.10
  */
@@ -988,7 +1000,8 @@ gtk_print_run_page_setup_dialog (GtkWindow        *parent,
  * @parent: (allow-none): transient parent, or %NULL
  * @page_setup: (allow-none): an existing #GtkPageSetup, or %NULL
  * @settings: a #GtkPrintSettings
- * @done_cb: a function to call when the user saves the modified page setup
+ * @done_cb: (scope async): a function to call when the user saves
+ *           the modified page setup
  * @data: user data to pass to @done_cb
  * 
  * Runs a page setup dialog, letting the user modify the values from @page_setup. 
@@ -1056,7 +1069,7 @@ find_printer_idle (gpointer data)
   
   printer_finder_free (finder);
 
-  return FALSE;
+  return G_SOURCE_REMOVE;
 }
 
 static void