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