application/davcontroller.c

Thu, 08 Feb 2024 10:31:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 08 Feb 2024 10:31:19 +0100
changeset 24
12ad3393c151
parent 22
d7942163a2a3
child 25
915131bc3233
permissions
-rw-r--r--

don't show number of uploading files when there is only 1 file

8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "davcontroller.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "window.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <cx/printf.h>
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
34 #include "config.h"
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
35
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
36 #include "system.h"
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
37
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
38 #include <libidav/config.h>
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include <libidav/utils.h>
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 DavBrowser* davbrowser_create(UiObject *toplevel) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 DavBrowser *doc = ui_document_new(sizeof(DavBrowser));
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 UiContext *ctx = ui_document_context(doc);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 doc->ctx = ctx;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
46 doc->navigation_stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
47 doc->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
48 doc->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
49
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 doc->dav_queue = ui_threadpool_create(1);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 doc->path = ui_string_new(ctx, "path");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 doc->resources = ui_list_new(ctx, "reslist");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return doc;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 void davbrowser_set_collection(UiObject *ui, DavBrowser *browser, DavResource *collection) {
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
60 if (browser->current) {
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
61 dav_resource_free_all(browser->current);
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
62 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 ui_list_clear(browser->resources);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
65 browser->current = collection;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 for (DavResource *res = collection->children; res; res = res->next) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 ui_list_append(browser->resources, res);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 browser->resources->update(browser->resources, 0);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
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 // ------------------------------ davbrowser_connect2repo ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
75 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
76 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
77 if (repo->user.value.ptr && repo->password.value.ptr) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 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
80 free(decodedpw.ptr);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 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
83 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
84 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
85 } else {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
86 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
87 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
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 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
90 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
91 free(dav_path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
93 davbrowser_query_path(ui, browser, path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 // ------------------------------ davbrowser_query_path ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 typedef struct DavBrowserQueryPath {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
100 UiThreadpool *pool;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 DavBrowser *browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 char *path;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 DavResource *result;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 } DavBrowserQueryPath;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 static int browser_query_path(void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 DavSession *sn = query->browser->sn;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
110 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
111 query->result = res;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 return 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 static void browser_query_finished(UiEvent *event, void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 DavBrowser *browser = event->document;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
120 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
121 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
122 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
123 } else {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
124 // TODO: error
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
125 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
126
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
127 window_progress(event->window, 0);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 } else {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
129 // operation aborted
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
130 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
131 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
132 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 free(query->path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 free(query);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
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 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
140 if (!browser->sn) {
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
141 // TODO: error
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
142 return;
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
143 }
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
144
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 // 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
146 size_t len = path ? strlen(path) : 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 if (len == 1 && *path == '/') {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 path = "";
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 }
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
150
3eb0cbab53db don't change the path bar value if the new path is a prefix of the current path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
151 // 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
152 // 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
153 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
154 char *full_path_col = util_concat_path(full_path, "/");
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 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
156 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
157 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
158 if (!cx_strprefix(cpath, newc)) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 ui_set(browser->path, full_path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 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
162 free(full_path_col);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 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
165 query->pool = browser->dav_queue;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 query->browser = browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 query->path = strdup(path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 query->result = NULL;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 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
170
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 window_progress(ui->window, 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
172
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
173 davbrowser_add2navstack(browser, browser->repo_base, path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
175
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
176 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
177 if (browser->repo_base) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
178 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
179 cxstring newurl = cx_str(url);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
180
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
181 if (cx_strprefix(newurl, base)) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
182 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
183 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
184 return;
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
185 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
186 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
187
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
188 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
189 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
190 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
191
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
192 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
193 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
194 }
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
195 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
196 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
197 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
198 }
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
199
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
200 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
201 if (browser->navstack_enabled) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
202 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
203 char *nav_url = cxListAt(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
204 cxListRemove(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
205 free(nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
206 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
207 browser->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
208
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
209 char *nav_url = util_concat_path(base, path);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
210 cxListInsert(browser->navigation_stack, 0, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
211
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
212 if (browser->navigation_stack->size > DAVBROWSER_MAX_NAVLIST) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
213 char *nav = cxListAt(browser->navigation_stack, browser->navigation_stack->size - 1);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
214 free(nav);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
215 cxListRemove(browser->navigation_stack, browser->navigation_stack->size - 1);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
216 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
217 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
218 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
219
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
220 void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
221 if (browser->navstack_pos+1 < browser->navigation_stack->size) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
222 browser->navstack_pos++;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
223 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
224 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
225 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
226 browser->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
227 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
228 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
229
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
230 void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
231 if (browser->navstack_pos > 0) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
232 browser->navstack_pos--;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
233 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
234 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
235 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
236 browser->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
237 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
238 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
239
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
240
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
241 // ------------------------------------- File Upload -------------------------------------
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
242
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
243 typedef struct DavFileUpload {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
244 UiObject *ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
245 DavBrowser *browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
246 DavSession *sn;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
247 UiFileList files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
248 char *base_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
249 UiThreadpool *queue;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
250
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
251 size_t total_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
252 size_t total_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
253 size_t total_directories;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
254 size_t uploaded_bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
255 size_t uploaded_files;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
256 size_t uploaded_directories;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
257
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
258 DavBool upload_file;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
259 size_t current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
260 size_t current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
261
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
262 char *current_file_name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
263
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
264 UiObject *dialog;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
265 UiDouble *progress;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
266 UiString *label_top_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
267 UiString *label_top_right;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
268 UiString *label_bottom_left;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
269 UiString *label_bottom_right;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
270 } DavFileUpload;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
271
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
272 typedef struct DUFile {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
273 char *path;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
274 char *upload_path;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
275 size_t bytes;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
276 DavBool isdirectory;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
277 DavFileUpload *upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
278 DavError error;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
279 } DUFile;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
280
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
281 static double upload_progress(DavFileUpload *upload) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
282 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
283 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
284
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
285 static void update_upload_labels(DavFileUpload *upload) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
286 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
287 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
288 char *sz_uploaded_end = strchr(sz_uploaded, ' ');
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
289 if (sz_uploaded_end) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
290 *sz_uploaded_end = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
291 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
292
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
293 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
294 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
295 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
296 "%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
297 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
298 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
299 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
300 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
301 } 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
302 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
303 "%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
304 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
305 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
306 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
307 ui_set(upload->label_top_left, label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
308
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
309 free(sz_total);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
310 free(label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
311
22
d7942163a2a3 don't show progress percent when the file size is 0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
312 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
313 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
314 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
315 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
316 }
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
317 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
318
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
319 static int uithr_update_upload_labels(void *data) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
320 update_upload_labels(data);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
321 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
322 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
323
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
324 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
325 DavFileUpload *upload = data;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
326 if (upload->upload_file) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
327 if (now > upload->current_file_size) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
328 // 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
329 // or we have some extra bytes because of encryption
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
330 // adjust current_file_size and the total upload size
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
331 int64_t extra = now - upload->current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
332 upload->current_file_size += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
333 upload->total_bytes += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
334 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
335
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
336 int64_t new_progress = now - upload->current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
337 upload->uploaded_bytes += new_progress;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
338 upload->current_file_upload = now;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
339
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
340 ui_call_mainthread(uithr_update_upload_labels, upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
341 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
342 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
343
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
344
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
345 typedef struct FileNameUpdate {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
346 DavFileUpload *upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
347 char *name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
348 } FileNameUpdate;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
349
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
350 static int uithr_update_file_label(FileNameUpdate *update) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
351 // replace upload->current_filename with update->name
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
352 if (update->upload->current_file_name) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
353 free(update->upload->current_file_name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
354 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
355 update->upload->current_file_name = update->name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
356
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
357 ui_set(update->upload->label_top_right, update->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
358
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
359 free(update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
360 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
361 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
362
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
363 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
364 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
365 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
366 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
367
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
368 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
369 if (!in) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
370 // TODO: error msg
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
371 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
372 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
373
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
374 upload->upload_file = TRUE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
375 upload->current_file_size = f->bytes;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
376 upload->current_file_upload = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
377
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
378 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
379
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
380 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
381 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
382 ui_update->name = strdup(res->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
383 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
384
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
385 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
386 if (dav_store(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
387 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
388 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
389 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
390
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
391 fclose(in);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
392
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
393 upload->upload_file = FALSE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
394
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
395 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
396 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
397
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
398 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
399 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
400 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
401
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
402 upload->uploaded_files++;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
403 //upload->uploaded_bytes += file->bytes;
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
404
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
405 double progress = upload_progress(upload);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
406 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
407
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
408 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
409
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
410 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
411 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
412 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
413
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
414 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
415 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
416 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
417 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
418
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
419 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
420 res->iscollection = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
422 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
423 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
424 ui_update->name = strdup(res->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
425 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
426
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
427 if (dav_create(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
428 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
429 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
430
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
431 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
432
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
433 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
434 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
435
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
436 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
437 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
438 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
439
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
440 upload->uploaded_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
441
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
442 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
443
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
444 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
445 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
446 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
447
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
448 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
449 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
450 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
451
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
452 static void uithr_upload_finished(UiEvent *event, void *data) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
453 DavFileUpload *upload = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
454 ui_threadpool_destroy(upload->queue);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
455
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
456 free(upload->base_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
457 dav_session_destroy(upload->sn);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
458 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
459
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
460 static int jobthr_upload_scan(void *data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
461 DavFileUpload *upload = data;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
462
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
463 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
464 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
465 DUFile *f = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
466 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
467 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
468 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
469 f->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
470 f->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
471 f->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
472 cxListInsert(stack, 0, f);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
473 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
474
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
475 while (stack->size > 0) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
476 DUFile *f = cxListAt(stack, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
477
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
478 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
479 cxListRemove(stack, 0);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
480
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
481 SYS_STAT s;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
482 if (!sys_stat(f->path, &s)) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
483 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
484 f->isdirectory = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
485 upload->total_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
486 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
487
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
488 SYS_DIR dir = sys_opendir(f->path);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
489 if (dir) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
490 SysDirEnt *entry;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
491 int nument = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
492 while((entry = sys_readdir(dir)) != NULL) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
493 if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
494 continue;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
495 }
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
496
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
497 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
498 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
499
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
500 DUFile *child = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
501 child->path = newpath.ptr;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
502 child->upload_path = new_upload_path;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
503 child->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
504 child->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
505 child->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
506 child->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
507 cxListAdd(stack, child);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
508 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
509
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
510 sys_closedir(dir);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
511 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
512 } 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
513 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
514 f->bytes = s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
515 upload->total_files++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
516 upload->total_bytes += s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
517 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
518 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
519 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
520 } // TODO: else error msg
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
521
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
522 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
523
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
524 ui_filelist_free(upload->files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
525
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
526 return 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
527 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
528
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
529 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
530 DavFileUpload *upload = data;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
531
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
532 update_upload_labels(upload);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
533 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
534
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
535 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
536 // 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
537 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
538
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
539 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
540 if (!browser->sn) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
541 return; // TODO: error msg
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
542 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
543
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
544 // 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
545 // is done in a separate thread
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
546 DavSession *upload_session = dav_session_clone(browser->sn);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
547
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
548 // 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
549 DavFileUpload *upload = malloc(sizeof(DavFileUpload));
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
550 memset(upload, 0, sizeof(DavFileUpload));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
551
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
552 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
553
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
554 upload->ui = ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
555 upload->browser = browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
556 upload->sn = upload_session;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
557 upload->files = files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
558 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
559 upload->queue = ui_threadpool_create(1);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
560
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
561 // create upload progress window
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
562 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
563 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
564 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
565 free(wtitle.ptr);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
566 upload->dialog = dialog;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
567 ui_window_size(dialog, 550, 120);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
568 upload->progress = ui_double_new(dialog->ctx, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
569 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
570 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
571 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
572 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
573
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
574 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
575 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
576 ui_rlabel(dialog, .value = upload->label_top_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
577 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
578
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
579 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
580 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
581
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
582 ui_llabel(dialog, .value = upload->label_bottom_left);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
583 ui_rlabel(dialog, .value = upload->label_bottom_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
584 ui_newline(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
585 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
586
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
587 ui_set(upload->label_top_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
588 ui_set(upload->label_top_right, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
589 ui_set(upload->label_bottom_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
590 ui_set(upload->label_bottom_right, "");
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
591 ui_set(upload->progress, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
592
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
593 ui_show(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
594
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
595 // start upload and stat threads
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
596 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
597 }

mercurial