Skip to content

Commit 3f48838

Browse files
Christian Perschraveit65
authored andcommitted
shell: Use gdbus-codegen for the org.mate.atril.Application interface
origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-6&id=c9aada8
1 parent e51014b commit 3f48838

File tree

4 files changed

+149
-119
lines changed

4 files changed

+149
-119
lines changed

configure.ac

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ AS_IF([test "x$found_zlib" = "xno"], [
144144
AC_SUBST(ZLIB_LIBS)
145145
])
146146

147-
dnl
148-
dnl SM client
149-
dnl
147+
AC_ARG_VAR([GDBUS_CODEGEN],[the gdbus-codegen programme])
148+
AC_PATH_PROG([GDBUS_CODEGEN],[gdbus-codegen],[])
149+
if test -z "$GDBUS_CODEGEN"; then
150+
AC_MSG_ERROR([gdbus-codegen not found])
151+
fi
152+
153+
# *********
154+
# SM client
155+
# *********
150156

151157
PKG_CHECK_MODULES([SMCLIENT],[gtk+-3.0 gthread-2.0 sm >= 1.0.0])
152158
AC_SUBST([SMCLIENT_CFLAGS])

shell/Makefile.am

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ atril_SOURCES= \
4444
ev-history.h \
4545
ev-keyring.h \
4646
ev-keyring.c \
47-
ev-marshal.c \
48-
ev-marshal.h \
4947
ev-message-area.c \
5048
ev-message-area.h \
5149
ev-metadata.c \
@@ -90,13 +88,22 @@ atril_SOURCES= \
9088
ev-sidebar-thumbnails.h \
9189
main.c
9290

91+
nodist_atril_SOURCES = \
92+
ev-marshal.c \
93+
ev-marshal.h \
94+
$(NULL)
95+
9396
if ENABLE_DBUS
9497
atril_SOURCES += \
9598
ev-media-player-keys.c \
96-
ev-media-player-keys.h
99+
ev-media-player-keys.h \
100+
$(NULL)
101+
nodist_atril_SOURCES += \
102+
ev-gdbus-generated.c \
103+
ev-gdbus-generated.h \
104+
$(NULL)
97105
endif
98106

99-
100107
atril_LDFLAGS = $(AM_LDFLAGS)
101108

102109
atril_LDADD= \
@@ -112,6 +119,10 @@ atril_LDADD= \
112119

113120
BUILT_SOURCES = ev-marshal.h ev-marshal.c
114121

122+
if ENABLE_DBUS
123+
BUILT_SOURCES += ev-gdbus-generated.c ev-gdbus-generated.h
124+
endif
125+
115126
if ENABLE_DBUS
116127
atrild_SOURCES= \
117128
ev-daemon.c
@@ -131,7 +142,9 @@ atrild_LDADD= \
131142
$(EV_DAEMON_LIBS)
132143
endif
133144

134-
EXTRA_DIST = ev-marshal.list
145+
EXTRA_DIST = \
146+
ev-marshal.list \
147+
ev-gdbus.xml
135148

