/** * g_action_print_detailed_name: * @action_name: a valid action name * @target_value: (allow-none): a #GVariant target value, or %NULL * * Formats a detailed action name from @action_name and @target_value. * * It is an error to call this function with an invalid action name. * * This function is the opposite of g_action_parse_detailed_name(). * It will produce a string that can be parsed back to the @action_name * and @target_value by that function. * * See that function for the types of strings that will be printed by * this function. * * Returns: a detailed format string * * Since: 2.38 **/ gchar * g_action_print_detailed_name (const gchar *action_name, GVariant *target_value) { g_return_val_if_fail (g_action_name_is_valid (action_name), NULL); if (target_value == NULL) return g_strdup (action_name); if (g_variant_is_of_type (target_value, G_VARIANT_TYPE_STRING)) { const gchar *str = g_variant_get_string (target_value, NULL); if (g_action_name_is_valid (str)) return g_strconcat (action_name, "::", str, NULL); } { GString *result = g_string_new (action_name); g_string_append_c (result, '('); g_variant_print_string (target_value, result, TRUE); g_string_append_c (result, ')'); return g_string_free (result, FALSE); } }
/** * g_notification_add_button_with_target_value: (rename-to g_notification_add_button_with_target) * @notification: a #GNotification * @label: label of the button * @action: an action name * @target: (allow-none): a #GVariant to use as @action's parameter, or %NULL * * Adds a button to @notification that activates @action when clicked. * @action must be an application-wide action (it must start with "app."). * * If @target is non-%NULL, @action will be activated with @target as * its parameter. * * Since: 2.40 */ void g_notification_add_button_with_target_value (GNotification *notification, const gchar *label, const gchar *action, GVariant *target) { Button *button; g_return_if_fail (G_IS_NOTIFICATION (notification)); g_return_if_fail (label != NULL); g_return_if_fail (action != NULL && g_action_name_is_valid (action)); if (!g_str_has_prefix (action, "app.")) { g_warning ("%s: action '%s' does not start with 'app.'." "This is unlikely to work properly.", G_STRFUNC, action); } button = g_slice_new0 (Button); button->label = g_strdup (label); button->action_name = g_strdup (action); if (target) button->target = g_variant_ref_sink (target); g_ptr_array_add (notification->buttons, button); }
static int app_action (gchar **args) { GVariantBuilder params; const gchar *name; if (!app_check_name (args, "action")) return 1; if (args[1] == NULL) { g_printerr (_("action name must be given after application id\n")); return 1; } name = args[1]; if (!g_action_name_is_valid (name)) { g_printerr (_("invalid action name: '%s'\n" "action names must consist of only alphanumerics, '-' and '.'\n"), name); return 1; } g_variant_builder_init (¶ms, G_VARIANT_TYPE ("av")); if (args[2]) { GError *error = NULL; GVariant *parameter; parameter = g_variant_parse (NULL, args[2], NULL, NULL, &error); if (!parameter) { gchar *context; context = g_variant_parse_error_print_context (error, args[2]); g_printerr (_("error parsing action parameter: %s\n"), context); g_variant_builder_clear (¶ms); g_error_free (error); g_free (context); return 1; } g_variant_builder_add (¶ms, "v", parameter); g_variant_unref (parameter); if (args[3]) { g_printerr (_("actions accept a maximum of one parameter\n")); g_variant_builder_clear (¶ms); return 1; } } return app_call (args[0], "ActivateAction", g_variant_new ("(sav@a{sv})", name, ¶ms, app_get_platform_data ())); }
/** * g_notification_set_default_action_and_target_value: (rename-to g_notification_set_default_action_and_target) * @notification: a #GNotification * @action: an action name * @target: (allow-none): a #GVariant to use as @action's parameter, or %NULL * * Sets the default action of @notification to @action. This action is * activated when the notification is clicked on. It must be an * application-wide action (start with "app."). * * If @target is non-%NULL, @action will be activated with @target as * its parameter. * * 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_and_target_value (GNotification *notification, const gchar *action, GVariant *target) { g_return_if_fail (G_IS_NOTIFICATION (notification)); g_return_if_fail (action != NULL && g_action_name_is_valid (action)); if (!g_str_has_prefix (action, "app.")) { g_warning ("%s: action '%s' does not start with 'app.'." "This is unlikely to work properly.", G_STRFUNC, action); } g_free (notification->default_action); g_clear_pointer (¬ification->default_action_target, g_variant_unref); notification->default_action = g_strdup (action); if (target) notification->default_action_target = g_variant_ref_sink (target); }