Ejemplo n.º 1
0
Archivo: xdata.c Proyecto: VoxOx/VoxOx
void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data)
{
	void *handle;
	xmlnode *fn, *x;
	GaimRequestFields *fields;
	GaimRequestFieldGroup *group;
	GaimRequestField *field;

	char *title = NULL;
	char *instructions = NULL;

	struct jabber_x_data_data *data = g_new0(struct jabber_x_data_data, 1);

	data->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	data->user_data = user_data;
	data->cb = cb;
	data->js = js;

	fields = gaim_request_fields_new();
	group = gaim_request_field_group_new(NULL);
	gaim_request_fields_add_group(fields, group);

	for(fn = xmlnode_get_child(packet, "field"); fn; fn = xmlnode_get_next_twin(fn)) {
		xmlnode *valuenode;
		const char *type = xmlnode_get_attrib(fn, "type");
		const char *label = xmlnode_get_attrib(fn, "label");
		const char *var = xmlnode_get_attrib(fn, "var");
		char *value = NULL;

		if(!type)
			continue;

		if(!var && strcmp(type, "fixed"))
			continue;
		if(!label)
			label = var;

		if((valuenode = xmlnode_get_child(fn, "value")))
			value = xmlnode_get_data(valuenode);


		/* XXX: handle <required/> */

		if(!strcmp(type, "text-private")) {
			if((valuenode = xmlnode_get_child(fn, "value")))
				value = xmlnode_get_data(valuenode);

			field = gaim_request_field_string_new(var, label,
					value ? value : "", FALSE);
			gaim_request_field_string_set_masked(field, TRUE);
			gaim_request_field_group_add_field(group, field);

			g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));

			if(value)
				g_free(value);
		} else if(!strcmp(type, "text-multi") || !strcmp(type, "jid-multi")) {
			GString *str = g_string_new("");

			for(valuenode = xmlnode_get_child(fn, "value"); valuenode;
					valuenode = xmlnode_get_next_twin(valuenode)) {

				if(!(value = xmlnode_get_data(valuenode)))
					continue;

				g_string_append_printf(str, "%s\n", value);
				g_free(value);
			}

			field = gaim_request_field_string_new(var, label,
					str->str, TRUE);
			gaim_request_field_group_add_field(group, field);

			g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI));

			g_string_free(str, TRUE);
		} else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) {
			xmlnode *optnode;
			GList *selected = NULL;

			field = gaim_request_field_list_new(var, label);

			if(!strcmp(type, "list-multi")) {
				gaim_request_field_list_set_multi_select(field, TRUE);
				g_hash_table_replace(data->fields, g_strdup(var),
						GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI));
			} else {
				g_hash_table_replace(data->fields, g_strdup(var),
						GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE));
			}

			for(valuenode = xmlnode_get_child(fn, "value"); valuenode;
					valuenode = xmlnode_get_next_twin(valuenode)) {
				selected = g_list_prepend(selected, xmlnode_get_data(valuenode));
			}

			for(optnode = xmlnode_get_child(fn, "option"); optnode;
					optnode = xmlnode_get_next_twin(optnode)) {
				const char *lbl;

				if(!(valuenode = xmlnode_get_child(optnode, "value")))
					continue;

				if(!(value = xmlnode_get_data(valuenode)))
					continue;

				if(!(lbl = xmlnode_get_attrib(optnode, "label")))
					label = value;

				data->values = g_slist_prepend(data->values, value);

				gaim_request_field_list_add(field, lbl, value);
				if(g_list_find_custom(selected, value, (GCompareFunc)strcmp))
					gaim_request_field_list_add_selected(field, lbl);
			}
			gaim_request_field_group_add_field(group, field);

			while(selected) {
				g_free(selected->data);
				selected = g_list_delete_link(selected, selected);
			}

		} else if(!strcmp(type, "boolean")) {
			gboolean def = FALSE;

			if((valuenode = xmlnode_get_child(fn, "value")))
				value = xmlnode_get_data(valuenode);

			if(value && (!g_ascii_strcasecmp(value, "yes") ||
						!g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1")))
				def = TRUE;

			field = gaim_request_field_bool_new(var, label, def);
			gaim_request_field_group_add_field(group, field);

			g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN));

			if(value)
				g_free(value);
		} else if(!strcmp(type, "fixed") && value) {
			if((valuenode = xmlnode_get_child(fn, "value")))
				value = xmlnode_get_data(valuenode);

			field = gaim_request_field_label_new("", value);
			gaim_request_field_group_add_field(group, field);

			if(value)
				g_free(value);
		} else if(!strcmp(type, "hidden")) {
			if((valuenode = xmlnode_get_child(fn, "value")))
				value = xmlnode_get_data(valuenode);

			field = gaim_request_field_string_new(var, "", value ? value : "",
					FALSE);
			gaim_request_field_set_visible(field, FALSE);
			gaim_request_field_group_add_field(group, field);

			g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));

			if(value)
				g_free(value);
		} else { /* text-single, jid-single, and the default */
			if((valuenode = xmlnode_get_child(fn, "value")))
				value = xmlnode_get_data(valuenode);

			field = gaim_request_field_string_new(var, label,
					value ? value : "", FALSE);
			gaim_request_field_group_add_field(group, field);

			if(!strcmp(type, "jid-single")) {
				gaim_request_field_set_type_hint(field, "screenname");
				g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_JID_SINGLE));
			} else {
				g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));
			}

			if(value)
				g_free(value);
		}
	}

	if((x = xmlnode_get_child(packet, "title")))
		title = xmlnode_get_data(x);

	if((x = xmlnode_get_child(packet, "instructions")))
		instructions = xmlnode_get_data(x);

	handle = gaim_request_fields(js->gc, title, title, instructions, fields,
			_("OK"), G_CALLBACK(jabber_x_data_ok_cb),
			_("Cancel"), G_CALLBACK(jabber_x_data_cancel_cb), data);

	if(title)
		g_free(title);
	if(instructions)
		g_free(instructions);

	return handle;
}
Ejemplo n.º 2
0
static void
set_profile(GaimPluginAction *action)
{
	GaimConnection *gc = (GaimConnection *)action->context;
	GaimRequestFields *fields;
	GaimRequestFieldGroup *group;
	GaimRequestField *field;

	fields = gaim_request_fields_new();

	/* Basic Profile group. */
	group = gaim_request_field_group_new(_("Basic Profile"));
	gaim_request_fields_add_group(fields, group);

	/* First Name */
	field = gaim_request_field_string_new("firstname", _("First Name"), NULL,
										  FALSE);
	gaim_request_field_group_add_field(group, field);
	gaim_debug(GAIM_DEBUG_MISC, "trepia", "feld type = %d\n",
			   field->type);

	/* Last Name */
	field = gaim_request_field_string_new("lastname", _("Last Name"), NULL,
										  FALSE);
	gaim_request_field_group_add_field(group, field);

	/* Gender */
	field = gaim_request_field_choice_new("gender", _("Gender"), 0);
	gaim_request_field_choice_add(field, _("Male"));
	gaim_request_field_choice_add(field, _("Female"));
	gaim_request_field_group_add_field(group, field);

	/* Age */
	field = gaim_request_field_int_new("age", _("Age"), 0);
	gaim_request_field_group_add_field(group, field);

	/* Homepage */
	field = gaim_request_field_string_new("homepage", _("Homepage"), NULL,
										  FALSE);
	gaim_request_field_group_add_field(group, field);

	/* E-Mail Address */
	field = gaim_request_field_string_new("email", _("E-Mail Address"), NULL,
										  FALSE);
	gaim_request_field_group_add_field(group, field);

	/* Profile String */
	field = gaim_request_field_string_new("profile",
										  _("Profile Information"), NULL,
										  TRUE);
	gaim_request_field_group_add_field(group, field);


	/* Instant Messagers */
	group = gaim_request_field_group_new(_("Instant Messagers"));
	gaim_request_fields_add_group(fields, group);

	/* AIM */
	field = gaim_request_field_string_new("aim", _("AIM"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);

	/* ICQ */
	field = gaim_request_field_string_new("icq", _("ICQ UIN"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);

	/* MSN */
	field = gaim_request_field_string_new("msn", _("MSN"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);

	/* Yahoo */
	field = gaim_request_field_string_new("yahoo", _("Yahoo"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);


	/* I'm From */
	group = gaim_request_field_group_new(_("I'm From"));
	gaim_request_fields_add_group(fields, group);

	/* City */
	field = gaim_request_field_string_new("city", _("City"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);

	/* State */
	field = gaim_request_field_string_new("state", _("State"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);

	/* Country */
	field = gaim_request_field_string_new("country", _("Country"), NULL, FALSE);
	gaim_request_field_group_add_field(group, field);


	/* Call the dialog. */
	gaim_request_fields(gc, NULL, _("Set your Trepia profile data."),
						NULL, fields,
						_("Save"), G_CALLBACK(save_profile_cb),
						_("Cancel"), NULL, gc);
}