void finch_request_save_in_prefs(gpointer null, PurpleRequestFields *allfields) { GList *list; for (list = purple_request_fields_get_groups(allfields); 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); PurplePrefType pt; gpointer val = NULL; const char *id = purple_request_field_get_id(field); switch (type) { case PURPLE_REQUEST_FIELD_LIST: val = purple_request_field_list_get_selected(field)->data; break; case PURPLE_REQUEST_FIELD_BOOLEAN: val = GINT_TO_POINTER(purple_request_field_bool_get_value(field)); break; case PURPLE_REQUEST_FIELD_INTEGER: val = GINT_TO_POINTER(purple_request_field_int_get_value(field)); break; case PURPLE_REQUEST_FIELD_STRING: val = (gpointer)purple_request_field_string_get_value(field); break; default: break; } pt = purple_prefs_get_type(id); switch (pt) { case PURPLE_PREF_INT: { long int tmp = GPOINTER_TO_INT(val); if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */ sscanf(val, "%ld", &tmp); purple_prefs_set_int(id, (gint)tmp); break; } case PURPLE_PREF_BOOLEAN: purple_prefs_set_bool(id, GPOINTER_TO_INT(val)); break; case PURPLE_PREF_STRING: purple_prefs_set_string(id, val); break; default: break; } } } }
void Request::FieldsDialog::IntegerField::OnActivate(CppConsUI::Button& activator) { char *value = g_strdup_printf("%d", purple_request_field_int_get_value(field)); CppConsUI::InputDialog *dialog = new CppConsUI::InputDialog(purple_request_field_get_label(field), value); g_free(value); dialog->SetFlags(CppConsUI::TextEntry::FLAG_NUMERIC); dialog->signal_response.connect(sigc::mem_fun(this, &IntegerField::ResponseHandler)); dialog->Show(); }
int purple_request_fields_get_integer(const PurpleRequestFields *fields, const char *id) { PurpleRequestField *field; g_return_val_if_fail(fields != NULL, 0); g_return_val_if_fail(id != NULL, 0); if ((field = purple_request_fields_get_field(fields, id)) == NULL) return 0; return purple_request_field_int_get_value(field); }
Request::FieldsDialog::IntegerField::IntegerField(PurpleRequestField *field) : Button(FLAG_VALUE), field(field) { g_assert(field); char *text = g_strdup_printf("%s%s", purple_request_field_is_required(field) ? "*" : "", purple_request_field_get_label(field)); SetText(text); g_free(text); SetValue(purple_request_field_int_get_value(field)); signal_activate.connect(sigc::mem_fun(this, &IntegerField::OnActivate)); }
void Request::FieldsDialog::IntegerField::ResponseHandler( CppConsUI::InputDialog& activator, CppConsUI::AbstractDialog::ResponseType response) { const char *text; long int i; switch (response) { case CppConsUI::AbstractDialog::RESPONSE_OK: text = activator.GetText(); errno = 0; i = strtol(text, NULL, 10); if (errno == ERANGE || i > INT_MAX || i < INT_MIN) LOG->Warning(_("Value is out of range.")); purple_request_field_int_set_value(field, CLAMP(i, INT_MIN, INT_MAX)); SetValue(purple_request_field_int_get_value(field)); break; default: break; } }