From f5ac7aa662e38ef8449ff0e32f0d198c7dcc52cf Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Tue, 28 Jan 2025 23:22:47 +0100 Subject: [PATCH 1/6] save-file: Use g_file_new_for_uri() instead if g_file_new_for_path() get_videos_dir_uri() return an uri and so we should use g_file_new_for_uri(). Otherwise the path returned by GFile is broken and so file_has_ancestor() always return False resulting by doing a copy of the media from the videos directory into this same directory. --- src/plugins/save-file/totem-save-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index ab93da670..acc551415 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -291,7 +291,7 @@ totem_save_file_file_opened (TotemObject *totem, /* Check whether it's in the Videos dir */ videos_dir = get_videos_dir_uri (); - videos_dir_file = g_file_new_for_path (videos_dir); + videos_dir_file = g_file_new_for_uri (videos_dir); if (file_has_ancestor (file, videos_dir_file)) { g_debug ("Not enabling offline save, as '%s' already in '%s'", mrl, videos_dir); g_object_unref (videos_dir_file); -- GitLab From 5d135c4fc677d3ddba22b6ac4589611e140ed0f5 Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Tue, 28 Jan 2025 23:29:00 +0100 Subject: [PATCH 2/6] save-file: Use g_file_has_prefix() instead of a reimplementation --- src/plugins/save-file/totem-save-file.c | 34 +------------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index acc551415..75b631173 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -228,38 +228,6 @@ totem_save_file_file_closed (TotemObject *totem, g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), FALSE); } -static gboolean -file_has_ancestor (GFile *file, - GFile *ancestor) -{ - GFile *cursor; - gboolean retval = FALSE; - - if (g_file_has_parent (file, ancestor)) - return TRUE; - - cursor = g_object_ref (file); - - while (1) { - GFile *tmp; - - tmp = g_file_get_parent (cursor); - g_object_unref (cursor); - cursor = tmp; - - if (cursor == NULL) - break; - - if (g_file_has_parent (cursor, ancestor)) { - g_object_unref (cursor); - retval = TRUE; - break; - } - } - - return retval; -} - static void totem_save_file_file_opened (TotemObject *totem, const char *mrl, @@ -292,7 +260,7 @@ totem_save_file_file_opened (TotemObject *totem, /* Check whether it's in the Videos dir */ videos_dir = get_videos_dir_uri (); videos_dir_file = g_file_new_for_uri (videos_dir); - if (file_has_ancestor (file, videos_dir_file)) { + if (g_file_has_prefix (file, videos_dir_file)) { g_debug ("Not enabling offline save, as '%s' already in '%s'", mrl, videos_dir); g_object_unref (videos_dir_file); g_free (videos_dir); -- GitLab From 08c4a3c941f97ff534c87f92ce8f31bfe67388f0 Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Wed, 29 Jan 2025 00:15:17 +0100 Subject: [PATCH 3/6] save-file: Remove the cache path and the compute of the checksum By allowing copying the cache mrl into the videos dir, we don't need anymore the media directory and the compute of the checksum for this mrl. --- src/plugins/save-file/totem-save-file.c | 82 ++----------------------- 1 file changed, 4 insertions(+), 78 deletions(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index 75b631173..7e34aa56f 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -110,16 +110,6 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, g_object_unref (proxy); } -static char * -get_cache_path (void) -{ - char *path; - - path = g_build_filename (g_get_user_cache_dir (), "totem", "media", NULL); - g_mkdir_with_parents (path, 0755); - return path; -} - static char * get_videos_dir_uri (void) { @@ -161,20 +151,6 @@ totem_save_file_get_filename (TotemSaveFilePlugin *pi) return filename; } -static char * -checksum_path_for_mrl (const char *mrl) -{ - char *dest_dir, *dest_name, *dest_path; - - dest_dir = get_cache_path (); - dest_name = g_compute_checksum_for_string (G_CHECKSUM_SHA256, mrl, -1); - dest_path = g_build_filename (dest_dir, dest_name, NULL); - g_free (dest_name); - g_free (dest_dir); - - return dest_path; -} - static void totem_save_file_plugin_copy (GSimpleAction *action, GVariant *parameter, @@ -233,8 +209,7 @@ totem_save_file_file_opened (TotemObject *totem, const char *mrl, TotemSaveFilePlugin *pi) { - GFile *cache_dir = NULL; - char *cache_path, *videos_dir; + char *videos_dir; GFile *file; g_clear_pointer (&pi->mrl, g_free); @@ -282,63 +257,20 @@ totem_save_file_file_opened (TotemObject *totem, g_free (path); } - /* Already cached? */ - cache_path = get_cache_path (); - cache_dir = g_file_new_for_path (cache_path); - g_free (cache_path); - if (g_file_has_parent (file, cache_dir)) { - g_debug ("Not enabling offline save, as '%s' already cached", mrl); - goto out; - } - 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); g_clear_object (&file); } -static void -cache_file_exists_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - TotemSaveFilePlugin *pi; - GFileInfo *info; - GError *error = NULL; - char *path; - - path = g_file_get_path (G_FILE (source_object)); - info = g_file_query_info_finish (G_FILE (source_object), res, &error); - 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->action), TRUE); - - g_debug ("Enabling offline save, as '%s' for '%s'", - path, pi->mrl); - } - g_free (path); - g_error_free (error); - return; - } - g_object_unref (info); - - pi = user_data; - g_debug ("Not enabling offline save, as '%s' already exists for '%s'", - path, pi->mrl); - g_free (path); -} - static void totem_save_file_download_filename (GObject *gobject, GParamSpec *pspec, TotemSaveFilePlugin *pi) { - char *filename, *cache_path; - GFile *file; + char *filename; /* We're already ready to copy it */ if (pi->cache_mrl != NULL) @@ -358,14 +290,8 @@ totem_save_file_download_filename (GObject *gobject, g_debug ("Cache MRL: '%s', name: '%s'", pi->cache_mrl, pi->name); - 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->cancellable, - cache_file_exists_cb, pi); - g_object_unref (file); + g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->action), TRUE); + g_debug ("Enabling offline save for '%s'", pi->cache_mrl); } static void -- GitLab From f9a17d354093d33ee51e840ef1a6e48ea9d04bf6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 6 Feb 2026 13:46:26 +0100 Subject: [PATCH 4/6] save-file: Don't use a hidden directory to save videos in When streaming a video, link the video from its cache directory to the Videos directory rather than putting it in a cache directory that's not easily accessible to the user. --- src/plugins/save-file/totem-save-file.c | 35 +++++++++---------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index 7e34aa56f..e2ed54ef3 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -156,41 +156,30 @@ totem_save_file_plugin_copy (GSimpleAction *action, GVariant *parameter, TotemSaveFilePlugin *pi) { - char *filename; + g_autofree char *filename = NULL; g_assert (pi->mrl != NULL); filename = totem_save_file_get_filename (pi); if (pi->is_tmp) { - char *src_path, *dest_path; + g_autofree char *src_path = NULL; + g_autofree char *dest_path = NULL; + int err; 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; - g_warning ("Failed to link '%s' to '%s': %s", - src_path, dest_path, g_strerror (err)); - } else { - GFile *file; - - g_debug ("Successfully linked '%s' to '%s'", - src_path, dest_path); + dest_path = g_build_filename (get_videos_dir_uri(), filename, NULL); - file = g_file_new_for_path (dest_path); - totem_object_add_to_view (pi->totem, file, filename); - g_object_unref (file); - } + if (link (src_path, dest_path) == 0) + return; - g_free (src_path); - g_free (dest_path); - } else { - 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 */ + err = errno; + g_debug ("Failed to link '%s' to '%s': %s", + src_path, dest_path, g_strerror (err)); } - g_free (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 */ } static void -- GitLab From ee63b75fe9f822942b885f5f4adcc50383666976 Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Sat, 1 Feb 2025 17:15:01 +0100 Subject: [PATCH 5/6] save-file: Remove support for natuilus < 3.30.0 --- src/plugins/save-file/totem-save-file.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index e2ed54ef3..1cdfc07cf 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -59,6 +59,8 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, g_return_if_fail (dest_dir != NULL); g_return_if_fail (dest_name != NULL); + const char *sources[2] = { source, NULL }; + flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, flags, @@ -83,23 +85,10 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, } ret = g_dbus_proxy_call_sync (proxy, - "CopyFile", g_variant_new ("(&s&s&s&s)", source, "", dest_dir, dest_name), + "CopyURIs", g_variant_new ("(^ass)", sources, dest_dir), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (ret == NULL) { - /* nautilus >= 3.30.0? */ - if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) { - const char *sources[2] = { source, NULL }; - - g_clear_error (&error); - ret = g_dbus_proxy_call_sync (proxy, - "CopyURIs", g_variant_new ("(^ass)", sources, dest_dir), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - } - } - if (ret == NULL) { g_warning ("Could not get nautilus to copy file: %s", error->message); g_error_free (error); -- GitLab From 2f8c36e45bda4277a13949235e4bfe5e970281b9 Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Sat, 1 Feb 2025 19:30:13 +0100 Subject: [PATCH 6/6] save-file: Use org.gnome.Nautilus.FileOperations2 interface org.gnome.Nautilus.FileOperations has been deprecated in nautilus 3.38 Closes: #647 --- src/plugins/save-file/totem-save-file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c index 1cdfc07cf..c492b0f14 100644 --- a/src/plugins/save-file/totem-save-file.c +++ b/src/plugins/save-file/totem-save-file.c @@ -66,8 +66,8 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, flags, NULL, /* GDBusInterfaceInfo */ "org.gnome.Nautilus", - "/org/gnome/Nautilus", - "org.gnome.Nautilus.FileOperations", + "/org/gnome/Nautilus/FileOperations2", + "org.gnome.Nautilus.FileOperations2", NULL, /* GCancellable */ &error); if (proxy == NULL) { @@ -85,7 +85,7 @@ copy_uris_with_nautilus (TotemSaveFilePlugin *pi, } ret = g_dbus_proxy_call_sync (proxy, - "CopyURIs", g_variant_new ("(^ass)", sources, dest_dir), + "CopyURIs", g_variant_new ("(^assa{sv})", sources, dest_dir, NULL), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); -- GitLab