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"
44 #include "ev-metadata-manager.h"
46 #include "ev-stock-icons.h"
49 #include "ev-media-player-keys.h"
50 #endif /* ENABLE_DBUS */
53 #include <dbus/dbus-glib-bindings.h>
54 #include "ev-application-service.h"
57 static void ev_application_save_print_settings (EvApplication *application);
59 struct _EvApplication {
60 GObject base_instance;
64 gchar *accel_map_file;
69 EggToolbarsModel *toolbars_model;
71 TotemScrsaver *scr_saver;
74 EggSMClient *smclient;
77 gchar *filechooser_open_uri;
78 gchar *filechooser_save_uri;
81 EvMediaPlayerKeys *keys;
82 #endif /* ENABLE_DBUS */
84 GtkPrintSettings *print_settings;
85 GtkPageSetup *page_setup;
86 GKeyFile *print_settings_file;
89 struct _EvApplicationClass {
90 GObjectClass base_class;
93 static EvApplication *instance;
95 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
97 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
99 #define EV_PRINT_SETTINGS_FILE "print-settings"
100 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
101 #define EV_PAGE_SETUP_GROUP "Page Setup"
105 ev_application_register_service (EvApplication *application)
107 static DBusGConnection *connection = NULL;
108 DBusGProxy *driver_proxy;
110 guint request_name_result;
113 g_warning ("Service already registered.");
117 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
118 if (connection == NULL) {
119 g_warning ("Service registration failed.");
125 driver_proxy = dbus_g_proxy_new_for_name (connection,
128 DBUS_INTERFACE_DBUS);
130 if (!org_freedesktop_DBus_request_name (driver_proxy,
131 APPLICATION_SERVICE_NAME,
132 DBUS_NAME_FLAG_DO_NOT_QUEUE,
133 &request_name_result, &err)) {
134 g_warning ("Service registration failed.");
135 g_clear_error (&err);
138 g_object_unref (driver_proxy);
140 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
144 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
145 &dbus_glib_ev_application_object_info);
146 dbus_g_connection_register_g_object (connection,
147 "/org/gnome/evince/Evince",
148 G_OBJECT (application));
150 application->scr_saver = totem_scrsaver_new (connection);
152 ev_metadata_manager_init ();
156 #endif /* ENABLE_DBUS */
159 * ev_application_get_instance:
161 * Checks for #EvApplication instance, if it doesn't exist it does create it.
163 * Returns: an instance of the #EvApplication data.
166 ev_application_get_instance (void)
169 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
177 save_session (EvApplication *application,
179 GKeyFile *state_file)
183 const gchar **uri_list;
184 const gchar *empty = "empty-window";
186 uri_list = g_new (const gchar *, g_list_length (windows_list));
187 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
188 EvWindow *window = EV_WINDOW (l->data);
190 if (ev_window_is_empty (window))
193 uri_list[i] = ev_window_get_uri (window);
195 g_key_file_set_string_list (state_file,
198 (const char **)uri_list,
204 ev_application_save_session_crashed (EvApplication *application)
208 windows = ev_application_get_windows (application);
210 GKeyFile *crashed_file;
213 GError *error = NULL;
215 crashed_file = g_key_file_new ();
216 save_session (application, windows, crashed_file);
218 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
219 g_file_set_contents (application->crashed_file, data, data_length, &error);
221 g_warning ("%s", error->message);
222 g_error_free (error);
225 g_key_file_free (crashed_file);
226 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
229 file = g_file_new_for_path (application->crashed_file);
230 g_file_delete (file, NULL, NULL);
231 g_object_unref (file);
236 save_session_crashed_in_idle_cb (EvApplication *application)
238 ev_application_save_session_crashed (application);
239 application->crashed_idle = 0;
245 save_session_crashed_in_idle (EvApplication *application)
247 if (application->crashed_idle > 0)
248 g_source_remove (application->crashed_idle);
249 application->crashed_idle =
250 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
255 ev_application_run_crash_recovery_dialog (EvApplication *application)
260 dialog = gtk_message_dialog_new (NULL,
264 _("Recover previous documents?"));
265 gtk_message_dialog_format_secondary_text (
266 GTK_MESSAGE_DIALOG (dialog),
267 _("Evince appears to have exited unexpectedly the last time "
268 "it was run. You can recover the opened documents."));
270 gtk_dialog_add_button (GTK_DIALOG (dialog),
272 GTK_RESPONSE_CANCEL);
273 gtk_dialog_add_button (GTK_DIALOG (dialog),
275 GTK_RESPONSE_ACCEPT);
277 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
278 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
279 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
280 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
281 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
283 response = gtk_dialog_run (GTK_DIALOG (dialog));
284 gtk_widget_destroy (dialog);
286 return response == GTK_RESPONSE_ACCEPT;
290 ev_application_load_session (EvApplication *application)
292 GKeyFile *state_file;
296 if (egg_sm_client_is_resumed (application->smclient)) {
297 state_file = egg_sm_client_get_state_file (application->smclient);
301 #endif /* WITH_SMCLIENT */
302 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
303 if (ev_application_run_crash_recovery_dialog (application)) {
304 state_file = g_key_file_new ();
305 g_key_file_load_from_file (state_file,
306 application->crashed_file,
316 uri_list = g_key_file_get_string_list (state_file,
323 for (i = 0; uri_list[i]; i++) {
324 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
325 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
327 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
329 g_strfreev (uri_list);
331 g_key_file_free (state_file);
339 smclient_save_state_cb (EggSMClient *client,
340 GKeyFile *state_file,
341 EvApplication *application)
345 windows = ev_application_get_windows (application);
347 save_session (application, windows, state_file);
348 g_list_free (windows);
353 smclient_quit_cb (EggSMClient *client,
354 EvApplication *application)
356 ev_application_shutdown (application);
359 #endif /* WITH_SMCLIENT */
362 ev_application_init_session (EvApplication *application)
364 application->crashed_file = g_build_filename (application->dot_dir,
365 "evince-crashed", NULL);
368 application->smclient = egg_sm_client_get ();
369 g_signal_connect (application->smclient, "save_state",
370 G_CALLBACK (smclient_save_state_cb),
372 g_signal_connect (application->smclient, "quit",
373 G_CALLBACK (smclient_quit_cb),
379 * ev_display_open_if_needed:
380 * @name: the name of the display to be open if it's needed.
382 * Search among all the open displays if any of them have the same name as the
383 * passed name. If the display isn't found it tries the open it.
385 * Returns: a #GdkDisplay of the display with the passed name.
388 ev_display_open_if_needed (const gchar *name)
392 GdkDisplay *display = NULL;
394 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
396 for (l = displays; l != NULL; l = l->next) {
397 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
399 if (g_ascii_strcasecmp (display_name, name) == 0) {
405 g_slist_free (displays);
407 return display != NULL ? display : gdk_display_open (name);
411 * get_screen_from_args:
412 * @args: a #GHashTable with data passed to the application.
414 * Looks for the screen in the display available in the hash table passed to the
415 * application. If the display isn't opened, it's opened and the #GdkScreen
416 * assigned to the screen in that display returned.
418 * Returns: the #GdkScreen assigned to the screen on the display indicated by
419 * the data on the #GHashTable.
422 get_screen_from_args (GHashTable *args)
424 GValue *value = NULL;
425 GdkDisplay *display = NULL;
426 GdkScreen *screen = NULL;
428 g_assert (args != NULL);
430 value = g_hash_table_lookup (args, "display");
432 const gchar *display_name;
434 display_name = g_value_get_string (value);
435 display = ev_display_open_if_needed (display_name);
438 value = g_hash_table_lookup (args, "screen");
442 screen_number = g_value_get_int (value);
443 screen = gdk_display_get_screen (display, screen_number);
450 * get_window_run_mode_from_args:
451 * @args: a #GHashTable with data passed to the application.
453 * It does look if the mode option has been passed from command line, using it
454 * as the window run mode, otherwise the run mode will be the normal mode.
456 * Returns: The window run mode passed from command line or
457 * EV_WINDOW_MODE_NORMAL in other case.
459 static EvWindowRunMode
460 get_window_run_mode_from_args (GHashTable *args)
462 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
463 GValue *value = NULL;
465 g_assert (args != NULL);
467 value = g_hash_table_lookup (args, "mode");
469 mode = g_value_get_uint (value);
476 * get_destination_from_args:
477 * @args: a #GHashTable with data passed to the application.
479 * It does look for the page-label argument parsed from the command line and
480 * if it does exist, it returns an #EvLinkDest.
482 * Returns: An #EvLinkDest to page-label if it has been passed from the command
483 * line, NULL in other case.
486 get_destination_from_args (GHashTable *args)
488 EvLinkDest *dest = NULL;
489 GValue *value = NULL;
491 g_assert (args != NULL);
493 value = g_hash_table_lookup (args, "page-label");
495 const gchar *page_label;
497 page_label = g_value_get_string (value);
498 dest = ev_link_dest_new_page_label (page_label);
505 get_find_string_from_args (GHashTable *args)
507 GValue *value = NULL;
509 g_assert (args != NULL);
511 value = g_hash_table_lookup (args, "find-string");
513 return value ? g_value_get_string (value) : NULL;
517 * ev_application_open_window:
518 * @application: The instance of the application.
519 * @args: A #GHashTable with the arguments data.
520 * @timestamp: Current time value.
521 * @error: The #GError facility.
523 * Creates a new window and if the args are available, it's not NULL, it gets
524 * the screen from them and assigns the just created window to it. At last it
530 ev_application_open_window (EvApplication *application,
535 GtkWidget *new_window = ev_window_new ();
536 GdkScreen *screen = NULL;
539 screen = get_screen_from_args (args);
543 ev_stock_icons_set_screen (screen);
544 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
547 ev_application_save_session_crashed (application);
548 g_signal_connect_swapped (new_window, "destroy",
549 G_CALLBACK (save_session_crashed_in_idle),
552 if (!GTK_WIDGET_REALIZED (new_window))
553 gtk_widget_realize (new_window);
555 #ifdef GDK_WINDOWING_X11
557 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
558 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
560 gtk_window_present (GTK_WINDOW (new_window));
562 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
563 #endif /* GDK_WINDOWING_X11 */
569 * ev_application_get_empty_window:
570 * @application: The instance of the application.
571 * @screen: The screen where the empty window will be search.
573 * It does look if there is any empty window in the indicated screen.
575 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
579 ev_application_get_empty_window (EvApplication *application,
582 EvWindow *empty_window = NULL;
583 GList *windows = ev_application_get_windows (application);
586 for (l = windows; l != NULL; l = l->next) {
587 EvWindow *window = EV_WINDOW (l->data);
589 if (ev_window_is_empty (window) &&
590 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
591 empty_window = window;
596 g_list_free (windows);
602 * ev_application_get_uri_window:
603 * @application: The instance of the application.
604 * @uri: The uri to be opened.
606 * It looks in the list of the windows for the one with the document represented
607 * by the passed uri on it. If the window is empty or the document isn't present
608 * on any window, it will return NULL.
610 * Returns: The #EvWindow where the document represented by the passed uri is
611 * shown, NULL in other case.
614 ev_application_get_uri_window (EvApplication *application, const char *uri)
616 EvWindow *uri_window = NULL;
617 GList *windows = gtk_window_list_toplevels ();
620 g_return_val_if_fail (uri != NULL, NULL);
622 for (l = windows; l != NULL; l = l->next) {
623 if (EV_IS_WINDOW (l->data)) {
624 EvWindow *window = EV_WINDOW (l->data);
625 const char *window_uri = ev_window_get_uri (window);
627 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
634 g_list_free (windows);
640 * ev_application_open_uri_at_dest:
641 * @application: The instance of the application.
642 * @uri: The uri to be opened.
643 * @screen: Thee screen where the link will be shown.
644 * @dest: The #EvLinkDest of the document.
645 * @mode: The run mode of the window.
646 * @timestamp: Current time value.
649 ev_application_open_uri_at_dest (EvApplication *application,
653 EvWindowRunMode mode,
654 const gchar *search_string,
657 EvWindow *new_window;
659 g_return_if_fail (uri != NULL);
661 new_window = ev_application_get_uri_window (application, uri);
663 if (new_window == NULL) {
664 new_window = ev_application_get_empty_window (application, screen);
667 if (new_window == NULL) {
668 new_window = EV_WINDOW (ev_window_new ());
672 ev_stock_icons_set_screen (screen);
673 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
676 /* We need to load uri before showing the window, so
677 we can restore window size without flickering */
678 ev_window_open_uri (new_window, uri, dest, mode, search_string);
680 ev_application_save_session_crashed (application);
681 g_signal_connect_swapped (new_window, "destroy",
682 G_CALLBACK (save_session_crashed_in_idle),
685 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
686 gtk_widget_realize (GTK_WIDGET (new_window));
688 #ifdef GDK_WINDOWING_X11
690 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
691 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
693 ev_document_fc_mutex_lock ();
694 gtk_window_present (GTK_WINDOW (new_window));
695 ev_document_fc_mutex_unlock ();
697 ev_document_fc_mutex_lock ();
698 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
699 ev_document_fc_mutex_unlock ();
700 #endif /* GDK_WINDOWING_X11 */
704 * ev_application_open_uri:
705 * @application: The instance of the application.
706 * @uri: The uri to be opened
707 * @args: A #GHashTable with the arguments data.
708 * @timestamp: Current time value.
709 * @error: The #GError facility.
712 ev_application_open_uri (EvApplication *application,
718 EvLinkDest *dest = NULL;
719 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
720 const gchar *search_string = NULL;
721 GdkScreen *screen = NULL;
724 screen = get_screen_from_args (args);
725 dest = get_destination_from_args (args);
726 mode = get_window_run_mode_from_args (args);
727 search_string = get_find_string_from_args (args);
730 ev_application_open_uri_at_dest (application, uri, screen,
731 dest, mode, search_string,
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->crashed_file) {
759 ev_application_save_session_crashed (application);
760 g_free (application->crashed_file);
761 application->crashed_file = NULL;
764 if (application->accel_map_file) {
765 gtk_accel_map_save (application->accel_map_file);
766 g_free (application->accel_map_file);
767 application->accel_map_file = NULL;
770 if (application->toolbars_model) {
771 g_object_unref (application->toolbars_model);
772 g_free (application->toolbars_file);
773 application->toolbars_model = NULL;
774 application->toolbars_file = NULL;
777 ev_application_save_print_settings (application);
779 if (application->print_settings_file) {
780 g_key_file_free (application->print_settings_file);
781 application->print_settings_file = NULL;
784 if (application->print_settings) {
785 g_object_unref (application->print_settings);
786 application->print_settings = NULL;
789 if (application->page_setup) {
790 g_object_unref (application->page_setup);
791 application->page_setup = NULL;
795 if (application->keys) {
796 g_object_unref (application->keys);
797 application->keys = NULL;
799 #endif /* ENABLE_DBUS */
801 ev_metadata_manager_shutdown ();
803 g_free (application->dot_dir);
804 application->dot_dir = NULL;
805 g_free (application->data_dir);
806 application->data_dir = NULL;
807 g_free (application->filechooser_open_uri);
808 application->filechooser_open_uri = NULL;
809 g_free (application->filechooser_save_uri);
810 application->filechooser_save_uri = NULL;
812 g_object_unref (application);
819 ev_application_class_init (EvApplicationClass *ev_application_class)
824 ev_application_init (EvApplication *ev_application)
827 const gchar *home_dir;
830 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
835 /* FIXME: why make this fatal? */
836 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
843 dir = g_win32_get_package_installation_directory_of_module (NULL);
844 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
848 ev_application->data_dir = g_strdup (DATADIR);
851 ev_application_init_session (ev_application);
853 home_dir = g_get_home_dir ();
855 ev_application->accel_map_file = g_build_filename (home_dir,
860 gtk_accel_map_load (ev_application->accel_map_file);
863 ev_application->toolbars_model = egg_toolbars_model_new ();
865 ev_application->toolbars_file = g_build_filename
866 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
868 toolbar_path = g_build_filename (ev_application->data_dir,
869 "evince-toolbar.xml", NULL);
870 egg_toolbars_model_load_names (ev_application->toolbars_model,
873 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
874 ev_application->toolbars_file)) {
875 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
878 g_free (toolbar_path);
880 /* Open item doesn't exist anymore,
881 * convert it to OpenRecent for compatibility
883 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
886 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
887 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
888 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
889 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
891 ev_application_save_toolbars_model (ev_application);
896 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
897 EGG_TB_MODEL_NOT_REMOVABLE);
900 ev_application->keys = ev_media_player_keys_new ();
901 #endif /* ENABLE_DBUS */
905 * ev_application_get_windows:
906 * @application: The instance of the application.
908 * It creates a list of the top level windows.
910 * Returns: A #GList of the top level windows.
913 ev_application_get_windows (EvApplication *application)
915 GList *l, *toplevels;
916 GList *windows = NULL;
918 toplevels = gtk_window_list_toplevels ();
920 for (l = toplevels; l != NULL; l = l->next) {
921 if (EV_IS_WINDOW (l->data)) {
922 windows = g_list_append (windows, l->data);
926 g_list_free (toplevels);
932 * ev_application_get_media_keys:
933 * @application: The instance of the application.
935 * It gives you access to the media player keys handler object.
937 * Returns: A #EvMediaPlayerKeys.
940 ev_application_get_media_keys (EvApplication *application)
943 return G_OBJECT (application->keys);
946 #endif /* ENABLE_DBUS */
950 ev_application_get_toolbars_model (EvApplication *application)
952 return application->toolbars_model;
956 ev_application_save_toolbars_model (EvApplication *application)
958 egg_toolbars_model_save_toolbars (application->toolbars_model,
959 application->toolbars_file, "1.0");
963 ev_application_set_filechooser_uri (EvApplication *application,
964 GtkFileChooserAction action,
967 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
968 g_free (application->filechooser_open_uri);
969 application->filechooser_open_uri = g_strdup (uri);
970 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
971 g_free (application->filechooser_save_uri);
972 application->filechooser_save_uri = g_strdup (uri);
977 ev_application_get_filechooser_uri (EvApplication *application,
978 GtkFileChooserAction action)
980 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
981 if (application->filechooser_open_uri)
982 return application->filechooser_open_uri;
983 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
984 if (application->filechooser_save_uri)
985 return application->filechooser_save_uri;
992 ev_application_screensaver_enable (EvApplication *application)
994 if (application->scr_saver)
995 totem_scrsaver_enable (application->scr_saver);
999 ev_application_screensaver_disable (EvApplication *application)
1001 if (application->scr_saver)
1002 totem_scrsaver_disable (application->scr_saver);
1006 ev_application_get_print_settings_file (EvApplication *application)
1010 if (application->print_settings_file)
1011 return application->print_settings_file;
1013 application->print_settings_file = g_key_file_new ();
1015 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1016 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1017 GError *error = NULL;
1019 g_key_file_load_from_file (application->print_settings_file,
1021 G_KEY_FILE_KEEP_COMMENTS |
1022 G_KEY_FILE_KEEP_TRANSLATIONS,
1025 g_warning ("%s", error->message);
1026 g_error_free (error);
1031 return application->print_settings_file;
1035 ev_application_save_print_settings (EvApplication *application)
1041 GError *error = NULL;
1043 if (!application->print_settings && !application->page_setup)
1046 key_file = ev_application_get_print_settings_file (application);
1047 if (application->print_settings)
1048 gtk_print_settings_to_key_file (application->print_settings,
1050 EV_PRINT_SETTINGS_GROUP);
1051 if (application->page_setup)
1052 gtk_page_setup_to_key_file (application->page_setup,
1054 EV_PAGE_SETUP_GROUP);
1056 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1057 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1058 g_file_set_contents (filename, data, data_length, &error);
1060 g_warning ("%s", error->message);
1061 g_error_free (error);
1068 ev_application_get_print_settings (EvApplication *application)
1071 GtkPrintSettings *print_settings;
1073 if (application->print_settings)
1074 return application->print_settings;
1076 key_file = ev_application_get_print_settings_file (application);
1077 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1078 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1079 gtk_print_settings_new ();
1081 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1083 return application->print_settings;
1087 ev_application_set_print_settings (EvApplication *application,
1088 GtkPrintSettings *settings)
1092 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1094 if (settings == application->print_settings)
1097 key_file = ev_application_get_print_settings_file (application);
1099 if (application->print_settings)
1100 g_object_unref (application->print_settings);
1102 application->print_settings = g_object_ref (settings);
1103 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1107 ev_application_get_page_setup (EvApplication *application)
1110 GtkPageSetup *page_setup;
1112 if (application->page_setup)
1113 return application->page_setup;
1115 key_file = ev_application_get_print_settings_file (application);
1116 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1117 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1118 gtk_page_setup_new ();
1120 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1122 return application->page_setup;
1126 ev_application_set_page_setup (EvApplication *application,
1127 GtkPageSetup *page_setup)
1131 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1133 if (page_setup == application->page_setup)
1136 key_file = ev_application_get_print_settings_file (application);
1138 if (application->page_setup)
1139 g_object_unref (application->page_setup);
1141 application->page_setup = g_object_ref (page_setup);
1142 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1146 ev_application_get_dot_dir (EvApplication *application)
1148 return application->dot_dir;
1152 ev_application_get_data_dir (EvApplication *application)
1154 return application->data_dir;