+ } else if (g_strcmp0 (method_name, "FindDocument") == 0) {
+ EvDoc *doc;
+ const gchar *uri;
+ gboolean spawn;
+
+ g_variant_get (parameters, "(&sb)", &uri, &spawn);
+
+ LOG ("FindDocument URI '%s' \n", uri);
+
+ doc = ev_daemon_find_doc (uri);
+ if (doc != NULL) {
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", doc->dbus_name));
+ return;
+ }
+
+ if (spawn) {
+ GList *uri_invocations;
+ gboolean ret_val = TRUE;
+
+ uri_invocations = g_hash_table_lookup (pending_invocations, uri);
+
+ if (uri_invocations == NULL) {
+ /* Only spawn once. */
+ ret_val = spawn_evince (uri);
+ }
+
+ if (ret_val) {
+ /* Only defer DBUS answer if evince was succesfully spawned */
+ uri_invocations = g_list_prepend (uri_invocations, invocation);
+ g_hash_table_insert (pending_invocations,
+ g_strdup (uri),
+ uri_invocations);
+ return;
+ }
+ }
+
+ LOG ("FindDocument URI '%s' was not registered!\n", uri);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)",""));
+ }