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