/** * 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); } }
/** * playerctl_player_print_metadata_prop: * @self: a #PlayerctlPlayer * @property: (allow-none): the property from the metadata to print * @err: (allow-none): the location of a GError or NULL * * Gets the artist from the metadata of the current track, or empty string if * no track is playing. * * Returns: (transfer full): The artist from the metadata of the current track */ gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, gchar *property, GError **err) { GVariant *prop_variant; const gchar **prop_strv; GString *prop; GVariant *metadata; GError *tmp_error = NULL; g_return_val_if_fail(err == NULL || *err == NULL, NULL); if (self->priv->init_error != NULL) { g_propagate_error(err, g_error_copy(self->priv->init_error)); return NULL; } metadata = org_mpris_media_player2_player_get_metadata(self->priv->proxy); if (!metadata) return g_strdup(""); if (!property) return g_variant_print(metadata, FALSE); prop_variant = g_variant_lookup_value(metadata, property, NULL); if (!prop_variant) return g_strdup(""); prop = g_string_new(""); if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING_ARRAY)) { gsize prop_count; prop_strv = g_variant_get_strv(prop_variant, &prop_count); for (int i = 0; i < prop_count; i += 1) { g_string_append(prop, prop_strv[i]); if (i != prop_count - 1) { g_string_append(prop, ", "); } } g_free(prop_strv); } else if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING)) { g_string_append(prop, g_variant_get_string(prop_variant, NULL)); } else { prop = g_variant_print_string(prop_variant, prop, FALSE); } return g_string_free(prop, FALSE); }
gchar * _gtk_accel_path_for_action (const gchar *action_name, GVariant *parameter) { GString *s; s = g_string_new ("<GAction>/"); g_string_append (s, action_name); if (parameter) { g_string_append_c (s, '/'); g_variant_print_string (parameter, s, FALSE); } return g_string_free (s, FALSE); }
static void print_reply (GDBusProxy *proxy, const gchar *method) { GVariant *var; GError *error = NULL; g_print ("calling %s\t", method); var = g_dbus_proxy_call_sync (proxy, method, g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, &error); if (var != NULL) { GString *string = g_variant_print_string (var, NULL, TRUE); g_print ("%s", string->str); } else { g_print ("returned NULL\t"); if (error) g_print ("error %s", error->message); } g_clear_error (&error); if (var) g_variant_unref (var); g_print ("\n"); }