pidgin/pidgin

Parents fb4b0ae193c0
Children 4caeb8c0b1ca
Add PurpleNamedValue to use in lists instead of consecutive key and value elements
--- 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 @@
field = NULL;
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;
switch(type) {
@@ -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;
char *value = NULL;
switch(type) {
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));
break;
case PURPLE_PREF_INT:
- value = g_strdup_printf("%d", GPOINTER_TO_INT(list->next->data));
+ value = g_strdup_printf("%d", GPOINTER_TO_INT(choice->value));
break;
case PURPLE_PREF_STRING:
- value = g_strdup(list->next->data);
+ value = g_strdup(choice->value);
break;
default:
break;
}
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);
}
g_free(current_value);
} else {
--- 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 @@
static GntWidget*
create_choice_field(PurpleRequestField *field)
{
- GList *it;
GntWidget *combo = gnt_combo_box_new();
- it = purple_request_field_choice_get_elements(field);
- while (it != NULL)
+ for (GList *it = purple_request_field_choice_get_elements(field); it != NULL; it = g_list_next(it))
{
- const gchar *text;
- gpointer value;
+ PurpleNamedValue *choice = it->data;
- text = it->data;
- it = g_list_next(it);
- g_assert(it != NULL);
- value = it->data;
- it = g_list_next(it);
-
- 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;
gpointer help_data;
- GSList *extra_actions, *it;
+ GSList *extra_actions;
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 @@
void
purple_plugin_pref_destroy(PurplePluginPref *pref)
{
- GList *tmp;
g_return_if_fail(pref != NULL);
g_free(pref->name);
g_free(pref->label);
- tmp = pref->choices;
- while(tmp) {
- g_free(tmp->data);
- /* 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);
g_free(pref);
}
@@ -255,12 +248,15 @@
void
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);
}
GList *
--- 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(
- field)) <= 2) {
+ field)) <= 1) {
gchar *name;
gboolean result;
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, ...)
{
va_list args;
- GSList *extra = NULL, *it;
-
- it = cpar->extra_actions;
- while (it != NULL) {
- gchar *label = it->data;
-
- g_free(label);
- it = g_slist_next(it);
- if (it == NULL)
- break;
- it = g_slist_next(it);
- }
+ GSList *extra = NULL;
+
+ g_slist_free_full(cpar->extra_actions, (GDestroyNotify)purple_named_value_free);
va_start(args, cpar);
while (TRUE) {
const gchar *label;
PurpleRequestFieldsCb cb;
+ PurpleNamedValue *extra_action;
label = va_arg(args, const gchar*);
if (label == NULL)
break;
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);
}
va_end(args);
@@ -946,22 +939,14 @@
}
else if (field->type == PURPLE_REQUEST_FIELD_CHOICE)
{
- if (field->u.choice.elements != NULL)
- {
- GList *it = field->u.choice.elements;
- while (it != NULL) {
- g_free(it->data);
- it = g_list_next(it); /* value */
- if (it == NULL) {
- g_warn_if_reached();
- break;
- }
- 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,
gpointer value)
{
+ 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,
- g_strdup(label));
- field->u.choice.elements = g_list_append(field->u.choice.elements,
- value);
+ choice);
}
void
--- 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
* setter).
*/
GSList *
@@ -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}.
*/
GList *
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 @@
g_free(kvp);
}
+PurpleNamedValue *
+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;
+
+ return named_value;
+}
+
+void
+purple_named_value_free(PurpleNamedValue *named_value)
+{
+ g_return_if_fail(named_value != NULL);
+
+ g_free(named_value->name);
+ g_free(named_value);
+}
+
gchar *
purple_uuid_random(void)
{
--- 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;
+/**
+ * PurpleNamedValue:
+ * @name: The name
+ * @value: The value
+ *
+ * A name-value pair.
+ *
+ * Similar to PurpleKeyValuePair except it doesn't allocate memory for @value.
+ */
+typedef struct _PurpleNamedValue PurpleNamedValue;
+
#include "account.h"
#include "signals.h"
#include "xmlnode.h"
@@ -58,7 +69,12 @@
{
gchar *key;
void *value;
+};
+struct _PurpleNamedValue
+{
+ gchar *name;
+ gpointer value;
};
G_BEGIN_DECLS
@@ -93,9 +109,34 @@
* @kvp: The PurpleKeyValuePair to free.
*
* Frees a PurpleKeyValuePair.
+ *
+ * Since: 3.0.0
*/
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
+ *
+ * Since: 3.0.0
+ */
+PurpleNamedValue *purple_named_value_new(const char *name, gpointer value);
+
+/**
+ * purple_named_value_free:
+ * @named_value: The PurpleNamedValue to free.
+ *
+ * Frees a PurpleNamedValue.
+ *
+ * Since: 3.0.0
+ */
+void purple_named_value_free(PurpleNamedValue *named_value);
+
/**************************************************************************/
/* Utility Subsystem */
/**************************************************************************/
--- 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 @@
{
GtkWidget *dropdown;
GtkWidget *label = NULL;
- gchar *text;
GtkListStore *store = NULL;
GtkTreeIter iter;
GtkTreeIter active;
@@ -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;
int int_value = 0;
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) {
+ break;
+ }
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
- PREF_DROPDOWN_TEXT, text,
+ PREF_DROPDOWN_TEXT, menu_item->name,
-1);
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,
-1);
}
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,
-1);
}
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,
-1);
@@ -550,8 +551,6 @@
active = iter;
}
-
- 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 @@
{
GtkWidget *widget;
GList *elements = purple_request_field_choice_get_elements(field);
- int num_labels = g_list_length(elements) / 2;
- GList *l;
+ guint num_labels = g_list_length(elements);
gpointer *values = g_new(gpointer, num_labels);
gpointer default_value;
gboolean default_found = FALSE;
@@ -1237,23 +1236,16 @@
widget = gtk_combo_box_text_new();
i = 0;
- l = elements;
- while (l != NULL)
+ for (GList *l = elements; l != NULL; l = g_list_next(l))
{
- const char *text;
- gpointer *value;
-
- text = l->data;
- l = g_list_next(l);
- value = l->data;
- 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) {
default_index = i;
default_found = TRUE;
}
- values[i++] = 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));
i = 0;
- l = elements;
- while (l != NULL)
+ for (GList *l = elements; l != NULL; l = g_list_next(l))
{
- const char *text;
- gpointer *value;
-
- text = l->data;
- l = g_list_next(l);
- value = l->data;
- 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 (first_radio == NULL)
first_radio = radio;
- if (value == default_value) {
+ if (choice->value == default_value) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
default_found = TRUE;
}
- values[i++] = value;
+ values[i++] = choice->value;
gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
gtk_widget_show(radio);
@@ -1889,8 +1874,8 @@
char *label_text;
char *primary_esc, *secondary_esc;
const gboolean compact = purple_request_cpar_is_compact(cpar);
- GSList *extra_actions, *it;
- size_t extra_actions_count, i;
+ GSList *extra_actions;
+ size_t i;
const gchar **tab_names;
guint tab_count;
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->cb_count = 2;
data->cbs = g_new0(GCallback, 2);
@@ -1934,14 +1918,12 @@
pidgin_request_add_help(GTK_DIALOG(win), cpar);
- it = extra_actions;
- 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);
}
/* Cancel button */