[gtk/ebassi/run-dialog-run: 2/7] Drop gtk_dialog_run() from GtkPrintOperationUnix



commit 45eec065009f232c0f6d1d7e68487b2bdf9c936c
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 30 16:28:00 2020 +0100

    Drop gtk_dialog_run() from GtkPrintOperationUnix
    
    We still provide a blocking API, but we should strongly reconsider it.

 gtk/gtkprintoperation-unix.c | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c
index ba79ea0bca..fc00ff004e 100644
--- a/gtk/gtkprintoperation-unix.c
+++ b/gtk/gtkprintoperation-unix.c
@@ -658,6 +658,8 @@ handle_print_response (GtkWidget *dialog,
     
   gtk_window_destroy (GTK_WINDOW (pd));
  
+  if (rdata->loop)
+    g_main_loop_quit (rdata->loop);
 }
 
 
@@ -669,7 +671,7 @@ found_printer (GtkPrinter        *printer,
   GtkPrintOperationPrivate *priv = op->priv;
   GtkPrintSettings *settings = NULL;
   GtkPageSetup *page_setup = NULL;
-  
+
   if (rdata->loop)
     g_main_loop_quit (rdata->loop);
 
@@ -851,7 +853,6 @@ gtk_print_operation_unix_run_dialog (GtkPrintOperation *op,
  {
   GtkWidget *pd;
   PrintResponseData rdata;
-  gint response;  
   const gchar *printer_name;
    
   rdata.op = op;
@@ -866,9 +867,19 @@ gtk_print_operation_unix_run_dialog (GtkPrintOperation *op,
   if (show_dialog)
     {
       pd = get_print_dialog (op, parent);
+      gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
+
+      g_signal_connect (pd, "response", 
+                       G_CALLBACK (handle_print_response), &rdata);
 
-      response = gtk_dialog_run (GTK_DIALOG (pd));
-      handle_print_response (pd, response, &rdata);
+      G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+      gtk_window_present (GTK_WINDOW (pd));
+      G_GNUC_END_IGNORE_DEPRECATIONS
+
+      rdata.loop = g_main_loop_new (NULL, FALSE);
+      g_main_loop_run (rdata.loop);
+      g_main_loop_unref (rdata.loop);
+      rdata.loop = NULL;
     }
   else
     {
@@ -897,6 +908,7 @@ typedef struct
   GtkPageSetupDoneFunc  done_cb;
   gpointer              data;
   GDestroyNotify        destroy;
+  GMainLoop            *loop;
 } PageSetupResponseData;
 
 static void
@@ -918,6 +930,9 @@ handle_page_setup_response (GtkWidget *dialog,
   GtkPageSetupUnixDialog *psd;
   PageSetupResponseData *rdata = data;
 
+  if (rdata->loop)
+    g_main_loop_quit (rdata->loop);
+
   psd = GTK_PAGE_SETUP_UNIX_DIALOG (dialog);
   if (response == GTK_RESPONSE_OK)
     rdata->page_setup = gtk_page_setup_unix_dialog_get_page_setup (psd);
@@ -971,18 +986,28 @@ gtk_print_run_page_setup_dialog (GtkWindow        *parent,
                                 GtkPrintSettings *settings)
 {
   GtkWidget *dialog;
-  gint response;
   PageSetupResponseData rdata;  
   
   rdata.page_setup = NULL;
   rdata.done_cb = NULL;
   rdata.data = NULL;
   rdata.destroy = NULL;
+  rdata.loop = g_main_loop_new (NULL, FALSE);
 
   dialog = get_page_setup_dialog (parent, page_setup, settings);
-  response = gtk_dialog_run (GTK_DIALOG (dialog));
-  handle_page_setup_response (dialog, response, &rdata);
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (handle_page_setup_response),
+                    &rdata);
+
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  gtk_window_present (GTK_WINDOW (dialog));
+  G_GNUC_END_IGNORE_DEPRECATIONS
  
+  g_main_loop_run (rdata.loop);
+  g_main_loop_unref (rdata.loop);
+  rdata.loop = NULL;
+
   if (rdata.page_setup)
     return rdata.page_setup;
   else if (page_setup)
@@ -1024,6 +1049,7 @@ gtk_print_run_page_setup_dialog_async (GtkWindow            *parent,
   rdata->done_cb = done_cb;
   rdata->data = data;
   rdata->destroy = page_setup_data_free;
+  rdata->loop = NULL;
 
   g_signal_connect (dialog, "response",
                    G_CALLBACK (handle_page_setup_response), rdata);


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