136149
ev-marshal.h: $(srcdir)/ev-marshal.list
137150
$(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=ev_marshal $(srcdir)/ev-marshal.list --header > ev-marshal.h
@@ -140,6 +153,14 @@ ev-marshal.c: $(srcdir)/ev-marshal.list
140153
echo '#include "ev-marshal.h"' > ev-marshal.c
141154
$(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=ev_marshal $(srcdir)/ev-marshal.list --body >> ev-marshal.c
142155

156+
ev-gdbus-generated.c ev-gdbus-generated.h: ev-gdbus.xml Makefile
157+
$(AM_V_GEN) $(GDBUS_CODEGEN) \
158+
--interface-prefix=org.mate.atril \
159+
--c-namespace=Ev \
160+
--c-generate-object-manager \
161+
--generate-c-code ev-gdbus-generated \
162+
$<
163+
143164
DISTCLEANFILES =
144165

145166
-include $(top_srcdir)/git.mk

shell/ev-application.c

Lines changed: 98 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "ev-stock-icons.h"
4242

4343
#ifdef ENABLE_DBUS
44+
#include "ev-gdbus-generated.h"
4445
#include "ev-media-player-keys.h"
4546
#endif /* ENABLE_DBUS */
4647

@@ -54,7 +55,7 @@ struct _EvApplication {
5455

5556
#ifdef ENABLE_DBUS
5657
GDBusConnection *connection;
57-
guint registration_id;
58+
EvAtrilApplication *skeleton;
5859
EvMediaPlayerKeys *keys;
5960
gboolean doc_registered;
6061
#endif
@@ -604,6 +605,9 @@ ev_application_open_uri_in_window (EvApplication *application,
604605
{
605606
GdkWindow *gdk_window;
606607

608+
if (uri == NULL)
609+
uri = application->uri;
610+
607611
if (screen) {
608612
ev_stock_icons_set_screen (screen);
609613
gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
@@ -717,110 +721,92 @@ ev_application_open_window (EvApplication *application,
717721
}
718722

719723
#ifdef ENABLE_DBUS
720-
static void
721-
method_call_cb (GDBusConnection *connection,
722-
const gchar *sender,
723-
const gchar *object_path,
724-
const gchar *interface_name,
725-
const gchar *method_name,
726-
GVariant *parameters,
727-
GDBusMethodInvocation *invocation,
728-
gpointer user_data)
724+
static gboolean
725+
handle_get_window_list_cb (EvAtrilApplication *object,
726+
GDBusMethodInvocation *invocation,
727+
EvApplication *application)
729728
{
730-
EvApplication *application = EV_APPLICATION (user_data);
731-
GList *windows, *l;
732-
guint timestamp;
733-
GVariantIter *iter;
734-
const gchar *key;
735-
GVariant *value;
736-
GdkDisplay *display = NULL;
737-
EvLinkDest *dest = NULL;
738-
EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
739-
const gchar *search_string = NULL;
740-
GdkScreen *screen = NULL;
741-
742-
if (g_strcmp0 (method_name, "Reload") == 0) {
743-
g_variant_get (parameters, "(a{sv}u)", &iter, &timestamp);
744-
745-
while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
746-
if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
747-
display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
748-
} else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
749-
mode = g_variant_get_uint32 (value);
750-
} else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
751-
dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
752-
} else if (strcmp (key, "named-dest") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
753-
dest = ev_link_dest_new_named (g_variant_get_string (value, NULL));
754-
} else if (strcmp (key, "page-index") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
755-
dest = ev_link_dest_new_page (g_variant_get_uint32 (value));
756-
} else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
757-
search_string = g_variant_get_string (value, NULL);
758-
}
759-
}
760-
g_variant_iter_free (iter);
729+
GList *windows, *l;
730+
GPtrArray *paths;
761731

762-
if (display != NULL)
763-
screen = gdk_display_get_default_screen (display);
764-
else
765-
screen = gdk_screen_get_default ();
732+
paths = g_ptr_array_new ();
766733

767-
windows = ev_application_get_windows (application);
768-
for (l = windows; l != NULL; l = g_list_next (l)) {
769-
EvWindow *ev_window = EV_WINDOW (l->data);
734+
windows = ev_application_get_windows (application);
735+
for (l = windows; l; l = g_list_next (l)) {
736+
EvWindow *window = (EvWindow *)l->data;
770737

771-
ev_application_open_uri_in_window (application, application->uri,
772-
ev_window,
773-
screen, dest, mode,
774-
search_string,
775-
timestamp);
776-
}
777-
g_list_free (windows);
738+
g_ptr_array_add (paths, (gpointer) ev_window_get_dbus_object_path (window));
739+
}
740+
g_list_free (windows);
778741

779-
if (dest)
780-
g_object_unref (dest);
742+
g_ptr_array_add (paths, NULL);
743+
ev_atril_application_complete_get_window_list (object, invocation,
744+
(const char * const *) paths->pdata);
781745

782-
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
783-
} else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
784-
GList *windows = ev_application_get_windows (application);
785-
GVariantBuilder builder;
786-
GList *l;
746+
g_ptr_array_free (paths, TRUE);
787747

788-
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
789-
g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
748+
return TRUE;
749+
}
790750

791-
for (l = windows; l; l = g_list_next (l)) {
792-
EvWindow *window = (EvWindow *)l->data;
751+
static gboolean
752+
handle_reload_cb (EvAtrilApplication *object,
753+
GDBusMethodInvocation *invocation,
754+
GVariant *args,
755+
guint timestamp,
756+
EvApplication *application)
757+
{
758+
GList *windows, *l;
759+
GVariantIter iter;
760+
const gchar *key;
761+
GVariant *value;
762+
GdkDisplay *display = NULL;
763+
EvLinkDest *dest = NULL;
764+
EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
765+
const gchar *search_string = NULL;
766+
GdkScreen *screen = NULL;
767+
768+
g_variant_iter_init (&iter, args);
769+
770+
while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) {
771+
if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
772+
display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
773+
} else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
774+
mode = g_variant_get_uint32 (value);
775+
} else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
776+
dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
777+
} else if (strcmp (key, "named-dest") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
778+
dest = ev_link_dest_new_named (g_variant_get_string (value, NULL));
779+
} else if (strcmp (key, "page-index") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
780+
dest = ev_link_dest_new_page (g_variant_get_uint32 (value));
781+
} else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
782+
search_string = g_variant_get_string (value, NULL);
783+
}
784+
}
793785

