summaryrefslogtreecommitdiff
path: root/shell/ev-application.c
diff options
context:
space:
mode:
authorChristian Persch <[email protected]>2012-06-10 16:05:59 +0200
committerraveit65 <[email protected]>2018-03-21 06:56:34 +0100
commit3f48838e6f469e5090a0b95864c298736b3b4e4f (patch)
treeb0dfdab3459ef977de03923c3e6a4c58929bb231 /shell/ev-application.c
parente51014b5a0b2750df5ccfe98696227c949c93c28 (diff)
downloadatril-3f48838e6f469e5090a0b95864c298736b3b4e4f.tar.bz2
atril-3f48838e6f469e5090a0b95864c298736b3b4e4f.tar.xz
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
Diffstat (limited to 'shell/ev-application.c')
-rw-r--r--shell/ev-application.c209
1 files changed, 98 insertions, 111 deletions
diff --git a/shell/ev-application.c b/shell/ev-application.c
index 96be3bc7..0a98bc8d 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -41,6 +41,7 @@
#include "ev-stock-icons.h"
#ifdef ENABLE_DBUS
+#include "ev-gdbus-generated.h"
#include "ev-media-player-keys.h"
#endif /* ENABLE_DBUS */
@@ -54,7 +55,7 @@ struct _EvApplication {
#ifdef ENABLE_DBUS
GDBusConnection *connection;
- guint registration_id;
+ EvAtrilApplication *skeleton;
EvMediaPlayerKeys *keys;
gboolean doc_registered;
#endif
@@ -604,6 +605,9 @@ ev_application_open_uri_in_window (EvApplication *application,
{
GdkWindow *gdk_window;
+ if (uri == NULL)
+ uri = application->uri;
+
if (screen) {
ev_stock_icons_set_screen (screen);
gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
@@ -717,110 +721,92 @@ ev_application_open_window (EvApplication *application,
}
#ifdef ENABLE_DBUS
-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)
+static gboolean
+handle_get_window_list_cb (EvAtrilApplication *object,
+ GDBusMethodInvocation *invocation,
+ EvApplication *application)
{
- EvApplication *application = EV_APPLICATION (user_data);
- GList *windows, *l;
- guint timestamp;
- GVariantIter *iter;
- const gchar *key;
- GVariant *value;
- GdkDisplay *display = NULL;
- EvLinkDest *dest = NULL;
- EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
- const gchar *search_string = NULL;
- GdkScreen *screen = NULL;
-
- if (g_strcmp0 (method_name, "Reload") == 0) {
- g_variant_get (parameters, "(a{sv}u)", &iter, &timestamp);
-
- while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
- if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
- display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
- } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
- mode = g_variant_get_uint32 (value);
- } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
- dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
- } else if (strcmp (key, "named-dest") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
- dest = ev_link_dest_new_named (g_variant_get_string (value, NULL));
- } else if (strcmp (key, "page-index") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
- dest = ev_link_dest_new_page (g_variant_get_uint32 (value));
- } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
- search_string = g_variant_get_string (value, NULL);
- }
- }
- g_variant_iter_free (iter);
+ GList *windows, *l;
+ GPtrArray *paths;
- if (display != NULL)
- screen = gdk_display_get_default_screen (display);
- else
- screen = gdk_screen_get_default ();
+ paths = g_ptr_array_new ();
- windows = ev_application_get_windows (application);
- for (l = windows; l != NULL; l = g_list_next (l)) {
- EvWindow *ev_window = EV_WINDOW (l->data);
+ windows = ev_application_get_windows (application);
+ for (l = windows; l; l = g_list_next (l)) {
+ EvWindow *window = (EvWindow *)l->data;
- ev_application_open_uri_in_window (application, application->uri,
- ev_window,
- screen, dest, mode,
- search_string,
- timestamp);
- }
- g_list_free (windows);
+ g_ptr_array_add (paths, (gpointer) ev_window_get_dbus_object_path (window));
+ }
+ g_list_free (windows);
- if (dest)
- g_object_unref (dest);
+ g_ptr_array_add (paths, NULL);
+ ev_atril_application_complete_get_window_list (object, invocation,
+ (const char * const *) paths->pdata);
- g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
- } else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
- GList *windows = ev_application_get_windows (application);
- GVariantBuilder builder;
- GList *l;
+ g_ptr_array_free (paths, TRUE);
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));
+ return TRUE;
+}
- for (l = windows; l; l = g_list_next (l)) {
- EvWindow *window = (EvWindow *)l->data;
+static gboolean
+handle_reload_cb (EvAtrilApplication *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *args,
+ guint timestamp,
+ EvApplication *application)
+{
+ GList *windows, *l;
+ GVariantIter iter;
+ const gchar *key;
+ GVariant *value;
+ GdkDisplay *display = NULL;
+ EvLinkDest *dest = NULL;
+ EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
+ const gchar *search_string = NULL;
+ GdkScreen *screen = NULL;
+
+ g_variant_iter_init (&iter, args);
+
+ while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) {
+ if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
+ display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
+ } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
+ mode = g_variant_get_uint32 (value);
+ } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
+ dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
+ } else if (strcmp (key, "named-dest") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
+ dest = ev_link_dest_new_named (g_variant_get_string (value, NULL));
+ } else if (strcmp (key, "page-index") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
+ dest = ev_link_dest_new_page (g_variant_get_uint32 (value));
+ } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
+ search_string = g_variant_get_string (value, NULL);
+ }
+ }
- g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
- }
+ if (display != NULL)
+ screen = gdk_display_get_default_screen (display);
+ else
+ screen = gdk_screen_get_default ();
- g_variant_builder_close (&builder);
- g_list_free (windows);
+ windows = ev_application_get_windows (application);
+ for (l = windows; l != NULL; l = g_list_next (l)) {
+ EvWindow *ev_window = EV_WINDOW (l->data);
- g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
- }
-}
+ ev_application_open_uri_in_window (application, NULL,
+ ev_window,
+ screen, dest, mode,
+ search_string,
+ timestamp);
+ }
+ g_list_free (windows);
-static const char introspection_xml[] =
- "<node>"
- "<interface name='org.mate.atril.Application'>"
- "<method name='Reload'>"
- "<arg type='a{sv}' name='args' direction='in'/>"
- "<arg type='u' name='timestamp' direction='in'/>"
- "</method>"
- "<method name='GetWindowList'>"
- "<arg type='ao' name='window_list' direction='out'/>"
- "</method>"
- "</interface>"
- "</node>";
-
-static const GDBusInterfaceVTable interface_vtable = {
- method_call_cb,
- NULL,
- NULL
-};
+ if (dest)
+ g_object_unref (dest);
-static GDBusNodeInfo *introspection_data;
+ ev_atril_application_complete_reload (object, invocation);
+
+ return TRUE;
+}
#endif /* ENABLE_DBUS */
void
@@ -916,19 +902,15 @@ ev_application_shutdown (EvApplication *application)
g_object_unref (application->keys);
application->keys = NULL;
}
- if (application->registration_id != 0) {
- g_dbus_connection_unregister_object (application->connection,
- application->registration_id);
- application->registration_id = 0;
+ if (application->skeleton != NULL) {
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (application->skeleton));
+ g_object_unref (application->skeleton);
+ application->skeleton = NULL;
}
if (application->connection != NULL) {
g_object_unref (application->connection);
application->connection = NULL;
}
- if (introspection_data) {
- g_dbus_node_info_ref (introspection_data);
- introspection_data = NULL;
- }
#endif /* ENABLE_DBUS */
g_free (application->dot_dir);
@@ -971,17 +953,22 @@ static void ev_application_init(EvApplication* ev_application)
#ifdef ENABLE_DBUS
ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (ev_application->connection != NULL) {
- introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
- g_assert (introspection_data != NULL);
-
- ev_application->registration_id =
- g_dbus_connection_register_object (ev_application->connection,
- APPLICATION_DBUS_OBJECT_PATH,
- introspection_data->interfaces[0],
- &interface_vtable,
- ev_application, NULL,
- &error);
- if (ev_application->registration_id == 0) {
+ EvAtrilApplication *skeleton;
+
+ skeleton = ev_atril_application_skeleton_new ();
+ if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
+ ev_application->connection,
+ APPLICATION_DBUS_OBJECT_PATH,
+ &error)) {
+ ev_application->skeleton = skeleton;
+ g_signal_connect (skeleton, "handle-get-window-list",
+ G_CALLBACK (handle_get_window_list_cb),
+ ev_application);
+ g_signal_connect (skeleton, "handle-reload",
+ G_CALLBACK (handle_reload_cb),
+ ev_application);
+ } else {
+ g_object_unref (skeleton);
g_printerr ("Failed to register bus object: %s\n", error->message);
g_error_free (error);
}