Skip to content

Commit

Permalink
shell: Use gdbus-codegen for the org.mate.atril.Window interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Persch authored and raveit65 committed Mar 21, 2018
1 parent 3f48838 commit f44500b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 148 deletions.
17 changes: 17 additions & 0 deletions shell/ev-gdbus.xml
Expand Up @@ -12,5 +12,22 @@
<arg type='ao' name='window_list' direction='out'/> <arg type='ao' name='window_list' direction='out'/>
</method> </method>
</interface> </interface>
<interface name='org.mate.atril.Window'>
<annotation name="org.gtk.GDBus.C.Name" value="AtrilWindow" />
<method name='SyncView'>
<arg type='s' name='source_file' direction='in'/>
<arg type='(ii)' name='source_point' direction='in'/>
<arg type='u' name='timestamp' direction='in'/>
</method>
<signal name='SyncSource'>
<arg type='s' name='source_file' direction='out'/>
<arg type='(ii)' name='source_point' direction='out'/>
<arg type='u' name='timestamp' direction='out'/>
</signal>
<signal name='Closed'/>
<signal name='DocumentLoaded'>
<arg type='s' name='uri' direction='out'/>
</signal>
</interface>
</node> </node>


202 changes: 54 additions & 148 deletions shell/ev-window.c
Expand Up @@ -99,6 +99,7 @@
#include "ev-bookmark-action.h" #include "ev-bookmark-action.h"


#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
#include "ev-gdbus-generated.h"
#include "ev-media-player-keys.h" #include "ev-media-player-keys.h"
#endif /* ENABLE_DBUS */ #endif /* ENABLE_DBUS */


Expand Down Expand Up @@ -225,8 +226,8 @@ struct _EvWindowPrivate {
GSettings *lockdown_settings; GSettings *lockdown_settings;
#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
/* DBus */ /* DBus */
guint dbus_object_id; EvAtrilWindow *skeleton;
gchar *dbus_object_path; gchar *dbus_object_path;
#endif #endif


/* Caret navigation */ /* Caret navigation */
Expand Down Expand Up @@ -5970,16 +5971,13 @@ ev_window_dispose (GObject *object)
} }


#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
if (priv->dbus_object_id > 0) { if (priv->skeleton != NULL) {
ev_window_emit_closed (window); ev_window_emit_closed (window);
g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP), g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (priv->skeleton));
priv->dbus_object_id); g_object_unref (priv->skeleton);
priv->dbus_object_id = 0; priv->skeleton = NULL;
} g_free (priv->dbus_object_path);

priv->dbus_object_path = NULL;
if (priv->dbus_object_path) {
g_free (priv->dbus_object_path);
priv->dbus_object_path = NULL;
} }
#endif /* ENABLE_DBUS */ #endif /* ENABLE_DBUS */


Expand Down Expand Up @@ -7504,17 +7502,11 @@ static void
ev_window_sync_source (EvWindow *window, ev_window_sync_source (EvWindow *window,
EvSourceLink *link) EvSourceLink *link)
{ {
GDBusConnection *connection;
GError *error = NULL;
guint32 timestamp; guint32 timestamp;
gchar *uri_input; gchar *uri_input;
GFile *input_gfile; GFile *input_gfile;


if (window->priv->dbus_object_id <= 0) if (window->priv->skeleton == NULL)
return;

connection = ev_application_get_dbus_connection (EV_APP);
if (!connection)
return; return;


timestamp = gtk_get_current_event_time (); timestamp = gtk_get_current_event_time ();
Expand All @@ -7540,144 +7532,57 @@ ev_window_sync_source (EvWindow *window,
uri_input = g_file_get_uri (input_gfile); uri_input = g_file_get_uri (input_gfile);
g_object_unref (input_gfile); g_object_unref (input_gfile);


g_dbus_connection_emit_signal (connection, ev_atril_window_emit_sync_source (window->priv->skeleton,
NULL, uri_input,
window->priv->dbus_object_path, g_variant_new ("(ii)", link->line, link->col),
EV_WINDOW_DBUS_INTERFACE, timestamp);
"SyncSource",
g_variant_new ("(s(ii)u)",
uri_input,
link->line,
link->col,
timestamp),
&error);
g_free (uri_input); g_free (uri_input);
if (error) {
g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
error->message);
g_error_free (error);
}
} }


