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 *filechooser_open_uri;
72 gchar *filechooser_save_uri;
75 EvMediaPlayerKeys *keys;
76 #endif /* ENABLE_DBUS */
78 GtkPrintSettings *print_settings;
79 GtkPageSetup *page_setup;
80 GKeyFile *print_settings_file;
83 struct _EvApplicationClass {
84 GObjectClass base_class;
87 static EvApplication *instance;
89 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
91 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
93 #define EV_PRINT_SETTINGS_FILE "print-settings"
94 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
95 #define EV_PAGE_SETUP_GROUP "Page Setup"
99 ev_application_register_service (EvApplication *application)
101 static DBusGConnection *connection = NULL;
102 DBusGProxy *driver_proxy;
104 guint request_name_result;
107 g_warning ("Service already registered.");
111 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
112 if (connection == NULL) {
113 g_warning ("Service registration failed.");
119 driver_proxy = dbus_g_proxy_new_for_name (connection,
122 DBUS_INTERFACE_DBUS);
124 if (!org_freedesktop_DBus_request_name (driver_proxy,
125 APPLICATION_SERVICE_NAME,
126 DBUS_NAME_FLAG_DO_NOT_QUEUE,
127 &request_name_result, &err)) {
128 g_warning ("Service registration failed.");
129 g_clear_error (&err);
132 g_object_unref (driver_proxy);
134 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
138 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
139 &dbus_glib_ev_application_object_info);
140 dbus_g_connection_register_g_object (connection,
141 "/org/gnome/evince/Evince",
142 G_OBJECT (application));
144 application->scr_saver = totem_scrsaver_new (connection);
146 ev_metadata_manager_init ();
150 #endif /* ENABLE_DBUS */
153 * ev_application_get_instance:
155 * Checks for #EvApplication instance, if it doesn't exist it does create it.
157 * Returns: an instance of the #EvApplication data.
160 ev_application_get_instance (void)
163 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
171 save_session (EvApplication *application,
173 GKeyFile *state_file)
177 const gchar **uri_list;
178 const gchar *empty = "empty-window";
180 uri_list = g_new (const gchar *, g_list_length (windows_list));
181 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
182 EvWindow *window = EV_WINDOW (l->data);
184 if (ev_window_is_empty (window))
187 uri_list[i] = ev_window_get_uri (window);
189 g_key_file_set_string_list (state_file,
192 (const char **)uri_list,
198 ev_application_save_session_crashed (EvApplication *application)
202 windows = ev_application_get_windows (application);
204 GKeyFile *crashed_file;
207 GError *error = NULL;
209 crashed_file = g_key_file_new ();
210 save_session (application, windows, crashed_file);
212 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
213 g_file_set_contents (application->crashed_file, data, data_length, &error);
215 g_warning ("%s", error->message);
216 g_error_free (error);
219 g_key_file_free (crashed_file);
220 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
223 file = g_file_new_for_path (application->crashed_file);
224 g_file_delete (file, NULL, NULL);
225 g_object_unref (file);
230 save_session_crashed_in_idle_cb (EvApplication *application)
232 ev_application_save_session_crashed (application);
233 application->crashed_idle = 0;
239 save_session_crashed_in_idle (EvApplication *application)
241 if (application->crashed_idle > 0)
242 g_source_remove (application->crashed_idle);
243 application->crashed_idle =
244 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
249 ev_application_run_crash_recovery_dialog (EvApplication *application)
254 dialog = gtk_message_dialog_new (NULL,
258 _("Recover previous documents?"));
259 gtk_message_dialog_format_secondary_text (
260 GTK_MESSAGE_DIALOG (dialog),
261 _("Evince appears to have exited unexpectedly the last time "
262 "it was run. You can recover the opened documents."));
264 gtk_dialog_add_button (GTK_DIALOG (dialog),
266 GTK_RESPONSE_CANCEL);
267 gtk_dialog_add_button (GTK_DIALOG (dialog),
269 GTK_RESPONSE_ACCEPT);
271 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
272 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
273 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
274 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
275 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
277 response = gtk_dialog_run (GTK_DIALOG (dialog));
278 gtk_widget_destroy (dialog);
280 return response == GTK_RESPONSE_ACCEPT;
284 ev_application_load_session (EvApplication *application)
286 GKeyFile *state_file;
289 if (egg_sm_client_is_resumed (application->smclient)) {
290 state_file = egg_sm_client_get_state_file (application->smclient);
293 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
294 if (ev_application_run_crash_recovery_dialog (application)) {
295 state_file = g_key_file_new ();
296 g_key_file_load_from_file (state_file,
297 application->crashed_file,
307 uri_list = g_key_file_get_string_list (state_file,
314 for (i = 0; uri_list[i]; i++) {
315 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
316 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
318 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
320 g_strfreev (uri_list);
322 g_key_file_free (state_file);
328 smclient_save_state_cb (EggSMClient *client,
329 GKeyFile *state_file,
330 EvApplication *application)
334 windows = ev_application_get_windows (application);
336 save_session (application, windows, state_file);
337 g_list_free (windows);
342 smclient_quit_cb (EggSMClient *client,
343 EvApplication *application)
345 ev_application_shutdown (application);
349 ev_application_init_session (EvApplication *application)
351 application->crashed_file = g_build_filename (application->dot_dir,
352 "evince-crashed", NULL);
354 application->smclient = egg_sm_client_get ();
355 g_signal_connect (application->smclient, "save_state",
356 G_CALLBACK (smclient_save_state_cb),
358 g_signal_connect (application->smclient, "quit",
359 G_CALLBACK (smclient_quit_cb),
364 * ev_display_open_if_needed:
365 * @name: the name of the display to be open if it's needed.
367 * Search among all the open displays if any of them have the same name as the
368 * passed name. If the display isn't found it tries the open it.
370 * Returns: a #GdkDisplay of the display with the passed name.
373 ev_display_open_if_needed (const gchar *name)
377 GdkDisplay *display = NULL;
379 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
381 for (l = displays; l != NULL; l = l->next) {
382 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
384 if (g_ascii_strcasecmp (display_name, name) == 0) {
390 g_slist_free (displays);
392 return display != NULL ? display : gdk_display_open (name);
396 * get_screen_from_args:
397 * @args: a #GHashTable with data passed to the application.
399 * Looks for the screen in the display available in the hash table passed to the
400 * application. If the display isn't opened, it's opened and the #GdkScreen
401 * assigned to the screen in that display returned.
403 * Returns: the #GdkScreen assigned to the screen on the display indicated by
404 * the data on the #GHashTable.
407 get_screen_from_args (GHashTable *args)
409 GValue *value = NULL;
410 GdkDisplay *display = NULL;
411 GdkScreen *screen = NULL;
413 g_assert (args != NULL);
415 value = g_hash_table_lookup (args, "display");
417 const gchar *display_name;
419 display_name = g_value_get_string (value);
420 display = ev_display_open_if_needed (display_name);
423 value = g_hash_table_lookup (args, "screen");
427 screen_number = g_value_get_int (value);
428 screen = gdk_display_get_screen (display, screen_number);
435 * get_window_run_mode_from_args:
436 * @args: a #GHashTable with data passed to the application.
438 * It does look if the mode option has been passed from command line, using it
439 * as the window run mode, otherwise the run mode will be the normal mode.
441 * Returns: The window run mode passed from command line or
442 * EV_WINDOW_MODE_NORMAL in other case.
444 static EvWindowRunMode
445 get_window_run_mode_from_args (GHashTable *args)
447 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
448 GValue *value = NULL;
450 g_assert (args != NULL);
452 value = g_hash_table_lookup (args, "mode");
454 mode = g_value_get_uint (value);
461 * get_destination_from_args:
462 * @args: a #GHashTable with data passed to the application.
464 * It does look for the page-label argument parsed from the command line and
465 * if it does exist, it returns an #EvLinkDest.
467 * Returns: An #EvLinkDest to page-label if it has been passed from the command
468 * line, NULL in other case.
471 get_destination_from_args (GHashTable *args)
473 EvLinkDest *dest = NULL;
474 GValue *value = NULL;
476 g_assert (args != NULL);
478 value = g_hash_table_lookup (args, "page-label");
480 const gchar *page_label;
482 page_label = g_value_get_string (value);
483 dest = ev_link_dest_new_page_label (page_label);
490 get_find_string_from_args (GHashTable *args)
492 GValue *value = NULL;
494 g_assert (args != NULL);
496 value = g_hash_table_lookup (args, "find-string");
498 return value ? g_value_get_string (value) : NULL;
502 * ev_application_open_window:
503 * @application: The instance of the application.
504 * @args: A #GHashTable with the arguments data.
505 * @timestamp: Current time value.
506 * @error: The #GError facility.
508 * Creates a new window and if the args are available, it's not NULL, it gets
509 * the screen from them and assigns the just created window to it. At last it
515 ev_application_open_window (EvApplication *application,
520 GtkWidget *new_window = ev_window_new ();
521 GdkScreen *screen = NULL;
524 screen = get_screen_from_args (args);
528 ev_stock_icons_set_screen (screen);
529 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
532 ev_application_save_session_crashed (application);
533 g_signal_connect_swapped (new_window, "destroy",
534 G_CALLBACK (save_session_crashed_in_idle),
537 if (!GTK_WIDGET_REALIZED (new_window))
538 gtk_widget_realize (new_window);
540 #ifdef GDK_WINDOWING_X11
542 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
543 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
545 gtk_window_present (GTK_WINDOW (new_window));
547 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
548 #endif /* GDK_WINDOWING_X11 */
554 * ev_application_get_empty_window:
555 * @application: The instance of the application.
556 * @screen: The screen where the empty window will be search.
558 * It does look if there is any empty window in the indicated screen.
560 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
564 ev_application_get_empty_window (EvApplication *application,
567 EvWindow *empty_window = NULL;
568 GList *windows = ev_application_get_windows (application);
571 for (l = windows; l != NULL; l = l->next) {
572 EvWindow *window = EV_WINDOW (l->data);
574 if (ev_window_is_empty (window) &&
575 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
576 empty_window = window;
581 g_list_free (windows);
587 * ev_application_get_uri_window:
588 * @application: The instance of the application.
589 * @uri: The uri to be opened.
591 * It looks in the list of the windows for the one with the document represented
592 * by the passed uri on it. If the window is empty or the document isn't present
593 * on any window, it will return NULL.
595 * Returns: The #EvWindow where the document represented by the passed uri is
596 * shown, NULL in other case.
599 ev_application_get_uri_window (EvApplication *application, const char *uri)
601 EvWindow *uri_window = NULL;
602 GList *windows = gtk_window_list_toplevels ();
605 g_return_val_if_fail (uri != NULL, NULL);
607 for (l = windows; l != NULL; l = l->next) {
608 if (EV_IS_WINDOW (l->data)) {
609 EvWindow *window = EV_WINDOW (l->data);
610 const char *window_uri = ev_window_get_uri (window);
612 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
619 g_list_free (windows);
625 * ev_application_open_uri_at_dest:
626 * @application: The instance of the application.
627 * @uri: The uri to be opened.
628 * @screen: Thee screen where the link will be shown.
629 * @dest: The #EvLinkDest of the document.
630 * @mode: The run mode of the window.
631 * @timestamp: Current time value.
634 ev_application_open_uri_at_dest (EvApplication *application,
638 EvWindowRunMode mode,
639 const gchar *search_string,
642 EvWindow *new_window;
644 g_return_if_fail (uri != NULL);
646 new_window = ev_application_get_uri_window (application, uri);
648 if (new_window == NULL) {
649 new_window = ev_application_get_empty_window (application, screen);
652 if (new_window == NULL) {
653 new_window = EV_WINDOW (ev_window_new ());
657 ev_stock_icons_set_screen (screen);
658 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
661 /* We need to load uri before showing the window, so
662 we can restore window size without flickering */
663 ev_window_open_uri (new_window, uri, dest, mode, search_string);
665 ev_application_save_session_crashed (application);
666 g_signal_connect_swapped (new_window, "destroy",
667 G_CALLBACK (save_session_crashed_in_idle),
670 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
671 gtk_widget_realize (GTK_WIDGET (new_window));
673 #ifdef GDK_WINDOWING_X11
675 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
676 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
678 ev_document_fc_mutex_lock ();
679 gtk_window_present (GTK_WINDOW (new_window));
680 ev_document_fc_mutex_unlock ();
682 ev_document_fc_mutex_lock ();
683 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
684 ev_document_fc_mutex_unlock ();
685 #endif /* GDK_WINDOWING_X11 */
689 * ev_application_open_uri:
690 * @application: The instance of the application.
691 * @uri: The uri to be opened
692 * @args: A #GHashTable with the arguments data.
693 * @timestamp: Current time value.
694 * @error: The #GError facility.
697 ev_application_open_uri (EvApplication *application,
703 EvLinkDest *dest = NULL;
704 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
705 const gchar *search_string = NULL;
706 GdkScreen *screen = NULL;
709 screen = get_screen_from_args (args);
710 dest = get_destination_from_args (args);
711 mode = get_window_run_mode_from_args (args);
712 search_string = get_find_string_from_args (args);
715 ev_application_open_uri_at_dest (application, uri, screen,
716 dest, mode, search_string,
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->crashed_file) {
744 ev_application_save_session_crashed (application);
745 g_free (application->crashed_file);
746 application->crashed_file = NULL;
749 if (application->accel_map_file) {
750 gtk_accel_map_save (application->accel_map_file);
751 g_free (application->accel_map_file);
752 application->accel_map_file = NULL;
755 if (application->toolbars_model) {
756 g_object_unref (application->toolbars_model);
757 g_free (application->toolbars_file);
758 application->toolbars_model = NULL;
759 application->toolbars_file = NULL;
762 ev_application_save_print_settings (application);
764 if (application->print_settings_file) {
765 g_key_file_free (application->print_settings_file);
766 application->print_settings_file = NULL;
769 if (application->print_settings) {
770 g_object_unref (application->print_settings);
771 application->print_settings = NULL;
774 if (application->page_setup) {
775 g_object_unref (application->page_setup);
776 application->page_setup = NULL;
780 if (application->keys) {
781 g_object_unref (application->keys);
782 application->keys = NULL;
784 #endif /* ENABLE_DBUS */
786 ev_metadata_manager_shutdown ();
788 g_free (application->dot_dir);
789 application->dot_dir = NULL;
790 g_free (application->filechooser_open_uri);
791 application->filechooser_open_uri = NULL;
792 g_free (application->filechooser_save_uri);
793 application->filechooser_save_uri = NULL;
795 g_object_unref (application);
802 ev_application_class_init (EvApplicationClass *ev_application_class)
807 ev_application_init (EvApplication *ev_application)
810 const gchar *home_dir;
812 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
817 /* FIXME: why make this fatal? */
818 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
821 ev_application_init_session (ev_application);
823 home_dir = g_get_home_dir ();
825 ev_application->accel_map_file = g_build_filename (home_dir,
830 gtk_accel_map_load (ev_application->accel_map_file);
833 ev_application->toolbars_model = egg_toolbars_model_new ();
835 ev_application->toolbars_file = g_build_filename
836 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
838 egg_toolbars_model_load_names (ev_application->toolbars_model,
839 DATADIR "/evince-toolbar.xml");
841 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
842 ev_application->toolbars_file)) {
843 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
844 DATADIR"/evince-toolbar.xml");
847 /* Open item doesn't exist anymore,
848 * convert it to OpenRecent for compatibility
850 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
853 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
854 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
855 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
856 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
858 ev_application_save_toolbars_model (ev_application);
863 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
864 EGG_TB_MODEL_NOT_REMOVABLE);
867 ev_application->keys = ev_media_player_keys_new ();
868 #endif /* ENABLE_DBUS */
872 * ev_application_get_windows:
873 * @application: The instance of the application.
875 * It creates a list of the top level windows.
877 * Returns: A #GList of the top level windows.
880 ev_application_get_windows (EvApplication *application)
882 GList *l, *toplevels;
883 GList *windows = NULL;
885 toplevels = gtk_window_list_toplevels ();
887 for (l = toplevels; l != NULL; l = l->next) {
888 if (EV_IS_WINDOW (l->data)) {
889 windows = g_list_append (windows, l->data);
893 g_list_free (toplevels);
899 * ev_application_get_media_keys:
900 * @application: The instance of the application.
902 * It gives you access to the media player keys handler object.
904 * Returns: A #EvMediaPlayerKeys.
907 ev_application_get_media_keys (EvApplication *application)
910 return G_OBJECT (application->keys);
913 #endif /* ENABLE_DBUS */
917 ev_application_get_toolbars_model (EvApplication *application)
919 return application->toolbars_model;
923 ev_application_save_toolbars_model (EvApplication *application)
925 egg_toolbars_model_save_toolbars (application->toolbars_model,
926 application->toolbars_file, "1.0");
930 ev_application_set_filechooser_uri (EvApplication *application,
931 GtkFileChooserAction action,
934 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
935 g_free (application->filechooser_open_uri);
936 application->filechooser_open_uri = g_strdup (uri);
937 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
938 g_free (application->filechooser_save_uri);
939 application->filechooser_save_uri = g_strdup (uri);
944 ev_application_get_filechooser_uri (EvApplication *application,
945 GtkFileChooserAction action)
947 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
948 if (application->filechooser_open_uri)
949 return application->filechooser_open_uri;
950 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
951 if (application->filechooser_save_uri)
952 return application->filechooser_save_uri;
959 ev_application_screensaver_enable (EvApplication *application)
961 if (application->scr_saver)
962 totem_scrsaver_enable (application->scr_saver);
966 ev_application_screensaver_disable (EvApplication *application)
968 if (application->scr_saver)
969 totem_scrsaver_disable (application->scr_saver);
973 ev_application_get_print_settings_file (EvApplication *application)
977 if (application->print_settings_file)
978 return application->print_settings_file;
980 application->print_settings_file = g_key_file_new ();
982 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
983 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
984 GError *error = NULL;
986 g_key_file_load_from_file (application->print_settings_file,
988 G_KEY_FILE_KEEP_COMMENTS |
989 G_KEY_FILE_KEEP_TRANSLATIONS,
992 g_warning ("%s", error->message);
993 g_error_free (error);
998 return application->print_settings_file;
1002 ev_application_save_print_settings (EvApplication *application)
1008 GError *error = NULL;
1010 if (!application->print_settings && !application->page_setup)
1013 key_file = ev_application_get_print_settings_file (application);
1014 if (application->print_settings)
1015 gtk_print_settings_to_key_file (application->print_settings,
1017 EV_PRINT_SETTINGS_GROUP);
1018 if (application->page_setup)
1019 gtk_page_setup_to_key_file (application->page_setup,
1021 EV_PAGE_SETUP_GROUP);
1023 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1024 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1025 g_file_set_contents (filename, data, data_length, &error);
1027 g_warning ("%s", error->message);
1028 g_error_free (error);
1035 ev_application_get_print_settings (EvApplication *application)
1038 GtkPrintSettings *print_settings;
1040 if (application->print_settings)
1041 return application->print_settings;
1043 key_file = ev_application_get_print_settings_file (application);
1044 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1045 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1046 gtk_print_settings_new ();
1048 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1050 return application->print_settings;
1054 ev_application_set_print_settings (EvApplication *application,
1055 GtkPrintSettings *settings)
1059 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1061 if (settings == application->print_settings)
1064 key_file = ev_application_get_print_settings_file (application);
1066 if (application->print_settings)
1067 g_object_unref (application->print_settings);
1069 application->print_settings = g_object_ref (settings);
1070 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1074 ev_application_get_page_setup (EvApplication *application)
1077 GtkPageSetup *page_setup;
1079 if (application->page_setup)
1080 return application->page_setup;
1082 key_file = ev_application_get_print_settings_file (application);
1083 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1084 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1085 gtk_page_setup_new ();
1087 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1089 return application->page_setup;
1093 ev_application_set_page_setup (EvApplication *application,
1094 GtkPageSetup *page_setup)
1098 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1100 if (page_setup == application->page_setup)
1103 key_file = ev_application_get_print_settings_file (application);
1105 if (application->page_setup)
1106 g_object_unref (application->page_setup);
1108 application->page_setup = g_object_ref (page_setup);
1109 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1113 ev_application_get_dot_dir (EvApplication *application)
1115 return application->dot_dir;