application/davcontroller.c

Wed, 07 Feb 2024 17:10:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 07 Feb 2024 17:10:01 +0100
changeset 20
db263186edf3
parent 19
813c97c5b6d3
child 21
3060a5a1d5fd
permissions
-rw-r--r--

improve upload progress window

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
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
293 cxmutstr label1 = cx_asprintf(
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
294 "%s/%s %zu/%zu files",
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
295 sz_uploaded,
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
296 sz_total,
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
297 upload->uploaded_files+upload->uploaded_directories,
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
298 upload->total_files+upload->total_directories);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
299 ui_set(upload->label_top_left, label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
300
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
301 free(sz_total);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
302 free(label1.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
303
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
304
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
305 cxmutstr file_label = cx_asprintf("%s (%.0f%%)", upload->current_file_name, ((float)upload->current_file_upload/(float)upload->current_file_size)*100);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
306 ui_set(upload->label_top_right, file_label.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
307
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
308 free(file_label.ptr);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
309 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
310
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
311 static int uithr_update_upload_labels(void *data) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
312 update_upload_labels(data);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
313 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
314 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
315
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
316 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
317 DavFileUpload *upload = data;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
318 if (upload->upload_file) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
319 if (now > upload->current_file_size) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
320 // 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
321 // or we have some extra bytes because of encryption
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
322 // adjust current_file_size and the total upload size
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
323 int64_t extra = now - upload->current_file_size;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
324 upload->current_file_size += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
325 upload->total_bytes += extra;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
326 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
327
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
328 int64_t new_progress = now - upload->current_file_upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
329 upload->uploaded_bytes += new_progress;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
330 upload->current_file_upload = now;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
331
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
332 ui_call_mainthread(uithr_update_upload_labels, upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
333 }
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
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
337 typedef struct FileNameUpdate {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
338 DavFileUpload *upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
339 char *name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
340 } FileNameUpdate;
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 static int uithr_update_file_label(FileNameUpdate *update) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
343 // replace upload->current_filename with update->name
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
344 if (update->upload->current_file_name) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
345 free(update->upload->current_file_name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
346 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
347 update->upload->current_file_name = update->name;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
348
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
349 ui_set(update->upload->label_top_right, update->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
350
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
351 free(update);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
352 return 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
353 }
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
354
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
355 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
356 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
357 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
358 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
359
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
360 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
361 if (!in) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
362 // TODO: error msg
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
363 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
364 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
365
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
366 upload->upload_file = TRUE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
367 upload->current_file_size = f->bytes;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
368 upload->current_file_upload = 0;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
369
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
370 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
371
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
372 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
373 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
374 ui_update->name = strdup(res->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
375 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
376
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
377 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
378 if (dav_store(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
379 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
380 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
381 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
382
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
383 fclose(in);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
384
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
385 upload->upload_file = FALSE;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
386
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
387 return 0;
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
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
390 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
391 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
392 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
393
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
394 upload->uploaded_files++;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
395 //upload->uploaded_bytes += file->bytes;
19
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 double progress = upload_progress(upload);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
398 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
399
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
400 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
401
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
402 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
403 free(file->upload_path);
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
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
406 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
407 DUFile *f = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
408 DavFileUpload *upload = f->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
409 DavSession *sn = upload->sn;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
410
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
411 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
412 res->iscollection = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
413
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
414 FileNameUpdate *ui_update = malloc(sizeof(FileNameUpdate));
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
415 ui_update->upload = upload;
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
416 ui_update->name = strdup(res->name);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
417 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
418
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
419 if (dav_create(res)) {
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
420 f->error = sn->error;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
422
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
423 dav_resource_free(res);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
424
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
425 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
426 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
427
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
428 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
429 DUFile *file = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
430 DavFileUpload *upload = file->upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
431
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
432 upload->uploaded_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
433
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
434 update_upload_labels(upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
435
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
436 free(file->path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
437 free(file->upload_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
438 }
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 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
441 return 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
442 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
443
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
444 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
445 DavFileUpload *upload = data;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
446 ui_threadpool_destroy(upload->queue);
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 free(upload->base_path);
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
449 dav_session_destroy(upload->sn);
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 int jobthr_upload_scan(void *data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
453 DavFileUpload *upload = data;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
454
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
455 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
456 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
457 DUFile *f = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
458 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
459 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
460 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
461 f->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
462 f->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
463 f->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
464 cxListInsert(stack, 0, f);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
465 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
466
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
467 while (stack->size > 0) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
468 DUFile *f = cxListAt(stack, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
469
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
470 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
471 cxListRemove(stack, 0);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
472
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
473 SYS_STAT s;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
474 if (!sys_stat(f->path, &s)) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
475 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
476 f->isdirectory = TRUE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
477 upload->total_directories++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
478 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
479
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
480 SYS_DIR dir = sys_opendir(f->path);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
481 if (dir) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
482 SysDirEnt *entry;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
483 int nument = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
484 while((entry = sys_readdir(dir)) != NULL) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
485 if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
486 continue;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
487 }
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
488
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
489 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
490 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
491
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
492 DUFile *child = malloc(sizeof(DUFile));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
493 child->path = newpath.ptr;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
494 child->upload_path = new_upload_path;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
495 child->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
496 child->bytes = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
497 child->upload = upload;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
498 child->error = 0;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
499 cxListAdd(stack, child);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
500 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
501
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
502 sys_closedir(dir);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
503 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
504 } 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
505 f->isdirectory = FALSE;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
506 f->bytes = s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
507 upload->total_files++;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
508 upload->total_bytes += s.st_size;
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
509 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
510 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
511 }
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
512 } // TODO: else error msg
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
513
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
514 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
515
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
516 ui_filelist_free(upload->files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
517
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
518 return 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
519 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
520
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
521 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
522 DavFileUpload *upload = data;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
523
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
524 update_upload_labels(upload);
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
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 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
529 if (!browser->sn) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
530 return; // TODO: error msg
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
531 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
532
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
533 // 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
534 // is done in a separate thread
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
535 DavSession *upload_session = dav_session_clone(browser->sn);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
536
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
537 // 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
538 DavFileUpload *upload = malloc(sizeof(DavFileUpload));
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
539 memset(upload, 0, sizeof(DavFileUpload));
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
540
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
541 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
542
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
543 upload->ui = ui;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
544 upload->browser = browser;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
545 upload->sn = upload_session;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
546 upload->files = files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
547 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
548 upload->queue = ui_threadpool_create(1);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
549
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
550 // create upload progress window
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
551 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
552 UiObject *dialog = ui_simple_window(wtitle.ptr, upload);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
553 free(wtitle.ptr);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
554 upload->dialog = dialog;
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
555 ui_window_size(dialog, 550, 120);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
556 upload->progress = ui_double_new(dialog->ctx, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
557 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
558 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
559 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
560 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
561
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
562 ui_grid(dialog, .margin = 10, .spacing = 10, .fill = TRUE) {
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
563 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
564 ui_rlabel(dialog, .value = upload->label_top_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
565 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
566
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
567 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
568 ui_newline(dialog);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
569
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
570 ui_llabel(dialog, .value = upload->label_bottom_left);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
571 ui_rlabel(dialog, .value = upload->label_bottom_right);
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
572 ui_newline(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
573 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
574
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
575 ui_set(upload->label_top_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
576 ui_set(upload->label_top_right, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
577 ui_set(upload->label_bottom_left, "");
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
578 ui_set(upload->label_bottom_right, "");
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
579 ui_set(upload->progress, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
580
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
581 ui_show(dialog);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
582
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
583 // start upload and stat threads
19
813c97c5b6d3 add a very basic upload progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
584 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
585 }

mercurial