Commit 6b6ba7b4 authored by Michael Natterer's avatar Michael Natterer 😴

app: port gimptagcache.c to GIO

parent afc46944
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
#include "config.h" #include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h> #include <gegl.h>
...@@ -351,12 +348,13 @@ gimp_tag_cache_tagged_to_cache_record_foreach (GimpTagged *tagged, ...@@ -351,12 +348,13 @@ gimp_tag_cache_tagged_to_cache_record_foreach (GimpTagged *tagged,
void void
gimp_tag_cache_save (GimpTagCache *cache) gimp_tag_cache_save (GimpTagCache *cache)
{ {
GString *buf; GString *buf;
GList *saved_records; GList *saved_records;
GList *iterator; GList *iterator;
gchar *filename; GFile *file;
GError *error = NULL; GOutputStream *output;
gint i; GError *error = NULL;
gint i;
g_return_if_fail (GIMP_IS_TAG_CACHE (cache)); g_return_if_fail (GIMP_IS_TAG_CACHE (cache));
...@@ -428,16 +426,29 @@ gimp_tag_cache_save (GimpTagCache *cache) ...@@ -428,16 +426,29 @@ gimp_tag_cache_save (GimpTagCache *cache)
g_string_append (buf, "</tags>\n"); g_string_append (buf, "</tags>\n");
filename = g_build_filename (gimp_directory (), GIMP_TAG_CACHE_FILE, NULL); file = gimp_directory_file (GIMP_TAG_CACHE_FILE, NULL);
if (! g_file_set_contents (filename, buf->str, buf->len, &error)) output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &error));
if (! output)
{
g_printerr (_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), error->message);
}
else if (! g_output_stream_write_all (output, buf->str, buf->len,
NULL, NULL, &error) ||
! g_output_stream_close (output, NULL, &error))
{ {
g_printerr ("Error while saving tag cache: %s\n", error->message); g_printerr (_("Error writing '%s': %s"),
g_error_free (error); gimp_file_get_utf8_name (file), error->message);
} }
g_free (filename); if (output)
g_object_unref (output);
g_clear_error (&error);
g_object_unref (file);
g_string_free (buf, TRUE); g_string_free (buf, TRUE);
for (iterator = saved_records; for (iterator = saved_records;
...@@ -462,19 +473,17 @@ gimp_tag_cache_save (GimpTagCache *cache) ...@@ -462,19 +473,17 @@ gimp_tag_cache_save (GimpTagCache *cache)
void void
gimp_tag_cache_load (GimpTagCache *cache) gimp_tag_cache_load (GimpTagCache *cache)
{ {
gchar *filename; GFile *file;
GError *error = NULL;
GMarkupParser markup_parser; GMarkupParser markup_parser;
GimpXmlParser *xml_parser; GimpXmlParser *xml_parser;
GimpTagCacheParseData parse_data; GimpTagCacheParseData parse_data;
GError *error = NULL;
g_return_if_fail (GIMP_IS_TAG_CACHE (cache)); g_return_if_fail (GIMP_IS_TAG_CACHE (cache));
/* clear any previous priv->records */ /* clear any previous priv->records */
cache->priv->records = g_array_set_size (cache->priv->records, 0); cache->priv->records = g_array_set_size (cache->priv->records, 0);
filename = g_build_filename (gimp_directory (), GIMP_TAG_CACHE_FILE, NULL);
parse_data.records = g_array_new (FALSE, FALSE, sizeof (GimpTagCacheRecord)); parse_data.records = g_array_new (FALSE, FALSE, sizeof (GimpTagCacheRecord));
memset (&parse_data.current_record, 0, sizeof (GimpTagCacheRecord)); memset (&parse_data.current_record, 0, sizeof (GimpTagCacheRecord));
...@@ -486,7 +495,9 @@ gimp_tag_cache_load (GimpTagCache *cache) ...@@ -486,7 +495,9 @@ gimp_tag_cache_load (GimpTagCache *cache)
xml_parser = gimp_xml_parser_new (&markup_parser, &parse_data); xml_parser = gimp_xml_parser_new (&markup_parser, &parse_data);
if (gimp_xml_parser_parse_file (xml_parser, filename, &error)) file = gimp_directory_file (GIMP_TAG_CACHE_FILE, NULL);
if (gimp_xml_parser_parse_gfile (xml_parser, file, &error))
{ {
cache->priv->records = g_array_append_vals (cache->priv->records, cache->priv->records = g_array_append_vals (cache->priv->records,
parse_data.records->data, parse_data.records->data,
...@@ -495,10 +506,10 @@ gimp_tag_cache_load (GimpTagCache *cache) ...@@ -495,10 +506,10 @@ gimp_tag_cache_load (GimpTagCache *cache)
else else
{ {
g_printerr ("Failed to parse tag cache: %s\n", g_printerr ("Failed to parse tag cache: %s\n",
error ? error->message : NULL); error ? error->message : "WTF unknown error");
} }
g_free (filename); g_object_unref (file);
gimp_xml_parser_free (xml_parser); gimp_xml_parser_free (xml_parser);
g_array_free (parse_data.records, TRUE); g_array_free (parse_data.records, TRUE);
} }
...@@ -602,7 +613,7 @@ gimp_tag_cache_load_error (GMarkupParseContext *context, ...@@ -602,7 +613,7 @@ gimp_tag_cache_load_error (GMarkupParseContext *context,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
printf ("Tag cache parse error: %s\n", error->message); g_printerr ("Tag cache parse error: %s\n", error->message);
} }
static const gchar* static const gchar*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment