--- a/finch/gntplugin.c Fri Nov 15 01:07:08 2019 -0600
+++ b/finch/gntplugin.c Sat Nov 16 13:36:56 2019 +0300
@@ -567,7 +567,6 @@
type = purple_prefs_get_pref_type(name);
if(purple_plugin_pref_get_pref_type(pref) == PURPLE_PLUGIN_PREF_CHOICE) {
- GList *list = purple_plugin_pref_get_choices(pref);
gpointer current_value = NULL;
@@ -586,27 +585,26 @@
field = purple_request_field_list_new(name, label);
purple_request_field_list_set_multi_select(field, FALSE);
- while (list && list->next) {
- const char *label = list->data;
+ for (GList *list = purple_plugin_pref_get_choices(pref); list != NULL; list = list->next) { + const PurpleNamedValue *choice = list->data; case PURPLE_PREF_BOOLEAN:
- value = g_strdup_printf("%d", GPOINTER_TO_INT(list->next->data));
+ value = g_strdup_printf("%d", GPOINTER_TO_INT(choice->value)); - value = g_strdup_printf("%d", GPOINTER_TO_INT(list->next->data));
+ value = g_strdup_printf("%d", GPOINTER_TO_INT(choice->value)); - value = g_strdup(list->next->data);
+ value = g_strdup(choice->value); stringlist = g_list_prepend(stringlist, value);
- purple_request_field_list_add_icon(field, label, NULL, value);
+ purple_request_field_list_add_icon(field, choice->name, NULL, value); if (purple_strequal(value, current_value))
- purple_request_field_list_add_selected(field, label);
- list = list->next->next;
+ purple_request_field_list_add_selected(field, choice->name); --- a/finch/gntrequest.c Fri Nov 15 01:07:08 2019 -0600
+++ b/finch/gntrequest.c Sat Nov 16 13:36:56 2019 +0300
@@ -471,22 +471,13 @@
create_choice_field(PurpleRequestField *field)
GntWidget *combo = gnt_combo_box_new();
- it = purple_request_field_choice_get_elements(field);
+ for (GList *it = purple_request_field_choice_get_elements(field); it != NULL; it = g_list_next(it))
+ PurpleNamedValue *choice = it->data;
- gnt_combo_box_add_data(GNT_COMBO_BOX(combo), value, text);
+ gnt_combo_box_add_data(GNT_COMBO_BOX(combo), choice->value, choice->name); gnt_combo_box_set_selected(GNT_COMBO_BOX(combo),
purple_request_field_choice_get_default_value(field));
@@ -604,7 +595,7 @@
GntWidget *username = NULL, *accountlist = NULL;
PurpleRequestHelpCb help_cb;
- GSList *extra_actions, *it;
window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS);
@@ -690,14 +681,13 @@
ok, ok_cb, cancel, cancel_cb, NULL);
extra_actions = purple_request_cpar_get_extra_actions(cpar);
- for (it = extra_actions; it; it = it->next->next) {
- const gchar *label = it->data;
- PurpleRequestFieldsCb *cb = it->next->data;
+ for (GSList *it = extra_actions; it; it = it->next) { + PurpleNamedValue *extra_action = it->data; - GntWidget *button = gnt_button_new(label);
+ GntWidget *button = gnt_button_new(extra_action->name); gnt_box_add_widget_in_front(GNT_BOX(box), button);
g_object_set_data(G_OBJECT(button), "ui-handle", window);
- g_object_set_data(G_OBJECT(button), "extra-cb", cb);
+ g_object_set_data(G_OBJECT(button), "extra-cb", extra_action->value); g_object_set_data(G_OBJECT(button), "extra-cb-data", userdata);
g_signal_connect(G_OBJECT(button), "activate",
G_CALLBACK(multifield_extra_cb), allfields);
--- a/libpurple/pluginpref.c Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/pluginpref.c Sat Nov 16 13:36:56 2019 +0300
@@ -141,18 +141,11 @@
purple_plugin_pref_destroy(PurplePluginPref *pref)
g_return_if_fail(pref != NULL);
- /* Remove the string, and the data entries */
- tmp = g_list_delete_link(tmp, tmp);
- tmp = g_list_delete_link(tmp, tmp);
+ g_list_free_full(pref->choices, (GDestroyNotify)purple_named_value_free); @@ -255,12 +248,15 @@
purple_plugin_pref_add_choice(PurplePluginPref *pref, const char *label, gpointer choice)
+ PurpleNamedValue *pref_choice; g_return_if_fail(pref != NULL);
g_return_if_fail(label != NULL);
g_return_if_fail(choice || purple_prefs_get_pref_type(pref->name) == PURPLE_PREF_INT);
- pref->choices = g_list_append(pref->choices, g_strdup(label));
- pref->choices = g_list_append(pref->choices, choice);
+ pref_choice = purple_named_value_new(label, choice); + pref->choices = g_list_append(pref->choices, pref_choice); --- a/libpurple/pluginpref.h Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/pluginpref.h Sat Nov 16 13:36:56 2019 +0300
@@ -30,7 +30,7 @@
typedef struct _PurplePluginPrefFrame PurplePluginPrefFrame;
-typedef struct _PurplePluginPref PurplePluginPref;
+typedef struct _PurplePluginPref PurplePluginPref; * PurpleStringFormatType:
@@ -245,7 +245,7 @@
* Get the choices for a choices plugin pref
- * Returns: (element-type void) (transfer none): GList of the choices
+ * Returns: (element-type PurpleNamedValue) (transfer none): GList of the choices GList *purple_plugin_pref_get_choices(PurplePluginPref *pref);
--- a/libpurple/protocols/jabber/jabber.c Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/protocols/jabber/jabber.c Sat Nov 16 13:36:56 2019 +0300
@@ -3377,7 +3377,7 @@
if (g_list_length(purple_request_field_choice_get_elements(
purple_request_field_destroy(field);
--- a/libpurple/request.c Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/request.c Sat Nov 16 13:36:56 2019 +0300
@@ -395,32 +395,25 @@
purple_request_cpar_set_extra_actions(PurpleRequestCommonParameters *cpar, ...)
- GSList *extra = NULL, *it;
- it = cpar->extra_actions;
- gchar *label = it->data;
+ g_slist_free_full(cpar->extra_actions, (GDestroyNotify)purple_named_value_free); PurpleRequestFieldsCb cb;
+ PurpleNamedValue *extra_action; label = va_arg(args, const gchar*);
cb = va_arg(args, PurpleRequestFieldsCb);
- extra = g_slist_append(extra, g_strdup(label));
- extra = g_slist_append(extra, cb);
+ extra_action = purple_named_value_new(label, cb); + extra = g_slist_append(extra, extra_action); @@ -946,22 +939,14 @@
else if (field->type == PURPLE_REQUEST_FIELD_CHOICE)
- if (field->u.choice.elements != NULL)
- GList *it = field->u.choice.elements;
- it = g_list_next(it); /* value */
- if (it->data && field->u.choice.data_destroy)
- field->u.choice.data_destroy(it->data);
- it = g_list_next(it); /* next label */
- g_list_free(field->u.choice.elements);
+ for (GList *it = field->u.choice.elements; it != NULL; it = g_list_next(it)) { + PurpleNamedValue *choice = it->data; + if (choice->value && field->u.choice.data_destroy) + field->u.choice.data_destroy(choice->value); + purple_named_value_free(choice); + g_list_free(field->u.choice.elements); else if (field->type == PURPLE_REQUEST_FIELD_LIST)
@@ -1477,14 +1462,16 @@
purple_request_field_choice_add(PurpleRequestField *field, const char *label,
+ PurpleNamedValue *choice; g_return_if_fail(field != NULL);
g_return_if_fail(label != NULL);
g_return_if_fail(field->type == PURPLE_REQUEST_FIELD_CHOICE);
+ choice = purple_named_value_new(label, value); field->u.choice.elements = g_list_append(field->u.choice.elements,
- field->u.choice.elements = g_list_append(field->u.choice.elements,
--- a/libpurple/request.h Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/request.h Sat Nov 16 13:36:56 2019 +0300
@@ -528,7 +528,7 @@
* Gets extra actions for the PurpleRequestFields dialog.
- * Returns: (element-type void) (transfer none): A list of actions (pairs of arguments, as in
+ * Returns: (element-type PurpleNamedValue) (transfer none): A list of actions (pairs of arguments, as in @@ -1472,7 +1472,7 @@
* Returns a list of elements in a choice field.
- * Returns: (element-type void) (transfer none): The list of pairs of {label, value}.
+ * Returns: (element-type PurpleNamedValue) (transfer none): The list of pairs of {label, value}. purple_request_field_choice_get_elements(const PurpleRequestField *field);
--- a/libpurple/util.c Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/util.c Sat Nov 16 13:36:56 2019 +0300
@@ -3791,6 +3791,27 @@
+purple_named_value_new(const char *name, gpointer value) + PurpleNamedValue *named_value; + named_value = g_new0(PurpleNamedValue, 1); + named_value->name = g_strdup(name); + named_value->value = value; +purple_named_value_free(PurpleNamedValue *named_value) + g_return_if_fail(named_value != NULL); + g_free(named_value->name); --- a/libpurple/util.h Fri Nov 15 01:07:08 2019 -0600
+++ b/libpurple/util.h Sat Nov 16 13:36:56 2019 +0300
@@ -45,6 +45,17 @@
typedef struct _PurpleKeyValuePair PurpleKeyValuePair;
+ * Similar to PurpleKeyValuePair except it doesn't allocate memory for @value. +typedef struct _PurpleNamedValue PurpleNamedValue; @@ -58,7 +69,12 @@
+struct _PurpleNamedValue @@ -93,9 +109,34 @@
* @kvp: The PurpleKeyValuePair to free.
* Frees a PurpleKeyValuePair.
void purple_key_value_pair_free(PurpleKeyValuePair *kvp);
+ * purple_named_value_new: + * @name: The name part of PurpleNamedValue + * @value: The value part of PurpleNamedValue + * Creates a new PurpleNamedValue. + * Returns: The created PurpleNamedValue +PurpleNamedValue *purple_named_value_new(const char *name, gpointer value); + * purple_named_value_free: + * @named_value: The PurpleNamedValue to free. + * Frees a PurpleNamedValue. +void purple_named_value_free(PurpleNamedValue *named_value); /**************************************************************************/
/**************************************************************************/
--- a/pidgin/gtkprefs.c Fri Nov 15 01:07:08 2019 -0600
+++ b/pidgin/gtkprefs.c Sat Nov 16 13:36:56 2019 +0300
@@ -484,7 +484,6 @@
GtkListStore *store = NULL;
@@ -509,33 +508,35 @@
*dropdown_out = GTK_COMBO_BOX(dropdown);
g_object_set_data(G_OBJECT(dropdown), "type", GINT_TO_POINTER(initial.type));
- while (menuitems != NULL && (text = (char *)menuitems->data) != NULL) {
+ for (; menuitems != NULL; menuitems = g_list_next(menuitems)) { + const PurpleNamedValue *menu_item = menuitems->data; const char *str_value = NULL;
gboolean bool_value = FALSE;
- menuitems = g_list_next(menuitems);
- g_return_val_if_fail(menuitems != NULL, NULL);
+ if (menu_item->name == NULL) { gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
- PREF_DROPDOWN_TEXT, text,
+ PREF_DROPDOWN_TEXT, menu_item->name, if (initial.type == PURPLE_PREF_INT) {
- int_value = GPOINTER_TO_INT(menuitems->data);
+ int_value = GPOINTER_TO_INT(menu_item->value); gtk_list_store_set(store, &iter,
PREF_DROPDOWN_VALUE, int_value,
else if (initial.type == PURPLE_PREF_STRING) {
- str_value = (const char *)menuitems->data;
+ str_value = (const char *)menu_item->value; gtk_list_store_set(store, &iter,
PREF_DROPDOWN_VALUE, str_value,
else if (initial.type == PURPLE_PREF_BOOLEAN) {
- bool_value = (gboolean)GPOINTER_TO_INT(menuitems->data);
+ bool_value = (gboolean)GPOINTER_TO_INT(menu_item->value); gtk_list_store_set(store, &iter,
PREF_DROPDOWN_VALUE, bool_value,
@@ -550,8 +551,6 @@
- menuitems = g_list_next(menuitems);
renderer = gtk_cell_renderer_text_new();
--- a/pidgin/gtkprefs.h Fri Nov 15 01:07:08 2019 -0600
+++ b/pidgin/gtkprefs.h Sat Nov 16 13:36:56 2019 +0300
@@ -136,7 +136,7 @@
* @title: The text to be displayed as the dropdown label
* @type: The type of preference to be stored in the dropdown
* @key: The key of the pref that will be represented by the dropdown
- * @menuitems: (element-type void): The choices to be added to the dropdown, choices should
+ * @menuitems: (element-type PurpleNamedValue): The choices to be added to the dropdown, choices should * be paired as label/value
* Add a new dropdown representing a preference of the specified type
--- a/pidgin/gtkrequest.c Fri Nov 15 01:07:08 2019 -0600
+++ b/pidgin/gtkrequest.c Sat Nov 16 13:36:56 2019 +0300
@@ -1223,8 +1223,7 @@
GList *elements = purple_request_field_choice_get_elements(field);
- int num_labels = g_list_length(elements) / 2;
+ guint num_labels = g_list_length(elements); gpointer *values = g_new(gpointer, num_labels);
gboolean default_found = FALSE;
@@ -1237,23 +1236,16 @@
widget = gtk_combo_box_text_new();
+ for (GList *l = elements; l != NULL; l = g_list_next(l))
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text);
- if (value == default_value) {
+ PurpleNamedValue *choice = l->data; + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), choice->name); + if (choice->value == default_value) {
+ values[i++] = choice->value; gtk_combo_box_set_active(GTK_COMBO_BOX(widget), default_index);
@@ -1279,29 +1271,22 @@
gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+ for (GList *l = elements; l != NULL; l = g_list_next(l))
+ PurpleNamedValue *choice = l->data; radio = gtk_radio_button_new_with_label_from_widget(
- GTK_RADIO_BUTTON(first_radio), text);
+ GTK_RADIO_BUTTON(first_radio), choice->name); g_object_set_data(G_OBJECT(radio), "box", box);
- if (value == default_value) {
+ if (choice->value == default_value) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
+ values[i++] = choice->value; gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
@@ -1889,8 +1874,8 @@
char *primary_esc, *secondary_esc;
const gboolean compact = purple_request_cpar_is_compact(cpar);
- GSList *extra_actions, *it;
- size_t extra_actions_count, i;
gboolean ok_btn = (ok_text != NULL);
@@ -1903,7 +1888,6 @@
purple_request_fields_set_ui_data(fields, data);
extra_actions = purple_request_cpar_get_extra_actions(cpar);
- extra_actions_count = g_slist_length(extra_actions) / 2;
data->cbs = g_new0(GCallback, 2);
@@ -1934,14 +1918,12 @@
pidgin_request_add_help(GTK_DIALOG(win), cpar);
- for (i = 0; i < extra_actions_count; i++, it = it->next->next) {
- const gchar *label = it->data;
- PurpleRequestFieldsCb *cb = it->next->data;
- button = pidgin_dialog_add_button(GTK_DIALOG(win), label,
+ for (GSList *it = extra_actions; it != NULL; it = it->next) { + PurpleNamedValue *extra_action = it->data; + button = pidgin_dialog_add_button(GTK_DIALOG(win), extra_action->name, G_CALLBACK(multifield_extra_cb), data);
- g_object_set_data(G_OBJECT(button), "extra-cb", cb);
+ g_object_set_data(G_OBJECT(button), "extra-cb", extra_action->value);