gthumb r2391 - in trunk: . libgthumb src
- From: mjc svn gnome org
- To: svn-commits-list gnome org
- Subject: gthumb r2391 - in trunk: . libgthumb src
- Date: Sun, 10 Aug 2008 11:55:57 +0000 (UTC)
Author: mjc
Date: Sun Aug 10 11:55:57 2008
New Revision: 2391
URL: http://svn.gnome.org/viewvc/gthumb?rev=2391&view=rev
Log:
2008-08-10 Michael J. Chudobiak <mjc svn gnome org>
* libgthumb/file-utils.c: (dir_remove_recursive),
(local_dir_remove_recursive), (ensure_dir_exists), (path_is_file),
(path_is_dir), (get_file_size), (get_temp_dir_name),
(get_destination_free_space):
* libgthumb/file-utils.h:
* libgthumb/gfile-utils.c: (gfile_get_uri), (gfile_get_path),
(gfile_warning), (gfile_is_filetype), (gfile_path_is_file),
(gfile_path_is_dir), (gfile_get_file_size), (make_directory_tree),
(gfile_ensure_dir_exists), (gfile_is_local),
(gfile_get_destination_free_space), (gfile_get_home_dir),
(gfile_get_tmp_dir), (ith_temp_folder_to_try),
(gfile_make_temp_in_dir), (gfile_get_temp_dir_name),
(delete_directory_recursive), (gfile_dir_remove_recursive):
* libgthumb/gfile-utils.h:
* src/catalog-web-exporter.c: (gfile_get_relative_uri),
(gfile_get_relative_path), (gth_parsed_doc_print),
(export__save_other_files), (save_thumbnail_cb),
(save_html_image_cb), (save_html_index_cb),
(save_image_preview_cb), (save_resized_image_cb),
(export__copy_image), (ensure_album_dir_exists),
(ensure_dir_structure), (catalog_web_exporter_export):
More gfile migration by Christophe BisiÃre. Bug #525482.
The new gfile-only utility functions are going into
gfile-utils.[ch]. The old path/uri functions are being reduced
to wrappers for the new gfile functions, until they can be
purged entirely.
Modified:
trunk/ChangeLog
trunk/libgthumb/file-utils.c
trunk/libgthumb/file-utils.h
trunk/libgthumb/gfile-utils.c
trunk/libgthumb/gfile-utils.h
trunk/src/catalog-web-exporter.c
Modified: trunk/libgthumb/file-utils.c
==============================================================================
--- trunk/libgthumb/file-utils.c (original)
+++ trunk/libgthumb/file-utils.c Sun Aug 10 11:55:57 2008
@@ -53,6 +53,7 @@
#include "gthumb-error.h"
#include "glib-utils.h"
#include "gconf-utils.h"
+#include "gfile-utils.h"
#include "file-utils.h"
#include "file-data.h"
#include "pixbuf-utils.h"
@@ -417,99 +418,54 @@
gboolean
-dir_remove_recursive (const char *uri)
+dir_remove_recursive (const char *path)
{
- GList *files, *dirs;
- GList *scan;
- gboolean error = FALSE;
-
- if (! path_is_dir (uri))
+ GFile *file;
+ gboolean result;
+ char *uri;
+
+ if (path == NULL)
return FALSE;
+
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
+
+ result = gfile_dir_remove_recursive (file);
+
+ g_free (uri);
+ g_object_unref (file);
- path_list_new (uri, &files, &dirs);
-
- for (scan = files; scan; scan = scan->next) {
- FileData *file = scan->data;
- if (! file_unlink (file->path)) {
- g_warning ("Cannot delete %s\n", file->path);
- error = TRUE;
- }
- }
- file_data_list_free (files);
-
- for (scan = dirs; scan; scan = scan->next) {
- char *sub_dir = scan->data;
- if (! dir_remove_recursive (sub_dir))
- error = TRUE;
- }
- path_list_free (dirs);
-
- if (! dir_remove (uri))
- error = TRUE;
-
- return ! error;
+ return result;
}
gboolean
local_dir_remove_recursive (const char *path)
{
- char *uri;
- gboolean result = FALSE;
-
- uri = get_uri_from_local_path (path);
- result = dir_remove_recursive (uri);
- g_free (uri);
-
- return result;
+ return dir_remove_recursive (path);
}
gboolean
-ensure_dir_exists (const char *a_path,
+ensure_dir_exists (const char *path,
mode_t mode)
{
- char *path;
- char *p;
-
- if (! a_path)
+ GFile *file;
+ gboolean result;
+ char *uri;
+
+ if (path == NULL)
return FALSE;
+
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
+
+ result = gfile_ensure_dir_exists (file, mode, NULL);
+
+ g_free (uri);
+ g_object_unref (file);
- if (path_is_dir (a_path))
- return TRUE;
-
- path = g_strdup (a_path);
-
- p = strstr (path, "://");
- if (p == NULL) /* Not a URI */
- p = path;
- else /* Is a URI */
- p = p + 3; /* Move p past the :// */
-
- while (*p != '\0') {
- p++;
- if ((*p == '/') || (*p == '\0')) {
- gboolean end = TRUE;
-
- if (*p != '\0') {
- *p = '\0';
- end = FALSE;
- }
-
- if (! path_is_dir (path)) {
- if (!dir_make (path, mode)) {
- g_warning ("directory creation failed: %s.", path);
- g_free (path);
- return FALSE;
- }
- }
- if (! end) *p = '/';
- }
- }
-
- g_free (path);
-
- return TRUE;
+ return result;
}
@@ -1091,78 +1047,65 @@
gboolean
path_is_file (const char *path)
{
- GnomeVFSFileInfo *info;
- GnomeVFSResult result;
- gboolean is_file;
-
- if (! path || ! *path)
+ GFile *file;
+ gboolean result;
+ char *uri;
+
+ if (path == NULL)
return FALSE;
+
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
+
+ result = gfile_path_is_file (file);
+
+ g_free (uri);
+ g_object_unref (file);
- info = gnome_vfs_file_info_new ();
- result = gnome_vfs_get_file_info (path,
- info,
- (GNOME_VFS_FILE_INFO_DEFAULT
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
- is_file = FALSE;
- if (result == GNOME_VFS_OK)
- is_file = (info->type == GNOME_VFS_FILE_TYPE_REGULAR);
-
- gnome_vfs_file_info_unref (info);
-
- return is_file;
+ return result;
}
-
gboolean
path_is_dir (const char *path)
{
- GnomeVFSFileInfo *info;
- GnomeVFSResult result;
- gboolean is_dir;
-
- if (! path || ! *path)
+ GFile *file;
+ gboolean result;
+ char *uri;
+
+ if (path == NULL)
return FALSE;
- info = gnome_vfs_file_info_new ();
- result = gnome_vfs_get_file_info (path,
- info,
- (GNOME_VFS_FILE_INFO_DEFAULT
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
- is_dir = FALSE;
- if (result == GNOME_VFS_OK)
- is_dir = (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY);
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
- gnome_vfs_file_info_unref (info);
+ result = gfile_path_is_dir (file);
+
+ g_free (uri);
+ g_object_unref (file);
- return is_dir;
+ return result;
}
goffset
-get_file_size (const char *uri)
+get_file_size (const char *path)
{
- GFile *file;
- GFileInfo *info;
- goffset size;
- GError *err = NULL;
-
- if ((uri == NULL) || (*uri == '\0'))
- return 0;
-
- file = g_file_new_for_uri (uri);
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, &err);
- if (err == NULL) {
- size = g_file_info_get_size (info);
- }
- else {
- g_warning ("Failed to get file size for %s: %s", uri, err->message);
- g_error_free (err);
- }
+ GFile *file;
+ goffset result;
+ char *uri;
+
+ if (path == NULL)
+ return 0;
+
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
- g_object_unref (info);
- g_object_unref (file);
+ result = gfile_get_file_size (file);
+
+ g_free (uri);
+ g_object_unref (file);
- return size;
+ return result;
}
@@ -2458,68 +2401,24 @@
/* temp */
-
-static const char *try_folder[] = { "~", "tmp", NULL };
-
-
-static const char *
-get_folder_from_try_folder_list (int n)
-{
- const char *folder;
-
- folder = try_folder[n];
- if (strcmp (folder, "~") == 0)
- folder = g_get_home_dir ();
- else if (strcmp (folder, "tmp") == 0)
- folder = g_get_tmp_dir ();
-
- return folder;
-}
-
+/* Note: callers of get_temp_dir_name seem to expect a path */
char *
get_temp_dir_name (void)
{
- GnomeVFSFileSize max_size = 0;
- char *best_folder = NULL;
- int i;
- char *template;
- char *result = NULL;
-
- /* find the folder with the bigger free space. */
-
- for (i = 0; try_folder[i] != NULL; i++) {
- const char *folder;
- char *uri;
- GnomeVFSFileSize size;
-
- folder = get_folder_from_try_folder_list (i);
- uri = get_uri_from_local_path (folder);
-
- size = get_destination_free_space (uri);
- if (size > max_size) {
- max_size = size;
- g_free (best_folder);
- best_folder = get_local_path_from_uri (uri);
- }
- else
- g_free (uri);
- }
-
- if (best_folder == NULL)
+ GFile *dir;
+ char *path;
+
+ dir = gfile_get_temp_dir_name ();
+
+ if (dir == NULL)
return NULL;
-
- template = g_strconcat (best_folder, "/.gth-XXXXXX", NULL);
- g_free (best_folder);
-
- result = mkdtemp (template);
-
- if ((result == NULL) || (*result == '\0')) {
- g_free (template);
- result = NULL;
- }
-
- return result;
+
+ path = g_file_get_path (dir);
+
+ g_object_unref (dir);
+
+ return path;
}
@@ -2766,21 +2665,25 @@
}
-GnomeVFSFileSize
-get_destination_free_space (const char *uri)
+guint64
+get_destination_free_space (const char *path)
{
- GnomeVFSURI *vfs_uri;
- GnomeVFSResult result;
- GnomeVFSFileSize free_space;
-
- vfs_uri = gnome_vfs_uri_new (uri);
- result = gnome_vfs_get_volume_free_space (vfs_uri, &free_space);
- gnome_vfs_uri_unref (vfs_uri);
+ GFile *file;
+ gboolean result;
+ char *uri;
+
+ if (path == NULL)
+ return FALSE;
+
+ uri = add_scheme_if_absent (path);
+ file = g_file_new_for_uri (uri);
- if (result != GNOME_VFS_OK)
- return (GnomeVFSFileSize) 0;
- else
- return free_space;
+ result = gfile_get_destination_free_space (file);
+
+ g_free (uri);
+ g_object_unref (file);
+
+ return result;
}
Modified: trunk/libgthumb/file-utils.h
==============================================================================
--- trunk/libgthumb/file-utils.h (original)
+++ trunk/libgthumb/file-utils.h Sun Aug 10 11:55:57 2008
@@ -95,10 +95,10 @@
gboolean dir_make (const char *uri,
mode_t mode);
gboolean dir_remove (const char *uri);
-gboolean dir_remove_recursive (const char *uri);
+gboolean dir_remove_recursive (const char *path);
gboolean local_dir_remove_recursive (const char *path);
-gboolean ensure_dir_exists (const char *a_path,
+gboolean ensure_dir_exists (const char *path,
mode_t mode);
GList * dir_list_filter_and_sort (GList *dir_list,
gboolean names_only,
@@ -150,7 +150,7 @@
gboolean path_exists (const char *s);
gboolean path_is_file (const char *s);
gboolean path_is_dir (const char *s);
-goffset get_file_size (const char *s);
+goffset get_file_size (const char *path);
time_t get_file_mtime (const char *s);
time_t get_file_ctime (const char *s);
void set_file_mtime (const char *s,
@@ -249,7 +249,7 @@
GnomeVFSResult _gnome_vfs_write_line (GnomeVFSHandle *handle,
const char *format,
...);
-GnomeVFSFileSize get_destination_free_space (const char *path);
+guint64 get_destination_free_space (const char *path);
const char * get_mime_type (const char *path);
const char* get_file_mime_type (const char *path,
gboolean fast_file_type);
Modified: trunk/libgthumb/gfile-utils.c
==============================================================================
--- trunk/libgthumb/gfile-utils.c (original)
+++ trunk/libgthumb/gfile-utils.c Sun Aug 10 11:55:57 2008
@@ -21,3 +21,400 @@
*/
+#include <stdlib.h>
+#include <glib.h>
+
+#include "gfile-utils.h"
+
+
+/*
+ * NOTE: All these functions accept/return _only_ uri-style GFiles.
+ */
+
+
+
+/* GFile to string */
+
+char *
+gfile_get_uri (GFile *file)
+{
+ return g_file_get_uri (file);
+}
+
+
+char *
+gfile_get_path (GFile *file)
+{
+ char *escaped, *unescaped;
+
+ escaped = g_file_get_path (file);
+ unescaped = g_uri_unescape_string (escaped, NULL);
+
+ g_free (escaped);
+
+ return unescaped;
+}
+
+
+/* warning about a GFile */
+
+void
+gfile_warning (const char *msg,
+ GFile *file,
+ GError *err)
+{
+ char *uri;
+ char *warning;
+
+ uri = gfile_get_uri (file);
+ warning = g_strdup_printf ("%s: file %s: %s\n", msg, uri, err->message);
+
+ g_warning (warning);
+
+ g_free (uri);
+}
+
+
+/* File utils */
+
+static gboolean
+gfile_is_filetype (GFile *file,
+ GFileType file_type)
+{
+ gboolean result = FALSE;
+ GFileInfo *info;
+ GError *error = NULL;
+
+ if (! g_file_query_exists (file, NULL))
+ return FALSE;
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ 0,
+ NULL,
+ &error);
+ if (error == NULL) {
+ result = (g_file_info_get_file_type (info) == file_type);
+ }
+ else {
+ gfile_warning ("Failed to get file type", file, error);
+ g_error_free (error);
+ }
+
+ g_object_unref (info);
+
+ return result;
+}
+
+
+gboolean
+gfile_path_is_file (GFile *file)
+{
+ return gfile_is_filetype (file, G_FILE_TYPE_REGULAR);
+}
+
+
+gboolean
+gfile_path_is_dir (GFile *file)
+{
+ return gfile_is_filetype (file, G_FILE_TYPE_DIRECTORY);
+}
+
+
+goffset
+gfile_get_file_size (GFile *file)
+{
+ GFileInfo *info;
+ goffset size = 0;
+ GError *err = NULL;
+
+ //FIXME: shouldn't we get rid of this test and fix the callers instead
+ if (file == NULL)
+ return 0;
+
+ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, &err);
+ if (err == NULL) {
+ size = g_file_info_get_size (info);
+ }
+ else {
+ gfile_warning ("Failed to get file size", file, err);
+ g_error_free (err);
+ }
+
+ g_object_unref (info);
+
+ return size;
+}
+
+
+/* Directory utils */
+
+static gboolean
+make_directory_tree (GFile *dir,
+ mode_t mode,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GFile *parent;
+
+ parent = g_file_get_parent (dir);
+ if (parent != NULL) {
+ success = make_directory_tree (parent, mode, error);
+ g_object_unref (parent);
+ if (! success)
+ return FALSE;
+ }
+
+ success = g_file_make_directory (dir, NULL, error);
+ if ((error != NULL) && (*error != NULL) && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_clear_error (error);
+ success = TRUE;
+ }
+
+ if (success)
+ g_file_set_attribute_uint32 (dir,
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ mode,
+ 0,
+ NULL,
+ NULL);
+
+ return success;
+}
+
+
+gboolean
+gfile_ensure_dir_exists (GFile *dir,
+ mode_t mode,
+ GError **error)
+{
+ GError *priv_error = NULL;
+
+ //FIXME: shouldn't we get rid of this test and fix the callers instead
+ if (dir == NULL)
+ return FALSE;
+
+ if (error == NULL)
+ error = &priv_error;
+
+ if (! make_directory_tree (dir, mode, error)) {
+
+ gfile_warning ("could not create directory", dir, *error);
+ if (priv_error != NULL)
+ g_clear_error (&priv_error);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+gboolean
+gfile_is_local (GFile *file)
+{
+ return g_file_has_uri_scheme (file, "file");
+}
+
+
+guint64
+gfile_get_destination_free_space (GFile *file)
+{
+ guint64 freespace = 0;
+ GFileInfo *info;
+ GError *err = NULL;
+
+ info = g_file_query_filesystem_info (file,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
+ NULL,
+ &err);
+ if (info != NULL) {
+ freespace = g_file_info_get_attribute_uint64 (info,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ g_object_unref (info);
+ }
+ else {
+ gfile_warning ("Could not get filesystem free space on volume containing the file",
+ file,
+ err);
+ g_error_free (err);
+ }
+
+ return freespace;
+}
+
+
+GFile *
+gfile_get_home_dir (void)
+{
+ GFile *dir;
+ char *path;
+
+ path = g_strconcat ("file://", g_get_home_dir (), NULL);
+ dir = g_file_new_for_uri (path);
+
+ g_free (path);
+
+ return dir;
+}
+
+
+GFile *
+gfile_get_tmp_dir (void)
+{
+ GFile *dir;
+ char *path;
+
+ path = g_strconcat ("file://", g_get_tmp_dir (), NULL);
+ dir = g_file_new_for_uri (path);
+
+ g_free (path);
+
+ return dir;
+}
+
+
+#define MAX_TEMP_FOLDER_TO_TRY 2
+
+static GFile *
+ith_temp_folder_to_try (int n)
+{
+ GFile *dir = NULL;
+
+ if (n == 1)
+ dir = gfile_get_home_dir ();
+ else if (n == 2)
+ dir = gfile_get_tmp_dir ();
+
+ return dir;
+}
+
+
+GFile *
+gfile_make_temp_in_dir (GFile *in_dir)
+{
+ char *path0;
+ char *path1;
+ char *path2;
+ char *template;
+ GFile *dir;
+
+ path0 = g_file_get_path (in_dir);
+ template = g_strconcat (path0, "/.gt-XXXXXX", NULL);
+ g_free (path0);
+
+ path1 = mkdtemp (template);
+
+ if (path1 == NULL)
+ return NULL;
+
+ path2 = g_strconcat ("file://", path1, NULL);
+ dir = g_file_new_for_uri (path2);
+
+ g_free (path1);
+ g_free (path2);
+
+ return dir;
+}
+
+
+GFile *
+gfile_get_temp_dir_name (void)
+{
+ int i;
+ guint64 max_size = 0;
+ GFile *best_folder = NULL;
+ GFile *tmp_dir;
+
+ /* find the folder with more free space. */
+
+ for (i = 1; i <= MAX_TEMP_FOLDER_TO_TRY; i++) {
+ GFile *folder;
+ guint64 size;
+
+ folder = ith_temp_folder_to_try (i);
+ size = gfile_get_destination_free_space (folder);
+ if (max_size < size) {
+ max_size = size;
+ UNREF (best_folder)
+ best_folder = folder;
+ }
+ else
+ g_object_unref (folder);
+ }
+
+ if (best_folder == NULL)
+ return NULL;
+
+ if (! gfile_is_local (best_folder)) {
+ g_object_unref (best_folder);
+ return NULL;
+ }
+
+ tmp_dir = gfile_make_temp_in_dir (best_folder);
+
+ g_object_unref (best_folder);
+
+ return tmp_dir;
+}
+
+
+static gboolean
+delete_directory_recursive (GFile *dir,
+ GError **error)
+{
+ GFileEnumerator *file_enum;
+ GFileInfo *info;
+ gboolean error_occurred = FALSE;
+
+ if (error != NULL)
+ *error = NULL;
+
+ file_enum = g_file_enumerate_children (dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ 0, NULL, error);
+
+ while (! error_occurred && (info = g_file_enumerator_next_file (file_enum, NULL, error)) != NULL) {
+ GFile *child;
+
+ child = g_file_get_child (dir, g_file_info_get_name (info));
+
+ switch (g_file_info_get_file_type (info)) {
+ case G_FILE_TYPE_DIRECTORY:
+ if (! delete_directory_recursive (child, error))
+ error_occurred = TRUE;
+ break;
+ default:
+ if (! g_file_delete (child, NULL, error))
+ error_occurred = TRUE;
+ break;
+ }
+
+ g_object_unref (child);
+ g_object_unref (info);
+ }
+
+ if (! error_occurred && ! g_file_delete (dir, NULL, error))
+ error_occurred = TRUE;
+
+ g_object_unref (file_enum);
+
+ return ! error_occurred;
+}
+
+
+gboolean
+gfile_dir_remove_recursive (GFile *dir)
+{
+ gboolean result;
+ GError *error = NULL;
+
+ result = delete_directory_recursive (dir, &error);
+ if (! result) {
+ gfile_warning ("Cannot delete directory", dir, error);
+ g_clear_error (&error);
+ }
+
+ return result;
+}
Modified: trunk/libgthumb/gfile-utils.h
==============================================================================
--- trunk/libgthumb/gfile-utils.h (original)
+++ trunk/libgthumb/gfile-utils.h Sun Aug 10 11:55:57 2008
@@ -23,5 +23,43 @@
#ifndef GFILE_UTILS_H
#define GFILE_UTILS_H
-
+#include <gio/gio.h>
+
+
+#define UNREF(obj) { \
+ if (obj != NULL) { \
+ g_object_unref (obj); \
+ obj = NULL; \
+ } \
+}
+
+/*
+ * NOTE: All these functions accept/return _only_ uri-style GFiles.
+ */
+
+/* GFile to string */
+
+char * gfile_get_uri (GFile *file);
+char * gfile_get_path (GFile *file);
+
+/* Warning */
+
+void gfile_warning (const char *msg,
+ GFile *file,
+ GError *err);
+/* File utils */
+
+gboolean gfile_path_is_file (GFile *file);
+gboolean gfile_path_is_dir (GFile *file);
+goffset gfile_get_file_size (GFile *file);
+
+/* Directory utils */
+
+gboolean gfile_ensure_dir_exists (GFile *dir,
+ mode_t mode,
+ GError **error);
+guint64 gfile_get_destination_free_space (GFile *file);
+GFile * gfile_get_temp_dir_name (void);
+gboolean gfile_dir_remove_recursive (GFile *dir);
+
#endif /* GFILE_UTILS_H */
Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c (original)
+++ trunk/src/catalog-web-exporter.c Sun Aug 10 11:55:57 2008
@@ -36,6 +36,7 @@
#include "catalog-web-exporter.h"
#include "comments.h"
+#include "gfile-utils.h"
#include "file-utils.h"
#include "gconf-utils.h"
#include "jpegutils/jpeg-data.h"
@@ -88,13 +89,6 @@
#define SAVING_TIMEOUT 5
-#define UNREF(obj) { \
- if (obj != NULL) { \
- g_object_unref (obj); \
- obj = NULL; \
- } \
-}
-
/* Default subdirectories.
* - Used as fallback when gconf values are empty or not accessible
* - Please keep in sync with values in gthumb.schemas.in
@@ -1100,22 +1094,15 @@
/* GFile to string */
static char *
-file_get_uri (GFile *file)
-{
- return g_file_get_uri (file);
-}
-
-
-static char *
-file_get_relative_uri (GFile *file,
- GFile *relative_to)
+gfile_get_relative_uri (GFile *file,
+ GFile *relative_to)
{
char *escaped;
char *relative_uri;
char *result;
- escaped = file_get_uri (file);
- relative_uri = file_get_uri (relative_to);
+ escaped = gfile_get_uri (file);
+ relative_uri = gfile_get_uri (relative_to);
result = get_path_relative_to_uri (escaped, relative_uri);
@@ -1127,26 +1114,12 @@
static char *
-file_get_path (GFile *file)
-{
- char *escaped, *unescaped;
-
- escaped = g_file_get_path (file);
- unescaped = g_uri_unescape_string (escaped, NULL);
-
- g_free (escaped);
-
- return unescaped;
-}
-
-
-static char *
-file_get_relative_path (GFile *file,
- GFile *relative_to)
+gfile_get_relative_path (GFile *file,
+ GFile *relative_to)
{
char *escaped, *unescaped;
- escaped = file_get_relative_uri (file, relative_to);
+ escaped = gfile_get_relative_uri (file, relative_to);
unescaped = g_uri_unescape_string (escaped, NULL);
g_free (escaped);
@@ -1155,6 +1128,7 @@
}
+
/* build a GFile (helpers) */
GFile *
@@ -1538,7 +1512,7 @@
file = get_theme_file (ce,
ce->target_dir,
src);
- line = file_get_relative_uri (file, relative_to);
+ line = gfile_get_relative_uri (file, relative_to);
write_markup_escape_line (line, fout);
@@ -1576,7 +1550,7 @@
break;
}
- image_src = file_get_relative_uri (file, relative_to);
+ image_src = gfile_get_relative_uri (file, relative_to);
src_attr = _g_escape_text_for_html (image_src, -1);
class = gth_tag_get_str (ce, tag, "class");
@@ -1633,7 +1607,7 @@
file = get_html_image_file (ce,
idata,
ce->target_dir);
- line = file_get_relative_uri (file, relative_to);
+ line = gfile_get_relative_uri (file, relative_to);
write_markup_escape_line (line, fout);
g_object_unref (file);
@@ -1686,10 +1660,10 @@
relative = (gth_tag_get_var (ce, tag, "with_relative_path") != 0);
if (relative)
- unescaped_path = file_get_relative_path (file,
+ unescaped_path = gfile_get_relative_path (file,
relative_to);
else
- unescaped_path = file_get_path (file);
+ unescaped_path = gfile_get_path (file);
if (relative || (gth_tag_get_var (ce, tag, "with_path") != 0)) {
@@ -1737,10 +1711,10 @@
relative = (gth_tag_get_var (ce, tag, "relative_path") != 0);
if (relative)
- line = file_get_relative_path (dir,
+ line = gfile_get_relative_path (dir,
relative_to);
else
- line = file_get_path (dir);
+ line = gfile_get_path (dir);
if (gth_tag_get_var (ce, tag, "utf8") != 0)
write_markup_escape_locale_line (line, fout);
@@ -1842,7 +1816,7 @@
file = get_html_index_file (ce,
idx,
ce->target_dir);
- line = file_get_relative_uri (file, relative_to);
+ line = gfile_get_relative_uri (file, relative_to);
write_markup_escape_line (line, fout);
g_object_unref (file);
@@ -2227,7 +2201,7 @@
file = get_theme_file (ce,
ce->target_tmp_dir,
info->name);
- uri = file_get_uri (file);
+ uri = gfile_get_uri (file);
target_uri = gnome_vfs_uri_new (uri);
source_uri_list = g_list_prepend (source_uri_list, source_uri);
@@ -2303,7 +2277,7 @@
file = get_thumbnail_file (ce,
idata,
ce->target_tmp_dir);
- local_file = file_get_path (file);
+ local_file = gfile_get_path (file);
debug (DEBUG_INFO, "save thumbnail: %s", local_file);
@@ -2374,7 +2348,7 @@
file = get_html_image_file (ce,
idata,
ce->target_tmp_dir);
- local_file = file_get_path (file);
+ local_file = gfile_get_path (file);
debug (DEBUG_INFO, "save html file: %s", local_file);
@@ -2456,7 +2430,7 @@
ce->page,
ce->target_tmp_dir);
- local_file = file_get_path (file);
+ local_file = gfile_get_path (file);
debug (DEBUG_INFO, "save html index: %s", local_file);
@@ -2584,7 +2558,7 @@
file = get_preview_file (ce,
idata,
ce->target_tmp_dir);
- local_file = file_get_path (file);
+ local_file = gfile_get_path (file);
debug (DEBUG_INFO, "saving preview: %s", local_file);
@@ -2630,8 +2604,8 @@
file = get_image_file (ce,
idata,
ce->target_tmp_dir);
- image_uri = file_get_uri (file);
- local_file = file_get_path (file);
+ image_uri = gfile_get_uri (file);
+ local_file = gfile_get_path (file);
debug (DEBUG_INFO, "saving image: %s", local_file);
@@ -2683,7 +2657,7 @@
file = get_image_file (ce,
idata,
ce->target_tmp_dir);
- uri = file_get_uri (file);
+ uri = gfile_get_uri (file);
target_uri = gnome_vfs_uri_new (uri);
result = gnome_vfs_xfer_uri (source_uri,
@@ -3051,30 +3025,16 @@
}
-gboolean
-ensure_album_dir_exists_from_file (GFile *dir)
-{
- char *uri;
- gboolean ok;
-
- uri = file_get_uri (dir);
- ok = ensure_dir_exists (uri, 0700);
-
- g_free (uri);
-
- return ok;
-}
-
-
-gboolean
-ensure_album_dir_exists (GFile *target_dir, const char *subdir)
+static gboolean
+ensure_album_dir_exists (GFile *target_dir,
+ const char *subdir)
{
gboolean ok;
GFile *dir;
dir = file_resolve_relative_path (target_dir, subdir);
- ok = ensure_album_dir_exists_from_file (dir);
+ ok = gfile_ensure_dir_exists (dir, 0700, NULL);
g_object_unref (dir);
@@ -3082,11 +3042,11 @@
}
-void
+static void
ensure_dir_structure (CatalogWebExporter *ce,
GFile *target_dir)
{
- ensure_album_dir_exists_from_file (target_dir);
+ gfile_ensure_dir_exists (target_dir, 0700, NULL);
if (ce->use_subfolders) {
ensure_album_dir_exists (target_dir, ce->ad->previews);
@@ -3104,8 +3064,6 @@
void
catalog_web_exporter_export (CatalogWebExporter *ce)
{
- char *tmp_dir;
-
g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
if ((ce->exporting) || (ce->file_list == NULL))
@@ -3124,19 +3082,21 @@
/* get tmp dir */
- tmp_dir = get_temp_dir_name ();
+ UNREF (ce->target_tmp_dir)
+ ce->target_tmp_dir = gfile_get_temp_dir_name ();
- if (tmp_dir == NULL) {
+ if (ce->target_tmp_dir == NULL) {
_gtk_error_dialog_run (GTK_WINDOW (ce->window), _("Could not create a temporary folder"));
g_signal_emit (G_OBJECT (ce), catalog_web_exporter_signals[WEB_EXPORTER_DONE], 0);
return;
}
-
- debug (DEBUG_INFO, "temp dir: %s", tmp_dir);
-
- UNREF (ce->target_tmp_dir)
- ce->target_tmp_dir = g_file_new_for_path (tmp_dir);
- g_free (tmp_dir);
+ else {
+ char *tmp_dir;
+
+ tmp_dir = gfile_get_path (ce->target_tmp_dir);
+ debug (DEBUG_INFO, "temp dir: %s", tmp_dir);
+ g_free (tmp_dir);
+ }
/* compute n_images, n_pages */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]