/pidgin/main: c652670afac5: Request API refactoring: custom PURP...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Sep 12 08:38:32 EDT 2013
Changeset: c652670afac534d677c180ee613c984ec3413cb9
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2013-09-12 14:38 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/c652670afac5
Description:
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
diffstat:
finch/gntblist.c | 8 +-
finch/gntrequest.c | 32 +++++---
libpurple/plugins/autoaccept.c | 8 +-
libpurple/protocols/gg/pubdir-prpl.c | 68 +++++++------------
libpurple/protocols/jabber/jabber.c | 24 +++---
libpurple/protocols/jabber/si.c | 9 +-
libpurple/protocols/jabber/xdata.c | 11 ++-
libpurple/protocols/mxit/actions.c | 6 +-
libpurple/protocols/mxit/login.c | 6 +-
libpurple/protocols/yahoo/libymsg.c | 6 +-
libpurple/request.c | 121 +++++++++++++++++++---------------
libpurple/request.h | 59 ++++++++++------
pidgin/gtkrequest.c | 87 ++++++++++++++++++------
pidgin/gtkutils.c | 2 +-
14 files changed, 254 insertions(+), 193 deletions(-)
diffs (truncated from 977 to 300 lines):
diff --git a/finch/gntblist.c b/finch/gntblist.c
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -2668,7 +2668,7 @@ block_select_cb(gpointer data, PurpleReq
PurpleAccount *account = purple_request_fields_get_account(fields, "account");
const char *name = purple_request_fields_get_string(fields, "screenname");
if (account && name && *name != '\0') {
- if (purple_request_fields_get_choice(fields, "block") == 1) {
+ if (GPOINTER_TO_INT(purple_request_fields_get_choice(fields, "block")) == 1) {
purple_privacy_deny(account, name, FALSE, FALSE);
} else {
purple_privacy_allow(account, name, FALSE, FALSE);
@@ -2701,9 +2701,9 @@ block_select(GntMenuItem *item, gpointer
purple_request_field_set_required(field, TRUE);
purple_request_field_group_add_field(group, field);
- field = purple_request_field_choice_new("block", _("Block/Unblock"), 1);
- purple_request_field_choice_add(field, _("Block"));
- purple_request_field_choice_add(field, _("Unblock"));
+ field = purple_request_field_choice_new("block", _("Block/Unblock"), GINT_TO_POINTER(1));
+ purple_request_field_choice_add(field, _("Block"), GINT_TO_POINTER(1));
+ purple_request_field_choice_add(field, _("Unblock"), GINT_TO_POINTER(2));
purple_request_field_group_add_field(group, field);
purple_request_fields(purple_get_blist(), _("Block/Unblock"),
diff --git a/finch/gntrequest.c b/finch/gntrequest.c
--- a/finch/gntrequest.c
+++ b/finch/gntrequest.c
@@ -197,7 +197,7 @@ request_choice_cb(GntWidget *button, Gnt
{
PurpleRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
- int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1;
+ gpointer choice = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
if (callback)
callback(data, choice);
@@ -210,7 +210,7 @@ request_choice_cb(GntWidget *button, Gnt
static void *
finch_request_choice(const char *title, const char *primary,
- const char *secondary, int default_value,
+ const char *secondary, gpointer default_value,
const char *ok_text, GCallback ok_cb,
const char *cancel_text, GCallback cancel_cb,
PurpleRequestCommonParameters *cpar,
@@ -229,7 +229,7 @@ finch_request_choice(const char *title,
val = va_arg(choices, int);
gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text);
}
- gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1));
+ gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), default_value);
box = setup_button_box(window, user_data, request_choice_cb, combo,
ok_text, ok_cb, cancel_text, cancel_cb, NULL);
@@ -337,9 +337,8 @@ request_fields_cb(GntWidget *button, Pur
else if (type == PURPLE_REQUEST_FIELD_CHOICE)
{
GntWidget *combo = purple_request_field_get_ui_data(field);
- int id;
- id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)));
- purple_request_field_choice_set_value(field, id);
+ gpointer value = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
+ purple_request_field_choice_set_value(field, value);
}
else if (type == PURPLE_REQUEST_FIELD_LIST)
{
@@ -477,18 +476,25 @@ create_integer_field(PurpleRequestField
static GntWidget*
create_choice_field(PurpleRequestField *field)
{
- int id;
- GList *list;
+ GList *it;
GntWidget *combo = gnt_combo_box_new();
- list = purple_request_field_choice_get_labels(field);
- for (id = 1; list; list = list->next, id++)
+ it = purple_request_field_choice_get_elements(field);
+ while (it != NULL)
{
- gnt_combo_box_add_data(GNT_COMBO_BOX(combo),
- GINT_TO_POINTER(id), list->data);
+ const gchar *text;
+ gpointer value;
+
+ 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_set_selected(GNT_COMBO_BOX(combo),
- GINT_TO_POINTER(purple_request_field_choice_get_default_value(field)));
+ purple_request_field_choice_get_default_value(field));
return combo;
}
diff --git a/libpurple/plugins/autoaccept.c b/libpurple/plugins/autoaccept.c
--- a/libpurple/plugins/autoaccept.c
+++ b/libpurple/plugins/autoaccept.c
@@ -200,13 +200,13 @@ set_auto_accept_settings(PurpleBlistNode
message = g_strdup_printf(_("When a file-transfer request arrives from %s"),
purple_contact_get_alias((PurpleContact *)node));
purple_request_choice(plugin, _("Set Autoaccept Setting"), message,
- NULL, purple_blist_node_get_int(node, "autoaccept"),
+ NULL, GINT_TO_POINTER(purple_blist_node_get_int(node, "autoaccept")),
_("_Save"), G_CALLBACK(save_cb),
_("_Cancel"), NULL,
NULL, node,
- _("Ask"), FT_ASK,
- _("Auto Accept"), FT_ACCEPT,
- _("Auto Reject"), FT_REJECT,
+ _("Ask"), GINT_TO_POINTER(FT_ASK),
+ _("Auto Accept"), GINT_TO_POINTER(FT_ACCEPT),
+ _("Auto Reject"), GINT_TO_POINTER(FT_REJECT),
NULL);
g_free(message);
}
diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c
--- a/libpurple/protocols/gg/pubdir-prpl.c
+++ b/libpurple/protocols/gg/pubdir-prpl.c
@@ -132,6 +132,7 @@ static void ggp_pubdir_set_info_got_resp
static const gchar *ggp_pubdir_provinces[] =
{
+ N_("Not specified"),
"dolnoÅlÄ
skie",
"kujawsko-pomorskie",
"lubelskie",
@@ -514,8 +515,7 @@ void ggp_pubdir_search(PurpleConnection
PurpleRequestFields *fields;
PurpleRequestFieldGroup *group;
PurpleRequestField *field;
- int default_gender;
-
+
purple_debug_info("gg", "ggp_pubdir_search\n");
fields = purple_request_fields_new();
@@ -529,18 +529,14 @@ void ggp_pubdir_search(PurpleConnection
field = purple_request_field_string_new("city", _("City"),
form ? form->city : NULL, FALSE);
purple_request_field_group_add_field(group, field);
-
- default_gender = 0;
- if (form && form->gender == GGP_PUBDIR_GENDER_MALE)
- default_gender = 1;
- else if (form && form->gender == GGP_PUBDIR_GENDER_FEMALE)
- default_gender = 2;
-
+
field = purple_request_field_choice_new("gender", _("Gender"),
- default_gender);
- purple_request_field_choice_add(field, _("Male or female"));
- purple_request_field_choice_add(field, _("Male"));
- purple_request_field_choice_add(field, _("Female"));
+ GINT_TO_POINTER(form->gender));
+ purple_request_field_choice_add(field, _("Male or female"), 0);
+ purple_request_field_choice_add(field, _("Male"),
+ GINT_TO_POINTER(GGP_PUBDIR_GENDER_MALE));
+ purple_request_field_choice_add(field, _("Female"),
+ GINT_TO_POINTER(GGP_PUBDIR_GENDER_FEMALE));
purple_request_field_group_add_field(group, field);
purple_request_fields(gc, _("Find buddies"), _("Find buddies"),
@@ -554,18 +550,13 @@ static void ggp_pubdir_search_request(Pu
PurpleRequestFields *fields)
{
ggp_pubdir_search_form *form = g_new0(ggp_pubdir_search_form, 1);
- int gender;
purple_debug_info("gg", "ggp_pubdir_search_request\n");
form->nick = g_strdup(purple_request_fields_get_string(fields, "name"));
form->city = g_strdup(purple_request_fields_get_string(fields, "city"));
- gender = purple_request_fields_get_choice(fields, "gender");
- if (gender == 1)
- form->gender = GGP_PUBDIR_GENDER_MALE;
- else if (gender == 2)
- form->gender = GGP_PUBDIR_GENDER_FEMALE;
-
+ form->gender = GPOINTER_TO_INT(purple_request_fields_get_choice(fields,
+ "gender"));
form->offset = 0;
form->limit = GGP_PUBDIR_SEARCH_PER_PAGE;
@@ -812,7 +803,6 @@ static void ggp_pubdir_set_info_dialog(P
PurpleRequestFields *fields;
PurpleRequestFieldGroup *group;
PurpleRequestField *field;
- int default_gender;
gsize i;
const ggp_pubdir_record *record;
@@ -832,18 +822,14 @@ static void ggp_pubdir_set_info_dialog(P
field = purple_request_field_string_new("last_name", _("Last name"),
record ? record->last_name : NULL, FALSE);
purple_request_field_group_add_field(group, field);
-
- default_gender = -1;
- if (record && record->gender == GGP_PUBDIR_GENDER_MALE)
- default_gender = 0;
- else if (record && record->gender == GGP_PUBDIR_GENDER_FEMALE)
- default_gender = 1;
-
+
field = purple_request_field_choice_new("gender", _("Gender"),
- default_gender);
+ GINT_TO_POINTER(record->gender));
purple_request_field_set_required(field, TRUE);
- purple_request_field_choice_add(field, _("Male"));
- purple_request_field_choice_add(field, _("Female"));
+ purple_request_field_choice_add(field, _("Male"),
+ GINT_TO_POINTER(GGP_PUBDIR_GENDER_MALE));
+ purple_request_field_choice_add(field, _("Female"),
+ GINT_TO_POINTER(GGP_PUBDIR_GENDER_FEMALE));
purple_request_field_group_add_field(group, field);
field = purple_request_field_string_new("birth_date", _("Birth Day"),
@@ -858,15 +844,14 @@ static void ggp_pubdir_set_info_dialog(P
field = purple_request_field_choice_new("province", _("Voivodeship"), 0);
purple_request_field_group_add_field(group, field);
- purple_request_field_choice_add(field, _("Not specified"));
for (i = 0; i < ggp_pubdir_provinces_count; i++)
{
- purple_request_field_choice_add(field, ggp_pubdir_provinces[i]);
- if (record && i + 1 == record->province)
+ purple_request_field_choice_add(field, ggp_pubdir_provinces[i],
+ GINT_TO_POINTER(i));
+ if (record && i == record->province)
{
- purple_request_field_choice_set_value(field, i + 1);
- purple_request_field_choice_set_default_value(field,
- i + 1); // TODO: libpurple bug?
+ purple_request_field_choice_set_value(field, GINT_TO_POINTER(i));
+ purple_request_field_choice_set_default_value(field, GINT_TO_POINTER(i));
}
}
@@ -894,13 +879,12 @@ static void ggp_pubdir_set_info_request(
"first_name"));
record->last_name = g_strdup(purple_request_fields_get_string(fields,
"last_name"));
- if (purple_request_fields_get_choice(fields, "gender") == 0)
- record->gender = GGP_PUBDIR_GENDER_MALE;
- else
- record->gender = GGP_PUBDIR_GENDER_FEMALE;
+ record->gender = GPOINTER_TO_INT(
+ purple_request_fields_get_choice(fields, "gender"));
record->city = g_strdup(purple_request_fields_get_string(fields,
"city"));
- record->province = purple_request_fields_get_choice(fields, "province");
+ record->province = GPOINTER_TO_INT(
+ purple_request_fields_get_choice(fields, "province"));
birth_s = g_strdup_printf("%sT10:00:00+00:00",
purple_request_fields_get_string(fields, "birth_date"));
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -3252,10 +3252,8 @@ jabber_media_ok_cb(JabberMediaRequest *r
{
PurpleRequestField *field =
purple_request_fields_get_field(fields, "resource");
- int selected_id = purple_request_field_choice_get_value(field);
- GList *labels = purple_request_field_choice_get_labels(field);
- gchar *who = g_strdup_printf("%s/%s", request->who,
- (gchar*)g_list_nth_data(labels, selected_id));
+ const gchar *selected = purple_request_field_choice_get_value(field);
+ gchar *who = g_strdup_printf("%s/%s", request->who, selected);
jabber_initiate_media(request->account, who, request->type);
g_free(who);
@@ -3340,6 +3338,8 @@ jabber_initiate_media(PurpleAccount *acc
PurpleRequestFieldGroup *group;
JabberMediaRequest *request;
+ purple_request_field_choice_set_data_destructor(field, g_free);
+
for(l = jb->resources; l; l = l->next)
{
JabberBuddyResource *ljbr = l->data;
@@ -3353,19 +3353,19 @@ jabber_initiate_media(PurpleAccount *acc
(type & PURPLE_MEDIA_VIDEO)) {
if (caps & PURPLE_MEDIA_CAPS_AUDIO_VIDEO) {
jbr = ljbr;
- purple_request_field_choice_add(
- field, jbr->name);
+ purple_request_field_choice_add(field,
+ jbr->name, g_strdup(jbr->name));
}
} else if (type & (PURPLE_MEDIA_AUDIO) &&
(caps & PURPLE_MEDIA_CAPS_AUDIO)) {
jbr = ljbr;
- purple_request_field_choice_add(
- field, jbr->name);
More information about the Commits
mailing list