[gimp] app: port GimpImageMapTool's settings API from filename to GFile
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port GimpImageMapTool's settings API from filename to GFile
- Date: Tue, 1 Jul 2014 13:16:00 +0000 (UTC)
commit 8c8135a8812952e922a3d1243f4fcb5b8d5c99a2
Author: Michael Natterer <mitch gimp org>
Date: Tue Jul 1 15:13:02 2014 +0200
app: port GimpImageMapTool's settings API from filename to GFile
app/core/gimpmarshal.list | 1 +
app/tools/gimpcurvestool.c | 52 +++++++++-------
app/tools/gimpimagemapoptions.c | 13 ++--
app/tools/gimpimagemapoptions.h | 2 +-
app/tools/gimpimagemaptool-settings.c | 47 +++++++--------
app/tools/gimpimagemaptool-settings.h | 16 +++---
app/tools/gimpimagemaptool.c | 7 ++-
app/tools/gimpimagemaptool.h | 6 +-
app/tools/gimplevelstool.c | 52 +++++++++-------
app/tools/gimpoperationtool.c | 13 +++-
app/widgets/gimpsettingsbox.c | 105 ++++++++++++++++++---------------
app/widgets/gimpsettingsbox.h | 8 +-
12 files changed, 177 insertions(+), 145 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index f3a1069..668e9fd 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -24,6 +24,7 @@
BOOLEAN: BOOLEAN
BOOLEAN: ENUM, INT
+BOOLEAN: OBJECT
BOOLEAN: OBJECT, POINTER
BOOLEAN: OBJECT, POINTER, STRING
BOOLEAN: STRING
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index 840627a..9e34213 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -93,10 +93,10 @@ static GeglNode * gimp_curves_tool_get_operation (GimpImageMapTool *image_m
static void gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_curves_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_curves_tool_settings_import(GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
static gboolean gimp_curves_tool_settings_export(GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
static void gimp_curves_tool_export_setup (GimpSettingsBox *settings_box,
@@ -594,31 +594,34 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
static gboolean
gimp_curves_tool_settings_import (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
- FILE *file;
+ gchar *path;
+ FILE *f;
gchar header[64];
- file = g_fopen (filename, "rt");
+ path = g_file_get_path (file);
+ f = g_fopen (path, "rt");
+ g_free (path);
- if (! file)
+ if (! f)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
return FALSE;
}
- if (! fgets (header, sizeof (header), file))
+ if (! fgets (header, sizeof (header), f))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not read header from '%s': %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
- fclose (file);
+ fclose (f);
return FALSE;
}
@@ -626,54 +629,57 @@ gimp_curves_tool_settings_import (GimpImageMapTool *image_map_tool,
{
gboolean success;
- rewind (file);
+ rewind (f);
- success = gimp_curves_config_load_cruft (tool->config, file, error);
+ success = gimp_curves_config_load_cruft (tool->config, f, error);
- fclose (file);
+ fclose (f);
return success;
}
- fclose (file);
+ fclose (f);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_import (image_map_tool,
- filename,
+ file,
error);
}
static gboolean
gimp_curves_tool_settings_export (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
if (tool->export_old_format)
{
- FILE *file;
+ gchar *path;
+ FILE *f;
gboolean success;
- file = g_fopen (filename, "wt");
+ path = g_file_get_path (file);
+ f = g_fopen (path, "wt");
+ g_free (path);
- if (! file)
+ if (! f)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
return FALSE;
}
- success = gimp_curves_config_save_cruft (tool->config, file, error);
+ success = gimp_curves_config_save_cruft (tool->config, f, error);
- fclose (file);
+ fclose (f);
return success;
}
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
- filename,
+ file,
error);
}
diff --git a/app/tools/gimpimagemapoptions.c b/app/tools/gimpimagemapoptions.c
index 8186f8d..077f3ce 100644
--- a/app/tools/gimpimagemapoptions.c
+++ b/app/tools/gimpimagemapoptions.c
@@ -76,9 +76,9 @@ gimp_image_map_options_class_init (GimpImageMapOptionsClass *klass)
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SETTINGS,
- g_param_spec_string ("settings",
+ g_param_spec_object ("settings",
NULL, NULL,
- NULL,
+ G_TYPE_FILE,
GIMP_PARAM_READWRITE));
}
@@ -94,7 +94,7 @@ gimp_image_map_options_finalize (GObject *object)
if (options->settings)
{
- g_free (options->settings);
+ g_object_unref (options->settings);
options->settings = NULL;
}
@@ -121,8 +121,9 @@ gimp_image_map_options_set_property (GObject *object,
break;
case PROP_SETTINGS:
- g_free (options->settings);
- options->settings = g_value_dup_string (value);
+ if (options->settings)
+ g_object_unref (options->settings);
+ options->settings = g_value_dup_object (value);
break;
default:
@@ -150,7 +151,7 @@ gimp_image_map_options_get_property (GObject *object,
break;
case PROP_SETTINGS:
- g_value_set_string (value, options->settings);
+ g_value_set_object (value, options->settings);
break;
default:
diff --git a/app/tools/gimpimagemapoptions.h b/app/tools/gimpimagemapoptions.h
index 55425a3..1ca8388 100644
--- a/app/tools/gimpimagemapoptions.h
+++ b/app/tools/gimpimagemapoptions.h
@@ -38,7 +38,7 @@ struct _GimpImageMapOptions
gboolean preview;
GimpImageMapRegion region;
- gchar *settings;
+ GFile *settings;
};
diff --git a/app/tools/gimpimagemaptool-settings.c b/app/tools/gimpimagemaptool-settings.c
index f9ce8fe..d8ac0f0 100644
--- a/app/tools/gimpimagemaptool-settings.c
+++ b/app/tools/gimpimagemaptool-settings.c
@@ -50,10 +50,10 @@
/* local function prototypes */
static gboolean gimp_image_map_tool_settings_import (GimpSettingsBox *box,
- const gchar *filename,
+ GFile *file,
GimpImageMapTool *tool);
static gboolean gimp_image_map_tool_settings_export (GimpSettingsBox *box,
- const gchar *filename,
+ GFile *file,
GimpImageMapTool *tool);
@@ -62,7 +62,7 @@ static gboolean gimp_image_map_tool_settings_export (GimpSettingsBox *box,
GtkWidget *
gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool *image_map_tool,
GimpContainer *settings,
- const gchar *settings_filename,
+ GFile *settings_file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
@@ -89,7 +89,7 @@ gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool *image_map_tool,
*settings_box = gimp_settings_box_new (tool_info->gimp,
image_map_tool->config,
settings,
- settings_filename,
+ settings_file,
import_dialog_title,
export_dialog_title,
file_dialog_help_id,
@@ -114,24 +114,24 @@ gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool *image_map_tool,
gboolean
gimp_image_map_tool_real_settings_import (GimpImageMapTool *tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
gboolean success;
if (GIMP_TOOL (tool)->tool_info->gimp->be_verbose)
- g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+ g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
- success = gimp_config_deserialize_file (GIMP_CONFIG (tool->config),
- filename,
- NULL, error);
+ success = gimp_config_deserialize_gfile (GIMP_CONFIG (tool->config),
+ file,
+ NULL, error);
return success;
}
gboolean
gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
@@ -143,12 +143,12 @@ gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
footer = g_strdup_printf ("end of %s tool settings", klass->settings_name);
if (GIMP_TOOL (tool)->tool_info->gimp->be_verbose)
- g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+ g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
- success = gimp_config_serialize_to_file (GIMP_CONFIG (tool->config),
- filename,
- header, footer,
- NULL, error);
+ success = gimp_config_serialize_to_gfile (GIMP_CONFIG (tool->config),
+ file,
+ header, footer,
+ NULL, error);
g_free (header);
g_free (footer);
@@ -161,7 +161,7 @@ gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
static gboolean
gimp_image_map_tool_settings_import (GimpSettingsBox *box,
- const gchar *filename,
+ GFile *file,
GimpImageMapTool *tool)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
@@ -169,7 +169,7 @@ gimp_image_map_tool_settings_import (GimpSettingsBox *box,
g_return_val_if_fail (tool_class->settings_import != NULL, FALSE);
- if (! tool_class->settings_import (tool, filename, &error))
+ if (! tool_class->settings_import (tool, file, &error))
{
gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
@@ -182,7 +182,7 @@ gimp_image_map_tool_settings_import (GimpSettingsBox *box,
gimp_image_map_tool_preview (tool);
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
- "settings", filename,
+ "settings", file,
NULL);
return TRUE;
@@ -190,16 +190,15 @@ gimp_image_map_tool_settings_import (GimpSettingsBox *box,
static gboolean
gimp_image_map_tool_settings_export (GimpSettingsBox *box,
- const gchar *filename,
+ GFile *file,
GimpImageMapTool *tool)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
GError *error = NULL;
- gchar *display_name;
g_return_val_if_fail (tool_class->settings_export != NULL, FALSE);
- if (! tool_class->settings_export (tool, filename, &error))
+ if (! tool_class->settings_export (tool, file, &error))
{
gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
@@ -209,16 +208,14 @@ gimp_image_map_tool_settings_export (GimpSettingsBox *box,
return FALSE;
}
- display_name = g_filename_display_name (filename);
gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (GIMP_TOOL (tool)->display),
GIMP_MESSAGE_INFO,
_("Settings saved to '%s'"),
- display_name);
- g_free (display_name);
+ gimp_file_get_utf8_name (file));
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
- "settings", filename,
+ "settings", file,
NULL);
return TRUE;
diff --git a/app/tools/gimpimagemaptool-settings.h b/app/tools/gimpimagemaptool-settings.h
index 825c396..0ed225f 100644
--- a/app/tools/gimpimagemaptool-settings.h
+++ b/app/tools/gimpimagemaptool-settings.h
@@ -22,18 +22,18 @@
GtkWidget * gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool *tool,
- GimpContainer *settings,
- const gchar *settings_filename,
- const gchar *import_dialog_title,
- const gchar *export_dialog_title,
- const gchar *file_dialog_help_id,
- const gchar *default_folder,
+ GimpContainer *settings,
+ GFile *settings_file,
+ const gchar *import_dialog_title,
+ const gchar *export_dialog_title,
+ const gchar *file_dialog_help_id,
+ const gchar *default_folder,
GtkWidget **settings_box);
gboolean gimp_image_map_tool_real_settings_import (GimpImageMapTool *tool,
- const gchar *filename,
+ GFile *file,
GError **error);
gboolean gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
- const gchar *filename,
+ GFile *file,
GError **error);
diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c
index 4963e39..26e079d 100644
--- a/app/tools/gimpimagemaptool.c
+++ b/app/tools/gimpimagemaptool.c
@@ -374,6 +374,7 @@ gimp_image_map_tool_initialize (GimpTool *tool,
GtkWidget *settings_ui;
gchar *settings_filename;
gchar *default_folder;
+ GFile *settings_file;
settings_filename =
gimp_tool_info_build_options_filename (tool_info, ".settings");
@@ -381,15 +382,19 @@ gimp_image_map_tool_initialize (GimpTool *tool,
default_folder =
g_build_filename (gimp_directory (), klass->settings_name, NULL);
+ settings_file = g_file_new_for_path (settings_filename);
+
settings_ui = klass->get_settings_ui (image_map_tool,
klass->recent_settings,
- settings_filename,
+ settings_file,
klass->import_dialog_title,
klass->export_dialog_title,
tool_info->help_id,
default_folder,
&image_map_tool->settings_box);
+ g_object_unref (settings_file);
+
g_free (settings_filename);
g_free (default_folder);
diff --git a/app/tools/gimpimagemaptool.h b/app/tools/gimpimagemaptool.h
index 300860e..6fda8a5 100644
--- a/app/tools/gimpimagemaptool.h
+++ b/app/tools/gimpimagemaptool.h
@@ -77,7 +77,7 @@ struct _GimpImageMapToolClass
GtkWidget * (* get_settings_ui) (GimpImageMapTool *image_map_tool,
GimpContainer *settings,
- const gchar *settings_filename,
+ GFile *settings_file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
@@ -85,10 +85,10 @@ struct _GimpImageMapToolClass
GtkWidget **settings_box);
gboolean (* settings_import) (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
gboolean (* settings_export) (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
void (* color_picked) (GimpImageMapTool *image_map_tool,
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 42bd1e6..587c577 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -80,10 +80,10 @@ static GeglNode * gimp_levels_tool_get_operation (GimpImageMapTool *im_tool,
static void gimp_levels_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_levels_tool_reset (GimpImageMapTool *im_tool);
static gboolean gimp_levels_tool_settings_import(GimpImageMapTool *im_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
static gboolean gimp_levels_tool_settings_export(GimpImageMapTool *im_tool,
- const gchar *filename,
+ GFile *file,
GError **error);
static void gimp_levels_tool_color_picked (GimpImageMapTool *im_tool,
gpointer identifier,
@@ -614,31 +614,34 @@ gimp_levels_tool_reset (GimpImageMapTool *image_map_tool)
static gboolean
gimp_levels_tool_settings_import (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
- FILE *file;
+ gchar *path;
+ FILE *f;
gchar header[64];
- file = g_fopen (filename, "rt");
+ path = g_file_get_path (file);
+ f = g_fopen (path, "rt");
+ g_free (path);
- if (! file)
+ if (! f)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
return FALSE;
}
- if (! fgets (header, sizeof (header), file))
+ if (! fgets (header, sizeof (header), f))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not read header from '%s': %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
- fclose (file);
+ fclose (f);
return FALSE;
}
@@ -646,54 +649,57 @@ gimp_levels_tool_settings_import (GimpImageMapTool *image_map_tool,
{
gboolean success;
- rewind (file);
+ rewind (f);
- success = gimp_levels_config_load_cruft (tool->config, file, error);
+ success = gimp_levels_config_load_cruft (tool->config, f, error);
- fclose (file);
+ fclose (f);
return success;
}
- fclose (file);
+ fclose (f);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_import (image_map_tool,
- filename,
+ file,
error);
}
static gboolean
gimp_levels_tool_settings_export (GimpImageMapTool *image_map_tool,
- const gchar *filename,
+ GFile *file,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
if (tool->export_old_format)
{
- FILE *file;
+ gchar *path;
+ FILE *f;
gboolean success;
- file = g_fopen (filename, "wt");
+ path = g_file_get_path (file);
+ f = g_fopen (path, "wt");
+ g_free (path);
- if (! file)
+ if (! f)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (filename),
+ gimp_file_get_utf8_name (file),
g_strerror (errno));
return FALSE;
}
- success = gimp_levels_config_save_cruft (tool->config, file, error);
+ success = gimp_levels_config_save_cruft (tool->config, f, error);
- fclose (file);
+ fclose (f);
return success;
}
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
- filename,
+ file,
error);
}
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index c9bdc46..e865fcc 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -76,7 +76,7 @@ static void gimp_operation_tool_dialog (GimpImageMapTool *im_to
static void gimp_operation_tool_reset (GimpImageMapTool *im_tool);
static GtkWidget * gimp_operation_tool_get_settings_ui (GimpImageMapTool *image_map_tool,
GimpContainer *settings,
- const gchar *settings_filename,
+ GFile *settings_file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
@@ -312,7 +312,7 @@ gimp_operation_tool_reset (GimpImageMapTool *image_map_tool)
static GtkWidget *
gimp_operation_tool_get_settings_ui (GimpImageMapTool *image_map_tool,
GimpContainer *settings,
- const gchar *settings_filename,
+ GFile *settings_file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
@@ -324,6 +324,7 @@ gimp_operation_tool_get_settings_ui (GimpImageMapTool *image_map_tool,
GtkWidget *widget;
gchar *basename;
gchar *filename;
+ GFile *file;
gchar *import_title;
gchar *export_title;
@@ -336,23 +337,27 @@ gimp_operation_tool_get_settings_ui (GimpImageMapTool *image_map_tool,
filename = g_build_filename (gimp_directory (), "filters", basename, NULL);
g_free (basename);
+ file = g_file_new_for_path (filename);
+ g_free (filename);
+
import_title = g_strdup_printf (_("Import '%s' Settings"), tool->undo_desc);
export_title = g_strdup_printf (_("Export '%s' Settings"), tool->undo_desc);
widget =
GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->get_settings_ui (image_map_tool,
settings,
- filename,
+ file,
import_title,
export_title,
"help-foo",
g_get_home_dir (),
settings_box);
- g_free (filename);
g_free (import_title);
g_free (export_title);
+ g_object_unref (file);
+
return widget;
}
diff --git a/app/widgets/gimpsettingsbox.c b/app/widgets/gimpsettingsbox.c
index b6a6519..cddf106 100644
--- a/app/widgets/gimpsettingsbox.c
+++ b/app/widgets/gimpsettingsbox.c
@@ -57,7 +57,7 @@ enum
PROP_GIMP,
PROP_CONFIG,
PROP_CONTAINER,
- PROP_FILENAME
+ PROP_FILE
};
@@ -75,13 +75,13 @@ struct _GimpSettingsBoxPrivate
Gimp *gimp;
GObject *config;
GimpContainer *container;
- gchar *filename;
+ GFile *file;
gchar *import_dialog_title;
gchar *export_dialog_title;
gchar *file_dialog_help_id;
gchar *default_folder;
- gchar *last_filename;
+ GFile *last_file;
};
#define GET_PRIVATE(item) G_TYPE_INSTANCE_GET_PRIVATE (item, \
@@ -174,9 +174,9 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpSettingsBoxClass, import),
NULL, NULL,
- gimp_marshal_BOOLEAN__STRING,
+ gimp_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1,
- G_TYPE_STRING);
+ G_TYPE_FILE);
settings_box_signals[EXPORT] =
g_signal_new ("export",
@@ -184,9 +184,9 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpSettingsBoxClass, export),
NULL, NULL,
- gimp_marshal_BOOLEAN__STRING,
+ gimp_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1,
- G_TYPE_STRING);
+ G_TYPE_FILE);
object_class->constructed = gimp_settings_box_constructed;
object_class->finalize = gimp_settings_box_finalize;
@@ -218,10 +218,10 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class, PROP_FILENAME,
- g_param_spec_string ("filename",
+ g_object_class_install_property (object_class, PROP_FILE,
+ g_param_spec_object ("file",
NULL, NULL,
- NULL,
+ G_TYPE_FILE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
@@ -252,7 +252,7 @@ gimp_settings_box_constructed (GObject *object)
g_assert (GIMP_IS_GIMP (private->gimp));
g_assert (GIMP_IS_CONFIG (private->config));
g_assert (GIMP_IS_CONTAINER (private->container));
- g_assert (private->filename != NULL);
+ g_assert (G_IS_FILE (private->file));
if (gimp_container_get_n_children (private->container) == 0)
gimp_settings_box_deserialize (box);
@@ -350,17 +350,22 @@ gimp_settings_box_finalize (GObject *object)
private->container = NULL;
}
- if (private->filename)
+ if (private->file)
{
- g_free (private->filename);
- private->filename = NULL;
+ g_object_unref (private->file);
+ private->file = NULL;
+ }
+
+ if (private->last_file)
+ {
+ g_object_unref (private->last_file);
+ private->last_file = NULL;
}
g_free (private->import_dialog_title);
g_free (private->export_dialog_title);
g_free (private->file_dialog_help_id);
g_free (private->default_folder);
- g_free (private->last_filename);
if (private->editor_dialog)
{
@@ -411,8 +416,8 @@ gimp_settings_box_set_property (GObject *object,
private->container = g_value_dup_object (value);
break;
- case PROP_FILENAME:
- private->filename = g_value_dup_string (value);
+ case PROP_FILE:
+ private->file = g_value_dup_object (value);
break;
default:
@@ -443,8 +448,8 @@ gimp_settings_box_get_property (GObject *object,
g_value_set_object (value, private->container);
break;
- case PROP_FILENAME:
- g_value_set_string (value, private->filename);
+ case PROP_FILE:
+ g_value_set_object (value, private->file);
break;
default:
@@ -482,11 +487,11 @@ gimp_settings_box_deserialize (GimpSettingsBox *box)
GError *error = NULL;
if (private->gimp->be_verbose)
- g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (private->filename));
+ g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (private->file));
- if (! gimp_config_deserialize_file (GIMP_CONFIG (private->container),
- private->filename,
- NULL, &error))
+ if (! gimp_config_deserialize_gfile (GIMP_CONFIG (private->container),
+ private->file,
+ NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
gimp_message_literal (private->gimp, NULL, GIMP_MESSAGE_ERROR,
@@ -507,13 +512,13 @@ gimp_settings_box_serialize (GimpSettingsBox *box)
gimp_settings_box_separator_remove (private->container);
if (private->gimp->be_verbose)
- g_print ("Writing '%s'\n", gimp_filename_to_utf8 (private->filename));
+ g_print ("Writing '%s'\n", gimp_file_get_utf8_name (private->file));
- if (! gimp_config_serialize_to_file (GIMP_CONFIG (private->container),
- private->filename,
- "settings",
- "end of settings",
- NULL, &error))
+ if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (private->container),
+ private->file,
+ "settings",
+ "end of settings",
+ NULL, &error))
{
gimp_message_literal (private->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
@@ -795,19 +800,19 @@ gimp_settings_box_file_dialog (GimpSettingsBox *box,
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
private->default_folder, NULL);
- if (! private->last_filename)
+ if (! private->last_file)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
private->default_folder);
}
- else if (! private->last_filename)
+ else if (! private->last_file)
{
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
g_get_home_dir ());
}
- if (private->last_filename)
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog),
- private->last_filename);
+ if (private->last_file)
+ gtk_file_chooser_set_file (GTK_FILE_CHOOSER (dialog),
+ private->last_file, NULL);
gimp_help_connect (private->file_dialog, gimp_standard_help_func,
private->file_dialog_help_id, NULL);
@@ -839,25 +844,28 @@ gimp_settings_box_file_response (GtkWidget *dialog,
if (response_id == GTK_RESPONSE_OK)
{
- gchar *filename;
+ GFile *file;
gboolean success = FALSE;
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (save)
- g_signal_emit (box, settings_box_signals[EXPORT], 0, filename,
+ g_signal_emit (box, settings_box_signals[EXPORT], 0, file,
&success);
else
- g_signal_emit (box, settings_box_signals[IMPORT], 0, filename,
+ g_signal_emit (box, settings_box_signals[IMPORT], 0, file,
&success);
if (success)
{
- g_free (private->last_filename);
- private->last_filename = g_strdup (filename);
+ if (private->last_file)
+ g_object_unref (private->last_file);
+ private->last_file = file;
+ }
+ else
+ {
+ g_object_unref (file);
}
-
- g_free (filename);
}
if (save)
@@ -931,12 +939,12 @@ GtkWidget *
gimp_settings_box_new (Gimp *gimp,
GObject *config,
GimpContainer *container,
- const gchar *filename,
+ GFile *file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
const gchar *default_folder,
- const gchar *last_filename)
+ GFile *last_file)
{
GimpSettingsBox *box;
GimpSettingsBoxPrivate *private;
@@ -944,13 +952,14 @@ gimp_settings_box_new (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL);
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
- g_return_val_if_fail (filename != NULL, NULL);
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+ g_return_val_if_fail (last_file == NULL || G_IS_FILE (last_file), NULL);
box = g_object_new (GIMP_TYPE_SETTINGS_BOX,
"gimp", gimp,
"config", config,
"container", container,
- "filename", filename,
+ "file", file,
NULL);
private = GET_PRIVATE (box);
@@ -959,7 +968,9 @@ gimp_settings_box_new (Gimp *gimp,
private->export_dialog_title = g_strdup (export_dialog_title);
private->file_dialog_help_id = g_strdup (file_dialog_help_id);
private->default_folder = g_strdup (default_folder);
- private->last_filename = g_strdup (last_filename);
+
+ if (last_file)
+ private->last_file = g_object_ref (last_file);
return GTK_WIDGET (box);
}
diff --git a/app/widgets/gimpsettingsbox.h b/app/widgets/gimpsettingsbox.h
index 6f62e23..25ff9d9 100644
--- a/app/widgets/gimpsettingsbox.h
+++ b/app/widgets/gimpsettingsbox.h
@@ -46,9 +46,9 @@ struct _GimpSettingsBoxClass
GtkFileChooserDialog *dialog,
gboolean export);
void (* import) (GimpSettingsBox *box,
- const gchar *filename);
+ GFile *file);
void (* export) (GimpSettingsBox *box,
- const gchar *filename);
+ GFile *file);
};
@@ -57,12 +57,12 @@ GType gimp_settings_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_settings_box_new (Gimp *gimp,
GObject *config,
GimpContainer *container,
- const gchar *filename,
+ GFile *file,
const gchar *import_dialog_title,
const gchar *export_dialog_title,
const gchar *file_dialog_help_id,
const gchar *default_folder,
- const gchar *last_filename);
+ GFile *last_file);
void gimp_settings_box_add_current (GimpSettingsBox *box,
gint max_recent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]