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"
45 #include "ev-stock-icons.h"
48 #include "ev-media-player-keys.h"
49 #endif /* ENABLE_DBUS */
52 #include <dbus/dbus-glib-bindings.h>
53 #include "ev-application-service.h"
56 static void ev_application_save_print_settings (EvApplication *application);
58 struct _EvApplication {
59 GObject base_instance;
63 gchar *accel_map_file;
71 EggToolbarsModel *toolbars_model;
73 TotemScrsaver *scr_saver;
76 EggSMClient *smclient;
79 gchar *filechooser_open_uri;
80 gchar *filechooser_save_uri;
83 EvMediaPlayerKeys *keys;
84 #endif /* ENABLE_DBUS */
86 GtkPrintSettings *print_settings;
87 GtkPageSetup *page_setup;
88 GKeyFile *print_settings_file;
91 struct _EvApplicationClass {
92 GObjectClass base_class;
95 static EvApplication *instance;
97 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
99 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
101 #define EV_PRINT_SETTINGS_FILE "print-settings"
102 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
103 #define EV_PAGE_SETUP_GROUP "Page Setup"
107 ev_application_register_service (EvApplication *application)
109 static DBusGConnection *connection = NULL;
110 DBusGProxy *driver_proxy;
112 guint request_name_result;
115 g_warning ("Service already registered.");
119 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
120 if (connection == NULL) {
121 g_warning ("Service registration failed.");
127 driver_proxy = dbus_g_proxy_new_for_name (connection,
130 DBUS_INTERFACE_DBUS);
132 if (!org_freedesktop_DBus_request_name (driver_proxy,
133 APPLICATION_SERVICE_NAME,
134 DBUS_NAME_FLAG_DO_NOT_QUEUE,
135 &request_name_result, &err)) {
136 g_warning ("Service registration failed.");
137 g_clear_error (&err);
140 g_object_unref (driver_proxy);
142 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
146 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
147 &dbus_glib_ev_application_object_info);
148 dbus_g_connection_register_g_object (connection,
149 "/org/gnome/evince/Evince",
150 G_OBJECT (application));
152 application->scr_saver = totem_scrsaver_new (connection);
156 #endif /* ENABLE_DBUS */
159 * ev_application_get_instance:
161 * Checks for #EvApplication instance, if it doesn't exist it does create it.
163 * Returns: an instance of the #EvApplication data.
166 ev_application_get_instance (void)
169 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
175 #if defined (WITH_SMCLIENT) || defined (ENABLE_DBUS)
179 save_session (EvApplication *application,
181 GKeyFile *state_file)
185 const gchar **uri_list;
186 const gchar *empty = "empty-window";
188 uri_list = g_new (const gchar *, g_list_length (windows_list));
189 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
190 EvWindow *window = EV_WINDOW (l->data);
192 if (ev_window_is_empty (window))
195 uri_list[i] = ev_window_get_uri (window);
197 g_key_file_set_string_list (state_file,
200 (const char **)uri_list,
205 #endif /* WITH_SMCLIENT || ENABLE_DBUS */
209 ev_application_save_session_crashed (EvApplication *application)
213 windows = ev_application_get_windows (application);
215 GKeyFile *crashed_file;
218 GError *error = NULL;
220 crashed_file = g_key_file_new ();
221 save_session (application, windows, crashed_file);
223 data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
224 g_file_set_contents (application->crashed_file, data, data_length, &error);
226 g_warning ("%s", error->message);
227 g_error_free (error);
230 g_key_file_free (crashed_file);
231 } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
234 file = g_file_new_for_path (application->crashed_file);
235 g_file_delete (file, NULL, NULL);
236 g_object_unref (file);
241 save_session_crashed_in_idle_cb (EvApplication *application)
243 ev_application_save_session_crashed (application);
244 application->crashed_idle = 0;
250 save_session_crashed_in_idle (EvApplication *application)
252 if (application->crashed_idle > 0)
253 g_source_remove (application->crashed_idle);
254 application->crashed_idle =
255 g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
260 ev_application_run_crash_recovery_dialog (EvApplication *application)
265 dialog = gtk_message_dialog_new (NULL,
269 _("Recover previous documents?"));
270 gtk_message_dialog_format_secondary_text (
271 GTK_MESSAGE_DIALOG (dialog),
272 _("Evince appears to have exited unexpectedly the last time "
273 "it was run. You can recover the opened documents."));
275 gtk_dialog_add_button (GTK_DIALOG (dialog),
277 GTK_RESPONSE_CANCEL);
278 gtk_dialog_add_button (GTK_DIALOG (dialog),
280 GTK_RESPONSE_ACCEPT);
282 gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
283 gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
284 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
285 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
286 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
288 response = gtk_dialog_run (GTK_DIALOG (dialog));
289 gtk_widget_destroy (dialog);
291 return response == GTK_RESPONSE_ACCEPT;
295 is_in_command_line (GFile *file,
303 for (i = 0; files[i]; i++) {
306 cfile = g_file_new_for_commandline_arg (files[i]);
307 if (g_file_equal (cfile, file)) {
308 g_object_unref (cfile);
311 g_object_unref (cfile);
318 ev_application_get_files_to_recover (EvApplication *application,
321 GKeyFile *state_file;
323 gchar **dest_list = NULL;
326 state_file = g_key_file_new ();
327 g_key_file_load_from_file (state_file,
328 application->crashed_file,
332 uri_list = g_key_file_get_string_list (state_file,
337 g_key_file_free (state_file);
341 for (i = 0, j = 0; uri_list[i]; i++) {
342 GFile *file = g_file_new_for_uri (uri_list[i]);
344 if (!g_file_query_exists (file, NULL) ||
345 is_in_command_line (file, files)) {
346 g_object_unref (file);
351 dest_list = g_new (gchar *, g_strv_length (uri_list) - i);
352 dest_list[j++] = uri_list[i];
356 g_key_file_set_string_list (state_file,
359 (const gchar **)dest_list,
362 g_key_file_free (state_file);
367 g_strfreev (uri_list);
371 #endif /* ENABLE_DBUS */
374 ev_application_load_session (EvApplication *application,
377 GKeyFile *state_file;
381 if (egg_sm_client_is_resumed (application->smclient)) {
382 state_file = egg_sm_client_get_state_file (application->smclient);
386 #endif /* WITH_SMCLIENT */
388 if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
389 state_file = ev_application_get_files_to_recover (application, files);
393 if (!ev_application_run_crash_recovery_dialog (application)) {
394 g_key_file_free (state_file);
398 #endif /* ENABLE_DBUS */
401 uri_list = g_key_file_get_string_list (state_file,
408 for (i = 0; uri_list[i]; i++) {
409 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
410 ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL);
412 ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL);
414 g_strfreev (uri_list);
416 g_key_file_free (state_file);
424 smclient_save_state_cb (EggSMClient *client,
425 GKeyFile *state_file,
426 EvApplication *application)
430 windows = ev_application_get_windows (application);
432 save_session (application, windows, state_file);
433 g_list_free (windows);
438 smclient_quit_cb (EggSMClient *client,
439 EvApplication *application)
441 ev_application_shutdown (application);
444 #endif /* WITH_SMCLIENT */
447 ev_application_init_session (EvApplication *application)
450 application->crashed_file = g_build_filename (application->dot_dir,
451 "evince-crashed", NULL);
455 application->smclient = egg_sm_client_get ();
456 g_signal_connect (application->smclient, "save_state",
457 G_CALLBACK (smclient_save_state_cb),
459 g_signal_connect (application->smclient, "quit",
460 G_CALLBACK (smclient_quit_cb),
466 * ev_display_open_if_needed:
467 * @name: the name of the display to be open if it's needed.
469 * Search among all the open displays if any of them have the same name as the
470 * passed name. If the display isn't found it tries the open it.
472 * Returns: a #GdkDisplay of the display with the passed name.
475 ev_display_open_if_needed (const gchar *name)
479 GdkDisplay *display = NULL;
481 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
483 for (l = displays; l != NULL; l = l->next) {
484 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
486 if (g_ascii_strcasecmp (display_name, name) == 0) {
492 g_slist_free (displays);
494 return display != NULL ? display : gdk_display_open (name);
498 * get_screen_from_args:
499 * @args: a #GHashTable with data passed to the application.
501 * Looks for the screen in the display available in the hash table passed to the
502 * application. If the display isn't opened, it's opened and the #GdkScreen
503 * assigned to the screen in that display returned.
505 * Returns: the #GdkScreen assigned to the screen on the display indicated by
506 * the data on the #GHashTable.
509 get_screen_from_args (GHashTable *args)
511 GValue *value = NULL;
512 GdkDisplay *display = NULL;
513 GdkScreen *screen = NULL;
515 g_assert (args != NULL);
517 value = g_hash_table_lookup (args, "display");
519 const gchar *display_name;
521 display_name = g_value_get_string (value);
522 display = ev_display_open_if_needed (display_name);
525 value = g_hash_table_lookup (args, "screen");
529 screen_number = g_value_get_int (value);
530 screen = gdk_display_get_screen (display, screen_number);
537 * get_window_run_mode_from_args:
538 * @args: a #GHashTable with data passed to the application.
540 * It does look if the mode option has been passed from command line, using it
541 * as the window run mode, otherwise the run mode will be the normal mode.
543 * Returns: The window run mode passed from command line or
544 * EV_WINDOW_MODE_NORMAL in other case.
546 static EvWindowRunMode
547 get_window_run_mode_from_args (GHashTable *args)
549 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
550 GValue *value = NULL;
552 g_assert (args != NULL);
554 value = g_hash_table_lookup (args, "mode");
556 mode = g_value_get_uint (value);
563 * get_destination_from_args:
564 * @args: a #GHashTable with data passed to the application.
566 * It does look for the page-label argument parsed from the command line and
567 * if it does exist, it returns an #EvLinkDest.
569 * Returns: An #EvLinkDest to page-label if it has been passed from the command
570 * line, NULL in other case.
573 get_destination_from_args (GHashTable *args)
575 EvLinkDest *dest = NULL;
576 GValue *value = NULL;
578 g_assert (args != NULL);
580 value = g_hash_table_lookup (args, "page-label");
582 const gchar *page_label;
584 page_label = g_value_get_string (value);
585 dest = ev_link_dest_new_page_label (page_label);
592 get_find_string_from_args (GHashTable *args)
594 GValue *value = NULL;
596 g_assert (args != NULL);
598 value = g_hash_table_lookup (args, "find-string");
600 return value ? g_value_get_string (value) : NULL;
604 * ev_application_open_window:
605 * @application: The instance of the application.
606 * @args: A #GHashTable with the arguments data.
607 * @timestamp: Current time value.
608 * @error: The #GError facility.
610 * Creates a new window and if the args are available, it's not NULL, it gets
611 * the screen from them and assigns the just created window to it. At last it
617 ev_application_open_window (EvApplication *application,
622 GtkWidget *new_window = ev_window_new ();
623 GdkScreen *screen = NULL;
626 screen = get_screen_from_args (args);
630 ev_stock_icons_set_screen (screen);
631 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
635 ev_application_save_session_crashed (application);
636 g_signal_connect_swapped (new_window, "destroy",
637 G_CALLBACK (save_session_crashed_in_idle),
641 if (!GTK_WIDGET_REALIZED (new_window))
642 gtk_widget_realize (new_window);
644 #ifdef GDK_WINDOWING_X11
646 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
647 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
649 gtk_window_present (GTK_WINDOW (new_window));
651 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
652 #endif /* GDK_WINDOWING_X11 */
658 * ev_application_get_empty_window:
659 * @application: The instance of the application.
660 * @screen: The screen where the empty window will be search.
662 * It does look if there is any empty window in the indicated screen.
664 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
668 ev_application_get_empty_window (EvApplication *application,
671 EvWindow *empty_window = NULL;
672 GList *windows = ev_application_get_windows (application);
675 for (l = windows; l != NULL; l = l->next) {
676 EvWindow *window = EV_WINDOW (l->data);
678 if (ev_window_is_empty (window) &&
679 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
680 empty_window = window;
685 g_list_free (windows);
691 * ev_application_get_uri_window:
692 * @application: The instance of the application.
693 * @uri: The uri to be opened.
695 * It looks in the list of the windows for the one with the document represented
696 * by the passed uri on it. If the window is empty or the document isn't present
697 * on any window, it will return NULL.
699 * Returns: The #EvWindow where the document represented by the passed uri is
700 * shown, NULL in other case.
703 ev_application_get_uri_window (EvApplication *application, const char *uri)
705 EvWindow *uri_window = NULL;
706 GList *windows = gtk_window_list_toplevels ();
709 g_return_val_if_fail (uri != NULL, NULL);
711 for (l = windows; l != NULL; l = l->next) {
712 if (EV_IS_WINDOW (l->data)) {
713 EvWindow *window = EV_WINDOW (l->data);
714 const char *window_uri = ev_window_get_uri (window);
716 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
723 g_list_free (windows);
729 * ev_application_open_uri_at_dest:
730 * @application: The instance of the application.
731 * @uri: The uri to be opened.
732 * @screen: Thee screen where the link will be shown.
733 * @dest: The #EvLinkDest of the document.
734 * @mode: The run mode of the window.
735 * @timestamp: Current time value.
738 ev_application_open_uri_at_dest (EvApplication *application,
742 EvWindowRunMode mode,
743 const gchar *search_string,
746 EvWindow *new_window;
748 g_return_if_fail (uri != NULL);
750 new_window = ev_application_get_uri_window (application, uri);
752 if (new_window == NULL) {
753 new_window = ev_application_get_empty_window (application, screen);
756 if (new_window == NULL) {
757 new_window = EV_WINDOW (ev_window_new ());
761 ev_stock_icons_set_screen (screen);
762 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
765 /* We need to load uri before showing the window, so
766 we can restore window size without flickering */
767 ev_window_open_uri (new_window, uri, dest, mode, search_string);
770 ev_application_save_session_crashed (application);
771 g_signal_connect_swapped (new_window, "destroy",
772 G_CALLBACK (save_session_crashed_in_idle),
776 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (new_window)))
777 gtk_widget_realize (GTK_WIDGET (new_window));
779 #ifdef GDK_WINDOWING_X11
781 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
782 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
784 ev_document_fc_mutex_lock ();
785 gtk_window_present (GTK_WINDOW (new_window));
786 ev_document_fc_mutex_unlock ();
788 ev_document_fc_mutex_lock ();
789 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
790 ev_document_fc_mutex_unlock ();
791 #endif /* GDK_WINDOWING_X11 */
795 * ev_application_open_uri:
796 * @application: The instance of the application.
797 * @uri: The uri to be opened
798 * @args: A #GHashTable with the arguments data.
799 * @timestamp: Current time value.
800 * @error: The #GError facility.
803 ev_application_open_uri (EvApplication *application,
809 EvLinkDest *dest = NULL;
810 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
811 const gchar *search_string = NULL;
812 GdkScreen *screen = NULL;
815 screen = get_screen_from_args (args);
816 dest = get_destination_from_args (args);
817 mode = get_window_run_mode_from_args (args);
818 search_string = get_find_string_from_args (args);
821 ev_application_open_uri_at_dest (application, uri, screen,
822 dest, mode, search_string,
826 g_object_unref (dest);
832 ev_application_open_uri_list (EvApplication *application,
839 for (l = uri_list; l != NULL; l = l->next) {
840 ev_application_open_uri_at_dest (application, (char *)l->data,
841 screen, NULL, 0, NULL,
847 ev_application_shutdown (EvApplication *application)
850 if (application->crashed_file) {
851 ev_application_save_session_crashed (application);
852 g_free (application->crashed_file);
853 application->crashed_file = NULL;
857 if (application->accel_map_file) {
858 gtk_accel_map_save (application->accel_map_file);
859 g_free (application->accel_map_file);
860 application->accel_map_file = NULL;
863 if (application->toolbars_model) {
864 g_object_unref (application->toolbars_model);
865 g_free (application->toolbars_file);
866 application->toolbars_model = NULL;
867 application->toolbars_file = NULL;
870 ev_application_save_print_settings (application);
872 if (application->print_settings_file) {
873 g_key_file_free (application->print_settings_file);
874 application->print_settings_file = NULL;
877 if (application->print_settings) {
878 g_object_unref (application->print_settings);
879 application->print_settings = NULL;
882 if (application->page_setup) {
883 g_object_unref (application->page_setup);
884 application->page_setup = NULL;
888 if (application->keys) {
889 g_object_unref (application->keys);
890 application->keys = NULL;
892 #endif /* ENABLE_DBUS */
894 g_free (application->dot_dir);
895 application->dot_dir = NULL;
896 g_free (application->data_dir);
897 application->data_dir = NULL;
898 g_free (application->filechooser_open_uri);
899 application->filechooser_open_uri = NULL;
900 g_free (application->filechooser_save_uri);
901 application->filechooser_save_uri = NULL;
903 g_object_unref (application);
910 ev_application_class_init (EvApplicationClass *ev_application_class)
915 ev_application_init (EvApplication *ev_application)
918 const gchar *home_dir;
921 ev_application->dot_dir = g_build_filename (g_get_home_dir (),
926 /* FIXME: why make this fatal? */
927 if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
934 dir = g_win32_get_package_installation_directory_of_module (NULL);
935 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
939 ev_application->data_dir = g_strdup (DATADIR);
942 ev_application_init_session (ev_application);
944 home_dir = g_get_home_dir ();
946 ev_application->accel_map_file = g_build_filename (home_dir,
951 gtk_accel_map_load (ev_application->accel_map_file);
954 ev_application->toolbars_model = egg_toolbars_model_new ();
956 ev_application->toolbars_file = g_build_filename
957 (ev_application->dot_dir, "evince_toolbar.xml", NULL);
959 toolbar_path = g_build_filename (ev_application->data_dir,
960 "evince-toolbar.xml", NULL);
961 egg_toolbars_model_load_names (ev_application->toolbars_model,
964 if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
965 ev_application->toolbars_file)) {
966 egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
969 g_free (toolbar_path);
971 /* Open item doesn't exist anymore,
972 * convert it to OpenRecent for compatibility
974 for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
977 item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
978 if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
979 egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
980 egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
982 ev_application_save_toolbars_model (ev_application);
987 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
988 EGG_TB_MODEL_NOT_REMOVABLE);
991 ev_application->keys = ev_media_player_keys_new ();
992 #endif /* ENABLE_DBUS */
996 * ev_application_get_windows:
997 * @application: The instance of the application.
999 * It creates a list of the top level windows.
1001 * Returns: A #GList of the top level windows.
1004 ev_application_get_windows (EvApplication *application)
1006 GList *l, *toplevels;
1007 GList *windows = NULL;
1009 toplevels = gtk_window_list_toplevels ();
1011 for (l = toplevels; l != NULL; l = l->next) {
1012 if (EV_IS_WINDOW (l->data)) {
1013 windows = g_list_append (windows, l->data);
1017 g_list_free (toplevels);
1023 * ev_application_get_media_keys:
1024 * @application: The instance of the application.
1026 * It gives you access to the media player keys handler object.
1028 * Returns: A #EvMediaPlayerKeys.
1031 ev_application_get_media_keys (EvApplication *application)
1034 return G_OBJECT (application->keys);
1037 #endif /* ENABLE_DBUS */
1041 ev_application_get_toolbars_model (EvApplication *application)
1043 return application->toolbars_model;
1047 ev_application_save_toolbars_model (EvApplication *application)
1049 egg_toolbars_model_save_toolbars (application->toolbars_model,
1050 application->toolbars_file, "1.0");
1054 ev_application_set_filechooser_uri (EvApplication *application,
1055 GtkFileChooserAction action,
1058 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1059 g_free (application->filechooser_open_uri);
1060 application->filechooser_open_uri = g_strdup (uri);
1061 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1062 g_free (application->filechooser_save_uri);
1063 application->filechooser_save_uri = g_strdup (uri);
1068 ev_application_get_filechooser_uri (EvApplication *application,
1069 GtkFileChooserAction action)
1071 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1072 if (application->filechooser_open_uri)
1073 return application->filechooser_open_uri;
1074 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1075 if (application->filechooser_save_uri)
1076 return application->filechooser_save_uri;
1083 ev_application_screensaver_enable (EvApplication *application)
1085 if (application->scr_saver)
1086 totem_scrsaver_enable (application->scr_saver);
1090 ev_application_screensaver_disable (EvApplication *application)
1092 if (application->scr_saver)
1093 totem_scrsaver_disable (application->scr_saver);
1097 ev_application_get_print_settings_file (EvApplication *application)
1101 if (application->print_settings_file)
1102 return application->print_settings_file;
1104 application->print_settings_file = g_key_file_new ();
1106 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1107 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1108 GError *error = NULL;
1110 g_key_file_load_from_file (application->print_settings_file,
1112 G_KEY_FILE_KEEP_COMMENTS |
1113 G_KEY_FILE_KEEP_TRANSLATIONS,
1116 g_warning ("%s", error->message);
1117 g_error_free (error);
1122 return application->print_settings_file;
1126 ev_application_save_print_settings (EvApplication *application)
1132 GError *error = NULL;
1134 if (!application->print_settings && !application->page_setup)
1137 key_file = ev_application_get_print_settings_file (application);
1138 if (application->print_settings)
1139 gtk_print_settings_to_key_file (application->print_settings,
1141 EV_PRINT_SETTINGS_GROUP);
1142 if (application->page_setup)
1143 gtk_page_setup_to_key_file (application->page_setup,
1145 EV_PAGE_SETUP_GROUP);
1147 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1148 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1149 g_file_set_contents (filename, data, data_length, &error);
1151 g_warning ("%s", error->message);
1152 g_error_free (error);
1159 ev_application_get_print_settings (EvApplication *application)
1162 GtkPrintSettings *print_settings;
1164 if (application->print_settings)
1165 return application->print_settings;
1167 key_file = ev_application_get_print_settings_file (application);
1168 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1169 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1170 gtk_print_settings_new ();
1172 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1174 return application->print_settings;
1178 ev_application_set_print_settings (EvApplication *application,
1179 GtkPrintSettings *settings)
1183 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1185 if (settings == application->print_settings)
1188 key_file = ev_application_get_print_settings_file (application);
1190 if (application->print_settings)
1191 g_object_unref (application->print_settings);
1193 application->print_settings = g_object_ref (settings);
1194 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1198 ev_application_get_page_setup (EvApplication *application)
1201 GtkPageSetup *page_setup;
1203 if (application->page_setup)
1204 return application->page_setup;
1206 key_file = ev_application_get_print_settings_file (application);
1207 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1208 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1209 gtk_page_setup_new ();
1211 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1213 return application->page_setup;
1217 ev_application_set_page_setup (EvApplication *application,
1218 GtkPageSetup *page_setup)
1222 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1224 if (page_setup == application->page_setup)
1227 key_file = ev_application_get_print_settings_file (application);
1229 if (application->page_setup)
1230 g_object_unref (application->page_setup);
1232 application->page_setup = g_object_ref (page_setup);
1233 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1237 ev_application_get_dot_dir (EvApplication *application)
1239 return application->dot_dir;
1243 ev_application_get_data_dir (EvApplication *application)
1245 return application->data_dir;