396 } |
396 } |
397 ucx_map_free(map1); |
397 ucx_map_free(map1); |
398 return equal; |
398 return equal; |
399 } |
399 } |
400 |
400 |
|
401 char* create_tags_hash(UcxList *tags) { |
|
402 if(!tags) { |
|
403 return NULL; |
|
404 } |
|
405 UcxBuffer *buf = create_text_taglist(tags); |
|
406 char *hash = dav_create_hash(buf->space, buf->size); |
|
407 ucx_buffer_free(buf); |
|
408 return hash; |
|
409 } |
|
410 |
|
411 UcxList* merge_tags(UcxList *tags1, UcxList *tags2) { |
|
412 // this map is used to check the existence of tags |
|
413 UcxMap *tag_map = ucx_map_new(32); |
|
414 // merged taglist |
|
415 UcxList *new_tags = NULL; |
|
416 |
|
417 // add all local tags |
|
418 UCX_FOREACH(elm, tags1) { |
|
419 DavTag *t = elm->data; |
|
420 ucx_map_cstr_put(tag_map, t->name, t); |
|
421 DavTag *newt = calloc(1, sizeof(DavTag)); |
|
422 newt->color = t->color ? strdup(t->color) : NULL; |
|
423 newt->name = strdup(t->name); |
|
424 new_tags = ucx_list_append(new_tags, newt); |
|
425 } |
|
426 // check if a remote tag is already in the map |
|
427 // and if not add it to the new taglist |
|
428 UCX_FOREACH(elm, tags2) { |
|
429 DavTag *t = elm->data; |
|
430 if(!ucx_map_cstr_get(tag_map, t->name)) { |
|
431 DavTag *newt = calloc(1, sizeof(DavTag)); |
|
432 newt->color = t->color ? strdup(t->color) : NULL; |
|
433 newt->name = strdup(t->name); |
|
434 new_tags = ucx_list_append(new_tags, newt); |
|
435 } |
|
436 } |
|
437 |
|
438 ucx_map_free(tag_map); |
|
439 |
|
440 return new_tags; |
|
441 } |
|
442 |
|
443 void add_tag_colors(UcxList *taglist, UcxList *colored) { |
|
444 UcxMap *tagmap = ucx_map_new(32); |
|
445 UCX_FOREACH(elm, taglist) { |
|
446 DavTag *tag = elm->data; |
|
447 ucx_map_cstr_put(tagmap, tag->name, tag); |
|
448 } |
|
449 |
|
450 UCX_FOREACH(elm, colored) { |
|
451 DavTag *colored_tag = elm->data; |
|
452 if(colored_tag->color) { |
|
453 DavTag *tag = ucx_map_cstr_get(tagmap, colored_tag->name); |
|
454 if(tag && !tag->color) { |
|
455 tag->color = strdup(colored_tag->color); |
|
456 } |
|
457 } |
|
458 } |
|
459 |
|
460 ucx_map_free(tagmap); |
|
461 } |
|
462 |
401 /* ----------- ----------- tag filter ---------------------- */ |
463 /* ----------- ----------- tag filter ---------------------- */ |
402 |
464 |
403 static size_t rtrimskip(scstr_t str, size_t skip) { |
465 static size_t rtrimskip(scstr_t str, size_t skip) { |
404 while (skip < str.length && isspace(str.ptr[skip])) skip++; |
466 while (skip < str.length && isspace(str.ptr[skip])) skip++; |
405 return skip; |
467 return skip; |