+#ifdef ENABLE_DBUS
+static void
+ev_window_sync_source (EvWindow *window,
+ EvSourceLink *link)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "SyncSource",
+ g_variant_new ("(s(ii))",
+ link->filename,
+ link->line,
+ link->col),
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+ev_window_emit_closed (EvWindow *window)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "Closed",
+ NULL,
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal Closed: %s\n",
+ error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ /* If this is the last window call g_dbus_connection_flush_sync()
+ * to make sure the signal is emitted.
+ */
+ if (ev_application_get_n_windows (EV_APP) == 1)
+ g_dbus_connection_flush_sync (connection, NULL, NULL);
+}
+
+static void
+ev_window_emit_doc_loaded (EvWindow *window)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "DocumentLoaded",
+ g_variant_new("(s)", window->priv->uri),
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal DocumentLoaded: %s\n",
+ error->message);
+ g_error_free (error);
+
+ return;
+ }
+}
+
+static void
+method_call_cb (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ EvWindow *window = EV_WINDOW (user_data);
+
+ if (g_strcmp0 (method_name, "SyncView") != 0)
+ return;
+
+ if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
+ EvSourceLink link;
+
+ g_variant_get (parameters, "(&s(ii))", &link.filename, &link.line, &link.col);
+ ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
+ gtk_window_present (GTK_WINDOW (window));
+ }
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+}
+
+static const char introspection_xml[] =
+ "<node>"
+ "<interface name='org.gnome.evince.Window'>"
+ "<method name='SyncView'>"
+ "<arg type='s' name='source_file' direction='in'/>"
+ "<arg type='(ii)' name='source_point' direction='in'/>"
+ "</method>"
+ "<signal name='SyncSource'>"
+ "<arg type='s' name='source_file' direction='out'/>"
+ "<arg type='(ii)' name='source_point' direction='out'/>"
+ "</signal>"
+ "<signal name='Closed'/>"
+ "<signal name='DocumentLoaded'>"
+ "<arg type='s' name='uri' direction='out'/>"
+ "</signal>"
+ "</interface>"
+ "</node>";
+
+static const GDBusInterfaceVTable interface_vtable = {
+ method_call_cb,
+ NULL,
+ NULL
+};
+
+static GDBusNodeInfo *introspection_data;
+#endif /* ENABLE_DBUS */
+