diff options
author | Ryan Lortie <desrt@desrt.ca> | 2011-12-17 00:17:08 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-12-17 12:54:02 -0500 |
commit | eefd08996f7657488cb8afed23667030d6bd45f7 (patch) | |
tree | 4ac93a6c87c2ef932fb6328dd69f8c7a6bed637e /gio/gdbusactiongroup.c | |
parent | ee9f104432ee1ed0bf1e7461cf3264d0f0f1d297 (diff) | |
download | glib-eefd08996f7657488cb8afed23667030d6bd45f7.tar.gz |
introduce GRemoteActionGroup
This interfaceifies the extra functions that were on GDBusActionGroup
for dealing with platform data.
The two main benefits of doing this:
- no longer have to do a silly song and dance in GApplication to avoid
calling GDBusActionGroup API from non-dbus-aware code
- the interface can be reused by the action group exporter to avoid
ugly and unbindable hook callbacks
https://bugzilla.gnome.org/show_bug.cgi?id=665737
Diffstat (limited to 'gio/gdbusactiongroup.c')
-rw-r--r-- | gio/gdbusactiongroup.c | 138 |
1 files changed, 50 insertions, 88 deletions
diff --git a/gio/gdbusactiongroup.c b/gio/gdbusactiongroup.c index 4e08d1002..4fe746956 100644 --- a/gio/gdbusactiongroup.c +++ b/gio/gdbusactiongroup.c @@ -24,6 +24,7 @@ #include "gdbusactiongroup.h" +#include "gremoteactiongroup.h" #include "gdbusconnection.h" #include "gactiongroup.h" @@ -122,9 +123,11 @@ action_info_new_from_iter (GVariantIter *iter) return info; } -static void g_dbus_action_group_iface_init (GActionGroupInterface *); +static void g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface); +static void g_dbus_action_group_iface_init (GActionGroupInterface *iface); G_DEFINE_TYPE_WITH_CODE (GDBusActionGroup, g_dbus_action_group, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_dbus_action_group_iface_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_dbus_action_group_iface_init) + G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_dbus_action_group_remote_iface_init)) static void g_dbus_action_group_changed (GDBusConnection *connection, @@ -363,23 +366,53 @@ g_dbus_action_group_query_action (GActionGroup *g_group, } static void -g_dbus_action_group_change_state (GActionGroup *g_group, +g_dbus_action_group_activate_action_full (GRemoteActionGroup *remote, + const gchar *action_name, + GVariant *parameter, + GVariant *platform_data) +{ + GDBusActionGroup *group = G_DBUS_ACTION_GROUP (remote); + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); + + if (parameter) + g_variant_builder_add (&builder, "v", parameter); + + g_dbus_connection_call (group->connection, group->bus_name, group->object_path, "org.gtk.Actions", "Activate", + g_variant_new ("(sav@a{sv})", action_name, &builder, platform_data), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); +} + +static void +g_dbus_action_group_change_action_state_full (GRemoteActionGroup *remote, + const gchar *action_name, + GVariant *value, + GVariant *platform_data) +{ + GDBusActionGroup *group = G_DBUS_ACTION_GROUP (remote); + + g_dbus_connection_call (group->connection, group->bus_name, group->object_path, "org.gtk.Actions", "SetState", + g_variant_new ("(sv@a{sv})", action_name, value, platform_data), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); +} + +static void +g_dbus_action_group_change_state (GActionGroup *group, const gchar *action_name, GVariant *value) { - GDBusActionGroup *group = G_DBUS_ACTION_GROUP (g_group); - - g_dbus_action_group_change_action_state_full (group, action_name, value, g_variant_new ("a{sv}", NULL)); + g_dbus_action_group_change_action_state_full (G_REMOTE_ACTION_GROUP (group), + action_name, value, g_variant_new ("a{sv}", NULL)); } static void -g_dbus_action_group_activate (GActionGroup *g_group, +g_dbus_action_group_activate (GActionGroup *group, const gchar *action_name, GVariant *parameter) { - GDBusActionGroup *group = G_DBUS_ACTION_GROUP (g_group); - - g_dbus_action_group_activate_action_full (group, action_name, parameter, g_variant_new ("a{sv}", NULL)); + g_dbus_action_group_activate_action_full (G_REMOTE_ACTION_GROUP (group), + action_name, parameter, g_variant_new ("a{sv}", NULL)); } static void @@ -415,6 +448,13 @@ g_dbus_action_group_class_init (GDBusActionGroupClass *class) } static void +g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface) +{ + iface->activate_action_full = g_dbus_action_group_activate_action_full; + iface->change_action_state_full = g_dbus_action_group_change_action_state_full; +} + +static void g_dbus_action_group_iface_init (GActionGroupInterface *iface) { iface->list_actions = g_dbus_action_group_list_actions; @@ -496,81 +536,3 @@ g_dbus_action_group_sync (GDBusActionGroup *group, return reply != NULL; } - -/** - * g_dbus_action_group_activate_action_full: - * @action_group: a #GDBusActionGroup - * @action_name: the name of the action to activate - * @parameter: (allow none): the optional parameter to the activation - * @platform_data: the platform data to send - * - * Activates the remote action. - * - * This is the same as g_action_group_activate_action() except that it - * allows for provision of "platform data" to be sent along with the - * activation request. This typically contains details such as the user - * interaction timestamp or startup notification information. - * - * @platform_data must be non-%NULL and must have the type - * %G_VARIANT_TYPE_VARDICT. If it is floating, it will be consumed. - * - * Since: 2.32 - **/ -void -g_dbus_action_group_activate_action_full (GDBusActionGroup *action_group, - const gchar *action_name, - GVariant *parameter, - GVariant *platform_data) -{ - GVariantBuilder builder; - - g_return_if_fail (G_IS_DBUS_ACTION_GROUP (action_group)); - g_return_if_fail (action_name != NULL); - g_return_if_fail (platform_data != NULL); - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); - - if (parameter) - g_variant_builder_add (&builder, "v", parameter); - - g_dbus_connection_call (action_group->connection, action_group->bus_name, action_group->object_path, - "org.gtk.Actions", "Activate", - g_variant_new ("(sav@a{sv})", action_name, &builder, platform_data), - NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); -} - -/** - * g_dbus_action_group_activate_action_full: - * @action_group: a #GDBusActionGroup - * @action_name: the name of the action to change the state of - * @value: the new requested value for the state - * @platform_data: the platform data to send - * - * Changes the state of a remote action. - * - * This is the same as g_action_group_change_action_state() except that - * it allows for provision of "platform data" to be sent along with the - * state change request. This typically contains details such as the - * user interaction timestamp or startup notification information. - * - * @platform_data must be non-%NULL and must have the type - * %G_VARIANT_TYPE_VARDICT. If it is floating, it will be consumed. - * - * Since: 2.32 - **/ -void -g_dbus_action_group_change_action_state_full (GDBusActionGroup *action_group, - const gchar *action_name, - GVariant *value, - GVariant *platform_data) -{ - g_return_if_fail (G_IS_DBUS_ACTION_GROUP (action_group)); - g_return_if_fail (action_name != NULL); - g_return_if_fail (value != NULL); - g_return_if_fail (platform_data != NULL); - - g_dbus_connection_call (action_group->connection, action_group->bus_name, action_group->object_path, - "org.gtk.Actions", "SetState", - g_variant_new ("(sv@a{sv})", action_name, value, platform_data), - NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); -} |