From: Carlos Garcia Campos Date: Fri, 10 Nov 2006 17:46:18 +0000 (+0000) Subject: Remove temp file created when evince is used by GTK+ in preview mode. X-Git-Tag: EVINCE_0_7_0~68 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=c7dd360a76aa50e8d46e031eee9629af466e677c;p=evince.git Remove temp file created when evince is used by GTK+ in preview mode. 2006-11-10 Carlos Garcia Campos * 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. --- diff --git a/ChangeLog b/ChangeLog index 36941c73..756dfb91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-11-10 Carlos Garcia Campos + + * 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 * shell/ev-window.c: (ev_window_sidebar_visibility_changed_cb): diff --git a/shell/ev-application.c b/shell/ev-application.c index 4bbec37c..7f912f2d 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -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); } } diff --git a/shell/ev-application.h b/shell/ev-application.h index 3b43b453..4f3ce7e4 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -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, diff --git a/shell/ev-window.c b/shell/ev-window.c index efd05653..184b1944 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -80,6 +80,7 @@ #include +#include #include #include #include @@ -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); diff --git a/shell/ev-window.h b/shell/ev-window.h index f624fe5f..af4795a4 100644 --- a/shell/ev-window.h +++ b/shell/ev-window.h @@ -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); diff --git a/shell/main.c b/shell/main.c index 56b6098a..9edb1f53 100644 --- a/shell/main.c +++ b/shell/main.c @@ -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; }