diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-04-06 17:32:08 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-04-07 13:46:20 +0200 |
commit | 2a7952a71285d140dafc3719ee1b699492015fbf (patch) | |
tree | 10b95171de3c78e4306620d9ef0ba6dd00365965 /src | |
parent | cb8a40e6bf189b80f4110b6519517db7aec859dd (diff) | |
download | totem-2a7952a71285d140dafc3719ee1b699492015fbf.tar.gz |
main: Use GSignalGroup to simplify playlist signal handling
Remove some helper macros, and unsightly signal connection/disconnection
in favour of using GSignalGroup to block/unblock all signals coming from
the playlist widget.
Diffstat (limited to 'src')
-rw-r--r-- | src/totem-object.c | 57 | ||||
-rw-r--r-- | src/totem-private.h | 8 | ||||
-rw-r--r-- | src/totem-session.c | 6 |
3 files changed, 32 insertions, 39 deletions
diff --git a/src/totem-object.c b/src/totem-object.c index b95dcade3..4ece7c72e 100644 --- a/src/totem-object.c +++ b/src/totem-object.c @@ -533,6 +533,7 @@ totem_object_finalize (GObject *object) { TotemObject *totem = TOTEM_OBJECT (object); + g_clear_object (&totem->playlist_signals); g_clear_pointer (&totem->busy_popup_ht, g_hash_table_destroy); g_clear_pointer (&totem->title, g_free); g_clear_pointer (&totem->subtitle, g_free); @@ -737,7 +738,7 @@ add_items_to_playlist_and_play_cb (TotemPlaylist *playlist, GAsyncResult *async_ /* totem_playlist_add_mrls_finish() never returns an error */ totem_playlist_add_mrls_finish (playlist, async_result, NULL); - totem_signal_unblock_by_data (playlist, totem); + g_signal_group_unblock (totem->playlist_signals); /* And start playback */ mrl = totem_playlist_get_current_mrl (playlist, &subtitle); @@ -771,7 +772,7 @@ add_to_playlist_and_play_cb (TotemPlaylist *playlist, GAsyncResult *async_result if (data->play) end = totem_playlist_get_last (playlist); - totem_signal_unblock_by_data (playlist, data->totem); + g_signal_group_unblock (data->totem->playlist_signals); if (data->play && playlist_changed && end != -1) { char *mrl, *subtitle; @@ -833,7 +834,7 @@ totem_object_add_to_playlist (TotemObject *totem, /* Block all signals from the playlist until we're finished. They're unblocked in the callback, add_to_playlist_and_play_cb. * There are no concurrency issues here, since blocking the signals multiple times should require them to be unblocked the * same number of times before they fire again. */ - totem_signal_block_by_data (totem->playlist, totem); + g_signal_group_block (totem->playlist_signals); data = g_slice_new (AddToPlaylistData); data->totem = g_object_ref (totem); @@ -862,7 +863,7 @@ totem_object_add_items_to_playlist (TotemObject *totem, /* Block all signals from the playlist until we're finished. They're unblocked in the callback, add_to_playlist_and_play_cb. * There are no concurrency issues here, since blocking the signals multiple times should require them to be unblocked the * same number of times before they fire again. */ - totem_signal_block_by_data (totem->playlist, totem); + g_signal_group_block (totem->playlist_signals); totem_playlist_add_mrls (totem->playlist, items, TRUE, NULL, (GAsyncReadyCallback) add_items_to_playlist_and_play_cb, totem); @@ -2321,8 +2322,8 @@ totem_object_drop_files_finished (TotemPlaylist *playlist, GAsyncResult *result, { char *mrl, *subtitle; - /* Reconnect the playlist's changed signal (which was disconnected below in totem_object_drop_files(). */ - g_signal_connect (G_OBJECT (playlist), "changed", G_CALLBACK (playlist_changed_cb), totem); + /* Unblock the playlist's signals (which was blocked below in totem_object_drop_files(). */ + g_signal_group_unblock (totem->playlist_signals); mrl = totem_playlist_get_current_mrl (playlist, &subtitle); totem_object_set_mrl_and_play (totem, mrl, subtitle); g_free (mrl); @@ -2373,7 +2374,7 @@ totem_object_drop_files (TotemObject *totem, } /* The function that calls us knows better if we should be doing something with the changed playlist... */ - g_signal_handlers_disconnect_by_func (G_OBJECT (totem->playlist), playlist_changed_cb, totem); + g_signal_group_block (totem->playlist_signals); totem_playlist_clear (totem->playlist); /* Add each MRL to the playlist asynchronously */ @@ -2398,7 +2399,7 @@ totem_object_drop_files (TotemObject *totem, mrl_list = g_list_prepend (mrl_list, totem_playlist_mrl_data_new (filename, title)); } - /* Add the MRLs to the playlist asynchronously and in order. We need to reconnect playlist's "changed" signal once all of the add-MRL + /* Add the MRLs to the playlist asynchronously and in order. We need to unblock playlist's "changed" signal once all of the add-MRL * operations have completed. */ if (mrl_list != NULL) { totem_playlist_add_mrls (totem->playlist, g_list_reverse (mrl_list), TRUE, NULL, @@ -2925,13 +2926,9 @@ totem_object_open_files_list (TotemObject *totem, GSList *list) g_application_unmark_busy (G_APPLICATION (totem)); - /* ... and reconnect because we're nice people */ + /* ... and unblock because we're nice people */ if (cleared != FALSE) - { - g_signal_connect (G_OBJECT (totem->playlist), - "changed", G_CALLBACK (playlist_changed_cb), - totem); - } + g_signal_group_unblock (totem->playlist_signals); return changed; } @@ -4093,6 +4090,7 @@ void playlist_widget_setup (TotemObject *totem) { totem->playlist = TOTEM_PLAYLIST (totem_playlist_new ()); + totem->playlist_signals = g_signal_group_new (TOTEM_TYPE_PLAYLIST); #if 0 { @@ -4104,24 +4102,19 @@ playlist_widget_setup (TotemObject *totem) gtk_widget_show_all (window); } #endif - g_signal_connect (G_OBJECT (totem->playlist), "active-name-changed", - G_CALLBACK (on_playlist_change_name), totem); - g_signal_connect (G_OBJECT (totem->playlist), "item-activated", - G_CALLBACK (item_activated_cb), totem); - g_signal_connect (G_OBJECT (totem->playlist), - "changed", G_CALLBACK (playlist_changed_cb), - totem); - g_signal_connect (G_OBJECT (totem->playlist), - "current-removed", G_CALLBACK (current_removed_cb), - totem); - g_signal_connect (G_OBJECT (totem->playlist), - "notify::repeat", - G_CALLBACK (playlist_repeat_toggle_cb), - totem); - g_signal_connect (G_OBJECT (totem->playlist), - "subtitle-changed", - G_CALLBACK (subtitle_changed_cb), - totem); + g_signal_group_connect (totem->playlist_signals, "active-name-changed", + G_CALLBACK (on_playlist_change_name), totem); + g_signal_group_connect (totem->playlist_signals, "item-activated", + G_CALLBACK (item_activated_cb), totem); + g_signal_group_connect (totem->playlist_signals, "changed", + G_CALLBACK (playlist_changed_cb), totem); + g_signal_group_connect (totem->playlist_signals, "current-removed", + G_CALLBACK (current_removed_cb), totem); + g_signal_group_connect (totem->playlist_signals, "notify::repeat", + G_CALLBACK (playlist_repeat_toggle_cb), totem); + g_signal_group_connect (totem->playlist_signals, "subtitle-changed", + G_CALLBACK (subtitle_changed_cb), totem); + g_signal_group_set_target (totem->playlist_signals, totem->playlist); } static void diff --git a/src/totem-private.h b/src/totem-private.h index 673edaadc..0ce1fd983 100644 --- a/src/totem-private.h +++ b/src/totem-private.h @@ -36,9 +36,6 @@ #include "totem-open-location.h" #include "totem-plugins-engine.h" -#define totem_signal_block_by_data(obj, data) (g_signal_handlers_block_matched (obj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data)) -#define totem_signal_unblock_by_data(obj, data) (g_signal_handlers_unblock_matched (obj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data)) - #define totem_set_sensitivity(xml, name, state) \ { \ GtkWidget *widget; \ @@ -144,10 +141,13 @@ struct _TotemObject { char *player_title; + /* Playlist */ + TotemPlaylist *playlist; + GSignalGroup *playlist_signals; + /* other */ char *mrl; char *next_subtitle; - TotemPlaylist *playlist; GSettings *settings; TotemStates state; TotemOpenLocation *open_location; diff --git a/src/totem-session.c b/src/totem-session.c index ba5a42780..fa6c8f471 100644 --- a/src/totem-session.c +++ b/src/totem-session.c @@ -56,7 +56,7 @@ totem_session_try_restore (Totem *totem) char *uri; char *mrl, *subtitle; - totem_signal_block_by_data (totem->playlist, totem); + g_signal_group_block (totem->playlist_signals); totem->pause_start = TRUE; /* Possibly the only place in Totem where it makes sense to add an MRL to the playlist synchronously, since we haven't yet entered @@ -64,14 +64,14 @@ totem_session_try_restore (Totem *totem) uri = get_session_filename (); if (totem_playlist_add_mrl_sync (totem->playlist, uri) == FALSE) { totem->pause_start = FALSE; - totem_signal_unblock_by_data (totem->playlist, totem); + g_signal_group_unblock (totem->playlist_signals); totem_object_set_mrl (totem, NULL, NULL); g_free (uri); return FALSE; } g_free (uri); - totem_signal_unblock_by_data (totem->playlist, totem); + g_signal_group_unblock (totem->playlist_signals); subtitle = NULL; mrl = totem_playlist_get_current_mrl (totem->playlist, &subtitle); |