changeset 31670:34404b2719c5

Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
author tomkiewicz@cpw.pidgin.im
date Sat, 18 Jun 2011 11:29:11 +0000
parents 35395b98f6b5
children 84f72590a319
files ChangeLog libpurple/protocols/gg/gg.c libpurple/protocols/gg/search.c libpurple/protocols/gg/search.h
diffstat 4 files changed, 42 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jun 18 06:59:36 2011 +0000
+++ b/ChangeLog	Sat Jun 18 11:29:11 2011 +0000
@@ -11,6 +11,10 @@
 	Plugins:
 	* The Evolution Integration plugin compiles again.
 
+	Gadu-Gadu:
+	* Fixed searching for buddies in public directory. (Tomasz Wasilczyk)
+	  (#5242)
+
 version 2.8.0 (06/07/2011):
 	General:
 	* Implement simple silence suppression for voice calls, preventing
--- a/libpurple/protocols/gg/gg.c	Sat Jun 18 06:59:36 2011 +0000
+++ b/libpurple/protocols/gg/gg.c	Sat Jun 18 11:29:11 2011 +0000
@@ -487,15 +487,16 @@
 	GGPSearchForm *form = user_data;
 	guint32 seq;
 
-	g_free(form->offset);
-	form->offset = g_strdup(form->last_uin);
+	form->page_number++;
 
 	ggp_search_remove(info->searches, form->seq);
-	purple_debug_info("gg", "ggp_callback_show_next(): Removed seq %u", form->seq);
+	purple_debug_info("gg", "ggp_callback_show_next(): Removed seq %u\n",
+		form->seq);
 
 	seq = ggp_search_start(gc, form);
 	ggp_search_add(info->searches, seq, form);
-	purple_debug_info("gg", "ggp_callback_show_next(): Added seq %u", seq);
+	purple_debug_info("gg", "ggp_callback_show_next(): Added seq %u\n",
+		seq);
 }
 
 static void ggp_callback_add_buddy(PurpleConnection *gc, GList *row, gpointer user_data)
@@ -526,21 +527,16 @@
 	form = ggp_search_form_new(GGP_SEARCH_TYPE_FULL);
 
 	form->user_data = info;
-	form->lastname  = charset_convert(
-				purple_request_fields_get_string(fields, "lastname"),
-				"UTF-8", "CP1250");
-	form->firstname = charset_convert(
-				purple_request_fields_get_string(fields, "firstname"),
-				"UTF-8", "CP1250");
-	form->nickname  = charset_convert(
-				purple_request_fields_get_string(fields, "nickname"),
-				"UTF-8", "CP1250");
-	form->city      = charset_convert(
-				purple_request_fields_get_string(fields, "city"),
-				"UTF-8", "CP1250");
-	form->birthyear = charset_convert(
-				purple_request_fields_get_string(fields, "year"),
-				"UTF-8", "CP1250");
+	form->lastname = g_strdup(
+		purple_request_fields_get_string(fields, "lastname"));
+	form->firstname = g_strdup(
+		purple_request_fields_get_string(fields, "firstname"));
+	form->nickname = g_strdup(
+		purple_request_fields_get_string(fields, "nickname"));
+	form->city = g_strdup(
+		purple_request_fields_get_string(fields, "city"));
+	form->birthyear = g_strdup(
+		purple_request_fields_get_string(fields, "year"));
 
 	switch (purple_request_fields_get_choice(fields, "gender")) {
 		case 1:
@@ -557,11 +553,10 @@
 	form->active = purple_request_fields_get_bool(fields, "active")
 				   ? g_strdup(GG_PUBDIR50_ACTIVE_TRUE) : NULL;
 
-	form->offset = g_strdup("0");
-
 	seq = ggp_search_start(gc, form);
 	ggp_search_add(info->searches, seq, form);
-	purple_debug_info("gg", "ggp_callback_find_buddies(): Added seq %u", seq);
+	purple_debug_info("gg", "ggp_callback_find_buddies(): Added seq %u\n",
+		seq);
 }
 
 static void ggp_find_buddies(PurplePluginAction *action)
@@ -1131,7 +1126,8 @@
 	GGPInfo *info = form->user_data;
 
 	ggp_search_remove(info->searches, form->seq);
-	purple_debug_info("gg", "ggp_sr_close_cb(): Removed seq %u", form->seq);
+	purple_debug_info("gg", "ggp_sr_close_cb(): Removed seq %u\n",
+		form->seq);
 	ggp_search_form_destroy(form);
 }
 
@@ -1246,6 +1242,8 @@
 
 	res_count = gg_pubdir50_count(req);
 	res_count = (res_count > PUBDIR_RESULTS_MAX) ? PUBDIR_RESULTS_MAX : res_count;
