summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-03-14 17:27:39 +0100
committerBastien Nocera <hadess@hadess.net>2014-03-14 17:27:39 +0100
commit208db5c3315a13ae4f085470c112231cd9c60b2c (patch)
treead59a3aaaeeba064b6b83a9656ae5c337d2509d7
parentc6763ae83cace2849918ffa8302174c0442b7cb8 (diff)
downloadtotem-208db5c3315a13ae4f085470c112231cd9c60b2c.tar.gz
save-file: Don't offer to save file in ~/Videos subdirs
We were only checking whether the file was a direct descendant of ~/Videos, instead of checking that ~/Videos was somewhere in its ancestors. This stops videos in ~/Videos subdirectories being made available for offline downloading. https://bugzilla.gnome.org/show_bug.cgi?id=725027
-rw-r--r--src/plugins/save-file/totem-save-file.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/plugins/save-file/totem-save-file.c b/src/plugins/save-file/totem-save-file.c
index 1b4bbcd7a..52c8c952d 100644
--- a/src/plugins/save-file/totem-save-file.c
+++ b/src/plugins/save-file/totem-save-file.c
@@ -195,6 +195,35 @@ totem_save_file_file_closed (TotemObject *totem,
g_simple_action_set_enabled (G_SIMPLE_ACTION (pi->priv->action), FALSE);
}
+static gboolean
+file_has_ancestor (GFile *file,
+ GFile *ancestor)
+{
+ GFile *cursor;
+ gboolean retval = FALSE;
+
+ 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,
@@ -223,7 +252,7 @@ totem_save_file_file_opened (TotemObject *totem,
/* We check whether it's in the Videos dir, in the future,
* we might want to check if it's native instead */
videos_dir = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS));
- if (g_file_has_parent (file, videos_dir)) {
+ if (file_has_ancestor (file, videos_dir)) {
g_debug ("Not enabling offline save, as '%s' already in ~/Videos", mrl);
goto out;
}