application/davcontroller.c

changeset 46
31bc86844659
parent 45
ab71409644b0
child 48
ae61523bce20
--- a/application/davcontroller.c	Sun Sep 29 20:25:41 2024 +0200
+++ b/application/davcontroller.c	Thu Oct 03 18:08:29 2024 +0200
@@ -952,7 +952,7 @@
 
 enum DavPathOpType {
     DAV_PATH_OP_DELETE = 0,
-    DAV_PATH_OP_MKCOL
+    DAV_PATH_OP_CREATE
 };
 
 typedef struct DavPathOp {
@@ -969,6 +969,8 @@
     size_t *list_indices;
     // number of path/list_indices elements
     size_t nelm;
+    // path is collection
+    DavBool iscollection;
 
     // browser->current ptr when the PathOp started
     // used in combination with collection_ctn to check if the browser list changed
@@ -981,6 +983,8 @@
     DavBrowser *browser;
     DavResource *collection;
     int64_t collection_ctn;
+    enum DavPathOpType op;
+    DavBool iscollection;
 
     char *path;
     int res_index;
@@ -1016,10 +1020,10 @@
     return 0;
 }
 
-static int uithr_pathop_mkcol_error(void *data) {
+static int uithr_pathop_create_resource_error(void *data) {
     DavPathOpResult *result = data;
 
-    cxmutstr msg = cx_asprintf("Cannot create collection %s", result->path);
+    cxmutstr msg = cx_asprintf("Cannot create %s %s", result->iscollection ? "collection" : "resource", result->path);
     ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
     free(msg.ptr);
 
@@ -1031,12 +1035,12 @@
     return 0;
 }
 
-static int uithr_pathop_mkcol_sucess(void *data) {
+static int uithr_pathop_create_resource_sucess(void *data) {
     DavPathOpResult *result = data;
 
     if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
         DavResource *res = dav_resource_new(result->browser->sn, result->path);
-        res->iscollection = TRUE;
+        res->iscollection = result->iscollection;
         // TODO: add the resource at the correct position or sort the list after append
         ui_list_append(result->browser->resources, res);
         result->browser->resources->update(result->browser->resources, 0);
@@ -1059,10 +1063,12 @@
             result->browser = op->browser;
             result->collection = op->collection;
             result->collection_ctn = op->collection_ctn;
+            result->op = op->op;
             result->path = strdup(res->path);
             result->result = 0;
             result->res_index = op->list_indices[i];
             result->errormsg = NULL;
+            result->iscollection = op->iscollection;
     
             if (op->op == DAV_PATH_OP_DELETE) {
                 ui_threadfunc result_callback = uithr_pathop_delete_sucess;
@@ -1071,15 +1077,15 @@
                     result_callback = uithr_pathop_delete_error;
                 }
                 ui_call_mainthread(result_callback, result);
-            } else if (op->op == DAV_PATH_OP_MKCOL) {
-                res->iscollection = TRUE;
-                ui_threadfunc result_callback = uithr_pathop_mkcol_sucess;
+            } else if (op->op == DAV_PATH_OP_CREATE) {
+                res->iscollection = op->iscollection;
+                ui_threadfunc result_callback = uithr_pathop_create_resource_sucess;
                 if (dav_create(res)) {
                     result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
-                    result_callback = uithr_pathop_mkcol_error;
+                    result_callback = uithr_pathop_create_resource_error;
                 }
                 ui_call_mainthread(result_callback, result);
-            }
+            } 
 
             dav_resource_free(res);
             free(op->path[i]);
@@ -1118,15 +1124,16 @@
     ui_job(ui, jobthr_path_op, op, NULL, NULL);
 }
 
-void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
+void davbrowser_create_resource(UiObject *ui, DavBrowser *browser, const char *name, DavBool iscollection) {
     DavPathOp *op = malloc(sizeof(DavPathOp));
     op->ui = ui;
     op->browser = browser;
-    op->op = DAV_PATH_OP_MKCOL;
+    op->op = DAV_PATH_OP_CREATE;
     op->sn = dav_session_clone(browser->sn);
     op->path = calloc(1, sizeof(char*));
     op->list_indices = calloc(1, sizeof(size_t));
     op->nelm = 1;
+    op->iscollection = iscollection;
 
     op->path[0] = util_concat_path(browser->current->path, name);
 
@@ -1135,3 +1142,11 @@
 
     ui_job(ui, jobthr_path_op, op, NULL, NULL);
 }
+
+void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
+    davbrowser_create_resource(ui, browser, name, TRUE);
+}
+
+void davbrowser_newfile(UiObject *ui, DavBrowser *browser, const char *name) {
+    davbrowser_create_resource(ui, browser, name, FALSE);
+}

mercurial