Wed, 13 Nov 2024 22:05:52 +0100
change binary name to idav
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" |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
37 | #include "common/context.h" |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
38 | |
16
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
39 | #include <libidav/config.h> |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include <libidav/utils.h> |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | DavBrowser* davbrowser_create(UiObject *toplevel) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | DavBrowser *doc = ui_document_new(sizeof(DavBrowser)); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | UiContext *ctx = ui_document_context(doc); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | doc->ctx = ctx; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
47 | doc->navigation_stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
48 | doc->navstack_enabled = true; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
49 | doc->navstack_pos = 0; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
50 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | doc->dav_queue = ui_threadpool_create(1); |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
52 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
53 | doc->res_open_inprogress = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 4); |
8
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 | doc->path = ui_string_new(ctx, "path"); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | doc->resources = ui_list_new(ctx, "reslist"); |
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 | return doc; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | 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
|
63 | if (browser->current) { |
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
64 | dav_resource_free_all(browser->current); |
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | ui_list_clear(browser->resources); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
13
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
68 | browser->current = collection; |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
69 | browser->res_counter++; |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | for (DavResource *res = collection->children; res; res = res->next) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | ui_list_append(browser->resources, res); |
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 | browser->resources->update(browser->resources, 0); |
68 | 75 | |
76 | ui_set_group(ui->ctx, APP_STATE_BROWSER_SESSION); | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | // ------------------------------ davbrowser_connect2repo ------------------------------ |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
16
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
81 | 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
|
82 | 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
|
83 | if (repo->user.value.ptr && repo->password.value.ptr) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | 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
|
86 | free(decodedpw.ptr); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | } else { |
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
92 | 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
|
93 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
16
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
95 | 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
|
96 | 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
|
97 | free(dav_path); |
56
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
98 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
99 | SessionAuthData *auth = cxMalloc(sn->mp->allocator, sizeof(SessionAuthData)); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
100 | auth->obj = ui; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
101 | auth->cond = ui_condvar_create(); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
102 | auth->sn = sn; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
103 | auth->user = repo->user.value.ptr ? cx_strdup_a(sn->mp->allocator, cx_strcast(repo->user.value)).ptr : NULL; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
104 | auth->password = NULL; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
105 | dav_session_set_authcallback(sn, jobthr_davbrowser_auth, auth); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
106 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
107 | davbrowser_query_path(ui, browser, path); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
108 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
56
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
110 | // ------------------------------ davbrowser_auth ------------------------------ |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
111 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
112 | static int davbrowser_auth_dialog(void *data) { |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
113 | SessionAuthData *auth = data; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
114 | auth_dialog(auth); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
115 | return 0; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
116 | } |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
117 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
118 | void davbrowser_auth_set_user_pwd(SessionAuthData *auth, const char *user, const char *password) { |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
119 | dav_session_free(auth->sn, auth->user); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
120 | dav_session_free(auth->sn, auth->password); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
121 | auth->user = user ? dav_session_strdup(auth->sn, user) : NULL; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
122 | auth->password = password ? dav_session_strdup(auth->sn, password) : NULL; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
123 | } |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
124 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
125 | int jobthr_davbrowser_auth(DavSession *sn, void *data) { |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
126 | SessionAuthData *auth = data; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
127 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
128 | ui_call_mainthread(davbrowser_auth_dialog, auth); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
129 | ui_condvar_wait(auth->cond); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
130 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
131 | if(auth->cond->intdata) { |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
132 | dav_session_set_auth(sn, auth->user, auth->password); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
133 | } |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
134 | dav_session_free(auth->sn, auth->password); |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
135 | auth->password = NULL; |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
136 | |
294d5515583a
add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
137 | return 0; |
8
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 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | // ------------------------------ davbrowser_query_path ------------------------------ |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | typedef struct DavBrowserQueryPath { |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
144 | UiThreadpool *pool; |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | DavBrowser *browser; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | char *path; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | DavResource *result; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | } DavBrowserQueryPath; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | static int browser_query_path(void *data) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | DavBrowserQueryPath *query = data; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | DavSession *sn = query->browser->sn; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
16
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
154 | 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
|
155 | query->result = res; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | return 0; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | static void browser_query_finished(UiEvent *event, void *data) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | DavBrowserQueryPath *query = data; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | DavBrowser *browser = event->document; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
164 | 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
|
165 | if (query->result) { |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
166 | 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
|
167 | } else { |
58
0d25f15e2625
add minimal query error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
168 | cxmutstr error = cx_asprintf("Error %d", query->browser->sn->error); |
0d25f15e2625
add minimal query error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
169 | ui_dialog(event->obj, .title = "Error", .content = error.ptr, .closebutton_label = "OK"); |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
170 | } |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
171 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
172 | window_progress(event->window, 0); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | } else { |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
174 | // operation aborted |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
175 | if (query->result) { |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
176 | 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
|
177 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | free(query->path); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | free(query); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | 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
|
185 | if (!browser->sn) { |
7cfd36aa005b
add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
186 | // TODO: error |
7cfd36aa005b
add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
187 | return; |
7cfd36aa005b
add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
188 | } |
7cfd36aa005b
add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
189 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | // 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
|
191 | size_t len = path ? strlen(path) : 0; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | if (len == 1 && *path == '/') { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | path = ""; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | } |
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
|
195 | |
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
|
196 | // 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
|
197 | // 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
|
198 | 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
|
199 | char *full_path_col = util_concat_path(full_path, "/"); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | if (!cx_strprefix(cpath, newc)) { |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | ui_set(browser->path, full_path); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | 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
|
207 | free(full_path_col); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | 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
|
210 | query->pool = browser->dav_queue; |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | query->browser = browser; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | query->path = strdup(path); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | query->result = NULL; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | 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
|
215 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | window_progress(ui->window, 1); |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
217 | |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
218 | davbrowser_add2navstack(browser, browser->repo_base, path); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | } |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
220 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
221 | 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
|
222 | if (browser->repo_base) { |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
223 | 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
|
224 | cxstring newurl = cx_str(url); |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
225 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
226 | if (cx_strprefix(newurl, base)) { |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
227 | 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
|
228 | 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
|
229 | return; |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
230 | } |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
231 | } |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
232 | |
16
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | |
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
237 | 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
|
238 | 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
|
239 | } |
f2e79b69d233
switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
240 | 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
|
241 | 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
|
242 | } |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
243 | } |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
244 | |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
245 | void davbrowser_open_resource(UiObject *ui, DavBrowser *browser, DavResource *res, const char *contenttype) { |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
246 | DavResourceViewType type = DAV_RESOURCE_VIEW_PROPERTIES; |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
247 | if(!contenttype) { |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
248 | contenttype = res->contenttype; |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
249 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
250 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
251 | if(res->iscollection) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
252 | // default type |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
253 | } else if(contenttype) { |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
254 | cxstring ctype = cx_str(contenttype); |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
255 | if(cx_strprefix(ctype, CX_STR("text/"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
256 | type = DAV_RESOURCE_VIEW_TEXT; |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
257 | } else if(cx_strprefix(ctype, CX_STR("image/"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
258 | type = DAV_RESOURCE_VIEW_IMAGE; |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
259 | } else if(cx_strprefix(ctype, CX_STR("application/"))) { |
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
260 | if(cx_strsuffix(ctype, CX_STR("json"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
261 | type = DAV_RESOURCE_VIEW_TEXT; |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
262 | } else if(cx_strsuffix(ctype, CX_STR("/xml"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
263 | type = DAV_RESOURCE_VIEW_TEXT; |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
264 | } else if(cx_strsuffix(ctype, CX_STR("+xml"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
265 | type = DAV_RESOURCE_VIEW_TEXT; |
53
da05df77652e
add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
266 | } else if(cx_strsuffix(ctype, CX_STR("/xml"))) { |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
267 | type = DAV_RESOURCE_VIEW_TEXT; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
268 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
269 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
270 | } else { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
271 | cxstring path = cx_str(res->path); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
272 | if(cx_strsuffix(path, CX_STR(".png"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
273 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
274 | } else if(cx_strsuffix(path, CX_STR(".jpg"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
275 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
276 | } else if(cx_strsuffix(path, CX_STR(".jpeg"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
277 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
278 | } else if(cx_strsuffix(path, CX_STR(".tif"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
279 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
280 | } else if(cx_strsuffix(path, CX_STR(".tiff"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
281 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
282 | } else if(cx_strsuffix(path, CX_STR(".webp"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
283 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
284 | } else if(cx_strsuffix(path, CX_STR(".bmp"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
285 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
286 | } else if(cx_strsuffix(path, CX_STR(".gif"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
287 | type = DAV_RESOURCE_VIEW_IMAGE; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
288 | } else if(cx_strsuffix(path, CX_STR(".txt"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
289 | type = DAV_RESOURCE_VIEW_TEXT; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
290 | } else if(cx_strsuffix(path, CX_STR(".md"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
291 | type = DAV_RESOURCE_VIEW_TEXT; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
292 | } else if(cx_strsuffix(path, CX_STR(".xml"))) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
293 | type = DAV_RESOURCE_VIEW_TEXT; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
294 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
295 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
296 | |
52
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
297 | resourceviewer_new(browser, res->path, type); |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
298 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
299 | |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
300 | 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
|
301 | if (browser->navstack_enabled) { |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
302 | 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
|
303 | char *nav_url = cxListAt(browser->navigation_stack, 0); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
304 | cxListRemove(browser->navigation_stack, 0); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
305 | free(nav_url); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
306 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
307 | browser->navstack_pos = 0; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
308 | |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
309 | char *nav_url = util_concat_path(base, path); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
310 | cxListInsert(browser->navigation_stack, 0, nav_url); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
311 | |
49
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
312 | if (cxListSize(browser->navigation_stack) > DAVBROWSER_MAX_NAVLIST) { |
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
313 | char *nav = cxListAt(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1); |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
314 | free(nav); |
49
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
315 | cxListRemove(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1); |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
316 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
317 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
318 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
319 | |
68 | 320 | void davbrowser_navigation_parent(UiObject *ui, DavBrowser *browser) { |
321 | if(browser->current) { | |
322 | char *parent = util_parent_path(browser->current->path); | |
323 | if(strlen(parent) > 0) { | |
324 | davbrowser_query_path(ui, browser, parent); | |
325 | } | |
326 | free(parent); | |
327 | } | |
328 | } | |
329 | ||
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
330 | void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser) { |
49
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
331 | if (browser->navstack_pos+1 < cxListSize(browser->navigation_stack)) { |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
332 | browser->navstack_pos++; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
333 | 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
|
334 | browser->navstack_enabled = false; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
335 | davbrowser_query_url(ui, browser, nav_url); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
336 | browser->navstack_enabled = true; |
48
ae61523bce20
improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
337 | ui_set(browser->path, nav_url); |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
338 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
339 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
340 | |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
341 | void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser) { |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
342 | if (browser->navstack_pos > 0) { |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
343 | browser->navstack_pos--; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
344 | 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
|
345 | browser->navstack_enabled = false; |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
346 | davbrowser_query_url(ui, browser, nav_url); |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
347 | browser->navstack_enabled = true; |
48
ae61523bce20
improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
348 | ui_set(browser->path, nav_url); |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
349 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
350 | } |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
351 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
352 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
353 | // ------------------------------------- File Upload ------------------------------------- |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
354 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
355 | typedef struct DavFileUpload { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
356 | UiObject *ui; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
357 | DavBrowser *browser; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
358 | DavSession *sn; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
359 | UiFileList files; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
360 | char *base_path; |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
361 | UiThreadpool *queue; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
362 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
363 | size_t total_bytes; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
364 | size_t total_files; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
365 | size_t total_directories; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
366 | size_t uploaded_bytes; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
367 | size_t uploaded_files; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
368 | size_t uploaded_directories; |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
369 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
370 | DavBool upload_file; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
371 | size_t current_file_size; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
372 | size_t current_file_upload; |
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 | char *current_file_name; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
375 | |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
376 | UiObject *dialog; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
377 | UiDouble *progress; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
378 | UiString *label_top_left; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
379 | UiString *label_top_right; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
380 | UiString *label_bottom_left; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
381 | UiString *label_bottom_right; |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
382 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
383 | // The collection, the files are uploaded to |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
384 | // It is only safe to access the collection ptr, if |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
385 | // collection == browser->current && collection_ctn == browser->res_counter |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
386 | // 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
|
387 | DavResource *collection; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
388 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
389 | // copy of browser->res_counter, used for integrity check |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
390 | int64_t collection_ctn; |
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 | // current uploaded resource, created as part of the browser session |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
393 | // only if collection == browser->current && collection_ctn == browser->res_counter |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
394 | DavResource *current_resource; |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
395 | } DavFileUpload; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
396 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
397 | typedef struct DUFile { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
398 | char *path; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
399 | char *upload_path; |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
400 | size_t bytes; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
401 | DavBool isdirectory; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
402 | DavFileUpload *upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
403 | DavError error; |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
404 | } DUFile; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
405 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
406 | static double upload_progress(DavFileUpload *upload) { |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
407 | 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
|
408 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
409 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
410 | static void update_upload_labels(DavFileUpload *upload) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
411 | 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
|
412 | 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
|
413 | char *sz_uploaded_end = strchr(sz_uploaded, ' '); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
414 | if (sz_uploaded_end) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
415 | *sz_uploaded_end = 0; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
416 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
417 | |
25
915131bc3233
update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
418 | double progress = upload_progress(upload); |
915131bc3233
update upload progress bar in update_upload_labels()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
419 | 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
|
420 | |
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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | "%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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | } 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
|
430 | 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
|
431 | "%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
|
432 | 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
|
433 | 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
|
434 | } |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
435 | ui_set(upload->label_top_left, label1.ptr); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
436 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
437 | free(sz_total); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
438 | free(label1.ptr); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
439 | |
22
d7942163a2a3
don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
440 | 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
|
441 | 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
|
442 | 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
|
443 | 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
|
444 | } |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
445 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
446 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
447 | static int uithr_update_upload_labels(void *data) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
448 | update_upload_labels(data); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
449 | return 0; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
450 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
451 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
452 | 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
|
453 | DavFileUpload *upload = data; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
454 | if (upload->upload_file) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
455 | if (now > upload->current_file_size) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
456 | // 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
|
457 | // or we have some extra bytes because of encryption |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
458 | // adjust current_file_size and the total upload size |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
459 | int64_t extra = now - upload->current_file_size; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
460 | upload->current_file_size += extra; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
461 | upload->total_bytes += extra; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
462 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
463 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
464 | int64_t new_progress = now - upload->current_file_upload; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
465 | upload->uploaded_bytes += new_progress; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
466 | upload->current_file_upload = now; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
467 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
468 | ui_call_mainthread(uithr_update_upload_labels, upload); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
469 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
470 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
471 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
472 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
473 | typedef struct FileNameUpdate { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
474 | DavFileUpload *upload; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
475 | char *name; |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
476 | char *path; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
477 | DavBool iscollection; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
478 | } FileNameUpdate; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
479 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
480 | static int uithr_update_file_label(FileNameUpdate *update) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
481 | // replace upload->current_filename with update->name |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
482 | if (update->upload->current_file_name) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
483 | free(update->upload->current_file_name); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
484 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
485 | update->upload->current_file_name = update->name; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
486 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
487 | ui_set(update->upload->label_top_right, update->name); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
488 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
489 | DavFileUpload *upload = update->upload; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
490 | DavBrowser *browser = upload->browser; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
491 | // 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
|
492 | 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
|
493 | char *parent = util_parent_path(update->path); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
494 | cxstring parent_s = cx_str(parent); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
495 | cxstring colpath_s = cx_str(upload->collection->path); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
496 | 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
|
497 | parent_s.length--; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
498 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
499 | 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
|
500 | colpath_s.length--; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
501 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
502 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
503 | // 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
|
504 | if (!cx_strcmp(parent_s, colpath_s)) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
505 | 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
|
506 | ui_res->iscollection = update->iscollection; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
507 | ui_res->lastmodified = time(NULL); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
508 | ui_res->creationdate = time(NULL); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
509 | upload->current_resource = ui_res; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
510 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
511 | ui_list_append(browser->resources, ui_res); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
512 | browser->resources->update(browser->resources, 0); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
513 | } else { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
514 | upload->current_resource = NULL; // maybe not necessary |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
515 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
516 | free(parent); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
517 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
518 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
519 | free(update->path); |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
520 | free(update); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
521 | return 0; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
522 | } |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
523 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
524 | 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
|
525 | DUFile *f = data; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
526 | DavFileUpload *upload = f->upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
527 | DavSession *sn = upload->sn; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
528 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
529 | 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
|
530 | if (!in) { |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
531 | // TODO: error msg |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
532 | return 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
533 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
534 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
535 | upload->upload_file = TRUE; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
536 | upload->current_file_size = f->bytes; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
537 | upload->current_file_upload = 0; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
538 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
539 | 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
|
540 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
541 | FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate)); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
542 | ui_update->upload = upload; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
543 | ui_update->name = strdup(res->name); |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
544 | ui_update->path = strdup(res->path); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
545 | ui_update->iscollection = FALSE; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
546 | 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
|
547 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
548 | 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
|
549 | if (dav_store(res)) { |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
550 | f->error = sn->error; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
551 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
552 | dav_resource_free(res); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
553 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
554 | fclose(in); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
555 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
556 | upload->upload_file = FALSE; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
557 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
558 | return 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
559 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
560 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
561 | 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
|
562 | DUFile *file = data; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
563 | DavFileUpload *upload = file->upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
564 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
565 | upload->uploaded_files++; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
566 | //upload->uploaded_bytes += file->bytes; |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
567 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
568 | double progress = upload_progress(upload); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
569 | 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
|
570 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
571 | update_upload_labels(upload); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
572 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
573 | // update resource content length in the browser |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
574 | DavBrowser *browser = upload->browser; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
575 | 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
|
576 | if (upload->current_resource) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
577 | upload->current_resource->contentlength = upload->current_file_upload; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
578 | browser->resources->update(browser->resources, 0); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
579 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
580 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
581 | upload->current_resource = NULL; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
582 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
583 | free(file->path); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
584 | free(file->upload_path); |
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 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
587 | 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
|
588 | DUFile *f = data; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
589 | DavFileUpload *upload = f->upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
590 | DavSession *sn = upload->sn; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
591 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
592 | 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
|
593 | res->iscollection = TRUE; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
594 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
595 | FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate)); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
596 | ui_update->upload = upload; |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
597 | ui_update->name = strdup(res->name); |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
598 | ui_update->path = strdup(res->path); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
599 | ui_update->iscollection = TRUE; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
600 | 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
|
601 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
602 | if (dav_create(res)) { |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
603 | f->error = sn->error; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
604 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
605 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
606 | dav_resource_free(res); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
607 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
608 | return 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
609 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
610 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
611 | 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
|
612 | DUFile *file = data; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
613 | DavFileUpload *upload = file->upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
614 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
615 | upload->uploaded_directories++; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
616 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
617 | update_upload_labels(upload); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
618 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
619 | upload->current_resource = NULL; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
620 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
621 | free(file->path); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
622 | free(file->upload_path); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
623 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
624 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
625 | 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
|
626 | return 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
627 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
628 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
629 | 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
|
630 | DavFileUpload *upload = data; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
631 | ui_threadpool_destroy(upload->queue); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
632 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
633 | free(upload->base_path); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
634 | dav_session_destroy(upload->sn); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
635 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
636 | |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
637 | static int jobthr_upload_scan(void *data) { |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
638 | DavFileUpload *upload = data; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
639 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
640 | CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
641 | 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
|
642 | DUFile *f = malloc(sizeof(DUFile)); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
643 | 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
|
644 | 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
|
645 | f->isdirectory = FALSE; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
646 | f->bytes = 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
647 | f->upload = upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
648 | f->error = 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
649 | cxListInsert(stack, 0, f); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
650 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
651 | |
49
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
652 | while (cxListSize(stack) > 0) { |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
653 | DUFile *f = cxListAt(stack, 0); |
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 | 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
|
656 | cxListRemove(stack, 0); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
657 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
658 | SYS_STAT s; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
659 | if (!sys_stat(f->path, &s)) { |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
660 | 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
|
661 | f->isdirectory = TRUE; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
662 | upload->total_directories++; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
663 | 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
|
664 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
665 | SYS_DIR dir = sys_opendir(f->path); |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
666 | if (dir) { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
667 | SysDirEnt *entry; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
668 | int nument = 0; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
669 | while((entry = sys_readdir(dir)) != NULL) { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
670 | if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
671 | continue; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
672 | } |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
673 | |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
674 | 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
|
675 | 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
|
676 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
677 | DUFile *child = malloc(sizeof(DUFile)); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
678 | child->path = newpath.ptr; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
679 | child->upload_path = new_upload_path; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
680 | child->isdirectory = FALSE; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
681 | child->bytes = 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
682 | child->upload = upload; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
683 | child->error = 0; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
684 | cxListAdd(stack, child); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
685 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
686 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
687 | sys_closedir(dir); |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
688 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
689 | } 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
|
690 | f->isdirectory = FALSE; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
691 | f->bytes = s.st_size; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
692 | upload->total_files++; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
693 | upload->total_bytes += s.st_size; |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
694 | 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
|
695 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
696 | } |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
697 | } // TODO: else error msg |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
698 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
699 | 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
|
700 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
701 | ui_filelist_free(upload->files); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
702 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
703 | return 0; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
704 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
705 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
706 | 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
|
707 | DavFileUpload *upload = data; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
708 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
709 | update_upload_labels(upload); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
710 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
711 | |
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
|
712 | 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
|
713 | // 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
|
714 | } |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
715 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
716 | 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
|
717 | if (!browser->sn) { |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
718 | return; // TODO: error msg |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
719 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
720 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
721 | // 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
|
722 | // is done in a separate thread |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
723 | DavSession *upload_session = dav_session_clone(browser->sn); |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
724 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
725 | // 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
|
726 | DavFileUpload *upload = malloc(sizeof(DavFileUpload)); |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
727 | memset(upload, 0, sizeof(DavFileUpload)); |
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
728 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
729 | 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
|
730 | |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
731 | upload->ui = ui; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
732 | upload->browser = browser; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
733 | upload->sn = upload_session; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
734 | upload->files = files; |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
735 | 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
|
736 | upload->queue = ui_threadpool_create(1); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
737 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
738 | upload->collection = browser->current; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
739 | upload->collection_ctn = browser->res_counter; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
740 | |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
741 | // create upload progress window |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
742 | 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
|
743 | 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
|
744 | 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
|
745 | free(wtitle.ptr); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
746 | upload->dialog = dialog; |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
747 | ui_window_size(dialog, 550, 120); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
748 | upload->progress = ui_double_new(dialog->ctx, NULL); |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
749 | 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
|
750 | 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
|
751 | 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
|
752 | 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
|
753 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
754 | ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) { |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
755 | 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
|
756 | ui_rlabel(dialog, .value = upload->label_top_right); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
757 | ui_newline(dialog); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
758 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
759 | 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
|
760 | ui_newline(dialog); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
761 | |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
762 | ui_llabel(dialog, .value = upload->label_bottom_left); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
763 | ui_rlabel(dialog, .value = upload->label_bottom_right); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
764 | ui_newline(dialog); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
765 | } |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
766 | |
20
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
767 | ui_set(upload->label_top_left, ""); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
768 | ui_set(upload->label_top_right, ""); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
769 | ui_set(upload->label_bottom_left, ""); |
db263186edf3
improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
770 | ui_set(upload->label_bottom_right, ""); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
771 | ui_set(upload->progress, 0); |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
772 | |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
773 | ui_show(dialog); |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
774 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
775 | // start upload and stat threads |
19
813c97c5b6d3
add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
776 | 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
|
777 | } |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
778 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
779 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
780 | // ------------------------------------- File Download ------------------------------------- |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
781 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
782 | typedef struct DavFileDownload { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
783 | UiObject *ui; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
784 | DavBrowser *browser; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
785 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
786 | DavSession *sn; |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
787 | DavSession *download_sn; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
788 | DavResource *reslist; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
789 | char *local_path; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
790 | DavBool isdirectory; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
791 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
792 | UiThreadpool *queue; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
793 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
794 | size_t total_bytes; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
795 | size_t total_files; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
796 | size_t total_directories; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
797 | size_t downloaded_bytes; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
798 | size_t downloaded_files; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
799 | size_t downloaded_directories; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
800 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
801 | size_t current_file_size; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
802 | size_t current_file_downloaded; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
803 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
804 | UiObject *dialog; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
805 | UiDouble *progress; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
806 | UiString *label_top_left; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
807 | UiString *label_top_right; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
808 | UiString *label_bottom_left; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
809 | UiString *label_bottom_right; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
810 | } DavFileDownload; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
811 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
812 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
813 | static int uithr_download_update_progress(void *data) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
814 | DavFileDownload *download = data; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
815 | 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
|
816 | 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
|
817 | char *sz_downloaded_end = strchr(sz_downloaded, ' '); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
818 | if (sz_downloaded_end) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
819 | *sz_downloaded_end = 0; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
820 | } |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
821 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
822 | if (download->total_bytes > 0) { |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
823 | 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
|
824 | ui_set(download->progress, progress*100); |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
825 | } |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
826 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
827 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
828 | cxmutstr label1; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
829 | if (download->total_files + download->total_directories > 1) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
830 | label1 = cx_asprintf( |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
831 | "%s/%s %zu/%zu files", |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
832 | sz_downloaded, |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
833 | sz_total, |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
834 | download->downloaded_files+download->downloaded_directories, |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
835 | download->total_files+download->total_directories); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
836 | } else { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
837 | label1 = cx_asprintf( |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
838 | "%s/%s", |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
839 | sz_downloaded, |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
840 | sz_total); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
841 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
842 | ui_set(download->label_top_left, label1.ptr); |
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 | free(sz_total); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
845 | free(label1.ptr); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
846 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
847 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
848 | return 1; |
30
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 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
851 | // dav download file |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
852 | typedef struct DDFile { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
853 | DavFileDownload *download; |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
854 | size_t size; |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
855 | char *path; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
856 | char *to; |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
857 | FILE *fd; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
858 | } DDFile; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
859 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
860 | 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
|
861 | DDFile *file = stream; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
862 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
863 | size_t w = fwrite(buf, size, count, file->fd); |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
864 | file->download->current_file_downloaded += w; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
865 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
866 | file->download->downloaded_bytes += w; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
867 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
868 | 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
|
869 | 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
|
870 | 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
|
871 | file->download->total_bytes += diff; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
872 | } |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
873 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
874 | ui_call_mainthread(uithr_download_update_progress, file->download); |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
875 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
876 | return w; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
877 | } |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
878 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
879 | static int qthr_download_resource(void *data) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
880 | DDFile *file = data; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
881 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
882 | file->download->current_file_downloaded = 0; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
883 | file->download->current_file_size = file->size; |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
884 | |
77
5de33c2d94c6
fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
885 | FILE *f = sys_fopen(file->to, "wb"); |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
886 | if (!f) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
887 | return 0; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
888 | } |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
889 | file->fd = f; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
890 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
891 | 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
|
892 | 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
|
893 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
894 | file->download->downloaded_files++; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
895 | |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
896 | ui_call_mainthread(uithr_download_update_progress, file->download); |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
897 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
898 | dav_resource_free(res); |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
899 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
900 | fclose(f); |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
901 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
902 | free(file->path); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
903 | free(file->to); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
904 | free(file); |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
905 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
906 | return 0; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
907 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
908 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
909 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
910 | typedef struct DlStackElm { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
911 | DavResource *resource; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
912 | char *sub_path; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
913 | } DlStackElm; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
914 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
915 | static int jobthr_download_scan(void *data) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
916 | DavFileDownload *download = data; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
917 | DavBrowser *browser = download->browser; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
918 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
919 | // check if the specified local location is a directory |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
920 | SYS_STAT s; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
921 | if (!sys_stat(download->local_path, &s)) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
922 | if (S_ISDIR(s.st_mode)) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
923 | download->isdirectory = TRUE; |
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 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
926 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
927 | CxList *stack = cxLinkedListCreateSimple(sizeof(DlStackElm)); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
928 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
929 | // add selected files to the download queue |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
930 | DavResource *res = download->reslist; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
931 | while (res) { |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
932 | DlStackElm elm; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
933 | elm.resource = res; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
934 | elm.sub_path = strdup(res->name); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
935 | cxListAdd(stack, &elm); |
29
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 | res = res->next; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
938 | } |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
939 | |
49
2f71f4ee247a
update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
940 | while (cxListSize(stack) > 0) { |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
941 | DlStackElm *elm = cxListAt(stack, 0); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
942 | DavResource *res = elm->resource; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
943 | char *sub_path = elm->sub_path; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
944 | cxListRemove(stack, 0); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
945 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
946 | if (res->iscollection) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
947 | if (dav_load(res)) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
948 | // TODO: handle error |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
949 | continue; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
950 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
951 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
952 | // update ui |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
953 | ui_call_mainthread(uithr_download_update_progress, download); |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
954 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
955 | 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
|
956 | int err = sys_mkdir(path); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
957 | free(path); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
958 | if (err) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
959 | // TODO: handle error |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
960 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
961 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
962 | DavResource *child = res->children; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
963 | while (child) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
964 | 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
|
965 | DlStackElm childelm; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
966 | childelm.resource = child; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
967 | childelm.sub_path = child_path; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
968 | cxListAdd(stack, &childelm); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
969 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
970 | child = child->next; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
971 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
972 | } else { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
973 | // add the file to the download queue |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
974 | DDFile *file = malloc(sizeof(DDFile)); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
975 | file->download = download; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
976 | file->path = strdup(res->path); |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
977 | file->size = res->contentlength; |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
978 | if (download->isdirectory) { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
979 | 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
|
980 | } else { |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
981 | file->to = strdup(download->local_path); |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
982 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
983 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
984 | // stats |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
985 | download->total_files++; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
986 | download->total_bytes += res->contentlength; |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
987 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
988 | // update ui |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
989 | ui_call_mainthread(uithr_download_update_progress, download); |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
990 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
991 | 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
|
992 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
993 | } |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
994 | |
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
995 | cxListDestroy(stack); |
31
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
996 | |
bf810176ddb8
implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
997 | return 0; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
998 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
999 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1000 | 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
|
1001 | DavFileDownload *download = data; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1002 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1003 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1004 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1005 | static void download_window_closed(UiEvent *event, void *data) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1006 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1007 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1008 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1009 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1010 | 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
|
1011 | DavFileDownload *download = malloc(sizeof(DavFileDownload)); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1012 | memset(download, 0, sizeof(DavFileDownload)); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1013 | |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
1014 | download->ui = ui; |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1015 | download->browser = browser; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1016 | download->sn = reslist->session; |
30
762afc7adc63
implement recursive collection downloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
1017 | download->download_sn = dav_session_clone(download->sn); |
52
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1018 | download->reslist = reslist; // TODO: is this safe or do we need a copy? |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1019 | download->local_path = strdup(local_path); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1020 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1021 | download->queue = ui_threadpool_create(1); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1022 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1023 | // create download progress window |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1024 | cxmutstr wtitle = cx_asprintf("Download to: %s", local_path); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1025 | UiObject *dialog = ui_simple_window(wtitle.ptr, download); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1026 | ui_context_closefunc(dialog->ctx, download_window_closed, NULL); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1027 | free(wtitle.ptr); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1028 | download->dialog = dialog; |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1029 | ui_window_size(dialog, 550, 120); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1030 | download->progress = ui_double_new(dialog->ctx, NULL); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1031 | 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
|
1032 | 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
|
1033 | 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
|
1034 | 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
|
1035 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1036 | ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1037 | 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
|
1038 | ui_rlabel(dialog, .value = download->label_top_right); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1039 | ui_newline(dialog); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1040 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
1041 | 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
|
1042 | ui_newline(dialog); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1043 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1044 | ui_llabel(dialog, .value = download->label_bottom_left); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1045 | ui_rlabel(dialog, .value = download->label_bottom_right); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1046 | ui_newline(dialog); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1047 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1048 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1049 | ui_set(download->label_top_left, ""); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1050 | ui_set(download->label_top_right, ""); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1051 | ui_set(download->label_bottom_left, ""); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1052 | ui_set(download->label_bottom_right, ""); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1053 | ui_set(download->progress, 0); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1054 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1055 | ui_show(dialog); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1056 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1057 | // start upload and stat threads |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1058 | 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
|
1059 | } |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1060 | |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1061 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1062 | // ------------------------------------- Path Operation (DELETE, MKCOL) ------------------------------------- |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1063 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1064 | enum DavPathOpType { |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1065 | DAV_PATH_OP_DELETE = 0, |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1066 | DAV_PATH_OP_CREATE |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1067 | }; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1068 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1069 | typedef struct DavPathOp { |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1070 | UiObject *ui; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1071 | DavBrowser *browser; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1072 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1073 | // operation type (delete, mkcol, ...) |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1074 | enum DavPathOpType op; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1075 | // clone of the browser's DavSession |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1076 | DavSession *sn; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1077 | // path array |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1078 | char **path; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1079 | // browser->resources indices |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1080 | size_t *list_indices; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1081 | // number of path/list_indices elements |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1082 | size_t nelm; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1083 | // path is collection |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1084 | DavBool iscollection; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1085 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1086 | // 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
|
1087 | // 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
|
1088 | DavResource *collection; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1089 | int64_t collection_ctn; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1090 | } DavPathOp; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1091 | |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1092 | typedef struct DavPathOpResult { |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1093 | UiObject *ui; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1094 | DavBrowser *browser; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1095 | DavResource *collection; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1096 | int64_t collection_ctn; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1097 | enum DavPathOpType op; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1098 | DavBool iscollection; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1099 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1100 | char *path; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1101 | int res_index; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1102 | int result; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1103 | char *errormsg; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1104 | } DavPathOpResult; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1105 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1106 | 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
|
1107 | DavPathOpResult *result = data; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1108 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1109 | 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
|
1110 | 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
|
1111 | free(msg.ptr); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1112 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1113 | if (result->errormsg) { |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1114 | free(result->errormsg); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1115 | } |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1116 | free(result->path); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1117 | free(result); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1118 | return 0; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1119 | } |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1120 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1121 | 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
|
1122 | DavPathOpResult *result = data; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1123 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1124 | 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
|
1125 | 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
|
1126 | 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
|
1127 | } |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1128 | |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1129 | free(result->path); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1130 | free(result); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1131 | return 0; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1132 | } |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1133 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1134 | 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
|
1135 | DavPathOpResult *result = data; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1136 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1137 | 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
|
1138 | 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
|
1139 | free(msg.ptr); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1140 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1141 | if (result->errormsg) { |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1142 | free(result->errormsg); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1143 | } |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1144 | free(result->path); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1145 | free(result); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1146 | return 0; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1147 | } |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1148 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1149 | 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
|
1150 | DavPathOpResult *result = data; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1151 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1152 | 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
|
1153 | 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
|
1154 | res->iscollection = result->iscollection; |
28
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1155 | // 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
|
1156 | ui_list_append(result->browser->resources, res); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1157 | result->browser->resources->update(result->browser->resources, 0); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1158 | } |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1159 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1160 | free(result->path); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1161 | free(result); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1162 | return 0; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1163 | } |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1164 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1165 | static int jobthr_path_op(void *data) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1166 | DavPathOp *op = data; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1167 | |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1168 | for (int i = op->nelm-1; i >= 0; i--) { |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1169 | if (op->path[i]) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1170 | DavResource *res = dav_resource_new(op->sn, op->path[i]); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1171 | |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1172 | DavPathOpResult *result = malloc(sizeof(DavPathOpResult)); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1173 | result->ui = op->ui; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1174 | result->browser = op->browser; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1175 | result->collection = op->collection; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1176 | result->collection_ctn = op->collection_ctn; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1177 | result->op = op->op; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1178 | result->path = strdup(res->path); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1179 | result->result = 0; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1180 | 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
|
1181 | result->errormsg = NULL; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1182 | result->iscollection = op->iscollection; |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1183 | |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1184 | 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
|
1185 | 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
|
1186 | if (dav_delete(res)) { |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1187 | 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
|
1188 | result_callback = uithr_pathop_delete_error; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1189 | } |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1190 | ui_call_mainthread(result_callback, result); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1191 | } else if (op->op == DAV_PATH_OP_CREATE) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1192 | res->iscollection = op->iscollection; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1193 | 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
|
1194 | if (dav_create(res)) { |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1195 | 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
|
1196 | result_callback = uithr_pathop_create_resource_error; |
28
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1197 | } |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1198 | ui_call_mainthread(result_callback, result); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1199 | } |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1200 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1201 | dav_resource_free(res); |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1202 | free(op->path[i]); |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1203 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1204 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1205 | |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1206 | dav_session_destroy(op->sn); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1207 | free(op->path); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1208 | free(op->list_indices); |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1209 | free(op); |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1210 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1211 | return 0; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1212 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1213 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1214 | void davbrowser_delete(UiObject *ui, DavBrowser *browser, UiListSelection selection) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1215 | DavPathOp *op = malloc(sizeof(DavPathOp)); |
27
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1216 | op->ui = ui; |
c254ed644edf
remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
1217 | op->browser = browser; |
26
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1218 | op->op = DAV_PATH_OP_DELETE; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1219 | op->sn = dav_session_clone(browser->sn); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1220 | op->path = calloc(selection.count, sizeof(char*)); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1221 | op->list_indices = calloc(selection.count, sizeof(size_t)); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1222 | op->nelm = selection.count; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1223 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1224 | op->collection = browser->current; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1225 | op->collection_ctn = browser->res_counter; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1226 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1227 | for (int i = 0; i < selection.count; i++) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1228 | DavResource *res = ui_list_get(browser->resources, selection.rows[i]); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1229 | if (res) { |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1230 | op->path[i] = strdup(res->path); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1231 | op->list_indices[i] = selection.rows[i]; |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1232 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1233 | } |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1234 | |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1235 | ui_job(ui, jobthr_path_op, op, NULL, NULL); |
40d6af793c1a
implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
1236 | } |
28
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1237 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1238 | 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
|
1239 | DavPathOp *op = malloc(sizeof(DavPathOp)); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1240 | op->ui = ui; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1241 | op->browser = browser; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1242 | op->op = DAV_PATH_OP_CREATE; |
28
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1243 | op->sn = dav_session_clone(browser->sn); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1244 | op->path = calloc(1, sizeof(char*)); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1245 | op->list_indices = calloc(1, sizeof(size_t)); |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1246 | op->nelm = 1; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1247 | op->iscollection = iscollection; |
28
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1248 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1249 | 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
|
1250 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1251 | op->collection = browser->current; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1252 | op->collection_ctn = browser->res_counter; |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1253 | |
1ecc1183f046
implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1254 | 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
|
1255 | } |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1256 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1257 | void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1258 | davbrowser_create_resource(ui, browser, name, TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1259 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1260 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1261 | void davbrowser_newfile(UiObject *ui, DavBrowser *browser, const char *name) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1262 | davbrowser_create_resource(ui, browser, name, FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
1263 | } |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1264 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1265 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1266 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1267 | DavResourceViewer* dav_resourceviewer_create(DavSession *sn, const char *path, DavResourceViewType type) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1268 | DavResourceViewer *doc = ui_document_new(sizeof(DavResourceViewer)); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1269 | UiContext *ctx = ui_document_context(doc); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1270 | doc->ctx = ctx; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1271 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1272 | doc->sn = dav_session_clone(sn); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1273 | doc->path = strdup(path); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1274 | doc->type = type; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1275 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1276 | doc->tabview = ui_int_new(ctx, "tabview"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1277 | doc->loading = ui_int_new(ctx, "loading"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1278 | doc->message = ui_string_new(ctx, "message"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1279 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1280 | doc->text = ui_text_new(ctx, "text"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1281 | doc->image = ui_generic_new(ctx, "image"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1282 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1283 | doc->properties = ui_list_new(ctx, "properties"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1284 | |
52
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1285 | doc->info_url = ui_string_new(ctx, "info_url"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1286 | doc->info_name = ui_string_new(ctx, "info_name"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1287 | doc->info_type = ui_string_new(ctx, "info_type"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1288 | doc->info_encrypted = ui_string_new(ctx, "info_encrypted"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1289 | doc->info_etag = ui_string_new(ctx, "info_etag"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1290 | doc->info_size = ui_string_new(ctx, "info_size"); |
0c881944fa10
add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1291 | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1292 | return doc; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1293 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1294 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1295 | static char* gen_tmp_download_filename(const char *name) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1296 | char *dir = ui_getappdir(); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1297 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1298 | unsigned char rd[8]; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1299 | memset(rd, 0, 8); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1300 | dav_rand_bytes(rd, 8); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1301 | char *hex = util_hexstr(rd, 8); |
77
5de33c2d94c6
fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1302 | cxmutstr tmp = cx_asprintf("%sdownload-%s-%s", dir, hex, name); |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1303 | return tmp.ptr; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1304 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1305 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1306 | static int jobthr_resourceviewer_load(void *data) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1307 | DavResourceViewer *doc = data; |
54
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1308 | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1309 | DavResource *res = dav_resource_new(doc->sn, doc->path); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1310 | doc->error = dav_load(res); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1311 | if(!doc->error) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1312 | doc->current = res; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1313 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1314 | if(res->contentlength < DAV_RESOURCEVIEWER_PREVIEW_MAX_SIZE) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1315 | if(doc->type == DAV_RESOURCE_VIEW_TEXT) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1316 | doc->text_content = cxBufferCreate(NULL, res->contentlength, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1317 | int err = dav_get_content(res, doc->text_content, (dav_write_func)cxBufferWrite); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1318 | cxBufferPut(doc->text_content, 0); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1319 | if(err) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1320 | doc->error = err; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1321 | doc->message_str = "Cannot load content"; // TODO: better message |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1322 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1323 | } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1324 | char *tmp = gen_tmp_download_filename(res->name); |
77
5de33c2d94c6
fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1325 | FILE *f = sys_fopen(tmp, "wb"); |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1326 | if(f) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1327 | int err = dav_get_content(res, f, (dav_write_func)fwrite); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1328 | if(!err) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1329 | doc->tmp_file = tmp; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1330 | } else { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1331 | free(tmp); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1332 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1333 | fclose(f); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1334 | } else { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1335 | free(tmp); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1336 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1337 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1338 | } else { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1339 | // TODO: add file too large message |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1340 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1341 | } else { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1342 | doc->message_str = "Cannot load properties"; // TODO: better message |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1343 | dav_resource_free(res); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1344 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1345 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1346 | return 0; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1347 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1348 | |
54
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1349 | static void resourceviewer_set_info(DavResourceViewer *doc) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1350 | DavResource *res = doc->current; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1351 | if(!res) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1352 | return; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1353 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1354 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1355 | char *url = util_concat_path(res->session->base_url, res->href); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1356 | ui_set(doc->info_url, url); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1357 | free(url); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1358 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1359 | ui_set(doc->info_name, res->name); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1360 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1361 | if(res->iscollection) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1362 | ui_set(doc->info_type, "Collection"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1363 | } else { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1364 | if(res->contenttype) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1365 | cxmutstr type = cx_asprintf("Resource (%s)", res->contenttype); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1366 | ui_set(doc->info_type, type.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1367 | free(type.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1368 | } else { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1369 | ui_set(doc->info_type, "Resource"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1370 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1371 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1372 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1373 | char *keyprop = dav_get_string_property_ns( |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1374 | res, |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1375 | DAV_NS, |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1376 | "crypto-key"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1377 | if(keyprop) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1378 | cxmutstr info_encrypted = cx_asprintf("Yes Key: %s", keyprop); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1379 | ui_set(doc->info_encrypted, info_encrypted.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1380 | free(info_encrypted.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1381 | } else { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1382 | ui_set(doc->info_encrypted, "No"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1383 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1384 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1385 | char *etag = dav_get_string_property_ns( |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1386 | res, |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1387 | "DAV:", |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1388 | "getetag"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1389 | ui_set(doc->info_etag, etag); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1390 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1391 | if(res->contentlength > 0) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1392 | char *sz = util_size_str(FALSE, res->contentlength); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1393 | cxmutstr size_str = cx_asprintf("%s (%" PRIu64 " bytes)", sz, res->contentlength); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1394 | ui_set(doc->info_size, size_str.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1395 | free(size_str.ptr); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1396 | } else { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1397 | ui_set(doc->info_size, "0"); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1398 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1399 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1400 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1401 | static void resourceviewer_update_proplist(DavResourceViewer *doc) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1402 | DavResource *res = doc->current; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1403 | if(!res) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1404 | return; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1405 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1406 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1407 | size_t count = 0; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1408 | DavPropName *properties = dav_get_property_names(res, &count); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1409 | for(int i=0;i<count;i++) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1410 | DavPropertyList *prop = ui_malloc(doc->ctx, sizeof(DavPropertyList)); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1411 | prop->ns = properties[i].ns ? ui_strdup(doc->ctx, properties[i].ns) : NULL; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1412 | prop->name = ui_strdup(doc->ctx, properties[i].name); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1413 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1414 | DavXmlNode *xval = dav_get_property_ns(res, prop->ns, prop->name); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1415 | if(xval) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1416 | if(dav_xml_isstring(xval)) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1417 | char *value = dav_xml_getstring(xval); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1418 | if(value) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1419 | prop->value_simplified = NULL; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1420 | prop->value_full = ui_strdup(doc->ctx, value); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1421 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1422 | } else { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1423 | DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1424 | cxmutstr value = cx_asprintf_a(ui_allocator(doc->ctx), "<%s>...</%s>", x->name, x->name); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1425 | prop->value_simplified = value.ptr; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1426 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1427 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1428 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1429 | ui_list_append(doc->properties, prop); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1430 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1431 | doc->properties->update(doc->properties, 0); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1432 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1433 | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1434 | static void resourceviewer_load_finished(UiEvent *event, void *data) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1435 | DavResourceViewer *doc = data; |
54
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1436 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1437 | if(doc->window_closed) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1438 | dav_resourceviewer_destroy(doc); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1439 | return; |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1440 | } |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1441 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1442 | resourceviewer_set_info(doc); |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1443 | resourceviewer_update_proplist(doc); |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1444 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1445 | if(doc->type == DAV_RESOURCE_VIEW_TEXT) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1446 | ui_set(doc->text, doc->text_content->space); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1447 | } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1448 | ui_image_load_file(doc->image, doc->tmp_file); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1449 | } |
54
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1450 | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1451 | ui_set(doc->tabview, 1); |
78
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1452 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1453 | doc->loaded = TRUE; |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1454 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1455 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1456 | void dav_resourceviewer_load(UiObject *ui, DavResourceViewer *res) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1457 | ui_set(res->loading, 1); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1458 | ui_set(res->message, "Loading..."); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1459 | ui_set(res->tabview, 0); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1460 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1461 | ui_job(ui, jobthr_resourceviewer_load, res, resourceviewer_load_finished, res); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1462 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1463 | |
78
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1464 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1465 | typedef struct ResourceViewerUploadFile { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1466 | UiObject *ui; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1467 | DavSession *sn; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1468 | char *path; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1469 | cxmutstr text; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1470 | int error; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1471 | } ResourceViewerUploadFile; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1472 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1473 | static int jobthr_upload_text(void *data) { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1474 | ResourceViewerUploadFile *upload = data; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1475 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1476 | DavResource *res = dav_resource_new(upload->sn, upload->path); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1477 | dav_set_content_data(res, upload->text.ptr, upload->text.length); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1478 | upload->error = dav_store(res); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1479 | dav_resource_free(res); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1480 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1481 | return 0; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1482 | } |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1483 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1484 | static void uithr_upload_text_finished(UiEvent *event, void *data) { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1485 | ResourceViewerUploadFile *upload = data; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1486 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1487 | if(upload->error) { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1488 | cxmutstr errormsg = cx_asprintf("Upload failed: %d", upload->sn->error); // TODO: add full error message |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1489 | ui_dialog(event->obj, .title = "Error", .content = errormsg.ptr, .closebutton_label = "OK"); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1490 | free(errormsg.ptr); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1491 | ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1492 | } |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1493 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1494 | dav_session_destroy(upload->sn); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1495 | free(upload->path); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1496 | free(upload->text.ptr); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1497 | free(upload); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1498 | } |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1499 | |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1500 | void dav_resourceviewer_save(UiObject *ui, DavResourceViewer *res) { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1501 | if(res->type == DAV_RESOURCE_VIEW_TEXT) { |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1502 | DavSession *newsn = dav_session_clone(res->current->session); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1503 | ResourceViewerUploadFile *upload = malloc(sizeof(ResourceViewerUploadFile)); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1504 | upload->ui = ui; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1505 | upload->sn = newsn; |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1506 | upload->path = strdup(res->current->path); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1507 | char *text = ui_get(res->text); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1508 | size_t textlen = strlen(text); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1509 | upload->text = cx_strdup(cx_strn(text, textlen)); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1510 | ui_job(ui, jobthr_upload_text, upload, uithr_upload_text_finished, upload); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1511 | ui_unset_group(ui->ctx, RESOURCEVIEWER_STATE_MODIFIED); |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1512 | } |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1513 | } |
ad7ced6cf00b
implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1514 | |
54
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1515 | void dav_resourceviewer_destroy(DavResourceViewer *res) { |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1516 | |
3ca3acefc66a
add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
1517 | } |