[conglomerate] Remove dependency on libgnome-vfs
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [conglomerate] Remove dependency on libgnome-vfs
- Date: Thu, 25 Aug 2011 04:16:11 +0000 (UTC)
commit f6cb9fbe7fd55c9be1437421a840270a9c260c27
Author: P. F. Chimento <philip chimento gmail com>
Date: Sat Aug 13 21:52:44 2011 +0200
Remove dependency on libgnome-vfs
See bug #656279.
This patch removes the dependency on libgnome-vfs. GFile objects are
passed to functions wherever possible - before it was a mix of
GnomeVfsURIs, C-string local paths, and C-string URIs. GFile allows
simple extraction of the filename, local path, or URI wherever each one
is needed.
configure.ac | 3 +-
src/cong-app.c | 14 +-
src/cong-dispspec-registry.c | 146 ++++++++---------
src/cong-dispspec.c | 24 ++--
src/cong-dispspec.h | 2 +-
src/cong-document.c | 161 +++++++-----------
src/cong-document.h | 24 ++--
src/cong-error-dialog.c | 2 +
src/cong-error-dialog.h | 36 ++--
src/cong-error-file-open.c | 233 +++++++++++----------------
src/cong-error-file-save.c | 216 +++++++------------------
src/cong-error-tests.c | 45 ++++--
src/cong-file-export.c | 51 ++++---
src/cong-file-import.c | 31 ++--
src/cong-file-open.c | 25 ++--
src/cong-file-properties.c | 36 +++--
src/cong-file-save.c | 150 ++++++++---------
src/cong-file-selection.h | 8 +-
src/cong-graph.c | 12 +-
src/cong-graph.h | 8 +-
src/cong-menus.c | 10 +-
src/cong-overview-view.c | 26 ++--
src/cong-parser-error.c | 22 ++--
src/cong-parser-error.h | 12 +-
src/cong-plugin.c | 19 ++-
src/cong-plugin.h | 6 +-
src/cong-service-exporter.c | 29 ++--
src/cong-service-exporter.h | 12 +-
src/cong-service-importer.c | 6 +-
src/cong-service-importer.h | 4 +-
src/cong-stylesheet.c | 29 ++--
src/cong-ui-hooks.h | 2 +-
src/cong-util.c | 100 +++++++++++-
src/cong-util.h | 6 +
src/cong-vfs.c | 367 +++++++++++++++--------------------------
src/cong-vfs.h | 48 +++---
src/file.c | 23 ++--
src/global.h | 3 -
src/main.c | 2 -
src/plugin-convert-case.c | 25 ++--
src/plugin-docbook.c | 48 +++---
src/plugin-dtd.c | 28 ++--
src/plugin-fo.c | 4 +-
src/plugin-save-dispspec.c | 34 +++--
src/plugin-sgml.c | 13 +-
src/plugin-templates.c | 66 +++++---
46 files changed, 1012 insertions(+), 1159 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c8e36ac..e569f67 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@ AM_GLIB_GNU_GETTEXT
dnl --- Package configuration ---
GTK2_REQUIRED=2.10.0
+GIO_REQUIRED=2.20.0
LIBXML_REQUIRED=2.0.0
LIBXSLT_REQUIRED=1.0.0
LIBGNOMEPRINT_REQUIRED=1.116.0
@@ -49,10 +50,10 @@ dnl --- Fundamentals ---
PKG_CHECK_MODULES([CONGLOMERATE], [
gtk+-2.0 >= $GTK2_REQUIRED
+ gio-2.0 >= $GIO_REQUIRED
gconf-2.0 >= $GCONF2_REQUIRED
libxml-2.0 >= $LIBXML_REQUIRED
libxslt >= $LIBXSLT_REQUIRED
- gnome-vfs-2.0
libart-2.0
libglade-2.0 >= $LIBGLADE2_REQUIRED])
diff --git a/src/cong-app.c b/src/cong-app.c
index 42d7108..9e45898 100644
--- a/src/cong-app.c
+++ b/src/cong-app.c
@@ -33,8 +33,7 @@
#include "cong-document.h"
#include "cong-font.h"
#include "cong-plugin-manager.h"
-
-#include <libgnomevfs/gnome-vfs.h>
+#include "cong-util.h"
#include "cong-fake-plugin-hooks.h"
@@ -945,15 +944,14 @@ static const GOptionEntry options[] = {
static gboolean
handle_cmdline_args ()
{
- GError *error = NULL;
- gchar *uri;
+ GFile *file;
int i;
if (startup_files) {
for (i = 0; startup_files [i]; ++i) {
- uri = gnome_vfs_make_uri_from_shell_arg (startup_files[i]);
- open_document_do (uri, NULL);
- g_free(uri);
+ file = g_file_new_for_commandline_arg (startup_files[i]);
+ open_document_do (file, NULL);
+ g_object_unref (file);
}
g_strfreev (startup_files);
}
@@ -1072,7 +1070,7 @@ cong_app_private_load_displayspecs (CongApp *app,
while (path != NULL) {
if (path->data != NULL) {
gchar *realpath;
- realpath = gnome_vfs_expand_initial_tilde((char *)(path->data));
+ realpath = cong_util_expand_initial_tilde((char *)(path->data));
/* g_message("Loading xds files from \"%s\"\n", realpath); */
cong_dispspec_registry_add_dir(PRIVATE(app)->ds_registry, realpath, toplevel_window, 0);
g_free (realpath);
diff --git a/src/cong-dispspec-registry.c b/src/cong-dispspec-registry.c
index 923e44a..be69270 100644
--- a/src/cong-dispspec-registry.c
+++ b/src/cong-dispspec-registry.c
@@ -9,74 +9,12 @@
#include "cong-app.h"
#include "cong-util.h"
-/* FIXME: eventually abstract this into cong-vfs */
-#include <libgnomevfs/gnome-vfs.h>
-
struct CongDispspecRegistry
{
int num;
CongDispspec** array;
};
-struct LoadingDetails
-{
- CongDispspecRegistry* registry;
- GnomeVFSURI* path_uri;
-};
-
-/**
- * visit_func:
- * @rel_path:
- * @info:
- * @recursing_will_loop:
- * @data:
- * @recurse:
- *
- * TODO: Write me
- */
-gboolean
-visit_func(const gchar *rel_path,
- GnomeVFSFileInfo *info,
- gboolean recursing_will_loop,
- gpointer data,
- gboolean *recurse)
-{
- struct LoadingDetails* details = (struct LoadingDetails*)data;
- char* match;
-
- /* g_message("visit_func called\n"); */
-
- /* FIXME: Ultimately we should do a MIME-lookup */
- /* Search for strings that are terminated with ".xds" */
- match=strstr(rel_path,".xds");
- if (match && match[4]=='\0') {
- /* This looks like an xds file: */
- /* get at name */
- GnomeVFSURI* uri_filename = gnome_vfs_uri_append_string(details->path_uri,
- rel_path);
- gchar* filename = gnome_vfs_uri_extract_short_path_name(uri_filename);
-
- CongDispspec* ds;
- GnomeVFSResult vfs_result = cong_dispspec_new_from_xds_file(uri_filename, &ds);
-
- if (vfs_result==GNOME_VFS_OK) {
-
- if (ds!=NULL) {
- cong_dispspec_registry_add(details->registry, ds);
- } else {
- g_warning("Problem parsing xds file: %s.\n",filename);
- }
- } else {
- g_warning("Problem loading xds file: %s.\n",filename);
- }
-
- gnome_vfs_uri_unref(uri_filename);
- /* FIXME: should filename be unref-ed ? GSt */
- }
-
- return TRUE;
-}
-
/* Add all disspecs found in directory to an existing DispspecRegistry */
/**
* cong_dispspec_registry_add_dir:
@@ -90,32 +28,84 @@ visit_func(const gchar *rel_path,
void
cong_dispspec_registry_add_dir(CongDispspecRegistry *registry, const gchar *xds_directory, GtkWindow *toplevel_window, gboolean raise_errs)
{
- GnomeVFSResult vfs_result;
- struct LoadingDetails details;
+ gboolean result;
+ GFile *xds_dir;
+ GFileEnumerator *directory;
+ GFileInfo *info;
+ GError *error = NULL;
- details.registry=registry;
- details.path_uri=gnome_vfs_uri_new(xds_directory);
+ xds_dir = g_file_new_for_path(xds_directory);
/* Scan the directory for xds files: */
- vfs_result = gnome_vfs_directory_visit(xds_directory,
- GNOME_VFS_FILE_INFO_DEFAULT,
- GNOME_VFS_DIRECTORY_VISIT_DEFAULT,
- visit_func,
- (gpointer)&details);
- if (raise_errs && vfs_result!=GNOME_VFS_OK) {
+ directory = g_file_enumerate_children(xds_dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ if(!directory) {
+ if(raise_errs) {
+ GtkDialog* dialog = cong_error_dialog_new_from_file_operation_failure(toplevel_window,
+ _("Conglomerate could not read its registry of document types."),
+ xds_dir,
+ error,
+ _("Conglomerate attempted to look at all the files in the location."));
+ cong_error_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ }
+
+ g_object_unref(xds_dir);
+ return;
+ }
+
+ while((info = g_file_enumerator_next_file(directory, NULL, &error)) != NULL) {
+ const char *rel_path = g_file_info_get_name(info);
+ /* FIXME: Ultimately we should do a MIME-lookup */
+ /* Search for strings that are terminated with ".xds" */
+ if (g_str_has_suffix(rel_path, ".xds")) {
+ /* This looks like an xds file: */
+ /* get at name */
+ GFile *file = g_file_get_child(xds_dir, rel_path);
+ char *filename = g_file_get_path(file);
+ CongDispspec* ds;
+ gboolean result;
+
+ result = cong_dispspec_new_from_xds_file(file, &ds, &error);
+ if (result == TRUE) {
+ if (ds!=NULL) {
+ cong_dispspec_registry_add(registry, ds);
+ } else {
+ g_warning("Problem parsing xds file: %s.\n", filename);
+ }
+ } else {
+ g_warning("Problem loading xds file: %s.\n",filename);
+ }
+
+ g_free(filename);
+ g_object_unref(file);
+ }
+ g_object_unref(info);
+ }
+
+ if(raise_errs && error) {
GtkDialog* dialog = cong_error_dialog_new_from_file_operation_failure(toplevel_window,
- _("Conglomerate could not read its registry of document types."),
- xds_directory,
- vfs_result,
- _("Conglomerate attempted to look at all the files in the location."));
+ _("Conglomerate failed while reading its registry of document types."),
+ xds_dir,
+ error,
+ _("Conglomerate attempted to look at all the files in the location."));
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
+ }
- gnome_vfs_uri_unref(details.path_uri);
+ result = g_file_enumerator_close(directory, NULL, &error);
+ if(!result) {
+ g_warning("Error closing directory '%s': %s", xds_directory, error->message);
+ g_error_free(error);
}
- gnome_vfs_uri_unref(details.path_uri);
+ g_object_unref(directory);
+ g_object_unref(xds_dir);
}
/* Create a new DispspecRegistry.
diff --git a/src/cong-dispspec.c b/src/cong-dispspec.c
index f9f1856..6176e87 100644
--- a/src/cong-dispspec.c
+++ b/src/cong-dispspec.c
@@ -238,31 +238,31 @@ cong_dispspec_new(void)
* cong_dispspec_new_from_xds_file:
* @uri:
* @ds:
+ * @error: Return location for an error, or %NULL.
*
* TODO: Write me
- * Returns:
+ * Returns: %TRUE on success, %FALSE if @error was set.
*/
-GnomeVFSResult
-cong_dispspec_new_from_xds_file(GnomeVFSURI *uri, CongDispspec** ds)
+gboolean
+cong_dispspec_new_from_xds_file(GFile *file, CongDispspec** ds, GError **error)
{
char* buffer;
- GnomeVFSFileSize size;
- GnomeVFSResult vfs_result;
+ gsize size;
+ gboolean result;
- g_return_val_if_fail(uri, GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(ds, GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail(file, FALSE);
+ g_return_val_if_fail(ds, FALSE);
- vfs_result = cong_vfs_new_buffer_from_uri(uri, &buffer, &size);
+ result = cong_vfs_new_buffer_from_file(file, &buffer, &size, error);
- if (vfs_result!=GNOME_VFS_OK) {
- return vfs_result;
- }
+ if (!result)
+ return FALSE;
*ds = cong_dispspec_new_from_xds_buffer(buffer, size);
g_free (buffer);
- return vfs_result;
+ return TRUE;
}
/**
diff --git a/src/cong-dispspec.h b/src/cong-dispspec.h
index a7815e9..e3a6ac2 100644
--- a/src/cong-dispspec.h
+++ b/src/cong-dispspec.h
@@ -48,7 +48,7 @@ CongDispspec* cong_dispspec_new(void);
/* Constructors that use the standard format: */
CongDispspec* cong_dispspec_new_from_ds_file(const char *name);
-GnomeVFSResult cong_dispspec_new_from_xds_file(GnomeVFSURI *uri, CongDispspec** ds);
+gboolean cong_dispspec_new_from_xds_file(GFile *file, CongDispspec** ds, GError **error);
CongDispspec* cong_dispspec_new_from_xds_buffer(const char *buffer, size_t size);
/* Constructors that try to generate from another format: */
diff --git a/src/cong-document.c b/src/cong-document.c
index 27982a8..ee4938d 100644
--- a/src/cong-document.c
+++ b/src/cong-document.c
@@ -19,6 +19,7 @@
#include "cong-dispspec-registry.h"
#include "cong-service-exporter.h"
#include "cong-plugin-manager.h"
+#include "cong-vfs.h"
#if ENABLE_PRINTING
#include "cong-service-print-method.h"
@@ -70,8 +71,8 @@ cong_document_handle_set_dtd_ptr (CongDocument *doc,
xmlDtdPtr dtd_ptr);
static void
-cong_document_handle_set_url (CongDocument *doc,
- const gchar *new_url);
+cong_document_handle_set_file (CongDocument *doc,
+ GFile *new_file);
#define TEST_VIEW 0
#define TEST_EDITOR_VIEW 0
@@ -102,7 +103,7 @@ enum {
SELECTION_CHANGE,
CURSOR_CHANGE,
SET_DTD_PTR,
- SET_URL,
+ SET_FILE,
LAST_SIGNAL
};
@@ -117,7 +118,7 @@ struct _CongDocumentDetails
CongDocumentTraversal *traversal;
- gchar *url;
+ GFile *file;
GList *views; /* a list of CongView* */
@@ -172,7 +173,7 @@ cong_document_class_init (CongDocumentClass *klass)
klass->selection_change = cong_document_handle_selection_change;
klass->cursor_change = cong_document_handle_cursor_change;
klass->set_dtd_ptr = cong_document_handle_set_dtd_ptr;
- klass->set_url = cong_document_handle_set_url;
+ klass->set_file = cong_document_handle_set_file;
/* Set up the various signals: */
signals[BEGIN_EDIT] = g_signal_new ("begin_edit",
@@ -282,14 +283,14 @@ cong_document_class_init (CongDocumentClass *klass)
cong_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE,
1, G_TYPE_POINTER);
- signals[SET_URL] = g_signal_new ("set_url",
- CONG_DOCUMENT_TYPE,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(CongDocumentClass, set_url),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE,
- 1, G_TYPE_STRING);
+ signals[SET_FILE] = g_signal_new ("set_file",
+ CONG_DOCUMENT_TYPE,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(CongDocumentClass, set_file),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_FILE);
}
static void
@@ -361,7 +362,7 @@ CongDocument*
cong_document_construct (CongDocument *doc,
xmlDocPtr xml_doc,
CongDispspec *ds,
- const gchar *url)
+ GFile *file)
{
CongNodePtr initial_cursor_node;
@@ -370,7 +371,7 @@ cong_document_construct (CongDocument *doc,
PRIVATE(doc)->xml_doc = xml_doc;
PRIVATE(doc)->default_ds = ds;
- PRIVATE(doc)->url = g_strdup(url);
+ PRIVATE(doc)->file = file? g_file_dup(file) : NULL;
g_get_current_time(&PRIVATE(doc)->time_of_last_save);
PRIVATE(doc)->modified = FALSE;
@@ -438,7 +439,7 @@ cong_document_construct (CongDocument *doc,
CongDocument*
cong_document_new_from_xmldoc (xmlDocPtr xml_doc,
CongDispspec *ds,
- const gchar *url)
+ GFile *file)
{
g_return_val_if_fail(xml_doc!=NULL, NULL);
#if 0
@@ -448,7 +449,7 @@ cong_document_new_from_xmldoc (xmlDocPtr xml_doc,
return cong_document_construct (g_object_new (CONG_DOCUMENT_TYPE, NULL),
xml_doc,
ds,
- url);
+ file);
}
/**
@@ -632,71 +633,43 @@ cong_document_get_filename(CongDocument *doc)
{
g_return_val_if_fail(doc, NULL);
- if (PRIVATE(doc)->url) {
- gchar *filename;
- gchar *path;
- GnomeVFSURI *uri = gnome_vfs_uri_new(PRIVATE(doc)->url);
-
- cong_vfs_split_vfs_uri (uri, &filename, &path);
-
- gnome_vfs_uri_unref(uri);
-
- g_free(path);
-
- return filename;
-
- } else {
- return g_strdup(_("(Untitled)"));
- }
+ if (PRIVATE(doc)->file)
+ return cong_vfs_extract_display_name (PRIVATE(doc)->file);
+ return g_strdup(_("(Untitled)"));
}
/**
- * cong_document_get_full_uri:
+ * cong_document_get_file:
* @doc:
*
* TODO: Write me
- * Returns:
+ * Returns: (transfer none): A #GFile referring to this document. Don't unref
+ * the file; it belongs to the document.
*/
-gchar*
-cong_document_get_full_uri(CongDocument *doc)
+GFile *
+cong_document_get_file(CongDocument *doc)
{
g_return_val_if_fail(doc, NULL);
- if (PRIVATE(doc)->url) {
- return g_strdup(PRIVATE(doc)->url);
- }
- else {
- return NULL;
- }
+ return PRIVATE(doc)->file;
}
/**
- * cong_document_get_parent_uri:
+ * cong_document_get_parent:
* @doc:
*
* TODO: Write me
* Returns:
*/
-gchar*
-cong_document_get_parent_uri(CongDocument *doc)
+GFile *
+cong_document_get_parent(CongDocument *doc)
{
g_return_val_if_fail(doc, NULL);
- if (PRIVATE(doc)->url) {
- gchar *filename;
- gchar *path;
- GnomeVFSURI *uri = gnome_vfs_uri_new(PRIVATE(doc)->url);
-
- cong_vfs_split_vfs_uri (uri, &filename, &path);
-
- gnome_vfs_uri_unref(uri);
-
- g_free(filename);
-
- return path;
-
+ if (PRIVATE(doc)->file) {
+ return g_file_get_parent(PRIVATE(doc)->file);
} else {
- return g_strdup(".");
+ return g_file_new_for_path(".");
}
}
@@ -756,51 +729,41 @@ cong_document_get_xml_ns (CongDocument *doc,
*/
void
cong_document_save(CongDocument *doc,
- const char* filename,
+ GFile *file,
GtkWindow *toplevel_window)
{
- GnomeVFSURI *file_uri;
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize file_size;
+ gboolean result;
+ gsize file_size;
+ GError *error = NULL;
g_return_if_fail(doc);
- g_return_if_fail(filename);
+ g_return_if_fail(file);
- if (!g_path_is_absolute (filename) && !(g_str_has_prefix (filename, "file:"))) {
+ result = cong_vfs_save_xml_to_file (PRIVATE(doc)->xml_doc,
+ file,
+ &file_size,
+ &error);
- gchar *absolute_path = g_strconcat (g_get_current_dir(), GNOME_VFS_URI_PATH_STR, filename, NULL);
- file_uri = gnome_vfs_uri_new (absolute_path);
- g_free (absolute_path);
- } else {
- file_uri = gnome_vfs_uri_new(filename);
- }
-
- vfs_result = cong_vfs_save_xml_to_uri (PRIVATE(doc)->xml_doc,
- file_uri,
- &file_size);
-
- if (vfs_result != GNOME_VFS_OK) {
+ if (!result) {
GtkDialog* dialog = cong_error_dialog_new_from_file_save_failure (toplevel_window,
- filename,
- vfs_result,
+ file,
+ error,
&file_size);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
- gnome_vfs_uri_unref(file_uri);
+ g_object_unref(file);
return;
}
- cong_document_set_url(doc, filename);
+ cong_document_set_file(doc, file);
cong_document_set_modified(doc, FALSE);
g_get_current_time(&PRIVATE(doc)->time_of_last_save);
-
- gnome_vfs_uri_unref(file_uri);
}
/**
@@ -880,19 +843,19 @@ cong_document_set_primary_window(CongDocument *doc, CongPrimaryWindow *window)
/**
* cong_document_set_url:
* @doc:
- * @url:
+ * @file:
*
* TODO: Write me
*/
void
-cong_document_set_url(CongDocument *doc, const gchar *url)
+cong_document_set_file(CongDocument *doc, GFile *file)
{
g_return_if_fail (IS_CONG_DOCUMENT (doc));
- g_return_if_fail (url);
+ g_return_if_fail (file);
g_signal_emit (G_OBJECT(doc),
- signals[SET_URL], 0,
- url);
+ signals[SET_FILE], 0,
+ file);
}
/**
@@ -2345,6 +2308,11 @@ cong_document_finalize (GObject *object)
CongDocument *doc = CONG_DOCUMENT (object);
g_message ("cong_document_finalize");
+
+ if(PRIVATE(doc)->file) {
+ g_object_unref(PRIVATE(doc)->file);
+ PRIVATE(doc)->file = NULL;
+ }
g_free (doc->private);
doc->private = NULL;
@@ -2378,11 +2346,6 @@ cong_document_dispose (GObject *object)
}
#endif
- if (PRIVATE(doc)->url) {
- g_free (PRIVATE(doc)->url);
- PRIVATE(doc)->url = NULL;
- }
-
cong_cursor_uninit(&PRIVATE(doc)->cursor);
if (PRIVATE(doc)->selection) {
@@ -2900,13 +2863,13 @@ cong_document_handle_set_dtd_ptr (CongDocument *doc,
}
static void
-cong_document_handle_set_url (CongDocument *doc,
- const gchar *new_url)
+cong_document_handle_set_file (CongDocument *doc,
+ GFile *new_file)
{
- if (PRIVATE(doc)->url) {
- g_free(PRIVATE(doc)->url);
+ if (PRIVATE(doc)->file) {
+ g_object_unref(PRIVATE(doc)->file);
}
- PRIVATE(doc)->url = g_strdup(new_url);
+ PRIVATE(doc)->file = g_file_dup(new_file);
/* FIXME: replace this with signal handler? */
/* get at primary window; set title */
diff --git a/src/cong-document.h b/src/cong-document.h
index 7e791b0..ad31b1d 100644
--- a/src/cong-document.h
+++ b/src/cong-document.h
@@ -109,8 +109,8 @@ struct _CongDocumentClass
void (*set_dtd_ptr) (CongDocument *doc,
xmlDtdPtr dtd_ptr);
- void (*set_url) (CongDocument *doc,
- const gchar *new_url);
+ void (*set_file) (CongDocument *doc,
+ GFile *new_file);
};
GType
@@ -120,12 +120,12 @@ CongDocument*
cong_document_construct (CongDocument *doc,
xmlDocPtr xml_doc,
CongDispspec *ds,
- const gchar *url);
+ GFile *file);
CongDocument*
cong_document_new_from_xmldoc (xmlDocPtr xml_doc,
CongDispspec *ds,
- const gchar *url);
+ GFile *file);
xmlDocPtr
cong_document_get_xml(CongDocument *doc);
@@ -162,13 +162,13 @@ gchar*
cong_document_get_filename(CongDocument *doc);
/* caller is responsible for freeeing */
-gchar*
-cong_document_get_full_uri(CongDocument *doc);
-/* caller is responsible for freeeing */
+GFile *
+cong_document_get_file(CongDocument *doc);
+/* caller is responsible for unreffing */
-gchar*
-cong_document_get_parent_uri(CongDocument *doc);
-/* caller is responsible for freeeing */
+GFile *
+cong_document_get_parent(CongDocument *doc);
+/* caller is responsible for unreffing */
const gchar*
cong_document_get_dtd_public_identifier(CongDocument *doc);
@@ -185,7 +185,7 @@ cong_document_get_nsptr (CongDocument *doc, const gchar* xmlns);
void
cong_document_save(CongDocument *doc,
- const char* filename,
+ GFile *file,
GtkWindow *parent_window);
gboolean
@@ -201,7 +201,7 @@ CongPrimaryWindow*
cong_document_get_primary_window(CongDocument *doc);
void
-cong_document_set_url(CongDocument *doc, const gchar *url);
+cong_document_set_file(CongDocument *doc, GFile *file);
glong
cong_document_get_seconds_since_last_save_or_load(const CongDocument *doc);
diff --git a/src/cong-error-dialog.c b/src/cong-error-dialog.c
index fff23b5..6215af8 100644
--- a/src/cong-error-dialog.c
+++ b/src/cong-error-dialog.c
@@ -341,6 +341,8 @@ cong_error_dialog_new_from_gerror(GtkWindow *toplevel_window,
details_dialog);
/* FIXME: this will leak the details dialog */
+ g_error_free(error);
+
return dialog;
}
diff --git a/src/cong-error-dialog.h b/src/cong-error-dialog.h
index 7a4ba58..b0a5cf0 100644
--- a/src/cong-error-dialog.h
+++ b/src/cong-error-dialog.h
@@ -117,30 +117,30 @@ cong_error_dialog_new_from_shell_command_failure_with_argv(GtkWindow *parent_win
/**
* Routine to manufacture a "what failed" string for when File->Open fails.
- * @string_uri: the stringified URI from which you tried to open the file.
+ * @file: the file reference of the file you tried to open.
*/
gchar*
-cong_error_what_failed_on_file_open_failure (const gchar *string_uri,
+cong_error_what_failed_on_file_open_failure (GFile *file,
gboolean transient);
/**
* Routine to manufacture an error dialog for when File->Open fails.
- * @string_uri: the stringified URI from which you tried to open the file.
+ * @file: the file reference of the file you tried to open.
*/
GtkDialog*
cong_error_dialog_new_from_file_open_failure (GtkWindow *parent_window,
- const gchar* string_uri,
+ GFile *file,
gboolean transient,
const gchar* why_failed,
const gchar* suggestions);
/**
* Routine to manufacture an error dialog for when File->Open fails.
- * @string_uri: the stringified URI from which you tried to open the file.
+ * @file: the file reference of the file you tried to open.
*/
GtkDialog*
cong_error_dialog_new_from_file_open_failure_with_convenience (GtkWindow *parent_window,
- const gchar* string_uri,
+ GFile *file,
gboolean transient,
const gchar* why_failed,
const gchar* suggestions,
@@ -151,32 +151,32 @@ cong_error_dialog_new_from_file_open_failure_with_convenience (GtkWindow *parent
/**
* Routine to manufacture an error dialog for when File->Open fails.
- * @string_uri: the URI from which you tried to open the file.
- * @vfs_result: the error code that occurred.
+ * @file: the file reference of the file you tried to open.
+ * @error: the GError that occurred.
*/
GtkDialog*
-cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_window,
- const gchar *string_uri,
- GnomeVFSResult vfs_result);
+cong_error_dialog_new_from_file_open_failure_with_gerror(GtkWindow *parent_window,
+ GFile *file,
+ GError *error);
/**
* Routine to manufacture an error dialog for when File->Save (or File->Save as...) fails.
- * @string_uri: the URI to which you tried to save the file.
- * @vfs_result: the error code that occurred.
+ * @file: the file reference of the file you tried to save.
+ * @error: the GError that occurred.
* @file_size: pointer to the size of the file if known, or NULL if not (useful if the error was due to lack of space)
*/
GtkDialog*
cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
- const gchar *string_uri,
- GnomeVFSResult vfs_result,
- const GnomeVFSFileSize* file_size);
+ GFile *file,
+ GError *error,
+ gsize *file_size);
GtkDialog*
cong_error_dialog_new_from_file_operation_failure(GtkWindow *parent_window,
const gchar *what_failed,
- const gchar *string_uri,
- GnomeVFSResult vfs_result,
+ GFile *file,
+ GError *error,
const gchar *technical_details);
/**
* A bunch of self-tests.
diff --git a/src/cong-error-file-open.c b/src/cong-error-file-open.c
index dbb1847..d9dc021 100644
--- a/src/cong-error-file-open.c
+++ b/src/cong-error-file-open.c
@@ -78,7 +78,7 @@ static void on_search(gpointer data)
* Returns:
*/
gchar*
-cong_error_what_failed_on_file_open_failure (const gchar *string_uri,
+cong_error_what_failed_on_file_open_failure (GFile *file,
gboolean transient)
{
gchar* app_name;
@@ -86,13 +86,13 @@ cong_error_what_failed_on_file_open_failure (const gchar *string_uri,
gchar* path;
gchar* what_failed;
- g_return_val_if_fail (string_uri, NULL);
+ g_return_val_if_fail (file, NULL);
app_name = cong_error_get_appname();
- cong_vfs_split_string_uri (string_uri,
- &filename_alone,
- &path);
+ cong_vfs_split_file_path (file,
+ &filename_alone,
+ &path);
g_assert(filename_alone);
g_assert(path);
@@ -115,7 +115,7 @@ cong_error_what_failed_on_file_open_failure (const gchar *string_uri,
/**
* cong_error_dialog_new_from_file_open_failure:
* @parent_window:
- * @string_uri:
+ * @file:
* @transient:
* @why_failed:
* @suggestions:
@@ -125,7 +125,7 @@ cong_error_what_failed_on_file_open_failure (const gchar *string_uri,
*/
GtkDialog*
cong_error_dialog_new_from_file_open_failure(GtkWindow *parent_window,
- const gchar* string_uri,
+ GFile *file,
gboolean transient,
const gchar* why_failed,
const gchar* suggestions)
@@ -134,11 +134,11 @@ cong_error_dialog_new_from_file_open_failure(GtkWindow *parent_window,
gchar* what_failed;
- g_return_val_if_fail(string_uri, NULL);
+ g_return_val_if_fail(file, NULL);
g_return_val_if_fail(why_failed, NULL);
g_return_val_if_fail(suggestions, NULL);
- what_failed = cong_error_what_failed_on_file_open_failure (string_uri,
+ what_failed = cong_error_what_failed_on_file_open_failure (file,
transient);
dialog = cong_error_dialog_new (parent_window,
@@ -154,7 +154,7 @@ cong_error_dialog_new_from_file_open_failure(GtkWindow *parent_window,
/**
* cong_error_dialog_new_from_file_open_failure_with_convenience:
* @parent_window:
- * @string_uri:
+ * @file:
* @transient:
* @why_failed:
* @suggestions:
@@ -167,7 +167,7 @@ cong_error_dialog_new_from_file_open_failure(GtkWindow *parent_window,
*/
GtkDialog*
cong_error_dialog_new_from_file_open_failure_with_convenience(GtkWindow *parent_window,
- const gchar *string_uri,
+ GFile *file,
gboolean transient,
const gchar* why_failed,
const gchar* suggestions,
@@ -179,11 +179,11 @@ cong_error_dialog_new_from_file_open_failure_with_convenience(GtkWindow *parent_
gchar* what_failed;
- g_return_val_if_fail(string_uri, NULL);
+ g_return_val_if_fail(file, NULL);
g_return_val_if_fail(why_failed, NULL);
g_return_val_if_fail(suggestions, NULL);
- what_failed = cong_error_what_failed_on_file_open_failure(string_uri, transient);
+ what_failed = cong_error_what_failed_on_file_open_failure(file, transient);
dialog = cong_error_dialog_new_with_convenience(parent_window,
what_failed,
@@ -201,65 +201,56 @@ cong_error_dialog_new_from_file_open_failure_with_convenience(GtkWindow *parent_
}
/**
- * cong_error_dialog_new_from_file_open_failure_with_vfs_result:
+ * cong_error_dialog_new_from_file_open_failure_with_gerror:
* @parent_window:
- * @string_uri:
- * @vfs_result:
+ * @file: the file reference of the file you tried to open.
+ * @error: the #GError that resulted from the failed file operation. For
+ * convenience, this function frees the error.
*
* TODO: Write me
* Returns:
*/
GtkDialog*
-cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_window,
- const gchar *string_uri,
- GnomeVFSResult vfs_result)
+cong_error_dialog_new_from_file_open_failure_with_gerror(GtkWindow *parent_window,
+ GFile *file,
+ GError *error)
{
GtkDialog* dialog = NULL;
gchar* filename_alone;
gchar* path;
- GnomeVFSURI* vfs_uri;
- GnomeVFSURI* parent_uri;
+ GFile* parent;
- g_return_val_if_fail (string_uri, NULL);
- g_return_val_if_fail (GNOME_VFS_OK!=vfs_result, NULL);
+ g_return_val_if_fail (file, NULL);
+ g_return_val_if_fail (error, NULL);
- cong_vfs_split_string_uri (string_uri, &filename_alone, &path);
+ cong_vfs_split_file_path (file, &filename_alone, &path);
g_assert(filename_alone);
g_assert(path);
/* Get at the parent URI in case it's needed: */
- vfs_uri = gnome_vfs_uri_new (string_uri);
- parent_uri = gnome_vfs_uri_get_parent (vfs_uri);
+ parent = g_file_get_parent (file);
- switch (vfs_result) {
+ switch (error->code) {
default:
- case GNOME_VFS_ERROR_INTERNAL:
- case GNOME_VFS_ERROR_BAD_PARAMETERS:
- case GNOME_VFS_ERROR_GENERIC:
- case GNOME_VFS_ERROR_TOO_BIG:
- case GNOME_VFS_ERROR_NO_SPACE:
- case GNOME_VFS_ERROR_READ_ONLY:
- case GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM:
- case GNOME_VFS_ERROR_TOO_MANY_LINKS:
- case GNOME_VFS_ERROR_NOT_OPEN:
- case GNOME_VFS_ERROR_INVALID_OPEN_MODE:
- case GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM:
- case GNOME_VFS_ERROR_FILE_EXISTS:
- case GNOME_VFS_ERROR_LOOP:
- case GNOME_VFS_ERROR_CANCELLED:
- case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:
- case GNOME_VFS_ERROR_NAME_TOO_LONG:
-
- case GNOME_VFS_ERROR_NOT_A_DIRECTORY: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_IN_PROGRESS: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_SERVICE_OBSOLETE: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_PROTOCOL_ERROR: /* FIXME: when does this occur? */
+ case G_IO_ERROR_INVALID_ARGUMENT:
+ case G_IO_ERROR_FAILED:
+ case G_IO_ERROR_NO_SPACE:
+ case G_IO_ERROR_READ_ONLY:
+ case G_IO_ERROR_TOO_MANY_LINKS:
+ case G_IO_ERROR_CLOSED:
+ case G_IO_ERROR_EXISTS:
+ case G_IO_ERROR_WOULD_RECURSE:
+ case G_IO_ERROR_CANCELLED:
+ case G_IO_ERROR_NOT_EMPTY:
+ case G_IO_ERROR_FILENAME_TOO_LONG:
+
+ case G_IO_ERROR_NOT_DIRECTORY: /* FIXME: when does this occur? */
+ case G_IO_ERROR_PENDING: /* FIXME: when does this occur? */
{
/* Unknown (or inapplicable) error */
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("An unexpected internal error occurred."),
_("Try again. If it fails again, file a bug report with the maintainer of this application."));
/* FIXME: ought to provide a convenience button that launches bug-buddy with lots of details filled in, including info
@@ -272,21 +263,14 @@ cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_w
}
break;
- case GNOME_VFS_ERROR_NOT_FOUND:
+ case G_IO_ERROR_NOT_FOUND:
{
/* Either "file not found" or "path not found": */
- /* Does the parent_uri exist? */
- GnomeVFSDirectoryHandle *handle;
- GnomeVFSResult vfs_result = gnome_vfs_directory_open_from_uri(&handle,
- parent_uri,
- GNOME_VFS_FILE_INFO_DEFAULT);
-
- if (vfs_result==GNOME_VFS_OK) {
- gnome_vfs_directory_close(handle);
-
+ /* Does the parent exist? */
+ if (g_file_query_exists(parent, NULL)) {
/* OK; the path exists, but the file doesn't: */
dialog = cong_error_dialog_new_from_file_open_failure_with_convenience(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("There is no file with that name at that location."),
_("(i) Try checking that you spelt the file's name correctly. Remember that capitalisation is significant (\"MyFile\" is not the same as \"MYFILE\" or \"myfile\").\n(ii) Try using the Search Tool to find your file."),
_("Search"),
@@ -295,7 +279,7 @@ cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_w
} else {
/* The path doesn't exist: */
dialog = cong_error_dialog_new_from_file_open_failure_with_convenience(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("The location does not exist."),
_("(i) Try checking that you spelt the location correctly. Remember that capitalisation is significant (\"MyDirectory\" is not the same as \"mydirectory\" or \"MYDIRECTORY\").\n(ii) Try using the Search Tool to find your file."),
_("Search"),
@@ -306,51 +290,23 @@ cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_w
}
break;
- case GNOME_VFS_ERROR_NOT_SUPPORTED:
- case GNOME_VFS_ERROR_NOT_PERMITTED:
+ case G_IO_ERROR_NOT_SUPPORTED:
{
/* FIXME: need some thought about the messages for this */
gchar* why_failed = g_strdup_printf(_("The location \"%s\" does not support the reading of files."),path);
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, FALSE,
+ file, FALSE,
why_failed,
_("Try loading a file from a different location. If you think that you ought to be able to read this file, contact your system administrator."));
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_IO:
- case GNOME_VFS_ERROR_EOF:
- {
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
- _("There were problems reading the content of the file."),
- _("Try again. If it fails again, contact your system administrator."));
- }
- break;
-
- case GNOME_VFS_ERROR_CORRUPTED_DATA:
- case GNOME_VFS_ERROR_BAD_FILE:
- {
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
- _("The contents of the file seem to be corrupt."),
- _("Try again. If it fails again, try looking for a backup copy of the file."));
- }
- break;
- case GNOME_VFS_ERROR_WRONG_FORMAT:
- {
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
- _("There were problems reading the contents of the file."),
- _("Try again. If it fails again, contact your system administrator."));
- }
- break;
- case GNOME_VFS_ERROR_INVALID_URI:
+ case G_IO_ERROR_INVALID_FILENAME:
{
/* FIXME: is case significant for VFS method names? */
dialog = cong_error_dialog_new_from_file_open_failure_with_convenience(parent_window,
- string_uri, FALSE,
+ file, FALSE,
_("The system does not recognise that as a valid location."),
_("(i) Try checking that you spelt the location correctly. Remember that capitalisation is significant (\"http\" is not the same as \"Http\" or \"HTTP\").\n(ii) Try using the Search Tool to find your file."),
_("Search"),
@@ -359,39 +315,39 @@ cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_w
}
break;
- case GNOME_VFS_ERROR_ACCESS_DENIED:
+ case G_IO_ERROR_PERMISSION_DENIED:
{
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, FALSE,
+ file, FALSE,
_("You do not have permission to read that file."),
_("Try asking your system administrator to give you permission."));
}
break;
- case GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES:
+ case G_IO_ERROR_TOO_MANY_OPEN_FILES:
{
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("The system is trying to operate on too many files at once."),
_("Try again. If it fails again, try closing unwanted applications, or contact your system administrator."));
}
break;
- case GNOME_VFS_ERROR_INTERRUPTED:
+ case G_IO_ERROR_TIMED_OUT:
{
/* FIXME: need a better "why-failed" message */
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("There were problems reading the contents of the file."),
_("Try again. If it fails again, contact your system administrator."));
}
break;
- case GNOME_VFS_ERROR_IS_DIRECTORY:
+ case G_IO_ERROR_IS_DIRECTORY:
{
/* FIXME: capitalisation issues */
gchar* why_failed = g_strdup_printf(_("\"%s\" is a directory, rather than a file."),filename_alone);
dialog = cong_error_dialog_new_from_file_open_failure_with_convenience(parent_window,
- string_uri, FALSE,
+ file, FALSE,
why_failed,
_("Try using the Search Tool to find your file."),
_("Search"),
@@ -401,68 +357,57 @@ cong_error_dialog_new_from_file_open_failure_with_vfs_result(GtkWindow *parent_w
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_NO_MEMORY:
- {
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
- _("The system ran out of memory."),
- _("Try again. If it fails again, try closing unwanted applications, or contact your system administrator."));
- }
- break;
- case GNOME_VFS_ERROR_HOST_NOT_FOUND:
+ case G_IO_ERROR_HOST_NOT_FOUND:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, FALSE,
+ file, FALSE,
_("The server could not be contacted."),
_("Try again. If it fails again, the server may be down."));
}
break;
- case GNOME_VFS_ERROR_INVALID_HOST_NAME:
- {
- /* FIXME: need to think more about these messages */
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, FALSE,
- _("The server could not be contacted."),
- _("(i) Try checking that you spelt the location correctly.\n(ii) Try again. If it fails again, the server may be down."));
- }
- break;
- case GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS:
- {
- /* FIXME: need to think more about these messages */
- dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, FALSE,
- _("The server could not be contacted."),
- _("(i) Try checking that you spelt the location correctly.\n(ii) Try again. If it fails again, the server may be down."));
- }
- break;
- case GNOME_VFS_ERROR_LOGIN_FAILED:
+#if GLIB_CHECK_VERSION(2,26,0)
+ case G_IO_ERROR_CONNECTION_REFUSED:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("The system could not login to the location."),
_("Try again. If it fails again, contact your system administrator."));
}
break;
-
- case GNOME_VFS_ERROR_DIRECTORY_BUSY:
+#endif
+ case G_IO_ERROR_BUSY:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new_from_file_open_failure(parent_window,
- string_uri, TRUE,
+ file, TRUE,
_("The location was too busy."),
_("Try again. If it fails again, contact your system administrator."));
}
break;
+ case G_IO_ERROR_FAILED_HANDLED:
+ {
+ /* FIXME: This means a helper program has already interacted
+ * with the user and we shouldn't display an error dialog. */
+ dialog = GTK_DIALOG(gtk_message_dialog_new(parent_window,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Click OK to continue.")));
+ }
+ break;
}
- gnome_vfs_uri_unref (parent_uri);
- gnome_vfs_uri_unref (vfs_uri);
+ g_object_unref (parent);
+ g_free(filename_alone);
+ g_free(path);
g_assert(dialog);
+ g_error_free(error);
+
return dialog;
}
@@ -477,8 +422,8 @@ static void on_details(gpointer data)
* cong_error_dialog_new_from_file_operation_failure:
* @parent_window:
* @what_failed:
- * @string_uri: the URI from which you tried to access file.
- * @vfs_result:
+ * @file: the file reference for the file you tried to access
+ * @error: the error that occurred. For convenience, this function frees the error.
* @technical_details:
*
* Routine to manufacture an error dialog for when some file operation fails that doesn't fall into one of the categories above.
@@ -489,20 +434,21 @@ static void on_details(gpointer data)
GtkDialog*
cong_error_dialog_new_from_file_operation_failure(GtkWindow *parent_window,
const gchar *what_failed,
- const gchar *string_uri,
- GnomeVFSResult vfs_result,
+ GFile *file,
+ GError *error,
const gchar *technical_details)
{
GtkDialog *dialog;
GtkDialog *details_dialog;
gchar *secondary_text;
+ char *string_uri = g_file_get_uri(file);
g_return_val_if_fail(what_failed,NULL);
g_return_val_if_fail(technical_details,NULL);
/* Manufacture a dialog that is displayed if the user requests further details: */
secondary_text = g_strdup_printf(_("The error \"%s\" was reported whilst accessing \"%s\""),
- gnome_vfs_result_to_string(vfs_result),
+ error->message,
string_uri);
details_dialog = cong_error_dialog_new(parent_window,
_("The program unexpectedly received an error report from the GNOME Virtual File System."),
@@ -521,5 +467,8 @@ cong_error_dialog_new_from_file_operation_failure(GtkWindow *parent_window,
details_dialog);
/* FIXME: this will leak the details dialog */
+ g_error_free(error);
+ g_free(string_uri);
+
return dialog;
}
diff --git a/src/cong-error-file-save.c b/src/cong-error-file-save.c
index af37759..cfa53f1 100644
--- a/src/cong-error-file-save.c
+++ b/src/cong-error-file-save.c
@@ -21,8 +21,8 @@
/**
* cong_error_dialog_new_from_file_save_failure:
* @parent_window:
- * @string_uri:
- * @vfs_result:
+ * @file: the file reference for the file you tried to access
+ * @error: the error that occurred. For convenience, this function frees the error.
* @file_size:
*
* TODO: Write me
@@ -30,9 +30,9 @@
*/
GtkDialog*
cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
- const gchar* string_uri,
- GnomeVFSResult vfs_result,
- const GnomeVFSFileSize* file_size)
+ GFile *file,
+ GError *error,
+ gsize* file_size)
{
GtkDialog* dialog = NULL;
gchar* app_name;
@@ -40,22 +40,20 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
gchar* path;
gchar* what_failed_permanent;
gchar* what_failed_transient;
- GnomeVFSURI* vfs_uri;
- GnomeVFSURI* parent_uri;
+ GFile* parent;
- g_return_val_if_fail(string_uri, NULL);
- g_return_val_if_fail(GNOME_VFS_OK!=vfs_result, NULL);
+ g_return_val_if_fail(file, NULL);
+ g_return_val_if_fail(error, NULL);
app_name = cong_error_get_appname();
- cong_vfs_split_string_uri (string_uri, &filename_alone, &path);
+ cong_vfs_split_file_path (file, &filename_alone, &path);
g_assert(filename_alone);
g_assert(path);
/* Get at the parent URI in case it's needed: */
- vfs_uri = gnome_vfs_uri_new (string_uri);
- parent_uri = gnome_vfs_uri_get_parent(vfs_uri);
+ parent = g_file_get_parent (file);
/* A "what failed" message when the failure is likely to be permanent; this URI won't be saveable */
what_failed_permanent = g_strdup_printf(_("%s cannot save \"%s\" to %s."),app_name, filename_alone, path);
@@ -63,28 +61,19 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
/* A "what failed" message when the failure is likely to be transient; this URI might be "saveable-to" on subsequent attempts, or with some troubleshooting. */
what_failed_transient = g_strdup_printf(_("%s could not save \"%s\" to %s."),app_name, filename_alone, path);
- switch (vfs_result) {
+ switch (error->code) {
default:
- case GNOME_VFS_ERROR_GENERIC:
- case GNOME_VFS_ERROR_INTERNAL:
- case GNOME_VFS_ERROR_BAD_PARAMETERS:
- case GNOME_VFS_ERROR_WRONG_FORMAT:
- case GNOME_VFS_ERROR_NOT_OPEN:
- case GNOME_VFS_ERROR_INVALID_OPEN_MODE:
- case GNOME_VFS_ERROR_EOF:
- case GNOME_VFS_ERROR_LOOP:
- case GNOME_VFS_ERROR_CANCELLED:
- case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:
- case GNOME_VFS_ERROR_TOO_MANY_LINKS:
- case GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM:
-
- case GNOME_VFS_ERROR_NOT_A_DIRECTORY: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_IN_PROGRESS: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_INTERRUPTED: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_FILE_EXISTS: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_SERVICE_OBSOLETE: /* FIXME: when does this occur? */
- case GNOME_VFS_ERROR_PROTOCOL_ERROR: /* FIXME: when does this occur? */
+ case G_IO_ERROR_FAILED:
+ case G_IO_ERROR_INVALID_ARGUMENT:
+ case G_IO_ERROR_CLOSED:
+ case G_IO_ERROR_WOULD_RECURSE:
+ case G_IO_ERROR_CANCELLED:
+ case G_IO_ERROR_NOT_EMPTY:
+ case G_IO_ERROR_TOO_MANY_LINKS:
+
+ case G_IO_ERROR_NOT_DIRECTORY: /* FIXME: when does this occur? */
+ case G_IO_ERROR_PENDING: /* FIXME: when does this occur? */
+ case G_IO_ERROR_EXISTS: /* FIXME: when does this occur? */
{
/* Unknown (or inapplicable) error */
dialog = cong_error_dialog_new(parent_window,
@@ -102,7 +91,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
}
break;
- case GNOME_VFS_ERROR_NOT_FOUND:
+ case G_IO_ERROR_NOT_FOUND:
{
/* Since we're saving, this must be "path not found" rather than "file not found": */
dialog = cong_error_dialog_new(parent_window,
@@ -112,8 +101,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
}
break;
- case GNOME_VFS_ERROR_NOT_SUPPORTED:
- case GNOME_VFS_ERROR_NOT_PERMITTED:
+ case G_IO_ERROR_NOT_SUPPORTED:
{
/* FIXME: need some thought about the messages for this */
gchar* why_failed = g_strdup_printf(_("The location \"%s\" does not support the writing of files."),path);
@@ -124,86 +112,27 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
g_free(why_failed);
}
break;
-
- case GNOME_VFS_ERROR_IO:
- case GNOME_VFS_ERROR_CORRUPTED_DATA:
- case GNOME_VFS_ERROR_BAD_FILE:
- {
- dialog = cong_error_dialog_new(parent_window,
- what_failed_transient,
- _("There were problems writing the content of the file."),
- _("Try again. If it fails again, try saving to a different location."));
- }
- break;
-
- case GNOME_VFS_ERROR_TOO_BIG:
- {
- gchar* why_failed = NULL;
-
- if (file_size) {
-
- char* file_size_string = gnome_vfs_format_file_size_for_display(*file_size);
-
-#if 0
- GnomeVFSFileSize volume_capacity;
-
- /* We call the "get space" function on the parent URI rather than the file URI since this function fails if
- the URI does not exist (it decides it's not a local URI as it can't stat the file) */
-
- /* FIXME: this function only exists at the moment on my local version of GNOME VFS */
- GnomeVFSResult volume_capacity_result = gnome_vfs_get_volume_capacity (parent_uri,
- &volume_capacity);
- if (volume_capacity_result==GNOME_VFS_OK) {
- char* volume_capacity_string = gnome_vfs_format_file_size_for_display(volume_capacity);
-
- why_failed = g_strdup_printf(_("The size of the file would be %s, but the device only has a capacity of %s."),file_size_string,volume_capacity_string);
-
- g_free(volume_capacity_string);
- } else {
-
- /* Can't get at the capacity for the device or "volume": */
- why_failed = g_strdup_printf(_("The file is too big to fit on the device (file size would be %s)."), file_size_string);
- }
-#else
- /* FIXME: This is the workaround: */
- why_failed = g_strdup_printf(_("The file is too big to fit on the device (file size would be %s)."), file_size_string);
-#endif
-
- g_free(file_size_string);
-
- } else {
-
- /* We don't know the size of the file: */
- why_failed = g_strdup_printf(_("The file is too big to fit on the device."));
-
- }
-
- g_assert(why_failed);
-
- dialog = cong_error_dialog_new(parent_window,
- what_failed_permanent,
- why_failed,
- _("Try saving the file to a different location."));
- g_free(why_failed);
- }
- break;
- case GNOME_VFS_ERROR_NO_SPACE:
+ case G_IO_ERROR_NO_SPACE:
{
gchar* why_failed = NULL;
if (file_size) {
- char* file_size_string = gnome_vfs_format_file_size_for_display(*file_size);
+ char* file_size_string = cong_util_format_file_size_for_display(*file_size);
/* We call the "get space" function on the parent URI rather than the file URI since this function fails if
the URI does not exist (it decides it's not a local URI as it can't stat the file) */
- GnomeVFSFileSize free_space;
- GnomeVFSResult free_space_result = gnome_vfs_get_volume_free_space(parent_uri,
- &free_space);
-
- if (free_space_result==GNOME_VFS_OK) {
- char* free_space_string = gnome_vfs_format_file_size_for_display(free_space);
+ GFileInfo *info = g_file_query_info(parent,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if(info) {
+ guint64 free_space = g_file_info_get_attribute_uint64(info,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+
+ char* free_space_string = cong_util_format_file_size_for_display(free_space);
why_failed = g_strdup_printf(_("The size of the file would be %s, but you only have %s free on that device."),file_size_string,free_space_string);
@@ -232,7 +161,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_READ_ONLY:
+ case G_IO_ERROR_READ_ONLY:
{
/* FIXME: need some thought about the messages for this */
gchar* why_failed = g_strdup_printf(_("The location \"%s\" does not support the writing of files."),path);
@@ -243,7 +172,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_INVALID_URI:
+ case G_IO_ERROR_INVALID_FILENAME:
{
/* FIXME: is case significant for VFS method names? */
dialog = cong_error_dialog_new(parent_window,
@@ -252,7 +181,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
_("(i) Try checking that you spelt the location correctly. Remember that capitalisation is significant (\"http\" is not the same as \"Http\" or \"HTTP\").\n(ii) Try saving to a different location."));
}
break;
- case GNOME_VFS_ERROR_ACCESS_DENIED:
+ case G_IO_ERROR_PERMISSION_DENIED:
{
/**
FIXME: This error can occur when attempting to write to the mountpoint of a filesystem that has not been mounted e.g. "file:///mnt/floppy".
@@ -267,7 +196,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
_("Try saving to a different location, or ask your system administrator to give you permission."));
}
break;
- case GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES:
+ case G_IO_ERROR_TOO_MANY_OPEN_FILES:
{
dialog = cong_error_dialog_new(parent_window,
what_failed_transient,
@@ -275,7 +204,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
_("Try again. If it fails again, try closing unwanted applications, or contact your system administrator."));
}
break;
- case GNOME_VFS_ERROR_IS_DIRECTORY:
+ case G_IO_ERROR_IS_DIRECTORY:
{
/* FIXME: capitalisation issues */
gchar* why_failed = g_strdup_printf(_("\"%s\" is a directory."),filename_alone);
@@ -286,15 +215,7 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_NO_MEMORY:
- {
- dialog = cong_error_dialog_new(parent_window,
- what_failed_transient,
- _("The system ran out of memory."),
- _("Try again. If it fails again, try closing unwanted applications, or contact your system administrator."));
- }
- break;
- case GNOME_VFS_ERROR_HOST_NOT_FOUND:
+ case G_IO_ERROR_HOST_NOT_FOUND:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new(parent_window,
@@ -303,25 +224,8 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
_("Try again. If it fails again, the server may be down; try saving to another location."));
}
break;
- case GNOME_VFS_ERROR_INVALID_HOST_NAME:
- {
- /* FIXME: need to think more about these messages */
- dialog = cong_error_dialog_new(parent_window,
- what_failed_permanent,
- _("The server could not be contacted."),
- _("(i) Try checking that you spelt the location correctly.\n(ii) Try again. If it fails again, the server may be down; try saving to another location."));
- }
- break;
- case GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS:
- {
- /* FIXME: need to think more about these messages */
- dialog = cong_error_dialog_new(parent_window,
- what_failed_permanent,
- _("The server could not be contacted."),
- _("(i) Try checking that you spelt the location correctly.\n(ii) Try again. If it fails again, the server may be down; try saving to another location."));
- }
- break;
- case GNOME_VFS_ERROR_LOGIN_FAILED:
+#if GLIB_CHECK_VERSION(2,26,0)
+ case G_IO_ERROR_CONNECTION_REFUSED:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new(parent_window,
@@ -330,7 +234,8 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
_("Try again. If it fails again, try saving to another location."));
}
break;
- case GNOME_VFS_ERROR_DIRECTORY_BUSY:
+#endif
+ case G_IO_ERROR_BUSY:
{
/* FIXME: need to think more about these messages */
dialog = cong_error_dialog_new(parent_window,
@@ -340,27 +245,27 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
}
break;
- case GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM:
+ case G_IO_ERROR_FILENAME_TOO_LONG:
{
- /* FIXME: need some thought about the messages for this */
- gchar* why_failed = g_strdup_printf(_("The location \"%s\" only allows files to be read, not written."),path);
+ /* FIXME: need to think more about these messages */
+ char* why_failed = g_strdup_printf(_("The name \"%s\" is too long for the location to manage."), filename_alone);
dialog = cong_error_dialog_new(parent_window,
what_failed_permanent,
why_failed,
- _("Try saving to a different location."));
+ _("Try again with a shorter file name."));
g_free(why_failed);
}
break;
- case GNOME_VFS_ERROR_NAME_TOO_LONG:
+ case G_IO_ERROR_FAILED_HANDLED:
{
- /* FIXME: need to think more about these messages */
- char* why_failed = g_strdup_printf(_("The name \"%s\" is too long for the location to manage."), filename_alone);
- dialog = cong_error_dialog_new(parent_window,
- what_failed_permanent,
- why_failed,
- _("Try again with a shorter file name."));
- g_free(why_failed);
+ /* FIXME: This means a helper program has already interacted
+ * with the user and we shouldn't display an error dialog. */
+ dialog = GTK_DIALOG(gtk_message_dialog_new(parent_window,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Click OK to continue.")));
}
break;
@@ -371,12 +276,13 @@ cong_error_dialog_new_from_file_save_failure(GtkWindow *parent_window,
g_free(filename_alone);
g_free(path);
- gnome_vfs_uri_unref (parent_uri);
- gnome_vfs_uri_unref (vfs_uri);
+ g_object_unref (parent);
g_free(app_name);
g_assert(dialog);
+ g_error_free(error);
+
return dialog;
}
diff --git a/src/cong-error-tests.c b/src/cong-error-tests.c
index b6b433d..0eceb85 100644
--- a/src/cong-error-tests.c
+++ b/src/cong-error-tests.c
@@ -15,36 +15,50 @@
*/
void
cong_error_test_file_ops(GtkWindow *parent_window,
- const gchar* filename,
- GnomeVFSResult vfs_result)
+ GFile *file,
+ GError *error)
{
GtkDialog* dialog;
+ char *filename;
- GnomeVFSFileSize file_size = 5*1024*1024; /* 5 megabytes, for a test */
+ gsize file_size = 5*1024*1024; /* 5 megabytes, for a test */
- g_message(_("Testing File->Open failure of \"%s\" with result %s"), filename, gnome_vfs_result_to_string(vfs_result));
+ filename = g_file_get_basename(file);
- dialog = cong_error_dialog_new_from_file_open_failure_with_vfs_result(parent_window, filename, vfs_result);
+ g_message(_("Testing File->Open failure of \"%s\" with result %s"), filename, error->message);
+
+ dialog = cong_error_dialog_new_from_file_open_failure_with_gerror(parent_window, file, error);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
- g_message(_("Testing File->Save failure of \"%s\" with result %s"), filename, gnome_vfs_result_to_string(vfs_result));
+ g_message(_("Testing File->Save failure of \"%s\" with result %s"), filename, error->message);
- dialog = cong_error_dialog_new_from_file_save_failure(parent_window, filename, vfs_result, &file_size);
+ dialog = cong_error_dialog_new_from_file_save_failure(parent_window, file, error, &file_size);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
- g_message(_("Testing generic failure of \"%s\" with result %s"), filename, gnome_vfs_result_to_string(vfs_result));
+ g_message(_("Testing generic failure of \"%s\" with result %s"), filename, error->message);
dialog = cong_error_dialog_new_from_file_operation_failure(parent_window,
_("Conglomerate is simulating the failure of a generic file operation."),
- filename,
- vfs_result,
+ file,
+ error,
_("This dialog was generated by the automated testing routine"));
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
+ g_free(filename);
}
+#if GLIB_CHECK_VERSION(2,26,0)
+#define LAST_ERROR G_IO_ERROR_PROXY_NOT_ALLOWED
+#elif GLIB_CHECK_VERSION(2,24,0)
+#define LAST_ERROR G_IO_ERROR_INVALID_DATA
+#elif GLIB_CHECK_VERSION(2,22,0)
+#define LAST_ERROR G_IO_ERROR_ADDRESS_IN_USE
+#else
+#define LAST_ERROR G_IO_ERROR_TOO_MANY_OPEN_FILES
+#endif
+
/**
* cong_error_tests:
* @parent_window:
@@ -54,8 +68,10 @@ cong_error_test_file_ops(GtkWindow *parent_window,
void
cong_error_tests(GtkWindow *parent_window)
{
+ GError *error;
+ GFile *file;
int i;
- for (i=(int)GNOME_VFS_ERROR_NOT_FOUND;i<(int)GNOME_VFS_NUM_ERRORS;i++) {
+ for (i=(int)G_IO_ERROR_FAILED;i<(int)LAST_ERROR;i++) {
#define TEST_URI ("file:///home/david/test.xml")
// #define TEST_URI ("file:///home/david/fubar.xml")
@@ -63,9 +79,12 @@ cong_error_tests(GtkWindow *parent_window)
// #define TEST_URI ("http://www.fubar.com/fubar.xml")
// #define TEST_URI ("ftp://www.fubar.com/fubar.xml")
+ error = g_error_new(G_IO_ERROR, i, "Test message");
+ file = g_file_new_for_uri(TEST_URI);
cong_error_test_file_ops(parent_window,
- TEST_URI,
- (GnomeVFSResult)i);
+ file,
+ error);
+ g_object_unref(file);
}
}
diff --git a/src/cong-file-export.c b/src/cong-file-export.c
index bbc4da9..fa1d199 100644
--- a/src/cong-file-export.c
+++ b/src/cong-file-export.c
@@ -97,11 +97,13 @@ static void gconf_notify_func(GConfClient *client,
g_message("gconf_notify_function");
if (exporter) {
- gchar *uri = cong_exporter_get_preferred_uri(exporter);
+ GFile *file = cong_exporter_get_preferred_location(exporter);
+ char *uri = g_file_get_uri(file);
gtk_entry_set_text(details->filename_entry, uri);
g_free(uri);
+ g_object_unref(file);
}
}
@@ -127,7 +129,8 @@ static void monitor_exporter(CongExportDialogDetails *dialog_details)
/* get value and set up entry accordingly */
{
- gchar *uri = cong_exporter_get_preferred_uri(exporter);
+ GFile *file = cong_exporter_get_preferred_location(exporter);
+ char *uri = g_file_get_uri(file);
if (uri) {
gtk_entry_set_text(dialog_details->filename_entry, uri);
@@ -135,6 +138,7 @@ static void monitor_exporter(CongExportDialogDetails *dialog_details)
} else {
gtk_entry_set_text(dialog_details->filename_entry, "");
}
+ g_object_unref(file);
}
}
@@ -197,8 +201,8 @@ static void on_exporter_selection_changed(GtkWidget *combo_box,
static void on_select_filename_button_clicked(GtkButton *button,
gpointer user_data)
{
- gchar *export_uri;
- gchar *new_uri;
+ GFile *export_file;
+ GFile *new_file;
CongExportDialogDetails *details = user_data;
CongServiceExporter* exporter = get_selected_exporter(details);
g_assert(exporter);
@@ -207,21 +211,21 @@ static void on_select_filename_button_clicked(GtkButton *button,
FIXME: ought to set up MIME-filters according to the selected exporter plugin.
Needs a decent file-selector API for this...
*/
- export_uri = cong_exporter_get_preferred_uri(exporter);
+ export_file = cong_exporter_get_preferred_location(exporter);
- new_uri = cong_get_file_name(_("Select file to export to"),
- export_uri,
- GTK_WINDOW(details->dialog),
- CONG_FILE_CHOOSER_ACTION_SAVE,
- NULL /* For now */);
-
- if (new_uri) {
- cong_exporter_set_preferred_uri(exporter, new_uri);
- g_free(new_uri);
+ new_file = cong_get_file_name(_("Select file to export to"),
+ export_file,
+ GTK_WINDOW(details->dialog),
+ CONG_FILE_CHOOSER_ACTION_SAVE,
+ NULL /* For now */);
+
+ if (new_file) {
+ cong_exporter_set_preferred_location(exporter, new_file);
+ g_object_unref(new_file);
}
- if (export_uri) {
- g_free(export_uri);
+ if (export_file) {
+ g_object_unref(export_file);
}
}
@@ -392,7 +396,7 @@ cong_ui_hook_file_export (CongDocument *doc,
GtkWidget *dialog;
CongExportDialogDetails *dialog_details;
CongServiceExporter* exporter = NULL;
- gchar *export_uri = NULL;
+ GFile *export_file = NULL;
gint flag = 1;
g_return_if_fail(doc);
@@ -424,8 +428,8 @@ cong_ui_hook_file_export (CongDocument *doc,
exporter = get_selected_exporter (dialog_details);
g_assert (exporter);
- export_uri = cong_exporter_get_preferred_uri (exporter);
- if (export_uri==NULL) {
+ export_file = cong_exporter_get_preferred_location (exporter);
+ if (export_file==NULL) {
GtkDialog* error_dialog;
error_dialog = cong_error_dialog_new (toplevel_window,
_("No output file specified"),
@@ -456,16 +460,19 @@ cong_ui_hook_file_export (CongDocument *doc,
* we call the exporter)
*/
if (exporter) {
- g_assert (export_uri);
+ g_assert (export_file);
+
+ char *export_uri = g_file_get_uri(export_file);
g_message("Exporter invoked: \"%s\" to \"%s\"",
cong_service_get_name(CONG_SERVICE(exporter)),
export_uri);
+ g_free(export_uri);
cong_exporter_invoke (exporter,
doc,
- export_uri,
+ export_file,
toplevel_window);
- g_free (export_uri);
+ g_object_unref(export_file);
}
}
diff --git a/src/cong-file-import.c b/src/cong-file-import.c
index c083170..6793790 100644
--- a/src/cong-file-import.c
+++ b/src/cong-file-import.c
@@ -35,11 +35,9 @@
#include "cong-eel.h"
#include <glade/glade-xml.h>
#include "cong-vfs.h"
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include "cong-file-selection.h"
#include "cong-service-importer.h"
#include "cong-plugin-manager.h"
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
static void add_importer_to_list(CongServiceImporter *importer, gpointer user_data)
{
@@ -64,7 +62,7 @@ static void add_importer_to_list(CongServiceImporter *importer, gpointer user_da
void
cong_ui_hook_file_import (GtkWindow *toplevel_window)
{
- gchar *filename;
+ GFile *file;
GList *list_of_filters = NULL;
GtkFileFilter *filter = NULL;
GList *iter;
@@ -77,16 +75,23 @@ cong_ui_hook_file_import (GtkWindow *toplevel_window)
g_object_ref (G_OBJECT (iter->data));
}
- filename = cong_get_file_name_with_filter (_("Import file..."),
- NULL,
- toplevel_window,
- CONG_FILE_CHOOSER_ACTION_OPEN,
- list_of_filters,
- &filter);
+ file = cong_get_file_name_with_filter (_("Import file..."),
+ NULL,
+ toplevel_window,
+ CONG_FILE_CHOOSER_ACTION_OPEN,
+ list_of_filters,
+ &filter);
- if (filename) {
+ if (file) {
CongServiceImporter *importer;
- char* mime_type = gnome_vfs_get_mime_type (filename);
+ GFileInfo *info = g_file_query_info(file,
+ G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+
+ char* mime_type = g_file_info_get_attribute_as_string(info,
+ G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
g_assert (filter);
importer = g_object_get_data (G_OBJECT (filter),
@@ -94,11 +99,11 @@ cong_ui_hook_file_import (GtkWindow *toplevel_window)
g_assert (importer);
cong_importer_invoke (importer,
- filename,
+ file,
mime_type,
toplevel_window);
g_free (mime_type);
- g_free (filename);
+ g_object_unref (file);
}
for (iter=list_of_filters;iter;iter=iter->next) {
diff --git a/src/cong-file-open.c b/src/cong-file-open.c
index ad6280f..02ca061 100644
--- a/src/cong-file-open.c
+++ b/src/cong-file-open.c
@@ -91,21 +91,21 @@ query_for_forced_dispspec (gchar *what_failed,
/**
* get_filename_extension:
- * @uri:
+ * @file:
*
* TODO: Write me
* Returns:
*/
gchar*
-get_filename_extension (const GnomeVFSURI *uri)
+get_filename_extension (GFile *file)
{
gchar *result = NULL;
gchar *short_name;
gchar *separator;
- g_return_val_if_fail (uri, NULL);
+ g_return_val_if_fail (file, NULL);
- short_name = gnome_vfs_uri_extract_short_name (uri);
+ short_name = g_file_get_basename(file);
separator = g_strrstr (short_name, ".");
@@ -126,14 +126,14 @@ get_filename_extension (const GnomeVFSURI *uri)
* TODO: Write me
*/
void
-open_document_do (const gchar* doc_name,
+open_document_do (GFile* doc_name,
GtkWindow *parent_window)
{
CongDispspec *ds;
CongDocument *cong_doc;
xmlDocPtr doc = NULL;
- doc = cong_vfs_load_xml_from_uri (doc_name, parent_window);
+ doc = cong_vfs_load_xml_from_file (doc_name, parent_window);
if (NULL==doc) {
return;
@@ -141,10 +141,9 @@ open_document_do (const gchar* doc_name,
/* Use libxml to load the doc: */
{
- GnomeVFSURI* file_uri = gnome_vfs_uri_new(doc_name);
gchar *filename_extension;
- filename_extension = get_filename_extension (file_uri);
+ filename_extension = get_filename_extension (doc_name);
ds = cong_dispspec_registry_get_appropriate_dispspec (cong_app_get_dispspec_registry (cong_app_singleton()),
doc,
@@ -176,8 +175,6 @@ open_document_do (const gchar* doc_name,
}
#endif
- gnome_vfs_uri_unref(file_uri);
-
if (filename_extension) {
g_free (filename_extension);
}
@@ -201,7 +198,9 @@ open_document_do (const gchar* doc_name,
/* Add recent entry */
{
CongPrimaryWindow *primary_window = cong_document_get_primary_window(cong_doc);
- gtk_recent_manager_add_item (primary_window->recent_manager, doc_name);
+ char *uri = g_file_get_uri(doc_name);
+ gtk_recent_manager_add_item (primary_window->recent_manager, uri);
+ g_free(uri);
}
g_object_unref( G_OBJECT(cong_doc));
@@ -216,7 +215,7 @@ open_document_do (const gchar* doc_name,
void
open_document(GtkWindow *parent_window)
{
- char *doc_name;
+ GFile *doc_name;
g_return_if_fail(parent_window);
@@ -231,7 +230,7 @@ open_document(GtkWindow *parent_window)
open_document_do(doc_name, parent_window);
- g_free(doc_name);
+ g_object_unref(doc_name);
}
/**
diff --git a/src/cong-file-properties.c b/src/cong-file-properties.c
index e147bd4..ed15e2a 100644
--- a/src/cong-file-properties.c
+++ b/src/cong-file-properties.c
@@ -45,7 +45,7 @@ struct CongFilePropertiesDialogDetails
gulong sigid_end_edit;
gulong sigid_set_dtd;
- gulong sigid_set_url;
+ gulong sigid_set_file;
};
static gboolean
@@ -66,9 +66,9 @@ on_doc_set_dtd_ptr (CongDocument *doc,
gpointer user_data);
static void
-on_doc_set_url (CongDocument *doc,
- const gchar *new_url,
- gpointer user_data);
+on_doc_set_file (CongDocument *doc,
+ GFile *new_file,
+ gpointer user_data);
static guint
count_words (PangoLanguage *language,
@@ -183,12 +183,16 @@ refresh_filename_and_location (CongFilePropertiesDialogDetails *dialog_details,
/* Location: */
{
- gchar *path;
- path = cong_document_get_parent_uri (doc);
-
+ GFile *parent;
+ char *path;
+
+ parent = cong_document_get_parent (doc);
+ path = g_file_get_uri (parent);
+
gtk_label_set_text ( GTK_LABEL (glade_xml_get_widget (dialog_details->xml,"label_location")),
path);
g_free (path);
+ g_object_unref (parent);
}
}
@@ -349,10 +353,10 @@ cong_file_properties_dialog_new (CongDocument *doc,
/* Filename & Location: */
refresh_filename_and_location (dialog_details, doc);
- dialog_details->sigid_set_url = g_signal_connect_after (G_OBJECT (doc),
- "set_url",
- G_CALLBACK (on_doc_set_url),
- dialog_details);
+ dialog_details->sigid_set_file = g_signal_connect_after (G_OBJECT (doc),
+ "set_file",
+ G_CALLBACK (on_doc_set_file),
+ dialog_details);
/* Modified: */
{
@@ -427,7 +431,7 @@ on_dialog_destroy (GtkWidget *widget,
CongFilePropertiesDialogDetails *dialog_details = (CongFilePropertiesDialogDetails*)user_data;
g_signal_handler_disconnect (G_OBJECT (dialog_details->doc),
- dialog_details->sigid_set_url);
+ dialog_details->sigid_set_file);
g_signal_handler_disconnect (G_OBJECT (dialog_details->doc),
dialog_details->sigid_end_edit);
g_signal_handler_disconnect (G_OBJECT (dialog_details->doc),
@@ -520,13 +524,13 @@ on_doc_set_dtd_ptr (CongDocument *doc,
}
static void
-on_doc_set_url (CongDocument *doc,
- const gchar *new_url,
- gpointer user_data)
+on_doc_set_file (CongDocument *doc,
+ GFile *new_file,
+ gpointer user_data)
{
CongFilePropertiesDialogDetails *dialog_details = (CongFilePropertiesDialogDetails*)user_data;
g_assert (IS_CONG_DOCUMENT (doc));
- g_assert (new_url);
+ g_assert (new_file);
refresh_filename_and_location (dialog_details,
doc);
diff --git a/src/cong-file-save.c b/src/cong-file-save.c
index ee3f831..49ccea9 100644
--- a/src/cong-file-save.c
+++ b/src/cong-file-save.c
@@ -24,7 +24,6 @@
*/
#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
#include "global.h"
@@ -63,102 +62,97 @@ toolbar_callback_save(GtkWidget *w, gpointer data)
gint
save_document_as(CongDocument *doc, GtkWindow *parent_window)
{
- char *current_doc_name;
- char *new_doc_name;
- GnomeVFSURI *uri;
+ GFile *current_doc;
+ GFile *new_doc;
g_return_val_if_fail(doc, FALSE);
g_return_val_if_fail(parent_window, FALSE);
- current_doc_name = cong_document_get_full_uri(doc);
+ current_doc = cong_document_get_file(doc);
- new_doc_name = cong_get_file_name(_("Save XML as..."),
- current_doc_name,
- parent_window,
- CONG_FILE_CHOOSER_ACTION_SAVE,
- cong_file_selection_make_xml_filter_list ());
- if (current_doc_name) {
- g_free(current_doc_name);
- }
+ new_doc = cong_get_file_name(_("Save XML as..."),
+ current_doc,
+ parent_window,
+ CONG_FILE_CHOOSER_ACTION_SAVE,
+ cong_file_selection_make_xml_filter_list ());
- if (!new_doc_name) {
+ if (!new_doc) {
return TRUE;
}
-
- uri = gnome_vfs_uri_new (new_doc_name);
-
- if (gnome_vfs_uri_exists (uri)) {
- GnomeVFSFileInfo *info;
- gboolean writable;
- GtkWidget *dialog;
- GtkWidget *content;
- gchar *reason;
-
- info = gnome_vfs_file_info_new ();
-
- if (gnome_vfs_get_file_info (new_doc_name,
- info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
- GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS) == GNOME_VFS_OK) {
-
- if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
-
- writable = info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE;
-
- if (!writable) {
- reason = g_strdup_printf (_("The file \"%s\" is read-only.\n"), new_doc_name);
+ if (g_file_query_exists (new_doc, NULL)) {
+
+ GFileInfo *info;
+ gboolean writable;
+ GtkWidget *dialog;
+ GtkWidget *content;
+ gchar *reason;
+ const char *filename;
- } else {
- reason = g_strdup_printf (_("A file named \"%s\" already exists.\n"), new_doc_name);
- }
-
- dialog = gtk_dialog_new_with_buttons(NULL,
- parent_window,
- GTK_DIALOG_MODAL,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- _("_Replace"),
- GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response(GTK_DIALOG(dialog),
- GTK_RESPONSE_OK);
-
-
- content = cong_alert_content_new(GTK_STOCK_DIALOG_WARNING,
- reason,
- _("Do you want to replace it with the "
- "one you are saving?"),
- NULL);
-
- gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), content);
- gtk_widget_show_all(dialog);
-
- if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
- cong_document_save(doc, new_doc_name, parent_window);
- }
-
- gtk_widget_destroy (dialog);
- g_free (reason);
+ info = g_file_query_info (new_doc,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+
+ if (info) {
+
+ filename = g_file_info_get_display_name(info);
+ writable = g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+
+ if (!writable) {
+ reason = g_strdup_printf (_("The file \"%s\" is read-only.\n"), filename);
+
+ } else {
+ reason = g_strdup_printf (_("A file named \"%s\" already exists.\n"), filename);
}
- }
+ dialog = gtk_dialog_new_with_buttons(NULL,
+ parent_window,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ _("_Replace"),
+ GTK_RESPONSE_OK,
+ NULL);
- gnome_vfs_file_info_unref (info);
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog),
+ GTK_RESPONSE_OK);
+
+
+ content = cong_alert_content_new(GTK_STOCK_DIALOG_WARNING,
+ reason,
+ _("Do you want to replace it with the "
+ "one you are saving?"),
+ NULL);
+
+ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), content);
+ gtk_widget_show_all(dialog);
+
+ if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+ cong_document_save(doc, new_doc, parent_window);
+ }
+
+ gtk_widget_destroy (dialog);
+ g_free (reason);
+
+ g_object_unref(info);
+
+ }
} else {
- cong_document_save(doc, new_doc_name, parent_window);
+ cong_document_save(doc, new_doc, parent_window);
}
/* Add recent entry */
{
CongPrimaryWindow *primary_window = cong_document_get_primary_window(doc);
- gtk_recent_manager_add_item (primary_window->recent_manager, new_doc_name);
+ char *uri = g_file_get_uri(new_doc);
+ gtk_recent_manager_add_item (primary_window->recent_manager, uri);
+ g_free(uri);
}
- g_free(new_doc_name);
- gnome_vfs_uri_unref (uri);
+ g_object_unref(new_doc);
return TRUE;
}
@@ -174,19 +168,17 @@ save_document_as(CongDocument *doc, GtkWindow *parent_window)
gint
save_document(CongDocument *doc, GtkWindow *parent_window)
{
- gchar *doc_name;
+ GFile *doc_name;
g_return_val_if_fail(doc, FALSE);
- doc_name = cong_document_get_full_uri(doc);
+ doc_name = cong_document_get_file(doc);
if (!doc_name) {
return save_document_as(doc, parent_window);
}
cong_document_save(doc, doc_name, parent_window);
-
- g_free(doc_name);
return TRUE;
}
diff --git a/src/cong-file-selection.h b/src/cong-file-selection.h
index c0f8065..d230c59 100644
--- a/src/cong-file-selection.h
+++ b/src/cong-file-selection.h
@@ -33,16 +33,16 @@ typedef enum
CONG_FILE_CHOOSER_ACTION_SAVE
} CongFileChooserAction;
-gchar*
+GFile *
cong_get_file_name (const gchar *title,
- const gchar *uri,
+ GFile *start_file,
GtkWindow *parent_window,
CongFileChooserAction action,
GList *list_of_filters);
-gchar*
+GFile *
cong_get_file_name_with_filter (const gchar *title,
- const gchar *filename,
+ GFile *start_file,
GtkWindow *parent_window,
CongFileChooserAction action,
GList *list_of_filters,
diff --git a/src/cong-graph.c b/src/cong-graph.c
index 7dcaa71..60654cf 100644
--- a/src/cong-graph.c
+++ b/src/cong-graph.c
@@ -24,13 +24,13 @@ const CongDependencyNodeClass klass_pure_dependency = {
* Returns: the new #CongDependencyNode
*/
CongDependencyNode *
-cong_dependency_node_new_from_file(GnomeVFSURI *uri)
+cong_dependency_node_new_from_file(GFile *file)
{
CongDependencyNodeFromFile *node;
node = g_new0(CongDependencyNodeFromFile,1);
- construct_dependency_node_from_file(node, &klass_pure_dependency, uri);
+ construct_dependency_node_from_file(node, &klass_pure_dependency, file);
return CONG_DEPENDENCY_NODE(node);
}
@@ -44,13 +44,13 @@ cong_dependency_node_new_from_file(GnomeVFSURI *uri)
* TODO: Write me
*/
void
-construct_dependency_node_from_file(CongDependencyNodeFromFile *node, const CongDependencyNodeClass *klass, GnomeVFSURI *uri)
+construct_dependency_node_from_file(CongDependencyNodeFromFile *node, const CongDependencyNodeClass *klass, GFile *file)
{
node->base.klass = klass;
- node->base.debug_name = gnome_vfs_uri_to_string(uri, GNOME_VFS_URI_HIDE_PASSWORD);
+ node->base.debug_name = g_file_get_uri(file);
- node->uri = uri;
- gnome_vfs_uri_ref(uri);
+ node->file = file;
+ g_object_ref(file);
}
/**
diff --git a/src/cong-graph.h b/src/cong-graph.h
index 89606a7..d8bbd23 100644
--- a/src/cong-graph.h
+++ b/src/cong-graph.h
@@ -47,7 +47,7 @@ struct _CongDependencyNodeFromFile
{
CongDependencyNode base;
- GnomeVFSURI *uri; /* in a subclass, to allow in-memory modification */
+ GFile *file; /* in a subclass, to allow in-memory modification */
};
struct _CongDependencyGraph
@@ -60,11 +60,11 @@ struct _CongBuildProcess
/* mapping from targets to modification times? */
};
-/* Manufacture a "pure" dependency from a URI: */
-CongDependencyNode *cong_dependency_node_new_from_file(GnomeVFSURI *uri);
+/* Manufacture a "pure" dependency from a GFile: */
+CongDependencyNode *cong_dependency_node_new_from_file(GFile *file);
void cong_dependency_node_add_dependency(CongDependencyNode *downstream, CongDependencyNode *upstream);
-void construct_dependency_node_from_file(CongDependencyNodeFromFile *node, const CongDependencyNodeClass *klass, GnomeVFSURI *uri);
+void construct_dependency_node_from_file(CongDependencyNodeFromFile *node, const CongDependencyNodeClass *klass, GFile *uri);
CongDependencyGraph *cong_dependency_graph_new(void);
void cong_dependency_graph_add_ultimate_target(CongDependencyGraph *graph, CongDependencyNode *target);
diff --git a/src/cong-menus.c b/src/cong-menus.c
index 3a77932..1939479 100644
--- a/src/cong-menus.c
+++ b/src/cong-menus.c
@@ -42,11 +42,6 @@
#include "cong-range.h"
#include "cong-ui-hooks.h"
-#if 1
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#endif
-
#include <libxml/tree.h>
#include <libxslt/xsltInternals.h>
@@ -1930,13 +1925,16 @@ recent_open_cb (GtkAction *action, CongPrimaryWindow *primary_window)
{
GtkRecentInfo *info;
const gchar *uri;
+ GFile *file;
info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
g_assert (info != NULL);
uri = gtk_recent_info_get_uri (info);
+ file = g_file_new_for_uri (uri);
- open_document_do (uri, GTK_WINDOW (primary_window->window));
+ open_document_do (file, GTK_WINDOW (primary_window->window));
+ g_object_unref (file);
}
static gint
diff --git a/src/cong-overview-view.c b/src/cong-overview-view.c
index c10da3d..7db9a12 100644
--- a/src/cong-overview-view.c
+++ b/src/cong-overview-view.c
@@ -47,9 +47,9 @@ GdkPixbuf* pixbuf_callback (CongTreeView *cong_tree_view,
gpointer user_data);
static void
-on_doc_set_url (CongDocument *doc,
- const gchar *new_url,
- gpointer user_data);
+on_doc_set_file (CongDocument *doc,
+ GFile *new_file,
+ gpointer user_data);
static void
on_widget_destroy (GtkWidget *widget,
@@ -62,7 +62,7 @@ struct CongOverviewDetails
{
CongTreeView *tree_view;
CongDocument *doc;
- gulong sigid_set_url;
+ gulong sigid_set_file;
};
/* Exported function implementations: */
@@ -94,10 +94,10 @@ cong_overview_view_new (CongDocument *doc,
overview_details->doc = doc;
g_object_ref (G_OBJECT (doc));
- overview_details->sigid_set_url = g_signal_connect_after (G_OBJECT (doc),
- "set_url",
- G_CALLBACK (on_doc_set_url),
- overview_details);
+ overview_details->sigid_set_file = g_signal_connect_after (G_OBJECT (doc),
+ "set_file",
+ G_CALLBACK (on_doc_set_file),
+ overview_details);
g_signal_connect_after (G_OBJECT (cong_tree_view_get_widget (overview_details->tree_view)),
"destroy",
G_CALLBACK (on_widget_destroy),
@@ -327,13 +327,13 @@ GdkPixbuf* pixbuf_callback (CongTreeView *cong_tree_view,
}
static void
-on_doc_set_url (CongDocument *doc,
- const gchar *new_url,
- gpointer user_data)
+on_doc_set_file (CongDocument *doc,
+ GFile *new_file,
+ gpointer user_data)
{
CongOverviewDetails *overview_details = (CongOverviewDetails*)user_data;
g_assert (IS_CONG_DOCUMENT (doc));
- g_assert (new_url);
+ g_assert (new_file);
/* Update root: */
cong_tree_view_protected_force_node_update (overview_details->tree_view,
@@ -347,7 +347,7 @@ on_widget_destroy (GtkWidget *widget,
CongOverviewDetails *overview_details = (CongOverviewDetails*)user_data;
g_signal_handler_disconnect (G_OBJECT (overview_details->doc),
- overview_details->sigid_set_url);
+ overview_details->sigid_set_file);
g_object_unref (G_OBJECT (overview_details->doc));
g_free (overview_details);
diff --git a/src/cong-parser-error.c b/src/cong-parser-error.c
index b366f56..70d093f 100644
--- a/src/cong-parser-error.c
+++ b/src/cong-parser-error.c
@@ -221,9 +221,9 @@ cong_parser_result_dialog_new(CongParserResult *parser_result)
g_return_val_if_fail(parser_result, NULL);
g_assert(parser_result);
- g_assert(parser_result->string_uri);
+ g_assert(parser_result->file);
- filename = cong_vfs_extract_short_name (parser_result->string_uri);
+ filename = cong_vfs_extract_short_name (parser_result->file);
title = g_strdup_printf(_("Parse errors loading %s"), filename);
@@ -376,14 +376,14 @@ on_parser_error_details(gpointer data)
/**
* cong_error_dialog_new_file_open_failed_from_parser_error:
- * @string_uri:
+ * @file:
* @parser_result:
*
* TODO: Write me
* Returns:
*/
GtkDialog*
-cong_error_dialog_new_file_open_failed_from_parser_error (const gchar* string_uri,
+cong_error_dialog_new_file_open_failed_from_parser_error (GFile *file,
CongParserResult *parser_result)
{
GtkDialog* dialog = NULL;
@@ -395,7 +395,7 @@ cong_error_dialog_new_file_open_failed_from_parser_error (const gchar* string_ur
g_assert(parser_result);
dialog = cong_error_dialog_new_from_file_open_failure_with_convenience (parser_result->parent_window,
- string_uri,
+ file,
FALSE,
why_failed,
_("Conglomerate currently requires documents to be \"well-formed\"; it has much stricter rules than most web browsers. It also does not yet support SGML. We hope to fix these problems in a later release."),
@@ -421,8 +421,8 @@ cong_error_dialog_new_file_open_failed_from_parser_error (const gchar* string_ur
*/
xmlDocPtr
cong_ui_parse_buffer (const char* buffer,
- GnomeVFSFileSize size,
- const gchar *string_uri,
+ gsize size,
+ GFile *file,
GtkWindow *parent_window)
{
#if 1
@@ -432,14 +432,14 @@ cong_ui_parse_buffer (const char* buffer,
CongParserResult parser_result;
g_return_val_if_fail(buffer, NULL);
- g_return_val_if_fail(string_uri, NULL);
+ g_return_val_if_fail(file, NULL);
parser_result.buffer=buffer;
parser_result.size=size;
parser_result.issues=NULL;
parser_result.parent_window=parent_window;
- parser_result.string_uri = g_strdup (string_uri);
+ parser_result.file = g_file_dup(file);
ctxt = cong_parse_from_memory (buffer,
size,
@@ -448,7 +448,7 @@ cong_ui_parse_buffer (const char* buffer,
if (ctxt->wellFormed) {
ret = ctxt->myDoc;
} else {
- GtkDialog* dialog = cong_error_dialog_new_file_open_failed_from_parser_error (string_uri,
+ GtkDialog* dialog = cong_error_dialog_new_file_open_failed_from_parser_error (file,
&parser_result);
cong_error_dialog_run(GTK_DIALOG(dialog));
@@ -523,7 +523,7 @@ cong_parse_from_filename (const gchar* string_uri,
*/
xmlParserCtxtPtr
cong_parse_from_memory (const char* buffer,
- GnomeVFSFileSize size,
+ gsize size,
CongParserResult *parser_result)
{
xmlParserCtxtPtr ctxt;
diff --git a/src/cong-parser-error.h b/src/cong-parser-error.h
index 5583356..87eabcd 100644
--- a/src/cong-parser-error.h
+++ b/src/cong-parser-error.h
@@ -23,17 +23,17 @@ typedef struct CongParserIssue
typedef struct CongParserResult
{
const char *buffer;
- GnomeVFSFileSize size;
+ gsize size;
GSList *issues; /* list of CongParserIssues */
- const gchar *string_uri;
+ GFile *file;
GtkWindow *parent_window;
} CongParserResult;
xmlDocPtr
cong_ui_parse_buffer (const char* buffer,
- GnomeVFSFileSize size,
- const gchar *string_uri,
+ gsize size,
+ GFile *file,
GtkWindow *parent_window);
void cong_parser_result_add_issue(CongParserResult *result, CongIssueType type, int linenum, gchar *description);
@@ -41,7 +41,7 @@ void cong_parser_result_add_issue(CongParserResult *result, CongIssueType type,
GtkDialog *cong_parser_result_dialog_new(CongParserResult *parser_result);
GtkDialog*
-cong_error_dialog_new_file_open_failed_from_parser_error (const gchar* string_uri,
+cong_error_dialog_new_file_open_failed_from_parser_error (GFile *file,
CongParserResult *parser_result);
xmlParserCtxtPtr
@@ -50,7 +50,7 @@ cong_parse_from_filename (const gchar* string_uri,
xmlParserCtxtPtr
cong_parse_from_memory (const char* buffer,
- GnomeVFSFileSize size,
+ gsize size,
CongParserResult *parser_result);
G_END_DECLS
diff --git a/src/cong-plugin.c b/src/cong-plugin.c
index b2f94ba..6fb07bc 100644
--- a/src/cong-plugin.c
+++ b/src/cong-plugin.c
@@ -611,23 +611,24 @@ cong_ui_new_document_from_imported_xml(xmlDocPtr xml_doc,
* Returns:
*/
gboolean
-cong_ui_load_imported_file_content(const gchar *string_uri,
+cong_ui_load_imported_file_content(GFile *file,
char** buffer,
- GnomeVFSFileSize* size,
+ gsize* size,
GtkWindow *parent_window)
{
- GnomeVFSResult vfs_result;
+ gboolean result;
+ GError *error = NULL;
- g_return_val_if_fail (string_uri, FALSE);
+ g_return_val_if_fail (file, FALSE);
g_return_val_if_fail (buffer, FALSE);
g_return_val_if_fail (size, FALSE);
- vfs_result = cong_vfs_new_buffer_from_file(string_uri, buffer, size);
+ result = cong_vfs_new_buffer_from_file(file, buffer, size, &error);
- if (vfs_result!=GNOME_VFS_OK) {
- GtkDialog* dialog = cong_error_dialog_new_from_file_open_failure_with_vfs_result (parent_window,
- string_uri,
- vfs_result);
+ if (!result) {
+ GtkDialog* dialog = cong_error_dialog_new_from_file_open_failure_with_gerror (parent_window,
+ file,
+ error);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
diff --git a/src/cong-plugin.h b/src/cong-plugin.h
index ec9d242..7dda02e 100644
--- a/src/cong-plugin.h
+++ b/src/cong-plugin.h
@@ -152,12 +152,12 @@ xmlDocPtr cong_ui_transform_doc(CongDocument *doc,
gboolean cong_ui_transform_doc_to_uri(CongDocument *doc,
const gchar *stylesheet_filename,
GList *list_of_parameters,
- const gchar *string_uri,
+ GFile *file,
GtkWindow *toplevel_window);
-gboolean cong_ui_load_imported_file_content(const gchar *uri,
+gboolean cong_ui_load_imported_file_content(GFile *file,
char** buffer,
- GnomeVFSFileSize* size,
+ gsize* size,
GtkWindow *parent_window);
void cong_ui_append_advanced_node_properties_page(GtkNotebook *notebook,
diff --git a/src/cong-service-exporter.c b/src/cong-service-exporter.c
index ce2744b..66728ef 100644
--- a/src/cong-service-exporter.c
+++ b/src/cong-service-exporter.c
@@ -111,33 +111,34 @@ cong_exporter_supports_document(CongServiceExporter *exporter, CongDocument *doc
* TODO: Write me
*/
void
-cong_exporter_invoke(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, GtkWindow *toplevel_window)
+cong_exporter_invoke(CongServiceExporter *exporter, CongDocument *doc, GFile *file, GtkWindow *toplevel_window)
{
g_return_if_fail (IS_CONG_SERVICE_EXPORTER (exporter));
g_return_if_fail (doc);
- g_return_if_fail (uri);
+ g_return_if_fail (file);
g_assert (PRIVATE (exporter)->action_callback);
return PRIVATE (exporter)->action_callback (exporter,
doc,
- uri,
+ file,
PRIVATE (exporter)->user_data,
toplevel_window);
}
/**
- * cong_exporter_get_preferred_uri:
+ * cong_exporter_get_preferred_location:
* @exporter:
*
* TODO: Write me
* Returns:
*/
-gchar *
-cong_exporter_get_preferred_uri(CongServiceExporter *exporter)
+GFile *
+cong_exporter_get_preferred_location(CongServiceExporter *exporter)
{
gchar *gconf_key;
gchar *preferred_uri;
+ GFile *retval;
g_return_val_if_fail (IS_CONG_SERVICE_EXPORTER (exporter), NULL);
@@ -150,25 +151,30 @@ cong_exporter_get_preferred_uri(CongServiceExporter *exporter)
g_free(gconf_key);
- return preferred_uri;
+ retval = g_file_new_for_uri(preferred_uri);
+ g_free(preferred_uri);
+
+ return retval;
}
/**
- * cong_exporter_set_preferred_uri:
+ * cong_exporter_set_preferred_location:
* @exporter:
- * @uri:
+ * @file:
*
* TODO: Write me
*/
void
-cong_exporter_set_preferred_uri(CongServiceExporter *exporter, const gchar *uri)
+cong_exporter_set_preferred_location(CongServiceExporter *exporter, GFile *file)
{
gchar *gconf_key;
+ char *uri;
g_return_if_fail (IS_CONG_SERVICE_EXPORTER (exporter));
- g_return_if_fail (uri);
+ g_return_if_fail (file);
gconf_key = cong_service_get_gconf_key(CONG_SERVICE(exporter), "preferred-uri");
+ uri = g_file_get_uri(file);
gconf_client_set_string (cong_app_get_gconf_client (cong_app_singleton()),
gconf_key,
@@ -176,6 +182,7 @@ cong_exporter_set_preferred_uri(CongServiceExporter *exporter, const gchar *uri)
NULL);
g_free(gconf_key);
+ g_free(uri);
}
GtkWidget*
diff --git a/src/cong-service-exporter.h b/src/cong-service-exporter.h
index c8590ef..0c50e9e 100644
--- a/src/cong-service-exporter.h
+++ b/src/cong-service-exporter.h
@@ -48,7 +48,7 @@ typedef GtkWidget*
typedef void
(*CongServiceExporterActionCallback) (CongServiceExporter *exporter,
CongDocument *doc,
- const gchar *uri,
+ GFile *file,
gpointer user_data,
GtkWindow *toplevel_window);
@@ -78,14 +78,14 @@ cong_exporter_supports_document (CongServiceExporter *exporter,
void
cong_exporter_invoke (CongServiceExporter *exporter,
CongDocument *doc,
- const gchar *uri,
+ GFile *file,
GtkWindow *toplevel_window);
-gchar*
-cong_exporter_get_preferred_uri (CongServiceExporter *exporter);
+GFile *
+cong_exporter_get_preferred_location (CongServiceExporter *exporter);
void
-cong_exporter_set_preferred_uri (CongServiceExporter *exporter,
- const gchar *uri);
+cong_exporter_set_preferred_location (CongServiceExporter *exporter,
+ GFile *uri);
GtkWidget*
cong_exporter_make_options_widget (CongServiceExporter *exporter,
diff --git a/src/cong-service-importer.c b/src/cong-service-importer.c
index 52ba841..30825ea 100644
--- a/src/cong-service-importer.c
+++ b/src/cong-service-importer.c
@@ -108,18 +108,18 @@ cong_importer_make_file_filter (CongServiceImporter *importer)
*/
void
cong_importer_invoke (CongServiceImporter *importer,
- const gchar *filename,
+ GFile *file,
const gchar *mime_type,
GtkWindow *toplevel_window)
{
g_return_if_fail (IS_CONG_SERVICE_IMPORTER (importer));
- g_return_if_fail (filename);
+ g_return_if_fail (file);
g_return_if_fail (mime_type);
g_assert(PRIVATE (importer)->action_callback);
return PRIVATE (importer)->action_callback (importer,
- filename,
+ file,
mime_type,
PRIVATE (importer)->user_data, toplevel_window);
}
diff --git a/src/cong-service-importer.h b/src/cong-service-importer.h
index 512f5bf..f21e373 100644
--- a/src/cong-service-importer.h
+++ b/src/cong-service-importer.h
@@ -49,7 +49,7 @@ typedef GtkWidget*
typedef void
(*CongServiceImporterActionCallback) (CongServiceImporter *importer,
- const gchar *uri,
+ GFile *file,
const gchar *mime_type,
gpointer user_data,
GtkWindow *toplevel_window);
@@ -78,7 +78,7 @@ cong_importer_make_file_filter (CongServiceImporter *importer);
void
cong_importer_invoke (CongServiceImporter *importer,
- const gchar *filename,
+ GFile *file,
const gchar *mime_type,
GtkWindow *toplevel_window);
diff --git a/src/cong-stylesheet.c b/src/cong-stylesheet.c
index 03a34f9..0557bb9 100644
--- a/src/cong-stylesheet.c
+++ b/src/cong-stylesheet.c
@@ -308,11 +308,11 @@ cong_ui_transform_doc(CongDocument *doc,
* @doc:
* @stylesheet_filename:
* @list_of_parameters: a #GList of #CongStylesheetParameter
- * @string_uri:
+ * @file:
* @toplevel_window:
*
* Applies the stylesheet (@stylesheet_filename) to the
- * document (@doc) and saves the output to @string_uri.
+ * document (@doc) and saves the output to @file.
*
* At present, it is assumed that a dialog window will be
* created if there is an error in the processing (e.g.
@@ -329,17 +329,17 @@ gboolean
cong_ui_transform_doc_to_uri(CongDocument *doc,
const gchar *stylesheet_filename,
GList *list_of_parameters,
- const gchar *string_uri,
+ GFile *file,
GtkWindow *toplevel_window)
{
xmlDocPtr doc_ptr;
- GnomeVFSURI *vfs_uri;
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize file_size;
+ gboolean result;
+ gsize file_size;
+ GError *error = NULL;
g_return_val_if_fail (doc, 0);
g_return_val_if_fail (stylesheet_filename, 0);
- g_return_val_if_fail (string_uri, 0);
+ g_return_val_if_fail (file, 0);
doc_ptr = cong_ui_transform_doc(doc,
stylesheet_filename,
@@ -349,15 +349,15 @@ cong_ui_transform_doc_to_uri(CongDocument *doc,
return 0;
}
- vfs_uri = gnome_vfs_uri_new(string_uri);
- vfs_result = cong_vfs_save_xml_to_uri (doc_ptr,
- vfs_uri,
- &file_size);
+ result = cong_vfs_save_xml_to_file (doc_ptr,
+ file,
+ &file_size,
+ &error);
- if (vfs_result != GNOME_VFS_OK) {
+ if (!result) {
GtkDialog* dialog = cong_error_dialog_new_from_file_save_failure(toplevel_window,
- string_uri,
- vfs_result,
+ file,
+ error,
&file_size);
cong_error_dialog_run(GTK_DIALOG(dialog));
@@ -365,7 +365,6 @@ cong_ui_transform_doc_to_uri(CongDocument *doc,
return 0;
}
- gnome_vfs_uri_unref(vfs_uri);
xmlFreeDoc(doc_ptr);
return 1;
}
diff --git a/src/cong-ui-hooks.h b/src/cong-ui-hooks.h
index b1d1893..f52b73e 100644
--- a/src/cong-ui-hooks.h
+++ b/src/cong-ui-hooks.h
@@ -212,7 +212,7 @@ gint save_document_as(CongDocument *doc, GtkWindow *parent_window);
char *pick_structural_tag(CongDispspec *ds);
-void open_document_do(const gchar *doc_name, GtkWindow *parent_window);
+void open_document_do(GFile *file, GtkWindow *parent_window);
void new_document(GtkWindow *parent_window);
int gui_window_new_document_make();
diff --git a/src/cong-util.c b/src/cong-util.c
index e69d827..7442135 100644
--- a/src/cong-util.c
+++ b/src/cong-util.c
@@ -23,6 +23,8 @@
* Fragments of code based upon libxslt: numbers.c
*/
+#include <sys/types.h>
+#include <pwd.h>
#include "global.h"
#include "cong-util.h"
#include "cong-app.h"
@@ -1594,7 +1596,7 @@ void
cong_util_run_add_dtd_dialog (CongDocument *doc,
GtkWindow *parent_window)
{
- gchar* dtd_filename;
+ GFile *dtd_file;
GList *list_of_filters;
g_return_if_fail (doc);
@@ -1602,24 +1604,26 @@ cong_util_run_add_dtd_dialog (CongDocument *doc,
list_of_filters = g_list_append (NULL, cong_util_make_file_filter (_("DTD files"),
"text/x-dtd"));
- dtd_filename = cong_get_file_name (_("Select a DTD"),
- NULL,
- parent_window,
- CONG_FILE_CHOOSER_ACTION_OPEN,
- list_of_filters);
+ dtd_file = cong_get_file_name (_("Select a DTD"),
+ NULL,
+ parent_window,
+ CONG_FILE_CHOOSER_ACTION_OPEN,
+ list_of_filters);
- if (dtd_filename) {
+ if (dtd_file) {
CongCommand *cmd = cong_document_begin_command (doc,
_("Associate with DTD"),
NULL);
+ char *dtd_uri = g_file_get_uri(dtd_file);
cong_command_add_set_external_dtd (cmd,
(const gchar*)cong_document_get_root_element (doc)->name,
NULL,
- dtd_filename);
+ dtd_uri);
cong_document_end_command (doc,
cmd);
- g_free (dtd_filename);
+ g_free(dtd_uri);
+ g_object_unref (dtd_file);
}
}
@@ -1825,3 +1829,81 @@ cong_util_set_attribute_int (xmlNodePtr xml_node, const gchar* name, int value)
xmlSetProp (xml_node, (const xmlChar*)name, (const xmlChar*)textual_value);
g_free(textual_value);
}
+
+/* From gnome-vfs-utils.c */
+
+/**
+ * cong_util_expand_initial_tilde:
+ * @path: a local file path which may start with a '~'.
+ *
+ * If @path starts with a ~, representing the user's home
+ * directory, expand it to the actual path location.
+ *
+ * Return value: a newly allocated string with the initial
+ * tilde (if there was one) converted to an actual path.
+ */
+char *
+cong_util_expand_initial_tilde(const char *path)
+{
+ char *slash_after_user_name, *user_name;
+ struct passwd *passwd_file_entry;
+
+ g_return_val_if_fail(path != NULL, NULL);
+
+ if(path[0] != '~')
+ return g_strdup(path);
+
+ if(path[1] == '/' || path[1] == '\0')
+ return g_strconcat(g_get_home_dir(), &path[1], NULL);
+
+ slash_after_user_name = strchr(&path[1], '/');
+ if(slash_after_user_name == NULL)
+ user_name = g_strdup(&path[1]);
+ else
+ user_name = g_strndup(&path[1], slash_after_user_name - &path[1]);
+
+ passwd_file_entry = getpwnam(user_name);
+ g_free(user_name);
+
+ if(passwd_file_entry == NULL || passwd_file_entry->pw_dir == NULL)
+ return g_strdup(path);
+
+ return g_strconcat(passwd_file_entry->pw_dir, slash_after_user_name, NULL);
+}
+
+/**
+ * cong_util_format_file_size_for_display:
+ * @size: a #gsize.
+ *
+ * Formats the file @size passed so that it is easy for
+ * the user to read. Gives the size in bytes, kilobytes, megabytes, or
+ * gigabytes, choosing whatever is appropriate.
+ *
+ * Returns: a newly allocated string with the size ready to be shown.
+ */
+#define KILOBYTE_FACTOR 1024.0
+#define MEGABYTE_FACTOR 1024.0 * KILOBYTE_FACTOR
+#define GIGABYTE_FACTOR 1024.0 * MEGABYTE_FACTOR
+char *
+cong_util_format_file_size_for_display (gsize size)
+{
+ if (size < (gsize)KILOBYTE_FACTOR) {
+ return g_strdup_printf (dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes", (unsigned) size), (unsigned) size);
+ } else {
+ double displayed_size;
+
+ if (size < (gsize) MEGABYTE_FACTOR) {
+ displayed_size = (double) size / KILOBYTE_FACTOR;
+ return g_strdup_printf (_("%.1f KB"),
+ displayed_size);
+ } else if (size < (gsize) GIGABYTE_FACTOR) {
+ displayed_size = (double) size / MEGABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f MB"),
+ displayed_size);
+ } else {
+ displayed_size = (double) size / GIGABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f GB"),
+ displayed_size);
+ }
+ }
+}
diff --git a/src/cong-util.h b/src/cong-util.h
index 37ca3f2..86a8e5b 100644
--- a/src/cong-util.h
+++ b/src/cong-util.h
@@ -306,6 +306,12 @@ cong_util_set_attribute_bool (xmlNodePtr xml_node, const gchar* name, gboolean v
void
cong_util_set_attribute_int (xmlNodePtr xml_node, const gchar* name, int value);
+char *
+cong_util_expand_initial_tilde(const char *path);
+
+char *
+cong_util_format_file_size_for_display (gsize size);
+
G_END_DECLS
#endif
diff --git a/src/cong-vfs.c b/src/cong-vfs.c
index b77b48e..699482e 100644
--- a/src/cong-vfs.c
+++ b/src/cong-vfs.c
@@ -34,150 +34,63 @@
*/
/**
* cong_vfs_read_bytes:
- * @vfs_handle:
+ * @input_stream:
* @buffer:
* @bytes:
*
* TODO: Write me
- * Returns:
+ * Returns: %TRUE in any case.
*/
-GnomeVFSResult
-cong_vfs_read_bytes (GnomeVFSHandle* vfs_handle,
+gboolean
+cong_vfs_read_bytes (GInputStream* stream,
char* buffer,
- GnomeVFSFileSize bytes)
+ gsize bytes)
{
- GnomeVFSFileSize bytes_read;
- GnomeVFSResult vfs_result = gnome_vfs_read(vfs_handle,buffer,bytes,&bytes_read);
+ gsize bytes_read = g_input_stream_read(stream, buffer, bytes, NULL, NULL);
g_assert(bytes==bytes_read); /* for now */
- return vfs_result;
+ return TRUE;
}
/*
A routine that tries to syncronously load a file into a buffer in memory (surely this exists already somewhere?)
+ -- It does indeed! g_file_get_contents().
*/
/**
* cong_vfs_new_buffer_from_file:
- * @filename:
+ * @file:
* @buffer:
* @size:
+ * @error: Return location for an error, or %NULL.
*
* TODO: Write me
- * Returns:
+ * Returns: %TRUE on success, %FALSE if @error was set.
*/
-GnomeVFSResult
-cong_vfs_new_buffer_from_file (const char* filename,
+gboolean
+cong_vfs_new_buffer_from_file (GFile *file,
char** buffer,
- GnomeVFSFileSize* size)
+ gsize* size,
+ GError **error)
{
- GnomeVFSResult vfs_result;
- GnomeVFSURI* uri;
-
- g_return_val_if_fail(filename,GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(buffer,GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(size,GNOME_VFS_ERROR_BAD_PARAMETERS);
-
- uri = gnome_vfs_uri_new (filename);
-
- vfs_result = cong_vfs_new_buffer_from_uri(uri, buffer, size);
+ g_return_val_if_fail(file, FALSE);
+ g_return_val_if_fail(buffer, FALSE);
+ g_return_val_if_fail(size, FALSE);
- gnome_vfs_uri_unref(uri);
-
- return vfs_result;
+ return g_file_load_contents(file, NULL, buffer, size, NULL, error);
}
/**
- * cong_vfs_new_buffer_from_uri:
- * @vfs_uri:
- * @buffer:
- * @size:
- *
- * A routine that tries to syncronously load a file into a buffer in memory (surely this exists already somewhere?)
- *
- * Returns:
- */
-GnomeVFSResult
-cong_vfs_new_buffer_from_uri (GnomeVFSURI* uri,
- char** buffer,
- GnomeVFSFileSize* size)
-{
- GnomeVFSResult vfs_result;
- GnomeVFSHandle *vfs_handle;
-
- g_return_val_if_fail(uri,GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(buffer,GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(size,GNOME_VFS_ERROR_BAD_PARAMETERS);
-
- vfs_result = gnome_vfs_open_uri(&vfs_handle,
- uri,
- GNOME_VFS_OPEN_READ);
-
- if (GNOME_VFS_OK!=vfs_result) {
- return vfs_result;
- } else {
- GnomeVFSFileInfo *info;
- *buffer=NULL;
-
- info = gnome_vfs_file_info_new ();
-
- /* Get the size of the file: */
- vfs_result = gnome_vfs_get_file_info_from_handle(vfs_handle,
- info,
- GNOME_VFS_FILE_INFO_DEFAULT);
- if (GNOME_VFS_OK!=vfs_result) {
- gnome_vfs_close(vfs_handle);
- gnome_vfs_file_info_unref (info);
-
- return vfs_result;
- }
-
- if (!(info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)) {
- gnome_vfs_close(vfs_handle);
- gnome_vfs_file_info_unref (info);
-
- return GNOME_VFS_ERROR_IO; /* FIXME: is this appropriate? */
- }
-
-
- /* Allocate the buffer: */
- *buffer = g_malloc(info->size);
-
- /* Read the file into the buffer: */
- vfs_result = cong_vfs_read_bytes(vfs_handle, *buffer, info->size);
-
- if (GNOME_VFS_OK!=vfs_result) {
-
- g_free(*buffer);
- gnome_vfs_close(vfs_handle);
- gnome_vfs_file_info_unref (info);
-
- *buffer=NULL;
-
- return vfs_result;
- }
-
- gnome_vfs_close(vfs_handle);
-
- *size = info->size;
-
- gnome_vfs_file_info_unref (info);
-
- return GNOME_VFS_OK;
- }
-}
-
-/**
- * cong_vfs_load_xml_from_uri:
- * @string_uri:
+ * cong_vfs_load_xml_from_file:
+ * @file:
* @parent_window:
*
* TODO: Write me
* Returns:
*/
xmlDocPtr
-cong_vfs_load_xml_from_uri (const gchar *string_uri,
- GtkWindow *parent_window)
+cong_vfs_load_xml_from_file (GFile *file,
+ GtkWindow *parent_window)
{
xmlDocPtr xml_doc = NULL;
@@ -238,22 +151,22 @@ cong_vfs_load_xml_from_uri (const gchar *string_uri,
return(ret);
}
#else
- /* Load using GnomeVFS: */
+ /* Load using GIO: */
{
- GnomeVFSURI* vfs_uri = gnome_vfs_uri_new (string_uri);
char* buffer;
- GnomeVFSFileSize size;
- GnomeVFSResult vfs_result = cong_vfs_new_buffer_from_file (string_uri,
- &buffer,
- &size);
- if (vfs_result!=GNOME_VFS_OK) {
- GtkDialog* dialog = cong_error_dialog_new_from_file_open_failure_with_vfs_result (parent_window,
- string_uri,
- vfs_result);
+ gsize size;
+ GError *error = NULL;
+ gboolean result = cong_vfs_new_buffer_from_file (file,
+ &buffer,
+ &size,
+ &error);
+
+ if (!result) {
+ GtkDialog* dialog = cong_error_dialog_new_from_file_open_failure_with_gerror (parent_window,
+ file,
+ error);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
-
- gnome_vfs_uri_unref (vfs_uri);
return NULL;
}
@@ -263,40 +176,40 @@ cong_vfs_load_xml_from_uri (const gchar *string_uri,
/* Parse the file from the buffer: */
xml_doc = cong_ui_parse_buffer (buffer,
size,
- string_uri,
+ file,
parent_window);
g_free(buffer);
- gnome_vfs_uri_unref (vfs_uri);
-
return xml_doc;
}
#endif
}
/**
- * cong_vfs_save_xml_to_uri:
+ * cong_vfs_save_xml_to_file:
* @doc_ptr:
- * @vfs_uri:
+ * @file: a file reference to save to.
* @output_file_size:
+ * @error: return location for an error, or %NULL.
*
* TODO: Write me
- * Returns:
+ * Returns: %TRUE on success, %FALSE if @error was set.
*/
-GnomeVFSResult
-cong_vfs_save_xml_to_uri (xmlDocPtr doc_ptr,
- GnomeVFSURI *file_uri,
- GnomeVFSFileSize *output_file_size)
+gboolean
+cong_vfs_save_xml_to_file (xmlDocPtr doc_ptr,
+ GFile *file,
+ gsize *output_file_size,
+ GError **error)
{
xmlChar* mem;
int size;
- GnomeVFSResult vfs_result;
- GnomeVFSHandle *vfs_handle;
- GnomeVFSFileSize written_size;
+ gboolean result;
+ GFileOutputStream *stream;
+ gsize written_size;
- g_return_val_if_fail(doc_ptr, GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(file_uri, GNOME_VFS_ERROR_BAD_PARAMETERS);
- g_return_val_if_fail(output_file_size, GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail(doc_ptr, FALSE);
+ g_return_val_if_fail(file, FALSE);
+ g_return_val_if_fail(output_file_size, FALSE);
/* Dump to a memory buffer. then write out buffer to GnomeVFS: */
xmlDocDumpMemory(doc_ptr,
@@ -307,32 +220,35 @@ cong_vfs_save_xml_to_uri (xmlDocPtr doc_ptr,
*output_file_size = size;
- vfs_result = gnome_vfs_create_uri(&vfs_handle,
- file_uri,
- GNOME_VFS_OPEN_WRITE,
- FALSE,
- 0644
- );
-
- if (vfs_result != GNOME_VFS_OK) {
- return vfs_result;
+ stream = g_file_replace(file,
+ NULL,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ error);
+ if(!stream) {
+ xmlFree(mem);
+ return FALSE;
}
- vfs_result = gnome_vfs_write(vfs_handle,
- mem,
- *output_file_size,
- &written_size);
-
- if (vfs_result != GNOME_VFS_OK) {
- gnome_vfs_close(vfs_handle);
- return vfs_result;
+ result = g_output_stream_write_all(G_OUTPUT_STREAM(stream),
+ mem,
+ *output_file_size,
+ &written_size,
+ NULL,
+ error);
+ xmlFree(mem);
+
+ if (!result) {
+ g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
+ return FALSE;
}
g_assert(*output_file_size == written_size);
- vfs_result = gnome_vfs_close(vfs_handle);
+ result = g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, error);
- return vfs_result;
+ return result;
}
/**
@@ -343,113 +259,98 @@ cong_vfs_save_xml_to_uri (xmlDocPtr doc_ptr,
* valid
*/
gchar*
-cong_vfs_get_local_path_from_uri (GnomeVFSURI *uri)
+cong_vfs_get_local_path_from_file (GFile *file)
{
- gchar *uri_string;
+ gchar *path_string;
- g_return_val_if_fail(uri, NULL);
+ g_return_val_if_fail(file, NULL);
- uri_string = gnome_vfs_uri_to_string(uri,
- (GNOME_VFS_URI_HIDE_USER_NAME
- |GNOME_VFS_URI_HIDE_PASSWORD
- |GNOME_VFS_URI_HIDE_HOST_NAME
- |GNOME_VFS_URI_HIDE_HOST_PORT
- |GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD
- |GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER)
- );
+ path_string = g_file_get_path(file);
- g_message("got \"%s\"",uri_string);
- return uri_string;
+ g_message("got \"%s\"", path_string);
+ return path_string;
}
/**
- * cong_vfs_split_vfs_uri:
- * @vfs_uri:
- * @filename_alone:
- * @path:
+ * cong_vfs_split_file_path:
+ * @file:
+ * @filename_alone: (allow-none): Return location for the basename of the file,
+ * or %NULL if you aren't interested in it.
+ * @path: (allow-none): Return location for the path to the file, or %NULL if
+ * you aren't interested in it.
*
* TODO: Write me
*/
void
-cong_vfs_split_vfs_uri (const GnomeVFSURI* vfs_uri,
- gchar** filename_alone,
- gchar** path)
+cong_vfs_split_file_path (GFile *file,
+ gchar** filename_alone,
+ gchar** path)
{
- GnomeVFSURI* parent_uri;
+ GFile *parent;
- g_return_if_fail(vfs_uri);
+ g_return_if_fail(file);
g_return_if_fail(filename_alone);
g_return_if_fail(path);
- parent_uri = gnome_vfs_uri_get_parent(vfs_uri);
+ if (filename_alone)
+ *filename_alone = g_file_get_basename(file);
- *filename_alone=gnome_vfs_uri_extract_short_name(vfs_uri);
+ if(path) {
+ parent = g_file_get_parent(file);
-#if 1
- /* This version seems better when dealing with e.g. http and ftp methods etc: */
- if (parent_uri) {
+ if (parent) {
- *path=gnome_vfs_uri_to_string(parent_uri,
- GNOME_VFS_URI_HIDE_USER_NAME|GNOME_VFS_URI_HIDE_PASSWORD);
- gnome_vfs_uri_unref(parent_uri);
- } else {
- *path=g_strdup("");
+ *path = g_file_get_path(parent);
+ g_object_unref(parent);
+ } else {
+ *path=g_strdup("");
+ }
}
-#else
- /* This version seems better when dealing with the "file" method; perhaps we should have a conditional here? */
- *path=gnome_vfs_uri_extract_dirname(vfs_uri);
-
- gnome_vfs_uri_unref(parent_uri);
-
-#endif
}
/**
- * cong_vfs_split_string_uri:
- * @string_uri:
- * @filename_alone:
- * @path:
+ * cong_vfs_extract_short_name:
+ * @file: file reference to query.
*
- * TODO: Write me
+ * Gets the short name (base name) of @file. Free the string when done. Note,
+ * this string is in the filename encoding, which might not be UTF-8!
+ * Returns: (transfer full): file's short name, or %NULL on error.
*/
-void
-cong_vfs_split_string_uri (const gchar* string_uri,
- gchar** filename_alone,
- gchar** path)
+gchar*
+cong_vfs_extract_short_name (GFile *file)
{
- GnomeVFSURI* vfs_uri;
-
- g_return_if_fail(string_uri);
-
- vfs_uri = gnome_vfs_uri_new (string_uri);
-
- cong_vfs_split_vfs_uri (vfs_uri,
- filename_alone,
- path);
-
- gnome_vfs_uri_unref (vfs_uri);
+ g_return_val_if_fail(file, NULL);
+ return g_file_get_basename(file);
}
/**
- * cong_vfs_extract_short_name:
- * @string_uri:
+ * cong_vfs_extract_display_name:
+ * @file: file reference to query.
*
- * TODO: Write me
- * Returns:
+ * Gets a short filename suitable for display. Free the string when done. May
+ * fall back to the short non-display name if necessary.
+ * Returns: (transfer full): file's display name, or %NULL on error.
*/
-gchar*
-cong_vfs_extract_short_name (const gchar *string_uri)
+char *
+cong_vfs_extract_display_name (GFile *file)
{
- GnomeVFSURI* vfs_uri;
- gchar *result;
-
- g_return_val_if_fail(string_uri, NULL);
-
- vfs_uri = gnome_vfs_uri_new (string_uri);
-
- result = gnome_vfs_uri_extract_short_name(vfs_uri);
-
- gnome_vfs_uri_unref (vfs_uri);
+ GFileInfo *info;
+ char *retval;
+
+ g_return_val_if_fail(file, NULL);
+
+ info = g_file_query_info(file,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if(info) {
+ retval = g_strdup(g_file_info_get_display_name(info));
+ g_object_unref(info);
+ } else {
+ g_warning("Couldn't query file info");
+ retval = cong_vfs_extract_short_name(file);
+ }
- return result;
+ return retval;
}
diff --git a/src/cong-vfs.h b/src/cong-vfs.h
index be12089..3edf968 100644
--- a/src/cong-vfs.h
+++ b/src/cong-vfs.h
@@ -25,8 +25,6 @@
#ifndef __CONG_VFS_H__
#define __CONG_VFS_H__
-#include <libgnomevfs/gnome-vfs.h>
-
G_BEGIN_DECLS
/* Handy utility functions: */
@@ -36,52 +34,48 @@ G_BEGIN_DECLS
* @filename:
* @buffer:
* @size:
+ * @error: Return location for an error, or %NULL.
*
* A routine that tries to syncronously load a file into a buffer in memory (surely this exists already somewhere?)
* (I believe that CVS gnome-vfs has a routine gnome_vfs_read_entire_file that does this)
*
- * Returns:
+ * Returns: %TRUE on success, %FALSE if @error was set.
*/
-GnomeVFSResult
-cong_vfs_new_buffer_from_file (const char* filename,
+gboolean
+cong_vfs_new_buffer_from_file (GFile *file,
char** buffer,
- GnomeVFSFileSize* size);
-
-GnomeVFSResult
-cong_vfs_new_buffer_from_uri (GnomeVFSURI *vfs_uri,
- char** buffer,
- GnomeVFSFileSize* size);
+ gsize* size,
+ GError **error);
xmlDocPtr
-cong_vfs_load_xml_from_uri (const gchar *string_uri,
- GtkWindow *parent_window);
+cong_vfs_load_xml_from_file (GFile *file,
+ GtkWindow *parent_window);
-GnomeVFSResult
-cong_vfs_save_xml_to_uri (xmlDocPtr doc_ptr,
- GnomeVFSURI *vfs_uri,
- GnomeVFSFileSize *output_file_size);
+gboolean
+cong_vfs_save_xml_to_file (xmlDocPtr doc_ptr,
+ GFile *file,
+ gsize *output_file_size,
+ GError **error);
/**
Convert a URI into a POSIX, path, assuming that this is valid:
*/
gchar*
-cong_vfs_get_local_path_from_uri (GnomeVFSURI *vfs_uri);
+cong_vfs_get_local_path_from_file (GFile *file);
void
-cong_vfs_split_vfs_uri (const GnomeVFSURI* vfs_uri,
- gchar** filename_alone,
- gchar** path);
-
-void
-cong_vfs_split_string_uri (const gchar* string_uri,
- gchar** filename_alone,
- gchar** path);
+cong_vfs_split_file_path (GFile* file,
+ gchar** filename_alone,
+ gchar** path);
/**
* Extract a short name from a stringified URI; typically the filename itself, without any path etc
*/
gchar*
-cong_vfs_extract_short_name (const gchar *string_uri);
+cong_vfs_extract_short_name (GFile *file);
+
+char *
+cong_vfs_extract_display_name (GFile *file);
G_END_DECLS
diff --git a/src/file.c b/src/file.c
index caef059..5913391 100644
--- a/src/file.c
+++ b/src/file.c
@@ -10,7 +10,7 @@
/**
* cong_get_file_name:
* @title: Title of the dialog.
- * @uri: File or path to start with. Can be NULL.
+ * @start_file: File or start with. Can be %NULL.
* @parent_window: Window to place dialog over. Can be @NULL.
* @action: CongFileChooserAction, for example, @CONG_FILE_CHOOSER_ACTION_OPEN
* @list_of_filters: GList of GtkFileFilter, often you can create it with
@@ -19,34 +19,33 @@
* This function can be used to present file chooser dialog and allow user
* to select a file.
*
- * Returns: file URI string (Note that it is valid escaped uri, not
- * usual filename, since in theory conglomerate fully use gnome-vfs.
+ * Returns: a #GFile representing the file's URI.
*/
-gchar*
+GFile *
cong_get_file_name (const gchar *title,
- const gchar *uri,
+ GFile *start_file,
GtkWindow *parent_window,
CongFileChooserAction cong_action,
GList *list_of_filters)
{
return cong_get_file_name_with_filter (title,
- uri,
+ start_file,
parent_window,
cong_action,
list_of_filters,
NULL);
}
-gchar*
+GFile *
cong_get_file_name_with_filter (const gchar *title,
- const gchar *uri,
+ GFile *start_file,
GtkWindow *parent_window,
CongFileChooserAction cong_action,
GList *list_of_filters,
GtkFileFilter **output_filter)
{
- gchar *result = NULL;
+ GFile *result = NULL;
GtkWidget *dialog;
GtkFileChooserAction gtk_action;
GList *iter;
@@ -72,8 +71,8 @@ cong_get_file_name_with_filter (const gchar *title,
(gtk_action==GTK_FILE_CHOOSER_ACTION_SAVE)?GTK_STOCK_SAVE:GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
- if (uri) {
- gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
+ if (start_file) {
+ gtk_file_chooser_set_file (GTK_FILE_CHOOSER (dialog), start_file, NULL);
}
for (iter = list_of_filters; iter; iter=iter->next) {
@@ -82,7 +81,7 @@ cong_get_file_name_with_filter (const gchar *title,
}
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
- result = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+ result = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (output_filter) {
GtkFileFilter *filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
diff --git a/src/global.h b/src/global.h
index d43ba36..499fd50 100644
--- a/src/global.h
+++ b/src/global.h
@@ -30,9 +30,6 @@
#include <glib/gi18n.h>
#include <gconf/gconf-client.h>
-/* We include GnomeVFS stuff here to try to alleviate build problems on Fink: */
-#include <libgnomevfs/gnome-vfs.h>
-
G_BEGIN_DECLS
#define CONG_GCONF_PATH "/apps/conglomerate/"
diff --git a/src/main.c b/src/main.c
index 0339023..f7d872c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,8 +15,6 @@ main( int argc,
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
- gnome_vfs_init();
-
cong_app_construct_singleton (argc,
argv);
diff --git a/src/plugin-convert-case.c b/src/plugin-convert-case.c
index ece0b92..0082942 100644
--- a/src/plugin-convert-case.c
+++ b/src/plugin-convert-case.c
@@ -59,13 +59,13 @@ static void visit_node(xmlNodePtr node) {
}
}
-static void convert_case_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, gpointer user_data, GtkWindow *toplevel_window)
+static void convert_case_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, GFile *file, gpointer user_data, GtkWindow *toplevel_window)
{
xmlDocPtr doc_ptr;
g_return_if_fail(exporter);
g_return_if_fail(doc);
- g_return_if_fail(uri);
+ g_return_if_fail(file);
g_message("convert_case_exporter_action_callback");
@@ -84,25 +84,24 @@ static void convert_case_exporter_action_callback(CongServiceExporter *exporter,
/* Save the result: */
if (doc_ptr) {
- GnomeVFSURI *file_uri = gnome_vfs_uri_new(uri);
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize file_size;
+ gboolean result;
+ gsize file_size;
+ GError *error = NULL;
- vfs_result = cong_vfs_save_xml_to_uri (doc_ptr,
- file_uri,
- &file_size);
+ result = cong_vfs_save_xml_to_file (doc_ptr,
+ file,
+ &file_size,
+ &error);
- if (vfs_result != GNOME_VFS_OK) {
+ if (!result) {
GtkDialog* dialog = cong_error_dialog_new_from_file_save_failure(toplevel_window,
- uri,
- vfs_result,
+ file,
+ error,
&file_size);
cong_error_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
}
-
- gnome_vfs_uri_unref(file_uri);
xmlFreeDoc(doc_ptr);
}
diff --git a/src/plugin-docbook.c b/src/plugin-docbook.c
index 63776ec..dacc125 100644
--- a/src/plugin-docbook.c
+++ b/src/plugin-docbook.c
@@ -45,13 +45,13 @@
/* Splits input UTF8 into a GList of nul-terminated GUnichar strings */
static GList*
split_utf8_into_unichar_lines (const gchar *utf8_input,
- GnomeVFSFileSize size);
+ gsize size);
static void
parse_text_buffer_into_docbook (CongDocument *doc,
CongNodePtr root_node,
const char* buffer,
- GnomeVFSFileSize size);
+ gsize size);
#if 0
struct DocBookAuthorInfo
@@ -470,7 +470,7 @@ append_line (GList **result,
static GList*
split_utf8_into_unichar_lines (const gchar *utf8_input,
- GnomeVFSFileSize size)
+ gsize size)
{
GList *result = NULL;
gunichar* ucs4_full_string;
@@ -706,7 +706,7 @@ static void
parse_text_buffer_into_docbook (CongDocument *doc,
CongNodePtr root_node,
const char* buffer,
- GnomeVFSFileSize size)
+ gsize size)
{
/* Note: this routine uses the private CongDocument methods which are normally reserved for the undo/redo system.
It is safe here, since we are not interacting with that - the document has only just been created. */
@@ -918,7 +918,7 @@ parse_text_buffer_into_docbook (CongDocument *doc,
/**
* text_importer_action_callback:
* @importer:
- * @uri:
+ * @file:
* @mime_type:
* @user_data:
* @toplevel_window:
@@ -926,15 +926,15 @@ parse_text_buffer_into_docbook (CongDocument *doc,
* TODO: Write me
*/
void
-text_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+text_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
char* buffer;
- GnomeVFSFileSize size;
+ gsize size;
xmlDocPtr xml_doc;
g_message("text_importer_action_callback");
- if (cong_ui_load_imported_file_content(uri, &buffer, &size, toplevel_window)) {
+ if (cong_ui_load_imported_file_content(file, &buffer, &size, toplevel_window)) {
CongDocument *doc;
xmlNodePtr root_node;
@@ -1005,18 +1005,21 @@ sourcecode_importer_mime_filter(CongServiceImporter *importer, const gchar *mime
* TODO: Write me
*/
void
-sourcecode_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+sourcecode_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
char* buffer;
- GnomeVFSFileSize size;
+ gsize size;
xmlDocPtr xml_doc;
xmlNodePtr root_node;
+ char *uri;
g_message("sourcecode_importer_action_callback");
- if (cong_ui_load_imported_file_content(uri, &buffer, &size, toplevel_window)) {
+ if (cong_ui_load_imported_file_content(file, &buffer, &size, toplevel_window)) {
g_assert(buffer);
+ uri = g_file_get_uri(file);
+
/* Build up the document and its content: */
xml_doc = xmlNewDoc((const xmlChar*)"1.0");
@@ -1044,6 +1047,7 @@ sourcecode_importer_action_callback(CongServiceImporter *importer, const gchar *
/* Finished building content: */
g_free(buffer);
+ g_free(uri);
/* Do appropriate UI stuff: */
cong_ui_new_document_from_imported_xml(xml_doc,
@@ -1121,7 +1125,7 @@ do_transform(gchar *type,
CongDocument *doc,
const gchar *stylesheet_path,
GList *stylesheet_args,
- const gchar *string_uri,
+ GFile *file,
GtkWindow *toplevel_window)
{
/*
@@ -1132,7 +1136,7 @@ do_transform(gchar *type,
if (cong_ui_transform_doc_to_uri(doc,
stylesheet_path,
stylesheet_args,
- string_uri,
+ file,
toplevel_window)) {
GtkDialog *dialog;
@@ -1140,7 +1144,7 @@ do_transform(gchar *type,
gchar *path;
gchar *message;
- cong_vfs_split_string_uri (string_uri, &filename_alone, &path);
+ cong_vfs_split_file_path (file, &filename_alone, &path);
message = g_strdup_printf (_("%s conversion complete.\n\nConverted %s to %s in %s"),
type,
cong_document_get_filename (doc),
@@ -1168,13 +1172,13 @@ do_transform(gchar *type,
* TODO: Write me
*/
void
-html_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, gpointer user_data, GtkWindow *toplevel_window)
+html_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, GFile *file, gpointer user_data, GtkWindow *toplevel_window)
{
gchar *stylesheet_path;
g_return_if_fail(exporter);
g_return_if_fail(doc);
- g_return_if_fail(uri);
+ g_return_if_fail(file);
g_message("html_exporter_action_callback");
@@ -1188,7 +1192,7 @@ html_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc,
doc,
stylesheet_path,
NULL,
- uri,
+ file,
toplevel_window);
g_free (stylesheet_path);
}
@@ -1243,7 +1247,7 @@ pdf_exporter_options_callback (CongServiceExporter *exporter,
* TODO: Write me
*/
void
-pdf_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, gpointer user_data, GtkWindow *toplevel_window)
+pdf_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, GFile *file, gpointer user_data, GtkWindow *toplevel_window)
{
#if 1
GtkWidget *progress_checklist_dialog;
@@ -1256,7 +1260,7 @@ pdf_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, c
g_return_if_fail(exporter);
g_return_if_fail(doc);
- g_return_if_fail(uri);
+ g_return_if_fail(file);
stylesheet_path = get_and_check_stylesheet_path ("fo","XSL:FO",toplevel_window);
if (stylesheet_path==NULL) {
@@ -1321,14 +1325,14 @@ fo_exporter_options_callback (CongServiceExporter *exporter,
* TODO: Write me
*/
void
-fo_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, gpointer user_data, GtkWindow *toplevel_window)
+fo_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, GFile *file, gpointer user_data, GtkWindow *toplevel_window)
{
gchar *stylesheet_path;
GList *list_of_parameters;
g_return_if_fail(exporter);
g_return_if_fail(doc);
- g_return_if_fail(uri);
+ g_return_if_fail(file);
g_message("fo_exporter_action_callback");
@@ -1343,7 +1347,7 @@ fo_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, co
doc,
stylesheet_path,
list_of_parameters,
- uri,
+ file,
toplevel_window);
g_free(stylesheet_path);
cong_stylesheet_parameter_list_free (list_of_parameters);
diff --git a/src/plugin-dtd.c b/src/plugin-dtd.c
index 4af68a1..01c31b3 100644
--- a/src/plugin-dtd.c
+++ b/src/plugin-dtd.c
@@ -39,7 +39,7 @@
/* Internal function declarations: */
static xmlDtdPtr
-load_dtd (const gchar *uri,
+load_dtd (GFile *file,
GtkWindow *toplevel_window);
static xmlDocPtr
@@ -81,17 +81,19 @@ dtd_importer_filter_factory_callback (CongServiceImporter *importer)
* TODO: Write me
*/
void
-dtd_to_xds_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+dtd_to_xds_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
xmlDtdPtr dtd;
g_message("dtd_to_xds_importer_action_callback");
- dtd = load_dtd(uri, toplevel_window);
+ dtd = load_dtd(file, toplevel_window);
if (dtd) {
+ char *uri = g_file_get_uri(file);
gchar *name = g_strdup_printf(_("Autogenerated document type based on %s"), uri);
gchar *description = g_strdup_printf(_("This Conglomerate display specification was automatically generated from %s"), uri);
+ g_free(uri);
CongDispspec *dispspec = cong_dispspec_new_generate_from_dtd(dtd, name, description);
xmlDocPtr xml_doc = cong_dispspec_make_xml(dispspec);
@@ -122,13 +124,13 @@ dtd_to_xds_importer_action_callback(CongServiceImporter *importer, const gchar *
* TODO: Write me
*/
void
-dtd_to_rng_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+dtd_to_rng_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
xmlDtdPtr dtd;
g_message("dtd_to_rng_importer_action_callback");
- dtd = load_dtd(uri, toplevel_window);
+ dtd = load_dtd(file, toplevel_window);
if (dtd) {
GList *list_of_start_elements = cong_dtd_guess_start_elements (dtd);
@@ -155,7 +157,7 @@ dtd_to_rng_importer_action_callback(CongServiceImporter *importer, const gchar *
* TODO: Write me
*/
void
-dtd_to_w3c_xml_schema_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+dtd_to_w3c_xml_schema_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
g_message("dtd_to_w3c_xml_schema_importer_action_callback");
@@ -173,7 +175,7 @@ dtd_to_w3c_xml_schema_importer_action_callback(CongServiceImporter *importer, co
* TODO: Write me
*/
void
-dtd_to_schematron_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+dtd_to_schematron_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
g_message("dtd_to_schematron_importer_action_callback");
@@ -191,7 +193,7 @@ dtd_to_schematron_importer_action_callback(CongServiceImporter *importer, const
* TODO: Write me
*/
void
-dtd_to_examplotron_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+dtd_to_examplotron_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
g_message("dtd_to_examplotron_importer_action_callback");
@@ -277,24 +279,22 @@ plugin_dtd_plugin_configure(CongPlugin *plugin)
/* Internal function definitions: */
static xmlDtdPtr
-load_dtd (const gchar *uri,
+load_dtd (GFile *file,
GtkWindow *toplevel_window)
{
xmlDtdPtr dtd;
- GnomeVFSURI *vfs_uri;
gchar *local_path;
- g_return_val_if_fail(uri, NULL);
+ g_return_val_if_fail(file, NULL);
- vfs_uri = gnome_vfs_uri_new(uri);
- local_path = cong_vfs_get_local_path_from_uri (vfs_uri);
- gnome_vfs_uri_unref(vfs_uri);
+ local_path = cong_vfs_get_local_path_from_file (file);
dtd = xmlIOParseDTD(NULL,
xmlParserInputBufferCreateFilename (local_path,
XML_CHAR_ENCODING_NONE),
XML_CHAR_ENCODING_NONE);
+ g_free(local_path);
return dtd;
}
diff --git a/src/plugin-fo.c b/src/plugin-fo.c
index 401a093..94c0cd0 100644
--- a/src/plugin-fo.c
+++ b/src/plugin-fo.c
@@ -85,13 +85,13 @@ fo_pdf_exporter_document_filter(CongServiceExporter *exporter, CongDocument *doc
* TODO: Write me
*/
void
-fo_pdf_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, const gchar *uri, gpointer user_data, GtkWindow *toplevel_window)
+fo_pdf_exporter_action_callback(CongServiceExporter *exporter, CongDocument *doc, GFile *file, gpointer user_data, GtkWindow *toplevel_window)
{
g_message("fo_pdf_exporter_action_callback");
g_return_if_fail(exporter);
g_return_if_fail(doc);
- g_return_if_fail(uri);
+ g_return_if_fail(file);
CONG_DO_UNIMPLEMENTED_DIALOG_WITH_BUGZILLA_ID(toplevel_window, _("Converting XSL Formatting Objects to PDF"), 108467);
diff --git a/src/plugin-save-dispspec.c b/src/plugin-save-dispspec.c
index e4f4ef8..667a231 100644
--- a/src/plugin-save-dispspec.c
+++ b/src/plugin-save-dispspec.c
@@ -44,14 +44,20 @@ static gboolean doc_filter(CongServiceDocTool *tool, CongDocument *doc, gpointer
*
* TODO: Write me
*/
-gchar*
-change_to_xds(gchar* filename)
+GFile *
+change_to_xds(GFile* file)
{
+ char *filename;
gchar **split_strings;
gchar *old_doc_name;
gchar *result;
+ GFile *parent;
+ GFile *new_child;
+
+ filename = g_file_get_basename(file);
split_strings = g_strsplit (filename, ".", 2);
+ g_free(filename);
old_doc_name = split_strings[0];
@@ -63,19 +69,25 @@ change_to_xds(gchar* filename)
g_strfreev (split_strings);
- return result;
+ parent = g_file_get_parent(file);
+ new_child = g_file_get_child(parent, result);
+ g_object_unref(parent);
+ g_free(result);
+
+ return new_child;
}
static void save_dispspec(CongServiceDocTool *tool, CongPrimaryWindow *primary_window, gpointer user_data)
{
- gchar *new_doc_name;
- gchar *old_doc_name;
+ GFile *new_doc_name;
+ GFile *old_doc_name;
CongDocument *doc;
xmlDocPtr xml;
+ char *new_doc_uri;
doc = cong_primary_window_get_document(primary_window);
- old_doc_name = change_to_xds (cong_document_get_filename(doc));
+ old_doc_name = change_to_xds (cong_document_get_file(doc));
new_doc_name = cong_get_file_name("Save Display Specification",
old_doc_name,
@@ -84,7 +96,7 @@ static void save_dispspec(CongServiceDocTool *tool, CongPrimaryWindow *primary_w
NULL /* FIXME */);
if (!new_doc_name) {
- g_free (old_doc_name);
+ g_object_unref (old_doc_name);
return;
}
@@ -93,12 +105,14 @@ static void save_dispspec(CongServiceDocTool *tool, CongPrimaryWindow *primary_w
(const xmlChar*)"dispspec",
NULL,
(const xmlChar*)"dispspec.dtd");
- xmlSaveFormatFile(new_doc_name, xml, TRUE);
+ new_doc_uri = g_file_get_uri(new_doc_name);
+ xmlSaveFormatFile(new_doc_uri, xml, TRUE);
+ g_free(new_doc_uri);
/* FIXME: does this leak xml? */
- g_free(new_doc_name);
- g_free(old_doc_name);
+ g_object_unref(new_doc_name);
+ g_object_unref(old_doc_name);
}
diff --git a/src/plugin-sgml.c b/src/plugin-sgml.c
index b6dce10..6f62d46 100644
--- a/src/plugin-sgml.c
+++ b/src/plugin-sgml.c
@@ -28,6 +28,7 @@
#include "cong-plugin.h"
#include "cong-error-dialog.h"
#include "cong-parser-error.h"
+#include "cong-vfs.h"
#include "cong-fake-plugin-hooks.h"
@@ -90,7 +91,7 @@ static gboolean on_stderr(GIOChannel *source,
* TODO: Write me
*/
void
-sgml_importer_action_callback(CongServiceImporter *importer, const gchar *uri, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
+sgml_importer_action_callback(CongServiceImporter *importer, GFile *file, const gchar *mime_type, gpointer user_data, GtkWindow *toplevel_window)
{
#if 0
char* buffer;
@@ -106,13 +107,13 @@ sgml_importer_action_callback(CongServiceImporter *importer, const gchar *uri, c
GError *error = NULL;
gboolean result;
-/* gchar * posix_name = cong_util_get_local_path_from_uri(GnomeVFSURI *uri); */
+ gchar *posix_name = cong_vfs_get_local_path_from_file(file);
g_message("sgml_importer_action_callback");
argv[0] = "sgml2xml";
- argv[1] = (gchar*)uri; /* FIXME: this is GnomeVFS uri path string, not a POSIX path */
+ argv[1] = posix_name;
argv[2] = NULL;
@@ -129,7 +130,7 @@ sgml_importer_action_callback(CongServiceImporter *importer, const gchar *uri, c
&error);
if (!result) {
- gchar *what_failed = cong_ui_make_what_failed_string_for_import(uri);
+ gchar *what_failed = cong_ui_make_what_failed_string_for_import(posix_name);
GtkDialog *dialog = cong_error_dialog_new_from_gerror(toplevel_window,
what_failed,
_("Attempting to run the sgml2xml tool"),
@@ -147,7 +148,7 @@ sgml_importer_action_callback(CongServiceImporter *importer, const gchar *uri, c
g_assert(standard_error);
if (exit_status) {
- gchar *what_failed = cong_ui_make_what_failed_string_for_import(uri);
+ gchar *what_failed = cong_ui_make_what_failed_string_for_import(posix_name);
GtkDialog* dialog = cong_error_dialog_new_from_shell_command_failure_with_argv(toplevel_window,
@@ -172,7 +173,7 @@ sgml_importer_action_callback(CongServiceImporter *importer, const gchar *uri, c
{
xml_doc = cong_ui_parse_buffer (standard_output,
strlen(standard_output),
- uri,
+ file,
toplevel_window);
}
diff --git a/src/plugin-templates.c b/src/plugin-templates.c
index c394867..830ee62 100644
--- a/src/plugin-templates.c
+++ b/src/plugin-templates.c
@@ -162,12 +162,9 @@ static xmlChar* cong_get_template_description(xmlDocPtr doc)
(const xmlChar*)"string(/*/cong:template/cong:description)");
}
-static gboolean
-register_template(const gchar *rel_path,
- GnomeVFSFileInfo *info,
- gboolean recursing_will_loop,
- gpointer data,
- gboolean *recurse)
+static void
+register_template(GFileInfo *info,
+ gpointer data)
{
xmlDocPtr doc;
gchar* file_name;
@@ -176,11 +173,11 @@ register_template(const gchar *rel_path,
CongTemplate* template = (CongTemplate*)data;
- g_return_val_if_fail(template->dir, TRUE);
- g_return_val_if_fail(rel_path, TRUE);
+ g_return_if_fail(template->dir);
+ g_return_if_fail(info);
- file_name = g_strconcat(template->dir, "/", rel_path, NULL);
- g_return_val_if_fail(file_name, TRUE);
+ file_name = g_build_filename(template->dir, g_file_info_get_name(info), NULL);
+ g_return_if_fail(file_name);
g_message("template file: %s", file_name);
@@ -199,41 +196,62 @@ register_template(const gchar *rel_path,
(const char*)name,
factory_page_creation_callback_templates,
factory_action_callback_templates,
- rel_path,
+ g_file_info_get_name(info),
file_name);
}else{
g_warning("Template %s is not a valid template", file_name);
}
+ g_free(file_name);
xmlFree(name);
xmlFree(description);
xmlFreeDoc(doc);
-
- return TRUE;
}
-static void visit_paths(GSList* paths, GnomeVFSDirectoryVisitFunc visit_path,
+static void visit_paths(GSList* paths, void (*visit_path)(GFileInfo *, gpointer),
void* data)
{
GSList* path;
- path = paths;
for(path = paths; path != NULL; path = g_slist_next(path))
{
- GnomeVFSResult vfs_result;
-
- gchar* absolute_path;
- absolute_path = gnome_vfs_expand_initial_tilde(path->data);
+ GFile *file;
+ GFileEnumerator *visitor;
+ GError *error = NULL;
+ GFileInfo *info;
+ char *absolute_path;
+ absolute_path = cong_util_expand_initial_tilde (path->data);
+ file = g_file_new_for_path(absolute_path);
/* g_message("loading templates from %s", absolute_path); */
((CongTemplate*)data)->dir = absolute_path;
- vfs_result = gnome_vfs_directory_visit(absolute_path,
- GNOME_VFS_FILE_INFO_DEFAULT,
- GNOME_VFS_DIRECTORY_VISIT_DEFAULT,
- visit_path,
- data);
+ visitor = g_file_enumerate_children(file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+ if(!visitor) {
+ g_warning("Couldn't visit directory %s: %s", absolute_path, error->message);
+ g_free(absolute_path);
+ g_object_unref(file);
+ g_error_free(error);
+ continue;
+ }
+
+ while((info = g_file_enumerator_next_file(visitor, NULL, &error)) != NULL) {
+ visit_path(info, data);
+ g_object_unref(info);
+ }
+
+ if(error)
+ g_warning("Error visiting directory %s: %s", absolute_path, error->message);
+
+ g_free(absolute_path);
+ g_object_unref(file);
+ g_object_unref(visitor);
+ g_error_free(error);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]