application/davcontroller.c

Sun, 06 Oct 2024 18:18:04 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Oct 2024 18:18:04 +0200
changeset 49
2f71f4ee247a
parent 48
ae61523bce20
child 51
e324291ca9f8
permissions
-rw-r--r--

update toolkit, ucx, libidav

8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "davcontroller.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "window.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <cx/printf.h>
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
34 #include "config.h"
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
35
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
36 #include "system.h"
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
37
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
38 #include <libidav/config.h>
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include <libidav/utils.h>
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 DavBrowser* davbrowser_create(UiObject *toplevel) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 DavBrowser *doc = ui_document_new(sizeof(DavBrowser));
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 UiContext *ctx = ui_document_context(doc);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 doc->ctx = ctx;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
46 doc->navigation_stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
47 doc->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
48 doc->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
49
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 doc->dav_queue = ui_threadpool_create(1);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 doc->path = ui_string_new(ctx, "path");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 doc->resources = ui_list_new(ctx, "reslist");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return doc;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 void davbrowser_set_collection(UiObject *ui, DavBrowser *browser, DavResource *collection) {
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
60 if (browser->current) {
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
61 dav_resource_free_all(browser->current);
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
62 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 ui_list_clear(browser->resources);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
65 browser->current = collection;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
66 browser->res_counter++;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 for (DavResource *res = collection->children; res; res = res->next) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 ui_list_append(browser->resources, res);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 browser->resources->update(browser->resources, 0);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 // ------------------------------ davbrowser_connect2repo ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
76 void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo, const char *path) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 if (repo->user.value.ptr && repo->password.value.ptr) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 dav_session_set_auth(sn, repo->user.value.ptr, decodedpw.ptr);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 free(decodedpw.ptr);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 browser->sn = sn;
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
84 if (repo->name.value.length > 0) {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
85 browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr;
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
86 } else {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
87 browser->repo_base = cx_strdup(cx_strn(repo->url.value.ptr, repo->url.value.length)).ptr;
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
88 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
90 char *dav_path = util_concat_path(browser->repo_base, path);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
91 ui_set(browser->path, dav_path);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
92 free(dav_path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
94 davbrowser_query_path(ui, browser, path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 // ------------------------------ davbrowser_query_path ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 typedef struct DavBrowserQueryPath {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
101 UiThreadpool *pool;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 DavBrowser *browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 char *path;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 DavResource *result;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 } DavBrowserQueryPath;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 static int browser_query_path(void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 DavSession *sn = query->browser->sn;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
111 DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery from %s with depth = 1 order by iscollection desc, name", query->path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 query->result = res;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 return 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 static void browser_query_finished(UiEvent *event, void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 DavBrowser *browser = event->document;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
121 if (query->pool == browser->dav_queue) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
122 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
123 davbrowser_set_collection(event->obj, browser, query->result);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
124 } else {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
125 // TODO: error
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
126 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
127
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
128 window_progress(event->window, 0);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 } else {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
130 // operation aborted
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
131 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
132 dav_resource_free_all(query->result);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
133 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 free(query->path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 free(query);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 void davbrowser_query_path(UiObject *ui, DavBrowser *browser, const char *path) {
17
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
141 if (!browser->sn) {
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
142 // TODO: error
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
143 return;
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
144 }
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
145
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 // for comparison, we need the current base_url/repo_name + path
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 size_t len = path ? strlen(path) : 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 if (len == 1 && *path == '/') {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 path = "";
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
12
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
151
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
152 // check if the new path is a prefix of the current path
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
153 // if not, we have to set the pathbar string to the new path
10
f8dfc5705516 create DavSession in the main GUI thread
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
154 char *full_path = util_concat_path(browser->repo_base, path);
12
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
155 char *full_path_col = util_concat_path(full_path, "/");
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 char *current_path = ui_get(browser->path);
12
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
157 cxstring cpath = cx_str(current_path);
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
158 cxstring newc = cx_str(full_path_col);
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
159 if (!cx_strprefix(cpath, newc)) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 ui_set(browser->path, full_path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 free(full_path);
12
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
163 free(full_path_col);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 DavBrowserQueryPath *query = malloc(sizeof(DavBrowserQueryPath));
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
166 query->pool = browser->dav_queue;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 query->browser = browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 query->path = strdup(path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 query->result = NULL;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 ui_threadpool_job(browser->dav_queue, ui, browser_query_path, query, browser_query_finished, query);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 window_progress(ui->window, 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
173
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
174 davbrowser_add2navstack(browser, browser->repo_base, path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
176
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
177 void davbrowser_query_url(UiObject *ui, DavBrowser *browser, const char *url) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
178 if (browser->repo_base) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
179 cxstring base = cx_str(browser->repo_base);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
180 cxstring newurl = cx_str(url);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
181
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
182 if (cx_strprefix(newurl, base)) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
183 const char *path = url + base.length;
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
184 davbrowser_query_path(ui, browser, path);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
185 return;
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
186 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
187 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
188
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
189 char *path = NULL;
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
190 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
191 davbrowser_connect2repo(ui, browser, repo, path);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
192
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
193 if (path) {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
194 free(path);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
195 }
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
196 if (!repo->node) {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
197 dav_repository_free(get_config(), repo);
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
198 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
199 }
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
200
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
201 void davbrowser_add2navstack(DavBrowser *browser, const char *base, const char *path) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
202 if (browser->navstack_enabled) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
203 for (int i = 0; i < browser->navstack_pos; i++) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
204 char *nav_url = cxListAt(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
205 cxListRemove(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
206 free(nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
207 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
208 browser->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
209
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
210 char *nav_url = util_concat_path(base, path);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
211 cxListInsert(browser->navigation_stack, 0, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
212
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
213 if (cxListSize(browser->navigation_stack) > DAVBROWSER_MAX_NAVLIST) {
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
214 char *nav = cxListAt(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
215 free(nav);
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
216 cxListRemove(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
217 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
218 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
219 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
220
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
221 void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser) {
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
222 if (browser->navstack_pos+1 < cxListSize(browser->navigation_stack)) {
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
223 browser->navstack_pos++;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
224 char *nav_url = cxListAt(browser->navigation_stack, browser->navstack_pos);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
225 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
226 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
227 browser->navstack_enabled = true;
48
ae61523bce20 improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
228 ui_set(browser->path, nav_url);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
229 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
230 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
231
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
232 void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
233 if (browser->navstack_pos > 0) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
234 browser->navstack_pos--;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
235 char *nav_url = cxListAt(browser->navigation_stack, browser->navstack_pos);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
236 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
237 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
238 browser->navstack_enabled = true;
48
ae61523bce20 improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
239 ui_set(browser->path, nav_url);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
240 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
241 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
242
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
243
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
244 // ------------------------------------- File Upload -------------------------------------
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
245
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
246 typedef struct DavFileUpload {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
247 UiObject *ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
248 DavBrowser *browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
249 DavSession *sn;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
250 UiFileList files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
251 char *base_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
252 UiThreadpool *queue;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
253
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
254 size_t total_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
255 size_t total_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
256 size_t total_directories;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
257 size_t uploaded_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
258 size_t uploaded_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
259 size_t uploaded_directories;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
260
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
261 DavBool upload_file;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
262 size_t current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
263 size_t current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
264
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
265 char *current_file_name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
266
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
267 UiObject *dialog;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
268 UiDouble *progress;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
269 UiString *label_top_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
270 UiString *label_top_right;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
271 UiString *label_bottom_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
272 UiString *label_bottom_right;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
273
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
274 // The collection, the files are uploaded to
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
275 // It is only safe to access the collection ptr, if
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
276 // collection == browser->current && collection_ctn == browser->res_counter
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
277 // and obviously it can only be accessed from the UI thread
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
278 DavResource *collection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
279
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
280 // copy of browser->res_counter, used for integrity check
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
281 int64_t collection_ctn;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
282
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
283 // current uploaded resource, created as part of the browser session
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
284 // only if collection == browser->current && collection_ctn == browser->res_counter
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
285 DavResource *current_resource;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
286 } DavFileUpload;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
287
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
288 typedef struct DUFile {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
289 char *path;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
290 char *upload_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
291 size_t bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
292 DavBool isdirectory;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
293 DavFileUpload *upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
294 DavError error;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
295 } DUFile;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
296
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
297 static double upload_progress(DavFileUpload *upload) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
298 return ((double)upload->uploaded_bytes / (double)upload->total_bytes) * 100;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
299 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
300
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
301 static void update_upload_labels(DavFileUpload *upload) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
302 char *sz_total = util_size_str(FALSE, upload->total_bytes);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
303 char *sz_uploaded = util_size_str2(FALSE, upload->uploaded_bytes, upload->total_bytes, 2);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
304 char *sz_uploaded_end = strchr(sz_uploaded, ' ');
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
305 if (sz_uploaded_end) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
306 *sz_uploaded_end = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
307 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
308
25
915131bc3233 update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
309 double progress = upload_progress(upload);
915131bc3233 update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
310 ui_set(upload->progress, upload_progress(upload));
915131bc3233 update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
311
24
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
312 cxmutstr label1;
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
313 if (upload->total_files + upload->total_directories > 1) {
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
314 label1 = cx_asprintf(
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
315 "%s/%s %zu/%zu files",
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
316 sz_uploaded,
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
317 sz_total,
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
318 upload->uploaded_files+upload->uploaded_directories,
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
319 upload->total_files+upload->total_directories);
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
320 } else {
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
321 label1 = cx_asprintf(
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
322 "%s/%s",
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
323 sz_uploaded,
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
324 sz_total);
12ad3393c151 don't show number of uploading files when there is only 1 file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
325 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
326 ui_set(upload->label_top_left, label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
327
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
328 free(sz_total);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
329 free(label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
330
22
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
331 if (upload->current_file_size > 0) {
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
332 cxmutstr file_label = cx_asprintf("%s (%.0f%%)", upload->current_file_name, ((float)upload->current_file_upload/(float)upload->current_file_size)*100);
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
333 ui_set(upload->label_top_right, file_label.ptr);
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
334 free(file_label.ptr);
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
335 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
336 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
337
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
338 static int uithr_update_upload_labels(void *data) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
339 update_upload_labels(data);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
340 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
341 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
342
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
343 static void upload_dav_progress(DavResource *res, int64_t total, int64_t now, void *data) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
344 DavFileUpload *upload = data;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
345 if (upload->upload_file) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
346 if (now > upload->current_file_size) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
347 // current_file_size is not accurate (either the file was changed after the last stat
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
348 // or we have some extra bytes because of encryption
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
349 // adjust current_file_size and the total upload size
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
350 int64_t extra = now - upload->current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
351 upload->current_file_size += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
352 upload->total_bytes += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
353 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
354
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
355 int64_t new_progress = now - upload->current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
356 upload->uploaded_bytes += new_progress;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
357 upload->current_file_upload = now;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
358
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
359 ui_call_mainthread(uithr_update_upload_labels, upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
360 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
361 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
362
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
363
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
364 typedef struct FileNameUpdate {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
365 DavFileUpload *upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
366 char *name;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
367 char *path;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
368 DavBool iscollection;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
369 } FileNameUpdate;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
370
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
371 static int uithr_update_file_label(FileNameUpdate *update) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
372 // replace upload->current_filename with update->name
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
373 if (update->upload->current_file_name) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
374 free(update->upload->current_file_name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
375 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
376 update->upload->current_file_name = update->name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
377
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
378 ui_set(update->upload->label_top_right, update->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
379
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
380 DavFileUpload *upload = update->upload;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
381 DavBrowser *browser = upload->browser;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
382 // update the resource list in the browser, if the current collection has not changed
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
383 if (upload->collection == browser->current && upload->collection_ctn == browser->res_counter) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
384 char *parent = util_parent_path(update->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
385 cxstring parent_s = cx_str(parent);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
386 cxstring colpath_s = cx_str(upload->collection->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
387 if (parent_s.length > 0 && parent_s.ptr[parent_s.length - 1] == '/') {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
388 parent_s.length--;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
389 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
390 if (colpath_s.length > 0 && colpath_s.ptr[colpath_s.length - 1] == '/') {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
391 colpath_s.length--;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
392 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
393
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
394 // only update, if the added resource has the current collection as parent
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
395 if (!cx_strcmp(parent_s, colpath_s)) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
396 DavResource *ui_res = dav_resource_new(upload->collection->session, update->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
397 ui_res->iscollection = update->iscollection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
398 ui_res->lastmodified = time(NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
399 ui_res->creationdate = time(NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
400 upload->current_resource = ui_res;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
401
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
402 ui_list_append(browser->resources, ui_res);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
403 browser->resources->update(browser->resources, 0);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
404 } else {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
405 upload->current_resource = NULL; // maybe not necessary
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
406 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
407 free(parent);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
408 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
409
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
410 free(update->path);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
411 free(update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
412 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
413 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
414
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
415 static int qthr_file_upload(void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
416 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
417 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
418 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
419
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
420 FILE *in = sys_fopen(f->path, "rb");
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421 if (!in) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
422 // TODO: error msg
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
423 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
424 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
425
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
426 upload->upload_file = TRUE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
427 upload->current_file_size = f->bytes;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
428 upload->current_file_upload = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
429
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
430 DavResource *res = dav_resource_new(sn, f->upload_path);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
431
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
432 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
433 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
434 ui_update->name = strdup(res->name);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
435 ui_update->path = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
436 ui_update->iscollection = FALSE;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
437 ui_call_mainthread((ui_threadfunc)uithr_update_file_label, ui_update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
438
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
439 dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)fseek);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
440 if (dav_store(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
441 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
442 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
443 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
444
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
445 fclose(in);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
446
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
447 upload->upload_file = FALSE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
448
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
449 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
450 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
451
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
452 static void uithr_file_uploaded(UiEvent *event, void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
453 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
454 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
455
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
456 upload->uploaded_files++;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
457 //upload->uploaded_bytes += file->bytes;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
458
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
459 double progress = upload_progress(upload);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
460 ui_set(upload->progress, upload_progress(upload));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
461
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
462 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
463
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
464 // update resource content length in the browser
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
465 DavBrowser *browser = upload->browser;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
466 if (upload->collection == browser->current && upload->collection_ctn == browser->res_counter) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
467 if (upload->current_resource) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
468 upload->current_resource->contentlength = upload->current_file_upload;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
469 browser->resources->update(browser->resources, 0);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
470 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
471 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
472 upload->current_resource = NULL;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
473
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
474 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
475 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
476 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
477
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
478 static int qthr_dir_upload(void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
479 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
480 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
481 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
482
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
483 DavResource *res = dav_resource_new(sn, f->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
484 res->iscollection = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
485
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
486 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
487 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
488 ui_update->name = strdup(res->name);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
489 ui_update->path = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
490 ui_update->iscollection = TRUE;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
491 ui_call_mainthread((ui_threadfunc)uithr_update_file_label, ui_update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
492
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
493 if (dav_create(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
494 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
495 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
496
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
497 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
498
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
499 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
500 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
501
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
502 static void uithr_dir_uploaded(UiEvent *event, void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
503 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
504 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
505
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
506 upload->uploaded_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
507
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
508 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
509
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
510 upload->current_resource = NULL;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
511
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
512 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
513 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
514 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
515
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
516 static int qthr_upload_finished(void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
517 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
518 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
519
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
520 static void uithr_upload_finished(UiEvent *event, void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
521 DavFileUpload *upload = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
522 ui_threadpool_destroy(upload->queue);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
523
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
524 free(upload->base_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
525 dav_session_destroy(upload->sn);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
526 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
527
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
528 static int jobthr_upload_scan(void *data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
529 DavFileUpload *upload = data;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
530
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
531 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
532 for (int i = 0; i < upload->files.nfiles; i++) {
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
533 DUFile *f = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
534 f->path = strdup(upload->files.files[i]);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
535 f->upload_path = util_concat_path(upload->base_path, util_path_file_name(f->path));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
536 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
537 f->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
538 f->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
539 f->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
540 cxListInsert(stack, 0, f);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
541 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
542
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
543 while (cxListSize(stack) > 0) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
544 DUFile *f = cxListAt(stack, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
545
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
546 char *path = util_concat_path(upload->base_path, f->upload_path);
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
547 cxListRemove(stack, 0);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
548
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
549 SYS_STAT s;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
550 if (!sys_stat(f->path, &s)) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
551 if (S_ISDIR(s.st_mode)) {
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
552 f->isdirectory = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
553 upload->total_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
554 ui_threadpool_job(upload->queue, upload->ui, qthr_dir_upload, f, uithr_dir_uploaded, f);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
555
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
556 SYS_DIR dir = sys_opendir(f->path);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
557 if (dir) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
558 SysDirEnt *entry;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
559 int nument = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
560 while((entry = sys_readdir(dir)) != NULL) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
561 if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
562 continue;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
563 }
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
564
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
565 cxmutstr newpath = util_concat_sys_path(cx_str(f->path), cx_str(entry->name));
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
566 char *new_upload_path = util_concat_path(f->upload_path, entry->name);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
567
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
568 DUFile *child = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
569 child->path = newpath.ptr;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
570 child->upload_path = new_upload_path;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
571 child->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
572 child->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
573 child->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
574 child->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
575 cxListAdd(stack, child);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
576 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
577
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
578 sys_closedir(dir);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
579 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
580 } else if (S_ISREG(s.st_mode)) {
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
581 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
582 f->bytes = s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
583 upload->total_files++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
584 upload->total_bytes += s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
585 ui_threadpool_job(upload->queue, upload->ui, qthr_file_upload, f, uithr_file_uploaded, f);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
586 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
587 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
588 } // TODO: else error msg
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
589
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
590 ui_threadpool_job(upload->queue, upload->ui, qthr_upload_finished, upload, uithr_upload_finished, upload);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
591
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
592 ui_filelist_free(upload->files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
593
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
594 return 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
595 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
596
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
597 static void uithr_upload_scan_finished(UiEvent *event, void *data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
598 DavFileUpload *upload = data;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
599
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
600 update_upload_labels(upload);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
601 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
602
21
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
603 static void upload_window_closed(UiEvent *event, void *data) {
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
604 // noop, prevents context destruction
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
605 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
606
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
607 void davbrowser_upload_files(UiObject *ui, DavBrowser *browser, UiFileList files) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
608 if (!browser->sn) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
609 return; // TODO: error msg
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
610 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
611
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
612 // we need a clone of the current session, because the upload
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
613 // is done in a separate thread
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
614 DavSession *upload_session = dav_session_clone(browser->sn);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
615
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
616 // create upload obj, that contains all relevant data for the upload
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
617 DavFileUpload *upload = malloc(sizeof(DavFileUpload));
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
618 memset(upload, 0, sizeof(DavFileUpload));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
619
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
620 dav_session_set_progresscallback(upload_session, NULL, upload_dav_progress, upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
621
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
622 upload->ui = ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
623 upload->browser = browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
624 upload->sn = upload_session;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
625 upload->files = files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
626 upload->base_path = strdup(browser->current->path);
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
627 upload->queue = ui_threadpool_create(1);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
628
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
629 upload->collection = browser->current;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
630 upload->collection_ctn = browser->res_counter;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
631
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
632 // create upload progress window
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
633 cxmutstr wtitle = cx_asprintf("Upload to: %s", ui_get(browser->path));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
634 UiObject *dialog = ui_simple_window(wtitle.ptr, upload);
21
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
635 ui_context_closefunc(dialog->ctx, upload_window_closed, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
636 free(wtitle.ptr);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
637 upload->dialog = dialog;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
638 ui_window_size(dialog, 550, 120);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
639 upload->progress = ui_double_new(dialog->ctx, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
640 upload->label_top_left = ui_string_new(dialog->ctx, NULL);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
641 upload->label_top_right = ui_string_new(dialog->ctx, NULL);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
642 upload->label_bottom_left = ui_string_new(dialog->ctx, NULL);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
643 upload->label_bottom_right = ui_string_new(dialog->ctx, NULL);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
644
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
645 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
646 ui_llabel(dialog, .value = upload->label_top_left, .hexpand = TRUE);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
647 ui_rlabel(dialog, .value = upload->label_top_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
648 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
649
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
650 ui_progressbar(dialog, .value = upload->progress, .colspan = 2, .hexpand = TRUE);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
651 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
652
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
653 ui_llabel(dialog, .value = upload->label_bottom_left);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
654 ui_rlabel(dialog, .value = upload->label_bottom_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
655 ui_newline(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
656 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
657
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
658 ui_set(upload->label_top_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
659 ui_set(upload->label_top_right, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
660 ui_set(upload->label_bottom_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
661 ui_set(upload->label_bottom_right, "");
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
662 ui_set(upload->progress, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
663
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
664 ui_show(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
665
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
666 // start upload and stat threads
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
667 ui_job(ui, jobthr_upload_scan, upload, uithr_upload_scan_finished, upload);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
668 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
669
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
670
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
671 // ------------------------------------- File Download -------------------------------------
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
672
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
673 typedef struct DavFileDownload {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
674 UiObject *ui;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
675 DavBrowser *browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
676
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
677 DavSession *sn;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
678 DavSession *download_sn;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
679 DavResource *reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
680 char *local_path;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
681 DavBool isdirectory;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
682
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
683 UiThreadpool *queue;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
684
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
685 size_t total_bytes;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
686 size_t total_files;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
687 size_t total_directories;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
688 size_t downloaded_bytes;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
689 size_t downloaded_files;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
690 size_t downloaded_directories;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
691
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
692 size_t current_file_size;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
693 size_t current_file_downloaded;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
694
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
695 UiObject *dialog;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
696 UiDouble *progress;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
697 UiString *label_top_left;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
698 UiString *label_top_right;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
699 UiString *label_bottom_left;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
700 UiString *label_bottom_right;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
701 } DavFileDownload;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
702
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
703
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
704 static int uithr_download_update_progress(void *data) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
705 DavFileDownload *download = data;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
706 char *sz_total = util_size_str(FALSE, download->total_bytes);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
707 char *sz_downloaded = util_size_str2(FALSE, download->downloaded_bytes, download->total_bytes, 2);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
708 char *sz_downloaded_end = strchr(sz_downloaded, ' ');
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
709 if (sz_downloaded_end) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
710 *sz_downloaded_end = 0;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
711 }
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
712
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
713 if (download->total_bytes > 0) {
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
714 double progress = (double)download->downloaded_bytes / (double)download->total_bytes;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
715 ui_set(download->progress, progress*100);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
716 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
717
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
718
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
719 cxmutstr label1;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
720 if (download->total_files + download->total_directories > 1) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
721 label1 = cx_asprintf(
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
722 "%s/%s %zu/%zu files",
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
723 sz_downloaded,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
724 sz_total,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
725 download->downloaded_files+download->downloaded_directories,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
726 download->total_files+download->total_directories);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
727 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
728 label1 = cx_asprintf(
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
729 "%s/%s",
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
730 sz_downloaded,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
731 sz_total);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
732 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
733 ui_set(download->label_top_left, label1.ptr);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
734
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
735 free(sz_total);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
736 free(label1.ptr);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
737
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
738
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
739 return 1;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
740 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
741
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
742 // dav download file
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
743 typedef struct DDFile {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
744 DavFileDownload *download;
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
745 size_t size;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
746 char *path;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
747 char *to;
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
748 FILE *fd;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
749 } DDFile;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
750
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
751 static size_t ddfile_write(const void *buf, size_t size, size_t count, void *stream) {
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
752 DDFile *file = stream;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
753
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
754 size_t w = fwrite(buf, size, count, file->fd);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
755 file->download->current_file_downloaded += w;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
756
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
757 file->download->downloaded_bytes += w;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
758
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
759 if (file->download->current_file_downloaded > file->download->current_file_size) {
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
760 size_t diff = file->download->current_file_downloaded - file->download->current_file_size;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
761 file->download->current_file_size = file->download->current_file_downloaded;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
762 file->download->total_bytes += diff;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
763 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
764
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
765 ui_call_mainthread(uithr_download_update_progress, file->download);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
766
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
767 return w;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
768 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
769
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
770 static int qthr_download_resource(void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
771 DDFile *file = data;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
772
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
773 file->download->current_file_downloaded = 0;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
774 file->download->current_file_size = file->size;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
775
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
776 FILE *f = fopen(file->to, "wb");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
777 if (!f) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
778 return 0;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
779 }
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
780 file->fd = f;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
781
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
782 DavResource *res = dav_resource_new(file->download->download_sn, file->path);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
783 dav_get_content(res, file, (dav_write_func)ddfile_write);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
784
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
785 file->download->downloaded_files++;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
786
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
787 ui_call_mainthread(uithr_download_update_progress, file->download);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
788
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
789 dav_resource_free(res);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
790
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
791 fclose(f);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
792
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
793 free(file->path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
794 free(file->to);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
795 free(file);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
796
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
797 return 0;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
798 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
799
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
800
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
801 typedef struct DlStackElm {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
802 DavResource *resource;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
803 char *sub_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
804 } DlStackElm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
805
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
806 static int jobthr_download_scan(void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
807 DavFileDownload *download = data;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
808 DavBrowser *browser = download->browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
809
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
810 // check if the specified local location is a directory
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
811 SYS_STAT s;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
812 if (!sys_stat(download->local_path, &s)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
813 if (S_ISDIR(s.st_mode)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
814 download->isdirectory = TRUE;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
815 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
816 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
817
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
818 CxList *stack = cxLinkedListCreateSimple(sizeof(DlStackElm));
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
819
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
820 // add selected files to the download queue
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
821 DavResource *res = download->reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
822 while (res) {
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
823 DlStackElm elm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
824 elm.resource = res;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
825 elm.sub_path = strdup(res->name);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
826 cxListAdd(stack, &elm);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
827
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
828 res = res->next;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
829 }
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
830
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
831 while (cxListSize(stack) > 0) {
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
832 DlStackElm *elm = cxListAt(stack, 0);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
833 DavResource *res = elm->resource;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
834 char *sub_path = elm->sub_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
835 cxListRemove(stack, 0);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
836
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
837 if (res->iscollection) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
838 if (dav_load(res)) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
839 // TODO: handle error
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
840 continue;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
841 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
842
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
843 // update ui
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
844 ui_call_mainthread(uithr_download_update_progress, download);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
845
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
846 char *path = util_concat_path(download->local_path, sub_path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
847 int err = sys_mkdir(path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
848 free(path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
849 if (err) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
850 // TODO: handle error
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
851 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
852
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
853 DavResource *child = res->children;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
854 while (child) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
855 char *child_path = util_concat_path(sub_path, child->name);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
856 DlStackElm childelm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
857 childelm.resource = child;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
858 childelm.sub_path = child_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
859 cxListAdd(stack, &childelm);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
860
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
861 child = child->next;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
862 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
863 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
864 // add the file to the download queue
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
865 DDFile *file = malloc(sizeof(DDFile));
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
866 file->download = download;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
867 file->path = strdup(res->path);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
868 file->size = res->contentlength;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
869 if (download->isdirectory) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
870 file->to = util_concat_path(download->local_path, sub_path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
871 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
872 file->to = strdup(download->local_path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
873 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
874
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
875 // stats
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
876 download->total_files++;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
877 download->total_bytes += res->contentlength;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
878
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
879 // update ui
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
880 ui_call_mainthread(uithr_download_update_progress, download);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
881
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
882 ui_threadpool_job(download->queue, download->ui, qthr_download_resource, file, NULL, NULL);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
883 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
884 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
885
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
886 cxListDestroy(stack);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
887
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
888 return 0;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
889 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
890
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
891 static void uithr_download_scan_finished(UiEvent *event, void *data) {
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
892 DavFileDownload *download = data;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
893
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
894 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
895
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
896 static void download_window_closed(UiEvent *event, void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
897
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
898 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
899
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
900
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
901 void davbrowser_download(UiObject *ui, DavBrowser *browser, DavResource *reslist, const char *local_path) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
902 DavFileDownload *download = malloc(sizeof(DavFileDownload));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
903 memset(download, 0, sizeof(DavFileDownload));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
904
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
905 download->ui = ui;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
906 download->browser = browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
907 download->sn = reslist->session;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
908 download->download_sn = dav_session_clone(download->sn);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
909 download->reslist = reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
910 download->local_path = strdup(local_path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
911
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
912 download->queue = ui_threadpool_create(1);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
913
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
914 // create download progress window
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
915 cxmutstr wtitle = cx_asprintf("Download to: %s", local_path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
916 UiObject *dialog = ui_simple_window(wtitle.ptr, download);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
917 ui_context_closefunc(dialog->ctx, download_window_closed, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
918 free(wtitle.ptr);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
919 download->dialog = dialog;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
920 ui_window_size(dialog, 550, 120);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
921 download->progress = ui_double_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
922 download->label_top_left = ui_string_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
923 download->label_top_right = ui_string_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
924 download->label_bottom_left = ui_string_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
925 download->label_bottom_right = ui_string_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
926
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
927 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
928 ui_llabel(dialog, .value = download->label_top_left, .hexpand = TRUE);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
929 ui_rlabel(dialog, .value = download->label_top_right);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
930 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
931
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
932 ui_progressbar(dialog, .value = download->progress, .min = 0, .max = 100, .colspan = 2, .hexpand = TRUE);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
933 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
934
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
935 ui_llabel(dialog, .value = download->label_bottom_left);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
936 ui_rlabel(dialog, .value = download->label_bottom_right);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
937 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
938 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
939
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
940 ui_set(download->label_top_left, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
941 ui_set(download->label_top_right, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
942 ui_set(download->label_bottom_left, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
943 ui_set(download->label_bottom_right, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
944 ui_set(download->progress, 0);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
945
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
946 ui_show(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
947
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
948 // start upload and stat threads
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
949 ui_job(ui, jobthr_download_scan, download, uithr_download_scan_finished, download);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
950 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
951
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
952
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
953 // ------------------------------------- Path Operation (DELETE, MKCOL) -------------------------------------
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
954
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
955 enum DavPathOpType {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
956 DAV_PATH_OP_DELETE = 0,
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
957 DAV_PATH_OP_CREATE
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
958 };
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
959
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
960 typedef struct DavPathOp {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
961 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
962 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
963
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
964 // operation type (delete, mkcol, ...)
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
965 enum DavPathOpType op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
966 // clone of the browser's DavSession
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
967 DavSession *sn;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
968 // path array
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
969 char **path;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
970 // browser->resources indices
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
971 size_t *list_indices;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
972 // number of path/list_indices elements
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
973 size_t nelm;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
974 // path is collection
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
975 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
976
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
977 // browser->current ptr when the PathOp started
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
978 // used in combination with collection_ctn to check if the browser list changed
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
979 DavResource *collection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
980 int64_t collection_ctn;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
981 } DavPathOp;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
982
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
983 typedef struct DavPathOpResult {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
984 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
985 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
986 DavResource *collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
987 int64_t collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
988 enum DavPathOpType op;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
989 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
990
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
991 char *path;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
992 int res_index;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
993 int result;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
994 char *errormsg;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
995 } DavPathOpResult;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
996
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
997 static int uithr_pathop_delete_error(void *data) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
998 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
999
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1000 cxmutstr msg = cx_asprintf("Cannot delete resource %s", result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1001 ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1002 free(msg.ptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1003
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1004 if (result->errormsg) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1005 free(result->errormsg);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1006 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1007 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1008 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1009 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1010 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1011
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1012 static int uithr_pathop_delete_sucess(void *data) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1013 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1014
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1015 if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1016 ui_list_remove(result->browser->resources, result->res_index);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1017 result->browser->resources->update(result->browser->resources, 0);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1018 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1019
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1020 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1021 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1022 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1023 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1024
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1025 static int uithr_pathop_create_resource_error(void *data) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1026 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1027
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1028 cxmutstr msg = cx_asprintf("Cannot create %s %s", result->iscollection ? "collection" : "resource", result->path);
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1029 ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1030 free(msg.ptr);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1031
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1032 if (result->errormsg) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1033 free(result->errormsg);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1034 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1035 free(result->path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1036 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1037 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1038 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1039
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1040 static int uithr_pathop_create_resource_sucess(void *data) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1041 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1042
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1043 if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1044 DavResource *res = dav_resource_new(result->browser->sn, result->path);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1045 res->iscollection = result->iscollection;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1046 // TODO: add the resource at the correct position or sort the list after append
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1047 ui_list_append(result->browser->resources, res);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1048 result->browser->resources->update(result->browser->resources, 0);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1049 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1050
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1051 free(result->path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1052 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1053 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1054 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1055
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1056 static int jobthr_path_op(void *data) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1057 DavPathOp *op = data;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1058
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1059 for (int i = op->nelm-1; i >= 0; i--) {
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1060 if (op->path[i]) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1061 DavResource *res = dav_resource_new(op->sn, op->path[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1062
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1063 DavPathOpResult *result = malloc(sizeof(DavPathOpResult));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1064 result->ui = op->ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1065 result->browser = op->browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1066 result->collection = op->collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1067 result->collection_ctn = op->collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1068 result->op = op->op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1069 result->path = strdup(res->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1070 result->result = 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1071 result->res_index = op->list_indices[i];
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1072 result->errormsg = NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1073 result->iscollection = op->iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1074
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1075 if (op->op == DAV_PATH_OP_DELETE) {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1076 ui_threadfunc result_callback = uithr_pathop_delete_sucess;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1077 if (dav_delete(res)) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1078 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1079 result_callback = uithr_pathop_delete_error;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1080 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1081 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1082 } else if (op->op == DAV_PATH_OP_CREATE) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1083 res->iscollection = op->iscollection;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1084 ui_threadfunc result_callback = uithr_pathop_create_resource_sucess;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1085 if (dav_create(res)) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1086 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1087 result_callback = uithr_pathop_create_resource_error;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1088 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1089 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1090 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1091
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1092 dav_resource_free(res);
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1093 free(op->path[i]);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1094 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1095 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1096
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1097 dav_session_destroy(op->sn);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1098 free(op->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1099 free(op->list_indices);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1100 free(op);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1101
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1102 return 0;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1103 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1104
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1105 void davbrowser_delete(UiObject *ui, DavBrowser *browser, UiListSelection selection) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1106 DavPathOp *op = malloc(sizeof(DavPathOp));
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1107 op->ui = ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1108 op->browser = browser;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1109 op->op = DAV_PATH_OP_DELETE;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1110 op->sn = dav_session_clone(browser->sn);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1111 op->path = calloc(selection.count, sizeof(char*));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1112 op->list_indices = calloc(selection.count, sizeof(size_t));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1113 op->nelm = selection.count;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1114
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1115 op->collection = browser->current;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1116 op->collection_ctn = browser->res_counter;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1117
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1118 for (int i = 0; i < selection.count; i++) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1119 DavResource *res = ui_list_get(browser->resources, selection.rows[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1120 if (res) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1121 op->path[i] = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1122 op->list_indices[i] = selection.rows[i];
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1123 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1124 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1125
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1126 ui_job(ui, jobthr_path_op, op, NULL, NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1127 }
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1128
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1129 void davbrowser_create_resource(UiObject *ui, DavBrowser *browser, const char *name, DavBool iscollection) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1130 DavPathOp *op = malloc(sizeof(DavPathOp));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1131 op->ui = ui;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1132 op->browser = browser;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1133 op->op = DAV_PATH_OP_CREATE;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1134 op->sn = dav_session_clone(browser->sn);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1135 op->path = calloc(1, sizeof(char*));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1136 op->list_indices = calloc(1, sizeof(size_t));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1137 op->nelm = 1;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1138 op->iscollection = iscollection;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1139
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1140 op->path[0] = util_concat_path(browser->current->path, name);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1141
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1142 op->collection = browser->current;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1143 op->collection_ctn = browser->res_counter;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1144
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1145 ui_job(ui, jobthr_path_op, op, NULL, NULL);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1146 }
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1147
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1148 void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1149 davbrowser_create_resource(ui, browser, name, TRUE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1150 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1151
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1152 void davbrowser_newfile(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1153 davbrowser_create_resource(ui, browser, name, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1154 }

mercurial