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 child_setup (gpointer user_data)
406 startup_id = g_strdup_printf ("_TIME%lu",
407 (unsigned long)GPOINTER_TO_INT (user_data));
408 g_setenv ("DESKTOP_STARTUP_ID", startup_id, TRUE);
413 ev_spawn (const char *uri,
416 EvWindowRunMode mode,
417 const gchar *search_string,
424 GError *error = NULL;
426 argv[arg++] = g_build_filename (BINDIR, "evince", NULL);
430 const gchar *page_label;
432 page_label = ev_link_dest_get_page_label (dest);
434 argv[arg++] = g_strdup_printf ("--page-label=%s", page_label);
436 argv[arg++] = g_strdup_printf ("--page-label=%d",
437 ev_link_dest_get_page (dest));
442 argv[arg++] = g_strdup_printf ("--find=%s", search_string);
447 case EV_WINDOW_MODE_FULLSCREEN:
448 argv[arg++] = g_strdup ("-f");
450 case EV_WINDOW_MODE_PRESENTATION:
451 argv[arg++] = g_strdup ("-s");
457 argv[arg++] = (gchar *)uri;
460 res = gdk_spawn_on_screen (screen, NULL /* wd */, argv, NULL /* env */,
463 GINT_TO_POINTER(timestamp),
466 g_warning ("Error launching evince %s: %s\n", uri, error->message);
467 g_error_free (error);
470 for (i = 0; i < arg - 1; i++) {
477 ev_application_register_uri (EvApplication *application,
484 gboolean retval = TRUE;
485 GError *error = NULL;
487 if (!application->connection)
490 proxy = dbus_g_proxy_new_for_name (application->connection,
491 "org.gnome.evince.Daemon",
492 "/org/gnome/evince/Daemon",
493 "org.gnome.evince.Daemon");
494 if (!dbus_g_proxy_call (proxy, "RegisterDocument", &error,
497 G_TYPE_STRING, &owner,
499 g_warning ("Error registering document: %s\n", error->message);
500 g_error_free (error);
501 g_object_unref (proxy);
505 g_object_unref (proxy);
508 /* Already registered */
509 proxy = dbus_g_proxy_new_for_name_owner (application->connection,
511 APPLICATION_DBUS_OBJECT_PATH,
512 APPLICATION_DBUS_INTERFACE,
515 if (!dbus_g_proxy_call (proxy, "OpenURI", &error,
517 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), args,
518 G_TYPE_UINT, timestamp,
521 g_warning ("%s", error->message);
522 g_error_free (error);
524 g_object_unref (proxy);
526 g_warning ("Error creating proxy: %s\n", error->message);
527 g_error_free (error);
530 /* Do not continue opening this document */
540 ev_application_unregister_uri (EvApplication *application,
544 GError *error = NULL;
546 if (!application->connection)
549 proxy = dbus_g_proxy_new_for_name (application->connection,
550 "org.gnome.evince.Daemon",
551 "/org/gnome/evince/Daemon",
552 "org.gnome.evince.Daemon");
553 if (!dbus_g_proxy_call (proxy, "UnregisterDocument", &error,
557 g_warning ("Error unregistering document: %s\n", error->message);
558 g_error_free (error);
561 g_object_unref (proxy);
563 #endif /* ENABLE_DBUS */
566 ev_application_open_uri_in_window (EvApplication *application,
570 EvWindowRunMode mode,
571 const gchar *search_string,
574 EvWindow *ev_window = application->window;
577 ev_stock_icons_set_screen (screen);
578 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
581 /* We need to load uri before showing the window, so
582 we can restore window size without flickering */
583 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
585 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (ev_window)))
586 gtk_widget_realize (GTK_WIDGET (ev_window));
588 #ifdef GDK_WINDOWING_X11
590 timestamp = gdk_x11_get_server_time (GTK_WIDGET (ev_window)->window);
591 gdk_x11_window_set_user_time (GTK_WIDGET (ev_window)->window, timestamp);
593 ev_document_fc_mutex_lock ();
594 gtk_window_present (GTK_WINDOW (ev_window));
595 ev_document_fc_mutex_unlock ();
597 ev_document_fc_mutex_lock ();
598 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
599 ev_document_fc_mutex_unlock ();
600 #endif /* GDK_WINDOWING_X11 */
604 * ev_application_open_uri_at_dest:
605 * @application: The instance of the application.
606 * @uri: The uri to be opened.
607 * @screen: Thee screen where the link will be shown.
608 * @dest: The #EvLinkDest of the document.
609 * @mode: The run mode of the window.
610 * @timestamp: Current time value.
613 ev_application_open_uri_at_dest (EvApplication *application,
617 EvWindowRunMode mode,
618 const gchar *search_string,
621 g_return_if_fail (uri != NULL);
623 if (application->window && !ev_window_is_empty (application->window)) {
624 if (application->uri && strcmp (application->uri, uri) != 0) {
625 /* spawn a new evince process */
626 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
631 GHashTable *args = build_args (screen, dest, mode, search_string);
634 /* Register the uri or send OpenURI to
635 * remote instance if already registered
637 ret = ev_application_register_uri (application, uri, args, timestamp);
638 g_hash_table_destroy (args);
641 #endif /* ENABLE_DBUS */
643 if (!application->window)
644 application->window = EV_WINDOW (ev_window_new ());
647 application->uri = g_strdup (uri);
649 ev_application_open_uri_in_window (application, uri,
656 * ev_application_open_window:
657 * @application: The instance of the application.
658 * @timestamp: Current time value.
660 * Creates a new window
663 ev_application_open_window (EvApplication *application,
667 GtkWidget *new_window = ev_window_new ();
669 application->window = EV_WINDOW (new_window);
672 ev_stock_icons_set_screen (screen);
673 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
676 if (!GTK_WIDGET_REALIZED (new_window))
677 gtk_widget_realize (new_window);
679 #ifdef GDK_WINDOWING_X11
681 timestamp = gdk_x11_get_server_time (new_window->window);
682 gdk_x11_window_set_user_time (new_window->window, timestamp);
684 gtk_window_present (GTK_WINDOW (new_window));
686 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
687 #endif /* GDK_WINDOWING_X11 */
691 * ev_application_open_uri:
692 * @application: The instance of the application.
693 * @uri: The uri to be opened
694 * @args: A #GHashTable with the arguments data.
695 * @timestamp: Current time value.
696 * @error: The #GError facility.
699 ev_application_open_uri (EvApplication *application,
705 EvLinkDest *dest = NULL;
706 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
707 const gchar *search_string = NULL;
708 GdkScreen *screen = NULL;
710 g_assert (application->window != NULL);
712 /* FIXME: we don't need uri anymore,
713 * maybe this method should be renamed
714 * as reload, refresh or something like that
716 if (!application->uri || strcmp (application->uri, uri)) {
717 g_warning ("Invalid uri: %s, expected %s\n",
718 uri, application->uri);
723 screen = get_screen_from_args (args);
724 dest = get_destination_from_args (args);
725 mode = get_window_run_mode_from_args (args);
726 search_string = get_find_string_from_args (args);
729 ev_application_open_uri_in_window (application, uri,
735 g_object_unref (dest);
741 ev_application_open_uri_list (EvApplication *application,
748 for (l = uri_list; l != NULL; l = l->next) {
749 ev_application_open_uri_at_dest (application, (char *)l->data,
750 screen, NULL, 0, NULL,
756 ev_application_shutdown (EvApplication *application)
758 if (application->uri) {
760 ev_application_unregister_uri (application,
763 g_free (application->uri);
764 application->uri = NULL;
767 if (application->accel_map_file) {
768 gtk_accel_map_save (application->accel_map_file);
769 g_free (application->accel_map_file);
770 application->accel_map_file = NULL;
773 if (application->toolbars_model) {
774 g_object_unref (application->toolbars_model);
775 g_free (application->toolbars_file);
776 application->toolbars_model = NULL;
777 application->toolbars_file = NULL;
780 ev_application_save_print_settings (application);
782 if (application->print_settings_file) {
783 g_key_file_free (application->print_settings_file);
784 application->print_settings_file = NULL;
787 if (application->print_settings) {
788 g_object_unref (application->print_settings);
789 application->print_settings = NULL;
792 if (application->page_setup) {
793 g_object_unref (application->page_setup);
794 application->page_setup = NULL;
798 if (application->keys) {
799 g_object_unref (application->keys);
800 application->keys = NULL;
802 #endif /* ENABLE_DBUS */
804 g_free (application->dot_dir);
805 application->dot_dir = NULL;
806 g_free (application->data_dir);
807 application->data_dir = NULL;
808 g_free (application->filechooser_open_uri);
809 application->filechooser_open_uri = NULL;
810 g_free (application->filechooser_save_uri);
811 application->filechooser_save_uri = NULL;
813 g_object_unref (application);
820 ev_application_class_init (EvApplicationClass *ev_application_class)
823 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
824 &dbus_glib_ev_application_object_info);
829 ev_application_init (EvApplication *ev_application)
832 const gchar *home_dir;
834 GError *error = NULL;
836 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
841 /* FIXME: why make this fatal? */
842 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
849 dir = g_win32_get_package_installation_directory_of_module (NULL);
850 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
854 ev_application->data_dir = g_strdup (DATADIR);
857 ev_application_init_session (ev_application);
859 home_dir = g_get_home_dir ();
861 ev_application->accel_map_file = g_build_filename (home_dir,
866 gtk_accel_map_load (ev_application->accel_map_file);
869 ev_application->toolbars_model = egg_toolbars_model_new ();
871 ev_application->toolbars_file = g_build_filename
872 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
874 toolbar_path = g_build_filename (ev_application->data_dir,
875 "evince-toolbar.xml", NULL);
876 egg_toolbars_model_load_names (ev_application->toolbars_model,
879 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
880 ev_application->toolbars_file)) {
881 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
884 g_free (toolbar_path);
886 /* Open item doesn't exist anymore,
887 * convert it to OpenRecent for compatibility
889 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
892 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
893 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
894 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
895 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
897 ev_application_save_toolbars_model (ev_application);
902 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
903 EGG_TB_MODEL_NOT_REMOVABLE);
906 ev_application->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
907 if (ev_application->connection) {
908 dbus_g_connection_register_g_object (ev_application->connection,
909 APPLICATION_DBUS_OBJECT_PATH,
910 G_OBJECT (ev_application));
911 ev_application->scr_saver = totem_scrsaver_new (ev_application->connection);
913 g_warning ("Error connection to DBus: %s\n", error->message);
914 g_error_free (error);
916 ev_application->keys = ev_media_player_keys_new ();
917 #endif /* ENABLE_DBUS */
921 ev_application_has_window (EvApplication *application)
923 return application->window != NULL;
927 ev_application_get_uri (EvApplication *application)
929 return application->uri;
933 * ev_application_get_media_keys:
934 * @application: The instance of the application.
936 * It gives you access to the media player keys handler object.
938 * Returns: A #EvMediaPlayerKeys.
941 ev_application_get_media_keys (EvApplication *application)
944 return G_OBJECT (application->keys);
947 #endif /* ENABLE_DBUS */
951 ev_application_get_toolbars_model (EvApplication *application)
953 return application->toolbars_model;
957 ev_application_save_toolbars_model (EvApplication *application)
959 egg_toolbars_model_save_toolbars (application->toolbars_model,
960 application->toolbars_file, "1.0");
964 ev_application_set_filechooser_uri (EvApplication *application,
965 GtkFileChooserAction action,
968 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
969 g_free (application->filechooser_open_uri);
970 application->filechooser_open_uri = g_strdup (uri);
971 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
972 g_free (application->filechooser_save_uri);
973 application->filechooser_save_uri = g_strdup (uri);
978 ev_application_get_filechooser_uri (EvApplication *application,
979 GtkFileChooserAction action)
981 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
982 if (application->filechooser_open_uri)
983 return application->filechooser_open_uri;
984 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
985 if (application->filechooser_save_uri)
986 return application->filechooser_save_uri;
993 ev_application_screensaver_enable (EvApplication *application)
995 if (application->scr_saver)
996 totem_scrsaver_enable (application->scr_saver);
1000 ev_application_screensaver_disable (EvApplication *application)
1002 if (application->scr_saver)
1003 totem_scrsaver_disable (application->scr_saver);
1007 ev_application_get_print_settings_file (EvApplication *application)
1011 if (application->print_settings_file)
1012 return application->print_settings_file;
1014 application->print_settings_file = g_key_file_new ();
1016 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1017 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1018 GError *error = NULL;
1020 g_key_file_load_from_file (application->print_settings_file,
1022 G_KEY_FILE_KEEP_COMMENTS |
1023 G_KEY_FILE_KEEP_TRANSLATIONS,
1026 g_warning ("%s", error->message);
1027 g_error_free (error);
1032 return application->print_settings_file;
1036 ev_application_save_print_settings (EvApplication *application)
1042 GError *error = NULL;
1044 if (!application->print_settings && !application->page_setup)
1047 key_file = ev_application_get_print_settings_file (application);
1048 if (application->print_settings)
1049 gtk_print_settings_to_key_file (application->print_settings,
1051 EV_PRINT_SETTINGS_GROUP);
1052 if (application->page_setup)
1053 gtk_page_setup_to_key_file (application->page_setup,
1055 EV_PAGE_SETUP_GROUP);
1057 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1058 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1059 g_file_set_contents (filename, data, data_length, &error);
1061 g_warning ("%s", error->message);
1062 g_error_free (error);
1069 ev_application_get_print_settings (EvApplication *application)
1072 GtkPrintSettings *print_settings;
1074 if (application->print_settings)
1075 return application->print_settings;
1077 key_file = ev_application_get_print_settings_file (application);
1078 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1079 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1080 gtk_print_settings_new ();
1082 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1084 return application->print_settings;
1088 ev_application_set_print_settings (EvApplication *application,
1089 GtkPrintSettings *settings)
1093 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1095 if (settings == application->print_settings)
1098 key_file = ev_application_get_print_settings_file (application);
1100 if (application->print_settings)
1101 g_object_unref (application->print_settings);
1103 application->print_settings = g_object_ref (settings);
1104 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1108 ev_application_get_page_setup (EvApplication *application)
1111 GtkPageSetup *page_setup;
1113 if (application->page_setup)
1114 return application->page_setup;
1116 key_file = ev_application_get_print_settings_file (application);
1117 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1118 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1119 gtk_page_setup_new ();
1121 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1123 return application->page_setup;
1127 ev_application_set_page_setup (EvApplication *application,
1128 GtkPageSetup *page_setup)
1132 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1134 if (page_setup == application->page_setup)
1137 key_file = ev_application_get_print_settings_file (application);
1139 if (application->page_setup)
1140 g_object_unref (application->page_setup);
1142 application->page_setup = g_object_ref (page_setup);
1143 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1147 ev_application_get_dot_dir (EvApplication *application)
1149 return application->dot_dir;
1153 ev_application_get_data_dir (EvApplication *application)
1155 return application->data_dir;