application/davcontroller.c

Thu, 03 Oct 2024 18:08:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 03 Oct 2024 18:08:29 +0200
changeset 46
31bc86844659
parent 45
ab71409644b0
child 48
ae61523bce20
permissions
-rw-r--r--

implement action_newfile

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
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
213 if (browser->navigation_stack->size > DAVBROWSER_MAX_NAVLIST) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
214 char *nav = cxListAt(browser->navigation_stack, browser->navigation_stack->size - 1);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
215 free(nav);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
216 cxListRemove(browser->navigation_stack, browser->navigation_stack->size - 1);
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) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
222 if (browser->navstack_pos+1 < browser->navigation_stack->size) {
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;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
228 }
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 void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
232 if (browser->navstack_pos > 0) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
233 browser->navstack_pos--;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
234 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
235 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
236 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
237 browser->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
238 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
239 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
240
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
241
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
242 // ------------------------------------- File Upload -------------------------------------
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 typedef struct DavFileUpload {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
245 UiObject *ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
246 DavBrowser *browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
247 DavSession *sn;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
248 UiFileList files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
249 char *base_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
250 UiThreadpool *queue;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
251
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
252 size_t total_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
253 size_t total_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
254 size_t total_directories;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
255 size_t uploaded_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
256 size_t uploaded_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
257 size_t uploaded_directories;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
258
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
259 DavBool upload_file;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
260 size_t current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
261 size_t current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
262
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
263 char *current_file_name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
264
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
265 UiObject *dialog;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
266 UiDouble *progress;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
267 UiString *label_top_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
268 UiString *label_top_right;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
269 UiString *label_bottom_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
270 UiString *label_bottom_right;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
271
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
272 // The collection, the files are uploaded to
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
273 // It is only safe to access the collection ptr, if
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
274 // collection == browser->current && collection_ctn == browser->res_counter
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
275 // 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
276 DavResource *collection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
277
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
278 // copy of browser->res_counter, used for integrity check
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
279 int64_t collection_ctn;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
280
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
281 // current uploaded resource, created as part of the browser session
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
282 // only if collection == browser->current && collection_ctn == browser->res_counter
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
283 DavResource *current_resource;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
284 } DavFileUpload;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
285
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
286 typedef struct DUFile {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
287 char *path;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
288 char *upload_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
289 size_t bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
290 DavBool isdirectory;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
291 DavFileUpload *upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
292 DavError error;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
293 } DUFile;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
294
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
295 static double upload_progress(DavFileUpload *upload) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
296 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
297 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
298
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
299 static void update_upload_labels(DavFileUpload *upload) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
300 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
301 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
302 char *sz_uploaded_end = strchr(sz_uploaded, ' ');
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
303 if (sz_uploaded_end) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
304 *sz_uploaded_end = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
305 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
306
25
915131bc3233 update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
307 double progress = upload_progress(upload);
915131bc3233 update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
308 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
309
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
310 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
311 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
312 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
313 "%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
314 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
315 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
316 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
317 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
318 } 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
319 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
320 "%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
321 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
322 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
323 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
324 ui_set(upload->label_top_left, label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
325
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
326 free(sz_total);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
327 free(label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
328
22
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
329 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
330 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
331 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
332 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
333 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
334 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
335
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
336 static int uithr_update_upload_labels(void *data) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
337 update_upload_labels(data);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
338 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
339 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
340
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
341 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
342 DavFileUpload *upload = data;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
343 if (upload->upload_file) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
344 if (now > upload->current_file_size) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
345 // 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
346 // or we have some extra bytes because of encryption
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
347 // adjust current_file_size and the total upload size
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
348 int64_t extra = now - upload->current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
349 upload->current_file_size += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
350 upload->total_bytes += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
351 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
352
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
353 int64_t new_progress = now - upload->current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
354 upload->uploaded_bytes += new_progress;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
355 upload->current_file_upload = now;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
356
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
357 ui_call_mainthread(uithr_update_upload_labels, upload);
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 }
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 typedef struct FileNameUpdate {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
363 DavFileUpload *upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
364 char *name;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
365 char *path;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
366 DavBool iscollection;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
367 } FileNameUpdate;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
368
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
369 static int uithr_update_file_label(FileNameUpdate *update) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
370 // replace upload->current_filename with update->name
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
371 if (update->upload->current_file_name) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
372 free(update->upload->current_file_name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
373 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
374 update->upload->current_file_name = update->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 ui_set(update->upload->label_top_right, update->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
377
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
378 DavFileUpload *upload = update->upload;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
379 DavBrowser *browser = upload->browser;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
380 // 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
381 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
382 char *parent = util_parent_path(update->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
383 cxstring parent_s = cx_str(parent);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
384 cxstring colpath_s = cx_str(upload->collection->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
385 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
386 parent_s.length--;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
387 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
388 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
389 colpath_s.length--;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
390 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
391
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
392 // 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
393 if (!cx_strcmp(parent_s, colpath_s)) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
394 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
395 ui_res->iscollection = update->iscollection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
396 ui_res->lastmodified = time(NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
397 ui_res->creationdate = time(NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
398 upload->current_resource = ui_res;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
399
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
400 ui_list_append(browser->resources, ui_res);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
401 browser->resources->update(browser->resources, 0);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
402 } else {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
403 upload->current_resource = NULL; // maybe not necessary
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
404 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
405 free(parent);
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
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
408 free(update->path);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
409 free(update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
410 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
411 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
412
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
413 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
414 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
415 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
416 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
417
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
418 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
419 if (!in) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
420 // TODO: error msg
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
422 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
423
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
424 upload->upload_file = TRUE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
425 upload->current_file_size = f->bytes;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
426 upload->current_file_upload = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
427
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
428 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
429
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
430 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
431 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
432 ui_update->name = strdup(res->name);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
433 ui_update->path = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
434 ui_update->iscollection = FALSE;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
435 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
436
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
437 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
438 if (dav_store(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
439 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
440 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
441 dav_resource_free(res);
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 fclose(in);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
444
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
445 upload->upload_file = FALSE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
446
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
447 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
448 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
449
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
450 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
451 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
452 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
453
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
454 upload->uploaded_files++;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
455 //upload->uploaded_bytes += file->bytes;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
456
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
457 double progress = upload_progress(upload);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
458 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
459
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
460 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
461
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
462 // update resource content length in the browser
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
463 DavBrowser *browser = upload->browser;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
464 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
465 if (upload->current_resource) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
466 upload->current_resource->contentlength = upload->current_file_upload;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
467 browser->resources->update(browser->resources, 0);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
468 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
469 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
470 upload->current_resource = NULL;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
471
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
472 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
473 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
474 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
475
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
476 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
477 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
478 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
479 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
480
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
481 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
482 res->iscollection = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
483
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
484 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
485 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
486 ui_update->name = strdup(res->name);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
487 ui_update->path = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
488 ui_update->iscollection = TRUE;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
489 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
490
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
491 if (dav_create(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
492 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
493 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
494
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
495 dav_resource_free(res);
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 return 0;
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
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
500 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
501 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
502 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
503
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
504 upload->uploaded_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
505
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
506 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
507
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
508 upload->current_resource = NULL;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
509
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
510 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
511 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
512 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
513
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
514 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
515 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
516 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
517
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
518 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
519 DavFileUpload *upload = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
520 ui_threadpool_destroy(upload->queue);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
521
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
522 free(upload->base_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
523 dav_session_destroy(upload->sn);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
524 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
525
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
526 static int jobthr_upload_scan(void *data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
527 DavFileUpload *upload = data;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
528
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
529 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
530 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
531 DUFile *f = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
532 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
533 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
534 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
535 f->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
536 f->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
537 f->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
538 cxListInsert(stack, 0, f);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
539 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
540
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
541 while (stack->size > 0) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
542 DUFile *f = cxListAt(stack, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
543
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
544 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
545 cxListRemove(stack, 0);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
546
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
547 SYS_STAT s;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
548 if (!sys_stat(f->path, &s)) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
549 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
550 f->isdirectory = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
551 upload->total_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
552 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
553
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
554 SYS_DIR dir = sys_opendir(f->path);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
555 if (dir) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
556 SysDirEnt *entry;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
557 int nument = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
558 while((entry = sys_readdir(dir)) != NULL) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
559 if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
560 continue;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
561 }
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
562
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
563 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
564 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
565
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
566 DUFile *child = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
567 child->path = newpath.ptr;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
568 child->upload_path = new_upload_path;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
569 child->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
570 child->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
571 child->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
572 child->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
573 cxListAdd(stack, child);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
574 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
575
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
576 sys_closedir(dir);
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 } 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
579 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
580 f->bytes = s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
581 upload->total_files++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
582 upload->total_bytes += s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
583 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
584 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
585 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
586 } // TODO: else error msg
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
587
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
588 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
589
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
590 ui_filelist_free(upload->files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
591
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
592 return 0;
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
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
595 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
596 DavFileUpload *upload = data;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
597
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
598 update_upload_labels(upload);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
599 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
600
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
601 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
602 // 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
603 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
604
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
605 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
606 if (!browser->sn) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
607 return; // TODO: error msg
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
608 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
609
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
610 // 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
611 // is done in a separate thread
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
612 DavSession *upload_session = dav_session_clone(browser->sn);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
613
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
614 // 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
615 DavFileUpload *upload = malloc(sizeof(DavFileUpload));
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
616 memset(upload, 0, sizeof(DavFileUpload));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
617
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
618 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
619
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
620 upload->ui = ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
621 upload->browser = browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
622 upload->sn = upload_session;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
623 upload->files = files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
624 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
625 upload->queue = ui_threadpool_create(1);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
626
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
627 upload->collection = browser->current;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
628 upload->collection_ctn = browser->res_counter;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
629
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
630 // create upload progress window
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
631 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
632 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
633 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
634 free(wtitle.ptr);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
635 upload->dialog = dialog;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
636 ui_window_size(dialog, 550, 120);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
637 upload->progress = ui_double_new(dialog->ctx, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
638 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
639 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
640 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
641 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
642
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
643 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
644 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
645 ui_rlabel(dialog, .value = upload->label_top_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
646 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
647
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
648 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
649 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
650
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
651 ui_llabel(dialog, .value = upload->label_bottom_left);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
652 ui_rlabel(dialog, .value = upload->label_bottom_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
653 ui_newline(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
654 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
655
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
656 ui_set(upload->label_top_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
657 ui_set(upload->label_top_right, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
658 ui_set(upload->label_bottom_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
659 ui_set(upload->label_bottom_right, "");
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
660 ui_set(upload->progress, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
661
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
662 ui_show(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
663
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
664 // start upload and stat threads
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
665 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
666 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
667
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
668
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
669 // ------------------------------------- File Download -------------------------------------
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
670
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
671 typedef struct DavFileDownload {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
672 UiObject *ui;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
673 DavBrowser *browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
674
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
675 DavSession *sn;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
676 DavSession *download_sn;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
677 DavResource *reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
678 char *local_path;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
679 DavBool isdirectory;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
680
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
681 UiThreadpool *queue;
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 size_t total_bytes;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
684 size_t total_files;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
685 size_t total_directories;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
686 size_t downloaded_bytes;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
687 size_t downloaded_files;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
688 size_t downloaded_directories;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
689
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
690 size_t current_file_size;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
691 size_t current_file_downloaded;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
692
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
693 UiObject *dialog;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
694 UiDouble *progress;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
695 UiString *label_top_left;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
696 UiString *label_top_right;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
697 UiString *label_bottom_left;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
698 UiString *label_bottom_right;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
699 } DavFileDownload;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
700
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
701
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
702 static int uithr_download_update_progress(void *data) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
703 DavFileDownload *download = data;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
704 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
705 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
706 char *sz_downloaded_end = strchr(sz_downloaded, ' ');
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
707 if (sz_downloaded_end) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
708 *sz_downloaded_end = 0;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
709 }
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
710
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
711 if (download->total_bytes > 0) {
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
712 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
713 ui_set(download->progress, progress*100);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
714 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
715
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
716
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
717 cxmutstr label1;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
718 if (download->total_files + download->total_directories > 1) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
719 label1 = cx_asprintf(
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
720 "%s/%s %zu/%zu files",
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
721 sz_downloaded,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
722 sz_total,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
723 download->downloaded_files+download->downloaded_directories,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
724 download->total_files+download->total_directories);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
725 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
726 label1 = cx_asprintf(
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
727 "%s/%s",
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
728 sz_downloaded,
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
729 sz_total);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
730 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
731 ui_set(download->label_top_left, label1.ptr);
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 free(sz_total);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
734 free(label1.ptr);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
735
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
736
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
737 return 1;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
738 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
739
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
740 // dav download file
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
741 typedef struct DDFile {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
742 DavFileDownload *download;
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
743 size_t size;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
744 char *path;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
745 char *to;
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
746 FILE *fd;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
747 } DDFile;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
748
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
749 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
750 DDFile *file = stream;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
751
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
752 size_t w = fwrite(buf, size, count, file->fd);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
753 file->download->current_file_downloaded += w;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
754
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
755 file->download->downloaded_bytes += 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 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
758 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
759 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
760 file->download->total_bytes += diff;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
761 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
762
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
763 ui_call_mainthread(uithr_download_update_progress, file->download);
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 return w;
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
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
768 static int qthr_download_resource(void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
769 DDFile *file = data;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
770
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
771 file->download->current_file_downloaded = 0;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
772 file->download->current_file_size = file->size;
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
773
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
774 FILE *f = fopen(file->to, "wb");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
775 if (!f) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
776 return 0;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
777 }
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
778 file->fd = f;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
779
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
780 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
781 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
782
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
783 file->download->downloaded_files++;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
784
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
785 ui_call_mainthread(uithr_download_update_progress, file->download);
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
786
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
787 dav_resource_free(res);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
788
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
789 fclose(f);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
790
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
791 free(file->path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
792 free(file->to);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
793 free(file);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
794
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
795 return 0;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
796 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
797
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
798
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
799 typedef struct DlStackElm {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
800 DavResource *resource;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
801 char *sub_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
802 } DlStackElm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
803
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
804 static int jobthr_download_scan(void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
805 DavFileDownload *download = data;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
806 DavBrowser *browser = download->browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
807
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
808 // check if the specified local location is a directory
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
809 SYS_STAT s;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
810 if (!sys_stat(download->local_path, &s)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
811 if (S_ISDIR(s.st_mode)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
812 download->isdirectory = TRUE;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
813 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
814 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
815
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
816 CxList *stack = cxLinkedListCreateSimple(sizeof(DlStackElm));
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
817
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
818 // add selected files to the download queue
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
819 DavResource *res = download->reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
820 while (res) {
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
821 DlStackElm elm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
822 elm.resource = res;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
823 elm.sub_path = strdup(res->name);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
824 cxListAdd(stack, &elm);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
825
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
826 res = res->next;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
827 }
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
828
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
829 while (stack->size > 0) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
830 DlStackElm *elm = cxListAt(stack, 0);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
831 DavResource *res = elm->resource;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
832 char *sub_path = elm->sub_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
833 cxListRemove(stack, 0);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
834
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
835 if (res->iscollection) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
836 if (dav_load(res)) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
837 // TODO: handle error
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
838 continue;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
839 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
840
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
841 // update ui
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
842 ui_call_mainthread(uithr_download_update_progress, download);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
843
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
844 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
845 int err = sys_mkdir(path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
846 free(path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
847 if (err) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
848 // TODO: handle error
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
849 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
850
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
851 DavResource *child = res->children;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
852 while (child) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
853 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
854 DlStackElm childelm;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
855 childelm.resource = child;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
856 childelm.sub_path = child_path;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
857 cxListAdd(stack, &childelm);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
858
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
859 child = child->next;
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 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
862 // add the file to the download queue
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
863 DDFile *file = malloc(sizeof(DDFile));
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
864 file->download = download;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
865 file->path = strdup(res->path);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
866 file->size = res->contentlength;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
867 if (download->isdirectory) {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
868 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
869 } else {
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
870 file->to = strdup(download->local_path);
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
871 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
872
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
873 // stats
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
874 download->total_files++;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
875 download->total_bytes += res->contentlength;
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
876
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
877 // update ui
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
878 ui_call_mainthread(uithr_download_update_progress, download);
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
879
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
880 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
881 }
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
882 }
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 cxListDestroy(stack);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
885
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
886 return 0;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
887 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
888
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
889 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
890 DavFileDownload *download = data;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
891
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
892 }
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 static void download_window_closed(UiEvent *event, void *data) {
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 }
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 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
900 DavFileDownload *download = malloc(sizeof(DavFileDownload));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
901 memset(download, 0, sizeof(DavFileDownload));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
902
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
903 download->ui = ui;
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
904 download->browser = browser;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
905 download->sn = reslist->session;
30
762afc7adc63 implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
906 download->download_sn = dav_session_clone(download->sn);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
907 download->reslist = reslist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
908 download->local_path = strdup(local_path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
909
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
910 download->queue = ui_threadpool_create(1);
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 // create download progress window
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
913 cxmutstr wtitle = cx_asprintf("Download to: %s", local_path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
914 UiObject *dialog = ui_simple_window(wtitle.ptr, download);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
915 ui_context_closefunc(dialog->ctx, download_window_closed, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
916 free(wtitle.ptr);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
917 download->dialog = dialog;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
918 ui_window_size(dialog, 550, 120);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
919 download->progress = ui_double_new(dialog->ctx, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
920 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
921 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
922 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
923 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
924
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
925 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
926 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
927 ui_rlabel(dialog, .value = download->label_top_right);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
928 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
929
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
930 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
931 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
932
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
933 ui_llabel(dialog, .value = download->label_bottom_left);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
934 ui_rlabel(dialog, .value = download->label_bottom_right);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
935 ui_newline(dialog);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
936 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
937
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
938 ui_set(download->label_top_left, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
939 ui_set(download->label_top_right, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
940 ui_set(download->label_bottom_left, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
941 ui_set(download->label_bottom_right, "");
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
942 ui_set(download->progress, 0);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
943
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
944 ui_show(dialog);
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 // start upload and stat threads
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
947 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
948 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
949
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
950
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
951 // ------------------------------------- Path Operation (DELETE, MKCOL) -------------------------------------
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
952
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
953 enum DavPathOpType {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
954 DAV_PATH_OP_DELETE = 0,
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
955 DAV_PATH_OP_CREATE
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
956 };
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
957
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
958 typedef struct DavPathOp {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
959 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
960 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
961
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
962 // operation type (delete, mkcol, ...)
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
963 enum DavPathOpType op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
964 // clone of the browser's DavSession
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
965 DavSession *sn;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
966 // path array
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
967 char **path;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
968 // browser->resources indices
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
969 size_t *list_indices;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
970 // number of path/list_indices elements
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
971 size_t nelm;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
972 // path is collection
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
973 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
974
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
975 // 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
976 // 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
977 DavResource *collection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
978 int64_t collection_ctn;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
979 } DavPathOp;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
980
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
981 typedef struct DavPathOpResult {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
982 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
983 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
984 DavResource *collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
985 int64_t collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
986 enum DavPathOpType op;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
987 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
988
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
989 char *path;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
990 int res_index;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
991 int result;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
992 char *errormsg;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
993 } DavPathOpResult;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
994
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
995 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
996 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
997
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
998 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
999 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
1000 free(msg.ptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1001
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1002 if (result->errormsg) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1003 free(result->errormsg);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1004 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1005 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1006 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1007 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1008 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1009
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1010 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
1011 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1012
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1013 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
1014 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
1015 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
1016 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1017
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1018 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1019 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1020 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1021 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1022
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1023 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
1024 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1025
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1026 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
1027 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
1028 free(msg.ptr);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1029
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1030 if (result->errormsg) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1031 free(result->errormsg);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1032 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1033 free(result->path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1034 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1035 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1036 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1037
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1038 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
1039 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1040
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1041 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
1042 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
1043 res->iscollection = result->iscollection;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1044 // 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
1045 ui_list_append(result->browser->resources, res);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1046 result->browser->resources->update(result->browser->resources, 0);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1047 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1048
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1049 free(result->path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1050 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1051 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1052 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1053
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1054 static int jobthr_path_op(void *data) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1055 DavPathOp *op = data;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1056
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1057 for (int i = op->nelm-1; i >= 0; i--) {
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1058 if (op->path[i]) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1059 DavResource *res = dav_resource_new(op->sn, op->path[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1060
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1061 DavPathOpResult *result = malloc(sizeof(DavPathOpResult));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1062 result->ui = op->ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1063 result->browser = op->browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1064 result->collection = op->collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1065 result->collection_ctn = op->collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1066 result->op = op->op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1067 result->path = strdup(res->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1068 result->result = 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1069 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
1070 result->errormsg = NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1071 result->iscollection = op->iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1072
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1073 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
1074 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
1075 if (dav_delete(res)) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1076 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
1077 result_callback = uithr_pathop_delete_error;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1078 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1079 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1080 } else if (op->op == DAV_PATH_OP_CREATE) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1081 res->iscollection = op->iscollection;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1082 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
1083 if (dav_create(res)) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1084 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
1085 result_callback = uithr_pathop_create_resource_error;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1086 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1087 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1088 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1089
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1090 dav_resource_free(res);
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1091 free(op->path[i]);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1092 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1093 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1094
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1095 dav_session_destroy(op->sn);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1096 free(op->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1097 free(op->list_indices);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1098 free(op);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1099
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1100 return 0;
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
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1103 void davbrowser_delete(UiObject *ui, DavBrowser *browser, UiListSelection selection) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1104 DavPathOp *op = malloc(sizeof(DavPathOp));
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1105 op->ui = ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
1106 op->browser = browser;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1107 op->op = DAV_PATH_OP_DELETE;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1108 op->sn = dav_session_clone(browser->sn);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1109 op->path = calloc(selection.count, sizeof(char*));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1110 op->list_indices = calloc(selection.count, sizeof(size_t));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1111 op->nelm = selection.count;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1112
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1113 op->collection = browser->current;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1114 op->collection_ctn = browser->res_counter;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1115
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1116 for (int i = 0; i < selection.count; i++) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1117 DavResource *res = ui_list_get(browser->resources, selection.rows[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1118 if (res) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1119 op->path[i] = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1120 op->list_indices[i] = selection.rows[i];
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1121 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1122 }
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 ui_job(ui, jobthr_path_op, op, NULL, NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
1125 }
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1126
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1127 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
1128 DavPathOp *op = malloc(sizeof(DavPathOp));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1129 op->ui = ui;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1130 op->browser = browser;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1131 op->op = DAV_PATH_OP_CREATE;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1132 op->sn = dav_session_clone(browser->sn);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1133 op->path = calloc(1, sizeof(char*));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1134 op->list_indices = calloc(1, sizeof(size_t));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1135 op->nelm = 1;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1136 op->iscollection = iscollection;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1137
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1138 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
1139
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1140 op->collection = browser->current;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1141 op->collection_ctn = browser->res_counter;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1142
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1143 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
1144 }
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1145
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1146 void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1147 davbrowser_create_resource(ui, browser, name, TRUE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1148 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1149
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1150 void davbrowser_newfile(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1151 davbrowser_create_resource(ui, browser, name, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
1152 }

mercurial