From: Olaf Wintermann Date: Wed, 5 Feb 2025 21:19:06 +0000 (+0100) Subject: add sidebar UI X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=fdf5faac5012a80741df060c704dd373673ab01d;p=note.git add sidebar UI --- diff --git a/application/application.h b/application/application.h index 1859d7a..601157a 100644 --- a/application/application.h +++ b/application/application.h @@ -34,6 +34,11 @@ extern "C" { #endif +typedef struct MainWindow { + UiList *notebooks; + UiList *sources; +} MainWindow; + void application_startup(UiEvent *event, void *data); diff --git a/application/window.c b/application/window.c index aa3013f..d44a15e 100644 --- a/application/window.c +++ b/application/window.c @@ -27,15 +27,37 @@ */ #include "window.h" +#include "application.h" void window_create() { UiObject *obj = ui_sidebar_window("note", NULL); + MainWindow *wdata = window_init_data(obj); - UiSubList sublists[] = { NULL }; + UiSubList sublists[] = { + { .value = wdata->notebooks, .header = "Notebooks" }, + { .value = wdata->sources, .header = "Sources", .separator = TRUE } + }; ui_sidebar(obj) { - ui_sourcelist(obj, .sublists = sublists); + ui_sourcelist(obj, .sublists = sublists, .numsublists = 2, .getvalue = window_sidebar_getvalue, .fill = UI_ON); + ui_hbox(obj, .spacing = 2, .fill = UI_OFF) { + ui_button(obj, .icon = "folder-new-symbolic", .style_class = "flat"); + } } ui_show(obj); } + +MainWindow* window_init_data(UiObject *obj) { + MainWindow *wdata = ui_calloc(obj->ctx, 1, sizeof(MainWindow)); + obj->window = wdata; + + wdata->notebooks = ui_list_new(obj->ctx, "notebooks"); + wdata->sources = ui_list_new(obj->ctx, "source"); + + return wdata; +} + +void window_sidebar_getvalue(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item) { + +} diff --git a/application/window.h b/application/window.h index 23c2125..71594a4 100644 --- a/application/window.h +++ b/application/window.h @@ -30,6 +30,7 @@ #define WINDOW_H #include +#include "application.h" #ifdef __cplusplus extern "C" { @@ -37,6 +38,10 @@ extern "C" { void window_create(); +MainWindow* window_init_data(UiObject *obj); + +void window_sidebar_getvalue(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item); + #ifdef __cplusplus } diff --git a/libidav/config.c b/libidav/config.c index 9cbb902..7b0abbc 100644 --- a/libidav/config.c +++ b/libidav/config.c @@ -266,14 +266,14 @@ DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error) { if(ret != 0 && error) { *error = ret; - cxMempoolDestroy(cfg_mp); + cxMempoolFree(cfg_mp); } return config; } void dav_config_free(DavConfig *config) { - cxMempoolDestroy(config->mp); + cxMempoolFree(config->mp); } CxBuffer* dav_config2buf(DavConfig *config) { diff --git a/libidav/davqlexec.c b/libidav/davqlexec.c index 6811ded..4af5816 100644 --- a/libidav/davqlexec.c +++ b/libidav/davqlexec.c @@ -287,16 +287,16 @@ static CxBuffer* fieldlist2propfindrequest(DavSession *sn, const CxAllocator *a, CxIterator i = cxListIterator(fields); cx_foreach(DavQLField*, field, i) { if(!cx_strcmp(field->name, CX_STR("*"))) { - cxMapDestroy(properties); + cxMapFree(properties); *isallprop = 1; return create_allprop_propfind_request(); } else if(!cx_strcmp(field->name, CX_STR("-"))) { - cxMapDestroy(properties); + cxMapFree(properties); return create_propfind_request(sn, NULL, "propfind", 0); } else { if(fl_add_properties(sn, a, properties, field->expr)) { // TODO: set error - cxMapDestroy(properties); + cxMapFree(properties); return NULL; } } @@ -309,8 +309,8 @@ static CxBuffer* fieldlist2propfindrequest(DavSession *sn, const CxAllocator *a, } CxBuffer *reqbuf = create_propfind_request(sn, list, "propfind", 0); - cxListDestroy(list); - cxMapDestroy(properties); + cxListFree(list); + cxMapFree(properties); return reqbuf; } @@ -478,7 +478,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { int isallprop; CxBuffer *rqbuf = fieldlist2propfindrequest(sn, mp->allocator, st->fields, &isallprop); if(!rqbuf) { - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } cxMempoolRegister(mp, rqbuf, (cx_destructor_func)cxBufferFree); @@ -527,7 +527,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { cxmutstr path = dav_format_string(mp->allocator, st->path, args, &error); if(error) { // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } @@ -537,7 +537,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { CxBuffer *where = dav_compile_expr(sn->context, mp->allocator, st->where, args); if(st->where && !where) { // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } @@ -571,7 +571,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { } else { // error // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } } else if(dav_identifier2resprop(column->srctext, &resprop)) { @@ -583,7 +583,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { } else { // error // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } @@ -594,7 +594,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { } else { // something is broken // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } } @@ -613,7 +613,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, mp->allocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); if(!rpbuf) { // TODO: cleanup - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } @@ -686,7 +686,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { result.result = NULL; result.status = -1; dav_resource_free_all(selroot); - cxListDestroy(stack); + cxListFree(stack); break; } } else { @@ -732,7 +732,7 @@ DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) { cxBufferSeek(rpbuf, SEEK_SET, 0); } - cxMempoolDestroy(mp); + cxMempoolFree(mp); return result; } diff --git a/libidav/davqlparser.c b/libidav/davqlparser.c index c18ab97..22fa594 100644 --- a/libidav/davqlparser.c +++ b/libidav/davqlparser.c @@ -1839,7 +1839,7 @@ DavQLStatement* dav_parse_statement(cxstring srctext) { void dav_free_statement(DavQLStatement *stmt) { if(stmt->fields) { cxDefineDestructor(stmt->fields, dav_free_field); - cxListDestroy(stmt->fields); + cxListFree(stmt->fields); } if (stmt->where) { @@ -1851,10 +1851,10 @@ void dav_free_statement(DavQLStatement *stmt) { if(stmt->orderby) { cxDefineDestructor(stmt->orderby, dav_free_order_criterion); - cxListDestroy(stmt->orderby); + cxListFree(stmt->orderby); } if(stmt->args) { - cxListDestroy(stmt->args); + cxListFree(stmt->args); } free(stmt); } diff --git a/libidav/methods.c b/libidav/methods.c index 0a436c1..a4fe63d 100644 --- a/libidav/methods.c +++ b/libidav/methods.c @@ -117,7 +117,7 @@ CURLcode do_propfind_request( // deactivate header capturing and free captured map util_capture_header(handle, NULL); - cxMapDestroy(respheaders); + cxMapFree(respheaders); return ret; } @@ -271,7 +271,7 @@ CxBuffer* create_propfind_request(DavSession *sn, CxList *properties, char *root // end cx_bprintf(buf, "\n\n", rootelm); - cxMapDestroy(namespaces); + cxMapFree(namespaces); return buf; } @@ -445,7 +445,7 @@ int get_propfind_response(PropfindParser *parser, ResponseTag *result) { void cleanup_response(ResponseTag *result) { if(result) { - cxListDestroy(result->properties); + cxListFree(result->properties); } } @@ -733,7 +733,7 @@ int parse_response_tag(DavResource *resource, xmlNode *node) { } } } - cxListDestroy(properties); + cxListFree(properties); if(crypto_prop && crypto_key) { char *crypto_prop_content = util_xml_get_text(crypto_prop); @@ -949,7 +949,7 @@ CxBuffer* create_proppatch_request(DavResourceData *data) { cxBufferWrite(s.ptr, 1, s.length, buf); // cleanup namespace map - cxMapDestroy(namespaces); + cxMapFree(namespaces); return buf; } diff --git a/libidav/pwdstore.c b/libidav/pwdstore.c index 466226b..5832ddb 100644 --- a/libidav/pwdstore.c +++ b/libidav/pwdstore.c @@ -224,11 +224,11 @@ static int read_indexentry(PwdStore *p, CxBuffer *in) { if(ret) { pwdstore_put_index(p, id, locations); if(cxListSize(locations) == 0) { - cxListDestroy(locations); + cxListFree(locations); } } else { if(id) free(id); - cxListDestroy(locations); + cxListFree(locations); } return ret; @@ -285,12 +285,14 @@ void pwdstore_remove_entry(PwdStore *s, const char *id) { remove_list_entries(s, id); CxHashKey key = cx_hash_key_str(id); - PwdIndexEntry *i = cxMapRemoveAndGet(s->index, key); - PwdEntry *e = cxMapRemoveAndGet(s->ids, key); + PwdIndexEntry *i = NULL; + cxMapRemoveAndGet(s->index, key, &i); + PwdEntry *e = NULL; + cxMapRemoveAndGet(s->ids, key, &e); if(i) { if(i->locations) { - cxListDestroy(i->locations); + cxListFree(i->locations); } free(i->id); free(i); @@ -396,9 +398,9 @@ void pwdstore_free_entry(PwdEntry *e) { void pwdstore_free(PwdStore* p) { cxDefineDestructor(p->ids, pwdstore_free_entry); - cxMapDestroy(p->ids); + cxMapFree(p->ids); - cxListDestroy(p->locations); + cxListFree(p->locations); if(p->content) { cxBufferFree(p->content); diff --git a/libidav/resource.c b/libidav/resource.c index 305358f..7808bc3 100644 --- a/libidav/resource.c +++ b/libidav/resource.c @@ -131,7 +131,7 @@ void resource_free_properties(DavSession *sn, CxMap *properties) { // TODO: free everything dav_session_free(sn, property); } - cxMapDestroy(properties); + cxMapFree(properties); } void dav_resource_free(DavResource *res) { @@ -807,7 +807,7 @@ int dav_load_prop(DavResource *res, DavPropName *properties, size_t numprop) { CxBuffer *rqbuf = create_propfind_request(res->session, proplist, "propfind", 0); int ret = dav_propfind(res->session, res, rqbuf); cxBufferFree(rqbuf); - cxMempoolDestroy(mp); + cxMempoolFree(mp); return ret; } @@ -1016,7 +1016,8 @@ int dav_store(DavResource *res) { cx_foreach(DavProperty *, property, i) { cxmutstr keystr = dav_property_key(property->ns->name, property->name); CxHashKey key = cx_hash_key(keystr.ptr, keystr.length); - DavProperty *existing_prop = cxMapRemoveAndGet(crypto_props, key); + DavProperty *existing_prop = NULL; + cxMapRemoveAndGet(crypto_props, key, &existing_prop); cxMapPut(crypto_props, key, property); if(existing_prop) { // TODO: free existing_prop @@ -1534,7 +1535,7 @@ DavXmlNode* create_crypto_prop(DavSession *sn, CxMap *properties) { cxBufferPutString(content, ""); - cxMapDestroy(nsmap); + cxMapFree(nsmap); // encrypt xml document char *crypto_prop_content = aes_encrypt(content->space, content->size, sn->key); @@ -1607,7 +1608,7 @@ CxMap* parse_crypto_prop_str(DavSession *sn, DavKey *key, const char *content) { xmlFreeDoc(doc); if(cxMapSize(map) == 0) { - cxMapDestroy(map); + cxMapFree(map); return NULL; } return map; diff --git a/libidav/session.c b/libidav/session.c index 17806b3..13ec76d 100644 --- a/libidav/session.c +++ b/libidav/session.c @@ -211,7 +211,21 @@ CURLcode dav_session_curl_perform_buf(DavSession *sn, CxBuffer *request, CxBuffe char *log_method; char *log_url; curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &log_url); +#if LIBCURL_VERSION_NUM >= 0x074800 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_METHOD , &log_method); +#else + long opt_upload = 0; + curl_easy_getinfo(sn->handle, CURLOPT_UPLOAD, &opt_upload); + char *opt_custom = NULL; + curl_easy_getinfo(sn->handle, CURLOPT_CUSTOMREQUEST, &opt_custom); + if(opt_custom) { + log_method = opt_custom; + } else if(opt_upload) { + log_method = "PUT"; + } else { + log_method = "GET"; + } +#endif char *log_reqbody = NULL; size_t log_reqbodylen = 0; char *log_rpbody = NULL; @@ -337,7 +351,7 @@ void dav_session_destroy(DavSession *sn) { } void dav_session_destructor(DavSession *sn) { - cxMempoolDestroy(sn->mp); + cxMempoolFree(sn->mp); curl_easy_cleanup(sn->handle); free(sn); } @@ -632,7 +646,7 @@ void dav_remove_lock(DavSession *sn, const char *path, DavLock *lock) { return; } - if(cxMapRemoveAndGet(locks->resource_locks, cx_hash_key_str(path))) { + if(!cxMapRemove(locks->resource_locks, cx_hash_key_str(path))) { return; } diff --git a/libidav/versioning.c b/libidav/versioning.c index e0a4514..2a7c6c2 100644 --- a/libidav/versioning.c +++ b/libidav/versioning.c @@ -158,7 +158,7 @@ DavResource* dav_versiontree(DavResource *res, char *properties) { cx_foreach(DavProperty*, p, i) { free(p->name); } - cxListDestroy(proplist); + cxListFree(proplist); } if(error && versions) { diff --git a/libidav/webdav.c b/libidav/webdav.c index bbc3ef2..97affd7 100644 --- a/libidav/webdav.c +++ b/libidav/webdav.c @@ -102,7 +102,7 @@ DavContext* dav_context_new(void) { void dav_context_destroy(DavContext *ctx) { // destroy all sessions assoziated with this context // ctx->sessions destructor must be dav_session_destructor - cxListDestroy(ctx->sessions); + cxListFree(ctx->sessions); if(ctx->http_proxy) { free(ctx->http_proxy); @@ -123,7 +123,7 @@ void dav_context_destroy(DavContext *ctx) { } free(ns); } - cxMapDestroy(ctx->namespaces); + cxMapFree(ctx->namespaces); } if(ctx->namespaceinfo) { // TODO: implement @@ -140,7 +140,7 @@ void dav_context_destroy(DavContext *ctx) { } free(key); } - cxMapDestroy(ctx->keys); + cxMapFree(ctx->keys); } free(ctx); @@ -418,7 +418,7 @@ DavResource* dav_get(DavSession *sn, char *path, const char *properties) { cx_foreach(DavProperty*, p, i) { free(p->name); } - cxListDestroy(proplist); + cxListFree(proplist); } return resource;