application/application.c

changeset 29
3fc287f06305
parent 28
1ecc1183f046
child 33
cdeb0dc47ef5
equal deleted inserted replaced
28:1ecc1183f046 29:3fc287f06305
86 ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected); 86 ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected);
87 } 87 }
88 ui_toolbar_item("NewFolder", .icon = "NewFolder", .onclick = action_mkcol); 88 ui_toolbar_item("NewFolder", .icon = "NewFolder", .onclick = action_mkcol);
89 ui_toolbar_item("NewFile", .icon = "Add", .onclick = action_newfile); 89 ui_toolbar_item("NewFile", .icon = "Add", .onclick = action_newfile);
90 ui_toolbar_item("Upload", .label = "Upload", .icon = "Upload", .onclick = action_upload_file); 90 ui_toolbar_item("Upload", .label = "Upload", .icon = "Upload", .onclick = action_upload_file);
91 ui_toolbar_item("Download", .icon = "SaveLocal"); 91 ui_toolbar_item("Download", .icon = "SaveLocal", .onclick = action_download);
92 ui_toolbar_item("Remove", .icon = "Delete", .onclick = action_delete ); 92 ui_toolbar_item("Remove", .icon = "Delete", .onclick = action_delete );
93 ui_toolbar_toggleitem("LocalBrowser", .icon = "DockLeft", .label = "Local Browser"); 93 ui_toolbar_toggleitem("LocalBrowser", .icon = "DockLeft", .label = "Local Browser");
94 ui_toolbar_toggleitem("PreviewPane", .icon = "DockRight"); 94 ui_toolbar_toggleitem("PreviewPane", .icon = "DockRight");
95 95
96 ui_toolbar_appmenu() { 96 ui_toolbar_appmenu() {
173 davbrowser_upload_files(event->obj, event->document, uploadList); 173 davbrowser_upload_files(event->obj, event->document, uploadList);
174 } 174 }
175 175
176 } 176 }
177 177
178
179
180 static void download_location_selected(UiEvent *event, void *data) {
181 DavBrowser *browser = event->document;
182 DavResource *reslist = data;
183 UiFileList *flist = event->eventdata;
184
185 if (flist && flist->nfiles > 0) {
186 davbrowser_download(event->obj, browser, reslist, flist->files[0]);
187 } else {
188 dav_session_destroy(reslist->session);
189 }
190 }
191
192 void action_download(UiEvent *event, void *data) {
193 DavBrowser *browser = event->document;
194 UiListSelection sel = ui_list_getselection(browser->resources);
195 if (sel.count > 0) {;
196 const char *initialFileName = NULL;
197 if (sel.count == 1) {
198 DavResource *res = ui_list_get(browser->resources, sel.rows[0]);
199 if (res && !res->iscollection) {
200 initialFileName = res->name;
201 }
202 }
203
204 // create a copy of the current session and all selected resources
205 DavSession *sn = dav_session_clone(browser->sn);
206 DavResource *first = NULL;
207 DavResource *last = NULL;
208 for (int i = 0; i < sel.count; i++) {
209 // get selected resource
210 DavResource *res = ui_list_get(browser->resources, sel.rows[i]);
211 // copy resource
212 DavResource *res_copy = dav_resource_new(sn, res->path);
213 res_copy->iscollection = res->iscollection;
214 res_copy->contentlength = res->contentlength;
215 res_copy->lastmodified = res->lastmodified;
216 res_copy->creationdate = res->creationdate;
217
218 // link resources
219 if (!first) {
220 first = res_copy;
221 }
222 if (last) {
223 res_copy->prev = last;
224 last->next = res_copy;
225 }
226 last = res_copy;
227 }
228
229 if (initialFileName) {
230 ui_savefiledialog(event->obj, initialFileName, download_location_selected, first);
231 } else {
232 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, download_location_selected, first);
233 }
234 }
235 }
236
178 void action_upload_file(UiEvent *event, void *data) { 237 void action_upload_file(UiEvent *event, void *data) {
179 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL); 238 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL);
180 } 239 }
181 240
182 void action_delete(UiEvent *event, void *data) { 241 void action_delete(UiEvent *event, void *data) {

mercurial