struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
								      SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token)
{
	PurpleNotifySearchResults *results = purple_notify_searchresults_new();

	if (results) {
		PurpleNotifySearchColumn *column;
		column = purple_notify_searchresults_column_new(_("User name"));
		purple_notify_searchresults_column_add(results, column);

		column = purple_notify_searchresults_column_new(_("Name"));
		purple_notify_searchresults_column_add(results, column);

		column = purple_notify_searchresults_column_new(_("Company"));
		purple_notify_searchresults_column_add(results, column);

		column = purple_notify_searchresults_column_new(_("Country"));
		purple_notify_searchresults_column_add(results, column);

		column = purple_notify_searchresults_column_new(_("Email"));
		purple_notify_searchresults_column_add(results, column);
	}

	return((struct sipe_backend_search_results *)results);
}
Exemple #2
0
static void ggp_pubdir_search_results_display(PurpleConnection *gc,
	int records_count, const ggp_pubdir_record *records, int next_offset,
	void *_form)
{
	ggp_pubdir_search_form *form = _form;
	PurpleNotifySearchResults *results;
	int i;

	purple_debug_info("gg", "ggp_pubdir_search_results_display: "
		"got %d records (next offset: %d)\n",
		records_count, next_offset);

	if (records_count < 0 ||
		(records_count == 0 && form->offset != 0))
	{
		purple_notify_error(gc, GGP_PUBDIR_SEARCH_TITLE,
			_("Error while searching for buddies"), NULL,
			purple_request_cpar_from_connection(gc));
		ggp_pubdir_search_form_free(form);
		return;
	}

	if (records_count == 0) {
		purple_notify_info(gc, GGP_PUBDIR_SEARCH_TITLE,
			_("No matching users found"),
			_("There are no users matching your search criteria."),
			purple_request_cpar_from_connection(gc));
		ggp_pubdir_search_form_free(form);
		return;
	}

	form->offset = next_offset;

	results = purple_notify_searchresults_new();

	purple_notify_searchresults_column_add(results,
		purple_notify_searchresults_column_new(_("GG Number")));
	purple_notify_searchresults_column_add(results,
		purple_notify_searchresults_column_new(_("Name")));
	purple_notify_searchresults_column_add(results,
		purple_notify_searchresults_column_new(_("City")));
	purple_notify_searchresults_column_add(results,
		purple_notify_searchresults_column_new(_("Gender")));
	purple_notify_searchresults_column_add(results,
		purple_notify_searchresults_column_new(_("Age")));

	for (i = 0; i < records_count; i++) {
		GList *row = NULL;
		const ggp_pubdir_record *record = &records[i];
		gchar *gender = NULL, *age = NULL;

		if (record->gender == GGP_PUBDIR_GENDER_MALE)
			gender = g_strdup("male");
		else if (record->gender == GGP_PUBDIR_GENDER_FEMALE)
			gender = g_strdup("female");

		if (record->age)
			age = g_strdup_printf("%d", record->age);

		row = g_list_append(row, g_strdup(ggp_uin_to_str(record->uin)));
		row = g_list_append(row, g_strdup(record->label));
		row = g_list_append(row, g_strdup(record->city));
		row = g_list_append(row, gender);
		row = g_list_append(row, age);
		purple_notify_searchresults_row_add(results, row);
	}

	purple_notify_searchresults_button_add(results,
		PURPLE_NOTIFY_BUTTON_ADD, ggp_pubdir_search_results_add);
	purple_notify_searchresults_button_add(results,
		PURPLE_NOTIFY_BUTTON_IM, ggp_pubdir_search_results_im);
	purple_notify_searchresults_button_add(results,
		PURPLE_NOTIFY_BUTTON_INFO, ggp_pubdir_search_results_info);
	purple_notify_searchresults_button_add_labeled(results, _("New search"),
		ggp_pubdir_search_results_new);
	if (next_offset != 0)
		purple_notify_searchresults_button_add(results,
			PURPLE_NOTIFY_BUTTON_CONTINUE,
			ggp_pubdir_search_results_next);

	if (!form->display_handle)
		form->display_handle = purple_notify_searchresults(gc,
			GGP_PUBDIR_SEARCH_TITLE, _("Search results"), NULL,
			results, ggp_pubdir_search_results_close, form);
	else
		purple_notify_searchresults_new_rows(gc, results,
			form->display_handle);
	g_assert(form->display_handle);
}
void
skypeweb_search_users_text_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonArray *resultsarray = NULL;
	gint index, length;
	GString *userids;
	gchar *search_term = user_data;

	PurpleNotifySearchResults *results;
	PurpleNotifySearchColumn *column;
	
	resultsarray = json_node_get_array(node);
	length = json_array_get_length(resultsarray);
	
	if (length == 0)
	{
		gchar *primary_text = g_strdup_printf("Your search for the user \"%s\" returned no results", search_term);
		purple_notify_warning(sa->pc, "No users found", primary_text, "");
		g_free(primary_text);
		g_free(search_term);
		return;
	}
	
	userids = g_string_new("");
	
	resultsarray = json_node_get_array(node);
	for(index = 0; index < length; index++)
	{
		JsonObject *result = json_array_get_object_element(resultsarray, index);
		g_string_append_printf(userids, "%s,", json_object_get_string_member(result, "skypewebid"));
	}

	
	results = purple_notify_searchresults_new();
	if (results == NULL)
	{
		g_free(search_term);
		return;
	}
		
	/* columns: Friend ID, Name, Network */
	column = purple_notify_searchresults_column_new(_("Skype Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Display Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("City"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Country"));
	purple_notify_searchresults_column_add(results, column);
	
	purple_notify_searchresults_button_add(results,
			PURPLE_NOTIFY_BUTTON_ADD,
			skypeweb_search_results_add_buddy);
	
	for(index = 0; index < length; index++)
	{
		JsonObject *contact = json_array_get_object_element(resultsarray, index);
		JsonObject *contactcards = json_object_get_object_member(contact, "ContactCards");
		JsonObject *skypecontact = json_object_get_object_member(contactcards, "Skype");
		JsonObject *currentlocation = json_object_get_object_member(contactcards, "CurrentLocation");
		
		/* the row in the search results table */
		/* prepend to it backwards then reverse to speed up adds */
		GList *row = NULL;
		
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "SkypeName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "DisplayName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "City")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "Country")));
		
		row = g_list_reverse(row);
		
		purple_notify_searchresults_row_add(results, row);
	}
	
	purple_notify_searchresults(sa->pc, NULL, search_term, NULL,
			results, NULL, NULL);
}