static void fb_util_request_buddy_ok(gpointer *mata, PurpleRequestFields *fields) { FbUtilRequestBuddyFunc func = mata[0]; GList *l; GList *select; gpointer data = mata[2]; GSList *ret = NULL; PurpleBuddy *bdy; PurpleRequestField *field; if (func == NULL) { g_free(mata); return; } field = purple_request_fields_get_field(fields, "buddy"); select = purple_request_field_list_get_selected(field); for (l = select; l != NULL; l = l->next) { bdy = purple_request_field_list_get_data(field, l->data); ret = g_slist_prepend(ret, bdy); } ret = g_slist_reverse(ret); func(ret, data); g_slist_free(ret); g_free(mata); }
static void buddytimezone_submitfields_cb(PurpleRequestFields * fields, PurpleBlistNode * data) { PurpleBlistNode *node; PurpleRequestField *list; /* timezone stuff */ purple_debug(PURPLE_DEBUG_INFO, PLUGIN_STATIC_NAME, "buddytimezone_submitfields_cb(%p,%p)\n", fields, data); switch (data->type) { case PURPLE_BLIST_BUDDY_NODE: node = (PurpleBlistNode *) purple_buddy_get_contact((PurpleBuddy *) data); break; case PURPLE_BLIST_CONTACT_NODE: case PURPLE_BLIST_GROUP_NODE: /* code handles either case */ node = data; break; case PURPLE_BLIST_CHAT_NODE: case PURPLE_BLIST_OTHER_NODE: default: /* Not applicable */ return; } list = purple_request_fields_get_field(fields, CONTROL_NAME); if (ui_ops != NULL && ui_ops->get_timezone_menu_selection != NULL) { const char *seldata = ui_ops->get_timezone_menu_selection(list->ui_data); if (seldata == NULL) purple_blist_node_remove_setting(node, SETTING_NAME); else purple_blist_node_set_string(node, SETTING_NAME, seldata); } else { const GList *sellist; void *seldata = NULL; sellist = purple_request_field_list_get_selected(list); if (sellist) seldata = purple_request_field_list_get_data(list, sellist->data); /* Otherwise, it's fixed value and this means deletion */ if (seldata == TIMEZONE_FLAG) purple_blist_node_set_string(node, SETTING_NAME, sellist->data); else if (seldata == DISABLED_FLAG) purple_blist_node_set_string(node, SETTING_NAME, "none"); else purple_blist_node_remove_setting(node, SETTING_NAME); } }
static GntWidget* create_list_field(PurpleRequestField *field) { GntWidget *ret = NULL; GList *list; gboolean multi = purple_request_field_list_get_multi_select(field); if (multi) { GntWidget *tree = gnt_tree_new(); list = purple_request_field_list_get_items(field); for (; list; list = list->next) { const char *text = list->data; gpointer key = purple_request_field_list_get_data(field, text); gnt_tree_add_choice(GNT_TREE(tree), key, gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL); if (purple_request_field_list_is_selected(field, text)) gnt_tree_set_choice(GNT_TREE(tree), key, TRUE); } ret = tree; } else { GntWidget *combo = gnt_combo_box_new(); list = purple_request_field_list_get_items(field); for (; list; list = list->next) { const char *text = list->data; gpointer key = purple_request_field_list_get_data(field, text); gnt_combo_box_add_data(GNT_COMBO_BOX(combo), key, text); if (purple_request_field_list_is_selected(field, text)) gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), key); } ret = combo; } return ret; }
static void fchat_select_buddies_list_ok_cb(FChatSelectBuddiesListCbData *fchat_select_buddies_list_cb_data, PurpleRequestFields *fields) { PurpleRequestField *field = purple_request_fields_get_field(fields, "buddies"); GList *selected_items = purple_request_field_list_get_selected(field); FChatBuddy *buddy; GHashTable *buddies = g_hash_table_new(g_str_hash, g_str_equal); for (; selected_items != NULL; selected_items = g_list_next(selected_items)) { buddy = (FChatBuddy *)purple_request_field_list_get_data(field, (gchar *)selected_items->data); g_hash_table_insert(buddies, g_strdup(buddy->host), buddy); } g_list_free(selected_items); if (fchat_select_buddies_list_cb_data->ok_cb) fchat_select_buddies_list_cb_data->ok_cb(fchat_select_buddies_list_cb_data->fchat_conn, buddies, fchat_select_buddies_list_cb_data->user_data); g_hash_table_destroy(buddies); g_free(fchat_select_buddies_list_cb_data); }
static void silcpurple_add_buddy_select_cb(SilcPurpleBuddyRes r, PurpleRequestFields *fields) { PurpleRequestField *f; GList *list; SilcClientEntry client_entry; f = purple_request_fields_get_field(fields, "list"); list = purple_request_field_list_get_selected(f); if (!list) { /* The user did not select any user. */ silcpurple_add_buddy_pk_no(r); silc_free(r); return; } client_entry = purple_request_field_list_get_data(f, list->data); silcpurple_add_buddy_resolved(r->client, r->conn, &client_entry, 1, r); }
/*------------------------------------------------------------------------ * The user has selected to change their profile. * * @param gc The connection object * @param fields The fields from the request pop-up */ static void mxit_profile_cb( PurpleConnection* gc, PurpleRequestFields* fields ) { struct MXitSession* session = purple_connection_get_protocol_data( gc ); PurpleRequestField* field = NULL; const char* name = NULL; const char* bday = NULL; const char* err = NULL; GList* entry = NULL; purple_debug_info( MXIT_PLUGIN_ID, "mxit_profile_cb\n" ); PURPLE_ASSERT_CONNECTION_IS_VALID(gc); /* validate name */ name = purple_request_fields_get_string( fields, "name" ); if ( ( !name ) || ( strlen( name ) < 3 ) ) { err = _( "The Display Name you entered is invalid." ); goto out; } /* validate birthdate */ bday = purple_request_fields_get_string( fields, "bday" ); if ( ( !bday ) || ( strlen( bday ) < 10 ) || ( !validateDate( bday ) ) ) { err = _( "The birthday you entered is invalid. The correct format is: 'YYYY-MM-DD'." ); goto out; } out: if ( !err ) { struct MXitProfile* profile = session->profile; GString* attributes = g_string_sized_new( 128 ); char attrib[512]; unsigned int acount = 0; /* update name */ g_strlcpy( profile->nickname, name, sizeof( profile->nickname ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FULLNAME, CP_PROFILE_TYPE_UTF8, profile->nickname ); g_string_append( attributes, attrib ); acount++; /* update birthday */ g_strlcpy( profile->birthday, bday, sizeof( profile->birthday ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_BIRTHDATE, CP_PROFILE_TYPE_UTF8, profile->birthday ); g_string_append( attributes, attrib ); acount++; /* update gender */ profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_GENDER, CP_PROFILE_TYPE_BOOL, ( profile->male ) ? "1" : "0" ); g_string_append( attributes, attrib ); acount++; /* update title */ name = purple_request_fields_get_string( fields, "title" ); if ( !name ) profile->title[0] = '\0'; else g_strlcpy( profile->title, name, sizeof( profile->title ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_TITLE, CP_PROFILE_TYPE_UTF8, profile->title ); g_string_append( attributes, attrib ); acount++; /* update firstname */ name = purple_request_fields_get_string( fields, "firstname" ); if ( !name ) profile->firstname[0] = '\0'; else g_strlcpy( profile->firstname, name, sizeof( profile->firstname ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FIRSTNAME, CP_PROFILE_TYPE_UTF8, profile->firstname ); g_string_append( attributes, attrib ); acount++; /* update lastname */ name = purple_request_fields_get_string( fields, "lastname" ); if ( !name ) profile->lastname[0] = '\0'; else g_strlcpy( profile->lastname, name, sizeof( profile->lastname ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_LASTNAME, CP_PROFILE_TYPE_UTF8, profile->lastname ); g_string_append( attributes, attrib ); acount++; /* update email address */ name = purple_request_fields_get_string( fields, "email" ); if ( !name ) profile->email[0] = '\0'; else g_strlcpy( profile->email, name, sizeof( profile->email ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_EMAIL, CP_PROFILE_TYPE_UTF8, profile->email ); g_string_append( attributes, attrib ); acount++; /* update mobile number */ name = purple_request_fields_get_string( fields, "mobilenumber" ); if ( !name ) profile->mobilenr[0] = '\0'; else g_strlcpy( profile->mobilenr, name, sizeof( profile->mobilenr ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_MOBILENR, CP_PROFILE_TYPE_UTF8, profile->mobilenr ); g_string_append( attributes, attrib ); acount++; /* update about me */ name = purple_request_fields_get_string( fields, "aboutme" ); if ( !name ) profile->aboutme[0] = '\0'; else g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_ABOUTME, CP_PROFILE_TYPE_UTF8, profile->aboutme ); g_string_append( attributes, attrib ); acount++; /* update where am i */ name = purple_request_fields_get_string( fields, "whereami" ); if ( !name ) profile->whereami[0] = '\0'; else g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_WHEREAMI, CP_PROFILE_TYPE_UTF8, profile->whereami ); g_string_append( attributes, attrib ); acount++; /* relationship status */ field = purple_request_fields_get_field( fields, "relationship" ); entry = g_list_first( purple_request_field_list_get_selected( field ) ); profile->relationship = atoi( purple_request_field_list_get_data( field, entry->data ) ); g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%i", CP_PROFILE_RELATIONSHIP, CP_PROFILE_TYPE_SHORT, profile->relationship ); g_string_append( attributes, attrib ); acount++; /* update flags */ field = purple_request_fields_get_field( fields, "searchable" ); if ( purple_request_field_bool_get_value( field ) ) /* is searchable -> clear not-searchable flag */ profile->flags &= ~CP_PROF_NOT_SEARCHABLE; else profile->flags |= CP_PROF_NOT_SEARCHABLE; field = purple_request_fields_get_field( fields, "suggestable" ); if ( purple_request_field_bool_get_value( field ) ) /* is suggestable -> clear not-suggestable flag */ profile->flags &= ~CP_PROF_NOT_SUGGESTABLE; else profile->flags |= CP_PROF_NOT_SUGGESTABLE; g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%" G_GINT64_FORMAT, CP_PROFILE_FLAGS, CP_PROFILE_TYPE_LONG, profile->flags); g_string_append( attributes, attrib ); acount++; /* send the profile update to MXit */ mxit_send_extprofile_update( session, NULL, acount, attributes->str ); g_string_free( attributes, TRUE ); } else { /* show error to user */ mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Profile Update Error" ), err ); } }
static void request_fields_cb(GntWidget *button, PurpleRequestFields *fields) { PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); GList *list; /* Update the data of the fields. Pidgin does this differently. Instead of * updating the fields at the end like here, it updates the appropriate field * instantly whenever a change is made. That allows it to make sure the * 'required' fields are entered before the user can hit OK. It's not the case * here, althought it can be done. */ for (list = purple_request_fields_get_groups(fields); list; list = list->next) { PurpleRequestFieldGroup *group = list->data; GList *fields = purple_request_field_group_get_fields(group); for (; fields ; fields = fields->next) { PurpleRequestField *field = fields->data; PurpleRequestFieldType type = purple_request_field_get_type(field); if (type == PURPLE_REQUEST_FIELD_BOOLEAN) { GntWidget *check = FINCH_GET_DATA(field); gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); purple_request_field_bool_set_value(field, value); } else if (type == PURPLE_REQUEST_FIELD_STRING) { GntWidget *entry = FINCH_GET_DATA(field); const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); purple_request_field_string_set_value(field, (text && *text) ? text : NULL); } else if (type == PURPLE_REQUEST_FIELD_INTEGER) { GntWidget *entry = FINCH_GET_DATA(field); const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); int value = (text && *text) ? atoi(text) : 0; purple_request_field_int_set_value(field, value); } else if (type == PURPLE_REQUEST_FIELD_CHOICE) { GntWidget *combo = FINCH_GET_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); } else if (type == PURPLE_REQUEST_FIELD_LIST) { GList *list = NULL; if (purple_request_field_list_get_multi_select(field)) { GList *iter; GntWidget *tree = FINCH_GET_DATA(field); iter = purple_request_field_list_get_items(field); for (; iter; iter = iter->next) { const char *text = iter->data; gpointer key = purple_request_field_list_get_data(field, text); if (gnt_tree_get_choice(GNT_TREE(tree), key)) list = g_list_prepend(list, key); } } else { GntWidget *combo = FINCH_GET_DATA(field); gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); list = g_list_append(list, data); } purple_request_field_list_set_selected(field, list); g_list_free(list); } else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) { GntWidget *combo = FINCH_GET_DATA(field); PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); purple_request_field_account_set_value(field, acc); } } } purple_notify_close_with_handle(button); if (!g_object_get_data(G_OBJECT(button), "cancellation-function") && !purple_request_fields_all_required_filled(fields)) { purple_notify_error(button, _("Error"), _("You must fill all the required fields."), _("The required fields are underlined.")); return; } if (callback) callback(data, fields); while (button->parent) button = button->parent; purple_request_close(PURPLE_REQUEST_FIELDS, button); }