[gthumb] use a GFile object instead of a filename
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] use a GFile object instead of a filename
- Date: Thu, 2 Aug 2012 12:33:59 +0000 (UTC)
commit 86aaa5791b6ffeec9db6000045a82e99cc7a42b3
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed May 9 00:16:24 2012 +0200
use a GFile object instead of a filename
gthumb/gth-filter-file.c | 14 ++++++--------
gthumb/gth-filter-file.h | 4 ++--
gthumb/gth-main.c | 24 +++++-------------------
gthumb/gth-tags-file.c | 15 +++++++--------
gthumb/gth-tags-file.h | 4 ++--
5 files changed, 22 insertions(+), 39 deletions(-)
---
diff --git a/gthumb/gth-filter-file.c b/gthumb/gth-filter-file.c
index 2f74639..0fd0609 100644
--- a/gthumb/gth-filter-file.c
+++ b/gthumb/gth-filter-file.c
@@ -112,7 +112,7 @@ gth_filter_file_load_from_data (GthFilterFile *filters,
gboolean
gth_filter_file_load_from_file (GthFilterFile *filters,
- const char *filename,
+ GFile *file,
GError **error)
{
char *buffer;
@@ -121,11 +121,10 @@ gth_filter_file_load_from_file (GthFilterFile *filters,
gboolean retval;
g_return_val_if_fail (filters != NULL, FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (file != NULL, FALSE);
read_error = NULL;
- g_file_get_contents (filename, &buffer, &len, &read_error);
- if (read_error != NULL) {
+ if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, &read_error)) {
g_propagate_error (error, read_error);
return FALSE;
}
@@ -174,7 +173,7 @@ gth_filter_file_to_data (GthFilterFile *filters,
gboolean
gth_filter_file_to_file (GthFilterFile *filters,
- const char *filename,
+ GFile *file,
GError **error)
{
char *data;
@@ -183,7 +182,7 @@ gth_filter_file_to_file (GthFilterFile *filters,
gboolean retval;
g_return_val_if_fail (filters != NULL, FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (file != NULL, FALSE);
data_error = NULL;
data = gth_filter_file_to_data (filters, &len, &data_error);
@@ -193,8 +192,7 @@ gth_filter_file_to_file (GthFilterFile *filters,
}
write_error = NULL;
- g_file_set_contents (filename, data, len, &write_error);
- if (write_error) {
+ if (! g_write_file (file, FALSE, 0, data, len, NULL, &write_error)) {
g_propagate_error (error, write_error);
retval = FALSE;
}
diff --git a/gthumb/gth-filter-file.h b/gthumb/gth-filter-file.h
index 64a07ca..a9dc6c3 100644
--- a/gthumb/gth-filter-file.h
+++ b/gthumb/gth-filter-file.h
@@ -36,13 +36,13 @@ gboolean gth_filter_file_load_from_data (GthFilterFile *filters,
gsize length,
GError **error);
gboolean gth_filter_file_load_from_file (GthFilterFile *bookmark,
- const char *filename,
+ GFile *file,
GError **error);
char * gth_filter_file_to_data (GthFilterFile *filters,
gsize *len,
GError **data_error);
gboolean gth_filter_file_to_file (GthFilterFile *filters,
- const gchar *filename,
+ GFile *file,
GError **error);
GList * gth_filter_file_get_tests (GthFilterFile *filters);
gboolean gth_filter_file_has_test (GthFilterFile *filters,
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index c39c936..87b2503 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -1041,17 +1041,14 @@ GthFilterFile *
gth_main_get_default_filter_file (void)
{
GFile *file;
- char *filename;
if (Main->priv->filters != NULL)
return Main->priv->filters;
Main->priv->filters = gth_filter_file_new ();
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, FILTERS_FILE, NULL);
- filename = g_file_get_path (file);
- gth_filter_file_load_from_file (Main->priv->filters, filename, NULL);
+ gth_filter_file_load_from_file (Main->priv->filters, file, NULL);
- g_free (filename);
g_object_unref (file);
return Main->priv->filters;
@@ -1105,16 +1102,12 @@ void
gth_main_filters_changed (void)
{
GFile *file;
- char *filename;
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, FILTERS_FILE, NULL);
- filename = g_file_get_path (file);
- gth_filter_file_to_file (Main->priv->filters, filename, NULL);
+ gth_filter_file_to_file (Main->priv->filters, file, NULL);
+ gth_monitor_filters_changed (gth_main_get_default_monitor ());
- g_free (filename);
g_object_unref (file);
-
- gth_monitor_filters_changed (gth_main_get_default_monitor ());
}
@@ -1122,17 +1115,14 @@ GthTagsFile *
gth_main_get_default_tag_file (void)
{
GFile *file;
- char *filename;
if (Main->priv->tags != NULL)
return Main->priv->tags;
Main->priv->tags = gth_tags_file_new ();
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, TAGS_FILE, NULL);
- filename = g_file_get_path (file);
- gth_tags_file_load_from_file (Main->priv->tags, filename, NULL);
+ gth_tags_file_load_from_file (Main->priv->tags, file, NULL);
- g_free (filename);
g_object_unref (file);
return Main->priv->tags;
@@ -1150,15 +1140,11 @@ void
gth_main_tags_changed (void)
{
GFile *file;
- char *filename;
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, TAGS_FILE, NULL);
- filename = g_file_get_path (file);
- gth_tags_file_to_file (Main->priv->tags, filename, NULL);
-
+ gth_tags_file_to_file (Main->priv->tags, file, NULL);
gth_monitor_tags_changed (gth_main_get_default_monitor ());
- g_free (filename);
g_object_unref (file);
}
diff --git a/gthumb/gth-tags-file.c b/gthumb/gth-tags-file.c
index 7e8c44e..6642203 100644
--- a/gthumb/gth-tags-file.c
+++ b/gthumb/gth-tags-file.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <glib/gi18n.h>
#include "dom.h"
+#include "gio-utils.h"
#include "glib-utils.h"
#include "gth-tags-file.h"
@@ -106,7 +107,7 @@ gth_tags_file_load_from_data (GthTagsFile *tags,
gboolean
gth_tags_file_load_from_file (GthTagsFile *tags,
- const char *filename,
+ GFile *file,
GError **error)
{
char *buffer;
@@ -115,11 +116,10 @@ gth_tags_file_load_from_file (GthTagsFile *tags,
gboolean retval;
g_return_val_if_fail (tags != NULL, FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (file != NULL, FALSE);
read_error = NULL;
- g_file_get_contents (filename, &buffer, &len, &read_error);
- if (read_error != NULL) {
+ if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, &read_error)) {
g_propagate_error (error, read_error);
return FALSE;
}
@@ -170,7 +170,7 @@ gth_tags_file_to_data (GthTagsFile *tags,
gboolean
gth_tags_file_to_file (GthTagsFile *tags,
- const char *filename,
+ GFile *file,
GError **error)
{
char *data;
@@ -179,7 +179,7 @@ gth_tags_file_to_file (GthTagsFile *tags,
gboolean retval;
g_return_val_if_fail (tags != NULL, FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (file != NULL, FALSE);
data_error = NULL;
data = gth_tags_file_to_data (tags, &len, &data_error);
@@ -189,8 +189,7 @@ gth_tags_file_to_file (GthTagsFile *tags,
}
write_error = NULL;
- g_file_set_contents (filename, data, len, &write_error);
- if (write_error) {
+ if (! g_write_file (file, FALSE, 0, data, len, NULL, &write_error)) {
g_propagate_error (error, write_error);
retval = FALSE;
}
diff --git a/gthumb/gth-tags-file.h b/gthumb/gth-tags-file.h
index 807f1d2..d256de2 100644
--- a/gthumb/gth-tags-file.h
+++ b/gthumb/gth-tags-file.h
@@ -36,13 +36,13 @@ gboolean gth_tags_file_load_from_data (GthTagsFile *tags,
gsize length,
GError **error);
gboolean gth_tags_file_load_from_file (GthTagsFile *bookmark,
- const char *filename,
+ GFile *file,
GError **error);
char * gth_tags_file_to_data (GthTagsFile *tags,
gsize *len,
GError **data_error);
gboolean gth_tags_file_to_file (GthTagsFile *tags,
- const char *filename,
+ GFile *filename,
GError **error);
char ** gth_tags_file_get_tags (GthTagsFile *tags);
gboolean gth_tags_file_has_tag (GthTagsFile *tags,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]