Commit 894cf70d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Added infrastructure to make sure we don't write to the global brush,

2004-01-28  Michael Natterer  <mitch@gimp.org>

	Added infrastructure to make sure we don't write to the global
	brush, pattern etc. directories. Needed to make this configurable
	because we can't rely on the global directories being read-only,
	having certain names or being otherwise detectable at runtime in a
	sane way. Fixes bug #132214.

	* libgimpbase/gimpdatafiles.[ch]: added "const gchar *dirname" to
	the GimpDataFileData struct so callbacks don't need to call
	g_path_get_dirname() for each file.

	* libgimpwidgets/gimpfileentry.c: made it work with non UTF-8
	encoded filenames.

	* libgimpwidgets/gimppatheditor.[ch]: ditto. Added GUI and API for
	setting/getting a second "writable_path". The widget makes sure
	that the writable_path is always a subset of the path.

	* app/config/gimpconfig-utils.[ch]: added new function
	gimp_config_build_writable_path().

	* app/config/gimpcoreconfig.[ch]: added separate properties for
	the writable brush, pattern, gradient, palette and font paths.

	* app/config/gimprc-blurbs.h: added (still empty) blurbs for the
	new properties.

	* app/core/gimpdata.[ch] (gimp_data_set_filename): added parameter
	"gboolean writable". Set data->writable to FALSE by default. If
	"writable" is passed as TRUE, still check if we can write to the
	file before setting data->writable to TRUE.

	(gimp_data_create_filename): changed "data_path" parameter to
	"dest_dir" and assume dest_dir is writable.

	(gimp_data_duplicate): set data->dirty to TRUE to make sure
	duplicated things will be saved.

	* app/core/gimpbrush.c
	* app/core/gimpbrushgenerated.c
	* app/core/gimpbrushpipe.c
	* app/core/gimpgradient.c
	* app/core/gimppalette.c
	* app/core/gimppattern.c: don't set the data's filename and don't
	touch data->dirty in the _load() functions because that's done by
	the data factory now. Don't touch data->dirty in the _duplicate()
	functions because that's done by gimp_data_duplicate() itself now.

	* app/core/gimpdatafactory.[ch] (gimp_data_factory_new): added
	"writable_property_name" and remember it.
	Added utility function gimp_data_factory_get_save_dir() which
	determines the directory to save new datas to.
	Added public function gimp_data_factory_data_save_single() which
	saves a single data object.
	Make sure new things get saved to the first writable directory
	as specified in preferences.

	* app/core/gimp.c (gimp_real_initialize): pass the writable_paths'
	property names to gimp_data_factory_new().

	* app/widgets/gimpdataeditor.c (gimp_data_editor_save_dirty): use
	gimp_data_factory_data_save_single() instead of implementing
	saving here.

	* app/widgets/gimppropwidgets.[ch] (gimp_prop_path_editor_new):
	added "const gchar *writable_property_name" parameter (can be
	NULL).

	Added the needed callbacks to handle the writable_path and made
	the path_editor and file_entry code aware of non UTF-8 filename
	encodings. Some general cleanup.

	* app/gui/preferences-dialog.c: changed accordingly.
