diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-02-21 10:34:03 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-02-21 11:20:21 +0100 |
commit | a819f86134be33bccc27631cf1b58d6c180bac97 (patch) | |
tree | 98885c3c1b1c332a5e72d5557e5b61833ce3e3a7 /src/plugins/save-file | |
parent | 8798e299f23c7263fd57636edcd4df583db130c9 (diff) | |
download | totem-a819f86134be33bccc27631cf1b58d6c180bac97.tar.gz |
save-file: Stop using intermediate private struct
Diffstat (limited to 'src/plugins/save-file')
-rw-r--r-- | src/plugins/save-file/totem-save-file.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index 7c80902c1..e9e08e54c 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -38,6 +38,8 @@ #define TOTEM_SAVE_FILE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_SAVE_FILE_PLUGIN, TotemSaveFilePlugin)) typedef struct { + PeasExtensionBase parent; + TotemObject *totem; GtkWidget *bvw; @@ -50,7 +52,7 @@ typedef struct { gboolean is_flatpaked; GSimpleAction *action; -} TotemSaveFilePluginPrivate; +} TotemSaveFilePlugin; TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_SAVE_FILE_PLUGIN, TotemSaveFilePlugin, totem_save_file_plugin) @@ -81,7 +83,7 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, if (proxy == NULL) { GtkWindow *main_window; - main_window = totem_object_get_main_window (pi->priv->totem); + main_window = totem_object_get_main_window (pi->totem); totem_interface_error (_("The video could not be made available offline."), /* translators: “Files” refers to nautilus' name */ _("“Files” is not available."), main_window); @@ -147,11 +149,11 @@ totem_save_file_get_filename (TotemSaveFilePlugin *pi) char *filename, *basename; GFile *file; - if (pi->priv->name != NULL) - return g_strdup (pi->priv->name); + if (pi->name != NULL) + return g_strdup (pi->name); /* Try to get a nice filename from the URI */ - file = g_file_new_for_uri (pi->priv->mrl); + file = g_file_new_for_uri (pi->mrl); basename = g_file_get_basename (file); g_object_unref (file); @@ -192,15 +194,15 @@ totem_save_file_plugin_copy (GSimpleAction *action, { char *filename; - g_assert (pi->priv->mrl != NULL); + g_assert (pi->mrl != NULL); filename = totem_save_file_get_filename (pi); - if (pi->priv->is_tmp) { + if (pi->is_tmp) { char *src_path, *dest_path; - src_path = g_filename_from_uri (pi->priv->cache_mrl, NULL, NULL); - dest_path = checksum_path_for_mrl (pi->priv->mrl); + src_path = g_filename_from_uri (pi->cache_mrl, NULL, NULL); + dest_path = checksum_path_for_mrl (pi->mrl); if (link (src_path, dest_path) != 0) { int err = errno; @@ -213,14 +215,14 @@ totem_save_file_plugin_copy (GSimpleAction *action, src_path, dest_path); file = g_file_new_for_path (dest_path); - totem_object_add_to_view (pi->priv->totem, file, filename); + totem_object_add_to_view (pi->totem, file, filename); g_object_unref (file); } g_free (src_path); g_free (dest_path); } else { - copy_uris_with_nautilus (pi, pi->priv->mrl, get_videos_dir_uri(), filename); + copy_uris_with_nautilus (pi, pi->mrl, get_videos_dir_uri(), filename); /* We don't call Totem to bookmark it, as Tracker should pick it up */ } @@ -231,11 +233,11 @@ static void totem_save_file_file_closed (TotemObject *totem, TotemSaveFilePlugin *pi) { - g_clear_pointer (&pi->priv->mrl, g_free); - g_clear_pointer (&pi->priv->cache_mrl, g_free); - g_clear_pointer (&pi->priv->name, g_free); + g_clear_pointer (&pi->mrl, g_free); + g_clear_pointer (&pi->cache_mrl, g_free); + g_clear_pointer (&pi->name, g_free); - g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->priv->action), FALSE); + g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), FALSE); } static gboolean @@ -279,13 +281,13 @@ totem_save_file_file_opened (TotemObject *totem, char *cache_path, *videos_dir; GFile *file; - g_clear_pointer (&pi->priv->mrl, g_free); - g_clear_pointer (&pi->priv->name, g_free); + g_clear_pointer (&pi->mrl, g_free); + g_clear_pointer (&pi->name, g_free); if (mrl == NULL) return; - pi->priv->mrl = g_strdup (mrl); + pi->mrl = g_strdup (mrl); /* We can only save files from file:/// and smb:/// URIs (for now) */ if (!g_str_has_prefix (mrl, "file:") && @@ -296,7 +298,7 @@ totem_save_file_file_opened (TotemObject *totem, file = g_file_new_for_uri (mrl); - if (pi->priv->is_flatpaked) { + if (pi->is_flatpaked) { GFile *videos_dir_file; /* Check whether it's in the Videos dir */ @@ -333,9 +335,9 @@ totem_save_file_file_opened (TotemObject *totem, goto out; } - g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->priv->action), TRUE); - pi->priv->name = totem_object_get_short_title (pi->priv->totem); - pi->priv->is_tmp = FALSE; + g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), TRUE); + pi->name = totem_object_get_short_title (pi->totem); + pi->is_tmp = FALSE; out: g_clear_object (&cache_dir); @@ -357,10 +359,10 @@ cache_file_exists_cb (GObject *source_object, if (!info) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { pi = user_data; - g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->priv->action), TRUE); + g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), TRUE); g_debug ("Enabling offline save, as '%s' for '%s'", - path, pi->priv->mrl); + path, pi->mrl); } g_free (path); g_error_free (error); @@ -370,7 +372,7 @@ cache_file_exists_cb (GObject *source_object, pi = user_data; g_debug ("Not enabling offline save, as '%s' already exists for '%s'", - path, pi->priv->mrl); + path, pi->mrl); g_free (path); } @@ -383,29 +385,29 @@ totem_save_file_download_filename (GObject *gobject, GFile *file; /* We're already ready to copy it */ - if (pi->priv->cache_mrl != NULL) + if (pi->cache_mrl != NULL) return; filename = NULL; - g_object_get (G_OBJECT (pi->priv->bvw), "download-filename", &filename, NULL); + g_object_get (G_OBJECT (pi->bvw), "download-filename", &filename, NULL); if (filename == NULL) return; g_debug ("download-filename changed to '%s'", filename); - pi->priv->cache_mrl = g_filename_to_uri (filename, NULL, NULL); + pi->cache_mrl = g_filename_to_uri (filename, NULL, NULL); g_free (filename); - pi->priv->name = totem_object_get_short_title (pi->priv->totem); - pi->priv->is_tmp = TRUE; + pi->name = totem_object_get_short_title (pi->totem); + pi->is_tmp = TRUE; - g_debug ("Cache MRL: '%s', name: '%s'", pi->priv->cache_mrl, pi->priv->name); + g_debug ("Cache MRL: '%s', name: '%s'", pi->cache_mrl, pi->name); - cache_path = checksum_path_for_mrl (pi->priv->mrl); + cache_path = checksum_path_for_mrl (pi->mrl); file = g_file_new_for_path (cache_path); g_free (cache_path); g_file_query_info_async (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NONE, 0, pi->priv->cancellable, + G_FILE_QUERY_INFO_NONE, 0, pi->cancellable, cache_file_exists_cb, pi); g_object_unref (file); } @@ -414,47 +416,46 @@ static void impl_activate (PeasActivatable *plugin) { TotemSaveFilePlugin *pi = TOTEM_SAVE_FILE_PLUGIN (plugin); - TotemSaveFilePluginPrivate *priv = pi->priv; GMenu *menu; GMenuItem *item; char *mrl; const char * const accels[] = { "<Primary>S", "Save", 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 (); - priv->is_flatpaked = g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS); + pi->totem = g_object_get_data (G_OBJECT (plugin), "object"); + pi->bvw = totem_object_get_video_widget (pi->totem); + pi->cancellable = g_cancellable_new (); + pi->is_flatpaked = g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS); - g_signal_connect (priv->totem, + g_signal_connect (pi->totem, "file-opened", G_CALLBACK (totem_save_file_file_opened), plugin); - g_signal_connect (priv->totem, + g_signal_connect (pi->totem, "file-closed", G_CALLBACK (totem_save_file_file_closed), plugin); - g_signal_connect (priv->bvw, + g_signal_connect (pi->bvw, "notify::download-filename", G_CALLBACK (totem_save_file_download_filename), plugin); - priv->action = g_simple_action_new ("save-as", NULL); - g_signal_connect (G_OBJECT (priv->action), "activate", + pi->action = g_simple_action_new ("save-as", NULL); + g_signal_connect (G_OBJECT (pi->action), "activate", G_CALLBACK (totem_save_file_plugin_copy), plugin); - g_action_map_add_action (G_ACTION_MAP (priv->totem), G_ACTION (priv->action)); - gtk_application_set_accels_for_action (GTK_APPLICATION (priv->totem), + g_action_map_add_action (G_ACTION_MAP (pi->totem), G_ACTION (pi->action)); + gtk_application_set_accels_for_action (GTK_APPLICATION (pi->totem), "app.save-as", accels); - g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->action), FALSE); + g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), FALSE); /* add UI */ - menu = totem_object_get_menu_section (priv->totem, "save-placeholder"); + menu = totem_object_get_menu_section (pi->totem, "save-placeholder"); item = g_menu_item_new (_("Make Available Offline"), "app.save-as"); g_menu_item_set_attribute (item, "accel", "s", "<Primary>s"); g_menu_append_item (G_MENU (menu), item); - mrl = totem_object_get_current_mrl (priv->totem); - totem_save_file_file_opened (priv->totem, mrl, pi); + mrl = totem_object_get_current_mrl (pi->totem); + totem_save_file_file_opened (pi->totem, mrl, pi); totem_save_file_download_filename (NULL, NULL, pi); g_free (mrl); } @@ -463,23 +464,22 @@ static void impl_deactivate (PeasActivatable *plugin) { TotemSaveFilePlugin *pi = TOTEM_SAVE_FILE_PLUGIN (plugin); - TotemSaveFilePluginPrivate *priv = pi->priv; - g_signal_handlers_disconnect_by_func (priv->totem, totem_save_file_file_opened, plugin); - g_signal_handlers_disconnect_by_func (priv->totem, totem_save_file_file_closed, plugin); - g_signal_handlers_disconnect_by_func (priv->bvw, totem_save_file_download_filename, plugin); + g_signal_handlers_disconnect_by_func (pi->totem, totem_save_file_file_opened, plugin); + g_signal_handlers_disconnect_by_func (pi->totem, totem_save_file_file_closed, plugin); + g_signal_handlers_disconnect_by_func (pi->bvw, totem_save_file_download_filename, plugin); - totem_object_empty_menu_section (priv->totem, "save-placeholder"); + totem_object_empty_menu_section (pi->totem, "save-placeholder"); - if (priv->cancellable) { - g_cancellable_cancel (priv->cancellable); - g_clear_object (&priv->cancellable); + if (pi->cancellable) { + g_cancellable_cancel (pi->cancellable); + g_clear_object (&pi->cancellable); } - priv->totem = NULL; - priv->bvw = NULL; + pi->totem = NULL; + pi->bvw = NULL; - g_clear_pointer (&pi->priv->mrl, g_free); - g_clear_pointer (&pi->priv->cache_mrl, g_free); - g_clear_pointer (&pi->priv->name, g_free); + g_clear_pointer (&pi->mrl, g_free); + g_clear_pointer (&pi->cache_mrl, g_free); + g_clear_pointer (&pi->name, g_free); } |