]> www.fi.muni.cz Git - evince.git/commitdiff
Remove temp file created when evince is used by GTK+ in preview mode.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Fri, 10 Nov 2006 17:46:18 +0000 (17:46 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Fri, 10 Nov 2006 17:46:18 +0000 (17:46 +0000)
2006-11-10  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-application.[ch]: (get_unlink_temp_file_from_args),
(ev_application_open_uri_at_dest), (ev_application_open_uri):
* shell/ev-window.[ch]: (ev_window_clear_temp_file),
(ev_window_open_uri):
* shell/main.c: (arguments_parse):
Remove temp file created when evince is used by GTK+ in
preview mode. Fixes bug #365282.

ChangeLog
shell/ev-application.c
shell/ev-application.h
shell/ev-window.c
shell/ev-window.h
shell/main.c

index 36941c7381629684beb41e42c84c21092f29393c..756dfb913da148c15cf71e0989062f72dd52d7e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-11-10  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-application.[ch]: (get_unlink_temp_file_from_args),
+       (ev_application_open_uri_at_dest), (ev_application_open_uri):
+       * shell/ev-window.[ch]: (ev_window_clear_temp_file),
+       (ev_window_open_uri):
+       * shell/main.c: (arguments_parse):
+
+       Remove temp file created when evince is used by GTK+ in
+       preview mode. Fixes bug #365282. 
+
 2006-11-10  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * shell/ev-window.c: (ev_window_sidebar_visibility_changed_cb):
index 4bbec37cd1d1348a63903a316fd317662084d590..7f912f2deae67e3e804c2b43979f73eecc6b7aa3 100644 (file)
@@ -260,6 +260,22 @@ get_destination_from_args (GHashTable *args)
        return dest;
 }
 
