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,
265 /* Do not show the recover dialog if the requested file is the
266 * only one to be recovered
268 if (files && g_strv_length ((gchar **)files) == 1) {
269 GKeyFile *state_file;
272 state_file = g_key_file_new ();
273 g_key_file_load_from_file (state_file,
274 application->crashed_file,
277 uri_list = g_key_file_get_string_list (state_file,
281 if (uri_list && g_strv_length (uri_list) == 1) {
285 file = g_file_new_for_commandline_arg (files[0]);
286 uri = g_file_get_uri (file);
287 g_object_unref (file);
288 if (g_ascii_strcasecmp (uri, uri_list[0]) == 0) {
289 g_strfreev (uri_list);
290 g_key_file_free (state_file);
296 g_strfreev (uri_list);
298 g_key_file_free (state_file);
301 dialog = gtk_message_dialog_new (NULL,
305 _("Recover previous documents?"));
306 gtk_message_dialog_format_secondary_text (
307 GTK_MESSAGE_DIALOG (dialog),
308 _("Evince appears to have exited unexpectedly the last time "
309 "it was run. You can recover the opened documents."));
311 gtk_dialog_add_button (GTK_DIALOG (dialog),
313 GTK_RESPONSE_CANCEL);
314 gtk_dialog_add_button (GTK_DIALOG (dialog),
316 GTK_RESPONSE_ACCEPT);
318 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
319 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
320 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
321 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
322 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
324 response = gtk_dialog_run (GTK_DIALOG (dialog));
325 gtk_widget_destroy (dialog);
327 return response == GTK_RESPONSE_ACCEPT;
329 #endif /* ENABLE_DBUS */
332 ev_application_load_session (EvApplication *application,
335 GKeyFile *state_file;
339 if (egg_sm_client_is_resumed (application->smclient)) {
340 state_file = egg_sm_client_get_state_file (application->smclient);
344 #endif /* WITH_SMCLIENT */
346 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
347 if (ev_application_run_crash_recovery_dialog (application, files)) {
348 state_file = g_key_file_new ();
349 g_key_file_load_from_file (state_file,
350 application->crashed_file,
357 #endif /* ENABLE_DBUS */
360 uri_list = g_key_file_get_string_list (state_file,
367 for (i = 0; uri_list[i]; i++) {
368 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
369 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
371 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
373 g_strfreev (uri_list);
375 g_key_file_free (state_file);
383 smclient_save_state_cb (EggSMClient *client,
384 GKeyFile *state_file,
385 EvApplication *application)
389 windows = ev_application_get_windows (application);
391 save_session (application, windows, state_file);
392 g_list_free (windows);
397 smclient_quit_cb (EggSMClient *client,
398 EvApplication *application)
400 ev_application_shutdown (application);
403 #endif /* WITH_SMCLIENT */
406 ev_application_init_session (EvApplication *application)
409 application->crashed_file = g_build_filename (application->dot_dir,
410 "evince-crashed", NULL);
414 application->smclient = egg_sm_client_get ();
415 g_signal_connect (application->smclient, "save_state",
416 G_CALLBACK (smclient_save_state_cb),
418 g_signal_connect (application->smclient, "quit",
419 G_CALLBACK (smclient_quit_cb),
425 * ev_display_open_if_needed:
426 * @name: the name of the display to be open if it's needed.
428 * Search among all the open displays if any of them have the same name as the
429 * passed name. If the display isn't found it tries the open it.
431 * Returns: a #GdkDisplay of the display with the passed name.
434 ev_display_open_if_needed (const gchar *name)
438 GdkDisplay *display = NULL;
440 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
442 for (l = displays; l != NULL; l = l->next) {
443 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
445 if (g_ascii_strcasecmp (display_name, name) == 0) {
451 g_slist_free (displays);
453 return display != NULL ? display : gdk_display_open (name);
457 * get_screen_from_args:
458 * @args: a #GHashTable with data passed to the application.
460 * Looks for the screen in the display available in the hash table passed to the
461 * application. If the display isn't opened, it's opened and the #GdkScreen
462 * assigned to the screen in that display returned.
464 * Returns: the #GdkScreen assigned to the screen on the display indicated by
465 * the data on the #GHashTable.
468 get_screen_from_args (GHashTable *args)
470 GValue *value = NULL;
471 GdkDisplay *display = NULL;
472 GdkScreen *screen = NULL;
474 g_assert (args != NULL);
476 value = g_hash_table_lookup (args, "display");
478 const gchar *display_name;
480 display_name = g_value_get_string (value);
481 display = ev_display_open_if_needed (display_name);
484 value = g_hash_table_lookup (args, "screen");
488 screen_number = g_value_get_int (value);
489 screen = gdk_display_get_screen (display, screen_number);
496 * get_window_run_mode_from_args:
497 * @args: a #GHashTable with data passed to the application.
499 * It does look if the mode option has been passed from command line, using it
500 * as the window run mode, otherwise the run mode will be the normal mode.
502 * Returns: The window run mode passed from command line or
503 * EV_WINDOW_MODE_NORMAL in other case.
505 static EvWindowRunMode
506 get_window_run_mode_from_args (GHashTable *args)
508 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
509 GValue *value = NULL;
511 g_assert (args != NULL);
513 value = g_hash_table_lookup (args, "mode");
515 mode = g_value_get_uint (value);
522 * get_destination_from_args:
523 * @args: a #GHashTable with data passed to the application.
525 * It does look for the page-label argument parsed from the command line and
526 * if it does exist, it returns an #EvLinkDest.
528 * Returns: An #EvLinkDest to page-label if it has been passed from the command
529 * line, NULL in other case.
532 get_destination_from_args (GHashTable *args)
534 EvLinkDest *dest = NULL;
535 GValue *value = NULL;
537 g_assert (args != NULL);
539 value = g_hash_table_lookup (args, "page-label");
541 const gchar *page_label;
543 page_label = g_value_get_string (value);
544 dest = ev_link_dest_new_page_label (page_label);
551 get_find_string_from_args (GHashTable *args)
553 GValue *value = NULL;
555 g_assert (args != NULL);
557 value = g_hash_table_lookup (args, "find-string");
559 return value ? g_value_get_string (value) : NULL;
563 * ev_application_open_window:
564 * @application: The instance of the application.
565 * @args: A #GHashTable with the arguments data.
566 * @timestamp: Current time value.
567 * @error: The #GError facility.
569 * Creates a new window and if the args are available, it's not NULL, it gets
570 * the screen from them and assigns the just created window to it. At last it
576 ev_application_open_window (EvApplication *application,
581 GtkWidget *new_window = ev_window_new ();
582 GdkScreen *screen = NULL;
585 screen = get_screen_from_args (args);
589 ev_stock_icons_set_screen (screen);
590 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
594 ev_application_save_session_crashed (application);
595 g_signal_connect_swapped (new_window, "destroy",
596 G_CALLBACK (save_session_crashed_in_idle),
600 if (!GTK_WIDGET_REALIZED (new_window))
601 gtk_widget_realize (new_window);
603 #ifdef GDK_WINDOWING_X11
605 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
606 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
608 gtk_window_present (GTK_WINDOW (new_window));
610 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
611 #endif /* GDK_WINDOWING_X11 */
617 * ev_application_get_empty_window:
618 * @application: The instance of the application.
619 * @screen: The screen where the empty window will be search.
621 * It does look if there is any empty window in the indicated screen.
623 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
627 ev_application_get_empty_window (EvApplication *application,
630 EvWindow *empty_window = NULL;
631 GList *windows = ev_application_get_windows (application);
634 for (l = windows; l != NULL; l = l->next) {
635 EvWindow *window = EV_WINDOW (l->data);
637 if (ev_window_is_empty (window) &&
638 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
639 empty_window = window;
644 g_list_free (windows);
650 * ev_application_get_uri_window:
651 * @application: The instance of the application.
652 * @uri: The uri to be opened.
654 * It looks in the list of the windows for the one with the document represented
655 * by the passed uri on it. If the window is empty or the document isn't present
656 * on any window, it will return NULL.
658 * Returns: The #EvWindow where the document represented by the passed uri is
659 * shown, NULL in other case.
662 ev_application_get_uri_window (EvApplication *application, const char *uri)
664 EvWindow *uri_window = NULL;
665 GList *windows = gtk_window_list_toplevels ();
668 g_return_val_if_fail (uri != NULL, NULL);
670 for (l = windows; l != NULL; l = l->next) {
671 if (EV_IS_WINDOW (l->data)) {
672 EvWindow *window = EV_WINDOW (l->data);
673 const char *window_uri = ev_window_get_uri (window);
675 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
682 g_list_free (windows);
688 * ev_application_open_uri_at_dest:
689 * @application: The instance of the application.
690 * @uri: The uri to be opened.
691 * @screen: Thee screen where the link will be shown.
692 * @dest: The #EvLinkDest of the document.
693 * @mode: The run mode of the window.
694 * @timestamp: Current time value.
697 ev_application_open_uri_at_dest (EvApplication *application,
701 EvWindowRunMode mode,
702 const gchar *search_string,
705 EvWindow *new_window;
707 g_return_if_fail (uri != NULL);
709 new_window = ev_application_get_uri_window (application, uri);
711 if (new_window == NULL) {
712 new_window = ev_application_get_empty_window (application, screen);
715 if (new_window == NULL) {
716 new_window = EV_WINDOW (ev_window_new ());
720 ev_stock_icons_set_screen (screen);
721 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
724 /* We need to load uri before showing the window, so
725 we can restore window size without flickering */
726 ev_window_open_uri (new_window, uri, dest, mode, search_string);
729 ev_application_save_session_crashed (application);
730 g_signal_connect_swapped (new_window, "destroy",
731 G_CALLBACK (save_session_crashed_in_idle),
735 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
736 gtk_widget_realize (GTK_WIDGET (new_window));
738 #ifdef GDK_WINDOWING_X11
740 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
741 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
743 ev_document_fc_mutex_lock ();
744 gtk_window_present (GTK_WINDOW (new_window));
745 ev_document_fc_mutex_unlock ();
747 ev_document_fc_mutex_lock ();
748 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
749 ev_document_fc_mutex_unlock ();
750 #endif /* GDK_WINDOWING_X11 */
754 * ev_application_open_uri:
755 * @application: The instance of the application.
756 * @uri: The uri to be opened
757 * @args: A #GHashTable with the arguments data.
758 * @timestamp: Current time value.
759 * @error: The #GError facility.
762 ev_application_open_uri (EvApplication *application,
768 EvLinkDest *dest = NULL;
769 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
770 const gchar *search_string = NULL;
771 GdkScreen *screen = NULL;
774 screen = get_screen_from_args (args);
775 dest = get_destination_from_args (args);
776 mode = get_window_run_mode_from_args (args);
777 search_string = get_find_string_from_args (args);
780 ev_application_open_uri_at_dest (application, uri, screen,
781 dest, mode, search_string,
785 g_object_unref (dest);
791 ev_application_open_uri_list (EvApplication *application,
798 for (l = uri_list; l != NULL; l = l->next) {
799 ev_application_open_uri_at_dest (application, (char *)l->data,
800 screen, NULL, 0, NULL,
806 ev_application_shutdown (EvApplication *application)
809 if (application->crashed_file) {
810 ev_application_save_session_crashed (application);
811 g_free (application->crashed_file);
812 application->crashed_file = NULL;
816 if (application->accel_map_file) {
817 gtk_accel_map_save (application->accel_map_file);
818 g_free (application->accel_map_file);
819 application->accel_map_file = NULL;
822 if (application->toolbars_model) {
823 g_object_unref (application->toolbars_model);
824 g_free (application->toolbars_file);
825 application->toolbars_model = NULL;
826 application->toolbars_file = NULL;
829 ev_application_save_print_settings (application);
831 if (application->print_settings_file) {
832 g_key_file_free (application->print_settings_file);
833 application->print_settings_file = NULL;
836 if (application->print_settings) {
837 g_object_unref (application->print_settings);
838 application->print_settings = NULL;
841 if (application->page_setup) {
842 g_object_unref (application->page_setup);
843 application->page_setup = NULL;
847 if (application->keys) {
848 g_object_unref (application->keys);
849 application->keys = NULL;
851 #endif /* ENABLE_DBUS */
853 ev_metadata_manager_shutdown ();
855 g_free (application->dot_dir);
856 application->dot_dir = NULL;
857 g_free (application->data_dir);
858 application->data_dir = NULL;
859 g_free (application->filechooser_open_uri);
860 application->filechooser_open_uri = NULL;
861 g_free (application->filechooser_save_uri);
862 application->filechooser_save_uri = NULL;
864 g_object_unref (application);
871 ev_application_class_init (EvApplicationClass *ev_application_class)
876 ev_application_init (EvApplication *ev_application)
879 const gchar *home_dir;
882 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
887 /* FIXME: why make this fatal? */
888 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
895 dir = g_win32_get_package_installation_directory_of_module (NULL);
896 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
900 ev_application->data_dir = g_strdup (DATADIR);
903 ev_application_init_session (ev_application);
905 home_dir = g_get_home_dir ();
907 ev_application->accel_map_file = g_build_filename (home_dir,
912 gtk_accel_map_load (ev_application->accel_map_file);
915 ev_application->toolbars_model = egg_toolbars_model_new ();
917 ev_application->toolbars_file = g_build_filename
918 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
920 toolbar_path = g_build_filename (ev_application->data_dir,
921 "evince-toolbar.xml", NULL);
922 egg_toolbars_model_load_names (ev_application->toolbars_model,
925 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
926 ev_application->toolbars_file)) {
927 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
930 g_free (toolbar_path);
932 /* Open item doesn't exist anymore,
933 * convert it to OpenRecent for compatibility
935 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
938 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
939 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
940 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
941 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
943 ev_application_save_toolbars_model (ev_application);
948 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
949 EGG_TB_MODEL_NOT_REMOVABLE);
952 ev_application->keys = ev_media_player_keys_new ();
953 #endif /* ENABLE_DBUS */
957 * ev_application_get_windows:
958 * @application: The instance of the application.
960 * It creates a list of the top level windows.
962 * Returns: A #GList of the top level windows.
965 ev_application_get_windows (EvApplication *application)
967 GList *l, *toplevels;
968 GList *windows = NULL;
970 toplevels = gtk_window_list_toplevels ();
972 for (l = toplevels; l != NULL; l = l->next) {
973 if (EV_IS_WINDOW (l->data)) {
974 windows = g_list_append (windows, l->data);
978 g_list_free (toplevels);
984 * ev_application_get_media_keys:
985 * @application: The instance of the application.
987 * It gives you access to the media player keys handler object.
989 * Returns: A #EvMediaPlayerKeys.
992 ev_application_get_media_keys (EvApplication *application)
995 return G_OBJECT (application->keys);
998 #endif /* ENABLE_DBUS */
1002 ev_application_get_toolbars_model (EvApplication *application)
1004 return application->toolbars_model;
1008 ev_application_save_toolbars_model (EvApplication *application)
1010 egg_toolbars_model_save_toolbars (application->toolbars_model,
1011 application->toolbars_file, "1.0");
1015 ev_application_set_filechooser_uri (EvApplication *application,
1016 GtkFileChooserAction action,
1019 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1020 g_free (application->filechooser_open_uri);
1021 application->filechooser_open_uri = g_strdup (uri);
1022 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1023 g_free (application->filechooser_save_uri);
1024 application->filechooser_save_uri = g_strdup (uri);
1029 ev_application_get_filechooser_uri (EvApplication *application,
1030 GtkFileChooserAction action)
1032 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1033 if (application->filechooser_open_uri)
1034 return application->filechooser_open_uri;
1035 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1036 if (application->filechooser_save_uri)
1037 return application->filechooser_save_uri;
1044 ev_application_screensaver_enable (EvApplication *application)
1046 if (application->scr_saver)
1047 totem_scrsaver_enable (application->scr_saver);
1051 ev_application_screensaver_disable (EvApplication *application)
1053 if (application->scr_saver)
1054 totem_scrsaver_disable (application->scr_saver);
1058 ev_application_get_print_settings_file (EvApplication *application)
1062 if (application->print_settings_file)
1063 return application->print_settings_file;
1065 application->print_settings_file = g_key_file_new ();
1067 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1068 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1069 GError *error = NULL;
1071 g_key_file_load_from_file (application->print_settings_file,
1073 G_KEY_FILE_KEEP_COMMENTS |
1074 G_KEY_FILE_KEEP_TRANSLATIONS,
1077 g_warning ("%s", error->message);
1078 g_error_free (error);
1083 return application->print_settings_file;
1087 ev_application_save_print_settings (EvApplication *application)
1093 GError *error = NULL;
1095 if (!application->print_settings && !application->page_setup)
1098 key_file = ev_application_get_print_settings_file (application);
1099 if (application->print_settings)
1100 gtk_print_settings_to_key_file (application->print_settings,
1102 EV_PRINT_SETTINGS_GROUP);
1103 if (application->page_setup)
1104 gtk_page_setup_to_key_file (application->page_setup,
1106 EV_PAGE_SETUP_GROUP);
1108 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1109 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1110 g_file_set_contents (filename, data, data_length, &error);
1112 g_warning ("%s", error->message);
1113 g_error_free (error);
1120 ev_application_get_print_settings (EvApplication *application)
1123 GtkPrintSettings *print_settings;
1125 if (application->print_settings)
1126 return application->print_settings;
1128 key_file = ev_application_get_print_settings_file (application);
1129 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1130 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1131 gtk_print_settings_new ();
1133 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1135 return application->print_settings;
1139 ev_application_set_print_settings (EvApplication *application,
1140 GtkPrintSettings *settings)
1144 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1146 if (settings == application->print_settings)
1149 key_file = ev_application_get_print_settings_file (application);
1151 if (application->print_settings)
1152 g_object_unref (application->print_settings);
1154 application->print_settings = g_object_ref (settings);
1155 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1159 ev_application_get_page_setup (EvApplication *application)
1162 GtkPageSetup *page_setup;
1164 if (application->page_setup)
1165 return application->page_setup;
1167 key_file = ev_application_get_print_settings_file (application);
1168 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1169 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1170 gtk_page_setup_new ();
1172 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1174 return application->page_setup;
1178 ev_application_set_page_setup (EvApplication *application,
1179 GtkPageSetup *page_setup)
1183 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1185 if (page_setup == application->page_setup)
1188 key_file = ev_application_get_print_settings_file (application);
1190 if (application->page_setup)
1191 g_object_unref (application->page_setup);
1193 application->page_setup = g_object_ref (page_setup);
1194 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1198 ev_application_get_dot_dir (EvApplication *application)
1200 return application->dot_dir;
1204 ev_application_get_data_dir (EvApplication *application)
1206 return application->data_dir;