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