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 g_string_append_printf (cmd, " %s", uri);
288 cmdline = g_string_free (cmd, FALSE);
289 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 g_app_info_launch (app, NULL,
297 G_APP_LAUNCH_CONTEXT (ctx), &error);
299 g_object_unref (app);
300 g_object_unref (ctx);
304 g_warning ("Error launching evince %s: %s\n", uri, error->message);
305 g_error_free (error);
312 ev_application_get_windows (EvApplication *application)
314 GList *l, *toplevels;
315 GList *windows = NULL;
317 toplevels = gtk_window_list_toplevels ();
319 for (l = toplevels; l != NULL; l = l->next) {
320 if (EV_IS_WINDOW (l->data)) {
321 windows = g_list_append (windows, l->data);
325 g_list_free (toplevels);
331 ev_application_get_empty_window (EvApplication *application,
334 EvWindow *empty_window = NULL;
335 GList *windows = ev_application_get_windows (application);
338 for (l = windows; l != NULL; l = l->next) {
339 EvWindow *window = EV_WINDOW (l->data);
341 if (ev_window_is_empty (window) &&
342 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
343 empty_window = window;
348 g_list_free (windows);
359 EvWindowRunMode mode;
360 gchar *search_string;
365 ev_register_doc_data_free (EvRegisterDocData *data)
371 if (data->search_string)
372 g_free (data->search_string);
374 g_object_unref (data->dest);
380 on_reload_cb (GObject *source_object,
384 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
386 GError *error = NULL;
388 value = g_dbus_connection_call_finish (connection, res, &error);
390 g_warning ("Failed to Reload: %s", error->message);
391 g_error_free (error);
393 g_variant_unref (value);
395 /* We did not open a window, so manually clear the startup
397 gdk_notify_startup_complete ();
399 ev_application_shutdown (EV_APP);
403 on_register_uri_cb (GObject *source_object,
407 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
408 EvRegisterDocData *data = (EvRegisterDocData *)user_data;
409 EvApplication *application = EV_APP;
412 GVariantBuilder builder;
413 GError *error = NULL;
415 value = g_dbus_connection_call_finish (connection, res, &error);
417 g_warning ("Error registering document: %s\n", error->message);
418 g_error_free (error);
420 _ev_application_open_uri_at_dest (application,
427 ev_register_doc_data_free (data);
432 g_variant_get (value, "(&s)", &owner);
434 /* This means that the document wasn't already registered; go
435 * ahead with opening it.
437 if (owner[0] == '\0') {
438 g_variant_unref (value);
440 application->doc_registered = TRUE;
442 _ev_application_open_uri_at_dest (application,
449 ev_register_doc_data_free (data);
454 /* Already registered */
455 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)"));
456 g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
457 g_variant_builder_add (&builder, "{sv}",
459 g_variant_new_string (gdk_display_get_name (gdk_screen_get_display (data->screen))));
460 g_variant_builder_add (&builder, "{sv}",
462 g_variant_new_int32 (gdk_screen_get_number (data->screen)));
464 g_variant_builder_add (&builder, "{sv}",
466 g_variant_new_string (ev_link_dest_get_page_label (data->dest)));
468 if (data->search_string) {
469 g_variant_builder_add (&builder, "{sv}",
471 g_variant_new_string (data->search_string));
473 if (data->mode != EV_WINDOW_MODE_NORMAL) {
474 g_variant_builder_add (&builder, "{sv}",
476 g_variant_new_uint32 (data->mode));
478 g_variant_builder_close (&builder);
480 g_variant_builder_add (&builder, "u", data->timestamp);
482 g_dbus_connection_call (connection,
484 APPLICATION_DBUS_OBJECT_PATH,
485 APPLICATION_DBUS_INTERFACE,
487 g_variant_builder_end (&builder),
489 G_DBUS_CALL_FLAGS_NONE,
494 g_variant_unref (value);
495 ev_register_doc_data_free (data);
499 * ev_application_register_uri:
508 * Registers @uri with evince-daemon.
512 ev_application_register_uri (EvApplication *application,
516 EvWindowRunMode mode,
517 const gchar *search_string,
520 EvRegisterDocData *data;
522 if (!application->connection)
525 if (application->doc_registered) {
526 /* Already registered, reload */
529 windows = ev_application_get_windows (application);
530 for (l = windows; l != NULL; l = g_list_next (l)) {
531 EvWindow *ev_window = EV_WINDOW (l->data);
533 ev_application_open_uri_in_window (application, uri, ev_window,
538 g_list_free (windows);
543 data = g_new (EvRegisterDocData, 1);
544 data->uri = g_strdup (uri);
545 data->screen = screen;
546 data->dest = dest ? g_object_ref (dest) : NULL;
548 data->search_string = search_string ? g_strdup (search_string) : NULL;
549 data->timestamp = timestamp;
551 g_dbus_connection_call (application->connection,
552 EVINCE_DAEMON_SERVICE,
553 EVINCE_DAEMON_OBJECT_PATH,
554 EVINCE_DAEMON_INTERFACE,
556 g_variant_new ("(s)", uri),
557 G_VARIANT_TYPE ("(s)"),
558 G_DBUS_CALL_FLAGS_NONE,
566 ev_application_unregister_uri (EvApplication *application,
570 GError *error = NULL;
572 if (!application->doc_registered)
575 /* This is called from ev_application_shutdown(),
576 * so it's safe to use the sync api
578 value = g_dbus_connection_call_sync (
579 application->connection,
580 EVINCE_DAEMON_SERVICE,
581 EVINCE_DAEMON_OBJECT_PATH,
582 EVINCE_DAEMON_INTERFACE,
583 "UnregisterDocument",
584 g_variant_new ("(s)", uri),
586 G_DBUS_CALL_FLAGS_NO_AUTO_START,
591 g_warning ("Error unregistering document: %s\n", error->message);
592 g_error_free (error);
594 g_variant_unref (value);
597 #endif /* ENABLE_DBUS */
600 ev_application_open_uri_in_window (EvApplication *application,
605 EvWindowRunMode mode,
606 const gchar *search_string,
609 #ifdef GDK_WINDOWING_X11
610 GdkWindow *gdk_window;
614 ev_stock_icons_set_screen (screen);
615 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
618 /* We need to load uri before showing the window, so
619 we can restore window size without flickering */
620 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
622 if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
623 gtk_widget_realize (GTK_WIDGET (ev_window));
625 #ifdef GDK_WINDOWING_X11
626 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
629 timestamp = gdk_x11_get_server_time (gdk_window);
630 gdk_x11_window_set_user_time (gdk_window, timestamp);
632 gtk_window_present (GTK_WINDOW (ev_window));
634 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
635 #endif /* GDK_WINDOWING_X11 */
639 _ev_application_open_uri_at_dest (EvApplication *application,
643 EvWindowRunMode mode,
644 const gchar *search_string,
649 ev_window = ev_application_get_empty_window (application, screen);
651 ev_window = EV_WINDOW (ev_window_new ());
653 ev_application_open_uri_in_window (application, uri, ev_window,
660 * ev_application_open_uri_at_dest:
661 * @application: The instance of the application.
662 * @uri: The uri to be opened.
663 * @screen: Thee screen where the link will be shown.
664 * @dest: The #EvLinkDest of the document.
665 * @mode: The run mode of the window.
666 * @timestamp: Current time value.
669 ev_application_open_uri_at_dest (EvApplication *application,
673 EvWindowRunMode mode,
674 const gchar *search_string,
677 g_return_if_fail (uri != NULL);
679 if (application->uri && strcmp (application->uri, uri) != 0) {
680 /* spawn a new evince process */
681 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
683 } else if (!application->uri) {
684 application->uri = g_strdup (uri);
688 /* Register the uri or send Reload to
689 * remote instance if already registered
691 ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp);
693 _ev_application_open_uri_at_dest (application, uri, screen, dest, mode, search_string, timestamp);
694 #endif /* ENABLE_DBUS */
698 * ev_application_open_window:
699 * @application: The instance of the application.
700 * @timestamp: Current time value.
702 * Creates a new window
705 ev_application_open_window (EvApplication *application,
709 GtkWidget *new_window = ev_window_new ();
710 #ifdef GDK_WINDOWING_X11
711 GdkWindow *gdk_window;
715 ev_stock_icons_set_screen (screen);
716 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
719 if (!gtk_widget_get_realized (new_window))
720 gtk_widget_realize (new_window);
722 #ifdef GDK_WINDOWING_X11
723 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
726 timestamp = gdk_x11_get_server_time (gdk_window);
727 gdk_x11_window_set_user_time (gdk_window, timestamp);
729 gtk_window_present (GTK_WINDOW (new_window));
731 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
732 #endif /* GDK_WINDOWING_X11 */
737 method_call_cb (GDBusConnection *connection,
739 const gchar *object_path,
740 const gchar *interface_name,
741 const gchar *method_name,
742 GVariant *parameters,
743 GDBusMethodInvocation *invocation,
746 EvApplication *application = EV_APPLICATION (user_data);
752 GdkDisplay *display = NULL;
753 int screen_number = 0;
754 EvLinkDest *dest = NULL;
755 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
756 const gchar *search_string = NULL;
757 GdkScreen *screen = NULL;
759 if (g_strcmp0 (method_name, "Reload") == 0) {
760 g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp);
762 while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
763 if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
764 display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
765 } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
766 screen_number = g_variant_get_int32 (value);
767 } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
768 mode = g_variant_get_uint32 (value);
769 } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
770 dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
771 } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
772 search_string = g_variant_get_string (value, NULL);
775 g_variant_iter_free (iter);
777 if (display != NULL &&
778 screen_number >= 0 &&
779 screen_number < gdk_display_get_n_screens (display))
780 screen = gdk_display_get_screen (display, screen_number);
782 screen = gdk_screen_get_default ();
784 windows = ev_application_get_windows (application);
785 for (l = windows; l != NULL; l = g_list_next (l)) {
786 EvWindow *ev_window = EV_WINDOW (l->data);
788 ev_application_open_uri_in_window (application, application->uri,
794 g_list_free (windows);
797 g_object_unref (dest);
799 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
800 } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
801 GList *windows = ev_application_get_windows (application);
802 GVariantBuilder builder;
805 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
806 g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
808 for (l = windows; l; l = g_list_next (l)) {
809 EvWindow *window = (EvWindow *)l->data;
811 g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
814 g_variant_builder_close (&builder);
815 g_list_free (windows);
817 g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
821 static const char introspection_xml[] =
823 "<interface name='org.gnome.evince.Application'>"
824 "<method name='Reload'>"
825 "<arg type='a{sv}' name='args' direction='in'/>"
826 "<arg type='u' name='timestamp' direction='in'/>"
828 "<method name='GetWindowList'>"
829 "<arg type='ao' name='window_list' direction='out'/>"
834 static const GDBusInterfaceVTable interface_vtable = {
840 static GDBusNodeInfo *introspection_data;
841 #endif /* ENABLE_DBUS */
844 ev_application_open_uri_list (EvApplication *application,
851 for (l = uri_list; l != NULL; l = l->next) {
852 ev_application_open_uri_at_dest (application, (char *)l->data,
853 screen, NULL, 0, NULL,
859 ev_application_accel_map_save (EvApplication *application)
861 gchar *accel_map_file;
865 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
866 tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
868 fd = g_mkstemp (tmp_filename);
870 g_free (accel_map_file);
871 g_free (tmp_filename);
875 gtk_accel_map_save_fd (fd);
878 g_mkdir_with_parents (application->dot_dir, 0700);
879 if (g_rename (tmp_filename, accel_map_file) == -1) {
881 g_unlink (tmp_filename);
884 g_free (accel_map_file);
885 g_free (tmp_filename);
889 ev_application_accel_map_load (EvApplication *application)
891 gchar *accel_map_file;
893 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
894 gtk_accel_map_load (accel_map_file);
895 g_free (accel_map_file);
899 ev_application_migrate_config_dir (EvApplication *application)
901 const gchar *userdir;
906 gboolean dir_created = FALSE;
907 static const gchar *config_files[] = {
908 "evince_toolbar.xml",
913 userdir = g_getenv ("GNOME22_USER_DIR");
915 old_dot_dir = g_build_filename (userdir, "evince", NULL);
916 old_accels = g_build_filename (userdir, "accels", "evince", NULL);
918 old_dot_dir = g_build_filename (g_get_home_dir (),
922 old_accels = g_build_filename (g_get_home_dir (),
927 if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
928 for (i = 0; config_files[i]; i++) {
934 old_filename = g_build_filename (old_dot_dir, config_files[i], NULL);
935 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
936 g_free (old_filename);
941 g_mkdir_with_parents (application->dot_dir, 0700);
945 new_filename = g_build_filename (application->dot_dir, config_files[i], NULL);
946 old_file = g_file_new_for_path (old_filename);
947 new_file = g_file_new_for_path (new_filename);
950 g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error);
952 g_warning ("Error migrating config file %s: %s\n",
953 old_filename, error->message);
954 g_error_free (error);
957 g_free (old_filename);
958 g_free (new_filename);
959 g_object_unref (old_file);
960 g_object_unref (new_file);
964 g_free (old_dot_dir);
966 if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) {
968 GFile *old_accels_file;
969 GFile *new_accels_file;
972 g_mkdir_with_parents (application->dot_dir, 0700);
974 new_accels = g_build_filename (application->dot_dir, "accels", NULL);
975 old_accels_file = g_file_new_for_path (old_accels);
976 new_accels_file = g_file_new_for_path (new_accels);
979 g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error);
981 g_warning ("Error migrating accelerator specifications file %s: %s\n",
982 old_accels, error->message);
983 g_error_free (error);
987 g_object_unref (old_accels_file);
988 g_object_unref (new_accels_file);
995 ev_application_shutdown (EvApplication *application)
997 if (application->uri) {
999 ev_application_unregister_uri (application,
1002 g_free (application->uri);
1003 application->uri = NULL;
1006 ev_application_accel_map_save (application);
1008 g_object_unref (application->scr_saver);
1009 application->scr_saver = NULL;
1012 if (application->keys) {
1013 g_object_unref (application->keys);
1014 application->keys = NULL;
1016 if (application->registration_id != 0) {
1017 g_dbus_connection_unregister_object (application->connection,
1018 application->registration_id);
1019 application->registration_id = 0;
1021 if (application->connection != NULL) {
1022 g_object_unref (application->connection);
1023 application->connection = NULL;
1025 if (introspection_data) {
1026 g_dbus_node_info_ref (introspection_data);
1027 introspection_data = NULL;
1029 #endif /* ENABLE_DBUS */
1031 g_free (application->dot_dir);
1032 application->dot_dir = NULL;
1033 g_free (application->data_dir);
1034 application->data_dir = NULL;
1035 g_free (application->filechooser_open_uri);
1036 application->filechooser_open_uri = NULL;
1037 g_free (application->filechooser_save_uri);
1038 application->filechooser_save_uri = NULL;
1040 g_object_unref (application);
1047 ev_application_class_init (EvApplicationClass *ev_application_class)
1052 ev_application_init (EvApplication *ev_application)
1054 GError *error = NULL;
1056 ev_application->dot_dir = g_build_filename (g_get_user_config_dir (),
1058 if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1059 ev_application_migrate_config_dir (ev_application);
1065 dir = g_win32_get_package_installation_directory_of_module (NULL);
1066 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
1070 ev_application->data_dir = g_strdup (EVINCEDATADIR);
1073 ev_application_init_session (ev_application);
1075 ev_application_accel_map_load (ev_application);
1078 ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1079 if (ev_application->connection != NULL) {
1080 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1081 g_assert (introspection_data != NULL);
1083 ev_application->registration_id =
1084 g_dbus_connection_register_object (ev_application->connection,
1085 APPLICATION_DBUS_OBJECT_PATH,
1086 introspection_data->interfaces[0],
1088 ev_application, NULL,
1090 if (ev_application->registration_id == 0) {
1091 g_printerr ("Failed to register bus object: %s\n", error->message);
1092 g_error_free (error);
1095 g_printerr ("Failed to get bus connection: %s\n", error->message);
1096 g_error_free (error);
1099 ev_application->keys = ev_media_player_keys_new ();
1100 #endif /* ENABLE_DBUS */
1102 ev_application->scr_saver = totem_scrsaver_new ();
1103 g_object_set (ev_application->scr_saver,
1104 "reason", _("Running in presentation mode"),
1109 ev_application_get_dbus_connection (EvApplication *application)
1112 return application->connection;
1119 ev_application_has_window (EvApplication *application)
1121 GList *l, *toplevels;
1122 gboolean retval = FALSE;
1124 toplevels = gtk_window_list_toplevels ();
1126 for (l = toplevels; l != NULL && !retval; l = l->next) {
1127 if (EV_IS_WINDOW (l->data))
1131 g_list_free (toplevels);
1137 ev_application_get_n_windows (EvApplication *application)
1139 GList *l, *toplevels;
1142 toplevels = gtk_window_list_toplevels ();
1144 for (l = toplevels; l != NULL; l = l->next) {
1145 if (EV_IS_WINDOW (l->data))
1149 g_list_free (toplevels);
1155 ev_application_get_uri (EvApplication *application)
1157 return application->uri;
1161 * ev_application_get_media_keys:
1162 * @application: The instance of the application.
1164 * It gives you access to the media player keys handler object.
1166 * Returns: A #EvMediaPlayerKeys.
1169 ev_application_get_media_keys (EvApplication *application)
1172 return G_OBJECT (application->keys);
1175 #endif /* ENABLE_DBUS */
1179 ev_application_set_filechooser_uri (EvApplication *application,
1180 GtkFileChooserAction action,
1183 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1184 g_free (application->filechooser_open_uri);
1185 application->filechooser_open_uri = g_strdup (uri);
1186 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1187 g_free (application->filechooser_save_uri);
1188 application->filechooser_save_uri = g_strdup (uri);
1193 ev_application_get_filechooser_uri (EvApplication *application,
1194 GtkFileChooserAction action)
1196 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1197 if (application->filechooser_open_uri)
1198 return application->filechooser_open_uri;
1199 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1200 if (application->filechooser_save_uri)
1201 return application->filechooser_save_uri;
1208 ev_application_screensaver_enable (EvApplication *application)
1210 totem_scrsaver_enable (application->scr_saver);
1214 ev_application_screensaver_disable (EvApplication *application)
1216 totem_scrsaver_disable (application->scr_saver);
1220 ev_application_get_dot_dir (EvApplication *application,
1224 g_mkdir_with_parents (application->dot_dir, 0700);
1226 return application->dot_dir;
1230 ev_application_get_data_dir (EvApplication *application)
1232 return application->data_dir;