1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2005 Red Hat, Inc
5 * Evince is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Evince is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #include "ev-job-xfer.h"
26 #include "ev-file-helpers.h"
27 #include "ev-document-factory.h"
29 #include <glib/gi18n.h>
32 #include <libgnomevfs/gnome-vfs-uri.h>
33 #include <libgnomevfs/gnome-vfs-utils.h>
34 #include <libgnomevfs/gnome-vfs-ops.h>
35 #include <libgnomevfs/gnome-vfs-xfer.h>
37 static void ev_job_xfer_init (EvJobXfer *job);
38 static void ev_job_xfer_class_init (EvJobXferClass *class);
40 G_DEFINE_TYPE (EvJobXfer, ev_job_xfer, EV_TYPE_JOB)
42 static void ev_job_xfer_init (EvJobXfer *job) { /* Do Nothing */ }
45 ev_job_xfer_dispose (GObject *object)
47 EvJobXfer *job = EV_JOB_XFER (object);
55 g_free (job->local_uri);
56 job->local_uri = NULL;
60 g_error_free (job->error);
64 (* G_OBJECT_CLASS (ev_job_xfer_parent_class)->dispose) (object);
68 ev_job_xfer_class_init (EvJobXferClass *class)
72 oclass = G_OBJECT_CLASS (class);
74 oclass->dispose = ev_job_xfer_dispose;
79 ev_job_xfer_new (const gchar *uri)
83 job = g_object_new (EV_TYPE_JOB_XFER, NULL);
85 job->uri = g_strdup (uri);
91 ev_job_xfer_run (EvJobXfer *job)
95 GnomeVFSURI *source_uri;
96 GnomeVFSURI *target_uri;
98 g_return_if_fail (EV_IS_JOB_XFER (job));
101 g_error_free (job->error);
105 document = ev_document_factory_get_document (job->uri, NULL, &error);
107 if (document != NULL) {
108 EV_JOB (job)->document = document;
111 EV_JOB (job)->finished = TRUE;
115 source_uri = gnome_vfs_uri_new (job->uri);
116 if (!gnome_vfs_uri_is_local (source_uri)) {
120 tmp_name = ev_tmp_filename ();
121 base_name = g_path_get_basename (job->uri);
122 job->local_uri = g_strconcat ("file:", tmp_name, base_name, NULL);
125 target_uri = gnome_vfs_uri_new (job->local_uri);
127 gnome_vfs_xfer_uri (source_uri, target_uri,
128 GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
129 GNOME_VFS_XFER_ERROR_MODE_ABORT,
130 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
133 gnome_vfs_uri_unref (target_uri);
135 gnome_vfs_uri_unref (source_uri);
137 EV_JOB (job)->finished = TRUE;