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));
178 #if defined (WITH_SMCLIENT) || defined (ENABLE_DBUS)
182 save_session (EvApplication *application,
184 GKeyFile *state_file)
188 const gchar **uri_list;
189 const gchar *empty = "empty-window";
191 uri_list = g_new (const gchar *, g_list_length (windows_list));
192 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
193 EvWindow *window = EV_WINDOW (l->data);
195 if (ev_window_is_empty (window))
198 uri_list[i] = ev_window_get_uri (window);
200 g_key_file_set_string_list (state_file,
203 (const char **)uri_list,
208 #endif /* WITH_SMCLIENT || ENABLE_DBUS */
212 ev_application_save_session_crashed (EvApplication *application)
216 windows = ev_application_get_windows (application);
218 GKeyFile *crashed_file;
221 GError *error = NULL;
223 crashed_file = g_key_file_new ();
224 save_session (application, windows, crashed_file);
226 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
227 g_file_set_contents (application->crashed_file, data, data_length, &error);
229 g_warning ("%s", error->message);
230 g_error_free (error);
233 g_key_file_free (crashed_file);
234 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
237 file = g_file_new_for_path (application->crashed_file);
238 g_file_delete (file, NULL, NULL);
239 g_object_unref (file);
244 save_session_crashed_in_idle_cb (EvApplication *application)
246 ev_application_save_session_crashed (application);
247 application->crashed_idle = 0;
253 save_session_crashed_in_idle (EvApplication *application)
255 if (application->crashed_idle > 0)
256 g_source_remove (application->crashed_idle);
257 application->crashed_idle =
258 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
263 ev_application_run_crash_recovery_dialog (EvApplication *application,
269 /* Do not show the recover dialog if the requested file is the
270 * only one to be recovered
272 if (files && g_strv_length ((gchar **)files) == 1) {
273 GKeyFile *state_file;
276 state_file = g_key_file_new ();
277 g_key_file_load_from_file (state_file,
278 application->crashed_file,
281 uri_list = g_key_file_get_string_list (state_file,
285 if (uri_list && g_strv_length (uri_list) == 1) {
289 file = g_file_new_for_commandline_arg (files[0]);
290 uri = g_file_get_uri (file);
291 g_object_unref (file);
292 if (g_ascii_strcasecmp (uri, uri_list[0]) == 0) {
293 g_strfreev (uri_list);
294 g_key_file_free (state_file);
300 g_strfreev (uri_list);
302 g_key_file_free (state_file);
305 dialog = gtk_message_dialog_new (NULL,
309 _("Recover previous documents?"));
310 gtk_message_dialog_format_secondary_text (
311 GTK_MESSAGE_DIALOG (dialog),
312 _("Evince appears to have exited unexpectedly the last time "
313 "it was run. You can recover the opened documents."));
315 gtk_dialog_add_button (GTK_DIALOG (dialog),
317 GTK_RESPONSE_CANCEL);
318 gtk_dialog_add_button (GTK_DIALOG (dialog),
320 GTK_RESPONSE_ACCEPT);
322 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
323 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
324 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
325 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
326 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
328 response = gtk_dialog_run (GTK_DIALOG (dialog));
329 gtk_widget_destroy (dialog);
331 return response == GTK_RESPONSE_ACCEPT;
333 #endif /* ENABLE_DBUS */
336 ev_application_load_session (EvApplication *application,
339 GKeyFile *state_file;
343 if (egg_sm_client_is_resumed (application->smclient)) {
344 state_file = egg_sm_client_get_state_file (application->smclient);
348 #endif /* WITH_SMCLIENT */
350 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
351 if (ev_application_run_crash_recovery_dialog (application, files)) {
352 state_file = g_key_file_new ();
353 g_key_file_load_from_file (state_file,
354 application->crashed_file,
361 #endif /* ENABLE_DBUS */
364 uri_list = g_key_file_get_string_list (state_file,
371 for (i = 0; uri_list[i]; i++) {
372 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
373 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
375 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
377 g_strfreev (uri_list);
379 g_key_file_free (state_file);
387 smclient_save_state_cb (EggSMClient *client,
388 GKeyFile *state_file,
389 EvApplication *application)
393 windows = ev_application_get_windows (application);
395 save_session (application, windows, state_file);
396 g_list_free (windows);
401 smclient_quit_cb (EggSMClient *client,
402 EvApplication *application)
404 ev_application_shutdown (application);
407 #endif /* WITH_SMCLIENT */
410 ev_application_init_session (EvApplication *application)
413 application->crashed_file = g_build_filename (application->dot_dir,
414 "evince-crashed", NULL);
418 application->smclient = egg_sm_client_get ();
419 g_signal_connect (application->smclient, "save_state",
420 G_CALLBACK (smclient_save_state_cb),
422 g_signal_connect (application->smclient, "quit",
423 G_CALLBACK (smclient_quit_cb),
429 * ev_display_open_if_needed:
430 * @name: the name of the display to be open if it's needed.
432 * Search among all the open displays if any of them have the same name as the
433 * passed name. If the display isn't found it tries the open it.
435 * Returns: a #GdkDisplay of the display with the passed name.
438 ev_display_open_if_needed (const gchar *name)
442 GdkDisplay *display = NULL;
444 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
446 for (l = displays; l != NULL; l = l->next) {
447 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
449 if (g_ascii_strcasecmp (display_name, name) == 0) {
455 g_slist_free (displays);
457 return display != NULL ? display : gdk_display_open (name);
461 * get_screen_from_args:
462 * @args: a #GHashTable with data passed to the application.
464 * Looks for the screen in the display available in the hash table passed to the
465 * application. If the display isn't opened, it's opened and the #GdkScreen
466 * assigned to the screen in that display returned.
468 * Returns: the #GdkScreen assigned to the screen on the display indicated by
469 * the data on the #GHashTable.
472 get_screen_from_args (GHashTable *args)
474 GValue *value = NULL;
475 GdkDisplay *display = NULL;
476 GdkScreen *screen = NULL;
478 g_assert (args != NULL);
480 value = g_hash_table_lookup (args, "display");
482 const gchar *display_name;
484 display_name = g_value_get_string (value);
485 display = ev_display_open_if_needed (display_name);
488 value = g_hash_table_lookup (args, "screen");
492 screen_number = g_value_get_int (value);
493 screen = gdk_display_get_screen (display, screen_number);
500 * get_window_run_mode_from_args:
501 * @args: a #GHashTable with data passed to the application.
503 * It does look if the mode option has been passed from command line, using it
504 * as the window run mode, otherwise the run mode will be the normal mode.
506 * Returns: The window run mode passed from command line or
507 * EV_WINDOW_MODE_NORMAL in other case.
509 static EvWindowRunMode
510 get_window_run_mode_from_args (GHashTable *args)
512 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
513 GValue *value = NULL;
515 g_assert (args != NULL);
517 value = g_hash_table_lookup (args, "mode");
519 mode = g_value_get_uint (value);
526 * get_destination_from_args:
527 * @args: a #GHashTable with data passed to the application.
529 * It does look for the page-label argument parsed from the command line and
530 * if it does exist, it returns an #EvLinkDest.
532 * Returns: An #EvLinkDest to page-label if it has been passed from the command
533 * line, NULL in other case.
536 get_destination_from_args (GHashTable *args)
538 EvLinkDest *dest = NULL;
539 GValue *value = NULL;
541 g_assert (args != NULL);
543 value = g_hash_table_lookup (args, "page-label");
545 const gchar *page_label;
547 page_label = g_value_get_string (value);
548 dest = ev_link_dest_new_page_label (page_label);
555 get_find_string_from_args (GHashTable *args)
557 GValue *value = NULL;
559 g_assert (args != NULL);
561 value = g_hash_table_lookup (args, "find-string");
563 return value ? g_value_get_string (value) : NULL;
567 * ev_application_open_window:
568 * @application: The instance of the application.
569 * @args: A #GHashTable with the arguments data.
570 * @timestamp: Current time value.
571 * @error: The #GError facility.
573 * Creates a new window and if the args are available, it's not NULL, it gets
574 * the screen from them and assigns the just created window to it. At last it
580 ev_application_open_window (EvApplication *application,
585 GtkWidget *new_window = ev_window_new ();
586 GdkScreen *screen = NULL;
589 screen = get_screen_from_args (args);
593 ev_stock_icons_set_screen (screen);
594 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
598 ev_application_save_session_crashed (application);
599 g_signal_connect_swapped (new_window, "destroy",
600 G_CALLBACK (save_session_crashed_in_idle),
604 if (!GTK_WIDGET_REALIZED (new_window))
605 gtk_widget_realize (new_window);
607 #ifdef GDK_WINDOWING_X11
609 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
610 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
612 gtk_window_present (GTK_WINDOW (new_window));
614 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
615 #endif /* GDK_WINDOWING_X11 */
621 * ev_application_get_empty_window:
622 * @application: The instance of the application.
623 * @screen: The screen where the empty window will be search.
625 * It does look if there is any empty window in the indicated screen.
627 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
631 ev_application_get_empty_window (EvApplication *application,
634 EvWindow *empty_window = NULL;
635 GList *windows = ev_application_get_windows (application);
638 for (l = windows; l != NULL; l = l->next) {
639 EvWindow *window = EV_WINDOW (l->data);
641 if (ev_window_is_empty (window) &&
642 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
643 empty_window = window;
648 g_list_free (windows);
654 * ev_application_get_uri_window:
655 * @application: The instance of the application.
656 * @uri: The uri to be opened.
658 * It looks in the list of the windows for the one with the document represented
659 * by the passed uri on it. If the window is empty or the document isn't present
660 * on any window, it will return NULL.
662 * Returns: The #EvWindow where the document represented by the passed uri is
663 * shown, NULL in other case.
666 ev_application_get_uri_window (EvApplication *application, const char *uri)
668 EvWindow *uri_window = NULL;
669 GList *windows = gtk_window_list_toplevels ();
672 g_return_val_if_fail (uri != NULL, NULL);
674 for (l = windows; l != NULL; l = l->next) {
675 if (EV_IS_WINDOW (l->data)) {
676 EvWindow *window = EV_WINDOW (l->data);
677 const char *window_uri = ev_window_get_uri (window);
679 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
686 g_list_free (windows);
692 * ev_application_open_uri_at_dest:
693 * @application: The instance of the application.
694 * @uri: The uri to be opened.
695 * @screen: Thee screen where the link will be shown.
696 * @dest: The #EvLinkDest of the document.
697 * @mode: The run mode of the window.
698 * @timestamp: Current time value.
701 ev_application_open_uri_at_dest (EvApplication *application,
705 EvWindowRunMode mode,
706 const gchar *search_string,
709 EvWindow *new_window;
711 g_return_if_fail (uri != NULL);
713 new_window = ev_application_get_uri_window (application, uri);
715 if (new_window == NULL) {
716 new_window = ev_application_get_empty_window (application, screen);
719 if (new_window == NULL) {
720 new_window = EV_WINDOW (ev_window_new ());
724 ev_stock_icons_set_screen (screen);
725 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
728 /* We need to load uri before showing the window, so
729 we can restore window size without flickering */
730 ev_window_open_uri (new_window, uri, dest, mode, search_string);
733 ev_application_save_session_crashed (application);
734 g_signal_connect_swapped (new_window, "destroy",
735 G_CALLBACK (save_session_crashed_in_idle),
739 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
740 gtk_widget_realize (GTK_WIDGET (new_window));
742 #ifdef GDK_WINDOWING_X11
744 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
745 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
747 ev_document_fc_mutex_lock ();
748 gtk_window_present (GTK_WINDOW (new_window));
749 ev_document_fc_mutex_unlock ();
751 ev_document_fc_mutex_lock ();
752 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
753 ev_document_fc_mutex_unlock ();
754 #endif /* GDK_WINDOWING_X11 */
758 * ev_application_open_uri:
759 * @application: The instance of the application.
760 * @uri: The uri to be opened
761 * @args: A #GHashTable with the arguments data.
762 * @timestamp: Current time value.
763 * @error: The #GError facility.
766 ev_application_open_uri (EvApplication *application,
772 EvLinkDest *dest = NULL;
773 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
774 const gchar *search_string = NULL;
775 GdkScreen *screen = NULL;
778 screen = get_screen_from_args (args);
779 dest = get_destination_from_args (args);
780 mode = get_window_run_mode_from_args (args);
781 search_string = get_find_string_from_args (args);
784 ev_application_open_uri_at_dest (application, uri, screen,
785 dest, mode, search_string,
789 g_object_unref (dest);
795 ev_application_open_uri_list (EvApplication *application,
802 for (l = uri_list; l != NULL; l = l->next) {
803 ev_application_open_uri_at_dest (application, (char *)l->data,
804 screen, NULL, 0, NULL,
810 ev_application_shutdown (EvApplication *application)
813 if (application->crashed_file) {
814 ev_application_save_session_crashed (application);
815 g_free (application->crashed_file);
816 application->crashed_file = NULL;
820 if (application->accel_map_file) {
821 gtk_accel_map_save (application->accel_map_file);
822 g_free (application->accel_map_file);
823 application->accel_map_file = NULL;
826 if (application->toolbars_model) {
827 g_object_unref (application->toolbars_model);
828 g_free (application->toolbars_file);
829 application->toolbars_model = NULL;
830 application->toolbars_file = NULL;
833 ev_application_save_print_settings (application);
835 if (application->print_settings_file) {
836 g_key_file_free (application->print_settings_file);
837 application->print_settings_file = NULL;
840 if (application->print_settings) {
841 g_object_unref (application->print_settings);
842 application->print_settings = NULL;
845 if (application->page_setup) {
846 g_object_unref (application->page_setup);
847 application->page_setup = NULL;
851 if (application->keys) {
852 g_object_unref (application->keys);
853 application->keys = NULL;
855 #endif /* ENABLE_DBUS */
857 ev_metadata_manager_shutdown ();
859 g_free (application->dot_dir);
860 application->dot_dir = NULL;
861 g_free (application->data_dir);
862 application->data_dir = NULL;
863 g_free (application->filechooser_open_uri);
864 application->filechooser_open_uri = NULL;
865 g_free (application->filechooser_save_uri);
866 application->filechooser_save_uri = NULL;
868 g_object_unref (application);
875 ev_application_class_init (EvApplicationClass *ev_application_class)
880 ev_application_init (EvApplication *ev_application)
883 const gchar *home_dir;
886 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
891 /* FIXME: why make this fatal? */
892 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
899 dir = g_win32_get_package_installation_directory_of_module (NULL);
900 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
904 ev_application->data_dir = g_strdup (DATADIR);
907 ev_application_init_session (ev_application);
909 home_dir = g_get_home_dir ();
911 ev_application->accel_map_file = g_build_filename (home_dir,
916 gtk_accel_map_load (ev_application->accel_map_file);
919 ev_application->toolbars_model = egg_toolbars_model_new ();
921 ev_application->toolbars_file = g_build_filename
922 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
924 toolbar_path = g_build_filename (ev_application->data_dir,
925 "evince-toolbar.xml", NULL);
926 egg_toolbars_model_load_names (ev_application->toolbars_model,
929 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
930 ev_application->toolbars_file)) {
931 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
934 g_free (toolbar_path);
936 /* Open item doesn't exist anymore,
937 * convert it to OpenRecent for compatibility
939 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
942 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
943 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
944 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
945 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
947 ev_application_save_toolbars_model (ev_application);
952 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
953 EGG_TB_MODEL_NOT_REMOVABLE);
956 ev_application->keys = ev_media_player_keys_new ();
957 #endif /* ENABLE_DBUS */
961 * ev_application_get_windows:
962 * @application: The instance of the application.
964 * It creates a list of the top level windows.
966 * Returns: A #GList of the top level windows.
969 ev_application_get_windows (EvApplication *application)
971 GList *l, *toplevels;
972 GList *windows = NULL;
974 toplevels = gtk_window_list_toplevels ();
976 for (l = toplevels; l != NULL; l = l->next) {
977 if (EV_IS_WINDOW (l->data)) {
978 windows = g_list_append (windows, l->data);
982 g_list_free (toplevels);
988 * ev_application_get_media_keys:
989 * @application: The instance of the application.
991 * It gives you access to the media player keys handler object.
993 * Returns: A #EvMediaPlayerKeys.
996 ev_application_get_media_keys (EvApplication *application)
999 return G_OBJECT (application->keys);
1002 #endif /* ENABLE_DBUS */
1006 ev_application_get_toolbars_model (EvApplication *application)
1008 return application->toolbars_model;
1012 ev_application_save_toolbars_model (EvApplication *application)
1014 egg_toolbars_model_save_toolbars (application->toolbars_model,
1015 application->toolbars_file, "1.0");
1019 ev_application_set_filechooser_uri (EvApplication *application,
1020 GtkFileChooserAction action,
1023 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1024 g_free (application->filechooser_open_uri);
1025 application->filechooser_open_uri = g_strdup (uri);
1026 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1027 g_free (application->filechooser_save_uri);
1028 application->filechooser_save_uri = g_strdup (uri);
1033 ev_application_get_filechooser_uri (EvApplication *application,
1034 GtkFileChooserAction action)
1036 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1037 if (application->filechooser_open_uri)
1038 return application->filechooser_open_uri;
1039 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1040 if (application->filechooser_save_uri)
1041 return application->filechooser_save_uri;
1048 ev_application_screensaver_enable (EvApplication *application)
1050 if (application->scr_saver)
1051 totem_scrsaver_enable (application->scr_saver);
1055 ev_application_screensaver_disable (EvApplication *application)
1057 if (application->scr_saver)
1058 totem_scrsaver_disable (application->scr_saver);
1062 ev_application_get_print_settings_file (EvApplication *application)
1066 if (application->print_settings_file)
1067 return application->print_settings_file;
1069 application->print_settings_file = g_key_file_new ();
1071 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1072 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1073 GError *error = NULL;
1075 g_key_file_load_from_file (application->print_settings_file,
1077 G_KEY_FILE_KEEP_COMMENTS |
1078 G_KEY_FILE_KEEP_TRANSLATIONS,
1081 g_warning ("%s", error->message);
1082 g_error_free (error);
1087 return application->print_settings_file;
1091 ev_application_save_print_settings (EvApplication *application)
1097 GError *error = NULL;
1099 if (!application->print_settings && !application->page_setup)
1102 key_file = ev_application_get_print_settings_file (application);
1103 if (application->print_settings)
1104 gtk_print_settings_to_key_file (application->print_settings,
1106 EV_PRINT_SETTINGS_GROUP);
1107 if (application->page_setup)
1108 gtk_page_setup_to_key_file (application->page_setup,
1110 EV_PAGE_SETUP_GROUP);
1112 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1113 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1114 g_file_set_contents (filename, data, data_length, &error);
1116 g_warning ("%s", error->message);
1117 g_error_free (error);
1124 ev_application_get_print_settings (EvApplication *application)
1127 GtkPrintSettings *print_settings;
1129 if (application->print_settings)
1130 return application->print_settings;
1132 key_file = ev_application_get_print_settings_file (application);
1133 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1134 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1135 gtk_print_settings_new ();
1137 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1139 return application->print_settings;
1143 ev_application_set_print_settings (EvApplication *application,
1144 GtkPrintSettings *settings)
1148 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1150 if (settings == application->print_settings)
1153 key_file = ev_application_get_print_settings_file (application);
1155 if (application->print_settings)
1156 g_object_unref (application->print_settings);
1158 application->print_settings = g_object_ref (settings);
1159 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1163 ev_application_get_page_setup (EvApplication *application)
1166 GtkPageSetup *page_setup;
1168 if (application->page_setup)
1169 return application->page_setup;
1171 key_file = ev_application_get_print_settings_file (application);
1172 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1173 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1174 gtk_page_setup_new ();
1176 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1178 return application->page_setup;
1182 ev_application_set_page_setup (EvApplication *application,
1183 GtkPageSetup *page_setup)
1187 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1189 if (page_setup == application->page_setup)
1192 key_file = ev_application_get_print_settings_file (application);
1194 if (application->page_setup)
1195 g_object_unref (application->page_setup);
1197 application->page_setup = g_object_ref (page_setup);
1198 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1202 ev_application_get_dot_dir (EvApplication *application)
1204 return application->dot_dir;
1208 ev_application_get_data_dir (EvApplication *application)
1210 return application->data_dir;