aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2008-04-18 00:59:08 +0800
committerMilan Crha <mcrha@src.gnome.org>2008-04-18 00:59:08 +0800
commite9a0cfe1a901f41456575a2cd07158f1947b873c (patch)
treeafaedd4dd4c72cbf773142e592324d83bd05b950 /e-util
parentb24bdfcc8d3e43499f1e81351f69ac667cedd08a (diff)
downloadgsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar.gz
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar.bz2
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar.lz
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar.xz
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.tar.zst
gsoc2013-evolution-e9a0cfe1a901f41456575a2cd07158f1947b873c.zip
** Fix for bug #526741 (gnome-vfs to gio/gvfs port)
2008-04-17 Milan Crha <mcrha@redhat.com> ** Fix for bug #526741 (gnome-vfs to gio/gvfs port) * configure.in: Drop dependency on gnome-vfs, depend on gio instead. * addressbook/gui/contact-editor/e-contact-editor.c: Do not include gnome-vfs. * calendar/gui/e-meeting-store.c: (start_async_read), (freebusy_async), (async_read): Read data with gio, not with gnome-vfs. * calendar/gui/e-meeting-store.c: (async_close): Function removed. * calendar/gui/migration.c: * calendar/gui/e-memos.c: * calendar/gui/alarm-notify/notify-main.c: * calendar/gui/e-tasks.c: * calendar/gui/main.c: * calendar/gui/e-meeting-list-view.c: Do not include gnome-vfs. * calendar/gui/dialogs/comp-editor.c: (set_attachment_list): * calendar/gui/dialogs/comp-editor.c: (attachment_guess_mime_type): Function removed, use e-util function instead. * calendar/gui/e-cal-popup.c: (temp_save_part): Reflect changes in CamelStreamVFS. * calendar/gui/e-cal-popup.c: (ecalp_apps_open_in), (ecalp_apps_popup_free), (ecalp_standard_menu_factory): Use gio to fill popup and launch app. * calendar/gui/e-cal-component-preview.h: (e_cal_comp_preview_url_requested_cb): * calendar/gui/e-cal-component-preview.c: (e_cal_comp_preview_url_requested_cb): New helper function to manage file:// urls for GtkHTML component. * calendar/gui/e-cal-component-preview.c: (e_cal_component_preview_init): * calendar/gui/e-cal-component-memo-preview.c: (e_cal_comp_preview_url_requested_cb): Use above helper function. * calendar/gui/e-cal-component-memo-preview.c: (url_requested_cb): * calendar/gui/e-cal-component-preview.c: (url_requested_cb): Function removed. * composer/e-msg-composer.h: (e_msg_composer_guess_mime_type): * composer/e-msg-composer.c: (e_msg_composer_guess_mime_type), (handle_uri), (e_msg_composer_add_inline_image_from_file): Use shared e_util_guess_mime_type instead of its own. * e-util/e-gui-utils.c: Do not include gnome-vfs. * e-util/e-util.c: (e_write_file_uri), (e_file_get_save_path): * e-util/e-dialog-utils.c: (e_file_can_save), (e_file_check_local): Use gio instead of gnome-vfs. * e-util/e-util.h: * e-util/e-util.c: (e_util_guess_mime_type), (e_util_filename_to_uri), (e_util_uri_to_filename), (e_util_read_file): New helper functions. * mail/Makefile.am: * mail/em-vfs-stream.h: * mail/em-vfs-stream.c: Removed from project, not used anywhere. * mail/em-menu.c: * mail/em-config.c: Do not include gnome-vfs. * mail/mail-ops.c: (save_messages_exec), (save_part_exec): Changes related to Data Server change of CamelStreamVFS. * mail/em-format.c: (em_format_describe_part): * mail/em-format-html-display.c: (efhd_bonobo_object), (efhd_find_handler), (efhd_use_component), (efhd_bonobo_unknown), (efhd_check_server_prop), (efhd_format_attachment): Drop use of deprecated gnome-vfs functions. * mail/em-utils.c: (em_utils_snoop_type): Use gio to guess the mime_type. * mail/em-popup.c: (emp_apps_open_in), (emp_apps_popup_free), (emp_standard_menu_factory): Use gio to fill popup and launch app. * plugins/import-ics-attachments/icsimporter.c: Do not include gnome-vfs. * plugins/ipod-sync/ical-format.c: (do_save_calendar_ical): * plugins/ipod-sync/ipod-sync.c: (destination_save_addressbook): Write to gio GOutputStream instead of gnome-vfs handle. * plugins/ipod-sync/format-handler.h: (open_for_writing): * plugins/ipod-sync/ipod-sync.c: (open_for_writing): New helper function. * plugins/publish-calendar/publish-format-fb.h: (publish_calendar_as_fb): * plugins/publish-calendar/publish-format-fb.c: (write_calendar), (publish_calendar_as_fb): * plugins/publish-calendar/publish-format-ical.h: (publish_calendar_as_ical): * plugins/publish-calendar/publish-format-ical.c: (write_calendar), (publish_calendar_as_ical): Use gio GOutputStream instead of gnome-vfs handle. * plugins/publish-calendar/url-editor-dialog.c: (create_uri): Use glib function to escape URI. * plugins/publish-calendar/publish-location.c: (migrateURI): Use EUri to parse URI. * plugins/publish-calendar/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. * plugins/save-calendar/ical-format.c: (do_save_calendar_ical): * plugins/save-calendar/csv-format.c: (do_save_calendar_csv): * plugins/save-calendar/rdf-format.c: (do_save_calendar_rdf): Use gio GOutpuStream instead of gnome-vfs handle. * plugins/save-calendar/format-handler.h: (open_for_writing): * plugins/save-calendar/save-calendar.c: (open_for_writing): New helper function. * shell/e-shell-window-commands.c: (command_quick_reference): Use gio instead of gnome-vfs. * widgets/misc/e-attachment.h: (struct _EAttachment): * widgets/misc/e-attachment.c: (finalise), (init), (attachment_guess_mime_type), (e_attachment_new), (struct DownloadInfo), (download_info_free), (data_ready_cb), (download_to_local_path), (e_attachment_new_remote_file): Use gio instead of gnome-vfs to download remote files. * widgets/misc/e-image-chooser.c: (image_drag_data_received_cb): Use new util function to read file. * widgets/misc/e-attachment-bar.c: (size_to_string): Stolen from gnome-vfs. svn path=/trunk/; revision=35378
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog12
-rw-r--r--e-util/e-dialog-utils.c6
-rw-r--r--e-util/e-gui-utils.c1
-rw-r--r--e-util/e-util.c233
-rw-r--r--e-util/e-util.h6
5 files changed, 240 insertions, 18 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 5291429431..8df4256595 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,15 @@
+2008-04-17 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #526739
+
+ * e-gui-utils.c: Do not include gnome-vfs.
+ * e-util.c: (e_write_file_uri), (e_file_get_save_path):
+ * e-dialog-utils.c: (e_file_can_save), (e_file_check_local):
+ Use gio instead of gnome-vfs.
+ * e-util.h:
+ * e-util.c: (e_util_guess_mime_type), (e_util_filename_to_uri),
+ (e_util_uri_to_filename), (e_util_read_file): New helper functions.
+
2008-04-12 Matthew Barnes <mbarnes@redhat.com>
* e-util-labels.c (e_util_labels_add_with_dlg):
diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c
index 1c75dc83e5..8207e18181 100644
--- a/e-util/e-dialog-utils.c
+++ b/e-util/e-dialog-utils.c
@@ -49,8 +49,6 @@
#include <glib/gi18n.h>
#include <libgnome/gnome-util.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-
#include "e-util/e-util.h"
#include "e-util/e-error.h"
@@ -408,7 +406,7 @@ e_file_can_save(GtkWindow *parent, const char *uri)
if (!e_file_check_local(uri))
return TRUE;
- path = gnome_vfs_get_local_path_from_uri(uri);
+ path = e_util_uri_to_filename (uri);
if (!path)
return FALSE;
@@ -438,7 +436,7 @@ e_file_check_local (const char *name)
{
char *uri;
- uri = gnome_vfs_get_local_path_from_uri(name);
+ uri = e_util_uri_to_filename (name);
if (uri) {
g_free(uri);
return TRUE;
diff --git a/e-util/e-gui-utils.c b/e-util/e-gui-utils.c
index 5a828dedf6..4da3e6dcfe 100644
--- a/e-util/e-gui-utils.c
+++ b/e-util/e-gui-utils.c
@@ -29,7 +29,6 @@
#include <gtk/gtkicontheme.h>
#include <libgnome/gnome-program.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomeui/gnome-icon-lookup.h>
/**
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 50bd7eab70..f1bc8968c4 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -38,8 +38,8 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include <libgnome/gnome-util.h>
-#include <libgnomevfs/gnome-vfs.h>
#ifdef G_OS_WIN32
#include <windows.h>
@@ -164,29 +164,59 @@ e_int_compare (gconstpointer x, gconstpointer y)
gint
e_write_file_uri (const gchar *filename, const gchar *data)
{
- guint64 length = strlen(data);
- guint64 bytes;
- GnomeVFSResult result;
- GnomeVFSHandle *handle = NULL;
+ gsize length = strlen (data);
+ gssize bytes;
+ GFile *file;
+ GOutputStream *stream;
+ GError *error = NULL;
- result = gnome_vfs_create (&handle, filename, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
- if (result != GNOME_VFS_OK) {
+ file = g_file_new_for_path (filename);
+ if (!file) {
g_warning ("Couldn't save item");
return 1;
}
+ stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
+ g_object_unref (file);
+
+ if (!stream || error) {
+ g_warning ("Couldn't save item%s%s", error ? ": " : "", error ? error->message : "");
+
+ if (stream)
+ g_object_unref (stream);
+
+ if (error)
+ g_error_free (error);
+
+ return 1;
+ }
+
while (length > 0) {
- gnome_vfs_write(handle, data, length, &bytes);
- if (bytes > 0) {
+ bytes = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
+ if (bytes > 0 && !error) {
length -= bytes;
data += bytes;
} else {
- gnome_vfs_close(handle);
+ g_warning ("Couldn't save item%s%s", error ? ": " : "", error ? error->message : "");
+
+ if (error)
+ g_error_free (error);
+
+ g_output_stream_close (stream, NULL, NULL);
+ g_object_unref (stream);
+
return 1;
}
}
- gnome_vfs_close (handle);
+ g_output_stream_close (stream, NULL, &error);
+ g_object_unref (stream);
+
+ if (error) {
+ g_warning ("Couldn't close output stream: %s", error->message);
+ g_error_free (error);
+ }
+
return 0;
}
@@ -1042,8 +1072,16 @@ e_file_get_save_path (void)
}
g_object_unref(gconf);
- if (uri == NULL)
- uri = gnome_vfs_get_uri_from_local_path(g_get_home_dir());
+ if (uri == NULL) {
+ GFile *file;
+
+ file = g_file_new_for_path (g_get_home_dir ());
+ if (file) {
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+ }
+ }
+
return (uri);
}
@@ -1096,3 +1134,172 @@ e_file_lock_exists ()
return g_file_test (fname, G_FILE_TEST_EXISTS);
}
+
+/**
+ * e_util_guess_mime_type:
+ * @filename: it's a local file name, or URI.
+ * Returns: NULL or newly allocated string with a mime_type of the given file. Free with g_free.
+ *
+ * Guesses mime_type for the given file_name.
+ **/
+char *
+e_util_guess_mime_type (const char *filename)
+{
+ GFile *file;
+ GFileInfo *fi;
+ char *mime_type;
+
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ if (strstr (filename, "://"))
+ file = g_file_new_for_uri (filename);
+ else
+ file = g_file_new_for_path (filename);
+
+ if (!file)
+ return NULL;
+
+ fi = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ if (!fi) {
+ g_object_unref (file);
+ return NULL;
+ }
+
+ mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (fi));
+
+ g_object_unref (fi);
+ g_object_unref (file);
+
+ return mime_type;
+}
+
+/**
+ * e_util_filename_to_uri:
+ * @filename: local file name.
+ * Returns: either newly allocated string or NULL. Free with g_free.
+ *
+ * Converts local file name to URI.
+ **/
+char *
+e_util_filename_to_uri (const char *filename)
+{
+ GFile *file;
+ char *uri = NULL;
+
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ file = g_file_new_for_path (filename);
+
+ if (file) {
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+ }
+
+ return uri;
+}
+
+/**
+ * e_util_uri_to_filename:
+ * @uri: uri.
+ * Returns: either newly allocated string or NULL. Free with g_free.
+ *
+ * Converts URI to local file name. NULL indicates no such local file name exists.
+ **/
+char *
+e_util_uri_to_filename (const char *uri)
+{
+ GFile *file;
+ char *filename = NULL;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ file = g_file_new_for_uri (uri);
+
+ if (file) {
+ filename = g_file_get_path (file);
+ g_object_unref (file);
+ }
+
+ return filename;
+}
+
+/**
+ * e_util_read_file:
+ * @filename: File name to read.
+ * @filename_is_uri: Whether the file name is URI, if not, then it's a local path.
+ * @buffer: Read content or the file. Should not be NULL. Returned value should be freed with g_free.
+ * @read: Number of actually read bytes. Should not be NULL.
+ * @error: Here will be returned an error from reading operations. Can be NULL. Not every time is set when returned FALSE.
+ * Returns: Whether was reading successful or not.
+ *
+ * Reads synchronously content of the file, to which is pointed either by path or by URI.
+ * Mount point should be already mounted when calling this function.
+ **/
+gboolean
+e_util_read_file (const char *filename, gboolean filename_is_uri, char **buffer, gsize *read, GError **error)
+{
+ GFile *file;
+ GFileInfo *info;
+ GError *err = NULL;
+ gboolean res = FALSE;
+
+ g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (buffer != NULL, FALSE);
+ g_return_val_if_fail (read != NULL, FALSE);
+
+ *buffer = NULL;
+ *read = 0;
+
+ if (filename_is_uri)
+ file = g_file_new_for_uri (filename);
+ else
+ file = g_file_new_for_path (filename);
+
+ g_return_val_if_fail (file != NULL, FALSE);
+
+ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
+
+ if (!err && info) {
+ guint64 sz;
+ char *buff;
+
+ sz = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
+ buff = g_malloc (sizeof (char) * sz);
+
+ if (buff) {
+ GInputStream *stream;
+
+ stream = G_INPUT_STREAM (g_file_read (file, NULL, &err));
+
+ if (!err && stream) {
+ res = g_input_stream_read_all (stream, buff, sz, read, NULL, &err);
+
+ if (err)
+ res = FALSE;
+
+ if (res)
+ *buffer = buff;
+ else
+ g_free (buff);
+ }
+
+ if (stream)
+ g_object_unref (stream);
+ }
+ }
+
+ if (info)
+ g_object_unref (info);
+
+ g_object_unref (file);
+
+ if (err) {
+ if (error)
+ *error = err;
+ else
+ g_error_free (err);
+ }
+
+ return res;
+}
+
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 15003d7226..0f76e9e29e 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -117,6 +117,12 @@ gboolean e_file_lock_create (void);
void e_file_lock_destroy (void);
gboolean e_file_lock_exists (void);
+char *e_util_guess_mime_type (const char *filename);
+char *e_util_filename_to_uri (const char *filename);
+char *e_util_uri_to_filename (const char *uri);
+
+gboolean e_util_read_file (const char *filename, gboolean filename_is_uri, char **buffer, gsize *read, GError **error);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */