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"
38 #include "eggsmclient.h"
41 #include "ev-application.h"
42 #include "ev-document-factory.h"
43 #include "ev-file-helpers.h"
45 #include "ev-stock-icons.h"
48 #include "ev-media-player-keys.h"
49 #endif /* ENABLE_DBUS */
52 #include <dbus/dbus-glib-bindings.h>
53 static gboolean ev_application_open_uri (EvApplication *application,
58 #include "ev-application-service.h"
61 static void ev_application_save_print_settings (EvApplication *application);
63 struct _EvApplication {
64 GObject base_instance;
71 gchar *accel_map_file;
75 DBusGConnection *connection;
76 EvMediaPlayerKeys *keys;
79 EggToolbarsModel *toolbars_model;
81 TotemScrsaver *scr_saver;
84 EggSMClient *smclient;
87 gchar *filechooser_open_uri;
88 gchar *filechooser_save_uri;
90 GtkPrintSettings *print_settings;
91 GtkPageSetup *page_setup;
92 GKeyFile *print_settings_file;
95 struct _EvApplicationClass {
96 GObjectClass base_class;
99 static EvApplication *instance;
101 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
104 #define APPLICATION_DBUS_OBJECT_PATH "/org/gnome/evince/Evince"
105 #define APPLICATION_DBUS_INTERFACE "org.gnome.evince.Application"
108 #define EV_PRINT_SETTINGS_FILE "print-settings"
109 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
110 #define EV_PAGE_SETUP_GROUP "Page Setup"
113 * ev_application_get_instance:
115 * Checks for #EvApplication instance, if it doesn't exist it does create it.
117 * Returns: an instance of the #EvApplication data.
120 ev_application_get_instance (void)
123 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
131 ev_application_load_session (EvApplication *application)
133 GKeyFile *state_file;
137 if (egg_sm_client_is_resumed (application->smclient)) {
138 state_file = egg_sm_client_get_state_file (application->smclient);
142 #endif /* WITH_SMCLIENT */
145 uri = g_key_file_get_string (state_file, "Evince", "uri", NULL);
149 ev_application_open_uri_at_dest (application, uri,
150 gdk_screen_get_default (),
154 g_key_file_free (state_file);
162 smclient_save_state_cb (EggSMClient *client,
163 GKeyFile *state_file,
164 EvApplication *application)
166 if (!application->uri)
169 g_key_file_set_string (state_file, "Evince", "uri", application->uri);
173 smclient_quit_cb (EggSMClient *client,
174 EvApplication *application)
176 ev_application_shutdown (application);
178 #endif /* WITH_SMCLIENT */
181 ev_application_init_session (EvApplication *application)
184 application->smclient = egg_sm_client_get ();
185 g_signal_connect (application->smclient, "save_state",
186 G_CALLBACK (smclient_save_state_cb),
188 g_signal_connect (application->smclient, "quit",
189 G_CALLBACK (smclient_quit_cb),
195 * ev_display_open_if_needed:
196 * @name: the name of the display to be open if it's needed.
198 * Search among all the open displays if any of them have the same name as the
199 * passed name. If the display isn't found it tries the open it.
201 * Returns: a #GdkDisplay of the display with the passed name.
204 ev_display_open_if_needed (const gchar *name)
208 GdkDisplay *display = NULL;
210 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
212 for (l = displays; l != NULL; l = l->next) {
213 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
215 if (g_ascii_strcasecmp (display_name, name) == 0) {
221 g_slist_free (displays);
223 return display != NULL ? display : gdk_display_open (name);
227 * get_screen_from_args:
228 * @args: a #GHashTable with data passed to the application.
230 * Looks for the screen in the display available in the hash table passed to the
231 * application. If the display isn't opened, it's opened and the #GdkScreen
232 * assigned to the screen in that display returned.
234 * Returns: the #GdkScreen assigned to the screen on the display indicated by
235 * the data on the #GHashTable.
238 get_screen_from_args (GHashTable *args)
240 GValue *value = NULL;
241 GdkDisplay *display = NULL;
242 GdkScreen *screen = NULL;
244 g_assert (args != NULL);
246 value = g_hash_table_lookup (args, "display");
248 const gchar *display_name;
250 display_name = g_value_get_string (value);
251 display = ev_display_open_if_needed (display_name);
254 value = g_hash_table_lookup (args, "screen");
258 screen_number = g_value_get_int (value);
259 screen = gdk_display_get_screen (display, screen_number);
266 * get_window_run_mode_from_args:
267 * @args: a #GHashTable with data passed to the application.
269 * It does look if the mode option has been passed from command line, using it
270 * as the window run mode, otherwise the run mode will be the normal mode.
272 * Returns: The window run mode passed from command line or
273 * EV_WINDOW_MODE_NORMAL in other case.
275 static EvWindowRunMode
276 get_window_run_mode_from_args (GHashTable *args)
278 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
279 GValue *value = NULL;
281 g_assert (args != NULL);
283 value = g_hash_table_lookup (args, "mode");
285 mode = g_value_get_uint (value);
292 * get_destination_from_args:
293 * @args: a #GHashTable with data passed to the application.
295 * It does look for the page-label argument parsed from the command line and
296 * if it does exist, it returns an #EvLinkDest.
298 * Returns: An #EvLinkDest to page-label if it has been passed from the command
299 * line, NULL in other case.
302 get_destination_from_args (GHashTable *args)
304 EvLinkDest *dest = NULL;
305 GValue *value = NULL;
307 g_assert (args != NULL);
309 value = g_hash_table_lookup (args, "page-label");
311 const gchar *page_label;
313 page_label = g_value_get_string (value);
314 dest = ev_link_dest_new_page_label (page_label);
321 get_find_string_from_args (GHashTable *args)
323 GValue *value = NULL;
325 g_assert (args != NULL);
327 value = g_hash_table_lookup (args, "find-string");
329 return value ? g_value_get_string (value) : NULL;
333 value_free (GValue *value)
335 g_value_unset (value);
340 build_args (GdkScreen *screen,
342 EvWindowRunMode mode,
343 const gchar *search_string)
348 const gchar *display_name;
351 args = g_hash_table_new_full (g_str_hash,
353 (GDestroyNotify)g_free,
354 (GDestroyNotify)value_free);
357 display = gdk_screen_get_display (screen);
358 display_name = gdk_display_get_name (display);
359 value = g_new0 (GValue, 1);
360 g_value_init (value, G_TYPE_STRING);
361 g_value_set_string (value, display_name);
362 g_hash_table_insert (args, g_strdup ("display"), value);
365 screen_number = gdk_screen_get_number (screen);
366 value = g_new0 (GValue, 1);
367 g_value_init (value, G_TYPE_INT);
368 g_value_set_int (value, screen_number);
369 g_hash_table_insert (args, g_strdup ("screen"), value);
373 value = g_new0 (GValue, 1);
374 g_value_init (value, G_TYPE_STRING);
375 g_value_set_string (value, ev_link_dest_get_page_label (dest));
377 g_hash_table_insert (args, g_strdup ("page-label"), value);
382 value = g_new0 (GValue, 1);
383 g_value_init (value, G_TYPE_STRING);
384 g_value_set_string (value, search_string);
386 g_hash_table_insert (args, g_strdup ("find-string"), value);
390 if (mode != EV_WINDOW_MODE_NORMAL) {
391 value = g_new0 (GValue, 1);
392 g_value_init (value, G_TYPE_UINT);
393 g_value_set_uint (value, mode);
395 g_hash_table_insert (args, g_strdup ("mode"), value);
402 ev_spawn (const char *uri,
405 EvWindowRunMode mode,
406 const gchar *search_string)
412 GError *error = NULL;
414 argv[arg++] = g_build_filename (BINDIR, "evince", NULL);
418 const gchar *page_label;
420 page_label = ev_link_dest_get_page_label (dest);
422 argv[arg++] = g_strdup_printf ("--page-label=%s", page_label);
424 argv[arg++] = g_strdup_printf ("--page-label=%d",
425 ev_link_dest_get_page (dest));
430 argv[arg++] = g_strdup_printf ("--find=%s", search_string);
435 case EV_WINDOW_MODE_FULLSCREEN:
436 argv[arg++] = g_strdup ("-f");
438 case EV_WINDOW_MODE_PRESENTATION:
439 argv[arg++] = g_strdup ("-s");
445 argv[arg++] = (gchar *)uri;
448 res = gdk_spawn_on_screen (screen, NULL /* wd */, argv, NULL /* env */,
449 0, NULL, NULL, NULL, &error);
451 g_warning ("Error launching evince %s: %s\n", uri, error->message);
452 g_error_free (error);
455 for (i = 0; i < arg - 1; i++) {
462 ev_application_register_uri (EvApplication *application,
469 gboolean retval = TRUE;
470 GError *error = NULL;
472 if (!application->connection)
475 proxy = dbus_g_proxy_new_for_name (application->connection,
476 "org.gnome.evince.Daemon",
477 "/org/gnome/evince/Daemon",
478 "org.gnome.evince.Daemon");
479 if (!dbus_g_proxy_call (proxy, "RegisterDocument", &error,
482 G_TYPE_STRING, &owner,
484 g_warning ("Error registering document: %s\n", error->message);
485 g_error_free (error);
486 g_object_unref (proxy);
490 g_object_unref (proxy);
493 /* Already registered */
494 proxy = dbus_g_proxy_new_for_name_owner (application->connection,
496 APPLICATION_DBUS_OBJECT_PATH,
497 APPLICATION_DBUS_INTERFACE,
500 if (!dbus_g_proxy_call (proxy, "OpenURI", &error,
502 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), args,
503 G_TYPE_UINT, timestamp,
506 g_warning ("%s", error->message);
507 g_error_free (error);
509 g_object_unref (proxy);
511 g_warning ("Error creating proxy: %s\n", error->message);
512 g_error_free (error);
515 /* Do not continue opening this document */
525 ev_application_unregister_uri (EvApplication *application,
529 GError *error = NULL;
531 if (!application->connection)
534 proxy = dbus_g_proxy_new_for_name (application->connection,
535 "org.gnome.evince.Daemon",
536 "/org/gnome/evince/Daemon",
537 "org.gnome.evince.Daemon");
538 if (!dbus_g_proxy_call (proxy, "UnregisterDocument", &error,
542 g_warning ("Error unregistering document: %s\n", error->message);
543 g_error_free (error);
546 g_object_unref (proxy);
548 #endif /* ENABLE_DBUS */
551 ev_application_open_uri_in_window (EvApplication *application,
555 EvWindowRunMode mode,
556 const gchar *search_string,
559 EvWindow *ev_window = application->window;
562 ev_stock_icons_set_screen (screen);
563 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
566 /* We need to load uri before showing the window, so
567 we can restore window size without flickering */
568 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
570 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (ev_window)))
571 gtk_widget_realize (GTK_WIDGET (ev_window));
573 #ifdef GDK_WINDOWING_X11
575 timestamp = gdk_x11_get_server_time (GTK_WIDGET (ev_window)->window);
576 gdk_x11_window_set_user_time (GTK_WIDGET (ev_window)->window, timestamp);
578 ev_document_fc_mutex_lock ();
579 gtk_window_present (GTK_WINDOW (ev_window));
580 ev_document_fc_mutex_unlock ();
582 ev_document_fc_mutex_lock ();
583 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
584 ev_document_fc_mutex_unlock ();
585 #endif /* GDK_WINDOWING_X11 */
589 * ev_application_open_uri_at_dest:
590 * @application: The instance of the application.
591 * @uri: The uri to be opened.
592 * @screen: Thee screen where the link will be shown.
593 * @dest: The #EvLinkDest of the document.
594 * @mode: The run mode of the window.
595 * @timestamp: Current time value.
598 ev_application_open_uri_at_dest (EvApplication *application,
602 EvWindowRunMode mode,
603 const gchar *search_string,
606 g_return_if_fail (uri != NULL);
608 if (application->window && !ev_window_is_empty (application->window)) {
609 if (application->uri && strcmp (application->uri, uri) != 0) {
610 /* spawn a new evince process */
611 ev_spawn (uri, screen, dest, mode, search_string);
616 GHashTable *args = build_args (screen, dest, mode, search_string);
619 /* Register the uri or send OpenURI to
620 * remote instance if already registered
622 ret = ev_application_register_uri (application, uri, args, timestamp);
623 g_hash_table_destroy (args);
626 #endif /* ENABLE_DBUS */
628 if (!application->window)
629 application->window = EV_WINDOW (ev_window_new ());
632 application->uri = g_strdup (uri);
634 ev_application_open_uri_in_window (application, uri,
641 * ev_application_open_window:
642 * @application: The instance of the application.
643 * @timestamp: Current time value.
645 * Creates a new window
648 ev_application_open_window (EvApplication *application,
652 GtkWidget *new_window = ev_window_new ();
654 application->window = EV_WINDOW (new_window);
657 ev_stock_icons_set_screen (screen);
658 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
661 if (!GTK_WIDGET_REALIZED (new_window))
662 gtk_widget_realize (new_window);
664 #ifdef GDK_WINDOWING_X11
666 timestamp = gdk_x11_get_server_time (new_window->window);
667 gdk_x11_window_set_user_time (new_window->window, timestamp);
669 gtk_window_present (GTK_WINDOW (new_window));
671 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
672 #endif /* GDK_WINDOWING_X11 */
676 * ev_application_open_uri:
677 * @application: The instance of the application.
678 * @uri: The uri to be opened
679 * @args: A #GHashTable with the arguments data.
680 * @timestamp: Current time value.
681 * @error: The #GError facility.
684 ev_application_open_uri (EvApplication *application,
690 EvLinkDest *dest = NULL;
691 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
692 const gchar *search_string = NULL;
693 GdkScreen *screen = NULL;
695 g_assert (application->window != NULL);
697 /* FIXME: we don't need uri anymore,
698 * maybe this method should be renamed
699 * as reload, refresh or something like that
701 if (!application->uri || strcmp (application->uri, uri)) {
702 g_warning ("Invalid uri: %s, expected %s\n",
703 uri, application->uri);
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_in_window (application, uri,
720 g_object_unref (dest);
726 ev_application_open_uri_list (EvApplication *application,
733 for (l = uri_list; l != NULL; l = l->next) {
734 ev_application_open_uri_at_dest (application, (char *)l->data,
735 screen, NULL, 0, NULL,
741 ev_application_shutdown (EvApplication *application)
743 if (application->uri) {
745 ev_application_unregister_uri (application,
748 g_free (application->uri);
749 application->uri = NULL;
752 if (application->accel_map_file) {
753 gtk_accel_map_save (application->accel_map_file);
754 g_free (application->accel_map_file);
755 application->accel_map_file = NULL;
758 if (application->toolbars_model) {
759 g_object_unref (application->toolbars_model);
760 g_free (application->toolbars_file);
761 application->toolbars_model = NULL;
762 application->toolbars_file = NULL;
765 ev_application_save_print_settings (application);
767 if (application->print_settings_file) {
768 g_key_file_free (application->print_settings_file);
769 application->print_settings_file = NULL;
772 if (application->print_settings) {
773 g_object_unref (application->print_settings);
774 application->print_settings = NULL;
777 if (application->page_setup) {
778 g_object_unref (application->page_setup);
779 application->page_setup = NULL;
783 if (application->keys) {
784 g_object_unref (application->keys);
785 application->keys = NULL;
787 #endif /* ENABLE_DBUS */
789 g_free (application->dot_dir);
790 application->dot_dir = NULL;
791 g_free (application->data_dir);
792 application->data_dir = NULL;
793 g_free (application->filechooser_open_uri);
794 application->filechooser_open_uri = NULL;
795 g_free (application->filechooser_save_uri);
796 application->filechooser_save_uri = NULL;
798 g_object_unref (application);
805 ev_application_class_init (EvApplicationClass *ev_application_class)
808 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
809 &dbus_glib_ev_application_object_info);
814 ev_application_init (EvApplication *ev_application)
817 const gchar *home_dir;
819 GError *error = NULL;
821 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
826 /* FIXME: why make this fatal? */
827 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
834 dir = g_win32_get_package_installation_directory_of_module (NULL);
835 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
839 ev_application->data_dir = g_strdup (DATADIR);
842 ev_application_init_session (ev_application);
844 home_dir = g_get_home_dir ();
846 ev_application->accel_map_file = g_build_filename (home_dir,
851 gtk_accel_map_load (ev_application->accel_map_file);
854 ev_application->toolbars_model = egg_toolbars_model_new ();
856 ev_application->toolbars_file = g_build_filename
857 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
859 toolbar_path = g_build_filename (ev_application->data_dir,
860 "evince-toolbar.xml", NULL);
861 egg_toolbars_model_load_names (ev_application->toolbars_model,
864 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
865 ev_application->toolbars_file)) {
866 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
869 g_free (toolbar_path);
871 /* Open item doesn't exist anymore,
872 * convert it to OpenRecent for compatibility
874 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
877 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
878 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
879 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
880 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
882 ev_application_save_toolbars_model (ev_application);
887 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
888 EGG_TB_MODEL_NOT_REMOVABLE);
891 ev_application->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
892 if (ev_application->connection) {
893 dbus_g_connection_register_g_object (ev_application->connection,
894 APPLICATION_DBUS_OBJECT_PATH,
895 G_OBJECT (ev_application));
896 ev_application->scr_saver = totem_scrsaver_new (ev_application->connection);
898 g_warning ("Error connection to DBus: %s\n", error->message);
899 g_error_free (error);
901 ev_application->keys = ev_media_player_keys_new ();
902 #endif /* ENABLE_DBUS */
906 ev_application_has_window (EvApplication *application)
908 return application->window != NULL;
912 ev_application_get_uri (EvApplication *application)
914 return application->uri;
918 * ev_application_get_media_keys:
919 * @application: The instance of the application.
921 * It gives you access to the media player keys handler object.
923 * Returns: A #EvMediaPlayerKeys.
926 ev_application_get_media_keys (EvApplication *application)
929 return G_OBJECT (application->keys);
932 #endif /* ENABLE_DBUS */
936 ev_application_get_toolbars_model (EvApplication *application)
938 return application->toolbars_model;
942 ev_application_save_toolbars_model (EvApplication *application)
944 egg_toolbars_model_save_toolbars (application->toolbars_model,
945 application->toolbars_file, "1.0");
949 ev_application_set_filechooser_uri (EvApplication *application,
950 GtkFileChooserAction action,
953 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
954 g_free (application->filechooser_open_uri);
955 application->filechooser_open_uri = g_strdup (uri);
956 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
957 g_free (application->filechooser_save_uri);
958 application->filechooser_save_uri = g_strdup (uri);
963 ev_application_get_filechooser_uri (EvApplication *application,
964 GtkFileChooserAction action)
966 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
967 if (application->filechooser_open_uri)
968 return application->filechooser_open_uri;
969 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
970 if (application->filechooser_save_uri)
971 return application->filechooser_save_uri;
978 ev_application_screensaver_enable (EvApplication *application)
980 if (application->scr_saver)
981 totem_scrsaver_enable (application->scr_saver);
985 ev_application_screensaver_disable (EvApplication *application)
987 if (application->scr_saver)
988 totem_scrsaver_disable (application->scr_saver);
992 ev_application_get_print_settings_file (EvApplication *application)
996 if (application->print_settings_file)
997 return application->print_settings_file;
999 application->print_settings_file = g_key_file_new ();
1001 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1002 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1003 GError *error = NULL;
1005 g_key_file_load_from_file (application->print_settings_file,
1007 G_KEY_FILE_KEEP_COMMENTS |
1008 G_KEY_FILE_KEEP_TRANSLATIONS,
1011 g_warning ("%s", error->message);
1012 g_error_free (error);
1017 return application->print_settings_file;
1021 ev_application_save_print_settings (EvApplication *application)
1027 GError *error = NULL;
1029 if (!application->print_settings && !application->page_setup)
1032 key_file = ev_application_get_print_settings_file (application);
1033 if (application->print_settings)
1034 gtk_print_settings_to_key_file (application->print_settings,
1036 EV_PRINT_SETTINGS_GROUP);
1037 if (application->page_setup)
1038 gtk_page_setup_to_key_file (application->page_setup,
1040 EV_PAGE_SETUP_GROUP);
1042 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1043 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1044 g_file_set_contents (filename, data, data_length, &error);
1046 g_warning ("%s", error->message);
1047 g_error_free (error);
1054 ev_application_get_print_settings (EvApplication *application)
1057 GtkPrintSettings *print_settings;
1059 if (application->print_settings)
1060 return application->print_settings;
1062 key_file = ev_application_get_print_settings_file (application);
1063 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1064 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1065 gtk_print_settings_new ();
1067 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1069 return application->print_settings;
1073 ev_application_set_print_settings (EvApplication *application,
1074 GtkPrintSettings *settings)
1078 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1080 if (settings == application->print_settings)
1083 key_file = ev_application_get_print_settings_file (application);
1085 if (application->print_settings)
1086 g_object_unref (application->print_settings);
1088 application->print_settings = g_object_ref (settings);
1089 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1093 ev_application_get_page_setup (EvApplication *application)
1096 GtkPageSetup *page_setup;
1098 if (application->page_setup)
1099 return application->page_setup;
1101 key_file = ev_application_get_print_settings_file (application);
1102 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1103 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1104 gtk_page_setup_new ();
1106 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1108 return application->page_setup;
1112 ev_application_set_page_setup (EvApplication *application,
1113 GtkPageSetup *page_setup)
1117 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1119 if (page_setup == application->page_setup)
1122 key_file = ev_application_get_print_settings_file (application);
1124 if (application->page_setup)
1125 g_object_unref (application->page_setup);
1127 application->page_setup = g_object_ref (page_setup);
1128 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1132 ev_application_get_dot_dir (EvApplication *application)
1134 return application->dot_dir;
1138 ev_application_get_data_dir (EvApplication *application)
1140 return application->data_dir;