diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-02-21 10:33:53 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-02-21 11:20:21 +0100 |
commit | 8798e299f23c7263fd57636edcd4df583db130c9 (patch) | |
tree | e895c051ba47b4af22f6d1271fee15fdd16bc28b | |
parent | bf75e8f16a5b8b55f9d5ab86734bf6054074d25f (diff) | |
download | totem-8798e299f23c7263fd57636edcd4df583db130c9.tar.gz |
rotation: Stop using intermediate private struct
-rw-r--r-- | src/plugins/rotation/totem-rotation.c | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/src/plugins/rotation/totem-rotation.c b/src/plugins/rotation/totem-rotation.c index 087915a09..743c9035f 100644 --- a/src/plugins/rotation/totem-rotation.c +++ b/src/plugins/rotation/totem-rotation.c @@ -43,13 +43,15 @@ #define STATE_COUNT 4 typedef struct { + PeasExtensionBase parent; + TotemObject *totem; GtkWidget *bvw; GCancellable *cancellable; GSimpleAction *rotate_left_action; GSimpleAction *rotate_right_action; -} TotemRotationPluginPrivate; +} TotemRotationPlugin; TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_ROTATION_PLUGIN, TotemRotationPlugin, totem_rotation_plugin) @@ -72,27 +74,26 @@ store_state_cb (GObject *source_object, static void store_state (TotemRotationPlugin *pi) { - TotemRotationPluginPrivate *priv = pi->priv; BvwRotation rotation; char *rotation_s; GFileInfo *info; char *mrl; GFile *file; - rotation = bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (priv->bvw)); + rotation = bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (pi->bvw)); rotation_s = g_strdup_printf ("%u", rotation); info = g_file_info_new (); g_file_info_set_attribute_string (info, GIO_ROTATION_FILE_ATTRIBUTE, rotation_s); g_free (rotation_s); - mrl = totem_object_get_current_mrl (priv->totem); + mrl = totem_object_get_current_mrl (pi->totem); file = g_file_new_for_uri (mrl); g_free (mrl); g_file_set_attributes_async (file, info, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, - priv->cancellable, + pi->cancellable, store_state_cb, pi); g_object_unref (file); @@ -126,7 +127,7 @@ restore_state_cb (GObject *source_object, goto out; rotation = atoi (rotation_s); - bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (pi->priv->bvw), rotation); + bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (pi->bvw), rotation); out: g_object_unref (info); @@ -135,11 +136,10 @@ out: static void restore_state (TotemRotationPlugin *pi) { - TotemRotationPluginPrivate *priv = pi->priv; char *mrl; GFile *file; - mrl = totem_object_get_current_mrl (priv->totem); + mrl = totem_object_get_current_mrl (pi->totem); file = g_file_new_for_uri (mrl); g_free (mrl); @@ -147,7 +147,7 @@ restore_state (TotemRotationPlugin *pi) GIO_ROTATION_FILE_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, - priv->cancellable, + pi->cancellable, restore_state_cb, pi); g_object_unref (file); @@ -157,14 +157,12 @@ static void update_state (TotemRotationPlugin *pi, const char *mrl) { - TotemRotationPluginPrivate *priv = pi->priv; - if (mrl == NULL) { - g_simple_action_set_enabled (priv->rotate_left_action, FALSE); - g_simple_action_set_enabled (priv->rotate_right_action, FALSE); + g_simple_action_set_enabled (pi->rotate_left_action, FALSE); + g_simple_action_set_enabled (pi->rotate_right_action, FALSE); } else { - g_simple_action_set_enabled (priv->rotate_left_action, TRUE); - g_simple_action_set_enabled (priv->rotate_right_action, TRUE); + g_simple_action_set_enabled (pi->rotate_left_action, TRUE); + g_simple_action_set_enabled (pi->rotate_right_action, TRUE); restore_state (pi); } } @@ -175,11 +173,10 @@ cb_rotate_left (GSimpleAction *simple, gpointer user_data) { TotemRotationPlugin *pi = user_data; - TotemRotationPluginPrivate *priv = pi->priv; int state; - state = (bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (priv->bvw)) - 1) % STATE_COUNT; - bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (priv->bvw), state); + state = (bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (pi->bvw)) - 1) % STATE_COUNT; + bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (pi->bvw), state); store_state (pi); } @@ -189,11 +186,10 @@ cb_rotate_right (GSimpleAction *simple, gpointer user_data) { TotemRotationPlugin *pi = user_data; - TotemRotationPluginPrivate *priv = pi->priv; int state; - state = (bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (priv->bvw)) + 1) % STATE_COUNT; - bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (priv->bvw), state); + state = (bacon_video_widget_get_rotation (BACON_VIDEO_WIDGET (pi->bvw)) + 1) % STATE_COUNT; + bacon_video_widget_set_rotation (BACON_VIDEO_WIDGET (pi->bvw), state); store_state (pi); } @@ -216,44 +212,43 @@ static void impl_activate (PeasActivatable *plugin) { TotemRotationPlugin *pi = TOTEM_ROTATION_PLUGIN (plugin); - TotemRotationPluginPrivate *priv = pi->priv; GMenu *menu; GMenuItem *item; char *mrl; const char * const rotate_cw[]= { "<Primary>r", NULL }; const char * const rotate_ccw[]= { "<Primary><Shift>r", NULL }; - priv->totem = g_object_get_data (G_OBJECT (plugin), "object"); - priv->bvw = totem_object_get_video_widget (priv->totem); - priv->cancellable = g_cancellable_new (); + pi->totem = g_object_get_data (G_OBJECT (plugin), "object"); + pi->bvw = totem_object_get_video_widget (pi->totem); + pi->cancellable = g_cancellable_new (); - g_signal_connect (priv->totem, + g_signal_connect (pi->totem, "file-opened", G_CALLBACK (totem_rotation_file_opened), plugin); - g_signal_connect (priv->totem, + g_signal_connect (pi->totem, "file-closed", G_CALLBACK (totem_rotation_file_closed), plugin); /* add UI */ - menu = totem_object_get_menu_section (priv->totem, "rotation-placeholder"); + menu = totem_object_get_menu_section (pi->totem, "rotation-placeholder"); - priv->rotate_left_action = g_simple_action_new ("rotate-left", NULL); - g_signal_connect (G_OBJECT (priv->rotate_left_action), "activate", + pi->rotate_left_action = g_simple_action_new ("rotate-left", NULL); + g_signal_connect (G_OBJECT (pi->rotate_left_action), "activate", G_CALLBACK (cb_rotate_left), pi); - g_action_map_add_action (G_ACTION_MAP (priv->totem), - G_ACTION (priv->rotate_left_action)); - gtk_application_set_accels_for_action (GTK_APPLICATION (priv->totem), + g_action_map_add_action (G_ACTION_MAP (pi->totem), + G_ACTION (pi->rotate_left_action)); + gtk_application_set_accels_for_action (GTK_APPLICATION (pi->totem), "app.rotate-left", rotate_ccw); - priv->rotate_right_action = g_simple_action_new ("rotate-right", NULL); - g_signal_connect (G_OBJECT (priv->rotate_right_action), "activate", + pi->rotate_right_action = g_simple_action_new ("rotate-right", NULL); + g_signal_connect (G_OBJECT (pi->rotate_right_action), "activate", G_CALLBACK (cb_rotate_right), pi); - g_action_map_add_action (G_ACTION_MAP (priv->totem), - G_ACTION (priv->rotate_right_action)); - gtk_application_set_accels_for_action (GTK_APPLICATION (priv->totem), + g_action_map_add_action (G_ACTION_MAP (pi->totem), + G_ACTION (pi->rotate_right_action)); + gtk_application_set_accels_for_action (GTK_APPLICATION (pi->totem), "app.rotate-right", rotate_cw); @@ -265,7 +260,7 @@ impl_activate (PeasActivatable *plugin) g_menu_item_set_attribute (item, "accel", "s", "<Primary><Shift>R"); g_menu_append_item (G_MENU (menu), item); - mrl = totem_object_get_current_mrl (priv->totem); + mrl = totem_object_get_current_mrl (pi->totem); update_state (pi, mrl); g_free (mrl); } @@ -274,28 +269,27 @@ static void impl_deactivate (PeasActivatable *plugin) { TotemRotationPlugin *pi = TOTEM_ROTATION_PLUGIN (plugin); - TotemRotationPluginPrivate *priv = pi->priv; const char * const accels[] = { NULL }; - if (priv->cancellable != NULL) { - g_cancellable_cancel (priv->cancellable); - g_clear_object (&priv->cancellable); + if (pi->cancellable != NULL) { + g_cancellable_cancel (pi->cancellable); + g_clear_object (&pi->cancellable); } - g_signal_handlers_disconnect_by_func (priv->totem, totem_rotation_file_opened, plugin); - g_signal_handlers_disconnect_by_func (priv->totem, totem_rotation_file_closed, plugin); + g_signal_handlers_disconnect_by_func (pi->totem, totem_rotation_file_opened, plugin); + g_signal_handlers_disconnect_by_func (pi->totem, totem_rotation_file_closed, plugin); - gtk_application_set_accels_for_action (GTK_APPLICATION (priv->totem), + gtk_application_set_accels_for_action (GTK_APPLICATION (pi->totem), "app.rotate-right", accels); - gtk_application_set_accels_for_action (GTK_APPLICATION (priv->totem), + gtk_application_set_accels_for_action (GTK_APPLICATION (pi->totem), "app.rotate-left", accels); - totem_object_empty_menu_section (priv->totem, "rotation-placeholder"); - g_action_map_remove_action (G_ACTION_MAP (priv->totem), "rotate-left"); - g_action_map_remove_action (G_ACTION_MAP (priv->totem), "rotate-right"); + totem_object_empty_menu_section (pi->totem, "rotation-placeholder"); + g_action_map_remove_action (G_ACTION_MAP (pi->totem), "rotate-left"); + g_action_map_remove_action (G_ACTION_MAP (pi->totem), "rotate-right"); - priv->totem = NULL; - priv->bvw = NULL; + pi->totem = NULL; + pi->bvw = NULL; } |