X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-application.c;h=5327825d5b705860832b4476571c13ccc8de07d8;hb=8c953cdc1375d46bd4fcc9341ec263b6b2eedad8;hp=5c0bd3802ba8db0526384fb8d3ca38ea1af121ac;hpb=15ef8efc8104114dd0e3e460524ad254a3a9cc7d;p=evince.git diff --git a/shell/ev-application.c b/shell/ev-application.c index 5c0bd380..5327825d 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -49,9 +49,6 @@ #include "ev-media-player-keys.h" #endif /* ENABLE_DBUS */ -#ifdef ENABLE_DBUS -#endif - struct _EvApplication { GObject base_instance; @@ -379,9 +376,9 @@ ev_register_doc_data_free (EvRegisterDocData *data) } static void -on_open_uri_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +on_reload_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { GDBusConnection *connection = G_DBUS_CONNECTION (source_object); GVariant *value; @@ -389,7 +386,7 @@ on_open_uri_cb (GObject *source_object, value = g_dbus_connection_call_finish (connection, res, &error); if (!value) { - g_warning ("Failed to OpenURI: %s", error->message); + g_warning ("Failed to Reload: %s", error->message); g_error_free (error); } g_variant_unref (value); @@ -450,9 +447,7 @@ on_register_uri_cb (GObject *source_object, } /* Already registered */ - g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sa{sv}u)")); - g_variant_builder_add (&builder, "s", data->uri); - + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a{sv}u)")); g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&builder, "{sv}", "display", @@ -483,13 +478,13 @@ on_register_uri_cb (GObject *source_object, owner, APPLICATION_DBUS_OBJECT_PATH, APPLICATION_DBUS_INTERFACE, - "OpenURI", + "Reload", g_variant_builder_end (&builder), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - on_open_uri_cb, + on_reload_cb, NULL); g_variant_unref (value); ev_register_doc_data_free (data); @@ -685,7 +680,7 @@ ev_application_open_uri_at_dest (EvApplication *application, } #ifdef ENABLE_DBUS - /* Register the uri or send OpenURI to + /* Register the uri or send Reload to * remote instance if already registered */ ev_application_register_uri (application, uri, screen, dest, mode, search_string, timestamp); @@ -745,7 +740,6 @@ method_call_cb (GDBusConnection *connection, { EvApplication *application = EV_APPLICATION (user_data); GList *windows, *l; - const gchar *uri; guint timestamp; GVariantIter *iter; const gchar *key; @@ -757,72 +751,78 @@ method_call_cb (GDBusConnection *connection, const gchar *search_string = NULL; GdkScreen *screen = NULL; - if (g_strcmp0 (method_name, "OpenURI") != 0) - return; + if (g_strcmp0 (method_name, "Reload") == 0) { + g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp); + + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { + if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + display = ev_display_open_if_needed (g_variant_get_string (value, NULL)); + } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + screen_number = g_variant_get_int32 (value); + } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) { + mode = g_variant_get_uint32 (value); + } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL)); + } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + search_string = g_variant_get_string (value, NULL); + } + } + g_variant_iter_free (iter); - g_variant_get (parameters, "(&sa{sv}u)", &uri, &iter, ×tamp); + if (display != NULL && + screen_number >= 0 && + screen_number < gdk_display_get_n_screens (display)) + screen = gdk_display_get_screen (display, screen_number); + else + screen = gdk_screen_get_default (); - /* FIXME: we don't need uri anymore, - * maybe this method should be renamed - * as reload, refresh or something like that - */ - if (g_strcmp0 (application->uri, uri) != 0) { - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Unexpected URI \"%s\"", - uri); - g_variant_iter_free (iter); - return; - } + windows = ev_application_get_windows (application); + for (l = windows; l != NULL; l = g_list_next (l)) { + EvWindow *ev_window = EV_WINDOW (l->data); - while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { - if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - display = ev_display_open_if_needed (g_variant_get_string (value, NULL)); - } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - screen_number = g_variant_get_int32 (value); - } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) { - mode = g_variant_get_uint32 (value); - } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL)); - } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - search_string = g_variant_get_string (value, NULL); - } - } - g_variant_iter_free (iter); - - if (display != NULL && - screen_number >= 0 && - screen_number < gdk_display_get_n_screens (display)) - screen = gdk_display_get_screen (display, screen_number); - else - screen = gdk_screen_get_default (); - - windows = ev_application_get_windows (application); - for (l = windows; l != NULL; l = g_list_next (l)) { - EvWindow *ev_window = EV_WINDOW (l->data); - - ev_application_open_uri_in_window (application, uri, ev_window, - screen, dest, mode, - search_string, - timestamp); - } - g_list_free (windows); + ev_application_open_uri_in_window (application, application->uri, + ev_window, + screen, dest, mode, + search_string, + timestamp); + } + g_list_free (windows); - if (dest) - g_object_unref (dest); + if (dest) + g_object_unref (dest); + + g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); + } else if (g_strcmp0 (method_name, "GetWindowList") == 0) { + GList *windows = ev_application_get_windows (application); + GVariantBuilder builder; + GList *l; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)")); + g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao")); + + for (l = windows; l; l = g_list_next (l)) { + EvWindow *window = (EvWindow *)l->data; + + g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window)); + } + + g_variant_builder_close (&builder); + g_list_free (windows); - g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); + g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder)); + } } static const char introspection_xml[] = "" "" - "" - "" + "" "" "" "" + "" + "" + "" "" ""; @@ -936,6 +936,10 @@ ev_application_shutdown (EvApplication *application) g_object_unref (application->connection); application->connection = NULL; } + if (introspection_data) { + g_dbus_node_info_ref (introspection_data); + introspection_data = NULL; + } #endif /* ENABLE_DBUS */ g_free (application->dot_dir); @@ -981,7 +985,7 @@ ev_application_init (EvApplication *ev_application) g_free (dir); } #else - ev_application->data_dir = g_strdup (DATADIR); + ev_application->data_dir = g_strdup (EVINCEDATADIR); #endif ev_application_init_session (ev_application); @@ -1014,15 +1018,53 @@ ev_application_init (EvApplication *ev_application) #endif /* ENABLE_DBUS */ ev_application->scr_saver = totem_scrsaver_new (); + g_object_set (ev_application->scr_saver, + "reason", _("Running in presentation mode"), + NULL); +} + +GDBusConnection * +ev_application_get_dbus_connection (EvApplication *application) +{ +#ifdef ENABLE_DBUS + return application->connection; +#else + return NULL; +#endif } gboolean ev_application_has_window (EvApplication *application) { - GList *windows = ev_application_get_windows (application); - gboolean retval = windows != NULL; + GList *l, *toplevels; + gboolean retval = FALSE; - g_list_free (windows); + toplevels = gtk_window_list_toplevels (); + + for (l = toplevels; l != NULL && !retval; l = l->next) { + if (EV_IS_WINDOW (l->data)) + retval = TRUE; + } + + g_list_free (toplevels); + + return retval; +} + +guint +ev_application_get_n_windows (EvApplication *application) +{ + GList *l, *toplevels; + guint retval = 0; + + toplevels = gtk_window_list_toplevels (); + + for (l = toplevels; l != NULL; l = l->next) { + if (EV_IS_WINDOW (l->data)) + retval++; + } + + g_list_free (toplevels); return retval; }