static void static void
ev_window_emit_closed (EvWindow *window) ev_window_emit_closed (EvWindow *window)
{ {
GDBusConnection *connection; if (window->priv->skeleton == NULL)
GError *error = NULL;

if (window->priv->dbus_object_id <= 0)
return;

connection = ev_application_get_dbus_connection (EV_APP);
if (!connection)
return; return;


g_dbus_connection_emit_signal (connection, ev_atril_window_emit_closed (window->priv->skeleton);
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() /* If this is the last window call g_dbus_connection_flush_sync()
* to make sure the signal is emitted. * to make sure the signal is emitted.
*/ */
if (ev_application_get_n_windows (EV_APP) == 1) if (ev_application_get_n_windows (EV_APP) == 1)
g_dbus_connection_flush_sync (connection, NULL, NULL); g_dbus_connection_flush_sync (ev_application_get_dbus_connection (EV_APP), NULL, NULL);
} }


static void static void
ev_window_emit_doc_loaded (EvWindow *window) ev_window_emit_doc_loaded (EvWindow *window)
{ {
GDBusConnection *connection; if (window->priv->skeleton == NULL)
GError *error = NULL; return;

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; ev_atril_window_emit_document_loaded (window->priv->skeleton, window->priv->uri);
}
} }


static void static gboolean
method_call_cb (GDBusConnection *connection, handle_sync_view_cb (EvAtrilWindow *object,
const gchar *sender, GDBusMethodInvocation *invocation,
const gchar *object_path, const gchar *source_file,
const gchar *interface_name, GVariant *source_point,
const gchar *method_name, guint timestamp,
GVariant *parameters, EvWindow *window)
GDBusMethodInvocation *invocation,
gpointer user_data)
{ {
EvWindow *window = EV_WINDOW (user_data);
if (window->priv->document->iswebdocument == TRUE ) return;

if (g_strcmp0 (method_name, "SyncView") != 0)
return;

if (window->priv->document && ev_document_has_synctex (window->priv->document)) { if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
EvSourceLink link; EvSourceLink link;
guint32 timestamp; link.filename = (char *) source_file;

g_variant_get (source_point, "(ii)", &link.line, &link.col);
g_variant_get (parameters, "(&s(ii)u)", &link.filename, &link.line, &link.col, &timestamp);
ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link); ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
gtk_window_present_with_time (GTK_WINDOW (window), timestamp); gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
} }


g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); ev_atril_window_complete_sync_view (object, invocation);
}

static const char introspection_xml[] =
"<node>"
"<interface name='org.mate.atril.Window'>"
"<method name='SyncView'>"
"<arg type='s' name='source_file' direction='in'/>"
"<arg type='(ii)' name='source_point' direction='in'/>"
"<arg type='u' name='timestamp' direction='in'/>"
"</method>"
"<signal name='SyncSource'>"
"<arg type='s' name='source_file' direction='out'/>"
"<arg type='(ii)' name='source_point' direction='out'/>"
"<arg type='u' name='timestamp' 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; return TRUE;
}
#endif /* ENABLE_DBUS */ #endif /* ENABLE_DBUS */


static void static void
Expand Down Expand Up @@ -7706,30 +7611,31 @@ ev_window_init (EvWindow *ev_window)
#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
connection = ev_application_get_dbus_connection (EV_APP); connection = ev_application_get_dbus_connection (EV_APP);
if (connection) { if (connection) {
if (!introspection_data) { EvAtrilWindow *skeleton;
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
if (error) g_warning ("%s\n", error->message); ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
}
g_assert (introspection_data != NULL); skeleton = ev_atril_window_skeleton_new ();

if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++); connection,
ev_window->priv->dbus_object_id = ev_window->priv->dbus_object_path,
g_dbus_connection_register_object (connection, &error)) {
ev_window->priv->dbus_object_path, ev_window->priv->skeleton = skeleton;
introspection_data->interfaces[0], g_signal_connect (skeleton, "handle-sync-view",
&interface_vtable, G_CALLBACK (handle_sync_view_cb),
ev_window, NULL, ev_window);
&error); } else {
if (ev_window->priv->dbus_object_id == 0) {
g_printerr ("Failed to register bus object %s: %s\n", g_printerr ("Failed to register bus object %s: %s\n",
ev_window->priv->dbus_object_path, error->message); ev_window->priv->dbus_object_path, error->message);
g_error_free (error); g_error_free (error);
g_free (ev_window->priv->dbus_object_path); g_free (ev_window->priv->dbus_object_path);
ev_window->priv->dbus_object_path = NULL; ev_window->priv->dbus_object_path = NULL;
error = NULL; error = NULL;

g_object_unref (skeleton);
ev_window->priv->skeleton = NULL;
} }
} }

#endif /* ENABLE_DBUS */ #endif /* ENABLE_DBUS */


ev_window->priv->model = ev_document_model_new (); ev_window->priv->model = ev_document_model_new ();
Expand Down

0 comments on commit f44500b

Please sign in to comment.