diff -r 8ccdde37275b -r 4e66271541e8 ui/common/types.c --- a/ui/common/types.c Thu May 15 17:17:58 2014 +0200 +++ b/ui/common/types.c Thu May 15 20:06:28 2014 +0200 @@ -28,9 +28,12 @@ #include #include +#include #include "../../ucx/list.h" +#include "../ui/tree.h" #include "types.h" +#include "context.h" UiObserver* ui_observer_new(ui_callback f, void *data) { UiObserver *observer = malloc(sizeof(UiObserver)); @@ -146,3 +149,53 @@ void ui_list_notify(UiList *list) { ui_notify(list->observers, list); } + + +typedef struct { + int type; + char *name; +} UiColumn; + +UiModelInfo* ui_model_info(UiContext *ctx, ...) { + UiModelInfo *info = ui_calloc(ctx, 1, sizeof(UiModelInfo)); + + va_list ap; + va_start(ap, ctx); + + UcxList *cols = NULL; + int type; + while((type = va_arg(ap, int)) != -1) { + char *name = va_arg(ap, char*); + + UiColumn *column = malloc(sizeof(UiColumn)); + column->type = type; + column->name = name; + + cols = ucx_list_append(cols, column); + } + + va_end(ap); + + size_t len = ucx_list_size(cols); + info->columns = len; + info->types = ui_calloc(ctx, len, sizeof(UiModelType)); + info->titles = ui_calloc(ctx, len, sizeof(char*)); + + int i = 0; + UCX_FOREACH(elm, cols) { + UiColumn *c = elm->data; + info->types[i] = c->type; + info->titles[i] = c->name; + free(c); + i++; + } + ucx_list_free(cols); + + return info; +} + +void ui_model_info_free(UiContext *ctx, UiModelInfo *mi) { + ucx_mempool_free(ctx->mempool, mi->types); + ucx_mempool_free(ctx->mempool, mi->titles); + ucx_mempool_free(ctx->mempool, mi); +}