# HG changeset patch # User Olaf Wintermann # Date 1529221805 -7200 # Node ID 84e6c407b43176a52c89b0031748692a517f4355 # Parent 1429fb38551317c98b6238df77cffac09b7fee58 adds support for tag colors diff -r 1429fb385513 -r 84e6c407b431 dav/tags.c --- a/dav/tags.c Sun Jun 17 07:49:25 2018 +0200 +++ b/dav/tags.c Sun Jun 17 09:50:05 2018 +0200 @@ -69,8 +69,25 @@ sstr_t line = sstrtrim(sstrn((char*)buf + line_start, i - line_start)); if(line.length > 0) { DavTag *tag = calloc(1, sizeof(DavTag)); - tag->name = sstrdup(line).ptr; - tag->color = NULL; + sstr_t color = sstrchr(line, '#'); + if(color.length>0) { + sstr_t name = line; + name.length = (int)(color.ptr-line.ptr); + if(name.length != 0) { + tag->name = sstrdup(name).ptr; + color.ptr++; + color.length--; + if(color.length > 0) { + tag->color = sstrdup(color).ptr; + } + } else { + free(tag); + } + } else { + tag->name = sstrdup(line).ptr; + tag->color = NULL; + } + tags = ucx_list_append(tags, tag); } line_start = i+1; @@ -88,7 +105,11 @@ UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); UCX_FOREACH(elm, tags) { DavTag *tag = elm->data; - ucx_bprintf(buf, "%s\n", tag->name); + if(tag->color) { + ucx_bprintf(buf, "%s#%s\n", tag->name, tag->color); + } else { + ucx_bprintf(buf, "%s\n", tag->name); + } } return buf; } @@ -133,6 +154,7 @@ static DavTag* parse_xml_dav_tag(DavXmlNode *node) { char *name = NULL; + char *color = NULL; DavXmlNode *c = node->children; while(c) { @@ -146,7 +168,12 @@ name = value; } } - // TODO: color, ... + if(!strcmp(c->name, "color")) { + char *value = dav_xml_getstring(c->children); + if(value) { + color = value; + } + } } } } @@ -157,7 +184,7 @@ if(name) { tag = malloc(sizeof(DavTag)); tag->name = strdup(name); - tag->color = NULL; + tag->color = color ? strdup(color) : NULL; } return tag; } @@ -189,8 +216,11 @@ DavXmlNode *tagelm = dav_xml_createnode(DAV_NS, "tag"); DavXmlNode *tagname = dav_xml_createnode_with_text(DAV_NS, "name", tag->name); - // TODO: color tagelm->children = tagname; + if(tag->color) { + DavXmlNode *tagcolor = dav_xml_createnode_with_text(DAV_NS, "color", tag->color); + tagname->next = tagcolor; + } if(lasttag) { lasttag->next = tagelm;