extern tcconf_section_t * tcconf_new(char *name) { tcconf_section_t *ts = tcallocdz(sizeof(*ts), NULL, tcconf_free); ts->sec = conf_new(name); return ts; }
static xtk_widget_t* create_skinned_box(xtk_widget_t *c, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { int x, y, width, height; widget_data_t *wd; int i=0; i += tcconf_getvalue(sec, "position", "%d %d", &x, &y); i += tcconf_getvalue(sec, "size", "%d %d", &width, &height); if(i != 4){ return NULL; } xtk_widget_t *w = xtk_widget_container_create(c, x, y, width, height); wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); wd->skin = tcref(skin); xtk_widget_container_set_data(w, wd); w->on_destroy = destroy_skinned_box; create_ui(w, skin, sec, parameters); return w; }
extern void * alloc_event(int type, int size, tcfree_fn ff) { tcvp_event_t *te; te = tcallocdz(size, NULL, ff); te->type = type; return te; }
extern conf_section * conf_new(char *name) { conf_section *sec; sec = tcallocdz(sizeof(*sec), NULL, conf_free); sec->name = name? strdup(name): NULL; sec->entries = tclist_new(TC_LOCK_SLOPPY); sec->merge = tclist_new(TC_LOCK_SLOPPY); return sec; }
/* Load a configuration file */ extern tcconf_section_t * tcconf_load(tcconf_section_t *ts, void *data, tcio_fn rfn) { conf_section *sec = ts? ts->sec: NULL; pthread_mutex_lock(&flex_mut); sec = tcc_lex(data, rfn, sec); pthread_mutex_unlock(&flex_mut); if(!ts && sec) ts = tcallocdz(sizeof(*ts), NULL, tcconf_free); if(ts && sec) ts->sec = sec; return sec? ts: NULL; }
extern tcmempool_t * tcmempool_new(size_t size, int lock) { tcmempool_t *mp; if(!pagesize) pagesize = sysconf(_SC_PAGESIZE); size = align(size, sizeof(void *)); if(size > pagesize - offsetof(tcmempool_page_t, data)) return NULL; mp = tcallocdz(sizeof(*mp), NULL, mp_free); mp->size = size; mp->cpp = (pagesize - offsetof(tcmempool_page_t, data)) / size; mp->locking = lock; pthread_mutex_init(&mp->lock, NULL); return mp; }
avf_free_packet(void *v) { avf_packet_t *ap = v; av_free_packet(&ap->apk); free(ap->data); } extern tcvp_packet_t * avf_next_packet(muxed_stream_t *ms, int stream) { avf_stream_t *as = ms->private; AVFormatContext *afc = as->afc; avf_packet_t *pk; int sx; pk = tcallocdz(sizeof(*pk), NULL, avf_free_packet); av_init_packet(&pk->apk); do { int rp; #if LIBAVFORMAT_BUILD < 4610 rp = av_read_packet(afc, &pk->apk); #else rp = av_read_frame(afc, &pk->apk); #endif if(rp < 0){ tcfree(pk); return NULL; } sx = pk->apk.stream_index;
extern void * tcallocz(size_t size) { return tcallocdz(size, NULL, NULL); }
static xtk_widget_t* create_skinned_state(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { int x, y; int ns = 0; image_t **imgs = NULL; char **states = NULL; void *c = NULL; int i; char *img, *st, def_state[512], *bg = NULL; widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); xtk_widget_t *s = NULL; i = tcconf_getvalue(sec, "position", "%d %d", &x, &y); i += tcconf_getvalue(sec, "value", "%s", &wd->value); if (i != 3) { return NULL; } while(i = tcconf_nextvalue(sec, "image", &c, "%s %s", &st, &img), c) { if(i == 2) { imgs = realloc(imgs, sizeof(*imgs)*(ns+1)); states = realloc(states, sizeof(*states)*(ns+1)); imgs[ns] = load_image(skin->path, img); states[ns] = st; ns++; free(img); } } tcconf_getvalue(sec, "action", "%s", &wd->action); wd->skin = tcref(skin); parse_text(wd->value, def_state, 512); if(ns > 0) { s = xtk_widget_state_create(win, x, y, imgs[0]->params.width[0], imgs[0]->params.height[0]); for(i=0; i<ns; i++) { xtk_widget_state_add_state(s, states[i], imgs[i]); tcfree(imgs[i]); } xtk_widget_state_set_state(s, def_state); xtk_widget_state_set_data(s, wd); xtk_widget_state_set_action(s, lookup_action); register_textwidget((xtk_widget_t *)s, wd->value); s->on_destroy = destroy_skinned_state; } free(bg); if(imgs) free(imgs); if(states){ for(i = 0; i < ns; i++) free(states[i]); free(states); } return s; }
static xtk_widget_t* create_skinned_list(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { int x, y; int width, height; int i=0; char *action = NULL; widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); xtk_widget_t *l; int disable = 0; int alpha = 0xff, calpha = 0xff; char *font, *color, *ccolor = NULL; tcconf_section_t *bfnt = NULL; tcconf_section_t *fig = NULL; int rows, spacing; int xs, ys; i += tcconf_getvalue(sec, "position", "%d %d", &x, &y); i += tcconf_getvalue(sec, "size", "%d %d", &width, &height); if((bfnt = tcconf_getsection(sec, "bitmap"))){ tcconf_setvalue(bfnt, "path", "%s", skin->path); i++; } else if(tcconf_getvalue(sec, "font", "%s", &font) == 1){ i++; } i += tcconf_getvalue(sec, "color", "%s %d", &color, &alpha) > 0; i += tcconf_getvalue(sec, "spacing", "%d", &spacing); i += tcconf_getvalue(sec, "rows", "%d", &rows); if(i != 8){ return NULL; } tcconf_getvalue(sec, "current-color", "%s %d", &ccolor, &calpha); fig = tcconf_getsection(sec, "background_figure"); tcconf_getvalue(sec, "action", "%s", &action); wd->action = action; wd->skin = tcref(skin); wd->values = calloc(1, sizeof(char *)); l = xtk_widget_list_create(win, x, y, width, height); if(tcconf_getvalue(sec, "scroll", "%d %d", &xs, &ys) == 2) { xtk_widget_list_set_scroll(l, xs, ys); } if(fig != NULL) { tcconf_setvalue(fig, "position", "%d %d", 0, 0); tcconf_setvalue(fig, "size", "%d %d", width, height); image_t *img = draw_figure(fig); xtk_widget_list_set_image(l, img); tcfree(img); tcfree(fig); } xtk_widget_list_set_data(l, wd); xtk_widget_list_set_action(l, lookup_action); if(l) { void *c = NULL; char *value, *variable; if(bfnt){ xtk_widget_list_set_bitmapfont(l, bfnt); tcfree(bfnt); } else { xtk_widget_list_set_font(l, font); free(font); } xtk_widget_list_set_color(l, color, alpha); free(color); if(ccolor) { xtk_widget_list_set_current_color(l, ccolor, calpha); free(ccolor); } xtk_widget_list_set_spacing(l, spacing); xtk_widget_list_set_rows(l, rows); while(i = tcconf_nextvalue(sec, "value", &c, "%s %s", &variable, &value), c) { if(i == 2) { if(strcmp(variable, "current_position") == 0) { int *val = NULL, *def = NULL; int p; save_varcb(l, list_set_current, "integer", value); register_varwidget(l, list_set_current, "integer", value); parse_variable("integer", value, (void *)&val, (void *)&def); if(!val) { if(def) { p = *def; tcfree(def); } val = &p; } list_set_current(l, val); } else if(strcmp(variable, "number_of_entries") == 0) { int *val = NULL, *def = NULL; int p; save_varcb(l, list_set_number_of_entries, "integer", value); register_varwidget(l, list_set_number_of_entries, "integer", value); parse_variable("integer", value, (void *)&val, (void *)&def); if(!val) { if(def) { p = *def; tcfree(def); } val = &p; } list_set_number_of_entries(l, val); } else if(strcmp(variable, "entries") == 0) { void *val = NULL; save_varcb(l, list_set_entries, "string_array", value); register_varwidget(l, list_set_entries, "string_array", value); parse_variable("string_array", value, &val, NULL); if(val) { list_set_entries(l, val); tcfree(val); } } free(value); free(variable); } } l->on_destroy = destroy_skinned_list; if(disable) xtk_widget_disable(l); } return l; }
static xtk_widget_t* create_skinned_seek_bar(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { int x, y; int sp_x, sp_y; int ep_x, ep_y; int xd=0, yd=0, sx=0, sy=0; char *bg, *indicator, *value, *variable, *ind_over = NULL, *ind_down = NULL; int i=0; char *action = NULL; widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); double *position = NULL, *def = NULL, p=0, snap; xtk_widget_t *s; int disable = 0; image_t *img; i += tcconf_getvalue(sec, "position", "%d %d", &x, &y); i += tcconf_getvalue(sec, "start_position", "%d %d", &sp_x, &sp_y); i += tcconf_getvalue(sec, "end_position", "%d %d", &ep_x, &ep_y); i += tcconf_getvalue(sec, "background", "%s", &bg); i += tcconf_getvalue(sec, "indicator", "%s", &indicator); i += tcconf_getvalue(sec, "value", "%s %s", &variable, &value); if(i != 10){ return NULL; } tcconf_getvalue(sec, "action", "%s", &action); tcconf_getvalue(sec, "mouse_over", "%s", &ind_over); tcconf_getvalue(sec, "pressed", "%s", &ind_down); tcconf_getvalue(sec, "scroll_direction", "%d %d %d %d", &xd, &yd, &sx, &sy); parse_variable("double", value, (void *)&position, (void *)&def); if(!position) { if(def) { p = *def; tcfree(def); } position = &p; } else if(*position < 0 || *position > 1) { disable = 1; } wd->action = action; wd->value = value; wd->skin = tcref(skin); img = load_image(skin->path, bg); s = xtk_widget_slider_create(win, x, y, img->params.width[0], img->params.height[0]); xtk_widget_slider_set_image(s, img); tcfree(img); xtk_widget_slider_set_data(s, wd); xtk_widget_slider_set_action(s, lookup_action); xtk_widget_slider_set_position(s, *position); xtk_widget_slider_set_bounds(s, sp_x, sp_y, ep_x, ep_y); xtk_widget_slider_set_scroll_direction(s, xd, yd, sx, sy); if(tcconf_getvalue(sec, "snap", "%lf", &snap) == 1) { xtk_widget_slider_set_snap(s, snap); } img = load_image(skin->path, indicator); xtk_widget_slider_set_indicator_image(s, img); tcfree(img); img = load_image(skin->path, ind_over); xtk_widget_slider_set_indicator_image_hover(s, img); if(img) tcfree(img); img = load_image(skin->path, ind_down); xtk_widget_slider_set_indicator_image_pressed(s, img); if(img) tcfree(img); if(s) { if(strcmp(variable, "position") == 0) { register_varwidget((xtk_widget_t *)s, seek_bar_update, "double", wd->value); } free(variable); s->on_destroy = destroy_skinned_seek_bar; if(disable) xtk_widget_disable(s); } free(ind_over); free(ind_down); free(indicator); free(bg); return s; }
static xtk_widget_t* create_skinned_label(xtk_widget_t *win, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { int x, y; int width, height; int xoff = 0, yoff = 0; char *font; char *color, *align_s, *stype_s; int alpha = 0xff; int stype, align; int i = 0; char *action = NULL, *bg = NULL, *text, *default_text; widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); xtk_widget_t *l, *w; tcconf_section_t *bfnt = NULL; image_t *bg_img; i += tcconf_getvalue(sec, "position", "%d %d", &x, &y); i += tcconf_getvalue(sec, "size", "%d %d", &width, &height); i += tcconf_getvalue(sec, "text", "%s", &text); if((bfnt = tcconf_getsection(sec, "bitmap"))){ tcconf_setvalue(bfnt, "path", "%s", skin->path); i++; } else if(tcconf_getvalue(sec, "font", "%s", &font) == 1){ i++; } i += tcconf_getvalue(sec, "color", "%s %d", &color, &alpha) > 0; if(tcconf_getvalue(sec, "scroll_style", "%s", &stype_s) < 1) stype_s = strdup("none"); if(tcconf_getvalue(sec, "align", "%s", &align_s) < 1) align_s = strdup("left"); if(strcasecmp(align_s, "left") == 0) { align = XTKLABELLEFT; } else if(strcasecmp(align_s, "right") == 0) { align = XTKLABELRIGHT; } else { align = XTKLABELCENTER; } free(align_s); if(strcasecmp(stype_s, "scroll") == 0) { stype = XTKLABELSCROLL; } else if(strcasecmp(stype_s, "pingpong") == 0) { stype = XTKLABELPINGPONG; } else { stype = 0; } free(stype_s); if(i != 7) return NULL; tcconf_getvalue(sec, "text_offset", "%d %d", &xoff, &yoff); tcconf_getvalue(sec, "action", "%s", &action); tcconf_getvalue(sec, "background", "%s", &bg); default_text = malloc(1024); parse_text(text, default_text, 1024); wd->action = action; wd->value = text; wd->skin = tcref(skin); l = xtk_widget_label_create(win, x, y, width, height); if(bfnt){ xtk_widget_label_set_bitmapfont(l, bfnt); tcfree(bfnt); } else { xtk_widget_label_set_font(l, font); free(font); } xtk_widget_label_set_offset(l, xoff, yoff); xtk_widget_label_set_color(l, color, alpha); xtk_widget_label_set_text(l, default_text); xtk_widget_label_set_data(l, wd); xtk_widget_label_set_action(l, lookup_action); xtk_widget_label_set_align(l, align); xtk_widget_label_set_scroll(l, stype); bg_img = load_image(skin->path, bg); w = xtk_widget_image_create(win, x, y, width, height); xtk_widget_image_set_image(w, bg_img); tcfree(bg_img); xtk_widget_show(w); register_textwidget(l, text); l->on_destroy = destroy_skinned_label; free(default_text); if(color) free(color); free(bg); return l; }
static xtk_widget_t* create_skinned_button(xtk_widget_t *c, skin_t *skin, tcconf_section_t *sec, tchash_table_t *parameters) { char *file = NULL, *of = NULL, *df = NULL, *bg = NULL; int x, y; int i=0; widget_data_t *wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); xtk_widget_t *bt; image_t *img; int shaped = 0; i += tcconf_getvalue(sec, "action", "%s", &wd->action); i += tcconf_getvalue(sec, "image", "%s", &file); i += tcconf_getvalue(sec, "position", "%d %d", &x, &y); if(i != 4){ return NULL; } tcconf_getvalue(sec, "shaped", "%d", &shaped); tcconf_getvalue(sec, "mouse_over", "%s", &of); tcconf_getvalue(sec, "pressed", "%s", &df); wd->skin = tcref(skin); /* tcconf_getvalue(sec, "background", "%s", &bg); */ if(!(img = load_image(skin->path, file))) return NULL; bt = xtk_widget_button_create(c, x, y, img->params.width[0], img->params.height[0]); xtk_widget_button_set_image(bt, img); if(shaped) xtk_widget_button_set_shape(bt, img); tcfree(img); if((img = load_image(skin->path, of))){ xtk_widget_button_set_hover_image(bt, img); if(shaped) xtk_widget_button_set_hover_shape(bt, img); tcfree(img); } if((img = load_image(skin->path, df))){ xtk_widget_button_set_pressed_image(bt, img); if(shaped) xtk_widget_button_set_pressed_shape(bt, img); tcfree(img); } xtk_widget_button_set_data(bt, wd); xtk_widget_button_set_action(bt, lookup_action); bt->on_destroy = destroy_skinned_button; free(file); free(of); free(df); free(bg); return bt; }
extern skin_t* load_skin(char *skinconf) { char *tmp; skin_t *skin = tcallocdz(sizeof(*skin), NULL, free_skin); int i=0; char *conf_tmp = NULL; struct stat stat_foo; int s = -1; if(skinconf[0] == '/' || stat(skinconf, &stat_foo) == 0) { conf_tmp = strdup(skinconf); s = stat(conf_tmp, &stat_foo); } else if (tcvp_ui_tcvpx_conf_skinpath_count > 0){ int i; for(i=0; i<tcvp_ui_tcvpx_conf_skinpath_count && conf_tmp == NULL; i++){ conf_tmp = malloc(strlen(tcvp_ui_tcvpx_conf_skinpath[i]) + strlen(skinconf) + 2); sprintf(conf_tmp, "%s/%s", tcvp_ui_tcvpx_conf_skinpath[i], skinconf); if((s = stat(conf_tmp, &stat_foo)) != 0) { free(conf_tmp); conf_tmp = NULL; } } } if(conf_tmp == NULL) { conf_tmp = malloc(strlen(getenv("HOME"))+strlen(skinconf)+15); sprintf(conf_tmp, "%s/.tcvp/skins/%s", getenv("HOME"), skinconf); if((s = stat(conf_tmp, &stat_foo)) != 0) { free(conf_tmp); conf_tmp = malloc(strlen(TCVP_SKINS)+strlen(skinconf)+2); sprintf(conf_tmp, "%s/%s", TCVP_SKINS, skinconf); s = stat(conf_tmp, &stat_foo); } } if(S_ISDIR(stat_foo.st_mode)) { tmp = conf_tmp; conf_tmp = malloc(strlen(tmp) + 11); sprintf(conf_tmp, "%s/skin.conf", tmp); free(tmp); } tc2_print("TCVPX", TC2_PRINT_DEBUG+4, "Using skin: \"%s\"\n", conf_tmp); if(!(skin->config = tcconf_load_file (NULL, conf_tmp))){ tc2_print("TCVPX", TC2_PRINT_ERROR, "Error loading file \"%s\".\n", conf_tmp); free(conf_tmp); return NULL; } skin->file = conf_tmp; skin->path = strdup(conf_tmp); tmp = strrchr(skin->path, '/'); if(!tmp){ strcpy(skin->path, "."); } else { *tmp = 0; } tcconf_getvalue(skin->config, "doubleclick_action", "%s", &skin->dblclick); /* if(tcconf_getvalue(skin->config, "name", "%s", &tmp) == 1) */ /* printf("Loaded skin: \"%s\"\n", tmp); */ i = tcconf_getvalue(skin->config, "size", "%d %d", &skin->width, &skin->height); if(i != 2) { tcfree(skin); return NULL; } skin->id_hash = tchash_new(10, 0, 0); return skin; }
extern skin_t* tcvp_open_ui(xtk_widget_t *w, void *p) { char *buf; widget_data_t *wd; widget_data_t *owd = xtk_widget_get_data(w); char *uifile = owd->action_data; skin_t *s = owd->skin; buf = malloc(strlen(uifile) + strlen(s->path) + 2); sprintf(buf, "%s/%s", s->path, uifile); skin_t *skin = load_skin(buf); if(!skin) { return NULL; } skin->window = xtk_window_create(NULL, 0, 0, skin->width, skin->height); xtk_window_set_dnd_callback(skin->window, tcvp_add_file); xtk_window_set_class(skin->window, "TCVP"); if(create_ui(skin->window, skin, skin->config, NULL) != 0){ tc2_print("TCVPX", TC2_PRINT_ERROR, "Unable to load skin: \"%s\"\n", buf); return NULL; } free(buf); wd = tcallocdz(sizeof(*wd), NULL, widgetdata_free); wd->action = skin->dblclick; wd->skin = tcref(skin); xtk_widget_container_set_data(skin->window, wd); xtk_window_set_doubleclick_callback(skin->window, lookup_action); xtk_window_set_sticky_callback(skin->window, sticky_cb); xtk_window_set_on_top_callback(skin->window, on_top_cb); char *default_text = malloc(1024); tcconf_getvalue(skin->config, "title", "%s", &wd->value); if(wd->value == NULL) { wd->value = strdup(tcvp_ui_tcvpx_conf_window_title); } register_textwidget(skin->window, wd->value); parse_text(wd->value, default_text, 1024); xtk_window_set_title(skin->window, default_text); free(default_text); xtk_window_show(skin->window); if((s->state & ST_STICKY) != 0) { xtk_window_set_sticky(skin->window, 1); skin->state |= ST_STICKY; } if((s->state & ST_ON_TOP) != 0) { xtk_window_set_always_on_top(skin->window, 1); skin->state |= ST_ON_TOP; } tcconf_getvalue(skin->config, "id", "%s", &skin->id); skin->skin_hash = s->skin_hash; if(skin->id != NULL) { tchash_search(skin->skin_hash, skin->id, -1, skin, NULL); } ui_count++; return skin; }
static conf_section * getsection(tcconf_section_t **ts, conf_section *sec, char *name) { tcconf_section_t *path = NULL; char *tmp = strdup(name); char *tn = tmp; char *s; if(ts) path = *ts; /* fprintf(stderr, "enter getsection\n"); */ /* fprintf(stderr, "finding '%s' in ", name); */ /* if(path) */ /* tcconf_dumppath(path); */ /* else */ /* fprintf(stderr, "%s\n", sec->name); */ while((s = strsep(&tmp, "/")) != NULL){ if(*s == 0) continue; if(!strcmp(s, "..")){ if(path && path->parent){ tcconf_section_t *p = path; path = tcref(path->parent); sec = path->sec; tcfree(p); } else if(sec->parent){ sec = sec->parent; } } else { tcconf_section_t *np; tcc_entry *te; if(tclist_find(sec->entries, s, &te, cmp_str_sec)){ tclist_t *mlist = sec->merge; tclist_item_t *li = NULL; char *m; sec = NULL; while((m = tclist_prev(mlist, &li))){ conf_section *ps, *ms; if(path) ps = path->parent? path->parent->sec: path->sec; else ps = sec->parent? sec->parent: sec; ms = getsection(NULL, ps, m); if(ms && (sec = getsection(NULL, ms, s))) break; } if(li) tclist_unlock(sec->merge, li); } else { sec = te->section; } if(!sec) break; if(path){ np = tcallocdz(sizeof(*np), NULL, tcconf_free); np->sec = tcref(sec); np->parent = path; path = np; } } /* tcconf_dumppath(path); */ } if(ts) *ts = path; /* fprintf(stderr, "leave getsection\n"); */ free(tn); return sec; }