+static gboolean
+get_unlink_temp_file_from_args (GHashTable *args)
+{
+       gboolean unlink_temp_file = FALSE;
+       GValue  *value = NULL;
+
+       g_assert (args != NULL);
+
+       value = g_hash_table_lookup (args, "unlink-temp-file");
+       if (value) {
+               unlink_temp_file = g_value_get_boolean (value);
+       }
+       
+       return unlink_temp_file;
+}
+
 gboolean
 ev_application_open_window (EvApplication  *application,
                            GHashTable     *args,
@@ -339,6 +355,7 @@ ev_application_open_uri_at_dest (EvApplication  *application,
                                 GdkScreen      *screen,
                                 EvLinkDest     *dest,
                                 EvWindowRunMode mode,
+                                gboolean        unlink_temp_file,
                                 guint           timestamp)
 {
        EvWindow *new_window;
@@ -360,7 +377,7 @@ ev_application_open_uri_at_dest (EvApplication  *application,
 
        /* We need to load uri before showing the window, so
           we can restore window size without flickering */     
-       ev_window_open_uri (new_window, uri, dest, mode);
+       ev_window_open_uri (new_window, uri, dest, mode, unlink_temp_file);
 
        gtk_widget_show (GTK_WIDGET (new_window));
 
@@ -377,16 +394,20 @@ ev_application_open_uri (EvApplication  *application,
 {
        EvLinkDest      *dest = NULL;
        EvWindowRunMode  mode = EV_WINDOW_MODE_NORMAL;
+       gboolean         unlink_temp_file = FALSE;
        GdkScreen       *screen = NULL;
 
        if (args) {
                screen = get_screen_from_args (args);
                dest = get_destination_from_args (args);
                mode = get_window_run_mode_from_args (args);
+               unlink_temp_file = (mode == EV_WINDOW_MODE_PREVIEW &&
+                                   get_unlink_temp_file_from_args (args));
        }
        
        ev_application_open_uri_at_dest (application, uri, screen,
-                                        dest, mode, timestamp);
+                                        dest, mode, unlink_temp_file, 
+                                        timestamp);
 
        if (dest)
                g_object_unref (dest);
@@ -404,7 +425,8 @@ ev_application_open_uri_list (EvApplication *application,
 
        for (l = uri_list; l != NULL; l = l->next) {
                ev_application_open_uri_at_dest (application, (char *)l->data,
-                                                screen, NULL, 0, timestamp);
+                                                screen, NULL, 0, FALSE, 
+                                                timestamp);
        }
 }
 
index 3b43b453961d146f68ba5160bcdcbcb51a887f1b..4f3ce7e4deaac1186c7ae9f9585749a03b76c3b1 100644 (file)
@@ -86,6 +86,7 @@ void              ev_application_open_uri_at_dest    (EvApplication   *applicati
                                                      GdkScreen       *screen,
                                                      EvLinkDest      *dest,
                                                      EvWindowRunMode  mode,
+                                                     gboolean         unlink_temp_file,
                                                      guint32          timestamp);
 void             ev_application_open_uri_list       (EvApplication   *application,
                                                      GSList          *uri_list,
index efd0565300468fa3b15f847479ca65d97354e65b..184b1944147c51be4f6b1bc8e884823519e16e00 100644 (file)
@@ -80,6 +80,7 @@
 
 #include <poppler.h>
 
+#include <glib/gstdio.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gnome.h>
@@ -158,6 +159,7 @@ struct _EvWindowPrivate {
        char *uri;
        char *local_uri;
        EvLinkDest *dest;
+       gboolean unlink_temp_file;
        
        EvDocument *document;
 
@@ -976,7 +978,7 @@ ev_window_clear_local_uri (EvWindow *ev_window)
     if (ev_window->priv->local_uri) {
            filename = g_filename_from_uri (ev_window->priv->local_uri, NULL, NULL);
            if (filename != NULL) {
-                   unlink (filename);
+                   g_unlink (filename);
                    g_free (filename);
            }
            g_free (ev_window->priv->local_uri);
@@ -984,6 +986,36 @@ ev_window_clear_local_uri (EvWindow *ev_window)
     }
 }
 
+static void
+ev_window_clear_temp_file (EvWindow *ev_window)
+{
+       GnomeVFSURI *uri;
+       gchar       *filename;
+       gchar       *dir;
+
+       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);
+
+       filename = g_filename_from_uri (ev_window->priv->uri, NULL, NULL);
+       if (!filename)
+               return;
+
+       dir = g_path_get_dirname (filename);
+       if (g_ascii_strcasecmp (dir, g_get_tmp_dir ()) == 0) {
+               g_unlink (filename);
+       }
+
+       g_free (dir);
+       g_free (filename);
+}
+
 /* This callback will executed when load job will be finished.
  *
  * Since the flow of the error dialog is very confusing, we assume that both
@@ -1105,13 +1137,17 @@ void
 ev_window_open_uri (EvWindow       *ev_window,
                    const char     *uri,
                    EvLinkDest     *dest,
-                   EvWindowRunMode mode)
+                   EvWindowRunMode mode,
+                   gboolean        unlink_temp_file)
 {
        ev_window_close_dialogs (ev_window);
        ev_window_clear_xfer_job (ev_window);
        ev_window_clear_local_uri (ev_window);
        ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
 
+       ev_window->priv->unlink_temp_file =
+               (mode == EV_WINDOW_MODE_PREVIEW) ? unlink_temp_file : FALSE;
+       
        ev_window->priv->xfer_job = ev_job_xfer_new (uri, dest, mode);
        g_signal_connect (ev_window->priv->xfer_job,
                          "finished",
@@ -1195,7 +1231,7 @@ ev_window_cmd_recent_file_activate (GtkAction     *action,
        
        ev_application_open_uri_at_dest (EV_APP, uri,
                                         gtk_window_get_screen (GTK_WINDOW (window)),
-                                        NULL, 0,
+                                        NULL, 0, FALSE,
                                         GDK_CURRENT_TIME);
 }
 #else
@@ -2690,7 +2726,7 @@ ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
 
        uri = g_strdup (ev_window->priv->uri);
 
-       ev_window_open_uri (ev_window, uri, NULL, 0);
+       ev_window_open_uri (ev_window, uri, NULL, 0, FALSE);
 
        g_free (uri);
 }
@@ -3421,6 +3457,8 @@ ev_window_dispose (GObject *object)
        }
 
        if (priv->uri) {
+               if (priv->unlink_temp_file)
+                       ev_window_clear_temp_file (window);
                g_free (priv->uri);
                priv->uri = NULL;
        }
@@ -3929,6 +3967,7 @@ open_remote_link (EvWindow *window, EvLinkAction *action)
                                         gtk_window_get_screen (GTK_WINDOW (window)),
                                         ev_link_action_get_dest (action),
                                         0,
+                                        FALSE,
                                         GDK_CURRENT_TIME);
 
        g_free (uri);
index f624fe5f49a84d856b03b32956f0ea36c88f7cde..af4795a4e425e7fc0178dcf6dd63dafd0777e77f 100644 (file)
@@ -76,7 +76,8 @@ const char     *ev_window_get_uri         (EvWindow       *ev_window);
 void           ev_window_open_uri        (EvWindow       *ev_window,
                                           const char     *uri,
                                           EvLinkDest     *dest,
-                                          EvWindowRunMode mode);
+                                          EvWindowRunMode mode,
+                                          gboolean        unlink_temp_file);
 void            ev_window_goto_dest       (EvWindow       *ev_window,
                                           EvLinkDest     *dest);
 gboolean       ev_window_is_empty        (const EvWindow *ev_window);
index 56b6098a55b4caec8126c782f6f6f31534e64451..9edb1f534a381251c756796c5e4f86362e58a784 100644 (file)
@@ -47,6 +47,7 @@ static gchar   *ev_page_label;
 static gboolean preview_mode = FALSE;
 static gboolean fullscren_mode = FALSE;
 static gboolean presentation_mode = FALSE;
+static gboolean unlink_temp_file = FALSE;
 static const char **file_arguments = NULL;
 
 static const GOptionEntry goption_options[] =
@@ -55,6 +56,7 @@ static const GOptionEntry goption_options[] =
        { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscren_mode, N_("Run evince in fullscreen mode"), NULL },
        { "presentation", 's', 0, G_OPTION_ARG_NONE, &presentation_mode, N_("Run evince in presentation mode"), NULL },
        { "preview", 'w', 0, G_OPTION_ARG_NONE, &preview_mode, N_("Run evince as a previewer"), NULL },
+       { "unlink-temp-file", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &unlink_temp_file, NULL, NULL },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, N_("[FILE...]") },
        { NULL }
 };
@@ -121,6 +123,16 @@ arguments_parse (void)
 
        g_hash_table_insert (args, g_strdup ("mode"), value);
 
+       if (mode == EV_WINDOW_MODE_PREVIEW && unlink_temp_file) {
+               value = g_new0 (GValue, 1);
+               g_value_init (value, G_TYPE_BOOLEAN);
+               g_value_set_boolean (value, unlink_temp_file);
+
+               g_hash_table_insert (args,
+                                    g_strdup ("unlink-temp-file"),
+                                    value);
+       }
+
        return args;
 }