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