parent 6ab5abcd
2004-01-28 Michael Natterer <mitch@gimp.org>
Added infrastructure to make sure we don't write to the global
brush, pattern etc. directories. Needed to make this configurable
because we can't rely on the global directories being read-only,
having certain names or being otherwise detectable at runtime in a
sane way. Fixes bug #132214.
* libgimpbase/gimpdatafiles.[ch]: added "const gchar *dirname" to
the GimpDataFileData struct so callbacks don't need to call
g_path_get_dirname() for each file.
* libgimpwidgets/gimpfileentry.c: made it work with non UTF-8
encoded filenames.
* libgimpwidgets/gimppatheditor.[ch]: ditto. Added GUI and API for
setting/getting a second "writable_path". The widget makes sure
that the writable_path is always a subset of the path.
* app/config/gimpconfig-utils.[ch]: added new function
gimp_config_build_writable_path().
* app/config/gimpcoreconfig.[ch]: added separate properties for
the writable brush, pattern, gradient, palette and font paths.
* app/config/gimprc-blurbs.h: added (still empty) blurbs for the
new properties.
* app/core/gimpdata.[ch] (gimp_data_set_filename): added parameter
"gboolean writable". Set data->writable to FALSE by default. If
"writable" is passed as TRUE, still check if we can write to the
file before setting data->writable to TRUE.
(gimp_data_create_filename): changed "data_path" parameter to
"dest_dir" and assume dest_dir is writable.
(gimp_data_duplicate): set data->dirty to TRUE to make sure
duplicated things will be saved.
* app/core/gimpbrush.c
* app/core/gimpbrushgenerated.c
* app/core/gimpbrushpipe.c
* app/core/gimpgradient.c
* app/core/gimppalette.c
* app/core/gimppattern.c: don't set the data's filename and don't
touch data->dirty in the _load() functions because that's done by
the data factory now. Don't touch data->dirty in the _duplicate()
functions because that's done by gimp_data_duplicate() itself now.
* app/core/gimpdatafactory.[ch] (gimp_data_factory_new): added
"writable_property_name" and remember it.
Added utility function gimp_data_factory_get_save_dir() which
determines the directory to save new datas to.
Added public function gimp_data_factory_data_save_single() which
saves a single data object.
Make sure new things get saved to the first writable directory
as specified in preferences.
* app/core/gimp.c (gimp_real_initialize): pass the writable_paths'
property names to gimp_data_factory_new().
* app/widgets/gimpdataeditor.c (gimp_data_editor_save_dirty): use
gimp_data_factory_data_save_single() instead of implementing
saving here.
* app/widgets/gimppropwidgets.[ch] (gimp_prop_path_editor_new):
added "const gchar *writable_property_name" parameter (can be
NULL).
Added the needed callbacks to handle the writable_path and made
the path_editor and file_entry code aware of non UTF-8 filename
encodings. Some general cleanup.
* app/gui/preferences-dialog.c: changed accordingly.
2004-01-28 Sven Neumann <sven@gimp.org>
* configure.in: according to the automake docs, we need to add
......@@ -442,6 +442,12 @@ gimp_config_build_data_path (const gchar *name)
NULL);
}
gchar *
gimp_config_build_writable_path (const gchar *name)
{
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
}
gchar *
gimp_config_build_plug_in_path (const gchar *name)
{
......
......@@ -42,6 +42,7 @@ void gimp_config_string_append_escaped (GString *string,
const gchar *val);
gchar * gimp_config_build_data_path (const gchar *name);
gchar * gimp_config_build_writable_path (const gchar *name);
gchar * gimp_config_build_plug_in_path (const gchar *name);
gboolean gimp_config_file_copy (const gchar *source,
......
......@@ -76,10 +76,15 @@ enum
PROP_MODULE_PATH,
PROP_ENVIRON_PATH,
PROP_BRUSH_PATH,
PROP_BRUSH_PATH_WRITABLE,
PROP_PATTERN_PATH,
PROP_PATTERN_PATH_WRITABLE,
PROP_PALETTE_PATH,
PROP_PALETTE_PATH_WRITABLE,
PROP_GRADIENT_PATH,
PROP_GRADIENT_PATH_WRITABLE,
PROP_FONT_PATH,
PROP_FONT_PATH_WRITABLE,
PROP_DEFAULT_BRUSH,
PROP_DEFAULT_PATTERN,
PROP_DEFAULT_PALETTE,
......@@ -167,26 +172,56 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_data_path ("brushes"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_BRUSH_PATH_WRITABLE,
"brush-path-writable",
BRUSH_PATH_WRITABLE_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_writable_path ("brushes"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PATTERN_PATH,
"pattern-path", PATTERN_PATH_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_data_path ("patterns"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PATTERN_PATH_WRITABLE,
"pattern-path-writable",
PATTERN_PATH_WRITABLE_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_writable_path ("patterns"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PALETTE_PATH,
"palette-path", PALETTE_PATH_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_data_path ("palettes"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PALETTE_PATH_WRITABLE,
"palette-path-writable",
PALETTE_PATH_WRITABLE_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_writable_path ("palettes"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRADIENT_PATH,
"gradient-path", GRADIENT_PATH_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_data_path ("gradients"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRADIENT_PATH_WRITABLE,
"gradient-path-writable",
GRADIENT_PATH_WRITABLE_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_writable_path ("gradients"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_FONT_PATH,
"font-path", FONT_PATH_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_data_path ("fonts"),
0);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_FONT_PATH_WRITABLE,
"font-path-writable",
FONT_PATH_WRITABLE_BLURB,
GIMP_PARAM_PATH_DIR_LIST,
gimp_config_build_writable_path ("fonts"),
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_DEFAULT_BRUSH,
"default-brush", DEFAULT_BRUSH_BLURB,
DEFAULT_BRUSH,
......@@ -278,10 +313,15 @@ gimp_core_config_finalize (GObject *object)
g_free (core_config->module_path);
g_free (core_config->environ_path);
g_free (core_config->brush_path);
g_free (core_config->brush_path_writable);
g_free (core_config->pattern_path);
g_free (core_config->pattern_path_writable);
g_free (core_config->palette_path);
g_free (core_config->palette_path_writable);
g_free (core_config->gradient_path);
g_free (core_config->gradient_path_writable);
g_free (core_config->font_path);
g_free (core_config->font_path_writable);
g_free (core_config->default_brush);
g_free (core_config->default_pattern);
g_free (core_config->default_palette);
......@@ -327,22 +367,42 @@ gimp_core_config_set_property (GObject *object,
g_free (core_config->brush_path);
core_config->brush_path = g_value_dup_string (value);
break;
case PROP_BRUSH_PATH_WRITABLE:
g_free (core_config->brush_path_writable);
core_config->brush_path_writable = g_value_dup_string (value);
break;
case PROP_PATTERN_PATH:
g_free (core_config->pattern_path);
core_config->pattern_path = g_value_dup_string (value);
break;
case PROP_PATTERN_PATH_WRITABLE:
g_free (core_config->pattern_path_writable);
core_config->pattern_path_writable = g_value_dup_string (value);
break;
case PROP_PALETTE_PATH:
g_free (core_config->palette_path);
core_config->palette_path = g_value_dup_string (value);
break;
case PROP_PALETTE_PATH_WRITABLE:
g_free (core_config->palette_path_writable);
core_config->palette_path_writable = g_value_dup_string (value);
break;
case PROP_GRADIENT_PATH:
g_free (core_config->gradient_path);
core_config->gradient_path = g_value_dup_string (value);
break;
case PROP_GRADIENT_PATH_WRITABLE:
g_free (core_config->gradient_path_writable);
core_config->gradient_path_writable = g_value_dup_string (value);
break;
case PROP_FONT_PATH:
g_free (core_config->font_path);
core_config->font_path = g_value_dup_string (value);
break;
case PROP_FONT_PATH_WRITABLE:
g_free (core_config->font_path_writable);
core_config->font_path_writable = g_value_dup_string (value);
break;
case PROP_DEFAULT_BRUSH:
g_free (core_config->default_brush);
core_config->default_brush = g_value_dup_string (value);
......@@ -430,18 +490,33 @@ gimp_core_config_get_property (GObject *object,
case PROP_BRUSH_PATH:
g_value_set_string (value, core_config->brush_path);
break;
case PROP_BRUSH_PATH_WRITABLE:
g_value_set_string (value, core_config->brush_path_writable);
break;
case PROP_PATTERN_PATH:
g_value_set_string (value, core_config->pattern_path);
break;
case PROP_PATTERN_PATH_WRITABLE:
g_value_set_string (value, core_config->pattern_path_writable);
break;
case PROP_PALETTE_PATH:
g_value_set_string (value, core_config->palette_path);
break;
case PROP_PALETTE_PATH_WRITABLE:
g_value_set_string (value, core_config->palette_path_writable);
break;
case PROP_GRADIENT_PATH:
g_value_set_string (value, core_config->gradient_path);
break;
case PROP_GRADIENT_PATH_WRITABLE:
g_value_set_string (value, core_config->gradient_path_writable);
break;
case PROP_FONT_PATH:
g_value_set_string (value, core_config->font_path);
break;
case PROP_FONT_PATH_WRITABLE:
g_value_set_string (value, core_config->font_path_writable);
break;
case PROP_DEFAULT_BRUSH:
g_value_set_string (value, core_config->default_brush);
break;
......
......@@ -45,10 +45,15 @@ struct _GimpCoreConfig
gchar *module_path;
gchar *environ_path;
gchar *brush_path;
gchar *brush_path_writable;
gchar *pattern_path;
gchar *pattern_path_writable;
gchar *palette_path;
gchar *palette_path_writable;
gchar *gradient_path;
gchar *gradient_path_writable;
gchar *font_path;
gchar *font_path_writable;
gchar *default_brush;
gchar *default_pattern;
gchar *default_palette;
......
......@@ -17,6 +17,8 @@ N_("When enabled, an image will become the active image when its image " \
#define BRUSH_PATH_BLURB \
"Sets the brush search path."
#define BRUSH_PATH_WRITABLE_BLURB ""
#define CANVAS_PADDING_MODE_BLURB \
N_("Specifies how the area around the image should be drawn.")
......@@ -111,9 +113,13 @@ N_("The window type hint that is set on dock windows. This may affect " \
#define GRADIENT_PATH_BLURB \
"Sets the gradient search path."
#define GRADIENT_PATH_WRITABLE_BLURB ""
#define FONT_PATH_BLURB \
"Where to look for fonts."
#define FONT_PATH_WRITABLE_BLURB ""
#define HELP_BROWSER_BLURB \
N_("Sets the browser used by the help system.")
......@@ -180,9 +186,13 @@ N_("On multiprocessor machines, if GIMP has been compiled with --enable-mp " \
#define PALETTE_PATH_BLURB \
"Sets the palette search path."
#define PALETTE_PATH_WRITABLE_BLURB ""
#define PATTERN_PATH_BLURB \
"Sets the pattern search path."
#define PATTERN_PATH_WRITABLE_BLURB ""
#define PERFECT_MOUSE_BLURB \
N_("When enabled, the X server is queried for the mouse's current position " \
"on each motion event, rather than relying on the position hint. This " \
......
......@@ -596,7 +596,7 @@ gimp_real_initialize (Gimp *gimp,
gimp->brush_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_BRUSH,
"brush_path",
"brush-path", "brush-path-writable",
brush_loader_entries,
G_N_ELEMENTS (brush_loader_entries),
gimp_brush_new,
......@@ -606,7 +606,7 @@ gimp_real_initialize (Gimp *gimp,
gimp->pattern_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_PATTERN,
"pattern_path",
"pattern-path", "pattern-path-writable",
pattern_loader_entries,
G_N_ELEMENTS (pattern_loader_entries),
gimp_pattern_new,
......@@ -616,7 +616,7 @@ gimp_real_initialize (Gimp *gimp,
gimp->gradient_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_GRADIENT,
"gradient_path",
"gradient-path", "gradient-path-writable",
gradient_loader_entries,
G_N_ELEMENTS (gradient_loader_entries),
gimp_gradient_new,
......@@ -626,7 +626,7 @@ gimp_real_initialize (Gimp *gimp,
gimp->palette_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_PALETTE,
"palette_path",
"palette-path", "palette-path-writable",
palette_loader_entries,
G_N_ELEMENTS (palette_loader_entries),
gimp_palette_new,
......
......@@ -423,8 +423,6 @@ gimp_brush_load (const gchar *filename,
if (! brush)
return NULL;
gimp_data_set_filename (GIMP_DATA (brush), filename);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
{
......@@ -434,8 +432,6 @@ gimp_brush_load (const gchar *filename,
temp_buf_swap (brush->pixmap);
}
GIMP_DATA (brush)->dirty = FALSE;
return GIMP_DATA (brush);
}
......
......@@ -423,8 +423,6 @@ gimp_brush_load (const gchar *filename,
if (! brush)
return NULL;
gimp_data_set_filename (GIMP_DATA (brush), filename);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
{
......@@ -434,8 +432,6 @@ gimp_brush_load (const gchar *filename,
temp_buf_swap (brush->pixmap);
}
GIMP_DATA (brush)->dirty = FALSE;
return GIMP_DATA (brush);
}
......
......@@ -407,8 +407,6 @@ gimp_brush_generated_load (const gchar *filename,
/* create new brush */
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
gimp_data_set_filename (GIMP_DATA (brush), filename);
gimp_brush_generated_freeze (brush);
/* read name */
......@@ -444,8 +442,6 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
GIMP_DATA (brush)->dirty = FALSE;
return GIMP_DATA (brush);
}
......
......@@ -407,8 +407,6 @@ gimp_brush_generated_load (const gchar *filename,
/* create new brush */
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
gimp_data_set_filename (GIMP_DATA (brush), filename);
gimp_brush_generated_freeze (brush);
/* read name */
......@@ -444,8 +442,6 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
GIMP_DATA (brush)->dirty = FALSE;
return GIMP_DATA (brush);
}
......
......@@ -407,8 +407,6 @@ gimp_brush_generated_load (const gchar *filename,
/* create new brush */
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
gimp_data_set_filename (GIMP_DATA (brush), filename);
gimp_brush_generated_freeze (brush);
/* read name */
......@@ -444,8 +442,6 @@ gimp_brush_generated_load (const gchar *filename,
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
GIMP_DATA (brush)->dirty = FALSE;
return GIMP_DATA (brush);
}
......
......@@ -503,11 +503,11 @@ gimp_brush_pipe_load (const gchar *filename,
pipe->nbrushes++;
}
close (fd);
/* Current brush is the first one. */
pipe->current = pipe->brushes[0];
gimp_data_set_filename (GIMP_DATA (pipe), filename);
/* just to satisfy the code that relies on this crap */
GIMP_BRUSH (pipe)->spacing = pipe->current->spacing;
GIMP_BRUSH (pipe)->x_axis = pipe->current->x_axis;
......@@ -515,9 +515,5 @@ gimp_brush_pipe_load (const gchar *filename,
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
close (fd);
GIMP_DATA (pipe)->dirty = FALSE;
return GIMP_DATA (pipe);
}
......@@ -503,11 +503,11 @@ gimp_brush_pipe_load (const gchar *filename,
pipe->nbrushes++;
}
close (fd);
/* Current brush is the first one. */
pipe->current = pipe->brushes[0];
gimp_data_set_filename (GIMP_DATA (pipe), filename);
/* just to satisfy the code that relies on this crap */
GIMP_BRUSH (pipe)->spacing = pipe->current->spacing;
GIMP_BRUSH (pipe)->x_axis = pipe->current->x_axis;
......@@ -515,9 +515,5 @@ gimp_brush_pipe_load (const gchar *filename,
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
close (fd);
GIMP_DATA (pipe)->dirty = FALSE;
return GIMP_DATA (pipe);
}
......@@ -145,9 +145,7 @@ gimp_data_init (GimpData *data)
static void
gimp_data_finalize (GObject *object)
{
GimpData *data;
data = GIMP_DATA (object);
GimpData *data = GIMP_DATA (object);
if (data->filename)
{
......@@ -171,11 +169,9 @@ static gint64
gimp_data_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpData *data;
GimpData *data = GIMP_DATA (object);
gint64 memsize = 0;
data = GIMP_DATA (object);
if (data->filename)
memsize += strlen (data->filename) + 1;
......@@ -260,42 +256,47 @@ gimp_data_get_extension (GimpData *data)
void
gimp_data_set_filename (GimpData *data,
const gchar *filename)
const gchar *filename,
gboolean writable)
{
g_return_if_fail (GIMP_IS_DATA (data));
g_return_if_fail (filename != NULL);
g_return_if_fail (g_path_is_absolute (filename));
if (data->internal)
return;
g_free (data->filename);
if (data->filename)
{
g_free (data->filename);
data->filename = NULL;
}
data->filename = NULL;
data->writeable = TRUE;
data->filename = g_strdup (filename);
data->writeable = FALSE;
if (filename)
/* if the data is supposed to be writable, still check if it really is */
if (writable)
{
data->filename = g_strdup (filename);
gchar *dirname = g_path_get_dirname (filename);
if (access (filename, W_OK) && /* check if the file is writeable */
access (filename, F_OK) == 0) /* or doesn't exist */
if ((access (filename, F_OK) == 0 && /* check if the file exists */
access (filename, W_OK) == 0) || /* and is writeable */
(access (filename, F_OK) != 0 && /* OR doesn't exist */
access (dirname, W_OK) == 0)) /* and we can write to its dir */
{
gchar *dirname = g_path_get_dirname (filename);
if (access (dirname, W_OK | X_OK)) /* check if we can write to the dir */
data->writeable = FALSE;
g_free (dirname);
data->writeable = TRUE;
}
g_free (dirname);
}
}
void
gimp_data_create_filename (GimpData *data,
const gchar *basename,
const gchar *data_path)
const gchar *dest_dir)
{
GList *path;
gchar *dir;
gchar *filename;
gchar *fullpath;
gchar *safe_name;
......@@ -304,27 +305,18 @@ gimp_data_create_filename (GimpData *data,
g_return_if_fail (GIMP_IS_DATA (data));
g_return_if_fail (basename != NULL);
g_return_if_fail (data_path != NULL);
path = gimp_path_parse (data_path, 16, TRUE, NULL);
dir = gimp_path_get_user_writable_dir (path);
gimp_path_free (path);
if (! dir)
return;
g_return_if_fail (dest_dir != NULL);
safe_name = g_strdup (basename);
if (safe_name[0] == '.')
safe_name[0] = '_';
safe_name[0] = '-';
for (i = 0; safe_name[i]; i++)
if (safe_name[i] == G_DIR_SEPARATOR || g_ascii_isspace (safe_name[i]))
safe_name[i] = '_';
safe_name[i] = '-';
filename = g_strdup_printf ("%s%s",
safe_name,
gimp_data_get_extension (data));
filename = g_strconcat (safe_name, gimp_data_get_extension (data), NULL);
fullpath = g_build_filename (dir, filename, NULL);
fullpath = g_build_filename (dest_dir, filename, NULL);
g_free (filename);
......@@ -337,15 +329,14 @@ gimp_data_create_filename (GimpData *data,
unum++,
gimp_data_get_extension (data));
fullpath = g_build_filename (dir, filename, NULL);
fullpath = g_build_filename (dest_dir, filename, NULL);
g_free (filename);
}
g_free (dir);
g_free (safe_name);
gimp_data_set_filename (data, fullpath);
gimp_data_set_filename (data, fullpath, TRUE);
g_free (fullpath);
}
......@@ -354,12 +345,19 @@ GimpData *
gimp_data_duplicate (GimpData *data,
gboolean stingy_memory_use)
{
GimpData *new = NULL;
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
if (GIMP_DATA_GET_CLASS (data)->duplicate)
return GIMP_DATA_GET_CLASS (data)->duplicate (data, stingy_memory_use);
{
new = GIMP_DATA_GET_CLASS (data)->duplicate (data, stingy_memory_use);
return NULL;
if (new)
new->dirty = TRUE;
}
return new;
}
GQuark
......
......@@ -83,10 +83,11 @@ 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);
const gchar *filename,
gboolean writable);
void gimp_data_create_filename (GimpData *data,
const gchar *basename,
const gchar *data_path);
const gchar *dest_dir);
GimpData * gimp_data_duplicate (GimpData *data,
gboolean stingy_memory_use);
......
......@@ -42,16 +42,20 @@
#include "gimp-intl.h"
static void gimp_data_factory_class_init (GimpDataFactoryClass *klass);
static void gimp_data_factory_init (GimpDataFactory *factory);
#define WRITABLE_PATH_KEY "gimp-data-factory-writable-path"
static void gimp_data_factory_finalize (GObject *object);
static gint64 gimp_data_factory_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_data_factory_class_init (GimpDataFactoryClass *klass);
static void gimp_data_factory_init (GimpDataFactory *factory);
static void gimp_data_factory_load_data (const GimpDatafileData *file_data,
gpointer user_data);
static void gimp_data_factory_finalize (GObject *object);
static gint64 gimp_data_factory_get_memsize (GimpObject *object,
gint64 *gui_size);
static gchar * gimp_data_factory_get_save_dir (GimpDataFactory *factory);
static void gimp_data_factory_load_data (const GimpDatafileData *file_data,
gpointer user_data);
static GimpObjectClass *parent_class = NULL;
......@@ -107,6 +111,7 @@ gimp_data_factory_init (GimpDataFactory *factory)
factory->gimp = NULL;
factory->container = NULL;
factory->path_property_name = NULL;
factory->writable_property_name = NULL;
factory->loader_entries = NULL;
factory->n_loader_entries = 0;
factory->data_new_func = NULL;
......@@ -132,6 +137,12 @@ gimp_data_factory_finalize (GObject *object)
factory->path_property_name = NULL;
}
if (factory->writable_property_name)
{
g_free (factory->writable_property_name);
factory->writable_property_name = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -155,6 +166,7 @@ GimpDataFactory *
gimp_data_factory_new (Gimp *gimp,
GType data_type,
const gchar *path_property_name,
const gchar *writable_property_name,
const GimpDataFactoryLoaderEntry *loader_entries,
gint n_loader_entries,
GimpDataNewFunc new_func,
......@@ -165,6 +177,7 @@ gimp_data_factory_new (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
g_return_val_if_fail (path_property_name != NULL, NULL);
g_return_val_if_fail (writable_property_name != NULL, NULL);
g_return_val_if_fail (loader_entries != NULL, NULL);
g_return_val_if_fail (n_loader_entries > 0, NULL);
......@@ -174,6 +187,7 @@ gimp_data_factory_new (Gimp *gimp,
factory->container = gimp_data_list_new (data_type);
factory->path_property_name = g_strdup (path_property_name);
factory->writable_property_name = g_strdup (writable_property_name);