@@ -41,6 +41,7 @@ struct _ClapperAppApplication
41
41
GtkApplication parent ;
42
42
43
43
GSettings * settings ;
44
+ GCancellable * cancellable ;
44
45
45
46
gboolean need_init_state ;
46
47
};
@@ -61,6 +62,12 @@ struct ClapperPluginData
61
62
struct ClapperPluginFeatureData features [10 ];
62
63
};
63
64
65
+ typedef struct
66
+ {
67
+ ClapperAppApplication * app ;
68
+ guint id ;
69
+ } ClapperAppWindowData ;
70
+
64
71
typedef struct
65
72
{
66
73
const gchar * action ;
@@ -396,7 +403,7 @@ show_info (GSimpleAction *action, GVariant *param, gpointer user_data)
396
403
}
397
404
398
405
static void
399
- _show_pipeline_cb (GtkFileLauncher * launcher ,
406
+ _launch_pipeline_cb (GtkFileLauncher * launcher ,
400
407
GAsyncResult * res , gpointer user_data G_GNUC_UNUSED )
401
408
{
402
409
GError * error = NULL ;
@@ -411,14 +418,52 @@ _show_pipeline_cb (GtkFileLauncher *launcher,
411
418
}
412
419
413
420
static void
414
- show_pipeline (GSimpleAction * action , GVariant * param , gpointer user_data )
421
+ _show_pipeline_cb (GObject * source G_GNUC_UNUSED ,
422
+ GAsyncResult * res , ClapperAppWindowData * win_data )
415
423
{
416
- GtkApplication * gtk_app = GTK_APPLICATION ( user_data );
424
+ GTask * task = G_TASK ( res );
417
425
GtkWindow * window ;
418
- GtkFileLauncher * launcher ;
419
426
GFile * svg_file ;
420
427
GError * error = NULL ;
421
428
429
+ svg_file = (GFile * ) g_task_propagate_pointer (task , & error );
430
+
431
+ if (error ) {
432
+ if (error -> domain != G_IO_ERROR || error -> code != G_IO_ERROR_CANCELLED ) {
433
+ GST_ERROR ("Could not create pipeline graph file, reason: %s" ,
434
+ GST_STR_NULL (error -> message ));
435
+ }
436
+ g_error_free (error );
437
+ g_free (win_data );
438
+
439
+ return ;
440
+ }
441
+
442
+ if ((window = gtk_application_get_window_by_id (
443
+ GTK_APPLICATION (win_data -> app ), win_data -> id ))) {
444
+ GtkFileLauncher * launcher = gtk_file_launcher_new (svg_file );
445
+
446
+ #if GTK_CHECK_VERSION (4 ,12 ,0 )
447
+ gtk_file_launcher_set_always_ask (launcher , TRUE);
448
+ #endif
449
+
450
+ gtk_file_launcher_launch (launcher , window , NULL ,
451
+ (GAsyncReadyCallback ) _launch_pipeline_cb , NULL );
452
+ g_object_unref (launcher );
453
+ }
454
+
455
+ g_object_unref (svg_file );
456
+ g_free (win_data );
457
+ }
458
+
459
+ static void
460
+ show_pipeline (GSimpleAction * action , GVariant * param , gpointer user_data )
461
+ {
462
+ ClapperAppApplication * self = CLAPPER_APP_APPLICATION_CAST (user_data );
463
+ GtkApplication * gtk_app = GTK_APPLICATION (self );
464
+ GtkWindow * window ;
465
+ ClapperAppWindowData * win_data ;
466
+
422
467
window = gtk_application_get_active_window (gtk_app );
423
468
424
469
while (window && !CLAPPER_APP_IS_WINDOW (window ))
@@ -427,25 +472,19 @@ show_pipeline (GSimpleAction *action, GVariant *param, gpointer user_data)
427
472
if (G_UNLIKELY (window == NULL ))
428
473
return ;
429
474
430
- if (!(svg_file = clapper_app_utils_create_pipeline_svg_file (
431
- clapper_app_window_get_player (CLAPPER_APP_WINDOW (window )), & error ))) {
432
- GST_ERROR ("Could not create pipeline graph file, reason: %s" ,
433
- GST_STR_NULL (error -> message ));
434
- g_error_free (error );
435
-
436
- return ;
475
+ if (self -> cancellable ) {
476
+ g_cancellable_cancel (self -> cancellable );
477
+ g_object_unref (self -> cancellable );
437
478
}
479
+ self -> cancellable = g_cancellable_new ();
438
480
439
- launcher = gtk_file_launcher_new (svg_file );
440
- g_object_unref (svg_file );
441
-
442
- #if GTK_CHECK_VERSION (4 ,12 ,0 )
443
- gtk_file_launcher_set_always_ask (launcher , TRUE);
444
- #endif
481
+ win_data = g_new (ClapperAppWindowData , 1 );
482
+ win_data -> app = self ;
483
+ win_data -> id = gtk_application_window_get_id (GTK_APPLICATION_WINDOW (window ));
445
484
446
- gtk_file_launcher_launch ( launcher , window , NULL ,
447
- ( GAsyncReadyCallback ) _show_pipeline_cb , NULL );
448
- g_object_unref ( launcher );
485
+ clapper_app_utils_create_pipeline_svg_file_async (
486
+ clapper_app_window_get_player ( CLAPPER_APP_WINDOW ( window )),
487
+ self -> cancellable , ( GAsyncReadyCallback ) _show_pipeline_cb , win_data );
449
488
}
450
489
451
490
static void
@@ -809,13 +848,30 @@ clapper_app_application_constructed (GObject *object)
809
848
G_OBJECT_CLASS (parent_class )-> constructed (object );
810
849
}
811
850
851
+ static void
852
+ clapper_app_application_dispose (GObject * object )
853
+ {
854
+ ClapperAppApplication * self = CLAPPER_APP_APPLICATION_CAST (object );
855
+
856
+ if (self -> cancellable ) {
857
+ g_cancellable_cancel (self -> cancellable );
858
+ g_clear_object (& self -> cancellable );
859
+ }
860
+
861
+ G_OBJECT_CLASS (parent_class )-> dispose (object );
862
+ }
863
+
812
864
static void
813
865
clapper_app_application_finalize (GObject * object )
814
866
{
815
867
ClapperAppApplication * self = CLAPPER_APP_APPLICATION_CAST (object );
816
868
817
869
GST_TRACE ("Finalize" );
818
870
871
+ if (self -> cancellable ) {
872
+ g_cancellable_cancel (self -> cancellable );
873
+ g_object_unref (self -> cancellable );
874
+ }
819
875
g_object_unref (self -> settings );
820
876
821
877
G_OBJECT_CLASS (parent_class )-> finalize (object );
@@ -832,6 +888,7 @@ clapper_app_application_class_init (ClapperAppApplicationClass *klass)
832
888
"Clapper App Application" );
833
889
834
890
gobject_class -> constructed = clapper_app_application_constructed ;
891
+ gobject_class -> dispose = clapper_app_application_dispose ;
835
892
gobject_class -> finalize = clapper_app_application_finalize ;
836
893
837
894
gtk_application_class -> window_removed = clapper_app_application_window_removed ;
0 commit comments