From a6368109ee6bbc2fa76ddc4ee50acf02ea755693 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Tue, 08 May 2007 16:40:22 +0000 Subject: Remember print settings. Fixes bug #349102. 2007-05-08 Carlos Garcia Campos * shell/ev-application.[ch]: (ev_application_shutdown), (ev_application_get_print_settings), (ev_application_set_print_settings): * shell/ev-window.c: Remember print settings. Fixes bug #349102. svn path=/trunk/; revision=2442 --- diff --git a/ChangeLog b/ChangeLog index e88543a..0a6a405 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-05-08 Carlos Garcia Campos + + * shell/ev-application.[ch]: (ev_application_shutdown), + (ev_application_get_print_settings), + (ev_application_set_print_settings): + * shell/ev-window.c: + + Remember print settings. Fixes bug #349102. + 2007-05-08 Christian Persch * configure.ac: diff --git a/shell/ev-application.c b/shell/ev-application.c index 75c2247..1d21c2c 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -59,6 +59,13 @@ struct _EvApplication { TotemScrsaver *scr_saver; gchar *last_chooser_uri; + +#ifdef WITH_GTK_PRINT + GtkPrintSettings *print_settings; +#if GTK_CHECK_VERSION (2, 11, 0) + gchar *print_settings_file; +#endif +#endif }; struct _EvApplicationClass { @@ -594,6 +601,35 @@ ev_application_shutdown (EvApplication *application) application->recent_model = NULL; } #endif + +#ifdef WITH_GTK_PRINT +#if GTK_CHECK_VERSION (2, 11, 0) + if (application->print_settings_file) { + if (application->print_settings) { + GError *error = NULL; + + gtk_print_settings_to_file (application->print_settings, + application->print_settings_file, + &error); + if (error) { + g_warning (error->message); + g_error_free (error); + } + + g_object_unref (application->print_settings); + application->print_settings = NULL; + } + + g_free (application->print_settings_file); + application->print_settings_file = NULL; + } +#else /* ! GTK 2.11.0 */ + if (application->print_settings) { + g_object_unref (application->print_settings); + application->print_settings = NULL; + } +#endif /* GTK 2.11.0 */ +#endif /* WITH_GTK_PRINT */ g_free (application->last_chooser_uri); g_object_unref (application); @@ -703,7 +739,7 @@ ev_application_get_chooser_uri (EvApplication *application) } void -ev_application_screensaver_enable (EvApplication *application) +ev_application_screensaver_enable (EvApplication *application) { if (application->scr_saver) totem_scrsaver_enable (application->scr_saver); @@ -715,3 +751,52 @@ ev_application_screensaver_disable (EvApplication *application) if (application->scr_saver) totem_scrsaver_disable (application->scr_saver); } + +#ifdef WITH_GTK_PRINT +GtkPrintSettings * +ev_application_get_print_settings (EvApplication *application) +{ + if (application->print_settings) + return application->print_settings; + +#if GTK_CHECK_VERSION (2, 11, 0) + if (!application->print_settings_file) { + application->print_settings_file = + g_build_filename (ev_dot_dir (), "print-settings", NULL); + } + + if (g_file_test (application->print_settings_file, G_FILE_TEST_IS_REGULAR)) { + GError *error = NULL; + + application->print_settings = + gtk_print_settings_new_from_file (application->print_settings_file, &error); + + if (error) { + g_warning (error->message); + g_error_free (error); + } else { + return application->print_settings; + } + } +#endif /* GTK 2.11.0 */ + + application->print_settings = gtk_print_settings_new (); + + return application->print_settings; +} + +void +ev_application_set_print_settings (EvApplication *application, + GtkPrintSettings *settings) +{ + g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings)); + + if (settings == application->print_settings) + return; + + if (application->print_settings) + g_object_unref (application->print_settings); + + application->print_settings = g_object_ref (settings); +} +#endif /* WITH_GTK_PRINT */ diff --git a/shell/ev-application.h b/shell/ev-application.h index 7981472..0ba1851 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -30,6 +30,10 @@ #include #include +#ifdef WITH_GTK_PRINT +#include +#endif + #include "ev-window.h" #include "egg-toolbars-model.h" @@ -89,6 +93,12 @@ void ev_application_set_chooser_uri (EvApplication *application, const gchar *ev_application_get_chooser_uri (EvApplication *application); void ev_application_screensaver_enable (EvApplication *application); void ev_application_screensaver_disable (EvApplication *application); +#ifdef WITH_GTK_PRINT +GtkPrintSettings *ev_application_get_print_settings (EvApplication *application); +void ev_application_set_print_settings (EvApplication *application, + GtkPrintSettings *settings); +#endif + G_END_DECLS #endif /* !EV_APPLICATION_H */ diff --git a/shell/ev-window.c b/shell/ev-window.c index b18abe7..c428643 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2073,6 +2073,10 @@ ev_window_print_finished (GtkPrintJob *print_job, gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); + } else { + /* If printed successfully, save print settings */ + ev_application_set_print_settings (EV_APP, + window->priv->print_settings); } } @@ -2280,8 +2284,10 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page) current_page = ev_page_cache_get_current_page (page_cache); document_last_page = ev_page_cache_get_n_pages (page_cache); - if (!ev_window->priv->print_settings) - ev_window->priv->print_settings = gtk_print_settings_new (); + if (!ev_window->priv->print_settings) { + ev_window->priv->print_settings = g_object_ref ( + ev_application_get_print_settings (EV_APP)); + } if (first_page != 1 || last_page != document_last_page) { GtkPageRange range; -- cgit v0.9.1