From 4fa53bd041062954bfddc6a9eaf179579c900826 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 24 Nov 2022 10:26:43 -0500 Subject: [PATCH] gtk-demo: Test cancellation support for file dialog Add a timeout that closes the file dialog after 20 seconds, to test programmatic cancellation. --- demos/gtk-demo/pickers.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/demos/gtk-demo/pickers.c b/demos/gtk-demo/pickers.c index aa5b0d1c58..2a5d1b58ce 100644 --- a/demos/gtk-demo/pickers.c +++ b/demos/gtk-demo/pickers.c @@ -33,17 +33,35 @@ file_opened (GObject *source, g_free (name); } +static gboolean +abort_mission (gpointer data) +{ + GCancellable *cancellable = data; + + g_cancellable_cancel (cancellable); + + return G_SOURCE_REMOVE; +} + static void open_file (GtkButton *picker, GtkLabel *label) { GtkWindow *parent = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (picker))); GtkFileDialog *dialog; + GCancellable *cancellable; dialog = gtk_file_dialog_new (); - gtk_file_dialog_open (dialog, parent, NULL, NULL, file_opened, label); + cancellable = g_cancellable_new (); + g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, + 20, + abort_mission, g_object_ref (cancellable), g_object_unref); + + gtk_file_dialog_open (dialog, parent, NULL, cancellable, file_opened, label); + + g_object_unref (cancellable); g_object_unref (dialog); }