aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/import-ics-attachments/ChangeLog6
-rw-r--r--plugins/import-ics-attachments/icsimporter.c4
-rw-r--r--plugins/ipod-sync/ChangeLog10
-rw-r--r--plugins/ipod-sync/format-handler.h3
-rw-r--r--plugins/ipod-sync/ical-format.c36
-rw-r--r--plugins/ipod-sync/ipod-sync.c117
-rw-r--r--plugins/publish-calendar/ChangeLog16
-rw-r--r--plugins/publish-calendar/publish-calendar.c285
-rw-r--r--plugins/publish-calendar/publish-format-fb.c41
-rw-r--r--plugins/publish-calendar/publish-format-fb.h4
-rw-r--r--plugins/publish-calendar/publish-format-ical.c37
-rw-r--r--plugins/publish-calendar/publish-format-ical.h4
-rw-r--r--plugins/publish-calendar/publish-location.c20
-rw-r--r--plugins/publish-calendar/url-editor-dialog.c4
-rw-r--r--plugins/save-calendar/ChangeLog11
-rw-r--r--plugins/save-calendar/csv-format.c38
-rw-r--r--plugins/save-calendar/format-handler.h3
-rw-r--r--plugins/save-calendar/ical-format.c51
-rw-r--r--plugins/save-calendar/rdf-format.c38
-rw-r--r--plugins/save-calendar/save-calendar.c51
20 files changed, 523 insertions, 256 deletions
diff --git a/plugins/import-ics-attachments/ChangeLog b/plugins/import-ics-attachments/ChangeLog
index dfc443ce64..68a87d906b 100644
--- a/plugins/import-ics-attachments/ChangeLog
+++ b/plugins/import-ics-attachments/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-17 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #526739
+
+ * icsimporter.c: Do not include gnome-vfs.
+
2007-02-20 Paul Bolle <pebolle@tiscali.nl>
** Fix for bug #517082
diff --git a/plugins/import-ics-attachments/icsimporter.c b/plugins/import-ics-attachments/icsimporter.c
index c869db35d9..7b9172c379 100644
--- a/plugins/import-ics-attachments/icsimporter.c
+++ b/plugins/import-ics-attachments/icsimporter.c
@@ -39,10 +39,6 @@
#include <camel/camel-vee-folder.h>
#include "e-util/e-error.h"
#include "e-util/e-icon-factory.h"
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-mime.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libedataserverui/e-source-selector.h>
#include <libecal/e-cal.h>
#include <libical/icalvcal.h>
diff --git a/plugins/ipod-sync/ChangeLog b/plugins/ipod-sync/ChangeLog
index 804f29b157..d6f2a15aef 100644
--- a/plugins/ipod-sync/ChangeLog
+++ b/plugins/ipod-sync/ChangeLog
@@ -1,3 +1,13 @@
+2008-04-17 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #526739
+
+ * ical-format.c: (do_save_calendar_ical):
+ * ipod-sync.c: (destination_save_addressbook):
+ Write to gio GOutputStream instead of gnome-vfs handle.
+ * format-handler.h: (open_for_writing):
+ * ipod-sync.c: (open_for_writing): New helper function.
+
2008-01-07 João Vale <jpvale@gmail.com>
** Fix for bug #375580
diff --git a/plugins/ipod-sync/format-handler.h b/plugins/ipod-sync/format-handler.h
index 7b53efeb2e..badafd7965 100644
--- a/plugins/ipod-sync/format-handler.h
+++ b/plugins/ipod-sync/format-handler.h
@@ -25,6 +25,7 @@
#include <glib.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include <libedataserver/e-source.h>
#include <libedataserverui/e-source-selector.h>
#include <libecal/e-cal.h>
@@ -45,3 +46,5 @@ struct _FormatHandler
};
FormatHandler *ical_format_handler_new (void);
+
+GOutputStream *open_for_writing (GtkWindow *parent, const char *uri, GError **error);
diff --git a/plugins/ipod-sync/ical-format.c b/plugins/ipod-sync/ical-format.c
index 76dc433c69..f5005c1bda 100644
--- a/plugins/ipod-sync/ical-format.c
+++ b/plugins/ipod-sync/ical-format.c
@@ -27,7 +27,6 @@
#include <glib/gi18n.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserdialog.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkstock.h>
#include <gtk/gtk.h>
@@ -37,7 +36,6 @@
#include <libecal/e-cal-util.h>
#include <calendar/gui/e-cal-popup.h>
#include <calendar/common/authentication.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
#include "format-handler.h"
@@ -80,8 +78,7 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc
error = NULL;
if (e_cal_get_object_list (source_client, "#t", &objects, &error)) {
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
+ GOutputStream *stream;
while (objects != NULL) {
icalcomponent *icalcomp = objects->data;
@@ -93,29 +90,22 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc
}
/* save the file */
- result = gnome_vfs_open (&handle, dest_uri, GNOME_VFS_OPEN_WRITE);
- if (result != GNOME_VFS_OK) {
- if ((result = gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE,
- TRUE, GNOME_VFS_PERM_USER_ALL)) != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
- }
+ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), dest_uri, &error);
- if (result == GNOME_VFS_OK) {
- char *ical_str;
- GnomeVFSFileSize bytes_written;
+ if (stream && !error) {
+ char *ical_str = icalcomponent_as_ical_string (top_level);
- ical_str = icalcomponent_as_ical_string (top_level);
- if ((result = gnome_vfs_write (handle, (gconstpointer) ical_str, strlen (ical_str), &bytes_written))
- != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
+ g_output_stream_write_all (stream, ical_str, strlen (ical_str), NULL, NULL, &error);
+ g_output_stream_close (stream);
- gnome_vfs_close (handle);
+ g_free (ical_str);
}
- } else {
+
+ if (stream)
+ g_object_unref (stream);
+ }
+
+ if (error) {
display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
g_error_free (error);
}
diff --git a/plugins/ipod-sync/ipod-sync.c b/plugins/ipod-sync/ipod-sync.c
index bca4242810..c60d19c818 100644
--- a/plugins/ipod-sync/ipod-sync.c
+++ b/plugins/ipod-sync/ipod-sync.c
@@ -40,7 +40,6 @@
#include <libecal/e-cal.h>
#include <calendar/gui/e-cal-popup.h>
#include <addressbook/gui/widgets/eab-popup.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
#include "format-handler.h"
@@ -62,6 +61,56 @@ display_error_message (GtkWidget *parent, const char *message)
gtk_widget_destroy (dialog);
}
+/* Returns output stream for the uri, or NULL on any error.
+ When done with the stream, just g_output_stream_close and g_object_unref it.
+ It will ask for overwrite if file already exists.
+*/
+GOutputStream *
+open_for_writing (GtkWindow *parent, const char *uri, GError **error)
+{
+ GFile *file;
+ GFileOutputStream *fostream;
+ GError *err = NULL;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ file = g_file_new_for_uri (uri);
+
+ g_return_val_if_fail (file != NULL, NULL);
+
+ fostream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &err);
+
+ if (err && err->code == G_IO_ERROR_EXISTS) {
+ g_error_clear (&err);
+
+ if (e_error_run (parent, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, uri, NULL) == GTK_RESPONSE_OK) {
+ fostream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
+
+ if (err && fostream) {
+ g_object_unref (fostream);
+ fostream = NULL;
+ }
+ } else if (fostream) {
+ g_object_unref (fostream);
+ fostream = NULL;
+ }
+ }
+
+ g_object_unref (file);
+
+ if (error && err)
+ *error = err;
+ else if (err)
+ g_error_free (err);
+
+ if (fostream)
+ return G_OUTPUT_STREAM (fostream);
+
+ return NULL;
+}
+
+
+
static void
destination_save_addressbook (EPlugin *ep, EABPopupTargetSource *target)
{
@@ -70,9 +119,9 @@ destination_save_addressbook (EPlugin *ep, EABPopupTargetSource *target)
GList *contacts, *tmp;
ESource *primary_source;
gchar *uri;
+ GOutputSream *stream;
+ GError *error = NULL;
char *dest_uri = NULL;
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
char *mount = ipod_get_mount();
primary_source = e_source_selector_peek_primary_selection (target->selector);
@@ -96,50 +145,50 @@ destination_save_addressbook (EPlugin *ep, EABPopupTargetSource *target)
e_book_get_contacts (book, query, &contacts, NULL);
e_book_query_unref (query);
- result = gnome_vfs_open (&handle, dest_uri, GNOME_VFS_OPEN_WRITE);
-
- if (result != GNOME_VFS_OK) {
- if ((result = gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE,
- TRUE, GNOME_VFS_PERM_USER_ALL)) != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
- }
-
- if (result == GNOME_VFS_OK) {
- GnomeVFSFileSize bytes_written;
+ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), dest_uri, &error);
+ if (stream && !error) {
for (tmp = contacts; tmp; tmp=tmp->next) {
- EContact *contact = tmp->data;
- gchar *temp = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
- gchar *vcard;
- gchar *converted_vcard;
- gsize vcard_latin1_length;
-
- vcard = g_strconcat(temp, "\r\n", NULL);
- converted_vcard = g_convert(vcard, -1, "ISO-8859-1", "UTF-8", NULL, &vcard_latin1_length, NULL);
- if ((result = gnome_vfs_write (handle, (gconstpointer) converted_vcard, vcard_latin1_length, &bytes_written))
- != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
-
- g_object_unref (contact);
- g_free (temp);
- g_free (vcard);
- g_free (converted_vcard);
+ EContact *contact = tmp->data;
+ gchar *temp = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
+ gchar *vcard;
+ gchar *converted_vcard;
+ gsize vcard_latin1_length;
+
+ vcard = g_strconcat (temp, "\r\n", NULL);
+ converted_vcard = g_convert (vcard, -1, "ISO-8859-1", "UTF-8", NULL, &vcard_latin1_length, NULL);
+ g_output_stream_write_all (stream, converted_vcard, vcard_latin1_length, NULL, NULL, &error);
+
+ if (error) {
+ display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
+ g_error_clear (&error);
+ }
+
+ g_object_unref (contact);
+ g_free (temp);
+ g_free (vcard);
+ g_free (converted_vcard);
}
+
+ g_output_stream_close (stream);
}
+ if (stream)
+ g_object_unref (stream);
+
sync();
if (contacts != NULL)
g_list_free (contacts);
- gnome_vfs_close (handle);
g_object_unref (book);
g_free (dest_uri);
g_free (uri);
+
+ if (error) {
+ display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
+ g_error_free (error);
+ }
}
static void
diff --git a/plugins/publish-calendar/ChangeLog b/plugins/publish-calendar/ChangeLog
index 7d1a09468e..7837857825 100644
--- a/plugins/publish-calendar/ChangeLog
+++ b/plugins/publish-calendar/ChangeLog
@@ -1,3 +1,19 @@
+2008-04-17 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #526739
+
+ * publish-format-fb.h: (publish_calendar_as_fb):
+ * publish-format-fb.c: (write_calendar), (publish_calendar_as_fb):
+ * publish-format-ical.h: (publish_calendar_as_ical):
+ * publish-format-ical.c: (write_calendar), (publish_calendar_as_ical):
+ Use gio GOutputStream instead of gnome-vfs handle.
+ * url-editor-dialog.c: (create_uri): Use glib function to escape URI.
+ * publish-location.c: (migrateURI): Use EUri to parse URI.
+ * publish-calendar.c: (publish_online), (unmount_done_cb),
+ (struct mnt_struct), (mount_ready_cb), (ask_password), (ask_question),
+ (mount_first), (publish):
+ Use gio instead of gnome-vfs for opening (remote) files.
+
2007-12-14 Tobias Mueller <tobiasmue@svn.gnome.org>
Patch by <nickspoon0@gmail.com>
diff --git a/plugins/publish-calendar/publish-calendar.c b/plugins/publish-calendar/publish-calendar.c
index fd5b283c1a..29788afa39 100644
--- a/plugins/publish-calendar/publish-calendar.c
+++ b/plugins/publish-calendar/publish-calendar.c
@@ -24,7 +24,8 @@
#include <glade/glade.h>
#include <gconf/gconf-client.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
+#include <libedataserver/e-url.h>
#include <libedataserverui/e-passwords.h>
#include <calendar/gui/e-cal-popup.h>
#include <calendar/gui/e-cal-config.h>
@@ -63,15 +64,228 @@ publish_uri_async (EPublishUri *uri)
}
static void
+publish_online (EPublishUri *uri, GFile *file, GError **perror)
+{
+ GOutputStream *stream;
+ GError *error = NULL;
+
+ stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
+
+ if (!stream || error) {
+ if (stream)
+ g_object_unref (stream);
+
+ if (perror) {
+ *perror = error;
+ } else if (error) {
+ g_warning ("Couldn't open %s: %s", uri->location, error->message);
+ g_error_free (error);
+ } else {
+ g_warning ("Couldn't open %s: Unknown error", uri->location);
+ }
+ return;
+ }
+
+ switch (uri->publish_format) {
+ case URI_PUBLISH_AS_ICAL:
+ publish_calendar_as_ical (stream, uri);
+ break;
+ case URI_PUBLISH_AS_FB:
+ publish_calendar_as_fb (stream, uri);
+ break;
+ /*
+ case URI_PUBLISH_AS_HTML:
+ publish_calendar_as_html (handle, uri);
+ break;
+ */
+ }
+
+ update_timestamp (uri);
+
+ g_output_stream_close (stream, NULL, NULL);
+ g_object_unref (stream);
+}
+
+static void
+unmount_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+
+ g_mount_unmount_finish (G_MOUNT (source_object), res, &error);
+
+ if (error) {
+ g_warning ("Unmount failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (source_object);
+}
+
+struct mnt_struct {
+ EPublishUri *uri;
+ GFile *file;
+ GMountOperation *mount_op;
+};
+
+static void
+mount_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ struct mnt_struct *ms = (struct mnt_struct *) user_data;
+ GError *error = NULL;
+ GMount *mount;
+
+ g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error);
+
+ if (error) {
+ if (error->code != G_IO_ERROR_CANCELLED)
+ g_warning ("Mount of %s failed: %s", ms->uri->location, error->message);
+
+ g_error_free (error);
+ if (ms)
+ g_object_unref (ms->mount_op);
+ g_free (ms);
+
+ g_object_unref (source_object);
+
+ return;
+ }
+
+ g_return_if_fail (ms != NULL);
+
+ publish_online (ms->uri, ms->file, NULL);
+
+ g_object_unref (ms->mount_op);
+ g_free (ms);
+
+ mount = g_file_find_enclosing_mount (G_FILE (source_object), NULL, NULL);
+ if (mount)
+ g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL, unmount_done_cb, NULL);
+
+ g_object_unref (source_object);
+}
+
+static void
+ask_password (GMountOperation *op, const gchar *message, const gchar *default_user, const gchar *default_domain, GAskPasswordFlags flags, gpointer user_data)
+{
+ struct mnt_struct *ms = (struct mnt_struct *) user_data;
+ gchar *username, *password;
+ gboolean req_pass = FALSE;
+ EUri *euri;
+
+ g_return_if_fail (ms != NULL);
+
+ /* we can ask only for a password */
+ if ((flags & G_ASK_PASSWORD_NEED_PASSWORD) == 0)
+ return;
+
+ euri = e_uri_new (ms->uri->location);
+ username = euri->user;
+ password = e_passwords_get_password ("Calendar", ms->uri->location);
+ req_pass = ((username && *username) && !(ms->uri->service_type == TYPE_ANON_FTP &&
+ !strcmp (username, "anonymous"))) ? TRUE:FALSE;
+
+ if (!password && req_pass) {
+ gboolean remember = FALSE;
+
+ password = e_passwords_ask_password (_("Enter password"), "", ms->uri->location, message,
+ E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET|E_PASSWORDS_ONLINE,
+ &remember,
+ NULL);
+
+ if (!password) {
+ /* user canceled password dialog */
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
+ e_uri_free (euri);
+
+ return;
+ }
+ }
+
+ if (!req_pass)
+ g_mount_operation_set_anonymous (op, TRUE);
+ else {
+ g_mount_operation_set_anonymous (op, FALSE);
+ g_mount_operation_set_username (op, username);
+ g_mount_operation_set_password (op, password);
+ }
+
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
+
+ e_uri_free (euri);
+}
+
+static void
+ask_question (GMountOperation *op, const char *message, const char *choices[])
+{
+ /* this has been stolen from file-chooser */
+ GtkWidget *dialog;
+ int cnt, len;
+ char *primary;
+ const char *secondary = NULL;
+ int res;
+
+ primary = strstr (message, "\n");
+ if (primary) {
+ secondary = primary + 1;
+ primary = g_strndup (message, strlen (message) - strlen (primary));
+ }
+
+ gdk_threads_enter ();
+ dialog = gtk_message_dialog_new (NULL,
+ 0, GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE, "%s", primary);
+ g_free (primary);
+
+ if (secondary) {
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", secondary);
+ }
+
+ if (choices) {
+ /* First count the items in the list then
+ * add the buttons in reverse order */
+ for (len = 0; choices[len] != NULL; len++) {
+ ;
+ }
+
+ for (cnt = len - 1; cnt >= 0; cnt--) {
+ gtk_dialog_add_button (GTK_DIALOG (dialog), choices[cnt], cnt);
+ }
+ }
+
+ res = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (res >= 0) {
+ g_mount_operation_set_choice (op, res);
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
+ } else {
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ gdk_threads_leave ();
+}
+
+static void
+mount_first (EPublishUri *uri, GFile *file)
+{
+ struct mnt_struct *ms = g_malloc (sizeof (struct mnt_struct));
+
+ ms->uri = uri;
+ ms->file = g_object_ref (file);
+ ms->mount_op = g_mount_operation_new ();
+
+ g_signal_connect (ms->mount_op, "ask-password", G_CALLBACK (ask_password), ms);
+ g_signal_connect (ms->mount_op, "ask-question", G_CALLBACK (ask_question), ms);
+
+ g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, ms->mount_op, NULL, mount_ready_cb, ms);
+}
+
+static void
publish (EPublishUri *uri)
{
if (online) {
- GnomeVFSURI *vfs_uri = NULL;
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- gchar *password;
- const char *username;
- gboolean req_pass = FALSE;
+ GError *error = NULL;
+ GFile *file;
if (g_slist_find (queued_publishes, uri))
queued_publishes = g_slist_remove (queued_publishes, uri);
@@ -79,60 +293,25 @@ publish (EPublishUri *uri)
if (!uri->enabled)
return;
- vfs_uri = gnome_vfs_uri_new (uri->location);
+ file = g_file_new_for_uri (uri->location);
- password = e_passwords_get_password ("Calendar", uri->location);
- username = gnome_vfs_uri_get_user_name (vfs_uri);
- req_pass = ((username && *username) && !(uri->service_type == TYPE_ANON_FTP &&
- !strcmp (username, "anonymous"))) ? TRUE:FALSE;
+ g_return_if_fail (file != NULL);
- if (!password && req_pass) {
- gboolean remember = FALSE;
- char *prompt = g_strdup_printf (_("Enter the password for `%s'"), uri->location);
+ publish_online (uri, file, &error);
- password = e_passwords_ask_password (_("Enter password"), "", uri->location, prompt,
- E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET|E_PASSWORDS_ONLINE,
- &remember,
- NULL);
- g_free (prompt);
- }
-
- gnome_vfs_uri_set_password (vfs_uri, password);
-
- if (vfs_uri == NULL) {
- fprintf (stderr, "Couldn't create uri %s\n", uri->location);
- /* FIXME: EError */
- g_free (password);
- return;
- }
+ if (error && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_MOUNTED) {
+ g_error_free (error);
+ error = NULL;
- result = gnome_vfs_create_uri (&handle, vfs_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0666);
- if (result != GNOME_VFS_OK) {
- /* FIXME: EError */
- fprintf (stderr, "Couldn't open %s: %s\n", uri->location, gnome_vfs_result_to_string (result));
- g_free (password);
- return;
+ mount_first (uri, file);
}
- switch (uri->publish_format) {
- case URI_PUBLISH_AS_ICAL:
- publish_calendar_as_ical (handle, uri);
- break;
- case URI_PUBLISH_AS_FB:
- publish_calendar_as_fb (handle, uri);
- break;
-/*
- case URI_PUBLISH_AS_HTML:
- publish_calendar_as_html (handle, uri);
- break;
-*/
+ if (error) {
+ g_warning ("Couldn't open %s: %s", uri->location, error->message);
+ g_error_free (error);
}
- update_timestamp (uri);
-
- result = gnome_vfs_close (handle);
- gnome_vfs_uri_unref (vfs_uri);
- g_free (password);
+ g_object_unref (file);
} else {
if (g_slist_find (queued_publishes, uri) == NULL)
queued_publishes = g_slist_prepend (queued_publishes, uri);
diff --git a/plugins/publish-calendar/publish-format-fb.c b/plugins/publish-calendar/publish-format-fb.c
index 7a4eae3b65..711b68cea7 100644
--- a/plugins/publish-calendar/publish-format-fb.c
+++ b/plugins/publish-calendar/publish-format-fb.c
@@ -22,7 +22,6 @@
#include <string.h>
#include <time.h>
#include <gconf/gconf-client.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <libedataserver/e-source.h>
#include <libedataserver/e-source-list.h>
#include <libecal/e-cal.h>
@@ -32,7 +31,7 @@
#include "publish-format-fb.h"
static gboolean
-write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
+write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream)
{
ESource *source;
ECal *client = NULL;
@@ -43,6 +42,7 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
icalcomponent *top_level;
char *email = NULL;
GList *users = NULL;
+ gboolean res = FALSE;
utc = icaltimezone_get_utc_timezone ();
start = time_day_begin_with_zone (start, utc);
@@ -57,9 +57,11 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
}
if (!e_cal_open (client, TRUE, &error)) {
- /* FIXME: EError */
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
g_object_unref (client);
- g_error_free (error);
return FALSE;
}
@@ -73,8 +75,6 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
if (e_cal_get_free_busy (client, users, start, end, &objects, &error)) {
char *ical_string;
- GnomeVFSFileSize bytes_written;
- GnomeVFSResult result;
while (objects) {
ECalComponent *comp = objects->data;
@@ -84,33 +84,27 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
}
ical_string = icalcomponent_as_ical_string (top_level);
- if ((result = gnome_vfs_write (handle, (gconstpointer) ical_string, strlen (ical_string), &bytes_written)) != GNOME_VFS_OK) {
- /* FIXME: EError */
- gnome_vfs_close (handle);
- return FALSE;
- }
- } else {
- /* FIXME: EError */
- g_object_unref (client);
- g_error_free (error);
- if (users)
- g_list_free (users);
- g_free (email);
+ res = g_output_stream_write_all (stream, ical_string, strlen (ical_string), NULL, NULL, &error);
- return FALSE;
+ g_free (ical_string);
}
if (users)
g_list_free (users);
g_free (email);
-
g_object_unref (client);
- return TRUE;
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ return res;
}
void
-publish_calendar_as_fb (GnomeVFSHandle *handle, EPublishUri *uri)
+publish_calendar_as_fb (GOutputStream *stream, EPublishUri *uri)
{
GSList *l;
ESourceList *source_list;
@@ -123,7 +117,8 @@ publish_calendar_as_fb (GnomeVFSHandle *handle, EPublishUri *uri)
l = uri->events;
while (l) {
gchar *uid = l->data;
- write_calendar (uid, source_list, handle);
+ if (!write_calendar (uid, source_list, stream))
+ break;
l = g_slist_next (l);
}
g_object_unref (source_list);
diff --git a/plugins/publish-calendar/publish-format-fb.h b/plugins/publish-calendar/publish-format-fb.h
index c6af2a886e..69be11394e 100644
--- a/plugins/publish-calendar/publish-format-fb.h
+++ b/plugins/publish-calendar/publish-format-fb.h
@@ -19,12 +19,12 @@
*
*/
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
#include "publish-location.h"
#ifndef PUBLISH_FORMAT_FB_H
#define PUBLISH_FORMAT_FB_H
-void publish_calendar_as_fb (GnomeVFSHandle *handle, EPublishUri *uri);
+void publish_calendar_as_fb (GOutputStream *stream, EPublishUri *uri);
#endif
diff --git a/plugins/publish-calendar/publish-format-ical.c b/plugins/publish-calendar/publish-format-ical.c
index 5f620accc9..b1f160d98e 100644
--- a/plugins/publish-calendar/publish-format-ical.c
+++ b/plugins/publish-calendar/publish-format-ical.c
@@ -21,7 +21,6 @@
#include <string.h>
#include <gconf/gconf-client.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <libedataserver/e-source.h>
#include <libedataserver/e-source-list.h>
#include <libecal/e-cal.h>
@@ -65,13 +64,14 @@ append_tz_to_comp (gpointer key, gpointer value, icalcomponent *toplevel)
}
static gboolean
-write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
+write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream)
{
ESource *source;
ECal *client = NULL;
GError *error = NULL;
GList *objects;
icalcomponent *top_level;
+ gboolean res = FALSE;
source = e_source_list_peek_source_by_uid (source_list, uid);
if (source)
@@ -82,9 +82,11 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
}
if (!e_cal_open (client, TRUE, &error)) {
- /* FIXME: EError */
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
g_object_unref (client);
- g_error_free (error);
return FALSE;
}
@@ -93,8 +95,6 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
if (e_cal_get_object_list (client, "#t", &objects, &error)) {
char *ical_string;
- GnomeVFSFileSize bytes_written = 0;
- GnomeVFSResult result;
CompTzData tdata;
tdata.zones = g_hash_table_new (g_str_hash, g_str_equal);
@@ -113,24 +113,22 @@ write_calendar (gchar *uid, ESourceList *source_list, GnomeVFSHandle *handle)
tdata.zones = NULL;
ical_string = icalcomponent_as_ical_string (top_level);
- if ((result = gnome_vfs_write (handle, (gconstpointer) ical_string, strlen (ical_string), &bytes_written)) != GNOME_VFS_OK) {
- /* FIXME: EError */
- gnome_vfs_close (handle);
- return FALSE;
- }
- } else {
- /* FIXME: EError */
- g_object_unref (client);
- g_error_free (error);
- return FALSE;
+ res = g_output_stream_write_all (stream, ical_string, strlen (ical_string), NULL, NULL, &error);
+ g_free (ical_string);
}
g_object_unref (client);
- return TRUE;
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ return res;
}
void
-publish_calendar_as_ical (GnomeVFSHandle *handle, EPublishUri *uri)
+publish_calendar_as_ical (GOutputStream *stream, EPublishUri *uri)
{
GSList *l;
ESourceList *source_list;
@@ -143,7 +141,8 @@ publish_calendar_as_ical (GnomeVFSHandle *handle, EPublishUri *uri)
l = uri->events;
while (l) {
gchar *uid = l->data;
- write_calendar (uid, source_list, handle);
+ if (!write_calendar (uid, source_list, stream))
+ break;
l = g_slist_next (l);
}
g_object_unref (source_list);
diff --git a/plugins/publish-calendar/publish-format-ical.h b/plugins/publish-calendar/publish-format-ical.h
index 35040d110a..ae76bc076f 100644
--- a/plugins/publish-calendar/publish-format-ical.h
+++ b/plugins/publish-calendar/publish-format-ical.h
@@ -19,12 +19,12 @@
*
*/
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
#include "publish-location.h"
#ifndef PUBLISH_FORMAT_ICAL_H
#define PUBLISH_FORMAT_ICAL_H
-void publish_calendar_as_ical (GnomeVFSHandle *handle, EPublishUri *uri);
+void publish_calendar_as_ical (GOutputStream *stream, EPublishUri *uri);
#endif
diff --git a/plugins/publish-calendar/publish-location.c b/plugins/publish-calendar/publish-location.c
index e4414a8109..34793bf932 100644
--- a/plugins/publish-calendar/publish-location.c
+++ b/plugins/publish-calendar/publish-location.c
@@ -24,7 +24,7 @@
#include "publish-location.h"
#include <libxml/tree.h>
#include <gconf/gconf-client.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <libedataserver/e-url.h>
#include <libedataserverui/e-passwords.h>
#include <string.h>
@@ -36,8 +36,8 @@ migrateURI (const gchar *xml, xmlDocPtr doc)
xmlChar *location, *enabled, *frequency, *username;
xmlNodePtr root, p;
EPublishUri *uri;
- GnomeVFSURI *vfs_uri;
gchar *password, *temp;
+ EUri *euri;
client = gconf_client_get_default ();
uris = gconf_client_get_list (client, "/apps/evolution/calendar/publish/uris", GCONF_VALUE_STRING, NULL);
@@ -59,18 +59,22 @@ migrateURI (const gchar *xml, xmlDocPtr doc)
frequency = xmlGetProp (root, (const unsigned char *)"frequency");
username = xmlGetProp (root, (const unsigned char *)"username");
- vfs_uri = gnome_vfs_uri_new ((char *)location);
+ euri = e_uri_new ((const char *)location);
- if (!vfs_uri) {
+ if (!euri) {
g_warning ("Could not form the uri for %s \n", location);
goto cleanup;
}
- gnome_vfs_uri_set_user_name ((GnomeVFSURI *)vfs_uri, (char *)username);
- temp = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD | GNOME_VFS_URI_HIDE_PASSWORD);
- uri->location = g_strdup_printf ("dav://%s", temp);
+ if (euri->user)
+ g_free (euri->user);
+
+ euri->user = g_strdup ((const char *)username);
+
+ temp = e_uri_to_string (euri, FALSE);
+ uri->location = g_strdup_printf ("dav://%s", strstr (temp, "//") + 2);
g_free (temp);
- gnome_vfs_uri_unref (vfs_uri);
+ e_uri_free (euri);
if (enabled != NULL)
uri->enabled = atoi ((char *)enabled);
diff --git a/plugins/publish-calendar/url-editor-dialog.c b/plugins/publish-calendar/url-editor-dialog.c
index 627c64fa87..f818cabb67 100644
--- a/plugins/publish-calendar/url-editor-dialog.c
+++ b/plugins/publish-calendar/url-editor-dialog.c
@@ -23,7 +23,7 @@
#include "url-editor-dialog.h"
#include <libedataserverui/e-passwords.h>
#include <libedataserver/e-url.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <glib.h>
#include <string.h>
#include <e-util/e-util-private.h>
@@ -46,7 +46,7 @@ create_uri (UrlEditorDialog *dialog)
server = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->server_entry)));
file = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->file_entry)));
port = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->port_entry)));
- username = gnome_vfs_escape_string (gtk_entry_get_text (GTK_ENTRY (dialog->username_entry)));
+ username = g_uri_escape_string (gtk_entry_get_text (GTK_ENTRY (dialog->username_entry)), "", FALSE);
password = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->password_entry)));
switch (uri->service_type) {
diff --git a/plugins/save-calendar/ChangeLog b/plugins/save-calendar/ChangeLog
index 0b6ecdaf34..3488ec9432 100644
--- a/plugins/save-calendar/ChangeLog
+++ b/plugins/save-calendar/ChangeLog
@@ -1,3 +1,14 @@
+2008-04-17 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #526739
+
+ * ical-format.c: (do_save_calendar_ical):
+ * csv-format.c: (do_save_calendar_csv):
+ * rdf-format.c: (do_save_calendar_rdf):
+ Use gio GOutpuStream instead of gnome-vfs handle.
+ * format-handler.h: (open_for_writing):
+ * save-calendar.c: (open_for_writing): New helper function.
+
2008-02-18 Srinivasa Ragavan <sragavan@novell.com>
* ical-format.c: (do_save_calendar_ical): Patch from OpenSUSE
diff --git a/plugins/save-calendar/csv-format.c b/plugins/save-calendar/csv-format.c
index e26b758cd4..4709b18305 100644
--- a/plugins/save-calendar/csv-format.c
+++ b/plugins/save-calendar/csv-format.c
@@ -36,7 +36,6 @@
#include <libecal/e-cal.h>
#include "calendar/common/authentication.h"
#include <calendar/gui/e-cal-popup.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
#include "e-util/e-error.h"
@@ -323,14 +322,11 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
ECal *source_client;
GError *error = NULL;
GList *objects=NULL;
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- GnomeVFSURI *uri;
+ GOutputStream *stream;
GString *line = NULL;
CsvConfig *config = NULL;
CsvPluginData *d = handler->data;
const gchar *tmp = NULL;
- gboolean doit = TRUE;
if (!dest_uri)
return;
@@ -356,22 +352,9 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
config->quote = userstring_to_systemstring (tmp?tmp:"\"");
config->header = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (d->header_check));
- uri = gnome_vfs_uri_new (dest_uri);
+ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), dest_uri, &error);
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
- if (result == GNOME_VFS_OK)
- doit = e_error_run(GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET (target->selector))),
- E_ERROR_ASK_FILE_EXISTS_OVERWRITE, dest_uri, NULL) == GTK_RESPONSE_OK;
-
- if (doit) {
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
- if (result != GNOME_VFS_OK) {
- gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
- }
- }
-
- if (result == GNOME_VFS_OK && doit && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
+ if (stream && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
if (config->header) {
@@ -406,11 +389,10 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
line = g_string_append (line, config->newline);
- gnome_vfs_write (handle, line->str, line->len, NULL);
+ g_output_stream_write_all (stream, line->str, line->len, NULL, NULL, NULL);
g_string_free (line, TRUE);
}
-
while (objects != NULL) {
ECalComponent *comp = objects->data;
gchar *delimiter_temp = NULL;
@@ -513,7 +495,7 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
* http://www.gnome.org/projects/evolution/developer-doc/libecal/ECalComponent.html
* #e-cal-component-get-last-modified
*/
- gnome_vfs_write (handle, line->str, line->len, NULL);
+ g_output_stream_write_all (stream, line->str, line->len, NULL, NULL, &error);
/* It's written, so we can free it */
g_string_free (line, TRUE);
@@ -521,9 +503,12 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
objects = g_list_next (objects);
}
- gnome_vfs_close (handle);
+ g_output_stream_close (stream, NULL, NULL);
}
+ if (stream)
+ g_object_unref (stream);
+
g_object_unref (source_client);
g_free (config->delimiter);
@@ -531,6 +516,11 @@ do_save_calendar_csv (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
g_free (config->newline);
g_free (config);
+ if (error) {
+ display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
+ g_error_free (error);
+ }
+
return;
}
diff --git a/plugins/save-calendar/format-handler.h b/plugins/save-calendar/format-handler.h
index 0dd23f6022..41b2cfb68f 100644
--- a/plugins/save-calendar/format-handler.h
+++ b/plugins/save-calendar/format-handler.h
@@ -25,6 +25,7 @@
#include <glib.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include <libedataserver/e-source.h>
#include <libedataserverui/e-source-selector.h>
#include <libecal/e-cal.h>
@@ -47,3 +48,5 @@ struct _FormatHandler
FormatHandler *csv_format_handler_new (void);
FormatHandler *ical_format_handler_new (void);
FormatHandler *rdf_format_handler_new (void);
+
+GOutputStream *open_for_writing (GtkWindow *parent, const char *uri, GError **error);
diff --git a/plugins/save-calendar/ical-format.c b/plugins/save-calendar/ical-format.c
index a5a533206d..b871657280 100644
--- a/plugins/save-calendar/ical-format.c
+++ b/plugins/save-calendar/ical-format.c
@@ -27,7 +27,6 @@
#include <glib/gi18n.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserdialog.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkstock.h>
#include <gtk/gtk.h>
@@ -37,7 +36,6 @@
#include <libecal/e-cal-util.h>
#include <calendar/gui/e-cal-popup.h>
#include <calendar/common/authentication.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
#include "format-handler.h"
@@ -96,8 +94,6 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc
GError *error = NULL;
GList *objects;
icalcomponent *top_level = NULL;
- GnomeVFSURI *uri;
- gboolean doit = TRUE;
primary_source = e_source_selector_peek_primary_selection (target->selector);
@@ -118,9 +114,8 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc
error = NULL;
if (e_cal_get_object_list (source_client, "#t", &objects, &error)) {
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
CompTzData tdata;
+ GOutputStream *stream;
tdata.zones = g_hash_table_new (g_str_hash, g_str_equal);
tdata.ecal = source_client;
@@ -141,38 +136,20 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc
tdata.zones = NULL;
/* save the file */
- uri = gnome_vfs_uri_new (dest_uri);
-
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
- if (result == GNOME_VFS_OK)
- doit = e_error_run(GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET (target->selector))),
- E_ERROR_ASK_FILE_EXISTS_OVERWRITE, dest_uri, NULL) == GTK_RESPONSE_OK;
-
- if (doit) {
- result = gnome_vfs_open (&handle, dest_uri, GNOME_VFS_OPEN_WRITE);
- if (result != GNOME_VFS_OK) {
- if ((result = gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE,
- TRUE, GNOME_VFS_PERM_USER_ALL)) != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
- }
-
- if (result == GNOME_VFS_OK) {
- char *ical_str;
- GnomeVFSFileSize bytes_written;
-
- ical_str = icalcomponent_as_ical_string (top_level);
- if ((result = gnome_vfs_write (handle, (gconstpointer) ical_str, strlen (ical_str), &bytes_written))
- != GNOME_VFS_OK) {
- display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
- gnome_vfs_result_to_string (result));
- }
-
- gnome_vfs_close (handle);
- }
+ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), dest_uri, &error);
+
+ if (stream) {
+ char *ical_str = icalcomponent_as_ical_string (top_level);
+
+ g_output_stream_write_all (stream, ical_str, strlen (ical_str), NULL, NULL, &error);
+ g_output_stream_close (stream, NULL, NULL);
+
+ g_object_unref (stream);
+ g_free (ical_str);
}
- } else {
+ }
+
+ if (error) {
display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
g_error_free (error);
}
diff --git a/plugins/save-calendar/rdf-format.c b/plugins/save-calendar/rdf-format.c
index 445dbd6cbf..6963c4bf10 100644
--- a/plugins/save-calendar/rdf-format.c
+++ b/plugins/save-calendar/rdf-format.c
@@ -33,7 +33,6 @@
#include <libedataserverui/e-source-selector.h>
#include <libecal/e-cal.h>
#include <calendar/gui/e-cal-popup.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <libecal/e-cal-time-util.h>
#include <libedataserver/e-data-server-util.h>
#include <libxml/xmlmemory.h>
@@ -196,11 +195,8 @@ do_save_calendar_rdf (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
ECal *source_client;
GError *error = NULL;
GList *objects=NULL;
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- GnomeVFSURI *uri;
gchar *temp = NULL;
- gboolean doit = TRUE;
+ GOutputStream *stream;
if (!dest_uri)
return;
@@ -216,23 +212,9 @@ do_save_calendar_rdf (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
return;
}
- uri = gnome_vfs_uri_new (dest_uri);
+ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), dest_uri, &error);
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
- if (result == GNOME_VFS_OK)
- doit = e_error_run(GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET (target->selector))),
- E_ERROR_ASK_FILE_EXISTS_OVERWRITE, dest_uri, NULL) == GTK_RESPONSE_OK;
-
- if (doit) {
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
- if (result != GNOME_VFS_OK) {
- gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
- result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
- }
- }
-
-
- if (result == GNOME_VFS_OK && doit && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
+ if (stream && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
xmlBufferPtr buffer=xmlBufferCreate();
xmlDocPtr doc = xmlNewDoc((xmlChar *) "1.0");
xmlNodePtr fnode = doc->children;
@@ -367,18 +349,26 @@ do_save_calendar_rdf (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource
objects = g_list_next (objects);
}
- /* I used a buffer rather than xmlDocDump: I want gnome-vfs support */
+ /* I used a buffer rather than xmlDocDump: I want gio support */
xmlNodeDump (buffer, doc, doc->children, 2, 1);
- gnome_vfs_write (handle, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL);
+ g_output_stream_write_all (stream, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL, NULL, &error);
+ g_output_stream_close (stream, NULL, NULL);
xmlBufferFree (buffer);
xmlFreeDoc (doc);
- gnome_vfs_close (handle);
}
+ if (stream)
+ g_object_unref (stream);
+
g_object_unref (source_client);
+ if (error) {
+ display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
+ g_error_free (error);
+ }
+
return;
}
diff --git a/plugins/save-calendar/save-calendar.c b/plugins/save-calendar/save-calendar.c
index f65dd64a5f..0ed4030b8b 100644
--- a/plugins/save-calendar/save-calendar.c
+++ b/plugins/save-calendar/save-calendar.c
@@ -28,6 +28,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserdialog.h>
#include <gtk/gtkmessagedialog.h>
@@ -37,7 +38,7 @@
#include <libedataserverui/e-source-selector.h>
#include <libecal/e-cal.h>
#include <calendar/gui/e-cal-popup.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <e-util/e-error.h>
#include <string.h>
#include "format-handler.h"
@@ -208,6 +209,54 @@ ask_destination_and_save (EPlugin *ep, ECalPopupTargetSource *target, ECalSource
}
+/* Returns output stream for the uri, or NULL on any error.
+ When done with the stream, just g_output_stream_close and g_object_unref it.
+ It will ask for overwrite if file already exists.
+*/
+GOutputStream *
+open_for_writing (GtkWindow *parent, const char *uri, GError **error)
+{
+ GFile *file;
+ GFileOutputStream *fostream;
+ GError *err = NULL;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ file = g_file_new_for_uri (uri);
+
+ g_return_val_if_fail (file != NULL, NULL);
+
+ fostream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &err);
+
+ if (err && err->code == G_IO_ERROR_EXISTS) {
+ g_clear_error (&err);
+
+ if (e_error_run (parent, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, uri, NULL) == GTK_RESPONSE_OK) {
+ fostream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
+
+ if (err && fostream) {
+ g_object_unref (fostream);
+ fostream = NULL;
+ }
+ } else if (fostream) {
+ g_object_unref (fostream);
+ fostream = NULL;
+ }
+ }
+
+ g_object_unref (file);
+
+ if (error && err)
+ *error = err;
+ else if (err)
+ g_error_free (err);
+
+ if (fostream)
+ return G_OUTPUT_STREAM (fostream);
+
+ return NULL;
+}
+
void
org_gnome_save_calendar (EPlugin *ep, ECalPopupTargetSource *target)
{