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