dav/tags.c

changeset 525
26a1d5b9d9d2
parent 524
d53fd1006485
child 667
6cdcd3e4e368
--- a/dav/tags.c	Fri Mar 15 20:30:09 2019 +0100
+++ b/dav/tags.c	Sun Mar 17 15:00:48 2019 +0100
@@ -398,6 +398,68 @@
     return equal;
 }
 
+char* create_tags_hash(UcxList *tags) {
+    if(!tags) {
+        return NULL;
+    }
+    UcxBuffer *buf = create_text_taglist(tags);
+    char *hash = dav_create_hash(buf->space, buf->size);
+    ucx_buffer_free(buf);
+    return hash;
+}
+
+UcxList* merge_tags(UcxList *tags1, UcxList *tags2) {
+    // this map is used to check the existence of tags
+    UcxMap *tag_map = ucx_map_new(32);
+    // merged taglist
+    UcxList *new_tags = NULL;
+
+    // add all local tags
+    UCX_FOREACH(elm, tags1) {
+        DavTag *t = elm->data;
+        ucx_map_cstr_put(tag_map, t->name, t);
+        DavTag *newt = calloc(1, sizeof(DavTag));
+        newt->color = t->color ? strdup(t->color) : NULL;
+        newt->name = strdup(t->name);
+        new_tags = ucx_list_append(new_tags, newt);
+    }
+    // check if a remote tag is already in the map
+    // and if not add it to the new taglist
+    UCX_FOREACH(elm, tags2) {
+        DavTag *t = elm->data;
+        if(!ucx_map_cstr_get(tag_map, t->name)) {
+            DavTag *newt = calloc(1, sizeof(DavTag));
+            newt->color = t->color ? strdup(t->color) : NULL;
+            newt->name = strdup(t->name);
+            new_tags = ucx_list_append(new_tags, newt);
+        }
+    }
+
+    ucx_map_free(tag_map);
+
+    return new_tags;
+}
+
+void add_tag_colors(UcxList *taglist, UcxList *colored) {
+    UcxMap *tagmap = ucx_map_new(32);
+    UCX_FOREACH(elm, taglist) {
+        DavTag *tag = elm->data;
+        ucx_map_cstr_put(tagmap, tag->name, tag);
+    }
+    
+    UCX_FOREACH(elm, colored) {
+        DavTag *colored_tag = elm->data;
+        if(colored_tag->color) {
+            DavTag *tag = ucx_map_cstr_get(tagmap, colored_tag->name);
+            if(tag && !tag->color) {
+                tag->color = strdup(colored_tag->color);
+            }
+        }
+    }
+    
+    ucx_map_free(tagmap);
+}
+
 /* ----------- ----------- tag filter  ---------------------- */
 
 static size_t rtrimskip(scstr_t str, size_t skip) {

mercurial