widget-factory: Port to async dialog API
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 00:16:21 +0000 (20:16 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 17:31:41 +0000 (13:31 -0400)
demos/widget-factory/widget-factory.c

index e1881cc5b246caf460cc1d84787be4059243749b..705606fcfef0ef67e825b0cd9cc4c7300401ac11 100644 (file)
@@ -214,10 +214,19 @@ activate_background (GSimpleAction *action,
 }
 
 static void
-file_chooser_response (GtkNativeDialog *self,
-                       int              response)
+file_chooser_response (GObject *source,
+                       GAsyncResult *result,
+                       void *user_data)
 {
-  gtk_native_dialog_destroy (self);
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GFile *file;
+
+  file = gtk_file_dialog_open_finish (dialog, result, NULL);
+  if (file)
+    {
+      g_print ("File selected: %s", g_file_peek_path (file));
+      g_object_unref (file);
+    }
 }
 
 static void
@@ -225,17 +234,11 @@ activate_open_file (GSimpleAction *action,
                     GVariant      *parameter,
                     gpointer       user_data)
 {
-  GtkFileChooserNative *chooser;
-
-  chooser = gtk_file_chooser_native_new ("Open file",
-                                         NULL,
-                                         GTK_FILE_CHOOSER_ACTION_OPEN,
-                                         "Open",
-                                         "Cancel");
-
-  g_signal_connect (chooser, "response", G_CALLBACK (file_chooser_response), NULL);
+  GtkFileDialog *dialog;
 
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
+  dialog = gtk_file_dialog_new ();
+  gtk_file_dialog_open (dialog, NULL, NULL, NULL, file_chooser_response, NULL);
+  g_object_unref (dialog);
 }
 
 static void