application/davcontroller.c

changeset 28
1ecc1183f046
parent 27
c254ed644edf
child 29
3fc287f06305
equal deleted inserted replaced
27:c254ed644edf 28:1ecc1183f046
732 free(result->path); 732 free(result->path);
733 free(result); 733 free(result);
734 return 0; 734 return 0;
735 } 735 }
736 736
737 static int uithr_pathop_mkcol_error(void *data) {
738 DavPathOpResult *result = data;
739
740 cxmutstr msg = cx_asprintf("Cannot create collection %s", result->path);
741 ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
742 free(msg.ptr);
743
744 if (result->errormsg) {
745 free(result->errormsg);
746 }
747 free(result->path);
748 free(result);
749 return 0;
750 }
751
752 static int uithr_pathop_mkcol_sucess(void *data) {
753 DavPathOpResult *result = data;
754
755 if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
756 DavResource *res = dav_resource_new(result->browser->sn, result->path);
757 res->iscollection = TRUE;
758 // TODO: add the resource at the correct position or sort the list after append
759 ui_list_append(result->browser->resources, res);
760 result->browser->resources->update(result->browser->resources, 0);
761 }
762
763 free(result->path);
764 free(result);
765 return 0;
766 }
767
737 static int jobthr_path_op(void *data) { 768 static int jobthr_path_op(void *data) {
738 DavPathOp *op = data; 769 DavPathOp *op = data;
739
740 770
741 for (int i = op->nelm-1; i >= 0; i--) { 771 for (int i = op->nelm-1; i >= 0; i--) {
742 if (op->path[i]) { 772 if (op->path[i]) {
743 DavResource *res = dav_resource_new(op->sn, op->path[i]); 773 DavResource *res = dav_resource_new(op->sn, op->path[i]);
744 774
757 if (dav_delete(res)) { 787 if (dav_delete(res)) {
758 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL; 788 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
759 result_callback = uithr_pathop_delete_error; 789 result_callback = uithr_pathop_delete_error;
760 } 790 }
761 ui_call_mainthread(result_callback, result); 791 ui_call_mainthread(result_callback, result);
792 } else if (op->op == DAV_PATH_OP_MKCOL) {
793 res->iscollection = TRUE;
794 ui_threadfunc result_callback = uithr_pathop_mkcol_sucess;
795 if (dav_create(res)) {
796 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
797 result_callback = uithr_pathop_mkcol_error;
798 }
799 ui_call_mainthread(result_callback, result);
762 } 800 }
763 801
764 dav_resource_free(res); 802 dav_resource_free(res);
765 free(op->path[i]); 803 free(op->path[i]);
766 } 804 }
797 } 835 }
798 } 836 }
799 837
800 ui_job(ui, jobthr_path_op, op, NULL, NULL); 838 ui_job(ui, jobthr_path_op, op, NULL, NULL);
801 } 839 }
840
841 void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
842 DavPathOp *op = malloc(sizeof(DavPathOp));
843 op->ui = ui;
844 op->browser = browser;
845 op->op = DAV_PATH_OP_MKCOL;
846 op->sn = dav_session_clone(browser->sn);
847 op->path = calloc(1, sizeof(char*));
848 op->list_indices = calloc(1, sizeof(size_t));
849 op->nelm = 1;
850
851 op->path[0] = util_concat_path(browser->current->path, name);
852
853 op->collection = browser->current;
854 op->collection_ctn = browser->res_counter;
855
856 ui_job(ui, jobthr_path_op, op, NULL, NULL);
857 }

mercurial