1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2004 Martin Kretzschmar
4 * Copyright © 2010 Christian Persch
7 * Martin Kretzschmar <martink@gnome.org>
9 * Evince is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Evince is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <glib/gi18n.h>
31 #include <glib/gstdio.h>
33 #ifdef GDK_WINDOWING_X11
38 #include "totem-scrsaver.h"
41 #include "eggsmclient.h"
44 #include "ev-application.h"
45 #include "ev-file-helpers.h"
46 #include "ev-stock-icons.h"
49 #include "ev-media-player-keys.h"
50 #endif /* ENABLE_DBUS */
52 struct _EvApplication {
53 GObject base_instance;
61 GDBusConnection *connection;
62 guint registration_id;
63 EvMediaPlayerKeys *keys;
64 gboolean doc_registered;
67 TotemScrsaver *scr_saver;
70 EggSMClient *smclient;
73 gchar *filechooser_open_uri;
74 gchar *filechooser_save_uri;
77 struct _EvApplicationClass {
78 GObjectClass base_class;
81 static EvApplication *instance;
83 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
86 #define APPLICATION_DBUS_OBJECT_PATH "/org/gnome/evince/Evince"
87 #define APPLICATION_DBUS_INTERFACE "org.gnome.evince.Application"
89 #define EVINCE_DAEMON_SERVICE "org.gnome.evince.Daemon"
90 #define EVINCE_DAEMON_OBJECT_PATH "/org/gnome/evince/Daemon"
91 #define EVINCE_DAEMON_INTERFACE "org.gnome.evince.Daemon"
94 static void _ev_application_open_uri_at_dest (EvApplication *application,
99 const gchar *search_string,
101 static void ev_application_open_uri_in_window (EvApplication *application,
106 EvWindowRunMode mode,
107 const gchar *search_string,
111 * ev_application_get_instance:
113 * Checks for #EvApplication instance, if it doesn't exist it does create it.
115 * Returns: an instance of the #EvApplication data.
118 ev_application_get_instance (void)
121 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
129 ev_application_load_session (EvApplication *application)
131 GKeyFile *state_file;
135 if (egg_sm_client_is_resumed (application->smclient)) {
136 state_file = egg_sm_client_get_state_file (application->smclient);
140 #endif /* WITH_SMCLIENT */
143 uri = g_key_file_get_string (state_file, "Evince", "uri", NULL);
147 ev_application_open_uri_at_dest (application, uri,
148 gdk_screen_get_default (),
152 g_key_file_free (state_file);
160 smclient_save_state_cb (EggSMClient *client,
161 GKeyFile *state_file,
162 EvApplication *application)
164 if (!application->uri)
167 g_key_file_set_string (state_file, "Evince", "uri", application->uri);
171 smclient_quit_cb (EggSMClient *client,
172 EvApplication *application)
174 ev_application_shutdown (application);
176 #endif /* WITH_SMCLIENT */
179 ev_application_init_session (EvApplication *application)
182 application->smclient = egg_sm_client_get ();
183 g_signal_connect (application->smclient, "save_state",
184 G_CALLBACK (smclient_save_state_cb),
186 g_signal_connect (application->smclient, "quit",
187 G_CALLBACK (smclient_quit_cb),
193 * ev_display_open_if_needed:
194 * @name: the name of the display to be open if it's needed.
196 * Search among all the open displays if any of them have the same name as the
197 * passed name. If the display isn't found it tries the open it.
199 * Returns: a #GdkDisplay of the display with the passed name.
202 ev_display_open_if_needed (const gchar *name)
206 GdkDisplay *display = NULL;
208 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
210 for (l = displays; l != NULL; l = l->next) {
211 const gchar *display_name = gdk_display_get_name ((GdkDisplay *) l->data);
213 if (g_ascii_strcasecmp (display_name, name) == 0) {
219 g_slist_free (displays);
221 return display != NULL ? display : gdk_display_open (name);
225 ev_spawn (const char *uri,
228 EvWindowRunMode mode,
229 const gchar *search_string,
233 gchar *path, *cmdline;
235 GdkAppLaunchContext *ctx;
236 GError *error = NULL;
238 cmd = g_string_new (NULL);
244 dir = g_win32_get_package_installation_directory_of_module (NULL);
245 path = g_build_filename (dir, "bin", "evince", NULL);
250 path = g_build_filename (BINDIR, "evince", NULL);
253 g_string_append_printf (cmd, " %s", path);
258 const gchar *page_label;
260 page_label = ev_link_dest_get_page_label (dest);
263 g_string_append_printf (cmd, " --page-label=%s", page_label);
265 g_string_append_printf (cmd, " --page-label=%d",
266 ev_link_dest_get_page (dest));
271 g_string_append_printf (cmd, " --find=%s", search_string);
276 case EV_WINDOW_MODE_FULLSCREEN:
277 g_string_append (cmd, " -f");
279 case EV_WINDOW_MODE_PRESENTATION:
280 g_string_append (cmd, " -s");
286 cmdline = g_string_free (cmd, FALSE);
287 app = g_app_info_create_from_commandline (cmdline, NULL, 0, &error);
292 ctx = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
293 gdk_app_launch_context_set_screen (ctx, screen);
294 gdk_app_launch_context_set_timestamp (ctx, timestamp);
296 /* Some URIs can be changed when passed through a GFile
297 * (for instance unsupported uris with strange formats like mailto:),
298 * so if you have a textual uri you want to pass in as argument,
299 * consider using g_app_info_launch_uris() instead.
300 * See https://bugzilla.gnome.org/show_bug.cgi?id=644604
302 uri_list.data = (gchar *)uri;
303 uri_list.prev = uri_list.next = NULL;
304 g_app_info_launch_uris (app, &uri_list,
305 G_APP_LAUNCH_CONTEXT (ctx), &error);
307 g_object_unref (app);
308 g_object_unref (ctx);
312 g_warning ("Error launching evince %s: %s\n", uri, error->message);
313 g_error_free (error);
320 ev_application_get_windows (EvApplication *application)
322 GList *l, *toplevels;
323 GList *windows = NULL;
325 toplevels = gtk_window_list_toplevels ();
327 for (l = toplevels; l != NULL; l = l->next) {
328 if (EV_IS_WINDOW (l->data)) {
329 windows = g_list_append (windows, l->data);
333 g_list_free (toplevels);
339 ev_application_get_empty_window (EvApplication *application,
342 EvWindow *empty_window = NULL;
343 GList *windows = ev_application_get_windows (application);
346 for (l = windows; l != NULL; l = l->next) {
347 EvWindow *window = EV_WINDOW (l->data);
349 if (ev_window_is_empty (window) &&
350 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
351 empty_window = window;
356 g_list_free (windows);
367 EvWindowRunMode mode;
368 gchar *search_string;
373 ev_register_doc_data_free (EvRegisterDocData *data)
379 if (data->search_string)
380 g_free (data->search_string);
382 g_object_unref (data->dest);
388 on_reload_cb (GObject *source_object,
392 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
394 GError *error = NULL;
396 value = g_dbus_connection_call_finish (connection, res, &error);
398 g_warning ("Failed to Reload: %s", error->message);
399 g_error_free (error);
401 g_variant_unref (value);
403 /* We did not open a window, so manually clear the startup
405 gdk_notify_startup_complete ();
407 ev_application_shutdown (EV_APP);
411 on_register_uri_cb (GObject *source_object,
415 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
416 EvRegisterDocData *data = (EvRegisterDocData *)user_data;
417 EvApplication *application = EV_APP;
420 GVariantBuilder builder;
421 GError *error = NULL;
423 value = g_dbus_connection_call_finish (connection, res, &error);
425 g_warning ("Error registering document: %s\n", error->message);
426 g_error_free (error);
428 _ev_application_open_uri_at_dest (application,
435 ev_register_doc_data_free (data);
440 g_variant_get (value, "(&s)", &owner);
442 /* This means that the document wasn't already registered; go
443 * ahead with opening it.
445 if (owner[0] == '\0') {
446 g_variant_unref (value);
448 application->doc_registered = TRUE;
450 _ev_application_open_uri_at_dest (application,
457 ev_register_doc_data_free (data);
462 /* Already registered */
463 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)"));
464 g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
465 g_variant_builder_add (&builder, "{sv}",
467 g_variant_new_string (gdk_display_get_name (gdk_screen_get_display (data->screen))));
468 g_variant_builder_add (&builder, "{sv}",
470 g_variant_new_int32 (gdk_screen_get_number (data->screen)));
472 const gchar *page_label = ev_link_dest_get_page_label (data->dest);
475 g_variant_builder_add (&builder, "{sv}",
477 g_variant_new_string (page_label));
479 g_variant_builder_add (&builder, "{sv}",
481 g_variant_new_uint32 (ev_link_dest_get_page (data->dest)));
484 if (data->search_string) {
485 g_variant_builder_add (&builder, "{sv}",
487 g_variant_new_string (data->search_string));
489 if (data->mode != EV_WINDOW_MODE_NORMAL) {
490 g_variant_builder_add (&builder, "{sv}",
492 g_variant_new_uint32 (data->mode));
494 g_variant_builder_close (&builder);
496 g_variant_builder_add (&builder, "u", data->timestamp);
498 g_dbus_connection_call (connection,
500 APPLICATION_DBUS_OBJECT_PATH,
501 APPLICATION_DBUS_INTERFACE,
503 g_variant_builder_end (&builder),
505 G_DBUS_CALL_FLAGS_NONE,
510 g_variant_unref (value);
511 ev_register_doc_data_free (data);
515 * ev_application_register_uri:
524 * Registers @uri with evince-daemon.
528 ev_application_register_uri (EvApplication *application,
532 EvWindowRunMode mode,
533 const gchar *search_string,
536 EvRegisterDocData *data;
538 if (!application->connection)
541 if (application->doc_registered) {
542 /* Already registered, reload */
545 windows = ev_application_get_windows (application);
546 for (l = windows; l != NULL; l = g_list_next (l)) {
547 EvWindow *ev_window = EV_WINDOW (l->data);
549 ev_application_open_uri_in_window (application, uri, ev_window,
554 g_list_free (windows);
559 data = g_new (EvRegisterDocData, 1);
560 data->uri = g_strdup (uri);
561 data->screen = screen;
562 data->dest = dest ? g_object_ref (dest) : NULL;
564 data->search_string = search_string ? g_strdup (search_string) : NULL;
565 data->timestamp = timestamp;
567 g_dbus_connection_call (application->connection,
568 EVINCE_DAEMON_SERVICE,
569 EVINCE_DAEMON_OBJECT_PATH,
570 EVINCE_DAEMON_INTERFACE,
572 g_variant_new ("(s)", uri),
573 G_VARIANT_TYPE ("(s)"),
574 G_DBUS_CALL_FLAGS_NONE,
582 ev_application_unregister_uri (EvApplication *application,
586 GError *error = NULL;
588 if (!application->doc_registered)
591 /* This is called from ev_application_shutdown(),
592 * so it's safe to use the sync api
594 value = g_dbus_connection_call_sync (
595 application->connection,
596 EVINCE_DAEMON_SERVICE,
597 EVINCE_DAEMON_OBJECT_PATH,
598 EVINCE_DAEMON_INTERFACE,
599 "UnregisterDocument",
600 g_variant_new ("(s)", uri),
602 G_DBUS_CALL_FLAGS_NO_AUTO_START,
607 g_warning ("Error unregistering document: %s\n", error->message);
608 g_error_free (error);
610 g_variant_unref (value);
613 #endif /* ENABLE_DBUS */
616 ev_application_open_uri_in_window (EvApplication *application,
621 EvWindowRunMode mode,
622 const gchar *search_string,
625 #ifdef GDK_WINDOWING_X11
626 GdkWindow *gdk_window;
630 ev_stock_icons_set_screen (screen);
631 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
634 /* We need to load uri before showing the window, so
635 we can restore window size without flickering */
636 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
638 if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
639 gtk_widget_realize (GTK_WIDGET (ev_window));
641 #ifdef GDK_WINDOWING_X11
642 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
645 timestamp = gdk_x11_get_server_time (gdk_window);
646 gdk_x11_window_set_user_time (gdk_window, timestamp);
648 gtk_window_present (GTK_WINDOW (ev_window));
650 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
651 #endif /* GDK_WINDOWING_X11 */
655 _ev_application_open_uri_at_dest (EvApplication *application,
659 EvWindowRunMode mode,
660 const gchar *search_string,
665 ev_window = ev_application_get_empty_window (application, screen);
667 ev_window = EV_WINDOW (ev_window_new ());
669 ev_application_open_uri_in_window (application, uri, ev_window,
676 * ev_application_open_uri_at_dest:
677 * @application: The instance of the application.
678 * @uri: The uri to be opened.
679 * @screen: Thee screen where the link will be shown.
680 * @dest: The #EvLinkDest of the document.
681 * @mode: The run mode of the window.
682 * @timestamp: Current time value.
685 ev_application_open_uri_at_dest (EvApplication *application,
689 EvWindowRunMode mode,
690 const gchar *search_string,
693 g_return_if_fail (uri != NULL);
695 if (application->uri && strcmp (application->uri, uri) != 0) {
696 /* spawn a new evince process */
697 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
699 } else if (!application->uri) {
700 application->uri = g_strdup (uri);
704 /* Register the uri or send Reload to
705 * remote instance if already registered
707 ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp);
709 _ev_application_open_uri_at_dest (application, uri, screen, dest, mode, search_string, timestamp);
710 #endif /* ENABLE_DBUS */
714 * ev_application_open_window:
715 * @application: The instance of the application.
716 * @timestamp: Current time value.
718 * Creates a new window
721 ev_application_open_window (EvApplication *application,
725 GtkWidget *new_window = ev_window_new ();
726 #ifdef GDK_WINDOWING_X11
727 GdkWindow *gdk_window;
731 ev_stock_icons_set_screen (screen);
732 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
735 if (!gtk_widget_get_realized (new_window))
736 gtk_widget_realize (new_window);
738 #ifdef GDK_WINDOWING_X11
739 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
742 timestamp = gdk_x11_get_server_time (gdk_window);
743 gdk_x11_window_set_user_time (gdk_window, timestamp);
745 gtk_window_present (GTK_WINDOW (new_window));
747 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
748 #endif /* GDK_WINDOWING_X11 */
753 method_call_cb (GDBusConnection *connection,
755 const gchar *object_path,
756 const gchar *interface_name,
757 const gchar *method_name,
758 GVariant *parameters,
759 GDBusMethodInvocation *invocation,
762 EvApplication *application = EV_APPLICATION (user_data);
768 GdkDisplay *display = NULL;
769 int screen_number = 0;
770 EvLinkDest *dest = NULL;
771 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
772 const gchar *search_string = NULL;
773 GdkScreen *screen = NULL;
775 if (g_strcmp0 (method_name, "Reload") == 0) {
776 g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp);
778 while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
779 if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
780 display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
781 } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_INT32) {
782 screen_number = g_variant_get_int32 (value);
783 } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
784 mode = g_variant_get_uint32 (value);
785 } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
786 dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
787 } else if (strcmp (key, "page-index") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
788 dest = ev_link_dest_new_page (g_variant_get_uint32 (value));
789 } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
790 search_string = g_variant_get_string (value, NULL);
793 g_variant_iter_free (iter);
795 if (display != NULL &&
796 screen_number >= 0 &&
797 screen_number < gdk_display_get_n_screens (display))
798 screen = gdk_display_get_screen (display, screen_number);
800 screen = gdk_screen_get_default ();
802 windows = ev_application_get_windows (application);
803 for (l = windows; l != NULL; l = g_list_next (l)) {
804 EvWindow *ev_window = EV_WINDOW (l->data);
806 ev_application_open_uri_in_window (application, application->uri,
812 g_list_free (windows);
815 g_object_unref (dest);
817 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
818 } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
819 GList *windows = ev_application_get_windows (application);
820 GVariantBuilder builder;
823 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
824 g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
826 for (l = windows; l; l = g_list_next (l)) {
827 EvWindow *window = (EvWindow *)l->data;
829 g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
832 g_variant_builder_close (&builder);
833 g_list_free (windows);
835 g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
839 static const char introspection_xml[] =
841 "<interface name='org.gnome.evince.Application'>"
842 "<method name='Reload'>"
843 "<arg type='a{sv}' name='args' direction='in'/>"
844 "<arg type='u' name='timestamp' direction='in'/>"
846 "<method name='GetWindowList'>"
847 "<arg type='ao' name='window_list' direction='out'/>"
852 static const GDBusInterfaceVTable interface_vtable = {
858 static GDBusNodeInfo *introspection_data;
859 #endif /* ENABLE_DBUS */
862 ev_application_open_uri_list (EvApplication *application,
869 for (l = uri_list; l != NULL; l = l->next) {
870 ev_application_open_uri_at_dest (application, (char *)l->data,
871 screen, NULL, 0, NULL,
877 ev_application_accel_map_save (EvApplication *application)
879 gchar *accel_map_file;
883 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
884 tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
886 fd = g_mkstemp (tmp_filename);
888 g_free (accel_map_file);
889 g_free (tmp_filename);
893 gtk_accel_map_save_fd (fd);
896 g_mkdir_with_parents (application->dot_dir, 0700);
897 if (g_rename (tmp_filename, accel_map_file) == -1) {
899 g_unlink (tmp_filename);
902 g_free (accel_map_file);
903 g_free (tmp_filename);
907 ev_application_accel_map_load (EvApplication *application)
909 gchar *accel_map_file;
911 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
912 gtk_accel_map_load (accel_map_file);
913 g_free (accel_map_file);
917 ev_application_migrate_config_dir (EvApplication *application)
919 const gchar *userdir;
924 gboolean dir_created = FALSE;
925 static const gchar *config_files[] = {
926 "evince_toolbar.xml",
931 userdir = g_getenv ("GNOME22_USER_DIR");
933 old_dot_dir = g_build_filename (userdir, "evince", NULL);
934 old_accels = g_build_filename (userdir, "accels", "evince", NULL);
936 old_dot_dir = g_build_filename (g_get_home_dir (),
940 old_accels = g_build_filename (g_get_home_dir (),
945 if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
946 for (i = 0; config_files[i]; i++) {
952 old_filename = g_build_filename (old_dot_dir, config_files[i], NULL);
953 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
954 g_free (old_filename);
959 g_mkdir_with_parents (application->dot_dir, 0700);
963 new_filename = g_build_filename (application->dot_dir, config_files[i], NULL);
964 old_file = g_file_new_for_path (old_filename);
965 new_file = g_file_new_for_path (new_filename);
968 g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error);
970 g_warning ("Error migrating config file %s: %s\n",
971 old_filename, error->message);
972 g_error_free (error);
975 g_free (old_filename);
976 g_free (new_filename);
977 g_object_unref (old_file);
978 g_object_unref (new_file);
982 g_free (old_dot_dir);
984 if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) {
986 GFile *old_accels_file;
987 GFile *new_accels_file;
990 g_mkdir_with_parents (application->dot_dir, 0700);
992 new_accels = g_build_filename (application->dot_dir, "accels", NULL);
993 old_accels_file = g_file_new_for_path (old_accels);
994 new_accels_file = g_file_new_for_path (new_accels);
997 g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error);
999 g_warning ("Error migrating accelerator specifications file %s: %s\n",
1000 old_accels, error->message);
1001 g_error_free (error);
1004 g_free (new_accels);
1005 g_object_unref (old_accels_file);
1006 g_object_unref (new_accels_file);
1009 g_free (old_accels);
1013 ev_application_shutdown (EvApplication *application)
1015 if (application->uri) {
1017 ev_application_unregister_uri (application,
1020 g_free (application->uri);
1021 application->uri = NULL;
1024 ev_application_accel_map_save (application);
1026 g_object_unref (application->scr_saver);
1027 application->scr_saver = NULL;
1030 if (application->keys) {
1031 g_object_unref (application->keys);
1032 application->keys = NULL;
1034 if (application->registration_id != 0) {
1035 g_dbus_connection_unregister_object (application->connection,
1036 application->registration_id);
1037 application->registration_id = 0;
1039 if (application->connection != NULL) {
1040 g_object_unref (application->connection);
1041 application->connection = NULL;
1043 if (introspection_data) {
1044 g_dbus_node_info_ref (introspection_data);
1045 introspection_data = NULL;
1047 #endif /* ENABLE_DBUS */
1049 g_free (application->dot_dir);
1050 application->dot_dir = NULL;
1051 g_free (application->data_dir);
1052 application->data_dir = NULL;
1053 g_free (application->filechooser_open_uri);
1054 application->filechooser_open_uri = NULL;
1055 g_free (application->filechooser_save_uri);
1056 application->filechooser_save_uri = NULL;
1058 g_object_unref (application);
1065 ev_application_class_init (EvApplicationClass *ev_application_class)
1070 ev_application_init (EvApplication *ev_application)
1072 GError *error = NULL;
1074 ev_application->dot_dir = g_build_filename (g_get_user_config_dir (),
1076 if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1077 ev_application_migrate_config_dir (ev_application);
1083 dir = g_win32_get_package_installation_directory_of_module (NULL);
1084 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
1088 ev_application->data_dir = g_strdup (EVINCEDATADIR);
1091 ev_application_init_session (ev_application);
1093 ev_application_accel_map_load (ev_application);
1096 ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1097 if (ev_application->connection != NULL) {
1098 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1099 g_assert (introspection_data != NULL);
1101 ev_application->registration_id =
1102 g_dbus_connection_register_object (ev_application->connection,
1103 APPLICATION_DBUS_OBJECT_PATH,
1104 introspection_data->interfaces[0],
1106 ev_application, NULL,
1108 if (ev_application->registration_id == 0) {
1109 g_printerr ("Failed to register bus object: %s\n", error->message);
1110 g_error_free (error);
1113 g_printerr ("Failed to get bus connection: %s\n", error->message);
1114 g_error_free (error);
1117 ev_application->keys = ev_media_player_keys_new ();
1118 #endif /* ENABLE_DBUS */
1120 ev_application->scr_saver = totem_scrsaver_new ();
1121 g_object_set (ev_application->scr_saver,
1122 "reason", _("Running in presentation mode"),
1127 ev_application_get_dbus_connection (EvApplication *application)
1130 return application->connection;
1137 ev_application_has_window (EvApplication *application)
1139 GList *l, *toplevels;
1140 gboolean retval = FALSE;
1142 toplevels = gtk_window_list_toplevels ();
1144 for (l = toplevels; l != NULL && !retval; l = l->next) {
1145 if (EV_IS_WINDOW (l->data))
1149 g_list_free (toplevels);
1155 ev_application_get_n_windows (EvApplication *application)
1157 GList *l, *toplevels;
1160 toplevels = gtk_window_list_toplevels ();
1162 for (l = toplevels; l != NULL; l = l->next) {
1163 if (EV_IS_WINDOW (l->data))
1167 g_list_free (toplevels);
1173 ev_application_get_uri (EvApplication *application)
1175 return application->uri;
1179 * ev_application_get_media_keys:
1180 * @application: The instance of the application.
1182 * It gives you access to the media player keys handler object.
1184 * Returns: A #EvMediaPlayerKeys.
1187 ev_application_get_media_keys (EvApplication *application)
1190 return G_OBJECT (application->keys);
1193 #endif /* ENABLE_DBUS */
1197 ev_application_set_filechooser_uri (EvApplication *application,
1198 GtkFileChooserAction action,
1201 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1202 g_free (application->filechooser_open_uri);
1203 application->filechooser_open_uri = g_strdup (uri);
1204 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1205 g_free (application->filechooser_save_uri);
1206 application->filechooser_save_uri = g_strdup (uri);
1211 ev_application_get_filechooser_uri (EvApplication *application,
1212 GtkFileChooserAction action)
1214 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1215 if (application->filechooser_open_uri)
1216 return application->filechooser_open_uri;
1217 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1218 if (application->filechooser_save_uri)
1219 return application->filechooser_save_uri;
1226 ev_application_screensaver_enable (EvApplication *application)
1228 totem_scrsaver_enable (application->scr_saver);
1232 ev_application_screensaver_disable (EvApplication *application)
1234 totem_scrsaver_disable (application->scr_saver);
1238 ev_application_get_dot_dir (EvApplication *application,
1242 g_mkdir_with_parents (application->dot_dir, 0700);
1244 return application->dot_dir;
1248 ev_application_get_data_dir (EvApplication *application)
1250 return application->data_dir;