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 ev_application_shutdown (EV_APP);
399 on_register_uri_cb (GObject *source_object,
403 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
404 EvRegisterDocData *data = (EvRegisterDocData *)user_data;
405 EvApplication *application = EV_APP;
408 GVariantBuilder builder;
409 GError *error = NULL;
411 value = g_dbus_connection_call_finish (connection, res, &error);
413 g_warning ("Error registering document: %s\n", error->message);
414 g_error_free (error);
416 _ev_application_open_uri_at_dest (application,
423 ev_register_doc_data_free (data);
428 g_variant_get (value, "(&s)", &owner);
430 /* This means that the document wasn't already registered; go
431 * ahead with opening it.
433 if (owner[0] == '\0') {
434 g_variant_unref (value);
436 application->doc_registered = TRUE;
438 _ev_application_open_uri_at_dest (application,
445 ev_register_doc_data_free (data);
450 /* Already registered */
451 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)"));
452 g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
453 g_variant_builder_add (&builder, "{sv}",
455 g_variant_new_string (gdk_display_get_name (gdk_screen_get_display (data->screen))));
456 g_variant_builder_add (&builder, "{sv}",
458 g_variant_new_int32 (gdk_screen_get_number (data->screen)));
460 g_variant_builder_add (&builder, "{sv}",
462 g_variant_new_string (ev_link_dest_get_page_label (data->dest)));
464 if (data->search_string) {
465 g_variant_builder_add (&builder, "{sv}",
467 g_variant_new_string (data->search_string));
469 if (data->mode != EV_WINDOW_MODE_NORMAL) {
470 g_variant_builder_add (&builder, "{sv}",
472 g_variant_new_uint32 (data->mode));
474 g_variant_builder_close (&builder);
476 g_variant_builder_add (&builder, "u", data->timestamp);
478 g_dbus_connection_call (connection,
480 APPLICATION_DBUS_OBJECT_PATH,
481 APPLICATION_DBUS_INTERFACE,
483 g_variant_builder_end (&builder),
485 G_DBUS_CALL_FLAGS_NONE,
490 g_variant_unref (value);
491 ev_register_doc_data_free (data);
495 * ev_application_register_uri:
504 * Registers @uri with evince-daemon.
508 ev_application_register_uri (EvApplication *application,
512 EvWindowRunMode mode,
513 const gchar *search_string,
516 EvRegisterDocData *data;
518 if (!application->connection)
521 if (application->doc_registered) {
522 /* Already registered, reload */
525 windows = ev_application_get_windows (application);
526 for (l = windows; l != NULL; l = g_list_next (l)) {
527 EvWindow *ev_window = EV_WINDOW (l->data);
529 ev_application_open_uri_in_window (application, uri, ev_window,
534 g_list_free (windows);
539 data = g_new (EvRegisterDocData, 1);
540 data->uri = g_strdup (uri);
541 data->screen = screen;
542 data->dest = dest ? g_object_ref (dest) : NULL;
544 data->search_string = search_string ? g_strdup (search_string) : NULL;
545 data->timestamp = timestamp;
547 g_dbus_connection_call (application->connection,
548 EVINCE_DAEMON_SERVICE,
549 EVINCE_DAEMON_OBJECT_PATH,
550 EVINCE_DAEMON_INTERFACE,
552 g_variant_new ("(s)", uri),
553 G_VARIANT_TYPE ("(s)"),
554 G_DBUS_CALL_FLAGS_NONE,
562 ev_application_unregister_uri (EvApplication *application,
566 GError *error = NULL;
568 if (!application->doc_registered)
571 /* This is called from ev_application_shutdown(),
572 * so it's safe to use the sync api
574 value = g_dbus_connection_call_sync (
575 application->connection,
576 EVINCE_DAEMON_SERVICE,
577 EVINCE_DAEMON_OBJECT_PATH,
578 EVINCE_DAEMON_INTERFACE,
579 "UnregisterDocument",
580 g_variant_new ("(s)", uri),
582 G_DBUS_CALL_FLAGS_NO_AUTO_START,
587 g_warning ("Error unregistering document: %s\n", error->message);
588 g_error_free (error);
590 g_variant_unref (value);
593 #endif /* ENABLE_DBUS */
596 ev_application_open_uri_in_window (EvApplication *application,
601 EvWindowRunMode mode,
602 const gchar *search_string,
605 #ifdef GDK_WINDOWING_X11
606 GdkWindow *gdk_window;
610 ev_stock_icons_set_screen (screen);
611 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
614 /* We need to load uri before showing the window, so
615 we can restore window size without flickering */
616 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
618 if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
619 gtk_widget_realize (GTK_WIDGET (ev_window));
621 #ifdef GDK_WINDOWING_X11
622 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
625 timestamp = gdk_x11_get_server_time (gdk_window);
626 gdk_x11_window_set_user_time (gdk_window, timestamp);
628 gtk_window_present (GTK_WINDOW (ev_window));
630 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
631 #endif /* GDK_WINDOWING_X11 */
635 _ev_application_open_uri_at_dest (EvApplication *application,
639 EvWindowRunMode mode,
640 const gchar *search_string,
645 ev_window = ev_application_get_empty_window (application, screen);
647 ev_window = EV_WINDOW (ev_window_new ());
649 ev_application_open_uri_in_window (application, uri, ev_window,
656 * ev_application_open_uri_at_dest:
657 * @application: The instance of the application.
658 * @uri: The uri to be opened.
659 * @screen: Thee screen where the link will be shown.
660 * @dest: The #EvLinkDest of the document.
661 * @mode: The run mode of the window.
662 * @timestamp: Current time value.
665 ev_application_open_uri_at_dest (EvApplication *application,
669 EvWindowRunMode mode,
670 const gchar *search_string,
673 g_return_if_fail (uri != NULL);
675 if (application->uri && strcmp (application->uri, uri) != 0) {
676 /* spawn a new evince process */
677 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
679 } else if (!application->uri) {
680 application->uri = g_strdup (uri);
684 /* Register the uri or send Reload to
685 * remote instance if already registered
687 ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp);
689 _ev_application_open_uri_at_dest (application, uri, screen, dest, mode, search_string, timestamp);
690 #endif /* ENABLE_DBUS */
694 * ev_application_open_window:
695 * @application: The instance of the application.
696 * @timestamp: Current time value.
698 * Creates a new window
701 ev_application_open_window (EvApplication *application,
705 GtkWidget *new_window = ev_window_new ();
706 #ifdef GDK_WINDOWING_X11
707 GdkWindow *gdk_window;
711 ev_stock_icons_set_screen (screen);
712 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
715 if (!gtk_widget_get_realized (new_window))
716 gtk_widget_realize (new_window);
718 #ifdef GDK_WINDOWING_X11
719 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
722 timestamp = gdk_x11_get_server_time (gdk_window);
723 gdk_x11_window_set_user_time (gdk_window, timestamp);
725 gtk_window_present (GTK_WINDOW (new_window));
727 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
728 #endif /* GDK_WINDOWING_X11 */
733 method_call_cb (GDBusConnection *connection,
735 const gchar *object_path,
736 const gchar *interface_name,
737 const gchar *method_name,
738 GVariant *parameters,
739 GDBusMethodInvocation *invocation,
742 EvApplication *application = EV_APPLICATION (user_data);
748 GdkDisplay *display = NULL;
749 int screen_number = 0;
750 EvLinkDest *dest = NULL;
751 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
752 const gchar *search_string = NULL;
753 GdkScreen *screen = NULL;
755 if (g_strcmp0 (method_name, "Reload") == 0) {
756 g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp);
758 while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
759 if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
760 display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
761 } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
762 screen_number = g_variant_get_int32 (value);
763 } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
764 mode = g_variant_get_uint32 (value);
765 } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
766 dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
767 } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
768 search_string = g_variant_get_string (value, NULL);
771 g_variant_iter_free (iter);
773 if (display != NULL &&
774 screen_number >= 0 &&
775 screen_number < gdk_display_get_n_screens (display))
776 screen = gdk_display_get_screen (display, screen_number);
778 screen = gdk_screen_get_default ();
780 windows = ev_application_get_windows (application);
781 for (l = windows; l != NULL; l = g_list_next (l)) {
782 EvWindow *ev_window = EV_WINDOW (l->data);
784 ev_application_open_uri_in_window (application, application->uri,
790 g_list_free (windows);
793 g_object_unref (dest);
795 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
796 } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
797 GList *windows = ev_application_get_windows (application);
798 GVariantBuilder builder;
801 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
802 g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
804 for (l = windows; l; l = g_list_next (l)) {
805 EvWindow *window = (EvWindow *)l->data;
807 g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
810 g_variant_builder_close (&builder);
811 g_list_free (windows);
813 g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
817 static const char introspection_xml[] =
819 "<interface name='org.gnome.evince.Application'>"
820 "<method name='Reload'>"
821 "<arg type='a{sv}' name='args' direction='in'/>"
822 "<arg type='u' name='timestamp' direction='in'/>"
824 "<method name='GetWindowList'>"
825 "<arg type='ao' name='window_list' direction='out'/>"
830 static const GDBusInterfaceVTable interface_vtable = {
836 static GDBusNodeInfo *introspection_data;
837 #endif /* ENABLE_DBUS */
840 ev_application_open_uri_list (EvApplication *application,
847 for (l = uri_list; l != NULL; l = l->next) {
848 ev_application_open_uri_at_dest (application, (char *)l->data,
849 screen, NULL, 0, NULL,
855 ev_application_accel_map_save (EvApplication *application)
857 gchar *accel_map_file;
861 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
862 tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
864 fd = g_mkstemp (tmp_filename);
866 g_free (accel_map_file);
867 g_free (tmp_filename);
871 gtk_accel_map_save_fd (fd);
874 g_mkdir_with_parents (application->dot_dir, 0700);
875 if (g_rename (tmp_filename, accel_map_file) == -1) {
877 g_unlink (tmp_filename);
880 g_free (accel_map_file);
881 g_free (tmp_filename);
885 ev_application_accel_map_load (EvApplication *application)
887 gchar *accel_map_file;
889 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
890 gtk_accel_map_load (accel_map_file);
891 g_free (accel_map_file);
895 ev_application_migrate_config_dir (EvApplication *application)
897 const gchar *userdir;
902 gboolean dir_created = FALSE;
903 static const gchar *config_files[] = {
904 "evince_toolbar.xml",
909 userdir = g_getenv ("GNOME22_USER_DIR");
911 old_dot_dir = g_build_filename (userdir, "evince", NULL);
912 old_accels = g_build_filename (userdir, "accels", "evince", NULL);
914 old_dot_dir = g_build_filename (g_get_home_dir (),
918 old_accels = g_build_filename (g_get_home_dir (),
923 if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
924 for (i = 0; config_files[i]; i++) {
930 old_filename = g_build_filename (old_dot_dir, config_files[i], NULL);
931 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
932 g_free (old_filename);
937 g_mkdir_with_parents (application->dot_dir, 0700);
941 new_filename = g_build_filename (application->dot_dir, config_files[i], NULL);
942 old_file = g_file_new_for_path (old_filename);
943 new_file = g_file_new_for_path (new_filename);
946 g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error);
948 g_warning ("Error migrating config file %s: %s\n",
949 old_filename, error->message);
950 g_error_free (error);
953 g_free (old_filename);
954 g_free (new_filename);
955 g_object_unref (old_file);
956 g_object_unref (new_file);
960 g_free (old_dot_dir);
962 if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) {
964 GFile *old_accels_file;
965 GFile *new_accels_file;
968 g_mkdir_with_parents (application->dot_dir, 0700);
970 new_accels = g_build_filename (application->dot_dir, "accels", NULL);
971 old_accels_file = g_file_new_for_path (old_accels);
972 new_accels_file = g_file_new_for_path (new_accels);
975 g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error);
977 g_warning ("Error migrating accelerator specifications file %s: %s\n",
978 old_accels, error->message);
979 g_error_free (error);
983 g_object_unref (old_accels_file);
984 g_object_unref (new_accels_file);
991 ev_application_shutdown (EvApplication *application)
993 if (application->uri) {
995 ev_application_unregister_uri (application,
998 g_free (application->uri);
999 application->uri = NULL;
1002 ev_application_accel_map_save (application);
1004 g_object_unref (application->scr_saver);
1005 application->scr_saver = NULL;
1008 if (application->keys) {
1009 g_object_unref (application->keys);
1010 application->keys = NULL;
1012 if (application->registration_id != 0) {
1013 g_dbus_connection_unregister_object (application->connection,
1014 application->registration_id);
1015 application->registration_id = 0;
1017 if (application->connection != NULL) {
1018 g_object_unref (application->connection);
1019 application->connection = NULL;
1021 if (introspection_data) {
1022 g_dbus_node_info_ref (introspection_data);
1023 introspection_data = NULL;
1025 #endif /* ENABLE_DBUS */
1027 g_free (application->dot_dir);
1028 application->dot_dir = NULL;
1029 g_free (application->data_dir);
1030 application->data_dir = NULL;
1031 g_free (application->filechooser_open_uri);
1032 application->filechooser_open_uri = NULL;
1033 g_free (application->filechooser_save_uri);
1034 application->filechooser_save_uri = NULL;
1036 g_object_unref (application);
1043 ev_application_class_init (EvApplicationClass *ev_application_class)
1048 ev_application_init (EvApplication *ev_application)
1050 GError *error = NULL;
1052 ev_application->dot_dir = g_build_filename (g_get_user_config_dir (),
1054 if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1055 ev_application_migrate_config_dir (ev_application);
1061 dir = g_win32_get_package_installation_directory_of_module (NULL);
1062 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
1066 ev_application->data_dir = g_strdup (EVINCEDATADIR);
1069 ev_application_init_session (ev_application);
1071 ev_application_accel_map_load (ev_application);
1074 ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1075 if (ev_application->connection != NULL) {
1076 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1077 g_assert (introspection_data != NULL);
1079 ev_application->registration_id =
1080 g_dbus_connection_register_object (ev_application->connection,
1081 APPLICATION_DBUS_OBJECT_PATH,
1082 introspection_data->interfaces[0],
1084 ev_application, NULL,
1086 if (ev_application->registration_id == 0) {
1087 g_printerr ("Failed to register bus object: %s\n", error->message);
1088 g_error_free (error);
1091 g_printerr ("Failed to get bus connection: %s\n", error->message);
1092 g_error_free (error);
1095 ev_application->keys = ev_media_player_keys_new ();
1096 #endif /* ENABLE_DBUS */
1098 ev_application->scr_saver = totem_scrsaver_new ();
1099 g_object_set (ev_application->scr_saver,
1100 "reason", _("Running in presentation mode"),
1105 ev_application_get_dbus_connection (EvApplication *application)
1108 return application->connection;
1115 ev_application_has_window (EvApplication *application)
1117 GList *l, *toplevels;
1118 gboolean retval = FALSE;
1120 toplevels = gtk_window_list_toplevels ();
1122 for (l = toplevels; l != NULL && !retval; l = l->next) {
1123 if (EV_IS_WINDOW (l->data))
1127 g_list_free (toplevels);
1133 ev_application_get_n_windows (EvApplication *application)
1135 GList *l, *toplevels;
1138 toplevels = gtk_window_list_toplevels ();
1140 for (l = toplevels; l != NULL; l = l->next) {
1141 if (EV_IS_WINDOW (l->data))
1145 g_list_free (toplevels);
1151 ev_application_get_uri (EvApplication *application)
1153 return application->uri;
1157 * ev_application_get_media_keys:
1158 * @application: The instance of the application.
1160 * It gives you access to the media player keys handler object.
1162 * Returns: A #EvMediaPlayerKeys.
1165 ev_application_get_media_keys (EvApplication *application)
1168 return G_OBJECT (application->keys);
1171 #endif /* ENABLE_DBUS */
1175 ev_application_set_filechooser_uri (EvApplication *application,
1176 GtkFileChooserAction action,
1179 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1180 g_free (application->filechooser_open_uri);
1181 application->filechooser_open_uri = g_strdup (uri);
1182 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1183 g_free (application->filechooser_save_uri);
1184 application->filechooser_save_uri = g_strdup (uri);
1189 ev_application_get_filechooser_uri (EvApplication *application,
1190 GtkFileChooserAction action)
1192 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1193 if (application->filechooser_open_uri)
1194 return application->filechooser_open_uri;
1195 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1196 if (application->filechooser_save_uri)
1197 return application->filechooser_save_uri;
1204 ev_application_screensaver_enable (EvApplication *application)
1206 totem_scrsaver_enable (application->scr_saver);
1210 ev_application_screensaver_disable (EvApplication *application)
1212 totem_scrsaver_disable (application->scr_saver);
1216 ev_application_get_dot_dir (EvApplication *application,
1220 g_mkdir_with_parents (application->dot_dir, 0700);
1222 return application->dot_dir;
1226 ev_application_get_data_dir (EvApplication *application)
1228 return application->data_dir;