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 static gboolean ev_application_open_uri (EvApplication *application,
58 #include "ev-application-service.h"
61 static void ev_application_save_print_settings (EvApplication *application);
63 struct _EvApplication {
64 GObject base_instance;
68 gchar *accel_map_file;
72 DBusGConnection *connection;
77 EggToolbarsModel *toolbars_model;
79 TotemScrsaver *scr_saver;
82 EggSMClient *smclient;
85 gchar *filechooser_open_uri;
86 gchar *filechooser_save_uri;
89 EvMediaPlayerKeys *keys;
90 #endif /* ENABLE_DBUS */
92 GtkPrintSettings *print_settings;
93 GtkPageSetup *page_setup;
94 GKeyFile *print_settings_file;
97 struct _EvApplicationClass {
98 GObjectClass base_class;
101 static EvApplication *instance;
103 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
106 #define APPLICATION_DBUS_OBJECT_PATH "/org/gnome/evince/Evince"
107 #define APPLICATION_DBUS_INTERFACE "org.gnome.evince.Application"
110 #define EV_PRINT_SETTINGS_FILE "print-settings"
111 #define EV_PRINT_SETTINGS_GROUP "Print Settings"
112 #define EV_PAGE_SETUP_GROUP "Page Setup"
115 * ev_application_get_instance:
117 * Checks for #EvApplication instance, if it doesn't exist it does create it.
119 * Returns: an instance of the #EvApplication data.
122 ev_application_get_instance (void)
125 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
131 #if defined (WITH_SMCLIENT)
134 save_session (EvApplication *application,
136 GKeyFile *state_file)
140 const gchar **uri_list;
141 const gchar *empty = "empty-window";
143 uri_list = g_new (const gchar *, g_list_length (windows_list));
144 for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
145 EvWindow *window = EV_WINDOW (l->data);
147 if (ev_window_is_empty (window))
150 uri_list[i] = ev_window_get_uri (window);
152 g_key_file_set_string_list (state_file,
155 (const char **)uri_list,
160 #endif /* WITH_SMCLIENT */
163 ev_application_load_session (EvApplication *application,
166 GKeyFile *state_file;
170 if (egg_sm_client_is_resumed (application->smclient)) {
171 state_file = egg_sm_client_get_state_file (application->smclient);
175 #endif /* WITH_SMCLIENT */
178 uri_list = g_key_file_get_string_list (state_file,
184 GdkScreen *screen = gdk_screen_get_default ();
186 for (i = 0; uri_list[i]; i++) {
187 if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0)
188 ev_application_open_window (application, screen, GDK_CURRENT_TIME);
190 ev_application_open_uri_at_dest (application, uri_list[i], screen,
191 NULL, 0, NULL, GDK_CURRENT_TIME);
193 g_strfreev (uri_list);
195 g_key_file_free (state_file);
203 smclient_save_state_cb (EggSMClient *client,
204 GKeyFile *state_file,
205 EvApplication *application)
209 windows = ev_application_get_windows (application);
211 save_session (application, windows, state_file);
212 g_list_free (windows);
217 smclient_quit_cb (EggSMClient *client,
218 EvApplication *application)
220 ev_application_shutdown (application);
223 #endif /* WITH_SMCLIENT */
226 ev_application_init_session (EvApplication *application)
229 application->smclient = egg_sm_client_get ();
230 g_signal_connect (application->smclient, "save_state",
231 G_CALLBACK (smclient_save_state_cb),
233 g_signal_connect (application->smclient, "quit",
234 G_CALLBACK (smclient_quit_cb),
240 * ev_display_open_if_needed:
241 * @name: the name of the display to be open if it's needed.
243 * Search among all the open displays if any of them have the same name as the
244 * passed name. If the display isn't found it tries the open it.
246 * Returns: a #GdkDisplay of the display with the passed name.
249 ev_display_open_if_needed (const gchar *name)
253 GdkDisplay *display = NULL;
255 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
257 for (l = displays; l != NULL; l = l->next) {
258 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
260 if (g_ascii_strcasecmp (display_name, name) == 0) {
266 g_slist_free (displays);
268 return display != NULL ? display : gdk_display_open (name);
272 * get_screen_from_args:
273 * @args: a #GHashTable with data passed to the application.
275 * Looks for the screen in the display available in the hash table passed to the
276 * application. If the display isn't opened, it's opened and the #GdkScreen
277 * assigned to the screen in that display returned.
279 * Returns: the #GdkScreen assigned to the screen on the display indicated by
280 * the data on the #GHashTable.
283 get_screen_from_args (GHashTable *args)
285 GValue *value = NULL;
286 GdkDisplay *display = NULL;
287 GdkScreen *screen = NULL;
289 g_assert (args != NULL);
291 value = g_hash_table_lookup (args, "display");
293 const gchar *display_name;
295 display_name = g_value_get_string (value);
296 display = ev_display_open_if_needed (display_name);
299 value = g_hash_table_lookup (args, "screen");
303 screen_number = g_value_get_int (value);
304 screen = gdk_display_get_screen (display, screen_number);
311 * get_window_run_mode_from_args:
312 * @args: a #GHashTable with data passed to the application.
314 * It does look if the mode option has been passed from command line, using it
315 * as the window run mode, otherwise the run mode will be the normal mode.
317 * Returns: The window run mode passed from command line or
318 * EV_WINDOW_MODE_NORMAL in other case.
320 static EvWindowRunMode
321 get_window_run_mode_from_args (GHashTable *args)
323 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
324 GValue *value = NULL;
326 g_assert (args != NULL);
328 value = g_hash_table_lookup (args, "mode");
330 mode = g_value_get_uint (value);
337 * get_destination_from_args:
338 * @args: a #GHashTable with data passed to the application.
340 * It does look for the page-label argument parsed from the command line and
341 * if it does exist, it returns an #EvLinkDest.
343 * Returns: An #EvLinkDest to page-label if it has been passed from the command
344 * line, NULL in other case.
347 get_destination_from_args (GHashTable *args)
349 EvLinkDest *dest = NULL;
350 GValue *value = NULL;
352 g_assert (args != NULL);
354 value = g_hash_table_lookup (args, "page-label");
356 const gchar *page_label;
358 page_label = g_value_get_string (value);
359 dest = ev_link_dest_new_page_label (page_label);
366 get_find_string_from_args (GHashTable *args)
368 GValue *value = NULL;
370 g_assert (args != NULL);
372 value = g_hash_table_lookup (args, "find-string");
374 return value ? g_value_get_string (value) : NULL;
378 value_free (GValue *value)
380 g_value_unset (value);
385 build_args (GdkScreen *screen,
387 EvWindowRunMode mode,
388 const gchar *search_string)
393 const gchar *display_name;
396 args = g_hash_table_new_full (g_str_hash,
398 (GDestroyNotify)g_free,
399 (GDestroyNotify)value_free);
402 display = gdk_screen_get_display (screen);
403 display_name = gdk_display_get_name (display);
404 value = g_new0 (GValue, 1);
405 g_value_init (value, G_TYPE_STRING);
406 g_value_set_string (value, display_name);
407 g_hash_table_insert (args, g_strdup ("display"), value);
410 screen_number = gdk_screen_get_number (screen);
411 value = g_new0 (GValue, 1);
412 g_value_init (value, G_TYPE_INT);
413 g_value_set_int (value, screen_number);
414 g_hash_table_insert (args, g_strdup ("screen"), value);
418 value = g_new0 (GValue, 1);
419 g_value_init (value, G_TYPE_STRING);
420 g_value_set_string (value, ev_link_dest_get_page_label (dest));
422 g_hash_table_insert (args, g_strdup ("page-label"), value);
427 value = g_new0 (GValue, 1);
428 g_value_init (value, G_TYPE_STRING);
429 g_value_set_string (value, search_string);
431 g_hash_table_insert (args, g_strdup ("find-string"), value);
435 if (mode != EV_WINDOW_MODE_NORMAL) {
436 value = g_new0 (GValue, 1);
437 g_value_init (value, G_TYPE_UINT);
438 g_value_set_uint (value, mode);
440 g_hash_table_insert (args, g_strdup ("mode"), value);
447 * ev_application_open_window:
448 * @application: The instance of the application.
449 * @timestamp: Current time value.
451 * Creates a new window
454 ev_application_open_window (EvApplication *application,
458 GtkWidget *new_window = ev_window_new ();
461 ev_stock_icons_set_screen (screen);
462 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
465 if (!GTK_WIDGET_REALIZED (new_window))
466 gtk_widget_realize (new_window);
468 #ifdef GDK_WINDOWING_X11
470 timestamp = gdk_x11_get_server_time (GTK_WIDGET (new_window)->window);
471 gdk_x11_window_set_user_time (GTK_WIDGET (new_window)->window, timestamp);
473 gtk_window_present (GTK_WINDOW (new_window));
475 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
476 #endif /* GDK_WINDOWING_X11 */
480 * ev_application_get_empty_window:
481 * @application: The instance of the application.
482 * @screen: The screen where the empty window will be search.
484 * It does look if there is any empty window in the indicated screen.
486 * Returns: The first empty #EvWindow in the passed #GdkScreen or NULL in other
490 ev_application_get_empty_window (EvApplication *application,
493 EvWindow *empty_window = NULL;
494 GList *windows = ev_application_get_windows (application);
497 for (l = windows; l != NULL; l = l->next) {
498 EvWindow *window = EV_WINDOW (l->data);
500 if (ev_window_is_empty (window) &&
501 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
502 empty_window = window;
507 g_list_free (windows);
513 * ev_application_get_uri_window:
514 * @application: The instance of the application.
515 * @uri: The uri to be opened.
517 * It looks in the list of the windows for the one with the document represented
518 * by the passed uri on it. If the window is empty or the document isn't present
519 * on any window, it will return NULL.
521 * Returns: The #EvWindow where the document represented by the passed uri is
522 * shown, NULL in other case.
525 ev_application_get_uri_window (EvApplication *application, const char *uri)
527 EvWindow *uri_window = NULL;
528 GList *windows = gtk_window_list_toplevels ();
531 g_return_val_if_fail (uri != NULL, NULL);
533 for (l = windows; l != NULL; l = l->next) {
534 if (EV_IS_WINDOW (l->data)) {
535 EvWindow *window = EV_WINDOW (l->data);
536 const char *window_uri = ev_window_get_uri (window);
538 if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) {
545 g_list_free (windows);
552 ev_application_register_uri (EvApplication *application,
559 gboolean retval = TRUE;
560 GError *error = NULL;
562 if (!application->connection)
565 proxy = dbus_g_proxy_new_for_name (application->connection,
566 "org.gnome.evince.Daemon",
567 "/org/gnome/evince/Daemon",
568 "org.gnome.evince.Daemon");
569 if (!dbus_g_proxy_call (proxy, "RegisterDocument", &error,
572 G_TYPE_STRING, &owner,
574 g_warning ("Error registering document: %s\n", error->message);
575 g_error_free (error);
576 g_object_unref (proxy);
580 g_object_unref (proxy);
583 /* Already registered */
584 proxy = dbus_g_proxy_new_for_name_owner (application->connection,
586 APPLICATION_DBUS_OBJECT_PATH,
587 APPLICATION_DBUS_INTERFACE,
590 if (!dbus_g_proxy_call (proxy, "OpenURI", &error,
592 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), args,
593 G_TYPE_UINT, timestamp,
596 g_warning ("%s", error->message);
597 g_error_free (error);
599 g_object_unref (proxy);
601 g_warning ("Error creating proxy: %s\n", error->message);
602 g_error_free (error);
605 /* Do not continue opening this document */
615 ev_application_unregister_uri (EvApplication *application,
619 GError *error = NULL;
621 if (!application->connection)
624 proxy = dbus_g_proxy_new_for_name (application->connection,
625 "org.gnome.evince.Daemon",
626 "/org/gnome/evince/Daemon",
627 "org.gnome.evince.Daemon");
628 if (!dbus_g_proxy_call (proxy, "UnregisterDocument", &error,
632 g_warning ("Error unregistering document: %s\n", error->message);
633 g_error_free (error);
636 g_object_unref (proxy);
640 ev_application_window_destroyed (EvApplication *application,
643 gchar *uri = g_hash_table_lookup (application->windows, ev_window);
645 ev_application_unregister_uri (application, uri);
646 g_hash_table_remove (application->windows, ev_window);
648 #endif /* ENABLE_DBUS */
651 ev_application_open_uri_in_window (EvApplication *application,
656 EvWindowRunMode mode,
657 const gchar *search_string,
661 ev_stock_icons_set_screen (screen);
662 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
665 /* We need to load uri before showing the window, so
666 we can restore window size without flickering */
667 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
670 if (!g_hash_table_lookup (application->windows, ev_window)) {
671 g_hash_table_insert (application->windows, ev_window, g_strdup (uri));
672 g_signal_connect_swapped (ev_window, "destroy",
673 G_CALLBACK (ev_application_window_destroyed),
678 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (ev_window)))
679 gtk_widget_realize (GTK_WIDGET (ev_window));
681 #ifdef GDK_WINDOWING_X11
683 timestamp = gdk_x11_get_server_time (GTK_WIDGET (ev_window)->window);
684 gdk_x11_window_set_user_time (GTK_WIDGET (ev_window)->window, timestamp);
686 ev_document_fc_mutex_lock ();
687 gtk_window_present (GTK_WINDOW (ev_window));
688 ev_document_fc_mutex_unlock ();
690 ev_document_fc_mutex_lock ();
691 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
692 ev_document_fc_mutex_unlock ();
693 #endif /* GDK_WINDOWING_X11 */
697 * ev_application_open_uri_at_dest:
698 * @application: The instance of the application.
699 * @uri: The uri to be opened.
700 * @screen: Thee screen where the link will be shown.
701 * @dest: The #EvLinkDest of the document.
702 * @mode: The run mode of the window.
703 * @timestamp: Current time value.
706 ev_application_open_uri_at_dest (EvApplication *application,
710 EvWindowRunMode mode,
711 const gchar *search_string,
716 g_return_if_fail (uri != NULL);
718 ev_window = ev_application_get_uri_window (application, uri);
721 GHashTable *args = build_args (screen, dest, mode, search_string);
724 /* Register the uri or send OpenURI to
725 * remote instance if already registered
727 ret = ev_application_register_uri (application, uri, args, timestamp);
728 g_hash_table_destroy (args);
732 #endif /* ENABLE_DBUS */
734 if (ev_window == NULL) {
735 ev_window = ev_application_get_empty_window (application, screen);
738 if (ev_window == NULL) {
739 ev_window = EV_WINDOW (ev_window_new ());
742 ev_application_open_uri_in_window (application, uri, ev_window,
743 screen, dest, mode, search_string,
748 * ev_application_open_uri:
749 * @application: The instance of the application.
750 * @uri: The uri to be opened
751 * @args: A #GHashTable with the arguments data.
752 * @timestamp: Current time value.
753 * @error: The #GError facility.
756 ev_application_open_uri (EvApplication *application,
763 EvLinkDest *dest = NULL;
764 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
765 const gchar *search_string = NULL;
766 GdkScreen *screen = NULL;
768 ev_window = ev_application_get_uri_window (application, uri);
769 g_assert (ev_window != NULL);
772 screen = get_screen_from_args (args);
773 dest = get_destination_from_args (args);
774 mode = get_window_run_mode_from_args (args);
775 search_string = get_find_string_from_args (args);
778 ev_application_open_uri_in_window (application, uri, ev_window,
779 screen, dest, mode, search_string,
783 g_object_unref (dest);
789 ev_application_open_uri_list (EvApplication *application,
796 for (l = uri_list; l != NULL; l = l->next) {
797 ev_application_open_uri_at_dest (application, (char *)l->data,
798 screen, NULL, 0, NULL,
804 ev_application_shutdown (EvApplication *application)
807 if (application->windows) {
808 g_hash_table_destroy (application->windows);
809 application->windows = NULL;
813 if (application->accel_map_file) {
814 gtk_accel_map_save (application->accel_map_file);
815 g_free (application->accel_map_file);
816 application->accel_map_file = NULL;
819 if (application->toolbars_model) {
820 g_object_unref (application->toolbars_model);
821 g_free (application->toolbars_file);
822 application->toolbars_model = NULL;
823 application->toolbars_file = NULL;
826 ev_application_save_print_settings (application);
828 if (application->print_settings_file) {
829 g_key_file_free (application->print_settings_file);
830 application->print_settings_file = NULL;
833 if (application->print_settings) {
834 g_object_unref (application->print_settings);
835 application->print_settings = NULL;
838 if (application->page_setup) {
839 g_object_unref (application->page_setup);
840 application->page_setup = NULL;
844 if (application->keys) {
845 g_object_unref (application->keys);
846 application->keys = NULL;
848 #endif /* ENABLE_DBUS */
850 g_free (application->dot_dir);
851 application->dot_dir = NULL;
852 g_free (application->data_dir);
853 application->data_dir = NULL;
854 g_free (application->filechooser_open_uri);
855 application->filechooser_open_uri = NULL;
856 g_free (application->filechooser_save_uri);
857 application->filechooser_save_uri = NULL;
859 g_object_unref (application);
866 ev_application_class_init (EvApplicationClass *ev_application_class)
869 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
870 &dbus_glib_ev_application_object_info);
875 ev_application_init (EvApplication *ev_application)
878 const gchar *home_dir;
880 GError *error = NULL;
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->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
953 if (ev_application->connection) {
954 dbus_g_connection_register_g_object (ev_application->connection,
955 APPLICATION_DBUS_OBJECT_PATH,
956 G_OBJECT (ev_application));
957 ev_application->windows = g_hash_table_new_full (g_direct_hash,
960 (GDestroyNotify)g_free);
961 ev_application->scr_saver = totem_scrsaver_new (ev_application->connection);
963 g_warning ("Error connection to DBus: %s\n", error->message);
964 g_error_free (error);
966 ev_application->keys = ev_media_player_keys_new ();
967 #endif /* ENABLE_DBUS */
971 * ev_application_get_windows:
972 * @application: The instance of the application.
974 * It creates a list of the top level windows.
976 * Returns: A #GList of the top level windows.
979 ev_application_get_windows (EvApplication *application)
981 GList *l, *toplevels;
982 GList *windows = NULL;
984 toplevels = gtk_window_list_toplevels ();
986 for (l = toplevels; l != NULL; l = l->next) {
987 if (EV_IS_WINDOW (l->data)) {
988 windows = g_list_append (windows, l->data);
992 g_list_free (toplevels);
998 * ev_application_get_media_keys:
999 * @application: The instance of the application.
1001 * It gives you access to the media player keys handler object.
1003 * Returns: A #EvMediaPlayerKeys.
1006 ev_application_get_media_keys (EvApplication *application)
1009 return G_OBJECT (application->keys);
1012 #endif /* ENABLE_DBUS */
1016 ev_application_get_toolbars_model (EvApplication *application)
1018 return application->toolbars_model;
1022 ev_application_save_toolbars_model (EvApplication *application)
1024 egg_toolbars_model_save_toolbars (application->toolbars_model,
1025 application->toolbars_file, "1.0");
1029 ev_application_set_filechooser_uri (EvApplication *application,
1030 GtkFileChooserAction action,
1033 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1034 g_free (application->filechooser_open_uri);
1035 application->filechooser_open_uri = g_strdup (uri);
1036 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1037 g_free (application->filechooser_save_uri);
1038 application->filechooser_save_uri = g_strdup (uri);
1043 ev_application_get_filechooser_uri (EvApplication *application,
1044 GtkFileChooserAction action)
1046 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1047 if (application->filechooser_open_uri)
1048 return application->filechooser_open_uri;
1049 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1050 if (application->filechooser_save_uri)
1051 return application->filechooser_save_uri;
1058 ev_application_screensaver_enable (EvApplication *application)
1060 if (application->scr_saver)
1061 totem_scrsaver_enable (application->scr_saver);
1065 ev_application_screensaver_disable (EvApplication *application)
1067 if (application->scr_saver)
1068 totem_scrsaver_disable (application->scr_saver);
1072 ev_application_get_print_settings_file (EvApplication *application)
1076 if (application->print_settings_file)
1077 return application->print_settings_file;
1079 application->print_settings_file = g_key_file_new ();
1081 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1082 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
1083 GError *error = NULL;
1085 g_key_file_load_from_file (application->print_settings_file,
1087 G_KEY_FILE_KEEP_COMMENTS |
1088 G_KEY_FILE_KEEP_TRANSLATIONS,
1091 g_warning ("%s", error->message);
1092 g_error_free (error);
1097 return application->print_settings_file;
1101 ev_application_save_print_settings (EvApplication *application)
1107 GError *error = NULL;
1109 if (!application->print_settings && !application->page_setup)
1112 key_file = ev_application_get_print_settings_file (application);
1113 if (application->print_settings)
1114 gtk_print_settings_to_key_file (application->print_settings,
1116 EV_PRINT_SETTINGS_GROUP);
1117 if (application->page_setup)
1118 gtk_page_setup_to_key_file (application->page_setup,
1120 EV_PAGE_SETUP_GROUP);
1122 filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
1123 data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
1124 g_file_set_contents (filename, data, data_length, &error);
1126 g_warning ("%s", error->message);
1127 g_error_free (error);
1134 ev_application_get_print_settings (EvApplication *application)
1137 GtkPrintSettings *print_settings;
1139 if (application->print_settings)
1140 return application->print_settings;
1142 key_file = ev_application_get_print_settings_file (application);
1143 print_settings = g_key_file_has_group (key_file, EV_PRINT_SETTINGS_GROUP) ?
1144 gtk_print_settings_new_from_key_file (key_file, EV_PRINT_SETTINGS_GROUP, NULL) :
1145 gtk_print_settings_new ();
1147 application->print_settings = print_settings ? print_settings : gtk_print_settings_new ();
1149 return application->print_settings;
1153 ev_application_set_print_settings (EvApplication *application,
1154 GtkPrintSettings *settings)
1158 g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
1160 if (settings == application->print_settings)
1163 key_file = ev_application_get_print_settings_file (application);
1165 if (application->print_settings)
1166 g_object_unref (application->print_settings);
1168 application->print_settings = g_object_ref (settings);
1169 gtk_print_settings_to_key_file (settings, key_file, EV_PRINT_SETTINGS_GROUP);
1173 ev_application_get_page_setup (EvApplication *application)
1176 GtkPageSetup *page_setup;
1178 if (application->page_setup)
1179 return application->page_setup;
1181 key_file = ev_application_get_print_settings_file (application);
1182 page_setup = g_key_file_has_group (key_file, EV_PAGE_SETUP_GROUP) ?
1183 gtk_page_setup_new_from_key_file (key_file, EV_PAGE_SETUP_GROUP, NULL) :
1184 gtk_page_setup_new ();
1186 application->page_setup = page_setup ? page_setup : gtk_page_setup_new ();
1188 return application->page_setup;
1192 ev_application_set_page_setup (EvApplication *application,
1193 GtkPageSetup *page_setup)
1197 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
1199 if (page_setup == application->page_setup)
1202 key_file = ev_application_get_print_settings_file (application);
1204 if (application->page_setup)
1205 g_object_unref (application->page_setup);
1207 application->page_setup = g_object_ref (page_setup);
1208 gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
1212 ev_application_get_dot_dir (EvApplication *application)
1214 return application->dot_dir;
1218 ev_application_get_data_dir (EvApplication *application)
1220 return application->data_dir;