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