Tue, 26 Nov 2024 10:40:45 +0100
add context menu, implement 'Select All'
87
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
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 |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "download.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include "davcontroller.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include "window.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <cx/printf.h> |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "config.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "system.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common/context.h" |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include <libidav/config.h> |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include <libidav/utils.h> |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | static int uithr_download_update_progress(void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | DavFileDownload *download = data; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | if(download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | return 1; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | char *sz_total = util_size_str(FALSE, download->progress.total_bytes); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | char *sz_downloaded = util_size_str2(FALSE, download->progress.transferred_bytes, download->progress.total_bytes, 2); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | char *sz_downloaded_end = strchr(sz_downloaded, ' '); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | if (sz_downloaded_end) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | *sz_downloaded_end = 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | if (download->progress.total_bytes > 0) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | double progress = (double)download->progress.transferred_bytes / (double)download->progress.total_bytes; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | ui_set(download->progressbar, progress*100); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | cxmutstr label1; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | if (download->progress.total_files + download->progress.total_directories > 1) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | label1 = cx_asprintf( |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | "%s/%s %zu/%zu files", |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | sz_downloaded, |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | sz_total, |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | download->progress.transferred_files+download->progress.transferred_directories, |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | download->progress.total_files+download->progress.total_directories); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | } else { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | label1 = cx_asprintf( |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | "%s/%s", |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | sz_downloaded, |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | sz_total); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | ui_set(download->label_top_left, label1.ptr); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | free(sz_total); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | free(label1.ptr); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | return 1; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | static size_t ddfile_write(const void *buf, size_t size, size_t count, void *stream) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | DDFile *file = stream; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | if(file->download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | size_t w = fwrite(buf, size, count, file->fd); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | file->download->progress.current_file_transferred += w; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | file->download->progress.transferred_bytes += w; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | if (file->download->progress.current_file_transferred > file->download->progress.current_file_size) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | size_t diff = file->download->progress.current_file_transferred - file->download->progress.current_file_size; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | file->download->progress.current_file_size = file->download->progress.current_file_transferred; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | file->download->progress.total_bytes += diff; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | ui_call_mainthread(uithr_download_update_progress, file->download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | return w; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | static int qthr_download_resource(void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | DDFile *file = data; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | if(file->download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | file->download->progress.current_file_transferred = 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | file->download->progress.current_file_size = file->size; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | FILE *f = sys_fopen(file->to, "wb"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | if (!f) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | file->fd = f; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | DavResource *res = dav_resource_new(file->download->download_sn, file->path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | dav_get_content(res, file, (dav_write_func)ddfile_write); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | file->download->progress.transferred_files++; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | ui_call_mainthread(uithr_download_update_progress, file->download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | dav_resource_free(res); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | fclose(f); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | free(file->path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | free(file->to); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | free(file); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | static int qthr_download_finished(void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | static void uithr_download_finished(UiEvent *event, void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | DavFileDownload *download = data; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | if(download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | ui_set(download->label_bottom_left, "Canceled"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | if(download->dialog->ref > 1) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | ui_close(download->dialog); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | ui_object_unref(download->dialog); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | typedef struct DlStackElm { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | DavResource *resource; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | char *sub_path; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | } DlStackElm; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | static int jobthr_download_scan(void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | DavFileDownload *download = data; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | // check if the specified local location is a directory |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | SYS_STAT s; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | if (!sys_stat(download->local_path, &s)) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | if (S_ISDIR(s.st_mode)) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | download->isdirectory = TRUE; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | CxList *stack = cxLinkedListCreateSimple(sizeof(DlStackElm)); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | // add selected files to the download queue |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | DavResource *res = download->reslist; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | while (res) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | DlStackElm elm; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | elm.resource = res; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | elm.sub_path = strdup(res->name); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | cxListAdd(stack, &elm); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | res = res->next; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | while (cxListSize(stack) > 0 && !download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | DlStackElm *elm = cxListAt(stack, 0); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | DavResource *res = elm->resource; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | char *sub_path = elm->sub_path; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | cxListRemove(stack, 0); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | if (res->iscollection) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | if (dav_load(res)) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | // TODO: handle error |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | continue; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | // update ui |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | ui_call_mainthread(uithr_download_update_progress, download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | char *path = util_concat_path(download->local_path, sub_path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | int err = sys_mkdir(path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | free(path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | if (err) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | // TODO: handle error |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | DavResource *child = res->children; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | while (child) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | char *child_path = util_concat_path(sub_path, child->name); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | DlStackElm childelm; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | childelm.resource = child; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | childelm.sub_path = child_path; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | cxListAdd(stack, &childelm); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | child = child->next; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | } else { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | // add the file to the download queue |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | DDFile *file = malloc(sizeof(DDFile)); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | file->download = download; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | file->path = strdup(res->path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | file->size = res->contentlength; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | if (download->isdirectory) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | file->to = util_concat_path(download->local_path, sub_path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | } else { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | file->to = strdup(download->local_path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | // stats |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | download->progress.total_files++; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | download->progress.total_bytes += res->contentlength; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | // update ui |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | ui_call_mainthread(uithr_download_update_progress, download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | ui_threadpool_job(download->queue, download->dialog, qthr_download_resource, file, NULL, NULL); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | ui_threadpool_job(download->queue, download->dialog, qthr_download_finished, download, uithr_download_finished, download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | cxListDestroy(stack); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | return 0; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | static void uithr_download_scan_finished(UiEvent *event, void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | DavFileDownload *download = data; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | static void download_window_closed(UiEvent *event, void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | DavFileDownload *download = event->obj->window; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | dav_session_destroy(download->sn); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | ui_threadpool_destroy(download->queue); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | void action_download_cancel(UiEvent *event, void *data) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | DavFileDownload *download = event->window; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | if(!download->cancel) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | ui_set(download->label_bottom_left, "Cancel..."); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | download->cancel = TRUE; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | DavFileDownload* dav_download_create(DavBrowser *browser, UiObject *dialog, DavResource *reslist, const char *local_path) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | UiContext *ctx = dialog->ctx; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | DavFileDownload *download = ui_malloc(ctx, sizeof(DavFileDownload)); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | memset(download, 0, sizeof(DavFileDownload)); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | download->dialog = dialog; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | dialog->window = download; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | ui_object_ref(dialog); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | download->browser = browser; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | download->sn = reslist->session; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | download->download_sn = dav_session_clone(download->sn); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | download->reslist = reslist; // TODO: is this safe or do we need a copy? |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | download->local_path = ui_strdup(dialog->ctx, local_path); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | download->queue = ui_threadpool_create(1); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | CxMempool *mp = ui_cx_mempool(ctx); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | cxMempoolRegister(mp, download->download_sn, (cx_destructor_func)dav_session_destroy); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | cxMempoolRegister(mp, download->queue, (cx_destructor_func)ui_threadpool_destroy); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | download->progressbar = ui_double_new(ctx, "progressbar"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | download->label_top_left = ui_string_new(ctx, "label_top_left"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | download->label_top_right = ui_string_new(ctx, "label_top_right"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | download->label_bottom_left = ui_string_new(ctx, "label_bottom_left"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | download->label_bottom_right = ui_string_new(ctx, "label_bottom_right"); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | ui_set(download->label_top_left, ""); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | ui_set(download->label_top_right, ""); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | ui_set(download->label_bottom_left, ""); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | ui_set(download->label_bottom_right, ""); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | ui_set(download->progressbar, 0); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | return download; |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | } |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | void dav_download_start(DavFileDownload *download) { |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | ui_show(download->dialog); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | ui_job(download->dialog, jobthr_download_scan, download, uithr_download_scan_finished, download); |
5360027fb282
download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | } |