]> www.fi.muni.cz Git - evince.git/blob - shell/ev-job-xfer.c
b75e9d1c97bcca0b349bb76f6fd56a051ef4fe5e
[evince.git] / shell / ev-job-xfer.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2005 Red Hat, Inc
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24
25 #include "ev-job-xfer.h"
26 #include "ev-document-types.h"
27
28 #include <glib/gi18n.h>
29 #include <glib.h>
30
31 #include <libgnomevfs/gnome-vfs-uri.h>
32 #include <libgnomevfs/gnome-vfs-utils.h>
33 #include <libgnomevfs/gnome-vfs-ops.h>
34
35 static void ev_job_xfer_init            (EvJobXfer           *job);
36 static void ev_job_xfer_class_init      (EvJobXferClass      *class);
37
38 G_DEFINE_TYPE (EvJobXfer, ev_job_xfer, EV_TYPE_JOB)
39
40 static void ev_job_xfer_init (EvJobXfer *job) { /* Do Nothing */ }
41
42 static void
43 ev_job_xfer_dispose (GObject *object)
44 {
45         EvJobXfer *job = EV_JOB_XFER (object);
46
47         if (job->uri) {
48                 g_free (job->uri);
49                 job->uri = NULL;
50         }
51
52         if (job->error) {
53                 g_error_free (job->error);
54                 job->error = NULL;
55         }
56
57         (* G_OBJECT_CLASS (ev_job_xfer_parent_class)->dispose) (object);
58 }
59
60 static void
61 ev_job_xfer_class_init (EvJobXferClass *class)
62 {
63         GObjectClass *oclass;
64
65         oclass = G_OBJECT_CLASS (class);
66
67         oclass->dispose = ev_job_xfer_dispose;
68 }
69
70
71 EvJob *
72 ev_job_xfer_new (const gchar *uri)
73 {
74         EvJobXfer *job;
75
76         job = g_object_new (EV_TYPE_JOB_XFER, NULL);
77
78         job->uri = g_strdup (uri);
79
80         return EV_JOB (job);
81 }
82
83 void
84 ev_job_xfer_run (EvJobXfer *job)
85 {
86         GnomeVFSURI *vfs_uri;
87         char *mime_type;
88         GType document_type;
89
90         g_return_if_fail (EV_IS_JOB_XFER (job));
91         
92         if (job->error) {
93                 g_error_free (job->error);
94                 job->error = NULL;
95         }
96
97         vfs_uri = gnome_vfs_uri_new (job->uri);
98         if (vfs_uri) {
99                 if (!gnome_vfs_uri_exists (vfs_uri)) {
100                         g_set_error (&job->error,
101                                      EV_DOCUMENT_ERROR,
102                                      0,
103                                      _("The file %s does not exist."), 
104                                      job->uri);
105                         
106                         EV_JOB (job)->finished = TRUE;
107                         return;
108                 }
109         }
110         gnome_vfs_uri_unref (vfs_uri);
111
112         document_type = ev_document_type_lookup (job->uri, &mime_type);
113
114         if (document_type != G_TYPE_INVALID) {
115                 EV_JOB (job)->document = g_object_new (document_type, NULL);
116         } else {
117                 g_set_error (&job->error,
118                              EV_DOCUMENT_ERROR,
119                              0,
120                              _("Unhandled MIME type: '%s'"),
121                              mime_type ? mime_type : "<Unknown MIME Type>");                    
122                 EV_JOB (job)->finished = TRUE;
123                 return; 
124         }
125
126         EV_JOB (job)->finished = TRUE;
127         return;
128 }
129
130