Commit 2afb91e8 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

simplified the API for the gth_user_dir_* functions

parent d86d86d7
......@@ -208,21 +208,21 @@ update_system_bookmark_list_ready (GObject *source_object,
static void
_gth_browser_update_system_bookmark_list (GthBrowser *browser)
{
char *bookmark_file_path;
GFile *bookmark_file;
GFileInputStream *input_stream;
UpdateBookmarksData *data;
/* give priority to XDG_CONFIG_HOME/gtk-3.0/bookmarks if not found
* try the old ~/.gtk-bookmarks */
bookmark_file_path = gth_user_dir_get_file (GTH_DIR_CONFIG, "gtk-3.0", "bookmarks", NULL);
bookmark_file = g_file_new_for_path (bookmark_file_path);
g_free (bookmark_file_path);
bookmark_file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, "gtk-3.0", "bookmarks", NULL);
if (! g_file_query_exists (bookmark_file, NULL)) {
char *path;
g_object_unref (bookmark_file);
bookmark_file_path = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
bookmark_file = g_file_new_for_path (bookmark_file_path);
g_free (bookmark_file_path);
path = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
bookmark_file = g_file_new_for_path (path);
g_free (path);
}
input_stream = g_file_read (bookmark_file, NULL, NULL);
......
......@@ -187,7 +187,7 @@ browser_data_free (BrowserData *data)
void
catalogs__initialize_cb (void)
{
gth_user_dir_make_dir_for_file (GTH_DIR_DATA, GTHUMB_DIR, "catalogs", "dummy", NULL);
gth_user_dir_mkdir_with_parents (GTH_DIR_DATA, GTHUMB_DIR, "catalogs", NULL);
}
......
......@@ -785,15 +785,7 @@ gth_catalog_update_metadata (GthCatalog *catalog,
GFile *
gth_catalog_get_base (void)
{
char *catalogs_dir;
GFile *base;
catalogs_dir = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, "catalogs", NULL);
base = g_file_new_for_path (catalogs_dir);
g_free (catalogs_dir);
return base;
return gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "catalogs", NULL);
}
......
......@@ -368,7 +368,6 @@ add_themes_from_dir (DialogData *data,
static void
load_themes (DialogData *data)
{
char *style_path;
GFile *style_dir;
int visible_columns;
int col_spacing;
......@@ -379,11 +378,9 @@ load_themes (DialogData *data)
/* local themes */
style_path = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", NULL);
style_dir = g_file_new_for_path (style_path);
style_dir = gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", NULL);
add_themes_from_dir (data, style_dir, TRUE);
g_object_unref (style_dir);
g_free (style_path);
/* system themes */
......@@ -472,12 +469,10 @@ theme_dialog_response_cb (GtkDialog *dialog,
new_theme = theme->file == NULL;
if (theme->file == NULL) {
char *themes_path;
GFile *themes_dir;
gth_user_dir_make_dir_for_file (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", "themename.cst", NULL);
themes_path = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", NULL);
themes_dir = g_file_new_for_path (themes_path);
gth_user_dir_mkdir_with_parents (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", NULL);
themes_dir = gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "contact_sheet_themes", NULL);
theme->file = _g_file_create_unique (themes_dir,
theme->display_name,
".cst",
......@@ -488,7 +483,6 @@ theme_dialog_response_cb (GtkDialog *dialog,
}
g_object_unref (themes_dir);
g_free (themes_path);
if (theme->file == NULL)
return;
......
......@@ -80,15 +80,11 @@ static GFile *
get_wallpaper_file_n (int n)
{
char *name;
char *filename;
GFile *file;
name = g_strdup_printf ("wallpaper%d.jpeg", n);
gth_user_dir_make_dir_for_file (GTH_DIR_DATA, GTHUMB_DIR, name, NULL);
filename = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, name, NULL);
file = g_file_new_for_path (filename);
file = gth_user_dir_get_file_for_write (GTH_DIR_DATA, GTHUMB_DIR, name, NULL);
g_free (filename);
g_free (name);
return file;
......
......@@ -1053,14 +1053,14 @@ GList *
facebook_accounts_load_from_file (void)
{
GList *accounts = NULL;
char *filename;
GFile *file;
char *buffer;
gsize len;
DomDocument *doc;
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
if (! g_file_get_contents (filename, &buffer, &len, NULL)) {
g_free (filename);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, NULL)) {
g_object_unref (file);
return NULL;
}
......@@ -1092,7 +1092,7 @@ facebook_accounts_load_from_file (void)
g_object_unref (doc);
g_free (buffer);
g_free (filename);
g_object_unref (file);
return accounts;
}
......@@ -1123,7 +1123,6 @@ facebook_accounts_save_to_file (GList *accounts,
GList *scan;
char *buffer;
gsize len;
char *filename;
GFile *file;
doc = dom_document_new ();
......@@ -1141,14 +1140,11 @@ facebook_accounts_save_to_file (GList *accounts,
dom_element_append_child (root, node);
}
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
file = g_file_new_for_path (filename);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
buffer = dom_document_dump (doc, &len);
g_write_file (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
g_free (buffer);
g_object_unref (file);
g_free (filename);
g_object_unref (doc);
}
......@@ -1167,18 +1167,18 @@ GList *
flickr_accounts_load_from_file (const char *server_name)
{
GList *accounts = NULL;
char *filename;
GFile *file;
char *buffer;
char *accounts_filename;
gsize len;
DomDocument *doc;
accounts_filename = get_server_accounts_filename (server_name);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
g_free (accounts_filename);
if (! g_file_get_contents (filename, &buffer, &len, NULL)) {
g_free (filename);
if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, NULL)) {
g_object_unref (file);
return NULL;
}
......@@ -1210,7 +1210,7 @@ flickr_accounts_load_from_file (const char *server_name)
g_object_unref (doc);
g_free (buffer);
g_free (filename);
g_object_unref (file);
return accounts;
}
......@@ -1243,7 +1243,6 @@ flickr_accounts_save_to_file (const char *server_name,
char *buffer;
gsize len;
char *accounts_filename;
char *filename;
GFile *file;
doc = dom_document_new ();
......@@ -1262,15 +1261,12 @@ flickr_accounts_save_to_file (const char *server_name,
}
accounts_filename = get_server_accounts_filename (server_name);
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
file = g_file_new_for_path (filename);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
buffer = dom_document_dump (doc, &len);
g_write_file (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
g_free (buffer);
g_object_unref (file);
g_free (filename);
g_free (accounts_filename);
g_object_unref (doc);
}
......@@ -1653,6 +1653,7 @@ print_operation_begin_print_cb (GtkPrintOperation *operation,
{
GthImagePrintJob *self = user_data;
GtkPrintSettings *settings;
GFile *file;
char *filename;
PangoLayout *pango_layout;
......@@ -1664,9 +1665,11 @@ print_operation_begin_print_cb (GtkPrintOperation *operation,
/* save the page setup */
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, "gthumb", "page_setup", NULL);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "page_setup", NULL);
filename = g_file_get_path (file);
gtk_page_setup_to_file (self->priv->page_setup, filename, NULL);
g_free (filename);
g_object_unref (file);
self->priv->printing = TRUE;
......@@ -1737,12 +1740,16 @@ print_operation_done_cb (GtkPrintOperation *operation,
}
else if (result == GTK_PRINT_OPERATION_RESULT_APPLY) {
GtkPrintSettings *settings;
GFile *file;
char *filename;
settings = gtk_print_operation_get_print_settings (operation);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, "gthumb", "print_settings", NULL);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "print_settings", NULL);
filename = g_file_get_path (file);
gtk_print_settings_to_file (settings, filename, NULL);
g_free (filename);
g_object_unref (file);
}
g_object_unref (self);
......@@ -1836,6 +1843,7 @@ load_image_info_task_completed_cb (GthTask *task,
GthImageInfo **loaded_images;
int i, j;
GtkPrintOperationResult result;
GFile *file;
char *filename;
GtkPrintSettings *settings;
......@@ -1878,17 +1886,21 @@ load_image_info_task_completed_cb (GthTask *task,
self->priv->images = loaded_images;
self->priv->n_images = n_loaded_images;
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, "gthumb", "print_settings", NULL);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "print_settings", NULL);
filename = g_file_get_path (file);
settings = gtk_print_settings_new_from_file (filename, NULL);
if (settings != NULL)
gtk_print_operation_set_print_settings (self->priv->print_operation, settings);
g_free (filename);
g_object_unref (file);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, "gthumb", "page_setup", NULL);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "page_setup", NULL);
filename = g_file_get_path (file);
self->priv->page_setup = gtk_page_setup_new_from_file (filename, NULL);
if (self->priv->page_setup != NULL)
gtk_print_operation_set_default_page_setup (self->priv->print_operation, self->priv->page_setup);
g_free (filename);
g_object_unref (file);
result = gtk_print_operation_run (self->priv->print_operation,
self->priv->action,
......
......@@ -153,7 +153,7 @@ gth_script_file_load_from_data (GthScriptFile *self,
static gboolean
gth_script_file_load_from_file (GthScriptFile *self,
const char *filename,
GFile *file,
GError **error)
{
char *buffer;
......@@ -162,10 +162,10 @@ gth_script_file_load_from_file (GthScriptFile *self,
gboolean retval;
g_return_val_if_fail (self != 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);
g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, &read_error);
if (read_error != NULL) {
g_propagate_error (error, read_error);
return FALSE;
......@@ -191,16 +191,16 @@ gth_script_file_load_from_file (GthScriptFile *self,
static void
_gth_script_file_load_if_needed (GthScriptFile *self)
{
char *default_script_file;
GFile *default_script_file;
if (self->priv->loaded)
return;
default_script_file = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "scripts.xml", NULL);
default_script_file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "scripts.xml", NULL);
gth_script_file_load_from_file (self, default_script_file, NULL);
self->priv->loaded = TRUE;
g_free (default_script_file);
g_object_unref (default_script_file);
}
......@@ -231,7 +231,7 @@ gth_script_file_to_data (GthScriptFile *self,
static gboolean
gth_script_file_to_file (GthScriptFile *self,
const char *filename,
GFile *file,
GError **error)
{
char *data;
......@@ -240,7 +240,7 @@ gth_script_file_to_file (GthScriptFile *self,
gboolean retval;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (file != NULL, FALSE);
data_error = NULL;
data = gth_script_file_to_data (self, &len, &data_error);
......@@ -250,8 +250,7 @@ gth_script_file_to_file (GthScriptFile *self,
}
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;
}
......@@ -285,17 +284,17 @@ gboolean
gth_script_file_save (GthScriptFile *self,
GError **error)
{
char *default_script_file;
GFile *default_script_file;
gboolean result;
_gth_script_file_load_if_needed (self);
default_script_file = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "scripts.xml", NULL);
default_script_file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "scripts.xml", NULL);
result = gth_script_file_to_file (self, default_script_file, error);
if (result)
g_signal_emit (G_OBJECT (self), gth_script_file_signals[CHANGED], 0);
g_free (default_script_file);
g_object_unref (default_script_file);
return result;
}
......
......@@ -727,18 +727,18 @@ oauth_accounts_load_from_file (const char *service_name,
{
GList *accounts = NULL;
char *filename;
char *path;
GFile *file;
char *buffer;
gsize len;
GError *error = NULL;
DomDocument *doc;
filename = g_strconcat (service_name, ".xml", NULL);
path = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
if (! g_file_get_contents (path, &buffer, &len, &error)) {
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
g_free (path);
g_object_unref (file);
g_free (filename);
return NULL;
}
......@@ -771,7 +771,7 @@ oauth_accounts_load_from_file (const char *service_name,
g_object_unref (doc);
g_free (buffer);
g_free (path);
g_object_unref (file);
g_free (filename);
return accounts;
......@@ -805,7 +805,6 @@ oauth_accounts_save_to_file (const char *service_name,
char *buffer;
gsize len;
char *filename;
char *path;
GFile *file;
doc = dom_document_new ();
......@@ -824,15 +823,12 @@ oauth_accounts_save_to_file (const char *service_name,
}
filename = g_strconcat (service_name, ".xml", NULL);
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
path = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
file = g_file_new_for_path (path);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
buffer = dom_document_dump (doc, &len);
g_write_file (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
g_free (buffer);
g_object_unref (file);
g_free (path);
g_free (filename);
g_object_unref (doc);
}
......@@ -755,14 +755,14 @@ GList *
picasa_web_accounts_load_from_file (char **_default)
{
GList *accounts = NULL;
char *filename;
GFile *file;
char *buffer;
gsize len;
DomDocument *doc;
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "picasaweb.xml", NULL);
if (! g_file_get_contents (filename, &buffer, &len, NULL)) {
g_free (filename);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "picasaweb.xml", NULL);
if (! g_load_file_in_buffer (file, (void **) &buffer, &len, NULL, NULL)) {
g_object_unref (file);
return NULL;
}
......@@ -795,7 +795,7 @@ picasa_web_accounts_load_from_file (char **_default)
g_object_unref (doc);
g_free (buffer);
g_free (filename);
g_object_unref (file);
return accounts;
}
......@@ -810,7 +810,6 @@ picasa_web_accounts_save_to_file (GList *accounts,
GList *scan;
char *buffer;
gsize len;
char *filename;
GFile *file;
doc = dom_document_new ();
......@@ -828,14 +827,11 @@ picasa_web_accounts_save_to_file (GList *accounts,
dom_element_append_child (root, node);
}
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "picasaweb.xml", NULL);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "picasaweb.xml", NULL);
file = g_file_new_for_path (filename);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "picasaweb.xml", NULL);
buffer = dom_document_dump (doc, &len);
g_write_file (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
g_free (buffer);
g_object_unref (file);
g_free (filename);
g_object_unref (doc);
}
......@@ -236,16 +236,18 @@ static char *
get_cache_full_path (const char *filename,
const char *extension)
{
char *name;
char *cache_filename;
char *name;
GFile *file;
char *cache_filename;
if (extension == NULL)
name = g_strdup (filename);
else
name = g_strconcat (filename, ".", extension, NULL);
gth_user_dir_make_dir_for_file (GTH_DIR_CACHE, "gthumb", name, NULL);
cache_filename = gth_user_dir_get_file (GTH_DIR_CACHE, "gthumb", name, NULL);
file = gth_user_dir_get_file_for_write (GTH_DIR_CACHE, GTHUMB_DIR, name, NULL);
cache_filename = g_file_get_path (file);
g_object_unref (file);
g_free (name);
return cache_filename;
......
......@@ -317,7 +317,6 @@ add_themes_from_dir (DialogData *data,
static void
load_themes (DialogData *data)
{
char *style_path;
GFile *style_dir;
GFile *data_dir;
char *default_theme;
......@@ -326,11 +325,9 @@ load_themes (DialogData *data)
/* local themes */
style_path = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, "albumthemes", NULL);
style_dir = g_file_new_for_path (style_path);
style_dir = gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "albumthemes", NULL);
add_themes_from_dir (data, style_dir);
g_object_unref (style_dir);
g_free (style_path);
/* system themes */
......
......@@ -267,7 +267,6 @@ static GFile *
get_style_dir (GthWebExporter *self,
const char *style_name)
{
char *style_path;
GFile *style_dir;
GFile *data_dir;
......@@ -276,9 +275,7 @@ get_style_dir (GthWebExporter *self,
/* search in local themes */
style_path = gth_user_dir_get_file (GTH_DIR_DATA, GTHUMB_DIR, "albumthemes", style_name, NULL);
style_dir = g_file_new_for_path (style_path);
g_free (style_path);
style_dir = gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "albumthemes", style_name, NULL);
if (g_file_query_exists (style_dir, NULL))
return style_dir;
......
......@@ -1001,18 +1001,20 @@ gth_main_get_registered_object (GType superclass_type,
GBookmarkFile *
gth_main_get_default_bookmarks (void)
{
char *path;
GFile *file;
char *filename;
if (Main->priv->bookmarks != NULL)
return Main->priv->bookmarks;
Main->priv->bookmarks = g_bookmark_file_new ();
path = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, BOOKMARKS_FILE, NULL);
g_bookmark_file_load_from_file (Main->priv->bookmarks,
path,
NULL);
g_free (path);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, BOOKMARKS_FILE, NULL);
filename = g_file_get_path (file);
g_bookmark_file_load_from_file (Main->priv->bookmarks, filename, NULL);
g_free (filename);
g_object_unref (file);
return Main->priv->bookmarks;
}
......@@ -1021,13 +1023,15 @@ gth_main_get_default_bookmarks (void)
void
gth_main_bookmarks_changed (void)
{
char *filename;
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, BOOKMARKS_FILE, NULL);
GFile *file;
char *filename;
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, BOOKMARKS_FILE, NULL);
file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, BOOKMARKS_FILE, NULL);
filename = g_file_get_path (file);
g_bookmark_file_to_file (Main->priv->bookmarks, filename, NULL);
g_free (filename);
g_object_unref (file);
gth_monitor_bookmarks_changed (gth_main_get_default_monitor ());
}
......@@ -1036,15 +1040,19 @@ gth_main_bookmarks_changed (void)
GthFilterFile *
gth_main_get_default_filter_file (void)