794-
g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
795-
}
786+
if (display != NULL)
787+
screen = gdk_display_get_default_screen (display);
788+
else
789+
screen = gdk_screen_get_default ();
796790

797-
g_variant_builder_close (&builder);
798-
g_list_free (windows);
791+
windows = ev_application_get_windows (application);
792+
for (l = windows; l != NULL; l = g_list_next (l)) {
793+
EvWindow *ev_window = EV_WINDOW (l->data);
799794

800-
g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
801-
}
802-
}
795+
ev_application_open_uri_in_window (application, NULL,
796+
ev_window,
797+
screen, dest, mode,
798+
search_string,
799+
timestamp);
800+
}
801+
g_list_free (windows);
803802

804-
static const char introspection_xml[] =
805-
"<node>"
806-
"<interface name='org.mate.atril.Application'>"
807-
"<method name='Reload'>"
808-
"<arg type='a{sv}' name='args' direction='in'/>"
809-
"<arg type='u' name='timestamp' direction='in'/>"
810-
"</method>"
811-
"<method name='GetWindowList'>"
812-
"<arg type='ao' name='window_list' direction='out'/>"
813-
"</method>"
814-
"</interface>"
815-
"</node>";
816-
817-
static const GDBusInterfaceVTable interface_vtable = {
818-
method_call_cb,
819-
NULL,
820-
NULL
821-
};
803+
if (dest)
804+
g_object_unref (dest);
822805

823-
static GDBusNodeInfo *introspection_data;
806+
ev_atril_application_complete_reload (object, invocation);
807+
808+
return TRUE;
809+
}
824810
#endif /* ENABLE_DBUS */
825811

826812
void
@@ -916,19 +902,15 @@ ev_application_shutdown (EvApplication *application)
916902
g_object_unref (application->keys);
917903
application->keys = NULL;
918904
}
919-
if (application->registration_id != 0) {
920-
g_dbus_connection_unregister_object (application->connection,
921-
application->registration_id);
922-
application->registration_id = 0;
905+
if (application->skeleton != NULL) {
906+
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (application->skeleton));
907+
g_object_unref (application->skeleton);
908+
application->skeleton = NULL;
923909
}
924910
if (application->connection != NULL) {
925911
g_object_unref (application->connection);
926912
application->connection = NULL;
927913
}
928-
if (introspection_data) {
929-
g_dbus_node_info_ref (introspection_data);
930-
introspection_data = NULL;
931-
}
932914
#endif /* ENABLE_DBUS */
933915

934916
g_free (application->dot_dir);
@@ -971,17 +953,22 @@ static void ev_application_init(EvApplication* ev_application)
971953
#ifdef ENABLE_DBUS
972954
ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
973955
if (ev_application->connection != NULL) {
974-
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
975-
g_assert (introspection_data != NULL);
976-
977-
ev_application->registration_id =
978-
g_dbus_connection_register_object (ev_application->connection,
979-
APPLICATION_DBUS_OBJECT_PATH,
980-
introspection_data->interfaces[0],
981-
&interface_vtable,
982-
ev_application, NULL,
983-
&error);
984-
if (ev_application->registration_id == 0) {
956+
EvAtrilApplication *skeleton;
957+
958+
skeleton = ev_atril_application_skeleton_new ();
959+
if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
960+
ev_application->connection,
961+
APPLICATION_DBUS_OBJECT_PATH,
962+
&error)) {
963+
ev_application->skeleton = skeleton;
964+
g_signal_connect (skeleton, "handle-get-window-list",
965+
G_CALLBACK (handle_get_window_list_cb),
966+
ev_application);
967+
g_signal_connect (skeleton, "handle-reload",
968+
G_CALLBACK (handle_reload_cb),
969+
ev_application);
970+
} else {
971+
g_object_unref (skeleton);
985972
g_printerr ("Failed to register bus object: %s\n", error->message);
986973
g_error_free (error);
987974
}

shell/ev-gdbus.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Introspection 0.1//EN"
3+
"http://www.freedesktop.org/software/dbus/introspection.dtd">
4+
<node>
5+
<interface name='org.mate.atril.Application'>
6+
<annotation name="org.gtk.GDBus.C.Name" value="AtrilApplication" />
7+
<method name='Reload'>
8+
<arg type='a{sv}' name='args' direction='in'/>
9+
<arg type='u' name='timestamp' direction='in'/>
10+
</method>
11+
<method name='GetWindowList'>
12+
<arg type='ao' name='window_list' direction='out'/>
13+
</method>
14+
</interface>
15+
</node>
16+

0 commit comments

Comments
 (0)