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