void activate_action_string(GmpvApplication *app, const gchar *str) { GActionMap *map = G_ACTION_MAP(app); GAction *action = NULL; gchar *name = NULL; GVariant *param = NULL; gboolean param_match = FALSE; g_action_parse_detailed_name(str, &name, ¶m, NULL); if(name) { const GVariantType *action_ptype; const GVariantType *given_ptype; action = g_action_map_lookup_action(map, name); action_ptype = g_action_get_parameter_type(action); given_ptype = param?g_variant_get_type(param):NULL; param_match = (action_ptype == given_ptype) || g_variant_type_is_subtype_of (action_ptype, given_ptype); } if(action && param_match) { g_debug("Activating action %s", str); g_action_activate(action, param); } else { g_warning("Failed to activate action \"%s\"", str); } }
static gboolean egg_empty_state_activate_link (EggEmptyState *self, const gchar *uri, GtkLabel *label) { g_assert (EGG_IS_EMPTY_STATE (self)); g_assert (uri != NULL); g_assert (GTK_IS_LABEL (label)); if (g_str_has_prefix (uri, "action://")) { g_autofree gchar *full_name = NULL; g_autofree gchar *action_name = NULL; g_autofree gchar *group_name = NULL; g_autoptr(GVariant) param = NULL; g_autoptr(GError) error = NULL; uri += strlen ("action://"); if (g_action_parse_detailed_name (uri, &full_name, ¶m, &error)) { const gchar *dot = strchr (full_name, '.'); if (param != NULL && g_variant_is_floating (param)) param = g_variant_ref_sink (param); if (dot == NULL) return FALSE; group_name = g_strndup (full_name, dot - full_name); action_name = g_strdup (++dot); egg_empty_state_action (GTK_WIDGET (self), group_name, action_name, param); return TRUE; } else g_warning ("%s", error->message); } return FALSE; }
/** * g_notification_set_default_action: * @notification: a #GNotification * @detailed_action: a detailed action name * * Sets the default action of @notification to @detailed_action. This * action is activated when the notification is clicked on. * * The action in @detailed_action must be an application-wide action (it * must start with "app."). If @detailed_action contains a target, the * given action will be activated with that target as its parameter. * See g_action_parse_detailed_name() for a description of the format * for @detailed_action. * * When no default action is set, the application that the notification * was sent on is activated. * * Since: 2.40 */ void g_notification_set_default_action (GNotification *notification, const gchar *detailed_action) { gchar *action; GVariant *target; GError *error = NULL; if (!g_action_parse_detailed_name (detailed_action, &action, &target, &error)) { g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); return; } g_notification_set_default_action_and_target_value (notification, action, target); g_free (action); if (target) g_variant_unref (target); }
/** * g_notification_add_button: * @notification: a #GNotification * @label: label of the button * @detailed_action: a detailed action name * * Adds a button to @notification that activates the action in * @detailed_action when clicked. That action must be an * application-wide action (starting with "app."). If @detailed_action * contains a target, the action will be activated with that target as * its parameter. * * See g_action_parse_detailed_name() for a description of the format * for @detailed_action. * * Since: 2.40 */ void g_notification_add_button (GNotification *notification, const gchar *label, const gchar *detailed_action) { gchar *action; GVariant *target; GError *error = NULL; g_return_if_fail (detailed_action != NULL); if (!g_action_parse_detailed_name (detailed_action, &action, &target, &error)) { g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); return; } g_notification_add_button_with_target_value (notification, label, action, target); g_free (action); if (target) g_variant_unref (target); }