[gimp] app: turn GimpData's "filename" string into a "file" GFile
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: turn GimpData's "filename" string into a "file" GFile
- Date: Mon, 30 Jun 2014 23:23:32 +0000 (UTC)
commit 9696e297ac4e91bb468a245512cad63aca769f47
Author: Michael Natterer <mitch gimp org>
Date: Tue Jul 1 01:19:35 2014 +0200
app: turn GimpData's "filename" string into a "file" GFile
One more step, but for now just causes more code in most places to get
to the path inside the GFile.
app/actions/brushes-actions.c | 14 +-
app/actions/data-commands.c | 17 +--
app/actions/dynamics-actions.c | 6 +-
app/actions/gradients-actions.c | 6 +-
app/actions/palettes-actions.c | 12 +-
app/actions/patterns-actions.c | 14 +-
app/actions/tool-presets-actions.c | 6 +-
app/core/gimpbrushgenerated-save.c | 9 +-
app/core/gimpcurve-save.c | 9 +-
app/core/gimpdata.c | 232 ++++++++++++++++++++----------------
app/core/gimpdata.h | 7 +-
app/core/gimpdatafactory.c | 26 +++--
app/core/gimpdynamics-save.c | 18 ++-
app/core/gimpgradient-save.c | 9 +-
app/core/gimppalette-save.c | 9 +-
app/core/gimptoolpreset-save.c | 18 ++-
16 files changed, 241 insertions(+), 171 deletions(-)
---
diff --git a/app/actions/brushes-actions.c b/app/actions/brushes-actions.c
index e71d1ee..5bc473d 100644
--- a/app/actions/brushes-actions.c
+++ b/app/actions/brushes-actions.c
@@ -107,10 +107,10 @@ void
brushes_actions_update (GimpActionGroup *group,
gpointer user_data)
{
- GimpContext *context = action_data_get_context (user_data);
- GimpBrush *brush = NULL;
- GimpData *data = NULL;
- const gchar *filename = NULL;
+ GimpContext *context = action_data_get_context (user_data);
+ GimpBrush *brush = NULL;
+ GimpData *data = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -125,7 +125,7 @@ brushes_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (brush);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -133,9 +133,9 @@ brushes_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
SET_SENSITIVE ("brushes-edit", brush);
- SET_SENSITIVE ("brushes-open-as-image", brush && filename && ! GIMP_IS_BRUSH_GENERATED (brush));
+ SET_SENSITIVE ("brushes-open-as-image", brush && file && ! GIMP_IS_BRUSH_GENERATED (brush));
SET_SENSITIVE ("brushes-duplicate", brush && GIMP_DATA_GET_CLASS (data)->duplicate);
- SET_SENSITIVE ("brushes-copy-location", brush && filename);
+ SET_SENSITIVE ("brushes-copy-location", brush && file);
SET_SENSITIVE ("brushes-delete", brush && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/actions/data-commands.c b/app/actions/data-commands.c
index 7479d4b..5d2dda8 100644
--- a/app/actions/data-commands.c
+++ b/app/actions/data-commands.c
@@ -69,9 +69,9 @@ data_open_as_image_cmd_callback (GtkAction *action,
gimp_context_get_by_type (context,
gimp_data_factory_view_get_children_type (view));
- if (data && gimp_data_get_filename (data))
+ if (data && gimp_data_get_file (data))
{
- gchar *uri = g_filename_to_uri (gimp_data_get_filename (data), NULL, NULL);
+ gchar *uri = g_file_get_uri (gimp_data_get_file (data));
if (uri)
{
@@ -182,17 +182,14 @@ data_copy_location_cmd_callback (GtkAction *action,
if (data)
{
- const gchar *filename = gimp_data_get_filename (data);
+ GFile *file = gimp_data_get_file (data);
- if (filename && *filename)
+ if (file)
{
- gchar *uri = g_filename_to_uri (filename, NULL, NULL);
+ gchar *uri = g_file_get_uri (file);
- if (uri)
- {
- gimp_clipboard_set_text (context->gimp, uri);
- g_free (uri);
- }
+ gimp_clipboard_set_text (context->gimp, uri);
+ g_free (uri);
}
}
}
diff --git a/app/actions/dynamics-actions.c b/app/actions/dynamics-actions.c
index 72f61f1..58af11d 100644
--- a/app/actions/dynamics-actions.c
+++ b/app/actions/dynamics-actions.c
@@ -104,7 +104,7 @@ dynamics_actions_update (GimpActionGroup *group,
GimpContext *context = action_data_get_context (user_data);
GimpDynamics *dynamics = NULL;
GimpData *data = NULL;
- const gchar *filename = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -114,7 +114,7 @@ dynamics_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (dynamics);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -123,7 +123,7 @@ dynamics_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("dynamics-edit", dynamics);
SET_SENSITIVE ("dynamics-duplicate", dynamics && GIMP_DATA_GET_CLASS (data)->duplicate);
- SET_SENSITIVE ("dynamics-copy-location", dynamics && filename);
+ SET_SENSITIVE ("dynamics-copy-location", dynamics && file);
SET_SENSITIVE ("dynamics-delete", dynamics && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/actions/gradients-actions.c b/app/actions/gradients-actions.c
index 5fa9e0e..1d796b4 100644
--- a/app/actions/gradients-actions.c
+++ b/app/actions/gradients-actions.c
@@ -111,7 +111,7 @@ gradients_actions_update (GimpActionGroup *group,
GimpContext *context = action_data_get_context (user_data);
GimpGradient *gradient = NULL;
GimpData *data = NULL;
- const gchar *filename = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -126,7 +126,7 @@ gradients_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (gradient);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -136,7 +136,7 @@ gradients_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("gradients-edit", gradient);
SET_SENSITIVE ("gradients-duplicate", gradient);
SET_SENSITIVE ("gradients-save-as-pov", gradient);
- SET_SENSITIVE ("gradients-copy-location", gradient && filename);
+ SET_SENSITIVE ("gradients-copy-location", gradient && file);
SET_SENSITIVE ("gradients-delete", gradient && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/actions/palettes-actions.c b/app/actions/palettes-actions.c
index a8235e0..a49e58d 100644
--- a/app/actions/palettes-actions.c
+++ b/app/actions/palettes-actions.c
@@ -114,10 +114,10 @@ void
palettes_actions_update (GimpActionGroup *group,
gpointer user_data)
{
- GimpContext *context = action_data_get_context (user_data);
- GimpPalette *palette = NULL;
- GimpData *data = NULL;
- const gchar *filename = NULL;
+ GimpContext *context = action_data_get_context (user_data);
+ GimpPalette *palette = NULL;
+ GimpData *data = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -132,7 +132,7 @@ palettes_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (palette);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -142,7 +142,7 @@ palettes_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("palettes-edit", palette);
SET_SENSITIVE ("palettes-duplicate", palette && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("palettes-merge", FALSE); /* FIXME palette && GIMP_IS_CONTAINER_LIST_VIEW
(editor->view)); */
- SET_SENSITIVE ("palettes-copy-location", palette && filename);
+ SET_SENSITIVE ("palettes-copy-location", palette && file);
SET_SENSITIVE ("palettes-delete", palette && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/actions/patterns-actions.c b/app/actions/patterns-actions.c
index 1fbac31..7f9e1c0 100644
--- a/app/actions/patterns-actions.c
+++ b/app/actions/patterns-actions.c
@@ -107,10 +107,10 @@ void
patterns_actions_update (GimpActionGroup *group,
gpointer user_data)
{
- GimpContext *context = action_data_get_context (user_data);
- GimpPattern *pattern = NULL;
- GimpData *data = NULL;
- const gchar *filename = NULL;
+ GimpContext *context = action_data_get_context (user_data);
+ GimpPattern *pattern = NULL;
+ GimpData *data = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -125,7 +125,7 @@ patterns_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (pattern);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -133,9 +133,9 @@ patterns_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
SET_SENSITIVE ("patterns-edit", pattern && FALSE);
- SET_SENSITIVE ("patterns-open-as-image", pattern && filename);
+ SET_SENSITIVE ("patterns-open-as-image", pattern && file);
SET_SENSITIVE ("patterns-duplicate", pattern && GIMP_DATA_GET_CLASS (data)->duplicate);
- SET_SENSITIVE ("patterns-copy-location", pattern && filename);
+ SET_SENSITIVE ("patterns-copy-location", pattern && file);
SET_SENSITIVE ("patterns-delete", pattern && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/actions/tool-presets-actions.c b/app/actions/tool-presets-actions.c
index 6e66d5f..9692c06 100644
--- a/app/actions/tool-presets-actions.c
+++ b/app/actions/tool-presets-actions.c
@@ -106,7 +106,7 @@ tool_presets_actions_update (GimpActionGroup *group,
GimpContext *context = action_data_get_context (user_data);
GimpToolPreset *tool_preset = NULL;
GimpData *data = NULL;
- const gchar *filename = NULL;
+ GFile *file = NULL;
if (context)
{
@@ -116,7 +116,7 @@ tool_presets_actions_update (GimpActionGroup *group,
{
data = GIMP_DATA (tool_preset);
- filename = gimp_data_get_filename (data);
+ file = gimp_data_get_file (data);
}
}
@@ -125,7 +125,7 @@ tool_presets_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("tool-presets-edit", tool_preset);
SET_SENSITIVE ("tool-presets-duplicate", tool_preset && GIMP_DATA_GET_CLASS (data)->duplicate);
- SET_SENSITIVE ("tool-presets-copy-location", tool_preset && filename);
+ SET_SENSITIVE ("tool-presets-copy-location", tool_preset && file);
SET_SENSITIVE ("tool-presets-delete", tool_preset && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c
index 89ae977..661640c 100644
--- a/app/core/gimpbrushgenerated-save.c
+++ b/app/core/gimpbrushgenerated-save.c
@@ -47,23 +47,28 @@ gimp_brush_generated_save (GimpData *data,
{
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
const gchar *name = gimp_object_get_name (data);
+ gchar *path;
FILE *file;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gboolean have_shape = FALSE;
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
- file = g_fopen (gimp_data_get_filename (data), "wb");
+ path = g_file_get_path (gimp_data_get_file (data));
+ file = g_fopen (path, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (gimp_data_get_filename (data)),
+ gimp_filename_to_utf8 (path),
g_strerror (errno));
+ g_free (path);
return FALSE;
}
+ g_free (path);
+
/* write magic header */
fprintf (file, "GIMP-VBR\n");
diff --git a/app/core/gimpcurve-save.c b/app/core/gimpcurve-save.c
index 37b262a..59563a0 100644
--- a/app/core/gimpcurve-save.c
+++ b/app/core/gimpcurve-save.c
@@ -38,6 +38,7 @@ gimp_curve_save (GimpData *data,
GError **error)
{
/* GimpCurve *curve; */
+ gchar *path;
FILE *file;
g_return_val_if_fail (GIMP_IS_CURVE (data), FALSE);
@@ -45,17 +46,21 @@ gimp_curve_save (GimpData *data,
/* curve = GIMP_CURVE (data); */
- file = g_fopen (gimp_data_get_filename (data), "wb");
+ path = g_file_get_path (gimp_data_get_file (data));
+ file = g_fopen (path, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (gimp_data_get_filename (data)),
+ gimp_filename_to_utf8 (path),
g_strerror (errno));
+ g_free (path);
return FALSE;
}
+ g_free (path);
+
/* FIXME: write curve */
fclose (file);
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index 9db220f..dffb151 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -57,7 +57,7 @@ enum
enum
{
PROP_0,
- PROP_FILENAME,
+ PROP_FILE,
PROP_WRITABLE,
PROP_DELETABLE,
PROP_MIME_TYPE
@@ -68,7 +68,7 @@ typedef struct _GimpDataPrivate GimpDataPrivate;
struct _GimpDataPrivate
{
- gchar *filename;
+ GFile *file;
GQuark mime_type;
guint writable : 1;
guint deletable : 1;
@@ -193,9 +193,9 @@ gimp_data_class_init (GimpDataClass *klass)
klass->get_extension = NULL;
klass->duplicate = NULL;
- g_object_class_install_property (object_class, PROP_FILENAME,
- g_param_spec_string ("filename", NULL, NULL,
- NULL,
+ g_object_class_install_property (object_class, PROP_FILE,
+ g_param_spec_object ("file", NULL, NULL,
+ G_TYPE_FILE,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_WRITABLE,
@@ -260,10 +260,10 @@ gimp_data_finalize (GObject *object)
{
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
- if (private->filename)
+ if (private->file)
{
- g_free (private->filename);
- private->filename = NULL;
+ g_object_unref (private->file);
+ private->file = NULL;
}
if (private->tags)
@@ -292,11 +292,11 @@ gimp_data_set_property (GObject *object,
switch (property_id)
{
- case PROP_FILENAME:
- gimp_data_set_filename (data,
- g_value_get_string (value),
- private->writable,
- private->deletable);
+ case PROP_FILE:
+ gimp_data_set_file (data,
+ g_value_get_object (value),
+ private->writable,
+ private->deletable);
break;
case PROP_WRITABLE:
@@ -330,8 +330,8 @@ gimp_data_get_property (GObject *object,
switch (property_id)
{
- case PROP_FILENAME:
- g_value_set_string (value, private->filename);
+ case PROP_FILE:
+ g_value_set_object (value, private->file);
break;
case PROP_WRITABLE:
@@ -370,7 +370,7 @@ gimp_data_get_memsize (GimpObject *object,
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
gint64 memsize = 0;
- memsize += gimp_string_get_memsize (private->filename);
+ memsize += gimp_g_object_get_memsize (G_OBJECT (private->file));
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@@ -443,39 +443,42 @@ gimp_data_get_identifier (GimpTagged *tagged)
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged);
gchar *identifier = NULL;
- if (private->filename)
+ if (private->file)
{
const gchar *data_dir = gimp_data_directory ();
const gchar *gimp_dir = gimp_directory ();
+ gchar *path = g_file_get_path (private->file);
gchar *tmp;
- if (g_str_has_prefix (private->filename, data_dir))
+ if (g_str_has_prefix (path, data_dir))
{
tmp = g_strconcat ("${gimp_data_dir}",
- private->filename + strlen (data_dir),
+ path + strlen (data_dir),
NULL);
identifier = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
g_free (tmp);
}
- else if (g_str_has_prefix (private->filename, gimp_dir))
+ else if (g_str_has_prefix (path, gimp_dir))
{
tmp = g_strconcat ("${gimp_dir}",
- private->filename + strlen (gimp_dir),
+ path + strlen (gimp_dir),
NULL);
identifier = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
g_free (tmp);
}
else
{
- identifier = g_filename_to_utf8 (private->filename, -1,
+ identifier = g_filename_to_utf8 (path, -1,
NULL, NULL, NULL);
}
if (! identifier)
{
- g_warning ("Failed to convert '%s' to utf8.\n", private->filename);
- identifier = g_strdup (private->filename);
+ g_warning ("Failed to convert '%s' to utf8.\n", path);
+ identifier = g_strdup (path);
}
+
+ g_free (path);
}
else if (private->internal)
{
@@ -496,11 +499,11 @@ gimp_data_get_checksum (GimpTagged *tagged)
* @data: object whose contents are to be saved.
* @error: return location for errors or %NULL
*
- * Save the object. If the object is marked as "internal", nothing happens.
- * Otherwise, it is saved to disk, using the file name set by
- * gimp_data_set_filename(). If the save is successful, the
- * object is marked as not dirty. If not, an error message is returned
- * using the @error argument.
+ * Save the object. If the object is marked as "internal", nothing
+ * happens. Otherwise, it is saved to disk, using the file name set
+ * by gimp_data_set_file(). If the save is successful, the object is
+ * marked as not dirty. If not, an error message is returned using
+ * the @error argument.
*
* Returns: %TRUE if the object is internal or the save is successful.
**/
@@ -524,15 +527,15 @@ gimp_data_save (GimpData *data,
return TRUE;
}
- g_return_val_if_fail (private->filename != NULL, FALSE);
+ g_return_val_if_fail (private->file != NULL, FALSE);
if (GIMP_DATA_GET_CLASS (data)->save)
success = GIMP_DATA_GET_CLASS (data)->save (data, error);
if (success)
{
- GFile *file = g_file_new_for_path (private->filename);
- GFileInfo *info = g_file_query_info (file, "time::*",
+ GFileInfo *info = g_file_query_info (private->file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
if (info)
@@ -543,8 +546,6 @@ gimp_data_save (GimpData *data,
g_object_unref (info);
}
- g_object_unref (file);
-
private->dirty = FALSE;
}
@@ -661,7 +662,7 @@ gimp_data_is_frozen (GimpData *data)
*
* Deletes the object from disk. If the object is marked as "internal",
* nothing happens. Otherwise, if the file exists whose name has been
- * set by gimp_data_set_filename(), it is deleted. Obviously this is
+ * set by gimp_data_set_file(), it is deleted. Obviously this is
* a potentially dangerous function, which should be used with care.
*
* Returns: %TRUE if the object is internal to Gimp, or the deletion is
@@ -678,22 +679,13 @@ gimp_data_delete_from_disk (GimpData *data,
private = GIMP_DATA_GET_PRIVATE (data);
- g_return_val_if_fail (private->filename != NULL, FALSE);
+ g_return_val_if_fail (private->file != NULL, FALSE);
g_return_val_if_fail (private->deletable == TRUE, FALSE);
if (private->internal)
return TRUE;
- if (g_unlink (private->filename) == -1)
- {
- g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_DELETE,
- _("Could not delete '%s': %s"),
- gimp_filename_to_utf8 (private->filename),
- g_strerror (errno));
- return FALSE;
- }
-
- return TRUE;
+ return g_file_delete (private->file, NULL, error);
}
const gchar *
@@ -708,39 +700,46 @@ gimp_data_get_extension (GimpData *data)
}
/**
- * gimp_data_set_filename:
+ * gimp_data_set_file:
* @data: A #GimpData object
- * @filename: File name to assign to @data.
+ * @file: File to assign to @data.
* @writable: %TRUE if we want to be able to write to this file.
* @deletable: %TRUE if we want to be able to delete this file.
*
- * This function assigns a file name to @data, and sets some flags
+ * This function assigns a file to @data, and sets some flags
* according to the properties of the file. If @writable is %TRUE,
- * and the user has permission to write or overwrite the requested file
- * name, and a "save" method exists for @data's object type, then
+ * and the user has permission to write or overwrite the requested
+ * file name, and a "save" method exists for @data's object type, then
* @data is marked as writable.
**/
void
-gimp_data_set_filename (GimpData *data,
- const gchar *filename,
- gboolean writable,
- gboolean deletable)
+gimp_data_set_file (GimpData *data,
+ GFile *file,
+ gboolean writable,
+ gboolean deletable)
{
GimpDataPrivate *private;
+ gchar *path;
g_return_if_fail (GIMP_IS_DATA (data));
- g_return_if_fail (filename != NULL);
- g_return_if_fail (g_path_is_absolute (filename));
+ g_return_if_fail (G_IS_FILE (file));
+
+ path = g_file_get_path (file);
+
+ g_return_if_fail (path != NULL);
+ g_return_if_fail (g_path_is_absolute (path));
+
+ g_free (path);
private = GIMP_DATA_GET_PRIVATE (data);
if (private->internal)
return;
- if (private->filename)
- g_free (private->filename);
+ if (private->file)
+ g_object_unref (private->file);
- private->filename = g_strdup (filename);
+ private->file = g_object_ref (file);
private->writable = FALSE;
private->deletable = FALSE;
@@ -749,18 +748,44 @@ gimp_data_set_filename (GimpData *data,
*/
if (writable || deletable)
{
- gchar *dirname = g_path_get_dirname (filename);
+ GFileInfo *info;
- if ((g_access (filename, F_OK) == 0 && /* check if the file exists */
- g_access (filename, W_OK) == 0) || /* and is writable */
- (g_access (filename, F_OK) != 0 && /* OR doesn't exist */
- g_access (dirname, W_OK) == 0)) /* and we can write to its dir */
+ if (g_file_query_exists (private->file, NULL)) /* check if it exists */
{
- private->writable = writable ? TRUE : FALSE;
- private->deletable = deletable ? TRUE : FALSE;
+ info = g_file_query_info (private->file,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+
+ /* and we can write it */
+ if (info &&
+ g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ {
+ private->writable = writable ? TRUE : FALSE;
+ private->deletable = deletable ? TRUE : FALSE;
+ }
+ }
+ else /* OR it doesn't exist */
+ {
+ GFile *parent = g_file_get_parent (private->file);
+
+ info = g_file_query_info (parent,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+
+ /* and we can write to its parent directory */
+ if (info &&
+ g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ {
+ private->writable = writable ? TRUE : FALSE;
+ private->deletable = deletable ? TRUE : FALSE;
+ }
+
+ g_object_unref (parent);
}
-
- g_free (dirname);
/* if we can't save, we are not writable */
if (! GIMP_DATA_GET_CLASS (data)->save)
@@ -768,6 +793,18 @@ gimp_data_set_filename (GimpData *data,
}
}
+GFile *
+gimp_data_get_file (GimpData *data)
+{
+ GimpDataPrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
+
+ private = GIMP_DATA_GET_PRIVATE (data);
+
+ return private->file;
+}
+
/**
* gimp_data_create_filename:
* @data: a #Gimpdata object.
@@ -785,8 +822,9 @@ gimp_data_create_filename (GimpData *data,
{
GimpDataPrivate *private;
gchar *safename;
- gchar *filename;
- gchar *fullpath;
+ gchar *basename;
+ gchar *path;
+ GFile *file;
gint i;
gint unum = 1;
GError *error = NULL;
@@ -820,43 +858,34 @@ gimp_data_create_filename (GimpData *data,
if (strchr ("\\/*?\"`'<>{}|\n\t ;:$^&", safename[i]))
safename[i] = '-';
- filename = g_strconcat (safename, gimp_data_get_extension (data), NULL);
+ basename = g_strconcat (safename, gimp_data_get_extension (data), NULL);
- fullpath = g_build_filename (dest_dir, filename, NULL);
+ path = g_build_filename (dest_dir, basename, NULL);
- g_free (filename);
+ g_free (basename);
- while (g_file_test (fullpath, G_FILE_TEST_EXISTS))
+ while (g_file_test (path, G_FILE_TEST_EXISTS))
{
- g_free (fullpath);
+ g_free (path);
- filename = g_strdup_printf ("%s-%d%s",
+ basename = g_strdup_printf ("%s-%d%s",
safename,
unum++,
gimp_data_get_extension (data));
- fullpath = g_build_filename (dest_dir, filename, NULL);
+ path = g_build_filename (dest_dir, basename, NULL);
- g_free (filename);
+ g_free (basename);
}
g_free (safename);
- gimp_data_set_filename (data, fullpath, TRUE, TRUE);
-
- g_free (fullpath);
-}
-
-const gchar *
-gimp_data_get_filename (GimpData *data)
-{
- GimpDataPrivate *private;
-
- g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
+ file = g_file_new_for_path (path);
+ g_free (path);
- private = GIMP_DATA_GET_PRIVATE (data);
+ gimp_data_set_file (data, file, TRUE, TRUE);
- return private->filename;
+ g_object_unref (file);
}
static const gchar *tag_blacklist[] = { "brushes",
@@ -886,6 +915,7 @@ gimp_data_set_folder_tags (GimpData *data,
const gchar *top_directory)
{
GimpDataPrivate *private;
+ gchar *path;
gchar *dirname;
g_return_if_fail (GIMP_IS_DATA (data));
@@ -895,9 +925,11 @@ gimp_data_set_folder_tags (GimpData *data,
if (private->internal)
return;
- g_return_if_fail (private->filename != NULL);
+ g_return_if_fail (private->file != NULL);
- dirname = g_path_get_dirname (private->filename);
+ path = g_file_get_path (private->file);
+ dirname = g_path_get_dirname (path);
+ g_free (path);
/* if this data is in a subfolder, walk up the hierarchy and
* set each folder on the way as tag, except the top_directory
@@ -1040,10 +1072,10 @@ gimp_data_duplicate (GimpData *data)
"deletable", TRUE,
NULL);
- if (private->filename)
+ if (private->file)
{
- g_free (private->filename);
- private->filename = NULL;
+ g_object_unref (private->file);
+ private->file = NULL;
}
return new;
@@ -1074,10 +1106,10 @@ gimp_data_make_internal (GimpData *data,
private = GIMP_DATA_GET_PRIVATE (data);
- if (private->filename)
+ if (private->file)
{
- g_free (private->filename);
- private->filename = NULL;
+ g_object_unref (private->file);
+ private->file = NULL;
}
private->identifier = g_strdup (identifier);
diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h
index fcecc68..a2173ae 100644
--- a/app/core/gimpdata.h
+++ b/app/core/gimpdata.h
@@ -82,13 +82,14 @@ gboolean gimp_data_delete_from_disk (GimpData *data,
const gchar * gimp_data_get_extension (GimpData *data);
-void gimp_data_set_filename (GimpData *data,
- const gchar *filename,
+void gimp_data_set_file (GimpData *data,
+ GFile *file,
gboolean writable,
gboolean deletable);
+GFile * gimp_data_get_file (GimpData *data);
+
void gimp_data_create_filename (GimpData *data,
const gchar *dest_dir);
-const gchar * gimp_data_get_filename (GimpData *data);
void gimp_data_set_folder_tags (GimpData *data,
const gchar *top_directory);
diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c
index 5851565..3d6e6f8 100644
--- a/app/core/gimpdatafactory.c
+++ b/app/core/gimpdatafactory.c
@@ -248,9 +248,9 @@ gimp_data_factory_refresh_cache_add (GimpDataFactory *factory,
GimpData *data,
gpointer user_data)
{
- const gchar *filename = gimp_data_get_filename (data);
+ GFile *file = gimp_data_get_file (data);
- if (filename)
+ if (file)
{
GHashTable *cache = user_data;
GList *list;
@@ -259,10 +259,10 @@ gimp_data_factory_refresh_cache_add (GimpDataFactory *factory,
gimp_container_remove (factory->priv->container, GIMP_OBJECT (data));
- list = g_hash_table_lookup (cache, filename);
+ list = g_hash_table_lookup (cache, file);
list = g_list_prepend (list, data);
- g_hash_table_insert (cache, (gpointer) filename, list);
+ g_hash_table_insert (cache, file, list);
}
}
@@ -385,7 +385,7 @@ gimp_data_factory_data_refresh (GimpDataFactory *factory,
/* First, save all dirty data objects */
gimp_data_factory_data_save (factory);
- cache = g_hash_table_new (g_str_hash, g_str_equal);
+ cache = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
gimp_data_factory_data_foreach (factory, TRUE,
gimp_data_factory_refresh_cache_add, cache);
@@ -439,7 +439,7 @@ gimp_data_factory_data_save (GimpDataFactory *factory)
{
GimpData *data = list->data;
- if (! gimp_data_get_filename (data))
+ if (! gimp_data_get_file (data))
gimp_data_create_filename (data, writable_dir);
if (gimp_data_is_dirty (data) &&
@@ -577,7 +577,7 @@ gimp_data_factory_data_delete (GimpDataFactory *factory,
gimp_container_remove (factory->priv->container, GIMP_OBJECT (data));
- if (delete_from_disk && gimp_data_get_filename (data))
+ if (delete_from_disk && gimp_data_get_file (data))
retval = gimp_data_delete_from_disk (data, error);
g_object_unref (data);
@@ -611,7 +611,7 @@ gimp_data_factory_data_save_single (GimpDataFactory *factory,
if (! gimp_data_is_dirty (data))
return TRUE;
- if (! gimp_data_get_filename (data))
+ if (! gimp_data_get_file (data))
{
gchar *writable_dir;
GError *my_error = NULL;
@@ -867,9 +867,11 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
insert:
if (cache)
{
+ GFile *file = g_file_new_for_path (file_data->filename);
GList *cached_data;
- cached_data = g_hash_table_lookup (cache, file_data->filename);
+ cached_data = g_hash_table_lookup (cache, file);
+ g_object_unref (file);
if (cached_data &&
gimp_data_get_mtime (cached_data->data) != 0 &&
@@ -914,11 +916,13 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
for (list = data_list; list; list = g_list_next (list))
{
GimpData *data = list->data;
+ GFile *file = g_file_new_for_path (file_data->filename);
- gimp_data_set_filename (data, file_data->filename,
- writable, deletable);
+ gimp_data_set_file (data, file, writable, deletable);
gimp_data_set_mtime (data, file_data->mtime);
+ g_object_unref (file);
+
gimp_data_clean (data);
if (obsolete)
diff --git a/app/core/gimpdynamics-save.c b/app/core/gimpdynamics-save.c
index a44640e..79eb4ed 100644
--- a/app/core/gimpdynamics-save.c
+++ b/app/core/gimpdynamics-save.c
@@ -32,12 +32,20 @@ gboolean
gimp_dynamics_save (GimpData *data,
GError **error)
{
+ gchar *path;
+ gboolean success;
+
g_return_val_if_fail (GIMP_IS_DYNAMICS (data), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return gimp_config_serialize_to_file (GIMP_CONFIG (data),
- gimp_data_get_filename (data),
- "GIMP dynamics file",
- "end of GIMP dynamics file",
- NULL, error);
+ path = g_file_get_path (gimp_data_get_file (data));
+
+ success = gimp_config_serialize_to_file (GIMP_CONFIG (data), path,
+ "GIMP dynamics file",
+ "end of GIMP dynamics file",
+ NULL, error);
+
+ g_free (path);
+
+ return success;
}
diff --git a/app/core/gimpgradient-save.c b/app/core/gimpgradient-save.c
index a7f496b..593fd8c 100644
--- a/app/core/gimpgradient-save.c
+++ b/app/core/gimpgradient-save.c
@@ -41,19 +41,24 @@ gimp_gradient_save (GimpData *data,
GimpGradient *gradient = GIMP_GRADIENT (data);
GimpGradientSegment *seg;
gint num_segments;
+ gchar *path;
FILE *file;
- file = g_fopen (gimp_data_get_filename (data), "wb");
+ path = g_file_get_path (gimp_data_get_file (data));
+ file = g_fopen (path, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (gimp_data_get_filename (data)),
+ gimp_filename_to_utf8 (path),
g_strerror (errno));
+ g_free (path);
return FALSE;
}
+ g_free (path);
+
/* File format is:
*
* GIMP Gradient
diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c
index 341076c..179e237 100644
--- a/app/core/gimppalette-save.c
+++ b/app/core/gimppalette-save.c
@@ -47,19 +47,24 @@ gimp_palette_save (GimpData *data,
{
GimpPalette *palette = GIMP_PALETTE (data);
GList *list;
+ gchar *path;
FILE *file;
- file = g_fopen (gimp_data_get_filename (data), "wb");
+ path = g_file_get_path (gimp_data_get_file (data));
+ file = g_fopen (path, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (gimp_data_get_filename (data)),
+ gimp_filename_to_utf8 (path),
g_strerror (errno));
+ g_free (path);
return FALSE;
}
+ g_free (path);
+
fprintf (file, "GIMP Palette\n");
fprintf (file, "Name: %s\n", gimp_object_get_name (palette));
fprintf (file, "Columns: %d\n#\n", CLAMP (gimp_palette_get_columns (palette),
diff --git a/app/core/gimptoolpreset-save.c b/app/core/gimptoolpreset-save.c
index 0e202b1..e2156d4 100644
--- a/app/core/gimptoolpreset-save.c
+++ b/app/core/gimptoolpreset-save.c
@@ -32,12 +32,20 @@ gboolean
gimp_tool_preset_save (GimpData *data,
GError **error)
{
+ gchar *path;
+ gboolean success;
+
g_return_val_if_fail (GIMP_IS_TOOL_PRESET (data), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return gimp_config_serialize_to_file (GIMP_CONFIG (data),
- gimp_data_get_filename (data),
- "GIMP tool preset file",
- "end of GIMP tool preset file",
- NULL, error);
+ path = g_file_get_path (gimp_data_get_file (data));
+
+ success = gimp_config_serialize_to_file (GIMP_CONFIG (data), path,
+ "GIMP tool preset file",
+ "end of GIMP tool preset file",
+ NULL, error);
+
+ g_free (path);
+
+ return success;
}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]