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