+2008-01-25 Carlos Garcia Campos <carlosgc@gnome.org>
+
+ * configure.ac:
+ * backend/comics/comics-document.c: (comics_document_load):
+ * libdocument/ev-attachment.[ch]: (ev_attachment_finalize),
+ (ev_attachment_set_property), (ev_attachment_init),
+ (ev_attachment_save), (ev_attachment_launch_app),
+ (ev_attachment_open):
+ * libdocument/ev-document-factory.c: (get_document_from_uri):
+ * libdocument/ev-file-helpers.[ch]: (ev_tmp_file_get),
+ (ev_tmp_file_unlink), (ev_tmp_uri_unlink), (ev_xfer_uri_simple),:
+ * shell/ev-jobs.c:
+ * shell/ev-password.c: (ev_password_dialog_set_property),
+ (ev_password_dialog_save_password):
+ * shell/ev-sidebar-attachments.c:
+ (ev_sidebar_attachments_drag_data_get):
+ * shell/ev-window-title.c: (get_filename_from_uri):
+ * shell/ev-window.c: (ev_window_clear_temp_file),
+ (ev_window_load_job_cb), (window_open_file_copy_ready_cb),
+ (ev_window_open_uri), (window_save_file_copy_ready_cb),
+ (ev_window_save_remote), (ev_window_cmd_save_as), (launch_action),
+ (launch_external_uri), (image_save_dialog_response_cb),
+ (attachment_save_dialog_response_cb):
+ * shell/main.c: (load_files), (load_files_remote), (main):
+ * thumbnailer/evince-thumbnailer.c: (main):
+
+ Port to gio and drop gnome-vfs dependency. Fixes bug
+ #510401. Based on patch by Cosimo Cecchi.
+
2008-01-24 Wouter Bolsterlee <wbolster@svn.gnome.org>
* NEWS:
#include <unistd.h>
#include <string.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
+#include <gio/gio.h>
#include "comics-document.h"
#include "ev-document-misc.h"
{
ComicsDocument *comics_document = COMICS_DOCUMENT (document);
GSList *supported_extensions;
- gchar *list_files_command = NULL, *std_out, *quoted_file, *mime_type;
+ GFile *file;
+ GFileInfo *file_info;
+ gchar *list_files_command = NULL, *std_out, *quoted_file;
+ const gchar *mime_type = NULL;
gchar **cbr_files;
gboolean success;
int i, retval;
g_return_val_if_fail (comics_document->archive != NULL, FALSE);
quoted_file = g_shell_quote (comics_document->archive);
- mime_type = gnome_vfs_get_mime_type (uri);
+ file = g_file_new_for_uri (uri);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ if (file_info != NULL) {
+ mime_type = g_file_info_get_content_type (file_info);
+ }
+ g_object_unref (file);
/* FIXME, use proper cbr/cbz mime types once they're
* included in shared-mime-info */
comics_document->regex_arg = TRUE;
}
+ g_object_unref (file_info);
g_free (quoted_file);
/* Get list of files in archive */
g_free (list_files_command);
if (!success) {
- g_free (mime_type);
return FALSE;
} else if (retval != 0) {
g_set_error (error,
EV_DOCUMENT_ERROR,
EV_DOCUMENT_ERROR_INVALID,
_("File corrupted."));
- g_free (mime_type);
return FALSE;
}
}
g_free (std_out);
- g_free (mime_type);
g_strfreev (cbr_files);
g_slist_foreach (supported_extensions, (GFunc) g_free, NULL);
g_slist_free (supported_extensions);
DBUS_GLIB_REQUIRED=0.70
GTK_REQUIRED=2.10.0
+GLIB_REQUIRED=2.15.4
KEYRING_REQUIRED=0.4.0
LIBGNOMEUI_REQUIRED=2.14.0
GTK_PRINT_REQUIRED=2.10.0
-PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED gnome-vfs-2.0)
+PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED gio-2.0 >= $GLIB_REQUIRED)
PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED)
-PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED libglade-2.0 gnome-vfs-2.0)
-PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gnome-vfs-2.0 libglade-2.0 gconf-2.0)
+PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED libglade-2.0 gio-2.0 >= $GLIB_REQUIRED)
+PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gio-2.0 >= $GLIB_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED libglade-2.0 gconf-2.0)
BACKEND_LIBTOOL_FLAGS="-module -avoid-version"
AC_SUBST(BACKEND_LIBTOOL_FLAGS)
#include <config.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include "ev-file-helpers.h"
#include "ev-attachment.h"
gchar *data;
gchar *mime_type;
- GnomeVFSMimeApplication *app;
- gchar *tmp_uri;
+ GAppInfo *app;
+ GFile *tmp_file;
};
#define EV_ATTACHMENT_GET_PRIVATE(object) \
}
if (attachment->priv->app) {
- gnome_vfs_mime_application_free (attachment->priv->app);
+ g_object_unref (attachment->priv->app);
attachment->priv->app = NULL;
}
- if (attachment->priv->tmp_uri) {
- ev_tmp_filename_unlink (attachment->priv->tmp_uri);
- g_free (attachment->priv->tmp_uri);
- attachment->priv->tmp_uri = NULL;
+ if (attachment->priv->tmp_file) {
+ ev_tmp_file_unlink (attachment->priv->tmp_file);
+ g_object_unref (attachment->priv->tmp_file);
+ attachment->priv->tmp_file = NULL;
}
(* G_OBJECT_CLASS (ev_attachment_parent_class)->finalize) (object);
break;
case PROP_DATA:
attachment->priv->data = g_value_get_pointer (value);
- attachment->priv->mime_type =
- g_strdup (gnome_vfs_get_mime_type_for_data (attachment->priv->data,
- attachment->priv->size));
+ attachment->priv->mime_type = g_content_type_guess (attachment->priv->name,
+ (guchar *) attachment->priv->data,
+ attachment->priv->size,
+ NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
attachment->priv->data = NULL;
attachment->priv->mime_type = NULL;
- attachment->priv->tmp_uri = NULL;
+ attachment->priv->tmp_file = NULL;
}
EvAttachment *
gboolean
ev_attachment_save (EvAttachment *attachment,
- const gchar *uri,
+ GFile *file,
GError **error)
{
- GnomeVFSHandle *handle = NULL;
- GnomeVFSFileSize written;
- GnomeVFSResult result;
-
+ GFileOutputStream *output_stream;
+ GError *ioerror = NULL;
+ gssize written_bytes;
+
g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
- result = gnome_vfs_create (&handle, uri,
- GNOME_VFS_OPEN_WRITE,
- FALSE, 0644);
- if (result != GNOME_VFS_OK) {
+ output_stream = g_file_create (file, 0, NULL, &ioerror);
+ if (output_stream == NULL) {
+ char *uri;
+
+ uri = g_file_get_uri (file);
g_set_error (error,
EV_ATTACHMENT_ERROR,
- (gint) result,
+ ioerror->code,
_("Couldn't save attachment “%s”: %s"),
uri,
- gnome_vfs_result_to_string (result));
+ ioerror->message);
+
+ g_error_free (ioerror);
+ g_free (uri);
return FALSE;
}
-
- result = gnome_vfs_write (handle, attachment->priv->data,
- attachment->priv->size, &written);
- if (result != GNOME_VFS_OK || written < attachment->priv->size){
+
+ written_bytes = g_output_stream_write (G_OUTPUT_STREAM (output_stream),
+ attachment->priv->data,
+ attachment->priv->size,
+ NULL, &ioerror);
+ if (written_bytes == -1) {
+ char *uri;
+
+ uri = g_file_get_uri (file);
g_set_error (error,
EV_ATTACHMENT_ERROR,
- (gint) result,
+ ioerror->code,
_("Couldn't save attachment “%s”: %s"),
uri,
- gnome_vfs_result_to_string (result));
+ ioerror->message);
- gnome_vfs_close (handle);
+ g_output_stream_close (G_OUTPUT_STREAM (output_stream), NULL, NULL);
+ g_error_free (ioerror);
+ g_free (uri);
return FALSE;
}
- gnome_vfs_close (handle);
+ g_output_stream_close (G_OUTPUT_STREAM (output_stream), NULL, NULL);
return TRUE;
+
}
static gboolean
ev_attachment_launch_app (EvAttachment *attachment,
GError **error)
{
- GnomeVFSResult result;
- GList *uris = NULL;
+ gboolean result;
+ GList *files = NULL;
+ GError *ioerror = NULL;
- g_assert (attachment->priv->tmp_uri != NULL);
- g_assert (attachment->priv->app != NULL);
+ g_assert (G_IS_FILE (attachment->priv->tmp_file));
+ g_assert (G_IS_APP_INFO (attachment->priv->app));
- uris = g_list_prepend (uris, attachment->priv->tmp_uri);
- result = gnome_vfs_mime_application_launch (attachment->priv->app,
- uris);
+ files = g_list_prepend (files, attachment->priv->tmp_file);
+ result = g_app_info_launch (attachment->priv->app, files,
+ NULL, &ioerror);
- if (result != GNOME_VFS_OK) {
+ if (!result) {
g_set_error (error,
EV_ATTACHMENT_ERROR,
(gint) result,
_("Couldn't open attachment “%s”: %s"),
attachment->priv->name,
- gnome_vfs_result_to_string (result));
+ ioerror->message);
- g_list_free (uris);
+ g_list_free (files);
+ g_error_free (ioerror);
return FALSE;
}
- g_list_free (uris);
+ g_list_free (files);
return TRUE;
}
ev_attachment_open (EvAttachment *attachment,
GError **error)
{
-
- gboolean retval = FALSE;
- GnomeVFSMimeApplication *default_app = NULL;
+ GAppInfo *app_info;
+ gboolean retval = FALSE;
g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE);
if (!attachment->priv->app) {
- default_app = gnome_vfs_mime_get_default_application (attachment->priv->mime_type);
- attachment->priv->app = default_app;
+ app_info = g_app_info_get_default_for_type (attachment->priv->mime_type, TRUE);
+ attachment->priv->app = app_info;
}
if (!attachment->priv->app) {
return FALSE;
}
- if (attachment->priv->tmp_uri &&
- g_file_test (attachment->priv->tmp_uri, G_FILE_TEST_EXISTS)) {
+ if (attachment->priv->tmp_file &&
+ g_file_query_exists (attachment->priv->tmp_file, NULL)) {
retval = ev_attachment_launch_app (attachment, error);
} else {
- gchar *uri, *filename;
+ GFile *tmpdir;
+ GFile *file;
- filename = g_build_filename (ev_tmp_dir (), attachment->priv->name, NULL);
- uri = g_filename_to_uri (filename, NULL, NULL);
+ tmpdir = g_file_new_for_path (ev_tmp_dir ());
+ file = g_file_get_child (tmpdir, attachment->priv->name);
- if (ev_attachment_save (attachment, uri, error)) {
- if (attachment->priv->tmp_uri)
- g_free (attachment->priv->tmp_uri);
- attachment->priv->tmp_uri = g_strdup (filename);
+ if (ev_attachment_save (attachment, file, error)) {
+ if (attachment->priv->tmp_file)
+ g_object_unref (attachment->priv->tmp_file);
+ attachment->priv->tmp_file = g_object_ref (file);
retval = ev_attachment_launch_app (attachment, error);
}
- g_free (filename);
- g_free (uri);
+ g_object_unref (file);
+ g_object_unref (tmpdir);
}
return retval;
}
+
#define __EV_ATTACHMENT_H__
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
GTime ev_attachment_get_creation_date (EvAttachment *attachment);
const gchar *ev_attachment_get_mime_type (EvAttachment *attachment);
gboolean ev_attachment_save (EvAttachment *attachment,
- const gchar *uri,
+ GFile *file,
GError **error);
gboolean ev_attachment_open (EvAttachment *attachment,
GError **error);
#endif
#include <string.h>
+#include <gio/gio.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-file-info.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
#include <gtk/gtkfilechooserdialog.h>
#include "ev-backends-manager.h"
GError **error)
{
EvDocument *document = NULL;
- GnomeVFSFileInfo *info;
- GnomeVFSResult result;
+ GFile *file;
+ GFileInfo *file_info;
+ const gchar *mime_type;
*compression = EV_COMPRESSION_NONE;
- info = gnome_vfs_file_info_new ();
- result = gnome_vfs_get_file_info (uri, info,
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
- (slow ? GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE : 0));
- if (result != GNOME_VFS_OK) {
+ file = g_file_new_for_uri (uri);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ g_object_unref (file);
+
+ if (file_info == NULL) {
g_set_error (error,
EV_DOCUMENT_ERROR,
0,
- gnome_vfs_result_to_string (result));
- gnome_vfs_file_info_unref (info);
+ _("Failed to get info for document"));
return NULL;
- }
-
- if (info->mime_type == NULL) {
+ }
+ mime_type = g_file_info_get_content_type (file_info);
+
+ if (mime_type == NULL) {
g_set_error (error,
EV_DOCUMENT_ERROR,
0,
_("Unknown MIME Type"));
- gnome_vfs_file_info_unref (info);
+ g_object_unref (file_info);
return NULL;
}
#ifdef ENABLE_PIXBUF
- if (mime_type_supported_by_gdk_pixbuf (info->mime_type)) {
+ if (mime_type_supported_by_gdk_pixbuf (mime_type))
document = ev_backends_manager_get_document ("image/*");
- } else
- document = ev_backends_manager_get_document (info->mime_type);
+ else
+ document = ev_backends_manager_get_document (mime_type);
#else
- document = ev_backends_manager_get_document (info->mime_type);
+ document = ev_backends_manager_get_document (mime_type);
#endif /* ENABLE_PIXBUF */
if (document == NULL) {
g_set_error (error,
EV_DOCUMENT_ERROR,
0,
- _("Unhandled MIME type: “%s”"), info->mime_type);
- gnome_vfs_file_info_unref (info);
+ _("Unhandled MIME type: “%s”"), mime_type);
+ g_object_unref (file_info);
return NULL;
}
- *compression = get_compression_from_mime_type (info->mime_type);
+ *compression = get_compression_from_mime_type (mime_type);
- gnome_vfs_file_info_unref (info);
+ g_object_unref (file_info);
return document;
}
#include <glib.h>
#include <glib/gstdio.h>
#include <errno.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-xfer.h>
#if WITH_GNOME
#include <libgnome/gnome-init.h>
tmp_dir = NULL;
}
+GFile *
+ev_tmp_file_get (const gchar *prefix)
+{
+ gchar *path;
+ GFile *file;
+
+ path = ev_tmp_filename (prefix);
+ file = g_file_new_for_path (path);
+
+ g_free (path);
+
+ return file;
+}
+
gchar *
ev_tmp_filename (const gchar *prefix)
{
}
}
+void
+ev_tmp_file_unlink (GFile *file)
+{
+ gboolean res;
+
+ if (!file)
+ return;
+
+ res = g_file_delete (file, NULL, NULL);
+ if (!res) {
+ char *uri;
+
+ uri = g_file_get_uri (file);
+ g_warning ("Unable to delete temp file %s\n", uri);
+ g_free (uri);
+ }
+}
+
void
ev_tmp_uri_unlink (const gchar *uri)
{
- GnomeVFSURI *vfs_uri;
- gchar *filename;
+ GFile *file;
if (!uri)
return;
- vfs_uri = gnome_vfs_uri_new (uri);
- if (!gnome_vfs_uri_is_local (vfs_uri)) {
- g_warning ("Attempting to delete non local uri: %s\n", uri);
- gnome_vfs_uri_unref (vfs_uri);
+ file = g_file_new_for_uri (uri);
+ if (!g_file_is_native (file)) {
+ g_warning ("Attempting to delete non native uri: %s\n", uri);
+ g_object_unref (file);
return;
}
- gnome_vfs_uri_unref (vfs_uri);
-
- filename = g_filename_from_uri (uri, NULL, NULL);
- ev_tmp_filename_unlink (filename);
- g_free (filename);
+
+ ev_tmp_file_unlink (file);
+ g_object_unref (file);
}
gboolean
const char *to,
GError **error)
{
- GnomeVFSResult result;
- GnomeVFSURI *source_uri;
- GnomeVFSURI *target_uri;
+ GFile *source_file;
+ GFile *target_file;
+ GError *ioerror;
+ gboolean result;
if (!from)
return FALSE;
- source_uri = gnome_vfs_uri_new (from);
- target_uri = gnome_vfs_uri_new (to);
-
- result = gnome_vfs_xfer_uri (source_uri, target_uri,
- GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- NULL,
- NULL);
- gnome_vfs_uri_unref (target_uri);
- gnome_vfs_uri_unref (source_uri);
+ source_file = g_file_new_for_uri (from);
+ target_file = g_file_new_for_uri (to);
+
+ result = g_file_copy (source_file, target_file,
+ G_FILE_COPY_OVERWRITE,
+ NULL, NULL, NULL, &ioerror);
+
+ g_object_unref (target_file);
+ g_object_unref (source_file);
- if (result != GNOME_VFS_OK)
- g_set_error (error,
- G_FILE_ERROR,
- G_FILE_ERROR_FAILED,
- gnome_vfs_result_to_string (result));
- return (result == GNOME_VFS_OK);
+ if (!result) {
+ g_propagate_error (error, ioerror);
+ }
+ return result;
}
* $Id$
*/
-#ifndef EPHY_FILE_HELPERS_H
-#define EPHY_FILE_HELPERS_H
+#ifndef EV_FILE_HELPERS_H
+#define EV_FILE_HELPERS_H
#include <glib.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
void ev_file_helpers_shutdown (void);
+GFile *ev_tmp_file_get (const gchar *prefix);
gchar *ev_tmp_filename (const char *prefix);
void ev_tmp_filename_unlink (const gchar *filename);
+void ev_tmp_file_unlink (GFile *file);
void ev_tmp_uri_unlink (const gchar *uri);
gboolean ev_xfer_uri_simple (const char *from,
G_END_DECLS
-#endif /* EPHY_FILE_HELPERS_H */
+#endif /* EV_FILE_HELPERS_H */
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <unistd.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
static void ev_job_init (EvJob *job);
static void ev_job_class_init (EvJobClass *class);
#endif
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
#ifdef WITH_KEYRING
#include <gnome-keyring.h>
char *format;
char *markup;
char *base_name;
- char *file_name;
+ GFile *file;
- switch (prop_id)
- {
+ switch (prop_id) {
case PROP_URI:
dialog->priv->uri = g_strdup (g_value_get_string (value));
+
+ file = g_file_new_for_uri (dialog->priv->uri);
- file_name = gnome_vfs_format_uri_for_display (dialog->priv->uri);
- base_name = g_path_get_basename (file_name);
+ base_name = g_file_get_basename (file);
format = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Password required"),
_("The document “%s” is locked and requires a password before it can be opened."));
gtk_label_set_markup (GTK_LABEL (dialog->priv->label), markup);
g_free (base_name);
- g_free (file_name);
g_free (format);
g_free (markup);
+ g_object_unref (file);
ev_password_search_in_keyring (dialog, dialog->priv->uri);
break;
attribute.value.string = g_strdup (dialog->priv->uri);
g_array_append_val (attributes, attribute);
- unescaped_uri = gnome_vfs_unescape_string_for_display (dialog->priv->uri);
+ unescaped_uri = g_uri_unescape_string (dialog->priv->uri, NULL);
name = g_strdup_printf (_("Password for document %s"), unescaped_uri);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->check_default))) {
EvAttachment *attachment;
GtkTreePath *path;
GtkTreeIter iter;
- gchar *uri, *filename;
+ GFile *file;
+ gchar *filename;
GError *error = NULL;
path = (GtkTreePath *) l->data;
filename = g_build_filename (ev_tmp_dir (),
ev_attachment_get_name (attachment),
NULL);
+ file = g_file_new_for_path (filename);
+ g_free (filename);
- uri = g_filename_to_uri (filename, NULL, NULL);
+ if (ev_attachment_save (attachment, file, &error)) {
+ gchar *uri;
- if (ev_attachment_save (attachment, filename, &error)) {
+ uri = g_file_get_uri (file);
g_string_append (uri_list, uri);
g_string_append_c (uri_list, '\n');
+ g_free (uri);
}
if (error) {
g_error_free (error);
}
- g_free (uri);
gtk_tree_path_free (path);
+ g_object_unref (file);
g_object_unref (attachment);
}
#include "ev-window-title.h"
#include "ev-backends-manager.h"
+#include <gio/gio.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
/* Known backends (for bad extensions fix) */
#define EV_BACKEND_PS "psdocument"
static char *
get_filename_from_uri (const char *uri)
{
+ GFile *file;
char *filename;
- char *display_name;
-
- display_name = gnome_vfs_format_uri_for_display (uri);
- filename = g_path_get_basename (display_name);
- g_free (display_name);
+
+ file = g_file_new_for_uri (uri);
+ filename = g_file_get_basename (file);
+ g_object_unref (file);
return filename;
}
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-async-ops.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
+#include <gio/gio.h>
#include <gconf/gconf-client.h>
#include <errno.h>
static void
ev_window_clear_temp_file (EvWindow *ev_window)
{
- GnomeVFSURI *uri;
- gchar *filename;
- const gchar *tempdir;
+ GFile *file, *tempdir;
if (!ev_window->priv->uri)
return;
- uri = gnome_vfs_uri_new (ev_window->priv->uri);
- if (!gnome_vfs_uri_is_local (uri)) {
- gnome_vfs_uri_unref (uri);
- return;
- }
- gnome_vfs_uri_unref (uri);
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ tempdir = g_file_new_for_path (g_get_tmp_dir ());
- filename = g_filename_from_uri (ev_window->priv->uri, NULL, NULL);
- if (!filename)
- return;
-
- tempdir = g_get_tmp_dir ();
- if (g_ascii_strncasecmp (filename, tempdir, strlen (tempdir)) == 0) {
- g_unlink (filename);
+ if (g_file_contains_file (tempdir, file)) {
+ g_file_delete (file, NULL, NULL);
}
- g_free (filename);
+ g_object_unref (file);
+ g_object_unref (tempdir);
}
/* This callback will executed when load job will be finished.
if (job->error->domain == EV_DOCUMENT_ERROR &&
job->error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
- gchar *base_name, *file_name;
+ GFile *file;
+ gchar *base_name;
setup_view_from_metadata (ev_window);
- file_name = gnome_vfs_format_uri_for_display (job->uri);
- base_name = g_path_get_basename (file_name);
+ file = g_file_new_for_uri (job->uri);
+ base_name = g_file_get_basename (file);
ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
base_name);
- g_free (file_name);
+ g_object_unref (file);
g_free (base_name);
ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
ev_window->priv->properties = NULL;
}
-static gint
-open_xfer_update_progress_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSXferProgressInfo *info,
- EvWindow *ev_window)
-{
- switch (info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
- ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
- }
-
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- case GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE:
- case GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE:
- return 1;
- default:
- g_assert_not_reached ();
- }
-
- return 0;
+static void
+window_open_file_copy_ready_cb (GFile *source,
+ GAsyncResult *async_result,
+ EvWindow *ev_window)
+{
+ g_file_copy_finish (source, async_result, NULL);
+ ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+ g_object_unref (source);
}
void
gboolean unlink_temp_file,
const gchar *print_settings)
{
- GnomeVFSURI *source_uri;
- GnomeVFSURI *target_uri;
+ GFile *source_file;
+ GFile *target_file;
if (ev_window->priv->uri &&
g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
G_CALLBACK (ev_window_load_job_cb),
ev_window);
- source_uri = gnome_vfs_uri_new (uri);
- if (!gnome_vfs_uri_is_local (source_uri) && !ev_window->priv->local_uri) {
- GnomeVFSAsyncHandle *handle;
- GList *slist = NULL;
- GList *tlist = NULL;
- char *tmp_name;
- char *base_name;
+ source_file = g_file_new_for_uri (uri);
+ if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
+ char *tmp_name;
+ char *base_name;
/* We'd like to keep extension of source uri since
* it helps to resolve some mime types, say cbz */
tmp_name = ev_tmp_filename (NULL);
- base_name = gnome_vfs_uri_extract_short_name (source_uri);
+ base_name = g_file_get_basename (source_file);
ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-", base_name, NULL);
ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
ev_window->priv->local_uri);
g_free (base_name);
g_free (tmp_name);
- target_uri = gnome_vfs_uri_new (ev_window->priv->local_uri);
-
- slist = g_list_prepend (slist, source_uri);
- tlist = g_list_prepend (tlist, target_uri);
- gnome_vfs_async_xfer (&handle, slist, tlist,
- GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- GNOME_VFS_PRIORITY_DEFAULT,
- (GnomeVFSAsyncXferProgressCallback)
- open_xfer_update_progress_callback,
- ev_window,
- NULL, NULL);
-
- g_list_free (slist);
- g_list_free (tlist);
- gnome_vfs_uri_unref (target_uri);
- gnome_vfs_uri_unref (source_uri);
-
+ target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+
+ g_file_copy_async (source_file, target_file,
+ 0, G_PRIORITY_DEFAULT, NULL,
+ NULL, NULL, /* no progress callback */
+ (GAsyncReadyCallback) window_open_file_copy_ready_cb,
+ ev_window);
+ g_object_unref (target_file);
return;
}
- gnome_vfs_uri_unref (source_uri);
+ g_object_unref (source_file);
ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
}
g_list_free (items);
}
-static gint
-save_xfer_update_progress_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSXferProgressInfo *info,
- GnomeVFSURI *tmp_uri)
-{
- switch (info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
- gchar *uri;
-
- uri = gnome_vfs_uri_to_string (tmp_uri, 0);
- ev_tmp_uri_unlink (uri);
- g_free (uri);
- gnome_vfs_uri_unref (tmp_uri);
- }
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- if (info->vfs_status != GNOME_VFS_OK) {
- GtkWidget *dialog;
- gchar *uri;
-
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("The file could not be saved as “%s”."),
- info->target_name);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- gnome_vfs_result_to_string (info->vfs_status));
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
- gtk_widget_show (dialog);
-
- uri = gnome_vfs_uri_to_string (tmp_uri, 0);
- ev_tmp_uri_unlink (uri);
- g_free (uri);
- gnome_vfs_uri_unref (tmp_uri);
- }
- return 1;
- case GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE:
- case GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE:
- return 1;
- default:
- g_assert_not_reached ();
+static void
+window_save_file_copy_ready_cb (GFile *src,
+ GAsyncResult *async_result,
+ GFile *dst)
+{
+ EvWindow *window;
+ GtkWidget *dialog;
+ gchar *name;
+ GError *error = NULL;
+
+ if (g_file_copy_finish (src, async_result, &error)) {
+ ev_tmp_file_unlink (src);
+ return;
}
- return 0;
+ window = g_object_get_data (G_OBJECT (dst), "ev-window");
+ name = g_file_get_basename (dst);
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("The file could not be saved as “%s”."),
+ name);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ error->message);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+ gtk_widget_show (dialog);
+ ev_tmp_file_unlink (src);
+
+ g_free (name);
+ g_error_free (error);
}
static void
-ev_window_save_remote (EvWindow *ev_window,
- GnomeVFSURI *src,
- GnomeVFSURI *dst)
+ev_window_save_remote (EvWindow *ev_window,
+ GFile *src,
+ GFile *dst)
{
- GnomeVFSAsyncHandle *handle;
- GList *slist = NULL;
- GList *tlist = NULL;
-
- slist = g_list_prepend (slist, src);
- tlist = g_list_prepend (tlist, dst);
- gnome_vfs_async_xfer (&handle, slist, tlist,
- GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- GNOME_VFS_PRIORITY_DEFAULT,
- (GnomeVFSAsyncXferProgressCallback)
- save_xfer_update_progress_callback,
- gnome_vfs_uri_ref (src),
- NULL, NULL);
- g_list_free (slist);
- g_list_free (tlist);
+ g_object_set_data (G_OBJECT (dst), "ev-window", ev_window);
+ g_file_copy_async (src, dst,
+ G_FILE_COPY_OVERWRITE,
+ G_PRIORITY_DEFAULT, NULL,
+ NULL, NULL, /* no progress callback */
+ (GAsyncReadyCallback) window_save_file_copy_ready_cb,
+ dst);
}
static void
{
GtkWidget *fc;
gchar *base_name;
- gchar *file_name;
+ GFile *file;
#if GLIB_CHECK_VERSION (2, 13, 3)
const gchar *folder;
#else
gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
- file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
- base_name = g_path_get_basename (file_name);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
+ file = g_file_new_for_uri (ev_window->priv->uri);
+ base_name = g_file_get_basename (file);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
#if GLIB_CHECK_VERSION (2, 13, 3)
free (folder);
#endif
- g_free (file_name);
+ g_object_unref (file);
g_free (base_name);
g_signal_connect (fc, "response",
launch_action (EvWindow *window, EvLinkAction *action)
{
const char *filename = ev_link_action_get_filename (action);
- char *uri = NULL;
+ const char *content_type;
+ GAppInfo *app_info;
+ GFileInfo *file_info;
+ GFile *file;
+ GList *file_list = NULL;
+
+ if (filename == NULL)
+ return;
- if (filename && g_path_is_absolute (filename)) {
- uri = gnome_vfs_get_uri_from_local_path (filename);
+ if (g_path_is_absolute (filename)) {
+ file = g_file_new_for_path (filename);
} else {
- GnomeVFSURI *base_uri, *resolved_uri;
-
- base_uri = gnome_vfs_uri_new (window->priv->uri);
- if (base_uri && filename) {
- resolved_uri = gnome_vfs_uri_resolve_relative (base_uri, filename);
- if (resolved_uri) {
- uri = gnome_vfs_uri_to_string (resolved_uri, GNOME_VFS_URI_HIDE_NONE);
- gnome_vfs_uri_unref (resolved_uri);
- }
- gnome_vfs_uri_unref (base_uri);
- }
+ GFile *base_file;
+
+ base_file = g_file_new_for_uri (window->priv->uri);
+ file = g_file_resolve_relative_path (base_file,
+ filename);
+
+ g_object_unref (base_file);
}
-
- if (uri) {
- gnome_vfs_url_show (uri);
- } else {
- gnome_vfs_url_show (filename);
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ if (file_info == NULL) {
+ g_object_unref (file);
+ return;
}
+
+ content_type = g_file_info_get_content_type (file_info);
+ app_info = g_app_info_get_default_for_type (content_type, TRUE);
+
+ file_list = g_list_append (file_list, file);
- g_free (uri);
+ /* FIXME: should we use a GAppLaunchContext? */
+ g_app_info_launch (app_info, file_list,
+ NULL, NULL);
+
+ g_list_free (file_list);
+ g_object_unref (app_info);
+ g_object_unref (file_info);
+ g_object_unref (file);
/* According to the PDF spec filename can be an executable. I'm not sure
allowing to launch executables is a good idea though. -- marco */
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
const gchar *uri = ev_link_action_get_uri (action);
- GnomeVFSResult result = gnome_vfs_url_show (uri);
- GtkWidget *dialog;
- gchar* message = NULL;
-
- switch(result) {
- case GNOME_VFS_OK:
- break;
- case GNOME_VFS_ERROR_BAD_PARAMETERS:
- message = _("Invalid URI: “%s”");
- break;
- case GNOME_VFS_ERROR_NOT_SUPPORTED:
- message = _("Unsupported URI: “%s”");
- break;
- default:
- message = _("Unknown error");
+ const char *content_type;
+ GFile *file;
+ GFileInfo *file_info;
+ GAppInfo *app;
+ GList *file_list = NULL;
+ GError *error = NULL;
+
+ file = g_file_new_for_uri (uri);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ if (file_info == NULL) {
+ g_object_unref (file);
+ return;
}
- if(message) {
+
+ content_type = g_file_info_get_content_type (file_info);
+ app = g_app_info_get_default_for_type (content_type, TRUE);
+ g_object_unref (file_info);
+
+ file_list = g_list_append (file_list, file);
+
+ if (!g_app_info_launch (app, file_list, NULL, &error)) {
+ GtkWidget *dialog;
+
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("Unable to open external link"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- message, uri);
+ error->message, uri);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_widget_show (dialog);
-
}
- return;
+
+ g_object_unref (app);
+ g_object_unref (file);
+ g_list_free (file_list);
}
static void
gint response_id,
EvWindow *ev_window)
{
- GnomeVFSURI *target_uri;
- gboolean is_local;
+ GFile *target_file;
+ gboolean is_native;
GError *error = NULL;
GdkPixbuf *pixbuf;
gchar *uri;
g_strfreev(extensions);
file_format = gdk_pixbuf_format_get_name (format);
- target_uri = gnome_vfs_uri_new (uri_extension);
- is_local = gnome_vfs_uri_is_local (target_uri);
+ target_file = g_file_new_for_uri (uri_extension);
+ is_native = g_file_is_native (target_file);
- if (is_local) {
- filename = g_filename_from_uri (uri_extension, NULL, NULL);
+ if (is_native) {
+ filename = g_file_get_path (target_file);
} else {
filename = ev_tmp_filename ("saveimage");
}
ev_document_doc_mutex_unlock ();
gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
+ g_free (file_format);
g_object_unref (pixbuf);
if (error) {
error);
g_error_free (error);
g_free (filename);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
return;
}
- if (!is_local) {
- GnomeVFSURI *source_uri;
- gchar *local_uri;
-
- local_uri = g_filename_to_uri (filename, NULL, NULL);
- source_uri = gnome_vfs_uri_new (local_uri);
- g_free (local_uri);
- ev_window_save_remote (ev_window, source_uri, target_uri);
- gnome_vfs_uri_unref (source_uri);
+ if (!is_native) {
+ GFile *source_file;
+
+ source_file = g_file_new_for_uri (filename);
+
+ ev_window_save_remote (ev_window, source_file, target_file);
+ g_object_unref (source_file);
}
g_free (filename);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
}
gint response_id,
EvWindow *ev_window)
{
- GnomeVFSURI *target_uri;
+ GFile *target_file;
gchar *uri;
GList *l;
GtkFileChooserAction fc_action;
gboolean is_dir;
- gboolean is_local;
+ gboolean is_native;
if (response_id != GTK_RESPONSE_OK) {
gtk_widget_destroy (fc);
}
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
- target_uri = gnome_vfs_uri_new (uri);
+ target_file = g_file_new_for_uri (uri);
g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- is_local = gnome_vfs_uri_is_local (target_uri);
+ is_native = g_file_is_native (target_file);
for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
EvAttachment *attachment;
- gchar *filename;
+ GFile *save_to;
GError *error = NULL;
attachment = (EvAttachment *) l->data;
- if (is_local) {
+ if (is_native) {
if (is_dir) {
- filename = g_strjoin ("/", uri,
- ev_attachment_get_name (attachment),
- NULL);
+ save_to = g_file_get_child (target_file,
+ ev_attachment_get_name (attachment));
} else {
- filename = g_strdup (uri);
+ save_to = g_object_ref (target_file);
}
} else {
- filename = ev_tmp_filename ("saveattachment");
+ save_to = ev_tmp_file_get ("saveattachment");
}
- ev_attachment_save (attachment, filename, &error);
+ ev_attachment_save (attachment, save_to, &error);
if (error) {
ev_window_error_message (GTK_WINDOW (ev_window),
_("The attachment could not be saved."),
error);
g_error_free (error);
- g_free (filename);
+ g_object_unref (save_to);
continue;
}
- if (!is_local) {
- GnomeVFSURI *src_uri;
- GnomeVFSURI *dest_uri;
- gchar *local_uri;
+ if (!is_native) {
+ GFile *dest_file;
if (is_dir) {
- const gchar *name = ev_attachment_get_name (attachment);
-
- dest_uri = gnome_vfs_uri_append_file_name (target_uri,
- name);
+ dest_file = g_file_get_child (target_file,
+ ev_attachment_get_name (attachment));
} else {
- dest_uri = gnome_vfs_uri_ref (target_uri);
+ dest_file = g_object_ref (target_file);
}
-
- local_uri = g_filename_to_uri (filename, NULL, NULL);
- src_uri = gnome_vfs_uri_new (local_uri);
- g_free (local_uri);
- ev_window_save_remote (ev_window, src_uri, dest_uri);
- gnome_vfs_uri_unref (src_uri);
- gnome_vfs_uri_unref (dest_uri);
+
+ ev_window_save_remote (ev_window, save_to, dest_file);
+
+ g_object_unref (dest_file);
}
- g_free (filename);
+ g_object_unref (save_to);
}
g_free (uri);
- gnome_vfs_uri_unref (target_uri);
+ g_object_unref (target_file);
gtk_widget_destroy (fc);
}
#include <libgnomeui/gnome-authentication-manager.h>
#endif
-#include <libgnomevfs/gnome-vfs-init.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-
#ifdef ENABLE_DBUS
#include <dbus/dbus-glib-bindings.h>
#endif
char *uri;
char *label;
GValue *old = NULL;
+ GFile *file;
- uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
+ file = g_file_new_for_commandline_arg (files[i]);
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
- label = strchr (uri, GNOME_VFS_URI_MAGIC_CHR);
+ label = strchr (uri, '#');
if (label) {
GValue *new;
for (i = 0; files[i]; i++) {
const char *page_label;
+ GFile *file;
char *uri;
- uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
+ file = g_file_new_for_commandline_arg (files[i]);
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+
page_label = ev_page_label ? ev_page_label : "";
if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
return 1;
}
g_option_context_free (context);
-
- gnome_vfs_init ();
accel_filename = g_build_filename (ev_dot_dir (), "accels", NULL);
gtk_accel_map_load (accel_filename);
*/
#include <config.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-init.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
#include <ev-document.h>
#include <ev-document-thumbnails.h>
#include <ev-document-factory.h>
#include <ev-backends-manager.h>
+#include <gio/gio.h>
+
#include <stdlib.h>
#include <string.h>
const char *output;
int size;
char *uri;
+ GFile *file;
if (argc <= 2 || argc > 5 || strcmp (argv[1], "-h") == 0 ||
strcmp (argv[1], "--help") == 0) {
if (!g_thread_supported ())
g_thread_init (NULL);
-
- gnome_vfs_init ();
ev_backends_manager_init ();
- uri = gnome_vfs_make_uri_from_shell_arg (input);
+ file = g_file_new_for_commandline_arg (input);
+ uri = g_file_get_uri (file);
document = evince_thumbnailer_get_document (uri);
+
+ g_object_unref (file);
g_free (uri);
if (!document) {