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 child_setup (gpointer user_data)
229 startup_id = g_strdup_printf ("_TIME%lu",
230 (unsigned long)GPOINTER_TO_INT (user_data));
231 g_setenv ("DESKTOP_STARTUP_ID", startup_id, TRUE);
236 ev_spawn (const char *uri,
239 EvWindowRunMode mode,
240 const gchar *search_string,
247 GError *error = NULL;
253 dir = g_win32_get_package_installation_directory_of_module (NULL);
254 argv[arg++] = g_build_filename (dir, "bin", "evince", NULL);
258 argv[arg++] = g_build_filename (BINDIR, "evince", NULL);
263 const gchar *page_label;
265 page_label = ev_link_dest_get_page_label (dest);
267 argv[arg++] = g_strdup_printf ("--page-label=%s", page_label);
269 argv[arg++] = g_strdup_printf ("--page-label=%d",
270 ev_link_dest_get_page (dest));
275 argv[arg++] = g_strdup_printf ("--find=%s", search_string);
280 case EV_WINDOW_MODE_FULLSCREEN:
281 argv[arg++] = g_strdup ("-f");
283 case EV_WINDOW_MODE_PRESENTATION:
284 argv[arg++] = g_strdup ("-s");
290 argv[arg++] = (gchar *)uri;
293 res = gdk_spawn_on_screen (screen, NULL /* wd */, argv, NULL /* env */,
296 GINT_TO_POINTER(timestamp),
299 g_warning ("Error launching evince %s: %s\n", uri, error->message);
300 g_error_free (error);
303 for (i = 0; i < arg - 1; i++) {
309 ev_application_get_windows (EvApplication *application)
311 GList *l, *toplevels;
312 GList *windows = NULL;
314 toplevels = gtk_window_list_toplevels ();
316 for (l = toplevels; l != NULL; l = l->next) {
317 if (EV_IS_WINDOW (l->data)) {
318 windows = g_list_append (windows, l->data);
322 g_list_free (toplevels);
328 ev_application_get_empty_window (EvApplication *application,
331 EvWindow *empty_window = NULL;
332 GList *windows = ev_application_get_windows (application);
335 for (l = windows; l != NULL; l = l->next) {
336 EvWindow *window = EV_WINDOW (l->data);
338 if (ev_window_is_empty (window) &&
339 gtk_window_get_screen (GTK_WINDOW (window)) == screen) {
340 empty_window = window;
345 g_list_free (windows);
356 EvWindowRunMode mode;
357 gchar *search_string;
362 ev_register_doc_data_free (EvRegisterDocData *data)
368 if (data->search_string)
369 g_free (data->search_string);
371 g_object_unref (data->dest);
377 on_reload_cb (GObject *source_object,
381 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
383 GError *error = NULL;
385 value = g_dbus_connection_call_finish (connection, res, &error);
387 g_warning ("Failed to Reload: %s", error->message);
388 g_error_free (error);
390 g_variant_unref (value);
392 ev_application_shutdown (EV_APP);
396 on_register_uri_cb (GObject *source_object,
400 GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
401 EvRegisterDocData *data = (EvRegisterDocData *)user_data;
402 EvApplication *application = EV_APP;
405 GVariantBuilder builder;
406 GError *error = NULL;
408 value = g_dbus_connection_call_finish (connection, res, &error);
410 g_warning ("Error registering document: %s\n", error->message);
411 g_error_free (error);
413 _ev_application_open_uri_at_dest (application,
420 ev_register_doc_data_free (data);
425 g_variant_get (value, "(&s)", &owner);
427 /* This means that the document wasn't already registered; go
428 * ahead with opening it.
430 if (owner[0] == '\0') {
431 g_variant_unref (value);
433 application->doc_registered = TRUE;
435 _ev_application_open_uri_at_dest (application,
442 ev_register_doc_data_free (data);
447 /* Already registered */
448 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)"));
449 g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
450 g_variant_builder_add (&builder, "{sv}",
452 g_variant_new_string (gdk_display_get_name (gdk_screen_get_display (data->screen))));
453 g_variant_builder_add (&builder, "{sv}",
455 g_variant_new_int32 (gdk_screen_get_number (data->screen)));
457 g_variant_builder_add (&builder, "{sv}",
459 g_variant_new_string (ev_link_dest_get_page_label (data->dest)));
461 if (data->search_string) {
462 g_variant_builder_add (&builder, "{sv}",
464 g_variant_new_string (data->search_string));
466 if (data->mode != EV_WINDOW_MODE_NORMAL) {
467 g_variant_builder_add (&builder, "{sv}",
469 g_variant_new_uint32 (data->mode));
471 g_variant_builder_close (&builder);
473 g_variant_builder_add (&builder, "u", data->timestamp);
475 g_dbus_connection_call (connection,
477 APPLICATION_DBUS_OBJECT_PATH,
478 APPLICATION_DBUS_INTERFACE,
480 g_variant_builder_end (&builder),
482 G_DBUS_CALL_FLAGS_NONE,
487 g_variant_unref (value);
488 ev_register_doc_data_free (data);
492 * ev_application_register_uri:
501 * Registers @uri with evince-daemon.
505 ev_application_register_uri (EvApplication *application,
509 EvWindowRunMode mode,
510 const gchar *search_string,
513 EvRegisterDocData *data;
515 if (!application->connection)
518 if (application->doc_registered) {
519 /* Already registered, reload */
522 windows = ev_application_get_windows (application);
523 for (l = windows; l != NULL; l = g_list_next (l)) {
524 EvWindow *ev_window = EV_WINDOW (l->data);
526 ev_application_open_uri_in_window (application, uri, ev_window,
531 g_list_free (windows);
536 data = g_new (EvRegisterDocData, 1);
537 data->uri = g_strdup (uri);
538 data->screen = screen;
539 data->dest = dest ? g_object_ref (dest) : NULL;
541 data->search_string = search_string ? g_strdup (search_string) : NULL;
542 data->timestamp = timestamp;
544 g_dbus_connection_call (application->connection,
545 EVINCE_DAEMON_SERVICE,
546 EVINCE_DAEMON_OBJECT_PATH,
547 EVINCE_DAEMON_INTERFACE,
549 g_variant_new ("(s)", uri),
550 G_VARIANT_TYPE ("(s)"),
551 G_DBUS_CALL_FLAGS_NONE,
559 ev_application_unregister_uri (EvApplication *application,
563 GError *error = NULL;
565 if (!application->doc_registered)
568 /* This is called from ev_application_shutdown(),
569 * so it's safe to use the sync api
571 value = g_dbus_connection_call_sync (
572 application->connection,
573 EVINCE_DAEMON_SERVICE,
574 EVINCE_DAEMON_OBJECT_PATH,
575 EVINCE_DAEMON_INTERFACE,
576 "UnregisterDocument",
577 g_variant_new ("(s)", uri),
579 G_DBUS_CALL_FLAGS_NO_AUTO_START,
584 g_warning ("Error unregistering document: %s\n", error->message);
585 g_error_free (error);
587 g_variant_unref (value);
590 #endif /* ENABLE_DBUS */
593 ev_application_open_uri_in_window (EvApplication *application,
598 EvWindowRunMode mode,
599 const gchar *search_string,
602 #ifdef GDK_WINDOWING_X11
603 GdkWindow *gdk_window;
607 ev_stock_icons_set_screen (screen);
608 gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
611 /* We need to load uri before showing the window, so
612 we can restore window size without flickering */
613 ev_window_open_uri (ev_window, uri, dest, mode, search_string);
615 if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
616 gtk_widget_realize (GTK_WIDGET (ev_window));
618 #ifdef GDK_WINDOWING_X11
619 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
622 timestamp = gdk_x11_get_server_time (gdk_window);
623 gdk_x11_window_set_user_time (gdk_window, timestamp);
625 gtk_window_present (GTK_WINDOW (ev_window));
627 gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
628 #endif /* GDK_WINDOWING_X11 */
632 _ev_application_open_uri_at_dest (EvApplication *application,
636 EvWindowRunMode mode,
637 const gchar *search_string,
642 ev_window = ev_application_get_empty_window (application, screen);
644 ev_window = EV_WINDOW (ev_window_new ());
646 ev_application_open_uri_in_window (application, uri, ev_window,
653 * ev_application_open_uri_at_dest:
654 * @application: The instance of the application.
655 * @uri: The uri to be opened.
656 * @screen: Thee screen where the link will be shown.
657 * @dest: The #EvLinkDest of the document.
658 * @mode: The run mode of the window.
659 * @timestamp: Current time value.
662 ev_application_open_uri_at_dest (EvApplication *application,
666 EvWindowRunMode mode,
667 const gchar *search_string,
670 g_return_if_fail (uri != NULL);
672 if (application->uri && strcmp (application->uri, uri) != 0) {
673 /* spawn a new evince process */
674 ev_spawn (uri, screen, dest, mode, search_string, timestamp);
676 } else if (!application->uri) {
677 application->uri = g_strdup (uri);
681 /* Register the uri or send Reload to
682 * remote instance if already registered
684 ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp);
686 _ev_application_open_uri_at_dest (application, uri, screen, dest, mode, search_string, timestamp);
687 #endif /* ENABLE_DBUS */
691 * ev_application_open_window:
692 * @application: The instance of the application.
693 * @timestamp: Current time value.
695 * Creates a new window
698 ev_application_open_window (EvApplication *application,
702 GtkWidget *new_window = ev_window_new ();
703 #ifdef GDK_WINDOWING_X11
704 GdkWindow *gdk_window;
708 ev_stock_icons_set_screen (screen);
709 gtk_window_set_screen (GTK_WINDOW (new_window), screen);
712 if (!gtk_widget_get_realized (new_window))
713 gtk_widget_realize (new_window);
715 #ifdef GDK_WINDOWING_X11
716 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
719 timestamp = gdk_x11_get_server_time (gdk_window);
720 gdk_x11_window_set_user_time (gdk_window, timestamp);
722 gtk_window_present (GTK_WINDOW (new_window));
724 gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
725 #endif /* GDK_WINDOWING_X11 */
730 method_call_cb (GDBusConnection *connection,
732 const gchar *object_path,
733 const gchar *interface_name,
734 const gchar *method_name,
735 GVariant *parameters,
736 GDBusMethodInvocation *invocation,
739 EvApplication *application = EV_APPLICATION (user_data);
745 GdkDisplay *display = NULL;
746 int screen_number = 0;
747 EvLinkDest *dest = NULL;
748 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
749 const gchar *search_string = NULL;
750 GdkScreen *screen = NULL;
752 if (g_strcmp0 (method_name, "Reload") == 0) {
753 g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp);
755 while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
756 if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
757 display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
758 } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
759 screen_number = g_variant_get_int32 (value);
760 } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
761 mode = g_variant_get_uint32 (value);
762 } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
763 dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
764 } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
765 search_string = g_variant_get_string (value, NULL);
768 g_variant_iter_free (iter);
770 if (display != NULL &&
771 screen_number >= 0 &&
772 screen_number < gdk_display_get_n_screens (display))
773 screen = gdk_display_get_screen (display, screen_number);
775 screen = gdk_screen_get_default ();
777 windows = ev_application_get_windows (application);
778 for (l = windows; l != NULL; l = g_list_next (l)) {
779 EvWindow *ev_window = EV_WINDOW (l->data);
781 ev_application_open_uri_in_window (application, application->uri,
787 g_list_free (windows);
790 g_object_unref (dest);
792 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
793 } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
794 GList *windows = ev_application_get_windows (application);
795 GVariantBuilder builder;
798 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
799 g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
801 for (l = windows; l; l = g_list_next (l)) {
802 EvWindow *window = (EvWindow *)l->data;
804 g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
807 g_variant_builder_close (&builder);
808 g_list_free (windows);
810 g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
814 static const char introspection_xml[] =
816 "<interface name='org.gnome.evince.Application'>"
817 "<method name='Reload'>"
818 "<arg type='a{sv}' name='args' direction='in'/>"
819 "<arg type='u' name='timestamp' direction='in'/>"
821 "<method name='GetWindowList'>"
822 "<arg type='ao' name='window_list' direction='out'/>"
827 static const GDBusInterfaceVTable interface_vtable = {
833 static GDBusNodeInfo *introspection_data;
834 #endif /* ENABLE_DBUS */
837 ev_application_open_uri_list (EvApplication *application,
844 for (l = uri_list; l != NULL; l = l->next) {
845 ev_application_open_uri_at_dest (application, (char *)l->data,
846 screen, NULL, 0, NULL,
852 ev_application_accel_map_save (EvApplication *application)
854 gchar *accel_map_file;
858 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
859 tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
861 fd = g_mkstemp (tmp_filename);
863 g_free (accel_map_file);
864 g_free (tmp_filename);
868 gtk_accel_map_save_fd (fd);
871 g_mkdir_with_parents (application->dot_dir, 0700);
872 if (g_rename (tmp_filename, accel_map_file) == -1) {
874 g_unlink (tmp_filename);
877 g_free (accel_map_file);
878 g_free (tmp_filename);
882 ev_application_accel_map_load (EvApplication *application)
884 gchar *accel_map_file;
886 accel_map_file = g_build_filename (application->dot_dir, "accels", NULL);
887 gtk_accel_map_load (accel_map_file);
888 g_free (accel_map_file);
892 ev_application_migrate_config_dir (EvApplication *application)
894 const gchar *userdir;
899 gboolean dir_created = FALSE;
900 static const gchar *config_files[] = {
901 "evince_toolbar.xml",
906 userdir = g_getenv ("GNOME22_USER_DIR");
908 old_dot_dir = g_build_filename (userdir, "evince", NULL);
909 old_accels = g_build_filename (userdir, "accels", "evince", NULL);
911 old_dot_dir = g_build_filename (g_get_home_dir (),
915 old_accels = g_build_filename (g_get_home_dir (),
920 if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
921 for (i = 0; config_files[i]; i++) {
927 old_filename = g_build_filename (old_dot_dir, config_files[i], NULL);
928 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
929 g_free (old_filename);
934 g_mkdir_with_parents (application->dot_dir, 0700);
938 new_filename = g_build_filename (application->dot_dir, config_files[i], NULL);
939 old_file = g_file_new_for_path (old_filename);
940 new_file = g_file_new_for_path (new_filename);
943 g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error);
945 g_warning ("Error migrating config file %s: %s\n",
946 old_filename, error->message);
947 g_error_free (error);
950 g_free (old_filename);
951 g_free (new_filename);
952 g_object_unref (old_file);
953 g_object_unref (new_file);
957 g_free (old_dot_dir);
959 if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) {
961 GFile *old_accels_file;
962 GFile *new_accels_file;
965 g_mkdir_with_parents (application->dot_dir, 0700);
967 new_accels = g_build_filename (application->dot_dir, "accels", NULL);
968 old_accels_file = g_file_new_for_path (old_accels);
969 new_accels_file = g_file_new_for_path (new_accels);
972 g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error);
974 g_warning ("Error migrating accelerator specifications file %s: %s\n",
975 old_accels, error->message);
976 g_error_free (error);
980 g_object_unref (old_accels_file);
981 g_object_unref (new_accels_file);
988 ev_application_shutdown (EvApplication *application)
990 if (application->uri) {
992 ev_application_unregister_uri (application,
995 g_free (application->uri);
996 application->uri = NULL;
999 ev_application_accel_map_save (application);
1001 g_object_unref (application->scr_saver);
1002 application->scr_saver = NULL;
1005 if (application->keys) {
1006 g_object_unref (application->keys);
1007 application->keys = NULL;
1009 if (application->registration_id != 0) {
1010 g_dbus_connection_unregister_object (application->connection,
1011 application->registration_id);
1012 application->registration_id = 0;
1014 if (application->connection != NULL) {
1015 g_object_unref (application->connection);
1016 application->connection = NULL;
1018 if (introspection_data) {
1019 g_dbus_node_info_ref (introspection_data);
1020 introspection_data = NULL;
1022 #endif /* ENABLE_DBUS */
1024 g_free (application->dot_dir);
1025 application->dot_dir = NULL;
1026 g_free (application->data_dir);
1027 application->data_dir = NULL;
1028 g_free (application->filechooser_open_uri);
1029 application->filechooser_open_uri = NULL;
1030 g_free (application->filechooser_save_uri);
1031 application->filechooser_save_uri = NULL;
1033 g_object_unref (application);
1040 ev_application_class_init (EvApplicationClass *ev_application_class)
1045 ev_application_init (EvApplication *ev_application)
1047 GError *error = NULL;
1049 ev_application->dot_dir = g_build_filename (g_get_user_config_dir (),
1051 if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1052 ev_application_migrate_config_dir (ev_application);
1058 dir = g_win32_get_package_installation_directory_of_module (NULL);
1059 ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
1063 ev_application->data_dir = g_strdup (EVINCEDATADIR);
1066 ev_application_init_session (ev_application);
1068 ev_application_accel_map_load (ev_application);
1071 ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
1072 if (ev_application->connection != NULL) {
1073 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
1074 g_assert (introspection_data != NULL);
1076 ev_application->registration_id =
1077 g_dbus_connection_register_object (ev_application->connection,
1078 APPLICATION_DBUS_OBJECT_PATH,
1079 introspection_data->interfaces[0],
1081 ev_application, NULL,
1083 if (ev_application->registration_id == 0) {
1084 g_printerr ("Failed to register bus object: %s\n", error->message);
1085 g_error_free (error);
1088 g_printerr ("Failed to get bus connection: %s\n", error->message);
1089 g_error_free (error);
1092 ev_application->keys = ev_media_player_keys_new ();
1093 #endif /* ENABLE_DBUS */
1095 ev_application->scr_saver = totem_scrsaver_new ();
1096 g_object_set (ev_application->scr_saver,
1097 "reason", _("Running in presentation mode"),
1102 ev_application_get_dbus_connection (EvApplication *application)
1105 return application->connection;
1112 ev_application_has_window (EvApplication *application)
1114 GList *l, *toplevels;
1115 gboolean retval = FALSE;
1117 toplevels = gtk_window_list_toplevels ();
1119 for (l = toplevels; l != NULL && !retval; l = l->next) {
1120 if (EV_IS_WINDOW (l->data))
1124 g_list_free (toplevels);
1130 ev_application_get_n_windows (EvApplication *application)
1132 GList *l, *toplevels;
1135 toplevels = gtk_window_list_toplevels ();
1137 for (l = toplevels; l != NULL; l = l->next) {
1138 if (EV_IS_WINDOW (l->data))
1142 g_list_free (toplevels);
1148 ev_application_get_uri (EvApplication *application)
1150 return application->uri;
1154 * ev_application_get_media_keys:
1155 * @application: The instance of the application.
1157 * It gives you access to the media player keys handler object.
1159 * Returns: A #EvMediaPlayerKeys.
1162 ev_application_get_media_keys (EvApplication *application)
1165 return G_OBJECT (application->keys);
1168 #endif /* ENABLE_DBUS */
1172 ev_application_set_filechooser_uri (EvApplication *application,
1173 GtkFileChooserAction action,
1176 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1177 g_free (application->filechooser_open_uri);
1178 application->filechooser_open_uri = g_strdup (uri);
1179 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1180 g_free (application->filechooser_save_uri);
1181 application->filechooser_save_uri = g_strdup (uri);
1186 ev_application_get_filechooser_uri (EvApplication *application,
1187 GtkFileChooserAction action)
1189 if (action == GTK_FILE_CHOOSER_ACTION_OPEN) {
1190 if (application->filechooser_open_uri)
1191 return application->filechooser_open_uri;
1192 } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
1193 if (application->filechooser_save_uri)
1194 return application->filechooser_save_uri;
1201 ev_application_screensaver_enable (EvApplication *application)
1203 totem_scrsaver_enable (application->scr_saver);
1207 ev_application_screensaver_disable (EvApplication *application)
1209 totem_scrsaver_disable (application->scr_saver);
1213 ev_application_get_dot_dir (EvApplication *application,
1217 g_mkdir_with_parents (application->dot_dir, 0700);
1219 return application->dot_dir;
1223 ev_application_get_data_dir (EvApplication *application)
1225 return application->data_dir;