app/core/gimp-contexts.[ch] add GErrors to save() and load().

2007-12-19  Michael Natterer  <mitch@gimp.org>

	* app/core/gimp-contexts.[ch]
	* app/core/gimp-documents.[ch]: add GErrors to save() and load().

	* app/core/gimp.c
	* app/tools/gimp-tools.c: handle the returned errors.


svn path=/trunk/; revision=24403
This commit is contained in:
Michael Natterer 2007-12-19 17:45:47 +00:00 committed by Michael Natterer
parent 8ce82f2415
commit 1542f99678
7 changed files with 125 additions and 62 deletions

View File

@ -1,3 +1,11 @@
2007-12-19 Michael Natterer <mitch@gimp.org>
* app/core/gimp-contexts.[ch]
* app/core/gimp-documents.[ch]: add GErrors to save() and load().
* app/core/gimp.c
* app/tools/gimp-tools.c: handle the returned errors.
2007-12-18 Sven Neumann <sven@gimp.org>
* plug-ins/common/psd-load.c: applied patch from John Marshall

View File

@ -74,55 +74,68 @@ gimp_contexts_exit (Gimp *gimp)
gimp_set_default_context (gimp, NULL);
}
void
gimp_contexts_load (Gimp *gimp)
gboolean
gimp_contexts_load (Gimp *gimp,
GError **error)
{
gchar *filename;
GError *error = NULL;
gchar *filename;
GError *my_error = NULL;
gboolean success;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = gimp_personal_rc_file ("contextrc");
if (gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
NULL, &error))
success = gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
NULL, &my_error);
if (! success)
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_error_free (error);
if (my_error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
{
g_clear_error (&my_error);
success = TRUE;
}
else
{
g_propagate_error (error, my_error);
}
}
g_free (filename);
return success;
}
void
gimp_contexts_save (Gimp *gimp)
gboolean
gimp_contexts_save (Gimp *gimp,
GError **error)
{
gchar *filename;
GError *error = NULL;
gchar *filename;
gboolean success;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = gimp_personal_rc_file ("contextrc");
if (gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
"GIMP user context",
"end of user context",
NULL, &error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_error_free (error);
}
success = gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
"GIMP user context",
"end of user context",
NULL, error);
g_free (filename);
return success;
}
gboolean
@ -138,7 +151,8 @@ gimp_contexts_clear (Gimp *gimp,
if (g_unlink (filename) != 0 && errno != ENOENT)
{
g_set_error (error, 0, 0, _("Deleting \"%s\" failed: %s"),
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Deleting \"%s\" failed: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
success = FALSE;
}

View File

@ -25,8 +25,10 @@
void gimp_contexts_init (Gimp *gimp);
void gimp_contexts_exit (Gimp *gimp);
void gimp_contexts_load (Gimp *gimp);
void gimp_contexts_save (Gimp *gimp);
gboolean gimp_contexts_load (Gimp *gimp,
GError **error);
gboolean gimp_contexts_save (Gimp *gimp,
GError **error);
gboolean gimp_contexts_clear (Gimp *gimp,
GError **error);

View File

@ -34,35 +34,49 @@
/* functions to load and save the gimp documents files */
void
gimp_documents_load (Gimp *gimp)
gboolean
gimp_documents_load (Gimp *gimp,
GError **error)
{
gchar *filename;
GError *error = NULL;
gchar *filename;
GError *my_error = NULL;
gboolean success;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_DOCUMENT_LIST (gimp->documents));
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (GIMP_IS_DOCUMENT_LIST (gimp->documents), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = gimp_personal_rc_file ("documents");
if (gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->documents),
filename,
GINT_TO_POINTER (gimp->config->thumbnail_size),
&error))
success = gimp_config_deserialize_file (GIMP_CONFIG (gimp->documents),
filename,
GINT_TO_POINTER (gimp->config->thumbnail_size),
&my_error);
if (! success)
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_error_free (error);
if (my_error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
{
g_clear_error (&my_error);
success = TRUE;
}
else
{
g_propagate_error (error, my_error);
}
}
g_free (filename);
return success;
}
void
gimp_documents_save (Gimp *gimp)
gboolean
gimp_documents_save (Gimp *gimp,
GError **error)
{
const gchar *header =
"GIMP documents\n"
@ -71,25 +85,24 @@ gimp_documents_save (Gimp *gimp)
const gchar *footer =
"end of documents";
gchar *filename;
GError *error = NULL;
gchar *filename;
gboolean success;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_DOCUMENT_LIST (gimp->documents));
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (GIMP_IS_DOCUMENT_LIST (gimp->documents), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = gimp_personal_rc_file ("documents");
if (gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp->documents),
filename,
header, footer, NULL,
&error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_error_free (error);
}
success = gimp_config_serialize_to_file (GIMP_CONFIG (gimp->documents),
filename,
header, footer, NULL,
error);
g_free (filename);
return success;
}

View File

@ -20,8 +20,10 @@
#define __GIMP_DOCUMENTS_H__
void gimp_documents_load (Gimp *gimp);
void gimp_documents_save (Gimp *gimp);
gboolean gimp_documents_load (Gimp *gimp,
GError **error);
gboolean gimp_documents_save (Gimp *gimp,
GError **error);
#endif /* __GIMP_DOCUMENTS_H__ */

View File

@ -624,6 +624,8 @@ static gboolean
gimp_real_exit (Gimp *gimp,
gboolean force)
{
GError *error = NULL;
if (gimp->be_verbose)
g_print ("EXIT: gimp_real_exit\n");
@ -638,7 +640,11 @@ gimp_real_exit (Gimp *gimp,
gimp_fonts_reset (gimp);
if (gimp->config->save_document_history)
gimp_documents_save (gimp);
if (! gimp_documents_save (gimp, &error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_clear_error (&error);
}
gimp_templates_save (gimp);
gimp_parasiterc_save (gimp);
@ -810,6 +816,8 @@ void
gimp_restore (Gimp *gimp,
GimpInitStatusFunc status_callback)
{
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (status_callback != NULL);
@ -843,7 +851,11 @@ gimp_restore (Gimp *gimp,
/* initialize the document history */
status_callback (NULL, _("Documents"), 0.6);
gimp_documents_load (gimp);
if (! gimp_documents_load (gimp, &error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
g_clear_error (&error);
}
/* initialize the template list */
status_callback (NULL, _("Templates"), 0.7);

View File

@ -227,6 +227,7 @@ gimp_tools_restore (Gimp *gimp)
GimpContainer *gimp_list;
gchar *filename;
GList *list;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
@ -282,7 +283,12 @@ gimp_tools_restore (Gimp *gimp)
gimp_tool_options_reset (tool_info->tool_options);
}
gimp_contexts_load (gimp);
if (! gimp_contexts_load (gimp, &error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
@ -339,9 +345,15 @@ gimp_tools_save (Gimp *gimp,
if (save_tool_options && (! tool_options_deleted || always_save))
{
GList *list;
GList *list;
GError *error = NULL;
gimp_contexts_save (gimp);
if (! gimp_contexts_save (gimp, &error))
{
gimp_message (gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
gimp_tool_options_create_folder ();