+	if (form->page_size == 0)
+		form->page_size = res_count;
 
 	results = purple_notify_searchresults_new();
 
@@ -1255,7 +1253,8 @@
 		purple_notify_error(gc, NULL,
 				  _("Unable to display the search results."),
 				  NULL);
-		ggp_sr_close_cb(form);
+		if (form->window == NULL)
+			ggp_sr_close_cb(form);
 		return;
 	}
 
@@ -1297,11 +1296,6 @@
 			(birth && strncmp(birth, "0", 1)) ? birth : g_strdup("-"));
 
 		purple_notify_searchresults_row_add(results, row);
-
-		if (i == res_count - 1) {
-			g_free(form->last_uin);
-			form->last_uin = ggp_search_get_result(req, i, GG_PUBDIR50_UIN);
-		}
 	}
 
 	purple_notify_searchresults_button_add(results, PURPLE_NOTIFY_BUTTON_CONTINUE,
@@ -1342,7 +1336,8 @@
 
 	seq = gg_pubdir50_seq(req);
 	form = ggp_search_get(info->searches, seq);
-	purple_debug_info("gg", "ggp_pubdir_reply_handler(): seq %u --> form %p", seq, form);
+	purple_debug_info("gg",
+		"ggp_pubdir_reply_handler(): seq %u --> form %p\n", seq, form);
 	/*
 	 * this can happen when user will request more results
 	 * and close the results window before they arrive.
@@ -1355,7 +1350,8 @@
 		purple_notify_error(gc, NULL,
 			_("No matching users found"),
 			_("There are no users matching your search criteria."));
-		ggp_sr_close_cb(form);
+		if (form->window == NULL)
+			ggp_sr_close_cb(form);
 		return;
 	}
 
@@ -2382,8 +2378,6 @@
 
 	form->user_data = info;
 	form->uin = g_strdup(name);
-	form->offset = g_strdup("0");
-	form->last_uin = g_strdup("0");
 
 	seq = ggp_search_start(gc, form);
 	ggp_search_add(info->searches, seq, form);
--- a/libpurple/protocols/gg/search.c	Sat Jun 18 06:59:36 2011 +0000
+++ b/libpurple/protocols/gg/search.c	Sat Jun 18 11:29:11 2011 +0000
@@ -38,6 +38,8 @@
 	form->window = NULL;
 	form->user_data = NULL;
 	form->seq = 0;
+	form->page_number = 0;
+	form->page_size = 0;
 
 	form->uin = NULL;
 	form->lastname = NULL;
@@ -47,8 +49,6 @@
 	form->birthyear = NULL;
 	form->gender = NULL;
 	form->active = NULL;
-	form->offset = NULL;
-	form->last_uin = NULL;
 
 	return form;
 }
@@ -62,6 +62,8 @@
 	form->window = NULL;
 	form->user_data = NULL;
 	form->seq = 0;
+	form->page_number = 0;
+	form->page_size = 0;
 
 	g_free(form->uin);
 	g_free(form->lastname);
@@ -71,8 +73,6 @@
 	g_free(form->birthyear);
 	g_free(form->gender);
 	g_free(form->active);
-	g_free(form->offset);
-	g_free(form->last_uin);
 	g_free(form);
 }
 /* }}} */
@@ -137,7 +137,7 @@
 {
 	GGPInfo *info = gc->proto_data;
 	gg_pubdir50_t req;
-	guint seq;
+	guint seq, offset;
 
 	purple_debug_info("gg", "It's time to perform a search...\n");
 
@@ -187,8 +187,10 @@
 		}
 	}
 
-	purple_debug_info("gg", "offset: %s\n", form->offset);
-	gg_pubdir50_add(req, GG_PUBDIR50_START, g_strdup(form->offset));
+	offset = form->page_size * form->page_number;
+	purple_debug_info("gg", "page number: %u, page size: %u, offset: %u\n",
+		form->page_number, form->page_size, offset);
+	gg_pubdir50_add(req, GG_PUBDIR50_START, g_strdup_printf("%u", offset));
 
 	if ((seq = gg_pubdir50(info->session, req)) == 0) {
 		purple_debug_warning("gg", "ggp_bmenu_show_details: Search failed.\n");
--- a/libpurple/protocols/gg/search.h	Sat Jun 18 06:59:36 2011 +0000
+++ b/libpurple/protocols/gg/search.h	Sat Jun 18 11:29:11 2011 +0000
@@ -46,12 +46,11 @@
 	char *birthyear;
 	char *gender;
 	char *active;
-	char *offset;
-
-	char *last_uin;
 
 	GGPSearchType search_type;
 	guint32 seq;
+	guint16 page_number;
+	guint16 page_size; /* how many contacts fits into one page of results */
 
 	void *user_data;
 	void *window;