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)
268 dialog = gtk_message_dialog_new (NULL,
272 _("Recover previous documents?"));
273 gtk_message_dialog_format_secondary_text (
274 GTK_MESSAGE_DIALOG (dialog),
275 _("Evince appears to have exited unexpectedly the last time "
276 "it was run. You can recover the opened documents."));
278 gtk_dialog_add_button (GTK_DIALOG (dialog),
280 GTK_RESPONSE_CANCEL);
281 gtk_dialog_add_button (GTK_DIALOG (dialog),
283 GTK_RESPONSE_ACCEPT);
285 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
286 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
287 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
288 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
289 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
291 response = gtk_dialog_run (GTK_DIALOG (dialog));
292 gtk_widget_destroy (dialog);
294 return response == GTK_RESPONSE_ACCEPT;
298 is_in_command_line (GFile *file,
306 for (i = 0; files[i]; i++) {
309 cfile = g_file_new_for_commandline_arg (files[i]);
310 if (g_file_equal (cfile, file)) {
311 g_object_unref (cfile);
314 g_object_unref (cfile);
321 ev_application_get_files_to_recover (EvApplication *application,
324 GKeyFile *state_file;
326 gchar **dest_list = NULL;
329 state_file = g_key_file_new ();
330 g_key_file_load_from_file (state_file,
331 application->crashed_file,
335 uri_list = g_key_file_get_string_list (state_file,
340 g_key_file_free (state_file);
344 for (i = 0, j = 0; uri_list[i]; i++) {
345 GFile *file = g_file_new_for_uri (uri_list[i]);
347 if (!g_file_query_exists (file, NULL) ||
348 is_in_command_line (file, files)) {
349 g_object_unref (file);
354 dest_list = g_new (gchar *, g_strv_length (uri_list) - i);
355 dest_list[j++] = uri_list[i];
359 g_key_file_set_string_list (state_file,
362 (const gchar **)dest_list,
365 g_key_file_free (state_file);
370 g_strfreev (uri_list);
374 #endif /* ENABLE_DBUS */
377 ev_application_load_session (EvApplication *application,
380 GKeyFile *state_file;
384 if (egg_sm_client_is_resumed (application->smclient)) {
385 state_file = egg_sm_client_get_state_file (application->smclient);
389 #endif /* WITH_SMCLIENT */
391 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
392 state_file = ev_application_get_files_to_recover (application, files);
396 if (!ev_application_run_crash_recovery_dialog (application)) {
397 g_key_file_free (state_file);
401 #endif /* ENABLE_DBUS */
404 uri_list = g_key_file_get_string_list (state_file,
411 for (i = 0; uri_list[i]; i++) {
412 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
413 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
415 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
417 g_strfreev (uri_list);
419 g_key_file_free (state_file);
427 smclient_save_state_cb (EggSMClient *client,
428 GKeyFile *state_file,
429 EvApplication *application)
433 windows = ev_application_get_windows (application);
435 save_session (application, windows, state_file);
436 g_list_free (windows);
441 smclient_quit_cb (EggSMClient *client,
442 EvApplication *application)
444 ev_application_shutdown (application);
447 #endif /* WITH_SMCLIENT */
450 ev_application_init_session (EvApplication *application)
453 application->crashed_file = g_build_filename (application->dot_dir,
454 "evince-crashed", NULL);
458 application->smclient = egg_sm_client_get ();
459 g_signal_connect (application->smclient, "save_state",
460 G_CALLBACK (smclient_save_state_cb),
462 g_signal_connect (application->smclient, "quit",
463 G_CALLBACK (smclient_quit_cb),
469 * ev_display_open_if_needed:
470 * @name: the name of the display to be open if it's needed.
472 * Search among all the open displays if any of them have the same name as the
473 * passed name. If the display isn't found it tries the open it.
475 * Returns: a #GdkDisplay of the display with the passed name.
478 ev_display_open_if_needed (const gchar *name)
482 GdkDisplay *display = NULL;
484 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
486 for (l = displays; l != NULL; l = l->next) {
487 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
489 if (g_ascii_strcasecmp (display_name, name) == 0) {
495 g_slist_free (displays);
497 return display != NULL ? display : gdk_display_open (name);
501 * get_screen_from_args:
502 * @args: a #GHashTable with data passed to the application.
504 * Looks for the screen in the display available in the hash table passed to the
505 * application. If the display isn't opened, it's opened and the #GdkScreen
506 * assigned to the screen in that display returned.
508 * Returns: the #GdkScreen assigned to the screen on the display indicated by
509 * the data on the #GHashTable.
512 get_screen_from_args (GHashTable *args)
514 GValue *value = NULL;
515 GdkDisplay *display = NULL;
516 GdkScreen *screen = NULL;
518 g_assert (args != NULL);
520 value = g_hash_table_lookup (args, "display");
522 const gchar *display_name;
524 display_name = g_value_get_string (value);
525 display = ev_display_open_if_needed (display_name);
528 value = g_hash_table_lookup (args, "screen");
532 screen_number = g_value_get_int (value);
533 screen = gdk_display_get_screen (display, screen_number);
540 * get_window_run_mode_from_args:
541 * @args: a #GHashTable with data passed to the application.
543 * It does look if the mode option has been passed from command line, using it
544 * as the window run mode, otherwise the run mode will be the normal mode.
546 * Returns: The window run mode passed from command line or
547 * EV_WINDOW_MODE_NORMAL in other case.
549 static EvWindowRunMode
550 get_window_run_mode_from_args (GHashTable *args)
552 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
553 GValue *value = NULL;
555 g_assert (args != NULL);
557 value = g_hash_table_lookup (args, "mode");
559 mode = g_value_get_uint (value);
566 * get_destination_from_args:
567 * @args: a #GHashTable with data passed to the application.
569 * It does look for the page-label argument parsed from the command line and
570 * if it does exist, it returns an #EvLinkDest.
572 * Returns: An #EvLinkDest to page-label if it has been passed from the command
573 * line, NULL in other case.
576 get_destination_from_args (GHashTable *args)
578 EvLinkDest *dest = NULL;
579 GValue *value = NULL;
581 g_assert (args != NULL);
583 value = g_hash_table_lookup (args, "page-label");
585 const gchar *page_label;
587 page_label = g_value_get_string (value);
588 dest = ev_link_dest_new_page_label (page_label);
595 get_find_string_from_args (GHashTable *args)
597 GValue *value = NULL;
599 g_assert (args != NULL);
601 value = g_hash_table_lookup (args, "find-string");
603 return value ? g_value_get_string (value) : NULL;
607 * ev_application_open_window:
608 * @application: The instance of the application.
609 * @args: A #GHashTable with the arguments data.
610 * @timestamp: Current time value.
611 * @error: The #GError facility.
613 * Creates a new window and if the args are available, it's not NULL, it gets
614 * the screen from them and assigns the just created window to it. At last it
620 ev_application_open_window (EvApplication *application,
625 GtkWidget *new_window = ev_window_new ();
626 GdkScreen *screen = NULL;
629 screen = get_screen_from_args (args);
633 ev_stock_icons_set_screen (screen);
634 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
638 ev_application_save_session_crashed (application);
639 g_signal_connect_swapped (new_window, "destroy",
640 G_CALLBACK (save_session_crashed_in_idle),
644 if (!GTK_WIDGET_REALIZED (new_window))
645 gtk_widget_realize (new_window);
647 #ifdef GDK_WINDOWING_X11
649 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
650 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
652 gtk_window_present (GTK_WINDOW (new_window));
654 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
655 #endif /* GDK_WINDOWING_X11 */
661 * ev_application_get_empty_window:
662 * @application: The instance of the application.
663 * @screen: The screen where the empty window will be search.
665 * It does look if there is any empty window in the indicated screen.
667 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
671 ev_application_get_empty_window (EvApplication *application,
674 EvWindow *empty_window = NULL;
675 GList *windows = ev_application_get_windows (application);
678 for (l = windows; l != NULL; l = l->next) {
679 EvWindow *window = EV_WINDOW (l->data);
681 if (ev_window_is_empty (window) &&
682 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
683 empty_window = window;
688 g_list_free (windows);
694 * ev_application_get_uri_window:
695 * @application: The instance of the application.
696 * @uri: The uri to be opened.
698 * It looks in the list of the windows for the one with the document represented
699 * by the passed uri on it. If the window is empty or the document isn't present
700 * on any window, it will return NULL.
702 * Returns: The #EvWindow where the document represented by the passed uri is
703 * shown, NULL in other case.
706 ev_application_get_uri_window (EvApplication *application, const char *uri)
708 EvWindow *uri_window = NULL;
709 GList *windows = gtk_window_list_toplevels ();
712 g_return_val_if_fail (uri != NULL, NULL);
714 for (l = windows; l != NULL; l = l->next) {
715 if (EV_IS_WINDOW (l->data)) {
716 EvWindow *window = EV_WINDOW (l->data);
717 const char *window_uri = ev_window_get_uri (window);
719 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
726 g_list_free (windows);
732 * ev_application_open_uri_at_dest:
733 * @application: The instance of the application.
734 * @uri: The uri to be opened.
735 * @screen: Thee screen where the link will be shown.
736 * @dest: The #EvLinkDest of the document.
737 * @mode: The run mode of the window.
738 * @timestamp: Current time value.
741 ev_application_open_uri_at_dest (EvApplication *application,
745 EvWindowRunMode mode,
746 const gchar *search_string,
749 EvWindow *new_window;
751 g_return_if_fail (uri != NULL);
753 new_window = ev_application_get_uri_window (application, uri);
755 if (new_window == NULL) {
756 new_window = ev_application_get_empty_window (application, screen);
759 if (new_window == NULL) {
760 new_window = EV_WINDOW (ev_window_new ());
764 ev_stock_icons_set_screen (screen);
765 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
768 /* We need to load uri before showing the window, so
769 we can restore window size without flickering */
770 ev_window_open_uri (new_window, uri, dest, mode, search_string);
773 ev_application_save_session_crashed (application);
774 g_signal_connect_swapped (new_window, "destroy",
775 G_CALLBACK (save_session_crashed_in_idle),
779 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
780 gtk_widget_realize (GTK_WIDGET (new_window));
782 #ifdef GDK_WINDOWING_X11
784 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
785 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
787 ev_document_fc_mutex_lock ();
788 gtk_window_present (GTK_WINDOW (new_window));
789 ev_document_fc_mutex_unlock ();
791 ev_document_fc_mutex_lock ();
792 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
793 ev_document_fc_mutex_unlock ();
794 #endif /* GDK_WINDOWING_X11 */
798 * ev_application_open_uri:
799 * @application: The instance of the application.
800 * @uri: The uri to be opened
801 * @args: A #GHashTable with the arguments data.
802 * @timestamp: Current time value.
803 * @error: The #GError facility.
806 ev_application_open_uri (EvApplication *application,
812 EvLinkDest *dest = NULL;
813 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
814 const gchar *search_string = NULL;
815 GdkScreen *screen = NULL;
818 screen = get_screen_from_args (args);
819 dest = get_destination_from_args (args);
820 mode = get_window_run_mode_from_args (args);
821 search_string = get_find_string_from_args (args);
824 ev_application_open_uri_at_dest (application, uri, screen,
825 dest, mode, search_string,
829 g_object_unref (dest);
835 ev_application_open_uri_list (EvApplication *application,
842 for (l = uri_list; l != NULL; l = l->next) {
843 ev_application_open_uri_at_dest (application, (char *)l->data,
844 screen, NULL, 0, NULL,
850 ev_application_shutdown (EvApplication *application)
853 if (application->crashed_file) {
854 ev_application_save_session_crashed (application);
855 g_free (application->crashed_file);
856 application->crashed_file = NULL;
860 if (application->accel_map_file) {
861 gtk_accel_map_save (application->accel_map_file);
862 g_free (application->accel_map_file);
863 application->accel_map_file = NULL;
866 if (application->toolbars_model) {
867 g_object_unref (application->toolbars_model);
868 g_free (application->toolbars_file);
869 application->toolbars_model = NULL;
870 application->toolbars_file = NULL;
873 ev_application_save_print_settings (application);
875 if (application->print_settings_file) {
876 g_key_file_free (application->print_settings_file);
877 application->print_settings_file = NULL;
880 if (application->print_settings) {
881 g_object_unref (application->print_settings);
882 application->print_settings = NULL;
885 if (application->page_setup) {
886 g_object_unref (application->page_setup);
887 application->page_setup = NULL;
891 if (application->keys) {
892 g_object_unref (application->keys);
893 application->keys = NULL;
895 #endif /* ENABLE_DBUS */
897 ev_metadata_manager_shutdown ();
899 g_free (application->dot_dir);
900 application->dot_dir = NULL;
901 g_free (application->data_dir);
902 application->data_dir = NULL;
903 g_free (application->filechooser_open_uri);
904 application->filechooser_open_uri = NULL;
905 g_free (application->filechooser_save_uri);
906 application->filechooser_save_uri = NULL;
908 g_object_unref (application);
915 ev_application_class_init (EvApplicationClass *ev_application_class)
920 ev_application_init (EvApplication *ev_application)
923 const gchar *home_dir;
926 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
931 /* FIXME: why make this fatal? */
932 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
939 dir = g_win32_get_package_installation_directory_of_module (NULL);
940 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
944 ev_application->data_dir = g_strdup (DATADIR);
947 ev_application_init_session (ev_application);
949 home_dir = g_get_home_dir ();
951 ev_application->accel_map_file = g_build_filename (home_dir,
956 gtk_accel_map_load (ev_application->accel_map_file);
959 ev_application->toolbars_model = egg_toolbars_model_new ();
961 ev_application->toolbars_file = g_build_filename
962 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
964 toolbar_path = g_build_filename (ev_application->data_dir,
965 "evince-toolbar.xml", NULL);
966 egg_toolbars_model_load_names (ev_application->toolbars_model,
969 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
970 ev_application->toolbars_file)) {
971 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
974 g_free (toolbar_path);
976 /* Open item doesn't exist anymore,
977 * convert it to OpenRecent for compatibility
979 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
982 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
983 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
984 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
985 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
987 ev_application_save_toolbars_model (ev_application);
992 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
993 EGG_TB_MODEL_NOT_REMOVABLE);
996 ev_application->keys = ev_media_player_keys_new ();
997 #endif /* ENABLE_DBUS */
1001 * ev_application_get_windows:
1002 * @application: The instance of the application.
1004 * It creates a list of the top level windows.
1006 * Returns: A #GList of the top level windows.
1009 ev_application_get_windows (EvApplication *application)
1011 GList *l, *toplevels;
1012 GList *windows = NULL;
1014 toplevels = gtk_window_list_toplevels ();
1016 for (l = toplevels; l != NULL; l = l->next) {
1017 if (EV_IS_WINDOW (l->data)) {
1018 windows = g_list_append (windows, l->data);
1022 g_list_free (toplevels);
1028 * ev_application_get_media_keys:
1029 * @application: The instance of the application.
1031 * It gives you access to the media player keys handler object.
1033 * Returns: A #EvMediaPlayerKeys.
1036 ev_application_get_media_keys (EvApplication *application)
1039 return G_OBJECT (application->keys);
1042 #endif /* ENABLE_DBUS */
1046 ev_application_get_toolbars_model (EvApplication *application)
1048 return application->toolbars_model;
1052 ev_application_save_toolbars_model (EvApplication *application)
1054 egg_toolbars_model_save_toolbars (application->toolbars_model,
1055 application->toolbars_file, "1.0");
1059 ev_application_set_filechooser_uri (EvApplication *application,
1060 GtkFileChooserAction action,
1063 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1064 g_free (application->filechooser_open_uri);
1065 application->filechooser_open_uri = g_strdup (uri);
1066 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1067 g_free (application->filechooser_save_uri);
1068 application->filechooser_save_uri = g_strdup (uri);
1073 ev_application_get_filechooser_uri (EvApplication *application,
1074 GtkFileChooserAction action)
1076 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1077 if (application->filechooser_open_uri)
1078 return application->filechooser_open_uri;
1079 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1080 if (application->filechooser_save_uri)
1081 return application->filechooser_save_uri;
1088 ev_application_screensaver_enable (EvApplication *application)
1090 if (application->scr_saver)
1091 totem_scrsaver_enable (application->scr_saver);
1095 ev_application_screensaver_disable (EvApplication *application)
1097 if (application->scr_saver)
1098 totem_scrsaver_disable (application->scr_saver);
1102 ev_application_get_print_settings_file (EvApplication *application)
1106 if (application->print_settings_file)
1107 return application->print_settings_file;
1109 application->print_settings_file = g_key_file_new ();
1111 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1112 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1113 GError *error = NULL;
1115 g_key_file_load_from_file (application->print_settings_file,
1117 G_KEY_FILE_KEEP_COMMENTS |
1118 G_KEY_FILE_KEEP_TRANSLATIONS,
1121 g_warning ("%s", error->message);
1122 g_error_free (error);
1127 return application->print_settings_file;
1131 ev_application_save_print_settings (EvApplication *application)
1137 GError *error = NULL;
1139 if (!application->print_settings && !application->page_setup)
1142 key_file = ev_application_get_print_settings_file (application);
1143 if (application->print_settings)
1144 gtk_print_settings_to_key_file (application->print_settings,
1146 EV_PRINT_SETTINGS_GROUP);
1147 if (application->page_setup)
1148 gtk_page_setup_to_key_file (application->page_setup,
1150 EV_PAGE_SETUP_GROUP);
1152 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1153 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1154 g_file_set_contents (filename, data, data_length, &error);
1156 g_warning ("%s", error->message);
1157 g_error_free (error);
1164 ev_application_get_print_settings (EvApplication *application)
1167 GtkPrintSettings *print_settings;
1169 if (application->print_settings)
1170 return application->print_settings;
1172 key_file = ev_application_get_print_settings_file (application);
1173 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1174 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1175 gtk_print_settings_new ();
1177 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1179 return application->print_settings;
1183 ev_application_set_print_settings (EvApplication *application,
1184 GtkPrintSettings *settings)
1188 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1190 if (settings == application->print_settings)
1193 key_file = ev_application_get_print_settings_file (application);
1195 if (application->print_settings)
1196 g_object_unref (application->print_settings);
1198 application->print_settings = g_object_ref (settings);
1199 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1203 ev_application_get_page_setup (EvApplication *application)
1206 GtkPageSetup *page_setup;
1208 if (application->page_setup)
1209 return application->page_setup;
1211 key_file = ev_application_get_print_settings_file (application);
1212 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1213 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1214 gtk_page_setup_new ();
1216 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1218 return application->page_setup;
1222 ev_application_set_page_setup (EvApplication *application,
1223 GtkPageSetup *page_setup)
1227 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1229 if (page_setup == application->page_setup)
1232 key_file = ev_application_get_print_settings_file (application);
1234 if (application->page_setup)
1235 g_object_unref (application->page_setup);
1237 application->page_setup = g_object_ref (page_setup);
1238 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1242 ev_application_get_dot_dir (EvApplication *application)
1244 return application->dot_dir;
1248 ev_application_get_data_dir (EvApplication *application)
1250 return application->data_dir;