+static void
+ev_application_unregister_uri (EvApplication *application,
+ const gchar *uri)
+{
+ DBusGProxy *proxy;
+ GError *error = NULL;
+
+ if (!application->connection)
+ return;
+
+ proxy = dbus_g_proxy_new_for_name (application->connection,
+ "org.gnome.evince.Daemon",
+ "/org/gnome/evince/Daemon",
+ "org.gnome.evince.Daemon");
+ if (!dbus_g_proxy_call (proxy, "UnregisterDocument", &error,
+ G_TYPE_STRING, uri,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID)) {
+ g_warning ("Error unregistering document: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (proxy);
+}
+#endif /* ENABLE_DBUS */
+
+static void
+ev_application_open_uri_in_window (EvApplication *application,
+ const char *uri,
+ EvWindow *ev_window,
+ GdkScreen *screen,
+ EvLinkDest *dest,
+ EvWindowRunMode mode,
+ const gchar *search_string,
+ guint timestamp)
+{
+ if (screen) {
+ ev_stock_icons_set_screen (screen);
+ gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
+ }
+
+ /* We need to load uri before showing the window, so
+ we can restore window size without flickering */
+ ev_window_open_uri (ev_window, uri, dest, mode, search_string);
+
+ if (!GTK_WIDGET_REALIZED (GTK_WIDGET (ev_window)))
+ gtk_widget_realize (GTK_WIDGET (ev_window));
+
+#ifdef GDK_WINDOWING_X11
+ if (timestamp <= 0)
+ timestamp = gdk_x11_get_server_time (GTK_WIDGET (ev_window)->window);
+ gdk_x11_window_set_user_time (GTK_WIDGET (ev_window)->window, timestamp);
+
+ ev_document_fc_mutex_lock ();
+ gtk_window_present (GTK_WINDOW (ev_window));
+ ev_document_fc_mutex_unlock ();
+#else
+ ev_document_fc_mutex_lock ();
+ gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
+ ev_document_fc_mutex_unlock ();
+#endif /* GDK_WINDOWING_X11 */
+}
+
+/**
+ * ev_application_open_uri_at_dest:
+ * @application: The instance of the application.
+ * @uri: The uri to be opened.
+ * @screen: Thee screen where the link will be shown.
+ * @dest: The #EvLinkDest of the document.
+ * @mode: The run mode of the window.
+ * @timestamp: Current time value.
+ */
+void
+ev_application_open_uri_at_dest (EvApplication *application,
+ const char *uri,
+ GdkScreen *screen,
+ EvLinkDest *dest,
+ EvWindowRunMode mode,
+ const gchar *search_string,
+ guint timestamp)
+{
+ EvWindow *ev_window;
+
+ g_return_if_fail (uri != NULL);
+
+ if (application->uri && strcmp (application->uri, uri) != 0) {
+ /* spawn a new evince process */
+ ev_spawn (uri, screen, dest, mode, search_string, timestamp);
+ return;
+ } else {
+#ifdef ENABLE_DBUS
+ GHashTable *args = build_args (screen, dest, mode, search_string);
+ gboolean ret;
+
+ /* Register the uri or send OpenURI to
+ * remote instance if already registered
+ */
+ ret = ev_application_register_uri (application, uri, args, timestamp);
+ g_hash_table_destroy (args);
+ if (!ret)
+ return;
+#endif /* ENABLE_DBUS */
+
+ ev_window = ev_application_get_empty_window (application, screen);
+ if (!ev_window)
+ ev_window = EV_WINDOW (ev_window_new ());
+ }
+
+ application->uri = g_strdup (uri);
+
+ ev_application_open_uri_in_window (application, uri, ev_window,
+ screen, dest, mode,
+ search_string,
+ timestamp);
+}
+
+/**
+ * ev_application_open_window:
+ * @application: The instance of the application.
+ * @timestamp: Current time value.
+ *
+ * Creates a new window
+ */
+void
+ev_application_open_window (EvApplication *application,
+ GdkScreen *screen,
+ guint32 timestamp)
+{
+ GtkWidget *new_window = ev_window_new ();
+
+ if (screen) {
+ ev_stock_icons_set_screen (screen);
+ gtk_window_set_screen (GTK_WINDOW (new_window), screen);
+ }
+
+ if (!GTK_WIDGET_REALIZED (new_window))
+ gtk_widget_realize (new_window);
+
+#ifdef GDK_WINDOWING_X11
+ if (timestamp <= 0)
+ timestamp = gdk_x11_get_server_time (new_window->window);
+ gdk_x11_window_set_user_time (new_window->window, timestamp);
+
+ gtk_window_present (GTK_WINDOW (new_window));
+#else
+ gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
+#endif /* GDK_WINDOWING_X11 */
+}
+
+/**
+ * ev_application_open_uri:
+ * @application: The instance of the application.
+ * @uri: The uri to be opened
+ * @args: A #GHashTable with the arguments data.
+ * @timestamp: Current time value.
+ * @error: The #GError facility.
+ */
+static gboolean