ges-formatter: Check if directory of URI is writeable

https://bugzilla.gnome.org/show_bug.cgi?id=679941
This commit is contained in:
Paul Lange 2012-07-20 14:19:01 +02:00 committed by Thibault Saunier
parent eab86c2913
commit 9d30f05798

View file

@ -276,6 +276,10 @@ ges_formatter_can_load_uri (const gchar * uri, GError ** error)
gboolean
ges_formatter_can_save_uri (const gchar * uri, GError ** error)
{
GFile *file = NULL;
GFile *dir = NULL;
GFileInfo *info = NULL;
if (!(gst_uri_is_valid (uri))) {
GST_ERROR ("%s invalid uri!", uri);
return FALSE;
@ -288,6 +292,39 @@ ges_formatter_can_save_uri (const gchar * uri, GError ** error)
return FALSE;
}
/* Check if URI or parent directory is writeable */
file = g_file_new_for_uri (uri);
if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL)
== G_FILE_TYPE_DIRECTORY) {
dir = file;
} else {
dir = g_file_get_parent (file);
if (dir == NULL)
return FALSE;
}
info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
G_FILE_QUERY_INFO_NONE, NULL, error);
if (error && *error != NULL) {
GST_ERROR ("Unable to write to directory: %s", (*error)->message);
return FALSE;
} else {
gboolean writeable = g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
if (!writeable) {
GST_ERROR ("Unable to write to directory");
return FALSE;
}
}
g_object_unref (file);
g_object_unref (dir);
g_object_unref (info);
/* TODO: implement file format registry */
/* TODO: search through the registry and chose a GESFormatter class that can
* handle the URI.*/