]> www.fi.muni.cz Git - evince.git/blobdiff - backend/ev-attachment.c
Make pdf compilation optional. See bug #38007.
[evince.git] / backend / ev-attachment.c
index 9d5aaffbe398d9b150d7f079a0a674df8c835a4e..7e7ca127ea0b35483179d555e11253c852db3b9e 100644 (file)
@@ -22,6 +22,7 @@
 #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"
 
 enum
@@ -293,14 +294,13 @@ ev_attachment_save (EvAttachment *attachment,
        g_return_val_if_fail (uri != NULL, FALSE);
 
        result = gnome_vfs_create (&handle, uri,
-                                  GNOME_VFS_OPEN_WRITE |
-                                  GNOME_VFS_OPEN_TRUNCATE,
+                                  GNOME_VFS_OPEN_WRITE,
                                   FALSE, 0644);
        if (result != GNOME_VFS_OK) {
                g_set_error (error,
                             EV_ATTACHMENT_ERROR, 
                             (gint) result,
-                            _("Couldn't save attachment '%s': %s"),
+                            _("Couldn't save attachment “%s”: %s"),
                             uri, 
                             gnome_vfs_result_to_string (result));
                
@@ -313,7 +313,7 @@ ev_attachment_save (EvAttachment *attachment,
                g_set_error (error,
                             EV_ATTACHMENT_ERROR,
                             (gint) result,
-                            _("Couldn't save attachment '%s': %s"),
+                            _("Couldn't save attachment “%s”: %s"),
                             uri,
                             gnome_vfs_result_to_string (result));
                
@@ -345,7 +345,7 @@ ev_attachment_launch_app (EvAttachment *attachment,
                g_set_error (error,
                             EV_ATTACHMENT_ERROR,
                             (gint) result,
-                            _("Couldn't open attachment '%s': %s"),
+                            _("Couldn't open attachment “%s”: %s"),
                             attachment->priv->name,
                             gnome_vfs_result_to_string (result));
 
@@ -364,11 +364,25 @@ ev_attachment_open (EvAttachment *attachment,
                    GError      **error)
 {
 
-       gboolean retval = FALSE;
+       gboolean                 retval = FALSE;
+       GnomeVFSMimeApplication *default_app = NULL;
 
-       if (!attachment->priv->app)
-               attachment->priv->app =
-                       gnome_vfs_mime_get_default_application (attachment->priv->mime_type);
+       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;
+       }
+
+       if (!attachment->priv->app) {
+               g_set_error (error,
+                            EV_ATTACHMENT_ERROR,
+                            0,
+                            _("Couldn't open attachment “%s”"),
+                            attachment->priv->name);
+               
+               return FALSE;
+       }
 
        if (attachment->priv->tmp_uri &&
            g_file_test (attachment->priv->tmp_uri, G_FILE_TEST_EXISTS)) {
@@ -376,7 +390,7 @@ ev_attachment_open (EvAttachment *attachment,
        } else {
                gchar *uri, *filename;
                
-               filename = g_build_filename (g_get_tmp_dir (), attachment->priv->name, NULL);
+               filename = g_build_filename (ev_tmp_dir (), attachment->priv->name, NULL);
                uri = g_filename_to_uri (filename, NULL, NULL);
 
                if (ev_attachment_save (attachment, uri, error)) {