]> uap-core.de Git - note.git/commitdiff
add sidebar UI
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Feb 2025 21:19:06 +0000 (22:19 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Feb 2025 21:19:06 +0000 (22:19 +0100)
12 files changed:
application/application.h
application/window.c
application/window.h
libidav/config.c
libidav/davqlexec.c
libidav/davqlparser.c
libidav/methods.c
libidav/pwdstore.c
libidav/resource.c
libidav/session.c
libidav/versioning.c
libidav/webdav.c

index 1859d7abf83ba71058bdf15ab2bab535e5bd8a98..601157a74917c537d6b60dbb81bc9f8d3374e8f2 100644 (file)
 extern "C" {
 #endif
 
+typedef struct MainWindow {
+    UiList *notebooks;
+    UiList *sources;
+} MainWindow;
+    
 void application_startup(UiEvent *event, void *data);
 
 
index aa3013fb06e5a330b45eb1bff3e19f4c805070ac..d44a15e1357dd0764aa32c5ce0faa511afb41cd9 100644 (file)
  */
 
 #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) {
+    
+}
index 23c212552d953eed59962edfcf58971b9d6fa89f..71594a40a951c802c148905f930bedd6c968c102 100644 (file)
@@ -30,6 +30,7 @@
 #define WINDOW_H
 
 #include <ui/ui.h>
+#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
 }
index 9cbb90247c20853a3789bbabed5a82150e5f8e63..7b0abbc62abb3564f073f50334ff4d17977d72d0 100644 (file)
@@ -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) {
index 6811dedd4948b4127196ed96f2392a36236e34ea..4af5816cabf4611eb552e44007b8edbfdc072b3d 100644 (file)
@@ -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;
 }
 
index c18ab979633f0bdbeb64e8a9ece748095eb4f18c..22fa594d98dc246823b7f6b2f4c9b514383b7831 100644 (file)
@@ -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);
 }
index 0a436c149aa3abf34f0b1ab4ace862d40dc54c0d..a4fe63d2285e036cbe3058de79b9e43e480f2d18 100644 (file)
@@ -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, "</D:prop>\n</D:%s>\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;
 }
index 466226b6bc14d71916454f9561e1275a177a1b1d..5832ddbd9041065f1e33457fd0f04f0bda163a04 100644 (file)
@@ -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);
index 305358fc2298bf64312d874c45c259e7b0ab1f26..7808bc37282c48539be98b5ea103524125bf4f92 100644 (file)
@@ -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, "</D:prop>");
     
-    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;
index 17806b383156bcefa71904948ead5da94a086bb9..13ec76d722dbc0116c2a687789f3c2bf72ce1d27 100644 (file)
@@ -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;
     }
 
index e0a4514d54a7bb9125ebdd191f4bf4ae57f9f045..2a7c6c22b58a940cf0c8932cde160f818fe70aac 100644 (file)
@@ -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) {
index bbc3ef2e1b05f0410a1fe4e4449ae9bbf3a3cf49..97affd78f04e3aa96ecf9b4252d48c5a18b67875 100644 (file)
@@ -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;