]> www.fi.muni.cz Git - evince.git/blob - shell/ev-application.c
Add print button in preview mode. Fixes bug #396475.
[evince.git] / shell / ev-application.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2004 Martin Kretzschmar
4  *
5  *  Author:
6  *    Martin Kretzschmar <martink@gnome.org>
7  *
8  * Evince is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Evince is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21  */
22
23 #include "ev-application.h"
24 #include "ev-utils.h"
25 #include "ev-file-helpers.h"
26 #include "ev-document-factory.h"
27 #include "totem-scrsaver.h"
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <glib-object.h>
32 #include <gtk/gtkfilechooserdialog.h>
33 #include <gtk/gtkstock.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkmain.h>
36
37 #if WITH_GNOME
38 #include <libgnomeui/gnome-client.h>
39 #endif
40
41 #ifdef ENABLE_DBUS
42 #include "ev-application-service.h"
43 #include <dbus/dbus-glib-bindings.h>
44 #endif
45
46 #include <string.h>
47
48 static void ev_application_add_icon_path_for_screen (GdkScreen *screen);
49
50 struct _EvApplication {
51         GObject base_instance;
52
53         gchar *toolbars_file;
54
55         EggToolbarsModel *toolbars_model;
56
57 #ifndef HAVE_GTK_RECENT
58         EggRecentModel  *recent_model;
59 #endif
60
61         TotemScrsaver *scr_saver;
62
63         gchar *last_chooser_uri;
64
65 #ifdef WITH_GTK_PRINT
66         GtkPrintSettings *print_settings;
67 #if GTK_CHECK_VERSION (2, 11, 0)
68         gchar            *print_settings_file;
69 #endif
70 #endif
71 };
72
73 struct _EvApplicationClass {
74         GObjectClass base_class;
75 };
76
77 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
78
79 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
80
81 #ifdef ENABLE_DBUS
82 gboolean
83 ev_application_register_service (EvApplication *application)
84 {
85         static DBusGConnection *connection = NULL;
86         DBusGProxy *driver_proxy;
87         GError *err = NULL;
88         guint request_name_result;
89
90         if (connection) {
91                 g_warning ("Service already registered.");
92                 return FALSE;
93         }
94         
95         connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
96         if (connection == NULL) {
97                 g_warning ("Service registration failed.");
98                 g_error_free (err);
99
100                 return FALSE;
101         }
102
103         driver_proxy = dbus_g_proxy_new_for_name (connection,
104                                                   DBUS_SERVICE_DBUS,
105                                                   DBUS_PATH_DBUS,
106                                                   DBUS_INTERFACE_DBUS);
107
108         if (!org_freedesktop_DBus_request_name (driver_proxy,
109                                                 APPLICATION_SERVICE_NAME,
110                                                 DBUS_NAME_FLAG_DO_NOT_QUEUE,
111                                                 &request_name_result, &err)) {
112                 g_warning ("Service registration failed.");
113                 g_clear_error (&err);
114         }
115
116         g_object_unref (driver_proxy);
117         
118         if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
119                 return FALSE;
120         }
121
122         dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
123                                          &dbus_glib_ev_application_object_info);
124         dbus_g_connection_register_g_object (connection,
125                                              "/org/gnome/evince/Evince",
126                                              G_OBJECT (application));
127         
128         application->scr_saver = totem_scrsaver_new (connection);
129         
130         return TRUE;
131 }
132 #endif /* ENABLE_DBUS */
133
134 /**
135  * ev_application_get_instance:
136  *
137  * Checks for #EvApplication instance, if it doesn't exist it does create it.
138  *
139  * Returns: an instance of the #EvApplication data.
140  */
141 EvApplication *
142 ev_application_get_instance (void)
143 {
144         static EvApplication *instance;
145
146         if (!instance) {
147                 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
148         }
149
150         return instance;
151 }
152
153 #if WITH_GNOME
154 static void
155 removed_from_session (GnomeClient *client, EvApplication *application)
156 {
157         ev_application_shutdown (application);
158 }
159
160 static gint
161 save_session (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gint shutdown,
162               GnomeInteractStyle interact_style, gint fast, EvApplication *application)
163 {
164         GList *windows, *l;
165         char **restart_argv;
166         int argc = 0, k;
167
168         windows = ev_application_get_windows (application);
169         restart_argv = g_new (char *, g_list_length (windows) + 1);
170         restart_argv[argc++] = g_strdup ("evince");
171
172         for (l = windows; l != NULL; l = l->next) {
173                 EvWindow *window = EV_WINDOW (l->data);
174                 restart_argv[argc++] = g_strdup (ev_window_get_uri (window));
175         }
176
177         gnome_client_set_restart_command (client, argc, restart_argv);
178
179         for (k = 0; k < argc; k++) {
180                 g_free (restart_argv[k]);
181         }
182
183         g_list_free (windows);
184         g_free (restart_argv);
185         
186         return TRUE;
187 }
188
189 static void
190 init_session (EvApplication *application)
191 {
192         GnomeClient *client;
193
194         client = gnome_master_client ();
195
196         g_signal_connect (client, "save_yourself",
197                           G_CALLBACK (save_session), application);      
198         g_signal_connect (client, "die",
199                           G_CALLBACK (removed_from_session), application);
200 }
201 #endif
202
203 /**
204  * ev_display_open_if_needed:
205  * @name: the name of the display to be open if it's needed.
206  *
207  * Search among all the open displays if any of them have the same name as the
208  * passed name. If the display isn't found it tries the open it.
209  *
210  * Returns: a #GdkDisplay of the display with the passed name.
211  */
212 static GdkDisplay *
213 ev_display_open_if_needed (const gchar *name)
214 {
215         GSList     *displays;
216         GSList     *l;
217         GdkDisplay *display = NULL;
218
219         displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
220
221         for (l = displays; l != NULL; l = l->next) {
222                 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
223
224                 if (g_ascii_strcasecmp (display_name, name) == 0) {
225                         display = l->data;
226                         break;
227                 }
228         }
229
230         g_slist_free (displays);
231
232         return display != NULL ? display : gdk_display_open (name);
233 }
234
235 /**
236  * get_screen_from_args:
237  * @args: a #GHashTable with data passed to the application.
238  *
239  * Looks for the screen in the display available in the hash table passed to the
240  * application. If the display isn't opened, it's opened and the #GdkScreen
241  * assigned to the screen in that display returned.
242  *
243  * Returns: the #GdkScreen assigned to the screen on the display indicated by
244  *          the data on the #GHashTable.
245  */
246 static GdkScreen *
247 get_screen_from_args (GHashTable *args)
248 {
249         GValue     *value = NULL;
250         GdkDisplay *display = NULL;
251         GdkScreen  *screen = NULL;
252
253         g_assert (args != NULL);
254         
255         value = g_hash_table_lookup (args, "display");
256         if (value) {
257                 const gchar *display_name;
258                 
259                 display_name = g_value_get_string (value);
260                 display = ev_display_open_if_needed (display_name);
261         }
262         
263         value = g_hash_table_lookup (args, "screen");
264         if (value) {
265                 gint screen_number;
266                 
267                 screen_number = g_value_get_int (value);
268                 screen = gdk_display_get_screen (display, screen_number);
269         }
270
271         return screen;
272 }
273
274 /**
275  * get_window_run_mode_from_args:
276  * @args: a #GHashTable with data passed to the application.
277  *
278  * It does look if the mode option has been passed from command line, using it
279  * as the window run mode, otherwise the run mode will be the normal mode.
280  *
281  * Returns: The window run mode passed from command line or
282  *          EV_WINDOW_MODE_NORMAL in other case.
283  */
284 static EvWindowRunMode
285 get_window_run_mode_from_args (GHashTable *args)
286 {
287         EvWindowRunMode  mode = EV_WINDOW_MODE_NORMAL;
288         GValue          *value = NULL;
289
290         g_assert (args != NULL);
291
292         value = g_hash_table_lookup (args, "mode");
293         if (value) {
294                 mode = g_value_get_uint (value);
295         }
296
297         return mode;
298 }
299
300 /**
301  * get_destination_from_args:
302  * @args: a #GHashTable with data passed to the application.
303  *
304  * It does look for the page-label argument parsed from the command line and
305  * if it does exist, it returns an #EvLinkDest.
306  *
307  * Returns: An #EvLinkDest to page-label if it has been passed from the command
308  *          line, NULL in other case.
309  */
310 static EvLinkDest *
311 get_destination_from_args (GHashTable *args)
312 {
313         EvLinkDest *dest = NULL;
314         GValue     *value = NULL;
315         
316         g_assert (args != NULL);
317         
318         value = g_hash_table_lookup (args, "page-label");
319         if (value) {
320                 const gchar *page_label;
321
322                 page_label = g_value_get_string (value);
323                 dest = ev_link_dest_new_page_label (page_label);
324         }
325
326         return dest;
327 }
328
329 /**
330  * get_unlink_temp_file_from_args:
331  * @args: a #GHashTable with data passed to the application.
332  *
333  * It does look if the unlink-temp-file option has been passed from the command
334  * line returning it's boolean representation, otherwise it does return %FALSE.
335  *
336  * Returns: the boolean representation of the unlink-temp-file value or %FALSE
337  *          in other case.
338  */
339 static gboolean
340 get_unlink_temp_file_from_args (GHashTable *args)
341 {
342         gboolean unlink_temp_file = FALSE;
343         GValue  *value = NULL;
344
345         g_assert (args != NULL);
346
347         value = g_hash_table_lookup (args, "unlink-temp-file");
348         if (value) {
349                 unlink_temp_file = g_value_get_boolean (value);
350         }
351         
352         return unlink_temp_file;
353 }
354
355 static const gchar *
356 get_print_settings_from_args (GHashTable *args)
357 {
358         const gchar *print_settings = NULL;
359         GValue      *value = NULL;
360
361         g_assert (args != NULL);
362
363         value = g_hash_table_lookup (args, "print-settings");
364         if (value) {
365                 print_settings = g_value_get_string (value);
366         }
367
368         return print_settings;
369 }
370
371 /**
372  * ev_application_open_window:
373  * @application: The instance of the application.
374  * @args: A #GHashTable with the arguments data.
375  * @timestamp: Current time value.
376  * @error: The #GError facility.
377  * 
378  * Creates a new window and if the args are available, it's not NULL, it gets
379  * the screen from them and assigns the just created window to it. At last it
380  * does show it.
381  *
382  * Returns: %TRUE.
383  */
384 gboolean
385 ev_application_open_window (EvApplication  *application,
386                             GHashTable     *args,
387                             guint32         timestamp,
388                             GError        **error)
389 {
390         GtkWidget *new_window = ev_window_new ();
391         GdkScreen *screen = NULL;
392
393         if (args) {
394                 screen = get_screen_from_args (args);
395         }
396         
397         if (screen) {
398                 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
399         }
400         ev_application_add_icon_path_for_screen (screen);
401         
402         gtk_widget_show (new_window);
403         
404         gtk_window_present_with_time (GTK_WINDOW (new_window),
405                                       timestamp);
406         return TRUE;
407 }
408
409 /**
410  * ev_application_get_empty_window:
411  * @application: The instance of the application.
412  * @screen: The screen where the empty window will be search.
413  *
414  * It does look if there is any empty window in the indicated screen.
415  *
416  * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
417  *          case.
418  */
419 static EvWindow *
420 ev_application_get_empty_window (EvApplication *application,
421                                  GdkScreen     *screen)
422 {
423         EvWindow *empty_window = NULL;
424         GList *windows = ev_application_get_windows (application);
425         GList *l;
426
427         for (l = windows; l != NULL; l = l->next) {
428                 EvWindow *window = EV_WINDOW (l->data);
429
430                 if (ev_window_is_empty (window) &&
431                     gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
432                         empty_window = window;
433                         break;
434                 }
435         }
436
437         g_list_free (windows);
438         
439         return empty_window;
440 }
441
442 /**
443  * ev_application_get_uri_window:
444  * @application: The instance of the application.
445  * @uri: The uri to be opened.
446  *
447  * It looks in the list of the windows for the one with the document represented
448  * by the passed uri on it. If the window is empty or the document isn't present
449  * on any window, it will return NULL.
450  *
451  * Returns: The #EvWindow where the document represented by the passed uri is
452  *          shown, NULL in other case.
453  */
454 static EvWindow *
455 ev_application_get_uri_window (EvApplication *application, const char *uri)
456 {
457         EvWindow *uri_window = NULL;
458         GList *windows = gtk_window_list_toplevels ();
459         GList *l;
460
461         g_return_val_if_fail (uri != NULL, NULL);
462
463         for (l = windows; l != NULL; l = l->next) {
464                 if (EV_IS_WINDOW (l->data)) {
465                         EvWindow *window = EV_WINDOW (l->data);
466                         const char *window_uri = ev_window_get_uri (window);
467
468                         if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
469                                 uri_window = window;
470                                 break;
471                         }
472                 }
473         }
474
475         g_list_free (windows);
476         
477         return uri_window;
478 }
479
480 static void
481 ev_application_add_icon_path_for_screen (GdkScreen *screen)
482 {
483         GtkIconTheme *icon_theme;
484
485         icon_theme = gtk_icon_theme_get_for_screen (screen);
486         if (icon_theme) {
487                 gchar **path = NULL;
488                 gint    n_paths;
489                 gint    i;
490                 gchar  *ev_icons_path;
491
492                 /* GtkIconTheme will then look in Evince custom hicolor dir
493                  * for icons as well as the standard search paths
494                  */
495                 ev_icons_path = g_build_filename (DATADIR, "icons", NULL);
496                 gtk_icon_theme_get_search_path (icon_theme, &path, &n_paths);
497                 for (i = n_paths - 1; i >= 0; i--) {
498                         if (g_ascii_strcasecmp (ev_icons_path, path[i]) == 0)
499                                 break;
500                 }
501
502                 if (i < 0)
503                         gtk_icon_theme_append_search_path (icon_theme,
504                                                            ev_icons_path);
505
506                 g_free (ev_icons_path);
507                 g_strfreev (path);
508         }       
509 }
510
511 /**
512  * ev_application_open_uri_at_dest:
513  * @application: The instance of the application.
514  * @uri: The uri to be opened.
515  * @screen: Thee screen where the link will be shown.
516  * @dest: The #EvLinkDest of the document.
517  * @mode: The run mode of the window.
518  * @unlink_temp_file: The unlink_temp_file option value.
519  * @timestamp: Current time value.
520  */
521 void
522 ev_application_open_uri_at_dest (EvApplication  *application,
523                                  const char     *uri,
524                                  GdkScreen      *screen,
525                                  EvLinkDest     *dest,
526                                  EvWindowRunMode mode,
527                                  gboolean        unlink_temp_file,
528                                  const gchar    *print_settings, 
529                                  guint           timestamp)
530 {
531         EvWindow *new_window;
532
533         g_return_if_fail (uri != NULL);
534         
535         ev_application_add_icon_path_for_screen (screen);
536
537         new_window = ev_application_get_uri_window (application, uri);
538         
539         if (new_window == NULL) {
540                 new_window = ev_application_get_empty_window (application, screen);
541         }
542
543         if (new_window == NULL) {
544                 new_window = EV_WINDOW (ev_window_new ());
545         }
546
547         if (screen)
548                 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
549
550         /* We need to load uri before showing the window, so
551            we can restore window size without flickering */     
552         ev_window_open_uri (new_window, uri, dest, mode,
553                             unlink_temp_file, print_settings);
554
555         ev_document_fc_mutex_lock ();
556         gtk_widget_show (GTK_WIDGET (new_window));
557         ev_document_fc_mutex_unlock ();
558
559         gtk_window_present_with_time (GTK_WINDOW (new_window),
560                                       timestamp);
561 }
562
563 /**
564  * ev_application_open_uri:
565  * @application: The instance of the application.
566  * @uri: The uri to be opened
567  * @args: A #GHashTable with the arguments data.
568  * @timestamp: Current time value.
569  * @error: The #GError facility.
570  */
571 gboolean
572 ev_application_open_uri (EvApplication  *application,
573                          const char     *uri,
574                          GHashTable     *args,
575                          guint           timestamp,
576                          GError        **error)
577 {
578         EvLinkDest      *dest = NULL;
579         EvWindowRunMode  mode = EV_WINDOW_MODE_NORMAL;
580         gboolean         unlink_temp_file = FALSE;
581         const gchar     *print_settings;
582         GdkScreen       *screen = NULL;
583
584         if (args) {
585                 screen = get_screen_from_args (args);
586                 dest = get_destination_from_args (args);
587                 mode = get_window_run_mode_from_args (args);
588                 unlink_temp_file = (mode == EV_WINDOW_MODE_PREVIEW &&
589                                     get_unlink_temp_file_from_args (args));
590                 print_settings = get_print_settings_from_args (args);
591         }
592         
593         ev_application_open_uri_at_dest (application, uri, screen,
594                                          dest, mode, unlink_temp_file,
595                                          print_settings, timestamp);
596
597         if (dest)
598                 g_object_unref (dest);
599
600         return TRUE;
601 }
602
603 void
604 ev_application_open_uri_list (EvApplication *application,
605                               GSList        *uri_list,
606                               GdkScreen     *screen,
607                               guint          timestamp)
608 {
609         GSList *l;
610
611         for (l = uri_list; l != NULL; l = l->next) {
612                 ev_application_open_uri_at_dest (application, (char *)l->data,
613                                                  screen, NULL, 0, FALSE,
614                                                  NULL, timestamp);
615         }
616 }
617
618 void
619 ev_application_shutdown (EvApplication *application)
620 {
621         if (application->toolbars_model) {
622                 g_object_unref (application->toolbars_model);
623                 g_free (application->toolbars_file);
624                 application->toolbars_model = NULL;
625                 application->toolbars_file = NULL;
626         }
627
628 #ifndef HAVE_GTK_RECENT
629         if (application->recent_model) {
630                 g_object_unref (application->recent_model);
631                 application->recent_model = NULL;
632         }
633 #endif
634
635 #ifdef WITH_GTK_PRINT
636 #if GTK_CHECK_VERSION (2, 11, 0)
637         if (application->print_settings_file) {
638                 if (application->print_settings) {
639                         GError *error = NULL;
640                         
641                         gtk_print_settings_to_file (application->print_settings,
642                                                     application->print_settings_file,
643                                                     &error);
644                         if (error) {
645                                 g_warning (error->message);
646                                 g_error_free (error);
647                         }
648
649                         g_object_unref (application->print_settings);
650                         application->print_settings = NULL;
651                 }
652
653                 g_free (application->print_settings_file);
654                 application->print_settings_file = NULL;
655         }
656 #else /* ! GTK 2.11.0 */
657         if (application->print_settings) {
658                 g_object_unref (application->print_settings);
659                 application->print_settings = NULL;
660         }
661 #endif /* GTK 2.11.0 */
662 #endif /* WITH_GTK_PRINT */
663         
664         g_free (application->last_chooser_uri);
665         g_object_unref (application);
666         
667         gtk_main_quit ();
668 }
669
670 static void
671 ev_application_class_init (EvApplicationClass *ev_application_class)
672 {
673 }
674
675 static void
676 ev_application_init (EvApplication *ev_application)
677 {
678 #if WITH_GNOME
679         init_session (ev_application);
680 #endif
681
682         ev_application->toolbars_model = egg_toolbars_model_new ();
683
684         ev_application->toolbars_file = g_build_filename
685                         (ev_dot_dir (), "evince_toolbar.xml", NULL);
686
687         egg_toolbars_model_load_names (ev_application->toolbars_model,
688                                        DATADIR "/evince-toolbar.xml");
689
690         if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
691                                                ev_application->toolbars_file)) {
692                 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
693                                                   DATADIR"/evince-toolbar.xml");
694         }
695
696         egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
697                                       EGG_TB_MODEL_NOT_REMOVABLE); 
698
699 #ifndef HAVE_GTK_RECENT
700         ev_application->recent_model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU);
701         /* FIXME we should add a mime type filter but current eggrecent
702            has only a varargs style api which does not work well when
703            the list of mime types is dynamic */
704         egg_recent_model_set_limit (ev_application->recent_model, 5);   
705         egg_recent_model_set_filter_groups (ev_application->recent_model,
706                                             "Evince", NULL);
707 #endif /* HAVE_GTK_RECENT */
708 }
709
710 /**
711  * ev_application_get_windows:
712  * @application: The instance of the application.
713  *
714  * It creates a list of the top level windows.
715  *
716  * Returns: A #GList of the top level windows.
717  */
718 GList *
719 ev_application_get_windows (EvApplication *application)
720 {
721         GList *l, *toplevels;
722         GList *windows = NULL;
723
724         toplevels = gtk_window_list_toplevels ();
725
726         for (l = toplevels; l != NULL; l = l->next) {
727                 if (EV_IS_WINDOW (l->data)) {
728                         windows = g_list_append (windows, l->data);
729                 }
730         }
731
732         g_list_free (toplevels);
733
734         return windows;
735 }
736
737 EggToolbarsModel *
738 ev_application_get_toolbars_model (EvApplication *application)
739 {
740         return application->toolbars_model;
741 }
742
743 #ifndef HAVE_GTK_RECENT
744 EggRecentModel *
745 ev_application_get_recent_model (EvApplication *application)
746 {
747         return application->recent_model;
748 }
749 #endif
750
751 void
752 ev_application_save_toolbars_model (EvApplication *application)
753 {
754         egg_toolbars_model_save_toolbars (application->toolbars_model,
755                                           application->toolbars_file, "1.0");
756 }
757
758 void
759 ev_application_set_chooser_uri (EvApplication *application, const gchar *uri)
760 {
761         g_free (application->last_chooser_uri);
762         application->last_chooser_uri = g_strdup (uri);
763 }
764
765 const gchar *
766 ev_application_get_chooser_uri (EvApplication *application)
767 {
768         return application->last_chooser_uri;
769 }
770
771 void
772 ev_application_screensaver_enable (EvApplication *application)
773 {
774         if (application->scr_saver)
775                 totem_scrsaver_enable (application->scr_saver); 
776 }
777
778 void
779 ev_application_screensaver_disable (EvApplication *application)
780 {
781         if (application->scr_saver)
782                 totem_scrsaver_disable (application->scr_saver);        
783 }
784
785 #ifdef WITH_GTK_PRINT
786 GtkPrintSettings *
787 ev_application_get_print_settings (EvApplication *application)
788 {
789         if (application->print_settings)
790                 return application->print_settings;
791         
792 #if GTK_CHECK_VERSION (2, 11, 0)
793         if (!application->print_settings_file) {
794                 application->print_settings_file =
795                         g_build_filename (ev_dot_dir (), "print-settings", NULL);
796         }
797
798         if (g_file_test (application->print_settings_file, G_FILE_TEST_IS_REGULAR)) {
799                 GError *error = NULL;
800                 
801                 application->print_settings =
802                         gtk_print_settings_new_from_file (application->print_settings_file, &error);
803                 
804                 if (error) {
805                         g_warning (error->message);
806                         g_error_free (error);
807                 } else {
808                         return application->print_settings;
809                 }
810         }
811 #endif /* GTK 2.11.0 */
812         
813         application->print_settings = gtk_print_settings_new ();
814
815         return application->print_settings;
816 }
817
818 void
819 ev_application_set_print_settings (EvApplication    *application,
820                                    GtkPrintSettings *settings)
821 {
822         g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
823         
824         if (settings == application->print_settings)
825                 return;
826
827         if (application->print_settings)
828                 g_object_unref (application->print_settings);
829         
830         application->print_settings = g_object_ref (settings);
831 }
832 #endif /* WITH_GTK_PRINT */