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 g_variant_builder_add (&builder, "{sv}",
474 g_variant_new_string (ev_link_dest_get_page_label (data->dest)));
476 if (data->search_string) {
477 g_variant_builder_add (&builder, "{sv}",
479 g_variant_new_string (data->search_string));
481 if (data->mode != EV_WINDOW_MODE_NORMAL) {
482 g_variant_builder_add (&builder, "{sv}",
484 g_variant_new_uint32 (data->mode));
486 g_variant_builder_close (&builder);
488 g_variant_builder_add (&builder, "u", data->timestamp);
490 g_dbus_connection_call (connection,
492 APPLICATION_DBUS_OBJECT_PATH,
493 APPLICATION_DBUS_INTERFACE,
495 g_variant_builder_end (&builder),
497 G_DBUS_CALL_FLAGS_NONE,
502 g_variant_unref (value);
503 ev_register_doc_data_free (data);
507 * ev_application_register_uri:
516 * Registers @uri with evince-daemon.
520 ev_application_register_uri (EvApplication *application,
524 EvWindowRunMode mode,
525 const gchar *search_string,
528 EvRegisterDocData *data;
530 if (!application->connection)
533 if (application->doc_registered) {
534 /* Already registered, reload */
537 windows = ev_application_get_windows (application);
538 for (l = windows; l != NULL; l = g_list_next (l)) {
539 EvWindow *ev_window = EV_WINDOW (l->data);
541 ev_application_open_uri_in_window (application, uri, ev_window,
546 g_list_free (windows);
551 data = g_new (EvRegisterDocData, 1);
552 data->uri = g_strdup (uri);
553 data->screen = screen;
554 data->dest = dest ? g_object_ref (dest) : NULL;
556 data->search_string = search_string ? g_strdup (search_string) : NULL;
557 data->timestamp = timestamp;
559 g_dbus_connection_call (application->connection,
560 EVINCE_DAEMON_SERVICE,
561 EVINCE_DAEMON_OBJECT_PATH,
562 EVINCE_DAEMON_INTERFACE,
564 g_variant_new ("(s)", uri),
565 G_VARIANT_TYPE ("(s)"),
566 G_DBUS_CALL_FLAGS_NONE,
574 ev_application_unregister_uri (EvApplication *application,
578 GError *error = NULL;
580 if (!application->doc_registered)
583 /* This is called from ev_application_shutdown(),
584 * so it's safe to use the sync api
586 value = g_dbus_connection_call_sync (
587 application->connection,
588 EVINCE_DAEMON_SERVICE,
589 EVINCE_DAEMON_OBJECT_PATH,
590 EVINCE_DAEMON_INTERFACE,
591 "UnregisterDocument",
592 g_variant_new ("(s)", uri),
594 G_DBUS_CALL_FLAGS_NO_AUTO_START,
599 g_warning ("Error unregistering document: %s\n", error->message);
600 g_error_free (error);
602 g_variant_unref (value);
605 #endif /* ENABLE_DBUS */
608 ev_application_open_uri_in_window (EvApplication *application,
613 EvWindowRunMode mode,
614 const gchar *search_string,
617 #ifdef GDK_WINDOWING_X11
618 GdkWindow *gdk_window;
622 ev_stock_icons_set_screen (screen);
623 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
626 /* We need to load uri before showing the window, so
627 we can restore window size without flickering */
628 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
630 if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
631 gtk_widget_realize (GTK_WIDGET (ev_window));
633 #ifdef GDK_WINDOWING_X11
634 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
637 timestamp = gdk_x11_get_server_time (gdk_window);
638 gdk_x11_window_set_user_time (gdk_window, timestamp);
640 gtk_window_present (GTK_WINDOW (ev_window));
642 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
643 #endif /* GDK_WINDOWING_X11 */
647 _ev_application_open_uri_at_dest (EvApplication *application,
651 EvWindowRunMode mode,
652 const gchar *search_string,
657 ev_window = ev_application_get_empty_window (application, screen);
659 ev_window = EV_WINDOW (ev_window_new ());
661 ev_application_open_uri_in_window (application, uri, ev_window,
668 * ev_application_open_uri_at_dest:
669 * @application: The instance of the application.
670 * @uri: The uri to be opened.
671 * @screen: Thee screen where the link will be shown.
672 * @dest: The #EvLinkDest of the document.
673 * @mode: The run mode of the window.
674 * @timestamp: Current time value.
677 ev_application_open_uri_at_dest (EvApplication *application,
681 EvWindowRunMode mode,
682 const gchar *search_string,
685 g_return_if_fail (uri != NULL);
687 if (application->uri && strcmp (application->uri, uri) != 0) {
688 /* spawn a new evince process */
689 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
691 } else if (!application->uri) {
692 application->uri = g_strdup (uri);
696 /* Register the uri or send Reload to
697 * remote instance if already registered
699 ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp);
701 _ev_application_open_uri_at_dest (application, uri, screen, dest, mode, search_string, timestamp);
702 #endif /* ENABLE_DBUS */
706 * ev_application_open_window:
707 * @application: The instance of the application.
708 * @timestamp: Current time value.
710 * Creates a new window
713 ev_application_open_window (EvApplication *application,
717 GtkWidget *new_window = ev_window_new ();
718 #ifdef GDK_WINDOWING_X11
719 GdkWindow *gdk_window;
723 ev_stock_icons_set_screen (screen);
724 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
727 if (!gtk_widget_get_realized (new_window))
728 gtk_widget_realize (new_window);
730 #ifdef GDK_WINDOWING_X11
731 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
734 timestamp = gdk_x11_get_server_time (gdk_window);
735 gdk_x11_window_set_user_time (gdk_window, timestamp);
737 gtk_window_present (GTK_WINDOW (new_window));
739 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
740 #endif /* GDK_WINDOWING_X11 */
745 method_call_cb (GDBusConnection *connection,
747 const gchar *object_path,
748 const gchar *interface_name,
749 const gchar *method_name,
750 GVariant *parameters,
751 GDBusMethodInvocation *invocation,
754 EvApplication *application = EV_APPLICATION (user_data);
760 GdkDisplay *display = NULL;
761 int screen_number = 0;
762 EvLinkDest *dest = NULL;
763 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
764 const gchar *search_string = NULL;
765 GdkScreen *screen = NULL;
767 if (g_strcmp0 (method_name, "Reload") == 0) {
768 g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp);
770 while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
771 if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
772 display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
773 } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
774 screen_number = g_variant_get_int32 (value);
775 } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
776 mode = g_variant_get_uint32 (value);
777 } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
778 dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
779 } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
780 search_string = g_variant_get_string (value, NULL);
783 g_variant_iter_free (iter);
785 if (display != NULL &&
786 screen_number >= 0 &&
787 screen_number < gdk_display_get_n_screens (display))
788 screen = gdk_display_get_screen (display, screen_number);
790 screen = gdk_screen_get_default ();
792 windows = ev_application_get_windows (application);
793 for (l = windows; l != NULL; l = g_list_next (l)) {
794 EvWindow *ev_window = EV_WINDOW (l->data);
796 ev_application_open_uri_in_window (application, application->uri,
802 g_list_free (windows);
805 g_object_unref (dest);
807 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
808 } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
809 GList *windows = ev_application_get_windows (application);
810 GVariantBuilder builder;
813 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
814 g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
816 for (l = windows; l; l = g_list_next (l)) {
817 EvWindow *window = (EvWindow *)l->data;
819 g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
822 g_variant_builder_close (&builder);
823 g_list_free (windows);
825 g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
829 static const char introspection_xml[] =
831 "<interface name='org.gnome.evince.Application'>"
832 "<method name='Reload'>"
833 "<arg type='a{sv}' name='args' direction='in'/>"
834 "<arg type='u' name='timestamp' direction='in'/>"
836 "<method name='GetWindowList'>"
837 "<arg type='ao' name='window_list' direction='out'/>"
842 static const GDBusInterfaceVTable interface_vtable = {
848 static GDBusNodeInfo *introspection_data;
849 #endif /* ENABLE_DBUS */
852 ev_application_open_uri_list (EvApplication *application,
859 for (l = uri_list; l != NULL; l = l->next) {
860 ev_application_open_uri_at_dest (application, (char *)l->data,
861 screen, NULL, 0, NULL,
867 ev_application_accel_map_save (EvApplication *application)
869 gchar *accel_map_file;
873 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
874 tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
876 fd = g_mkstemp (tmp_filename);
878 g_free (accel_map_file);
879 g_free (tmp_filename);
883 gtk_accel_map_save_fd (fd);
886 g_mkdir_with_parents (application->dot_dir, 0700);
887 if (g_rename (tmp_filename, accel_map_file) == -1) {
889 g_unlink (tmp_filename);
892 g_free (accel_map_file);
893 g_free (tmp_filename);
897 ev_application_accel_map_load (EvApplication *application)
899 gchar *accel_map_file;
901 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
902 gtk_accel_map_load (accel_map_file);
903 g_free (accel_map_file);
907 ev_application_migrate_config_dir (EvApplication *application)
909 const gchar *userdir;
914 gboolean dir_created = FALSE;
915 static const gchar *config_files[] = {
916 "evince_toolbar.xml",
921 userdir = g_getenv ("GNOME22_USER_DIR");
923 old_dot_dir = g_build_filename (userdir, "evince", NULL);
924 old_accels = g_build_filename (userdir, "accels", "evince", NULL);
926 old_dot_dir = g_build_filename (g_get_home_dir (),
930 old_accels = g_build_filename (g_get_home_dir (),
935 if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
936 for (i = 0; config_files[i]; i++) {
942 old_filename = g_build_filename (old_dot_dir, config_files[i], NULL);
943 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
944 g_free (old_filename);
949 g_mkdir_with_parents (application->dot_dir, 0700);
953 new_filename = g_build_filename (application->dot_dir, config_files[i], NULL);
954 old_file = g_file_new_for_path (old_filename);
955 new_file = g_file_new_for_path (new_filename);
958 g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error);
960 g_warning ("Error migrating config file %s: %s\n",
961 old_filename, error->message);
962 g_error_free (error);
965 g_free (old_filename);
966 g_free (new_filename);
967 g_object_unref (old_file);
968 g_object_unref (new_file);
972 g_free (old_dot_dir);
974 if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) {
976 GFile *old_accels_file;
977 GFile *new_accels_file;
980 g_mkdir_with_parents (application->dot_dir, 0700);
982 new_accels = g_build_filename (application->dot_dir, "accels", NULL);
983 old_accels_file = g_file_new_for_path (old_accels);
984 new_accels_file = g_file_new_for_path (new_accels);
987 g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error);
989 g_warning ("Error migrating accelerator specifications file %s: %s\n",
990 old_accels, error->message);
991 g_error_free (error);
995 g_object_unref (old_accels_file);
996 g_object_unref (new_accels_file);
1003 ev_application_shutdown (EvApplication *application)
1005 if (application->uri) {
1007 ev_application_unregister_uri (application,
1010 g_free (application->uri);
1011 application->uri = NULL;
1014 ev_application_accel_map_save (application);
1016 g_object_unref (application->scr_saver);
1017 application->scr_saver = NULL;
1020 if (application->keys) {
1021 g_object_unref (application->keys);
1022 application->keys = NULL;
1024 if (application->registration_id != 0) {
1025 g_dbus_connection_unregister_object (application->connection,
1026 application->registration_id);
1027 application->registration_id = 0;
1029 if (application->connection != NULL) {
1030 g_object_unref (application->connection);
1031 application->connection = NULL;
1033 if (introspection_data) {
1034 g_dbus_node_info_ref (introspection_data);
1035 introspection_data = NULL;
1037 #endif /* ENABLE_DBUS */
1039 g_free (application->dot_dir);
1040 application->dot_dir = NULL;
1041 g_free (application->data_dir);
1042 application->data_dir = NULL;
1043 g_free (application->filechooser_open_uri);
1044 application->filechooser_open_uri = NULL;
1045 g_free (application->filechooser_save_uri);
1046 application->filechooser_save_uri = NULL;
1048 g_object_unref (application);
1055 ev_application_class_init (EvApplicationClass *ev_application_class)
1060 ev_application_init (EvApplication *ev_application)
1062 GError *error = NULL;
1064 ev_application->dot_dir = g_build_filename (g_get_user_config_dir (),
1066 if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1067 ev_application_migrate_config_dir (ev_application);
1073 dir = g_win32_get_package_installation_directory_of_module (NULL);
1074 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
1078 ev_application->data_dir = g_strdup (EVINCEDATADIR);
1081 ev_application_init_session (ev_application);
1083 ev_application_accel_map_load (ev_application);
1086 ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1087 if (ev_application->connection != NULL) {
1088 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1089 g_assert (introspection_data != NULL);
1091 ev_application->registration_id =
1092 g_dbus_connection_register_object (ev_application->connection,
1093 APPLICATION_DBUS_OBJECT_PATH,
1094 introspection_data->interfaces[0],
1096 ev_application, NULL,
1098 if (ev_application->registration_id == 0) {
1099 g_printerr ("Failed to register bus object: %s\n", error->message);
1100 g_error_free (error);
1103 g_printerr ("Failed to get bus connection: %s\n", error->message);
1104 g_error_free (error);
1107 ev_application->keys = ev_media_player_keys_new ();
1108 #endif /* ENABLE_DBUS */
1110 ev_application->scr_saver = totem_scrsaver_new ();
1111 g_object_set (ev_application->scr_saver,
1112 "reason", _("Running in presentation mode"),
1117 ev_application_get_dbus_connection (EvApplication *application)
1120 return application->connection;
1127 ev_application_has_window (EvApplication *application)
1129 GList *l, *toplevels;
1130 gboolean retval = FALSE;
1132 toplevels = gtk_window_list_toplevels ();
1134 for (l = toplevels; l != NULL && !retval; l = l->next) {
1135 if (EV_IS_WINDOW (l->data))
1139 g_list_free (toplevels);
1145 ev_application_get_n_windows (EvApplication *application)
1147 GList *l, *toplevels;
1150 toplevels = gtk_window_list_toplevels ();
1152 for (l = toplevels; l != NULL; l = l->next) {
1153 if (EV_IS_WINDOW (l->data))
1157 g_list_free (toplevels);
1163 ev_application_get_uri (EvApplication *application)
1165 return application->uri;
1169 * ev_application_get_media_keys:
1170 * @application: The instance of the application.
1172 * It gives you access to the media player keys handler object.
1174 * Returns: A #EvMediaPlayerKeys.
1177 ev_application_get_media_keys (EvApplication *application)
1180 return G_OBJECT (application->keys);
1183 #endif /* ENABLE_DBUS */
1187 ev_application_set_filechooser_uri (EvApplication *application,
1188 GtkFileChooserAction action,
1191 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1192 g_free (application->filechooser_open_uri);
1193 application->filechooser_open_uri = g_strdup (uri);
1194 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1195 g_free (application->filechooser_save_uri);
1196 application->filechooser_save_uri = g_strdup (uri);
1201 ev_application_get_filechooser_uri (EvApplication *application,
1202 GtkFileChooserAction action)
1204 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1205 if (application->filechooser_open_uri)
1206 return application->filechooser_open_uri;
1207 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1208 if (application->filechooser_save_uri)
1209 return application->filechooser_save_uri;
1216 ev_application_screensaver_enable (EvApplication *application)
1218 totem_scrsaver_enable (application->scr_saver);
1222 ev_application_screensaver_disable (EvApplication *application)
1224 totem_scrsaver_disable (application->scr_saver);
1228 ev_application_get_dot_dir (EvApplication *application,
1232 g_mkdir_with_parents (application->dot_dir, 0700);
1234 return application->dot_dir;
1238 ev_application_get_data_dir (EvApplication *application)
1240 return application->data_dir;