1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2004 Martin Kretzschmar
6 * Martin Kretzschmar <martink@gnome.org>
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.
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.
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.
29 #include <glib/gi18n.h>
31 #ifdef GDK_WINDOWING_X11
35 #include "totem-scrsaver.h"
36 #include "eggsmclient.h"
38 #include "ev-application.h"
39 #include "ev-document-factory.h"
40 #include "ev-file-helpers.h"
41 #include "ev-metadata-manager.h"
43 #include "ev-stock-icons.h"
46 #include "ev-media-player-keys.h"
47 #endif /* ENABLE_DBUS */
50 #include <dbus/dbus-glib-bindings.h>
51 #include "ev-application-service.h"
54 static void ev_application_save_print_settings (EvApplication *application);
56 struct _EvApplication {
57 GObject base_instance;
60 gchar *accel_map_file;
65 EggToolbarsModel *toolbars_model;
67 TotemScrsaver *scr_saver;
69 EggSMClient *smclient;
71 gchar *last_chooser_uri;
74 EvMediaPlayerKeys *keys;
75 #endif /* ENABLE_DBUS */
77 GtkPrintSettings *print_settings;
78 GtkPageSetup *page_setup;
79 GKeyFile *print_settings_file;
82 struct _EvApplicationClass {
83 GObjectClass base_class;
86 static EvApplication *instance;
88 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
90 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
92 #define EV_PRINT_SETTINGS_FILE "print-settings"
93 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
94 #define EV_PAGE_SETUP_GROUP "Page Setup"
98 ev_application_register_service (EvApplication *application)
100 static DBusGConnection *connection = NULL;
101 DBusGProxy *driver_proxy;
103 guint request_name_result;
106 g_warning ("Service already registered.");
110 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
111 if (connection == NULL) {
112 g_warning ("Service registration failed.");
118 driver_proxy = dbus_g_proxy_new_for_name (connection,
121 DBUS_INTERFACE_DBUS);
123 if (!org_freedesktop_DBus_request_name (driver_proxy,
124 APPLICATION_SERVICE_NAME,
125 DBUS_NAME_FLAG_DO_NOT_QUEUE,
126 &request_name_result, &err)) {
127 g_warning ("Service registration failed.");
128 g_clear_error (&err);
131 g_object_unref (driver_proxy);
133 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
137 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
138 &dbus_glib_ev_application_object_info);
139 dbus_g_connection_register_g_object (connection,
140 "/org/gnome/evince/Evince",
141 G_OBJECT (application));
143 application->scr_saver = totem_scrsaver_new (connection);
145 ev_metadata_manager_init ();
149 #endif /* ENABLE_DBUS */
152 * ev_application_get_instance:
154 * Checks for #EvApplication instance, if it doesn't exist it does create it.
156 * Returns: an instance of the #EvApplication data.
159 ev_application_get_instance (void)
162 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
170 save_session (EvApplication *application,
172 GKeyFile *state_file)
176 const gchar **uri_list;
177 const gchar *empty = "empty-window";
179 uri_list = g_new (const gchar *, g_list_length (windows_list));
180 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
181 EvWindow *window = EV_WINDOW (l->data);
183 if (ev_window_is_empty (window))
186 uri_list[i] = ev_window_get_uri (window);
188 g_key_file_set_string_list (state_file,
191 (const char **)uri_list,
197 ev_application_save_session_crashed (EvApplication *application)
201 windows = ev_application_get_windows (application);
203 GKeyFile *crashed_file;
206 GError *error = NULL;
208 crashed_file = g_key_file_new ();
209 save_session (application, windows, crashed_file);
211 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
212 g_file_set_contents (application->crashed_file, data, data_length, &error);
214 g_warning ("%s", error->message);
215 g_error_free (error);
218 g_key_file_free (crashed_file);
219 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
222 file = g_file_new_for_path (application->crashed_file);
223 g_file_delete (file, NULL, NULL);
224 g_object_unref (file);
229 save_session_crashed_in_idle_cb (EvApplication *application)
231 ev_application_save_session_crashed (application);
232 application->crashed_idle = 0;
238 save_session_crashed_in_idle (EvApplication *application)
240 if (application->crashed_idle > 0)
241 g_source_remove (application->crashed_idle);
242 application->crashed_idle =
243 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
248 ev_application_run_crash_recovery_dialog (EvApplication *application)
253 dialog = gtk_message_dialog_new (NULL,
257 _("Recover previous documents?"));
258 gtk_message_dialog_format_secondary_text (
259 GTK_MESSAGE_DIALOG (dialog),
260 _("Evince appears to have exited unexpectedly the last time "
261 "it was run. You can recover the opened documents."));
263 gtk_dialog_add_button (GTK_DIALOG (dialog),
265 GTK_RESPONSE_CANCEL);
266 gtk_dialog_add_button (GTK_DIALOG (dialog),
268 GTK_RESPONSE_ACCEPT);
270 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
271 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
272 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
273 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
274 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
276 response = gtk_dialog_run (GTK_DIALOG (dialog));
277 gtk_widget_destroy (dialog);
279 return response == GTK_RESPONSE_ACCEPT;
283 ev_application_load_session (EvApplication *application)
285 GKeyFile *state_file;
288 if (egg_sm_client_is_resumed (application->smclient)) {
289 state_file = egg_sm_client_get_state_file (application->smclient);
292 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
293 if (ev_application_run_crash_recovery_dialog (application)) {
294 state_file = g_key_file_new ();
295 g_key_file_load_from_file (state_file,
296 application->crashed_file,
306 uri_list = g_key_file_get_string_list (state_file,
313 for (i = 0; uri_list[i]; i++) {
314 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
315 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
317 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
319 g_strfreev (uri_list);
321 g_key_file_free (state_file);
327 smclient_save_state_cb (EggSMClient *client,
328 GKeyFile *state_file,
329 EvApplication *application)
333 windows = ev_application_get_windows (application);
335 save_session (application, windows, state_file);
336 g_list_free (windows);
341 smclient_quit_cb (EggSMClient *client,
342 EvApplication *application)
344 ev_application_shutdown (application);
348 ev_application_init_session (EvApplication *application)
350 application->crashed_file = g_build_filename (application->dot_dir,
351 "evince-crashed", NULL);
353 application->smclient = egg_sm_client_get ();
354 g_signal_connect (application->smclient, "save_state",
355 G_CALLBACK (smclient_save_state_cb),
357 g_signal_connect (application->smclient, "quit",
358 G_CALLBACK (smclient_quit_cb),
363 * ev_display_open_if_needed:
364 * @name: the name of the display to be open if it's needed.
366 * Search among all the open displays if any of them have the same name as the
367 * passed name. If the display isn't found it tries the open it.
369 * Returns: a #GdkDisplay of the display with the passed name.
372 ev_display_open_if_needed (const gchar *name)
376 GdkDisplay *display = NULL;
378 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
380 for (l = displays; l != NULL; l = l->next) {
381 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
383 if (g_ascii_strcasecmp (display_name, name) == 0) {
389 g_slist_free (displays);
391 return display != NULL ? display : gdk_display_open (name);
395 * get_screen_from_args:
396 * @args: a #GHashTable with data passed to the application.
398 * Looks for the screen in the display available in the hash table passed to the
399 * application. If the display isn't opened, it's opened and the #GdkScreen
400 * assigned to the screen in that display returned.
402 * Returns: the #GdkScreen assigned to the screen on the display indicated by
403 * the data on the #GHashTable.
406 get_screen_from_args (GHashTable *args)
408 GValue *value = NULL;
409 GdkDisplay *display = NULL;
410 GdkScreen *screen = NULL;
412 g_assert (args != NULL);
414 value = g_hash_table_lookup (args, "display");
416 const gchar *display_name;
418 display_name = g_value_get_string (value);
419 display = ev_display_open_if_needed (display_name);
422 value = g_hash_table_lookup (args, "screen");
426 screen_number = g_value_get_int (value);
427 screen = gdk_display_get_screen (display, screen_number);
434 * get_window_run_mode_from_args:
435 * @args: a #GHashTable with data passed to the application.
437 * It does look if the mode option has been passed from command line, using it
438 * as the window run mode, otherwise the run mode will be the normal mode.
440 * Returns: The window run mode passed from command line or
441 * EV_WINDOW_MODE_NORMAL in other case.
443 static EvWindowRunMode
444 get_window_run_mode_from_args (GHashTable *args)
446 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
447 GValue *value = NULL;
449 g_assert (args != NULL);
451 value = g_hash_table_lookup (args, "mode");
453 mode = g_value_get_uint (value);
460 * get_destination_from_args:
461 * @args: a #GHashTable with data passed to the application.
463 * It does look for the page-label argument parsed from the command line and
464 * if it does exist, it returns an #EvLinkDest.
466 * Returns: An #EvLinkDest to page-label if it has been passed from the command
467 * line, NULL in other case.
470 get_destination_from_args (GHashTable *args)
472 EvLinkDest *dest = NULL;
473 GValue *value = NULL;
475 g_assert (args != NULL);
477 value = g_hash_table_lookup (args, "page-label");
479 const gchar *page_label;
481 page_label = g_value_get_string (value);
482 dest = ev_link_dest_new_page_label (page_label);
489 get_find_string_from_args (GHashTable *args)
491 GValue *value = NULL;
493 g_assert (args != NULL);
495 value = g_hash_table_lookup (args, "find-string");
497 return value ? g_value_get_string (value) : NULL;
501 * ev_application_open_window:
502 * @application: The instance of the application.
503 * @args: A #GHashTable with the arguments data.
504 * @timestamp: Current time value.
505 * @error: The #GError facility.
507 * Creates a new window and if the args are available, it's not NULL, it gets
508 * the screen from them and assigns the just created window to it. At last it
514 ev_application_open_window (EvApplication *application,
519 GtkWidget *new_window = ev_window_new ();
520 GdkScreen *screen = NULL;
523 screen = get_screen_from_args (args);
527 ev_stock_icons_set_screen (screen);
528 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
531 ev_application_save_session_crashed (application);
532 g_signal_connect_swapped (new_window, "destroy",
533 G_CALLBACK (save_session_crashed_in_idle),
536 if (!GTK_WIDGET_REALIZED (new_window))
537 gtk_widget_realize (new_window);
539 #ifdef GDK_WINDOWING_X11
541 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
542 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
544 gtk_window_present (GTK_WINDOW (new_window));
546 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
547 #endif /* GDK_WINDOWING_X11 */
553 * ev_application_get_empty_window:
554 * @application: The instance of the application.
555 * @screen: The screen where the empty window will be search.
557 * It does look if there is any empty window in the indicated screen.
559 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
563 ev_application_get_empty_window (EvApplication *application,
566 EvWindow *empty_window = NULL;
567 GList *windows = ev_application_get_windows (application);
570 for (l = windows; l != NULL; l = l->next) {
571 EvWindow *window = EV_WINDOW (l->data);
573 if (ev_window_is_empty (window) &&
574 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
575 empty_window = window;
580 g_list_free (windows);
586 * ev_application_get_uri_window:
587 * @application: The instance of the application.
588 * @uri: The uri to be opened.
590 * It looks in the list of the windows for the one with the document represented
591 * by the passed uri on it. If the window is empty or the document isn't present
592 * on any window, it will return NULL.
594 * Returns: The #EvWindow where the document represented by the passed uri is
595 * shown, NULL in other case.
598 ev_application_get_uri_window (EvApplication *application, const char *uri)
600 EvWindow *uri_window = NULL;
601 GList *windows = gtk_window_list_toplevels ();
604 g_return_val_if_fail (uri != NULL, NULL);
606 for (l = windows; l != NULL; l = l->next) {
607 if (EV_IS_WINDOW (l->data)) {
608 EvWindow *window = EV_WINDOW (l->data);
609 const char *window_uri = ev_window_get_uri (window);
611 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
618 g_list_free (windows);
624 * ev_application_open_uri_at_dest:
625 * @application: The instance of the application.
626 * @uri: The uri to be opened.
627 * @screen: Thee screen where the link will be shown.
628 * @dest: The #EvLinkDest of the document.
629 * @mode: The run mode of the window.
630 * @timestamp: Current time value.
633 ev_application_open_uri_at_dest (EvApplication *application,
637 EvWindowRunMode mode,
638 const gchar *search_string,
641 EvWindow *new_window;
643 g_return_if_fail (uri != NULL);
645 new_window = ev_application_get_uri_window (application, uri);
647 if (new_window == NULL) {
648 new_window = ev_application_get_empty_window (application, screen);
651 if (new_window == NULL) {
652 new_window = EV_WINDOW (ev_window_new ());
656 ev_stock_icons_set_screen (screen);
657 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
660 /* We need to load uri before showing the window, so
661 we can restore window size without flickering */
662 ev_window_open_uri (new_window, uri, dest, mode, search_string);
664 ev_application_save_session_crashed (application);
665 g_signal_connect_swapped (new_window, "destroy",
666 G_CALLBACK (save_session_crashed_in_idle),
669 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
670 gtk_widget_realize (GTK_WIDGET (new_window));
672 #ifdef GDK_WINDOWING_X11
674 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
675 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
677 ev_document_fc_mutex_lock ();
678 gtk_window_present (GTK_WINDOW (new_window));
679 ev_document_fc_mutex_unlock ();
681 ev_document_fc_mutex_lock ();
682 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
683 ev_document_fc_mutex_unlock ();
684 #endif /* GDK_WINDOWING_X11 */
688 * ev_application_open_uri:
689 * @application: The instance of the application.
690 * @uri: The uri to be opened
691 * @args: A #GHashTable with the arguments data.
692 * @timestamp: Current time value.
693 * @error: The #GError facility.
696 ev_application_open_uri (EvApplication *application,
702 EvLinkDest *dest = NULL;
703 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
704 const gchar *search_string = NULL;
705 GdkScreen *screen = NULL;
708 screen = get_screen_from_args (args);
709 dest = get_destination_from_args (args);
710 mode = get_window_run_mode_from_args (args);
711 search_string = get_find_string_from_args (args);
714 ev_application_open_uri_at_dest (application, uri, screen,
715 dest, mode, search_string,
719 g_object_unref (dest);
725 ev_application_open_uri_list (EvApplication *application,
732 for (l = uri_list; l != NULL; l = l->next) {
733 ev_application_open_uri_at_dest (application, (char *)l->data,
734 screen, NULL, 0, NULL,
740 ev_application_shutdown (EvApplication *application)
742 if (application->crashed_file) {
743 ev_application_save_session_crashed (application);
744 g_free (application->crashed_file);
745 application->crashed_file = NULL;
748 if (application->accel_map_file) {
749 gtk_accel_map_save (application->accel_map_file);
750 g_free (application->accel_map_file);
751 application->accel_map_file = NULL;
754 if (application->toolbars_model) {
755 g_object_unref (application->toolbars_model);
756 g_free (application->toolbars_file);
757 application->toolbars_model = NULL;
758 application->toolbars_file = NULL;
761 ev_application_save_print_settings (application);
763 if (application->print_settings_file) {
764 g_key_file_free (application->print_settings_file);
765 application->print_settings_file = NULL;
768 if (application->print_settings) {
769 g_object_unref (application->print_settings);
770 application->print_settings = NULL;
773 if (application->page_setup) {
774 g_object_unref (application->page_setup);
775 application->page_setup = NULL;
779 if (application->keys) {
780 g_object_unref (application->keys);
781 application->keys = NULL;
783 #endif /* ENABLE_DBUS */
785 ev_metadata_manager_shutdown ();
787 g_free (application->dot_dir);
788 application->dot_dir = NULL;
789 g_free (application->last_chooser_uri);
790 application->last_chooser_uri = NULL;
792 g_object_unref (application);
799 ev_application_class_init (EvApplicationClass *ev_application_class)
804 ev_application_init (EvApplication *ev_application)
807 const gchar *home_dir;
809 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
814 /* FIXME: why make this fatal? */
815 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
818 ev_application_init_session (ev_application);
820 home_dir = g_get_home_dir ();
822 ev_application->accel_map_file = g_build_filename (home_dir,
827 gtk_accel_map_load (ev_application->accel_map_file);
830 ev_application->toolbars_model = egg_toolbars_model_new ();
832 ev_application->toolbars_file = g_build_filename
833 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
835 egg_toolbars_model_load_names (ev_application->toolbars_model,
836 DATADIR "/evince-toolbar.xml");
838 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
839 ev_application->toolbars_file)) {
840 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
841 DATADIR"/evince-toolbar.xml");
844 /* Open item doesn't exist anymore,
845 * convert it to OpenRecent for compatibility
847 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
850 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
851 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
852 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
853 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
855 ev_application_save_toolbars_model (ev_application);
860 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
861 EGG_TB_MODEL_NOT_REMOVABLE);
864 ev_application->keys = ev_media_player_keys_new ();
865 #endif /* ENABLE_DBUS */
869 * ev_application_get_windows:
870 * @application: The instance of the application.
872 * It creates a list of the top level windows.
874 * Returns: A #GList of the top level windows.
877 ev_application_get_windows (EvApplication *application)
879 GList *l, *toplevels;
880 GList *windows = NULL;
882 toplevels = gtk_window_list_toplevels ();
884 for (l = toplevels; l != NULL; l = l->next) {
885 if (EV_IS_WINDOW (l->data)) {
886 windows = g_list_append (windows, l->data);
890 g_list_free (toplevels);
896 * ev_application_get_media_keys:
897 * @application: The instance of the application.
899 * It gives you access to the media player keys handler object.
901 * Returns: A #EvMediaPlayerKeys.
904 ev_application_get_media_keys (EvApplication *application)
907 return G_OBJECT (application->keys);
910 #endif /* ENABLE_DBUS */
914 ev_application_get_toolbars_model (EvApplication *application)
916 return application->toolbars_model;
920 ev_application_save_toolbars_model (EvApplication *application)
922 egg_toolbars_model_save_toolbars (application->toolbars_model,
923 application->toolbars_file, "1.0");
927 ev_application_set_chooser_uri (EvApplication *application, const gchar *uri)
929 g_free (application->last_chooser_uri);
930 application->last_chooser_uri = g_strdup (uri);
934 ev_application_get_chooser_uri (EvApplication *application)
936 return application->last_chooser_uri;
940 ev_application_screensaver_enable (EvApplication *application)
942 if (application->scr_saver)
943 totem_scrsaver_enable (application->scr_saver);
947 ev_application_screensaver_disable (EvApplication *application)
949 if (application->scr_saver)
950 totem_scrsaver_disable (application->scr_saver);
954 ev_application_get_print_settings_file (EvApplication *application)
958 if (application->print_settings_file)
959 return application->print_settings_file;
961 application->print_settings_file = g_key_file_new ();
963 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
964 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
965 GError *error = NULL;
967 g_key_file_load_from_file (application->print_settings_file,
969 G_KEY_FILE_KEEP_COMMENTS |
970 G_KEY_FILE_KEEP_TRANSLATIONS,
973 g_warning ("%s", error->message);
974 g_error_free (error);
979 return application->print_settings_file;
983 ev_application_save_print_settings (EvApplication *application)
989 GError *error = NULL;
991 if (!application->print_settings && !application->page_setup)
994 key_file = ev_application_get_print_settings_file (application);
995 if (application->print_settings)
996 gtk_print_settings_to_key_file (application->print_settings,
998 EV_PRINT_SETTINGS_GROUP);
999 if (application->page_setup)
1000 gtk_page_setup_to_key_file (application->page_setup,
1002 EV_PAGE_SETUP_GROUP);
1004 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1005 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1006 g_file_set_contents (filename, data, data_length, &error);
1008 g_warning ("%s", error->message);
1009 g_error_free (error);
1016 ev_application_get_print_settings (EvApplication *application)
1019 GtkPrintSettings *print_settings;
1021 if (application->print_settings)
1022 return application->print_settings;
1024 key_file = ev_application_get_print_settings_file (application);
1025 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1026 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1027 gtk_print_settings_new ();
1029 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1031 return application->print_settings;
1035 ev_application_set_print_settings (EvApplication *application,
1036 GtkPrintSettings *settings)
1040 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1042 if (settings == application->print_settings)
1045 key_file = ev_application_get_print_settings_file (application);
1047 if (application->print_settings)
1048 g_object_unref (application->print_settings);
1050 application->print_settings = g_object_ref (settings);
1051 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1055 ev_application_get_page_setup (EvApplication *application)
1058 GtkPageSetup *page_setup;
1060 if (application->page_setup)
1061 return application->page_setup;
1063 key_file = ev_application_get_print_settings_file (application);
1064 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1065 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1066 gtk_page_setup_new ();
1068 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1070 return application->page_setup;
1074 ev_application_set_page_setup (EvApplication *application,
1075 GtkPageSetup *page_setup)
1079 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1081 if (page_setup == application->page_setup)
1084 key_file = ev_application_get_print_settings_file (application);
1086 if (application->page_setup)
1087 g_object_unref (application->page_setup);
1089 application->page_setup = g_object_ref (page_setup);
1090 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1094 ev_application_get_dot_dir (EvApplication *application)
1096 return application->dot_dir;