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;
72 EggToolbarsModel *toolbars_model;
74 TotemScrsaver *scr_saver;
77 EggSMClient *smclient;
80 gchar *filechooser_open_uri;
81 gchar *filechooser_save_uri;
84 EvMediaPlayerKeys *keys;
85 #endif /* ENABLE_DBUS */
87 GtkPrintSettings *print_settings;
88 GtkPageSetup *page_setup;
89 GKeyFile *print_settings_file;
92 struct _EvApplicationClass {
93 GObjectClass base_class;
96 static EvApplication *instance;
98 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
100 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
102 #define EV_PRINT_SETTINGS_FILE "print-settings"
103 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
104 #define EV_PAGE_SETUP_GROUP "Page Setup"
108 ev_application_register_service (EvApplication *application)
110 static DBusGConnection *connection = NULL;
111 DBusGProxy *driver_proxy;
113 guint request_name_result;
116 g_warning ("Service already registered.");
120 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
121 if (connection == NULL) {
122 g_warning ("Service registration failed.");
128 driver_proxy = dbus_g_proxy_new_for_name (connection,
131 DBUS_INTERFACE_DBUS);
133 if (!org_freedesktop_DBus_request_name (driver_proxy,
134 APPLICATION_SERVICE_NAME,
135 DBUS_NAME_FLAG_DO_NOT_QUEUE,
136 &request_name_result, &err)) {
137 g_warning ("Service registration failed.");
138 g_clear_error (&err);
141 g_object_unref (driver_proxy);
143 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
147 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
148 &dbus_glib_ev_application_object_info);
149 dbus_g_connection_register_g_object (connection,
150 "/org/gnome/evince/Evince",
151 G_OBJECT (application));
153 application->scr_saver = totem_scrsaver_new (connection);
155 ev_metadata_manager_init ();
159 #endif /* ENABLE_DBUS */
162 * ev_application_get_instance:
164 * Checks for #EvApplication instance, if it doesn't exist it does create it.
166 * Returns: an instance of the #EvApplication data.
169 ev_application_get_instance (void)
172 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
180 save_session (EvApplication *application,
182 GKeyFile *state_file)
186 const gchar **uri_list;
187 const gchar *empty = "empty-window";
189 uri_list = g_new (const gchar *, g_list_length (windows_list));
190 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
191 EvWindow *window = EV_WINDOW (l->data);
193 if (ev_window_is_empty (window))
196 uri_list[i] = ev_window_get_uri (window);
198 g_key_file_set_string_list (state_file,
201 (const char **)uri_list,
208 ev_application_save_session_crashed (EvApplication *application)
212 windows = ev_application_get_windows (application);
214 GKeyFile *crashed_file;
217 GError *error = NULL;
219 crashed_file = g_key_file_new ();
220 save_session (application, windows, crashed_file);
222 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
223 g_file_set_contents (application->crashed_file, data, data_length, &error);
225 g_warning ("%s", error->message);
226 g_error_free (error);
229 g_key_file_free (crashed_file);
230 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
233 file = g_file_new_for_path (application->crashed_file);
234 g_file_delete (file, NULL, NULL);
235 g_object_unref (file);
240 save_session_crashed_in_idle_cb (EvApplication *application)
242 ev_application_save_session_crashed (application);
243 application->crashed_idle = 0;
249 save_session_crashed_in_idle (EvApplication *application)
251 if (application->crashed_idle > 0)
252 g_source_remove (application->crashed_idle);
253 application->crashed_idle =
254 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
259 ev_application_run_crash_recovery_dialog (EvApplication *application)
264 dialog = gtk_message_dialog_new (NULL,
268 _("Recover previous documents?"));
269 gtk_message_dialog_format_secondary_text (
270 GTK_MESSAGE_DIALOG (dialog),
271 _("Evince appears to have exited unexpectedly the last time "
272 "it was run. You can recover the opened documents."));
274 gtk_dialog_add_button (GTK_DIALOG (dialog),
276 GTK_RESPONSE_CANCEL);
277 gtk_dialog_add_button (GTK_DIALOG (dialog),
279 GTK_RESPONSE_ACCEPT);
281 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
282 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
283 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
284 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
285 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
287 response = gtk_dialog_run (GTK_DIALOG (dialog));
288 gtk_widget_destroy (dialog);
290 return response == GTK_RESPONSE_ACCEPT;
292 #endif /* ENABLE_DBUS */
295 ev_application_load_session (EvApplication *application)
297 GKeyFile *state_file;
301 if (egg_sm_client_is_resumed (application->smclient)) {
302 state_file = egg_sm_client_get_state_file (application->smclient);
306 #endif /* WITH_SMCLIENT */
308 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
309 if (ev_application_run_crash_recovery_dialog (application)) {
310 state_file = g_key_file_new ();
311 g_key_file_load_from_file (state_file,
312 application->crashed_file,
319 #endif /* ENABLE_DBUS */
322 uri_list = g_key_file_get_string_list (state_file,
329 for (i = 0; uri_list[i]; i++) {
330 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
331 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
333 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
335 g_strfreev (uri_list);
337 g_key_file_free (state_file);
345 smclient_save_state_cb (EggSMClient *client,
346 GKeyFile *state_file,
347 EvApplication *application)
351 windows = ev_application_get_windows (application);
353 save_session (application, windows, state_file);
354 g_list_free (windows);
359 smclient_quit_cb (EggSMClient *client,
360 EvApplication *application)
362 ev_application_shutdown (application);
365 #endif /* WITH_SMCLIENT */
368 ev_application_init_session (EvApplication *application)
371 application->crashed_file = g_build_filename (application->dot_dir,
372 "evince-crashed", NULL);
376 application->smclient = egg_sm_client_get ();
377 g_signal_connect (application->smclient, "save_state",
378 G_CALLBACK (smclient_save_state_cb),
380 g_signal_connect (application->smclient, "quit",
381 G_CALLBACK (smclient_quit_cb),
387 * ev_display_open_if_needed:
388 * @name: the name of the display to be open if it's needed.
390 * Search among all the open displays if any of them have the same name as the
391 * passed name. If the display isn't found it tries the open it.
393 * Returns: a #GdkDisplay of the display with the passed name.
396 ev_display_open_if_needed (const gchar *name)
400 GdkDisplay *display = NULL;
402 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
404 for (l = displays; l != NULL; l = l->next) {
405 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
407 if (g_ascii_strcasecmp (display_name, name) == 0) {
413 g_slist_free (displays);
415 return display != NULL ? display : gdk_display_open (name);
419 * get_screen_from_args:
420 * @args: a #GHashTable with data passed to the application.
422 * Looks for the screen in the display available in the hash table passed to the
423 * application. If the display isn't opened, it's opened and the #GdkScreen
424 * assigned to the screen in that display returned.
426 * Returns: the #GdkScreen assigned to the screen on the display indicated by
427 * the data on the #GHashTable.
430 get_screen_from_args (GHashTable *args)
432 GValue *value = NULL;
433 GdkDisplay *display = NULL;
434 GdkScreen *screen = NULL;
436 g_assert (args != NULL);
438 value = g_hash_table_lookup (args, "display");
440 const gchar *display_name;
442 display_name = g_value_get_string (value);
443 display = ev_display_open_if_needed (display_name);
446 value = g_hash_table_lookup (args, "screen");
450 screen_number = g_value_get_int (value);
451 screen = gdk_display_get_screen (display, screen_number);
458 * get_window_run_mode_from_args:
459 * @args: a #GHashTable with data passed to the application.
461 * It does look if the mode option has been passed from command line, using it
462 * as the window run mode, otherwise the run mode will be the normal mode.
464 * Returns: The window run mode passed from command line or
465 * EV_WINDOW_MODE_NORMAL in other case.
467 static EvWindowRunMode
468 get_window_run_mode_from_args (GHashTable *args)
470 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
471 GValue *value = NULL;
473 g_assert (args != NULL);
475 value = g_hash_table_lookup (args, "mode");
477 mode = g_value_get_uint (value);
484 * get_destination_from_args:
485 * @args: a #GHashTable with data passed to the application.
487 * It does look for the page-label argument parsed from the command line and
488 * if it does exist, it returns an #EvLinkDest.
490 * Returns: An #EvLinkDest to page-label if it has been passed from the command
491 * line, NULL in other case.
494 get_destination_from_args (GHashTable *args)
496 EvLinkDest *dest = NULL;
497 GValue *value = NULL;
499 g_assert (args != NULL);
501 value = g_hash_table_lookup (args, "page-label");
503 const gchar *page_label;
505 page_label = g_value_get_string (value);
506 dest = ev_link_dest_new_page_label (page_label);
513 get_find_string_from_args (GHashTable *args)
515 GValue *value = NULL;
517 g_assert (args != NULL);
519 value = g_hash_table_lookup (args, "find-string");
521 return value ? g_value_get_string (value) : NULL;
525 * ev_application_open_window:
526 * @application: The instance of the application.
527 * @args: A #GHashTable with the arguments data.
528 * @timestamp: Current time value.
529 * @error: The #GError facility.
531 * Creates a new window and if the args are available, it's not NULL, it gets
532 * the screen from them and assigns the just created window to it. At last it
538 ev_application_open_window (EvApplication *application,
543 GtkWidget *new_window = ev_window_new ();
544 GdkScreen *screen = NULL;
547 screen = get_screen_from_args (args);
551 ev_stock_icons_set_screen (screen);
552 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
556 ev_application_save_session_crashed (application);
557 g_signal_connect_swapped (new_window, "destroy",
558 G_CALLBACK (save_session_crashed_in_idle),
562 if (!GTK_WIDGET_REALIZED (new_window))
563 gtk_widget_realize (new_window);
565 #ifdef GDK_WINDOWING_X11
567 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
568 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
570 gtk_window_present (GTK_WINDOW (new_window));
572 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
573 #endif /* GDK_WINDOWING_X11 */
579 * ev_application_get_empty_window:
580 * @application: The instance of the application.
581 * @screen: The screen where the empty window will be search.
583 * It does look if there is any empty window in the indicated screen.
585 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
589 ev_application_get_empty_window (EvApplication *application,
592 EvWindow *empty_window = NULL;
593 GList *windows = ev_application_get_windows (application);
596 for (l = windows; l != NULL; l = l->next) {
597 EvWindow *window = EV_WINDOW (l->data);
599 if (ev_window_is_empty (window) &&
600 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
601 empty_window = window;
606 g_list_free (windows);
612 * ev_application_get_uri_window:
613 * @application: The instance of the application.
614 * @uri: The uri to be opened.
616 * It looks in the list of the windows for the one with the document represented
617 * by the passed uri on it. If the window is empty or the document isn't present
618 * on any window, it will return NULL.
620 * Returns: The #EvWindow where the document represented by the passed uri is
621 * shown, NULL in other case.
624 ev_application_get_uri_window (EvApplication *application, const char *uri)
626 EvWindow *uri_window = NULL;
627 GList *windows = gtk_window_list_toplevels ();
630 g_return_val_if_fail (uri != NULL, NULL);
632 for (l = windows; l != NULL; l = l->next) {
633 if (EV_IS_WINDOW (l->data)) {
634 EvWindow *window = EV_WINDOW (l->data);
635 const char *window_uri = ev_window_get_uri (window);
637 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
644 g_list_free (windows);
650 * ev_application_open_uri_at_dest:
651 * @application: The instance of the application.
652 * @uri: The uri to be opened.
653 * @screen: Thee screen where the link will be shown.
654 * @dest: The #EvLinkDest of the document.
655 * @mode: The run mode of the window.
656 * @timestamp: Current time value.
659 ev_application_open_uri_at_dest (EvApplication *application,
663 EvWindowRunMode mode,
664 const gchar *search_string,
667 EvWindow *new_window;
669 g_return_if_fail (uri != NULL);
671 new_window = ev_application_get_uri_window (application, uri);
673 if (new_window == NULL) {
674 new_window = ev_application_get_empty_window (application, screen);
677 if (new_window == NULL) {
678 new_window = EV_WINDOW (ev_window_new ());
682 ev_stock_icons_set_screen (screen);
683 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
686 /* We need to load uri before showing the window, so
687 we can restore window size without flickering */
688 ev_window_open_uri (new_window, uri, dest, mode, search_string);
691 ev_application_save_session_crashed (application);
692 g_signal_connect_swapped (new_window, "destroy",
693 G_CALLBACK (save_session_crashed_in_idle),
697 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
698 gtk_widget_realize (GTK_WIDGET (new_window));
700 #ifdef GDK_WINDOWING_X11
702 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
703 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
705 ev_document_fc_mutex_lock ();
706 gtk_window_present (GTK_WINDOW (new_window));
707 ev_document_fc_mutex_unlock ();
709 ev_document_fc_mutex_lock ();
710 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
711 ev_document_fc_mutex_unlock ();
712 #endif /* GDK_WINDOWING_X11 */
716 * ev_application_open_uri:
717 * @application: The instance of the application.
718 * @uri: The uri to be opened
719 * @args: A #GHashTable with the arguments data.
720 * @timestamp: Current time value.
721 * @error: The #GError facility.
724 ev_application_open_uri (EvApplication *application,
730 EvLinkDest *dest = NULL;
731 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
732 const gchar *search_string = NULL;
733 GdkScreen *screen = NULL;
736 screen = get_screen_from_args (args);
737 dest = get_destination_from_args (args);
738 mode = get_window_run_mode_from_args (args);
739 search_string = get_find_string_from_args (args);
742 ev_application_open_uri_at_dest (application, uri, screen,
743 dest, mode, search_string,
747 g_object_unref (dest);
753 ev_application_open_uri_list (EvApplication *application,
760 for (l = uri_list; l != NULL; l = l->next) {
761 ev_application_open_uri_at_dest (application, (char *)l->data,
762 screen, NULL, 0, NULL,
768 ev_application_shutdown (EvApplication *application)
771 if (application->crashed_file) {
772 ev_application_save_session_crashed (application);
773 g_free (application->crashed_file);
774 application->crashed_file = NULL;
778 if (application->accel_map_file) {
779 gtk_accel_map_save (application->accel_map_file);
780 g_free (application->accel_map_file);
781 application->accel_map_file = NULL;
784 if (application->toolbars_model) {
785 g_object_unref (application->toolbars_model);
786 g_free (application->toolbars_file);
787 application->toolbars_model = NULL;
788 application->toolbars_file = NULL;
791 ev_application_save_print_settings (application);
793 if (application->print_settings_file) {
794 g_key_file_free (application->print_settings_file);
795 application->print_settings_file = NULL;
798 if (application->print_settings) {
799 g_object_unref (application->print_settings);
800 application->print_settings = NULL;
803 if (application->page_setup) {
804 g_object_unref (application->page_setup);
805 application->page_setup = NULL;
809 if (application->keys) {
810 g_object_unref (application->keys);
811 application->keys = NULL;
813 #endif /* ENABLE_DBUS */
815 ev_metadata_manager_shutdown ();
817 g_free (application->dot_dir);
818 application->dot_dir = NULL;
819 g_free (application->data_dir);
820 application->data_dir = NULL;
821 g_free (application->filechooser_open_uri);
822 application->filechooser_open_uri = NULL;
823 g_free (application->filechooser_save_uri);
824 application->filechooser_save_uri = NULL;
826 g_object_unref (application);
833 ev_application_class_init (EvApplicationClass *ev_application_class)
838 ev_application_init (EvApplication *ev_application)
841 const gchar *home_dir;
844 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
849 /* FIXME: why make this fatal? */
850 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
857 dir = g_win32_get_package_installation_directory_of_module (NULL);
858 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
862 ev_application->data_dir = g_strdup (DATADIR);
865 ev_application_init_session (ev_application);
867 home_dir = g_get_home_dir ();
869 ev_application->accel_map_file = g_build_filename (home_dir,
874 gtk_accel_map_load (ev_application->accel_map_file);
877 ev_application->toolbars_model = egg_toolbars_model_new ();
879 ev_application->toolbars_file = g_build_filename
880 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
882 toolbar_path = g_build_filename (ev_application->data_dir,
883 "evince-toolbar.xml", NULL);
884 egg_toolbars_model_load_names (ev_application->toolbars_model,
887 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
888 ev_application->toolbars_file)) {
889 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
892 g_free (toolbar_path);
894 /* Open item doesn't exist anymore,
895 * convert it to OpenRecent for compatibility
897 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
900 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
901 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
902 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
903 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
905 ev_application_save_toolbars_model (ev_application);
910 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
911 EGG_TB_MODEL_NOT_REMOVABLE);
914 ev_application->keys = ev_media_player_keys_new ();
915 #endif /* ENABLE_DBUS */
919 * ev_application_get_windows:
920 * @application: The instance of the application.
922 * It creates a list of the top level windows.
924 * Returns: A #GList of the top level windows.
927 ev_application_get_windows (EvApplication *application)
929 GList *l, *toplevels;
930 GList *windows = NULL;
932 toplevels = gtk_window_list_toplevels ();
934 for (l = toplevels; l != NULL; l = l->next) {
935 if (EV_IS_WINDOW (l->data)) {
936 windows = g_list_append (windows, l->data);
940 g_list_free (toplevels);
946 * ev_application_get_media_keys:
947 * @application: The instance of the application.
949 * It gives you access to the media player keys handler object.
951 * Returns: A #EvMediaPlayerKeys.
954 ev_application_get_media_keys (EvApplication *application)
957 return G_OBJECT (application->keys);
960 #endif /* ENABLE_DBUS */
964 ev_application_get_toolbars_model (EvApplication *application)
966 return application->toolbars_model;
970 ev_application_save_toolbars_model (EvApplication *application)
972 egg_toolbars_model_save_toolbars (application->toolbars_model,
973 application->toolbars_file, "1.0");
977 ev_application_set_filechooser_uri (EvApplication *application,
978 GtkFileChooserAction action,
981 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
982 g_free (application->filechooser_open_uri);
983 application->filechooser_open_uri = g_strdup (uri);
984 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
985 g_free (application->filechooser_save_uri);
986 application->filechooser_save_uri = g_strdup (uri);
991 ev_application_get_filechooser_uri (EvApplication *application,
992 GtkFileChooserAction action)
994 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
995 if (application->filechooser_open_uri)
996 return application->filechooser_open_uri;
997 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
998 if (application->filechooser_save_uri)
999 return application->filechooser_save_uri;
1006 ev_application_screensaver_enable (EvApplication *application)
1008 if (application->scr_saver)
1009 totem_scrsaver_enable (application->scr_saver);
1013 ev_application_screensaver_disable (EvApplication *application)
1015 if (application->scr_saver)
1016 totem_scrsaver_disable (application->scr_saver);
1020 ev_application_get_print_settings_file (EvApplication *application)
1024 if (application->print_settings_file)
1025 return application->print_settings_file;
1027 application->print_settings_file = g_key_file_new ();
1029 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1030 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1031 GError *error = NULL;
1033 g_key_file_load_from_file (application->print_settings_file,
1035 G_KEY_FILE_KEEP_COMMENTS |
1036 G_KEY_FILE_KEEP_TRANSLATIONS,
1039 g_warning ("%s", error->message);
1040 g_error_free (error);
1045 return application->print_settings_file;
1049 ev_application_save_print_settings (EvApplication *application)
1055 GError *error = NULL;
1057 if (!application->print_settings && !application->page_setup)
1060 key_file = ev_application_get_print_settings_file (application);
1061 if (application->print_settings)
1062 gtk_print_settings_to_key_file (application->print_settings,
1064 EV_PRINT_SETTINGS_GROUP);
1065 if (application->page_setup)
1066 gtk_page_setup_to_key_file (application->page_setup,
1068 EV_PAGE_SETUP_GROUP);
1070 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1071 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1072 g_file_set_contents (filename, data, data_length, &error);
1074 g_warning ("%s", error->message);
1075 g_error_free (error);
1082 ev_application_get_print_settings (EvApplication *application)
1085 GtkPrintSettings *print_settings;
1087 if (application->print_settings)
1088 return application->print_settings;
1090 key_file = ev_application_get_print_settings_file (application);
1091 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1092 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1093 gtk_print_settings_new ();
1095 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1097 return application->print_settings;
1101 ev_application_set_print_settings (EvApplication *application,
1102 GtkPrintSettings *settings)
1106 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1108 if (settings == application->print_settings)
1111 key_file = ev_application_get_print_settings_file (application);
1113 if (application->print_settings)
1114 g_object_unref (application->print_settings);
1116 application->print_settings = g_object_ref (settings);
1117 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1121 ev_application_get_page_setup (EvApplication *application)
1124 GtkPageSetup *page_setup;
1126 if (application->page_setup)
1127 return application->page_setup;
1129 key_file = ev_application_get_print_settings_file (application);
1130 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1131 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1132 gtk_page_setup_new ();
1134 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1136 return application->page_setup;
1140 ev_application_set_page_setup (EvApplication *application,
1141 GtkPageSetup *page_setup)
1145 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1147 if (page_setup == application->page_setup)
1150 key_file = ev_application_get_print_settings_file (application);
1152 if (application->page_setup)
1153 g_object_unref (application->page_setup);
1155 application->page_setup = g_object_ref (page_setup);
1156 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1160 ev_application_get_dot_dir (EvApplication *application)
1162 return application->dot_dir;
1166 ev_application_get_data_dir (EvApplication *application)
1168 return application->data_dir;