diff -r 1ecc1183f046 -r 3fc287f06305 application/application.c --- a/application/application.c Sun Feb 11 15:59:56 2024 +0100 +++ b/application/application.c Mon Feb 12 17:32:02 2024 +0100 @@ -88,7 +88,7 @@ ui_toolbar_item("NewFolder", .icon = "NewFolder", .onclick = action_mkcol); ui_toolbar_item("NewFile", .icon = "Add", .onclick = action_newfile); ui_toolbar_item("Upload", .label = "Upload", .icon = "Upload", .onclick = action_upload_file); - ui_toolbar_item("Download", .icon = "SaveLocal"); + ui_toolbar_item("Download", .icon = "SaveLocal", .onclick = action_download); ui_toolbar_item("Remove", .icon = "Delete", .onclick = action_delete ); ui_toolbar_toggleitem("LocalBrowser", .icon = "DockLeft", .label = "Local Browser"); ui_toolbar_toggleitem("PreviewPane", .icon = "DockRight"); @@ -175,6 +175,65 @@ } + + +static void download_location_selected(UiEvent *event, void *data) { + DavBrowser *browser = event->document; + DavResource *reslist = data; + UiFileList *flist = event->eventdata; + + if (flist && flist->nfiles > 0) { + davbrowser_download(event->obj, browser, reslist, flist->files[0]); + } else { + dav_session_destroy(reslist->session); + } +} + +void action_download(UiEvent *event, void *data) { + DavBrowser *browser = event->document; + UiListSelection sel = ui_list_getselection(browser->resources); + if (sel.count > 0) {; + const char *initialFileName = NULL; + if (sel.count == 1) { + DavResource *res = ui_list_get(browser->resources, sel.rows[0]); + if (res && !res->iscollection) { + initialFileName = res->name; + } + } + + // create a copy of the current session and all selected resources + DavSession *sn = dav_session_clone(browser->sn); + DavResource *first = NULL; + DavResource *last = NULL; + for (int i = 0; i < sel.count; i++) { + // get selected resource + DavResource *res = ui_list_get(browser->resources, sel.rows[i]); + // copy resource + DavResource *res_copy = dav_resource_new(sn, res->path); + res_copy->iscollection = res->iscollection; + res_copy->contentlength = res->contentlength; + res_copy->lastmodified = res->lastmodified; + res_copy->creationdate = res->creationdate; + + // link resources + if (!first) { + first = res_copy; + } + if (last) { + res_copy->prev = last; + last->next = res_copy; + } + last = res_copy; + } + + if (initialFileName) { + ui_savefiledialog(event->obj, initialFileName, download_location_selected, first); + } else { + ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, download_location_selected, first); + } + } +} + void action_upload_file(UiEvent *event, void *data) { ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL); }