application/davcontroller.c

Thu, 28 Nov 2024 18:03:12 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 28 Nov 2024 18:03:12 +0100
changeset 97
5a3d27b8e6b0
parent 95
e92c72705da4
permissions
-rw-r--r--

implement UI for editing properties, relates to #497

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"
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
35 #include "upload.h"
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
36 #include "download.h"
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
37
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
38 #include "system.h"
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
39 #include "common/context.h"
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
40
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
41 #include <libidav/config.h>
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <libidav/utils.h>
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 DavBrowser* davbrowser_create(UiObject *toplevel) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 DavBrowser *doc = ui_document_new(sizeof(DavBrowser));
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UiContext *ctx = ui_document_context(doc);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
47 CxMempool *mp = ui_cx_mempool(ctx);
95
e92c72705da4 add upload/download list, resolves #512
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 93
diff changeset
48 doc->window = toplevel;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 doc->ctx = ctx;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
51 doc->navigation_stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
52 doc->navstack_enabled = true;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
53 doc->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
54
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 doc->dav_queue = ui_threadpool_create(1);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
56 cxMempoolRegister(mp, doc->dav_queue, (cx_destructor_func)ui_threadpool_destroy);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
57
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
58 doc->res_open_inprogress = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 4);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 doc->path = ui_string_new(ctx, "path");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 doc->resources = ui_list_new(ctx, "reslist");
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 return doc;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 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
68 if (browser->current) {
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
69 dav_resource_free_all(browser->current);
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
70 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 ui_list_clear(browser->resources);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
73 browser->current = collection;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
74 browser->res_counter++;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 for (DavResource *res = collection->children; res; res = res->next) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 ui_list_append(browser->resources, res);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 browser->resources->update(browser->resources, 0);
68
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
80
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
81 ui_set_group(ui->ctx, APP_STATE_BROWSER_SESSION);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 // ------------------------------ davbrowser_connect2repo ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
86 typedef struct DavConnect2Repo {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
87 UiObject *ui;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
88 DavBrowser *browser;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
89
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
90 DavCfgRepository *repo;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
91 char *path;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
92
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
93 UiString *password;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
94 } DavConnect2Repo;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
95
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
96 static void dialog_secretstore_decrypt(UiEvent *event, void *data) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
97 DavConnect2Repo *c2r = event->window;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
98
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
99 if(event->intval == 4) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
100 char *pw = ui_get(c2r->password);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
101
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
102 PwdStore *secrets = get_pwdstore();
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
103 pwdstore_setpassword(secrets, pw);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
104 if(pwdstore_decrypt(secrets)) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
105 ui_dialog(c2r->ui, .title = "Error", .content = "Cannot decrypt Secret Store", .closebutton_label = "OK");
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
106 } else {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
107 davbrowser_connect2repo(c2r->ui, c2r->browser, c2r->repo, c2r->path);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
108 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
109 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
110 free(c2r->path);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
111 if(!c2r->repo->node) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
112 dav_repository_free(get_config(), c2r->repo);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
113 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
114
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
115 ui_close(event->obj);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
116 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
117
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
118 int davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo, const char *path) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
119 char *user = NULL;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
120 char *password = NULL;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
121 char *password_free = NULL;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 if (repo->user.value.ptr && repo->password.value.ptr) {
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
123 user = repo->user.value.ptr;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo);
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
125 password = decodedpw.ptr;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
126 password_free = decodedpw.ptr;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
127 } else {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
128 PwdStore *secrets = get_pwdstore();
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
129 const char *credentials = NULL;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
130 if(repo->stored_user.value.ptr) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
131 if(pwdstore_has_id(secrets, repo->stored_user.value.ptr)) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
132 credentials = repo->stored_user.value.ptr;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
133 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
134 } else {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
135 credentials = get_location_credentials(repo, path);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
136 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
137
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
138 if(credentials) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
139 if(!secrets->isdecrypted) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
140 UiObject *obj = ui_dialog_window(ui,
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
141 .title = "Authentication",
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
142 .lbutton1 = "Cancel",
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
143 .rbutton4 = "Connect",
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
144 .default_button = 4,
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
145 .show_closebutton = UI_OFF,
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
146 .onclick = dialog_secretstore_decrypt);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
147
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
148 DavConnect2Repo *c2r = ui_malloc(obj->ctx, sizeof(DavConnect2Repo));
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
149 c2r->ui = ui;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
150 c2r->browser = browser;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
151 c2r->repo = repo;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
152 c2r->path = path ? strdup(path) : NULL;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
153 c2r->password = ui_string_new(obj->ctx, NULL);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
154 obj->window = c2r;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
155
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
156 ui_grid(obj, .margin = 20, .columnspacing = 12, .rowspacing = 16) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
157 ui_llabel(obj, .label = "Decrypt Secret Store", .colspan = 2);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
158 ui_newline(obj);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
159
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
160 ui_llabel(obj, .label = "Password");
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
161 ui_passwordfield(obj, .value = c2r->password, .hexpand = TRUE);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
162 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
163
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
164 ui_show(obj);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
165
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
166 return 1;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
167 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
168
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
169 if(!get_stored_credentials(credentials, &user, &password)) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
170 fprintf(stderr, "Error: failed to get user/password for credentials %s\n", credentials);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
171 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
172 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
174
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
175 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
176 if (user && password) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
177 dav_session_set_auth(sn, user, password);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
178 }
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
179 free(password_free);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
180
93
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
181 sn->flags = dav_repository_get_flags(repo);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
182 sn->key = dav_context_get_key(application_dav_context(), repo->default_key.value.ptr);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
183 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
184 if(repo->cert.value.ptr) {
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
185 curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert.value.ptr);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
186 }
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
187 if(!repo->verification.value) {
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
188 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
189 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0);
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
190 }
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
191
5ee236155955 use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
192
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 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
194 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
195 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
196 } else {
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
197 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
198 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
200 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
201 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
202 free(dav_path);
56
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
203
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
204 SessionAuthData *auth = cxMalloc(sn->mp->allocator, sizeof(SessionAuthData));
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
205 auth->obj = ui;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
206 auth->cond = ui_condvar_create();
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
207 auth->sn = sn;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
208 auth->user = repo->user.value.ptr ? cx_strdup_a(sn->mp->allocator, cx_strcast(repo->user.value)).ptr : NULL;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
209 auth->password = NULL;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
210 dav_session_set_authcallback(sn, jobthr_davbrowser_auth, auth);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
211
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
212 davbrowser_query_path(ui, browser, path);
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
213
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
214 return 0;
56
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
215 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
56
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
217 // ------------------------------ davbrowser_auth ------------------------------
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
218
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
219 static int davbrowser_auth_dialog(void *data) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
220 SessionAuthData *auth = data;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
221 auth_dialog(auth);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
222 return 0;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
223 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
224
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
225 void davbrowser_auth_set_user_pwd(SessionAuthData *auth, const char *user, const char *password) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
226 dav_session_free(auth->sn, auth->user);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
227 dav_session_free(auth->sn, auth->password);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
228 auth->user = user ? dav_session_strdup(auth->sn, user) : NULL;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
229 auth->password = password ? dav_session_strdup(auth->sn, password) : NULL;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
230 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
231
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
232 int jobthr_davbrowser_auth(DavSession *sn, void *data) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
233 SessionAuthData *auth = data;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
234
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
235 ui_call_mainthread(davbrowser_auth_dialog, auth);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
236 ui_condvar_wait(auth->cond);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
237
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
238 if(auth->cond->intdata) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
239 dav_session_set_auth(sn, auth->user, auth->password);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
240 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
241 dav_session_free(auth->sn, auth->password);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
242 auth->password = NULL;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
243
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
244 return 0;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 // ------------------------------ davbrowser_query_path ------------------------------
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 typedef struct DavBrowserQueryPath {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
251 UiThreadpool *pool;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 DavBrowser *browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 char *path;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 DavResource *result;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 } DavBrowserQueryPath;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 static int browser_query_path(void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 DavSession *sn = query->browser->sn;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
261 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
262 query->result = res;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 return 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 static void browser_query_finished(UiEvent *event, void *data) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 DavBrowserQueryPath *query = data;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 DavBrowser *browser = event->document;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
271 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
272 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
273 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
274 } else {
58
0d25f15e2625 add minimal query error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
275 cxmutstr error = cx_asprintf("Error %d", query->browser->sn->error);
0d25f15e2625 add minimal query error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
276 ui_dialog(event->obj, .title = "Error", .content = error.ptr, .closebutton_label = "OK");
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
277 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
278
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
279 window_progress(event->window, 0);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 } else {
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
281 // operation aborted
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
282 if (query->result) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
283 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
284 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 free(query->path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 free(query);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 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
292 if (!browser->sn) {
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
293 // TODO: error
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
294 return;
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
295 }
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
296
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 // 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
298 size_t len = path ? strlen(path) : 0;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 if (len == 1 && *path == '/') {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 path = "";
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 }
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
302
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
303 // 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
304 // 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
305 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
306 char *full_path_col = util_concat_path(full_path, "/");
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 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
308 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
309 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
310 if (!cx_strprefix(cpath, newc)) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 ui_set(browser->path, full_path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 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
314 free(full_path_col);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 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
317 query->pool = browser->dav_queue;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 query->browser = browser;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 query->path = strdup(path);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 query->result = NULL;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 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
322
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 window_progress(ui->window, 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
324
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
325 davbrowser_add2navstack(browser, browser->repo_base, path);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
327
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
328 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
329 if (browser->repo_base) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
330 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
331 cxstring newurl = cx_str(url);
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
332
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
333 if (cx_strprefix(newurl, base)) {
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
334 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
335 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
336 return;
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
337 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
338 }
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
339
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
340 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
341 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path);
85
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
342
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
343 int ret = davbrowser_connect2repo(ui, browser, repo, path);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
344 free(path);
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
345 if(ret) {
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
346 return;
44ebbb4c8a13 add support for secret store credentials when connecting to repositories, resolves #496
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
347 }
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
348
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
349 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
350 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
351 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
352 }
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
353
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
354 void davbrowser_open_resource(UiObject *ui, DavBrowser *browser, DavResource *res, const char *contenttype) {
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
355 DavResourceViewType type = DAV_RESOURCE_VIEW_PROPERTIES;
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
356 if(!contenttype) {
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
357 contenttype = res->contenttype;
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
358 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
359
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
360 if(res->iscollection) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
361 // default type
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
362 } else if(contenttype) {
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
363 cxstring ctype = cx_str(contenttype);
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
364 if(cx_strprefix(ctype, CX_STR("text/"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
365 type = DAV_RESOURCE_VIEW_TEXT;
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
366 } else if(cx_strprefix(ctype, CX_STR("image/"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
367 type = DAV_RESOURCE_VIEW_IMAGE;
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
368 } else if(cx_strprefix(ctype, CX_STR("application/"))) {
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
369 if(cx_strsuffix(ctype, CX_STR("json"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
370 type = DAV_RESOURCE_VIEW_TEXT;
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
371 } else if(cx_strsuffix(ctype, CX_STR("/xml"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
372 type = DAV_RESOURCE_VIEW_TEXT;
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
373 } else if(cx_strsuffix(ctype, CX_STR("+xml"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
374 type = DAV_RESOURCE_VIEW_TEXT;
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
375 } else if(cx_strsuffix(ctype, CX_STR("/xml"))) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
376 type = DAV_RESOURCE_VIEW_TEXT;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
377 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
378 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
379 } else {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
380 cxstring path = cx_str(res->path);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
381 if(cx_strsuffix(path, CX_STR(".png"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
382 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
383 } else if(cx_strsuffix(path, CX_STR(".jpg"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
384 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
385 } else if(cx_strsuffix(path, CX_STR(".jpeg"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
386 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
387 } else if(cx_strsuffix(path, CX_STR(".tif"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
388 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
389 } else if(cx_strsuffix(path, CX_STR(".tiff"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
390 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
391 } else if(cx_strsuffix(path, CX_STR(".webp"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
392 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
393 } else if(cx_strsuffix(path, CX_STR(".bmp"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
394 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
395 } else if(cx_strsuffix(path, CX_STR(".gif"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
396 type = DAV_RESOURCE_VIEW_IMAGE;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
397 } else if(cx_strsuffix(path, CX_STR(".txt"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
398 type = DAV_RESOURCE_VIEW_TEXT;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
399 } else if(cx_strsuffix(path, CX_STR(".md"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
400 type = DAV_RESOURCE_VIEW_TEXT;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
401 } else if(cx_strsuffix(path, CX_STR(".xml"))) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
402 type = DAV_RESOURCE_VIEW_TEXT;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
403 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
404 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
405
52
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
406 resourceviewer_new(browser, res->path, type);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
407 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
408
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
409 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
410 if (browser->navstack_enabled) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
411 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
412 char *nav_url = cxListAt(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
413 cxListRemove(browser->navigation_stack, 0);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
414 free(nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
415 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
416 browser->navstack_pos = 0;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
417
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
418 char *nav_url = util_concat_path(base, path);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
419 cxListInsert(browser->navigation_stack, 0, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
420
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
421 if (cxListSize(browser->navigation_stack) > DAVBROWSER_MAX_NAVLIST) {
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
422 char *nav = cxListAt(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
423 free(nav);
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
424 cxListRemove(browser->navigation_stack, cxListSize(browser->navigation_stack) - 1);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
425 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
426 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
427 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
428
68
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
429 void davbrowser_navigation_parent(UiObject *ui, DavBrowser *browser) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
430 if(browser->current) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
431 char *parent = util_parent_path(browser->current->path);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
432 if(strlen(parent) > 0) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
433 davbrowser_query_path(ui, browser, parent);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
434 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
435 free(parent);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
436 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
437 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
438
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
439 void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser) {
49
2f71f4ee247a update toolkit, ucx, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
440 if (browser->navstack_pos+1 < cxListSize(browser->navigation_stack)) {
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
441 browser->navstack_pos++;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
442 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
443 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
444 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
445 browser->navstack_enabled = true;
48
ae61523bce20 improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
446 ui_set(browser->path, nav_url);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
447 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
448 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
449
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
450 void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
451 if (browser->navstack_pos > 0) {
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
452 browser->navstack_pos--;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
453 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
454 browser->navstack_enabled = false;
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
455 davbrowser_query_url(ui, browser, nav_url);
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
456 browser->navstack_enabled = true;
48
ae61523bce20 improve pathbar visuals
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
457 ui_set(browser->path, nav_url);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
458 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
459 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
460
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
461
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
462 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
463 if (!browser->sn) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
464 return; // TODO: error msg
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
465 }
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
466
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
467 cxmutstr wtitle = cx_asprintf("Upload to: %s", ui_get(browser->path));
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
468 UiObject *dialog = ui_simple_window(wtitle.ptr, NULL);
20
db263186edf3 improve upload progress window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
469 free(wtitle.ptr);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
470
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
471 DavFileUpload *upload = dav_upload_create(browser, dialog, files);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
472 transfer_window_init(dialog, action_upload_cancel);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
473 dav_upload_start(upload);
95
e92c72705da4 add upload/download list, resolves #512
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 93
diff changeset
474 application_register_transfer(&upload->trans);
31
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
475 }
bf810176ddb8 implement download progress bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
476
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
477 void davbrowser_download(UiObject *ui, DavBrowser *browser, DavResource *reslist, const char *local_path) {
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
478 cxmutstr wtitle = cx_asprintf("Download to: %s", local_path);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
479 UiObject *dialog = ui_simple_window(wtitle.ptr, NULL);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
480 free(wtitle.ptr);
86
8e7c57c23133 add reference counting to download window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
481
87
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
482 DavFileDownload *download = dav_download_create(browser, dialog, reslist, local_path);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
483 transfer_window_init(dialog, action_download_cancel);
5360027fb282 download/upload refactoring, add cancel button, resolves #498 fixes #506
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
484 dav_download_start(download);
95
e92c72705da4 add upload/download list, resolves #512
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 93
diff changeset
485 application_register_transfer(&download->trans);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
486 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
487
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
488
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
489 // ------------------------------------- Path Operation (DELETE, MKCOL) -------------------------------------
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
490
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
491 enum DavPathOpType {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
492 DAV_PATH_OP_DELETE = 0,
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
493 DAV_PATH_OP_CREATE
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
494 };
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
495
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
496 typedef struct DavPathOp {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
497 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
498 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
499
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
500 // operation type (delete, mkcol, ...)
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
501 enum DavPathOpType op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
502 // clone of the browser's DavSession
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
503 DavSession *sn;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
504 // path array
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
505 char **path;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
506 // browser->resources indices
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
507 size_t *list_indices;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
508 // number of path/list_indices elements
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
509 size_t nelm;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
510 // path is collection
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
511 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
512
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
513 // browser->current ptr when the PathOp started
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
514 // used in combination with collection_ctn to check if the browser list changed
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
515 DavResource *collection;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
516 int64_t collection_ctn;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
517 } DavPathOp;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
518
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
519 typedef struct DavPathOpResult {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
520 UiObject *ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
521 DavBrowser *browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
522 DavResource *collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
523 int64_t collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
524 enum DavPathOpType op;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
525 DavBool iscollection;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
526
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
527 char *path;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
528 int res_index;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
529 int result;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
530 char *errormsg;
84
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
531
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
532 time_t result_lastmodified;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
533 uint64_t result_contentlength;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
534 char *result_contenttype;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
535 } DavPathOpResult;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
536
89
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
537 typedef struct DavRenameOp {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
538 UiObject *ui;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
539 DavBrowser *browser;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
540
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
541 // clone of the browser's DavSession
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
542 DavSession *sn;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
543 char *path;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
544 char *newname;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
545 int result;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
546 char *errormsg;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
547
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
548 // browser->resources index
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
549 size_t index;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
550
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
551 // browser->current ptr when the PathOp started
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
552 // used in combination with collection_ctn to check if the browser list changed
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
553 DavResource *collection;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
554 int64_t collection_ctn;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
555 } DavRenameOp;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
556
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
557 static int uithr_pathop_delete_error(void *data) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
558 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
559
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
560 cxmutstr msg = cx_asprintf("Cannot delete resource %s", result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
561 ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
562 free(msg.ptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
563
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
564 if (result->errormsg) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
565 free(result->errormsg);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
566 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
567 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
568 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
569 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
570 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
571
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
572 static int uithr_pathop_delete_sucess(void *data) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
573 DavPathOpResult *result = data;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
574
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
575 if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
576 ui_list_remove(result->browser->resources, result->res_index);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
577 result->browser->resources->update(result->browser->resources, 0);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
578 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
579
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
580 free(result->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
581 free(result);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
582 return 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
583 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
584
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
585 static int uithr_pathop_create_resource_error(void *data) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
586 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
587
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
588 cxmutstr msg = cx_asprintf("Cannot create %s %s", result->iscollection ? "collection" : "resource", result->path);
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
589 ui_dialog(result->ui, .title = "Error", .content = msg.ptr, .button1_label = "OK");
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
590 free(msg.ptr);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
591
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
592 if (result->errormsg) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
593 free(result->errormsg);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
594 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
595 free(result->path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
596 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
597 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
598 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
599
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
600 static int uithr_pathop_create_resource_sucess(void *data) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
601 DavPathOpResult *result = data;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
602
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
603 if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
604 DavResource *res = dav_resource_new(result->browser->sn, result->path);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
605 res->iscollection = result->iscollection;
84
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
606 res->lastmodified = result->result_lastmodified;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
607 res->contentlength = result->result_contentlength;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
608 res->contenttype = result->result_contenttype ? dav_session_strdup(res->session, result->result_contenttype) : NULL;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
609 // TODO: add the resource at the correct position or sort the list after append
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
610 ui_list_append(result->browser->resources, res);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
611 result->browser->resources->update(result->browser->resources, 0);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
612 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
613
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
614 free(result->path);
84
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
615 free(result->result_contenttype);
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
616 free(result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
617 return 0;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
618 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
619
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
620 static int jobthr_path_op(void *data) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
621 DavPathOp *op = data;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
622
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
623 for (int i = op->nelm-1; i >= 0; i--) {
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
624 if (op->path[i]) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
625 DavResource *res = dav_resource_new(op->sn, op->path[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
626
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
627 DavPathOpResult *result = malloc(sizeof(DavPathOpResult));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
628 result->ui = op->ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
629 result->browser = op->browser;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
630 result->collection = op->collection;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
631 result->collection_ctn = op->collection_ctn;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
632 result->op = op->op;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
633 result->path = strdup(res->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
634 result->result = 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
635 result->res_index = op->list_indices[i];
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
636 result->errormsg = NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
637 result->iscollection = op->iscollection;
84
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
638 result->result_lastmodified = 0;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
639 result->result_contentlength = 0;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
640 result->result_contenttype = NULL;
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
641
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
642 if (op->op == DAV_PATH_OP_DELETE) {
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
643 ui_threadfunc result_callback = uithr_pathop_delete_sucess;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
644 if (dav_delete(res)) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
645 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
646 result_callback = uithr_pathop_delete_error;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
647 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
648 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
649 } else if (op->op == DAV_PATH_OP_CREATE) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
650 res->iscollection = op->iscollection;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
651 ui_threadfunc result_callback = uithr_pathop_create_resource_sucess;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
652 if (dav_create(res)) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
653 result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
654 result_callback = uithr_pathop_create_resource_error;
84
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
655 } else {
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
656 // try to load some basic resource properties
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
657 // we don't care about the result, if it fails,
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
658 // we just don't have the new properties
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
659 dav_load_prop(res, NULL, 0);
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
660 result->result_lastmodified = res->lastmodified;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
661 result->result_contentlength = res->contentlength;
57a359c52617 load properties after resource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
662 result->result_contenttype = res->contenttype ? strdup(res->contenttype) : NULL;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
663 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
664 ui_call_mainthread(result_callback, result);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
665 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
666
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
667 dav_resource_free(res);
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
668 free(op->path[i]);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
669 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
670 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
671
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
672 dav_session_destroy(op->sn);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
673 free(op->path);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
674 free(op->list_indices);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
675 free(op);
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
676
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
677 return 0;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
678 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
679
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
680 void davbrowser_delete(UiObject *ui, DavBrowser *browser, UiListSelection selection) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
681 DavPathOp *op = malloc(sizeof(DavPathOp));
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
682 op->ui = ui;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
683 op->browser = browser;
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
684 op->op = DAV_PATH_OP_DELETE;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
685 op->sn = dav_session_clone(browser->sn);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
686 op->path = calloc(selection.count, sizeof(char*));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
687 op->list_indices = calloc(selection.count, sizeof(size_t));
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
688 op->nelm = selection.count;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
689
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
690 op->collection = browser->current;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
691 op->collection_ctn = browser->res_counter;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
692
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
693 for (int i = 0; i < selection.count; i++) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
694 DavResource *res = ui_list_get(browser->resources, selection.rows[i]);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
695 if (res) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
696 op->path[i] = strdup(res->path);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
697 op->list_indices[i] = selection.rows[i];
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
698 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
699 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
700
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
701 ui_job(ui, jobthr_path_op, op, NULL, NULL);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
702 }
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
703
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
704 void davbrowser_create_resource(UiObject *ui, DavBrowser *browser, const char *name, DavBool iscollection) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
705 DavPathOp *op = malloc(sizeof(DavPathOp));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
706 op->ui = ui;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
707 op->browser = browser;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
708 op->op = DAV_PATH_OP_CREATE;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
709 op->sn = dav_session_clone(browser->sn);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
710 op->path = calloc(1, sizeof(char*));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
711 op->list_indices = calloc(1, sizeof(size_t));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
712 op->nelm = 1;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
713 op->iscollection = iscollection;
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
714
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
715 op->path[0] = util_concat_path(browser->current->path, name);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
716
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
717 op->collection = browser->current;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
718 op->collection_ctn = browser->res_counter;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
719
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
720 ui_job(ui, jobthr_path_op, op, NULL, NULL);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
721 }
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
722
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
723 void davbrowser_mkcol(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
724 davbrowser_create_resource(ui, browser, name, TRUE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
725 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
726
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
727 void davbrowser_newfile(UiObject *ui, DavBrowser *browser, const char *name) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
728 davbrowser_create_resource(ui, browser, name, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
729 }
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
730
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
731
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
732
89
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
733
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
734 static int jobthr_rename(void *data) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
735 DavRenameOp *op = data;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
736
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
737 DavResource *res = dav_get(op->sn, op->path, NULL);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
738 if(!res) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
739 fprintf(stderr, "Error: Cannot get resource %s\n", op->path);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
740 op->result = 1;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
741 return 0;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
742 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
743
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
744 char *cryptoname = dav_get_string_property_ns(res, DAV_NS, "crypto-name");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
745 char *cryptokey = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
746 if(cryptoname && cryptokey) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
747 // encrypted resource, the name is stored in the crypto-name property
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
748 // these properties are only loaded if encryption is enabled for
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
749 // this session
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
750 DavKey *key = dav_context_get_key(op->sn->context, cryptokey);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
751 if(!key) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
752 cxmutstr error = cx_asprintf_a(op->sn->mp->allocator, "Cannot rename resource: crypto key %s not found.", cryptokey);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
753 op->errormsg = error.ptr;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
754 op->result = 1;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
755 return 0;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
756 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
757
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
758 // check if a resource with this name already exists
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
759 char *parent = util_parent_path(res->path);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
760 char *newpath = util_concat_path(parent, op->newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
761 DavResource *testres = dav_resource_new(op->sn, newpath);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
762 if(dav_exists(testres)) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
763 cxmutstr error = cx_asprintf_a(op->sn->mp->allocator, "A resource with the name %s already exists.", op->newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
764 op->errormsg = error.ptr;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
765 op->result = 1;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
766 } else {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
767 char *crname = aes_encrypt(op->newname, strlen(op->newname), key);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
768 dav_set_string_property_ns(res, DAV_NS, "crypto-name", crname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
769 free(crname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
770 if(dav_store(res)) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
771 op->result = 1;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
772 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
773 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
774 free(parent);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
775 free(newpath);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
776 } else {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
777 // rename the resource by changing the url mapping with MOVE
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
778 char *parent = util_parent_path(res->href);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
779 char *new_href = util_concat_path(parent, op->newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
780 char *dest = util_get_url(op->sn, new_href);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
781 free(parent);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
782 free(new_href);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
783 if(dav_moveto(res, dest, false)) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
784 op->result = 1;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
785 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
786 free(dest);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
787 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
788
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
789 if(op->result && !op->errormsg) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
790 cxmutstr error = cx_asprintf_a(op->sn->mp->allocator, "Error: %d", op->sn->error);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
791 op->errormsg = error.ptr;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
792 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
793
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
794 return 0;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
795 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
796
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
797 static void uithr_rename_finished(UiEvent *event, void *data) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
798 DavRenameOp *op = data;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
799
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
800 if(!op->result) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
801 // update name in the browser list
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
802 if (op->browser->current == op->collection && op->browser->res_counter == op->collection_ctn) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
803 DavResource *res = ui_list_get(op->browser->resources, op->index);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
804
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
805 char *parent = util_parent_path(res->path);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
806 char *newpath = util_concat_path(parent, op->newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
807 dav_session_free(res->session, res->path);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
808 dav_session_free(res->session, res->name);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
809 res->path = dav_session_strdup(res->session, newpath);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
810 res->name = dav_session_strdup(res->session, op->newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
811 op->browser->resources->update(op->browser->resources, 0);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
812 free(parent);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
813 free(newpath);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
814 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
815 } else {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
816 // error
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
817 ui_dialog(op->ui, .title = "Error", .content = op->errormsg, .closebutton_label = "OK");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
818 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
819 dav_session_destroy(op->sn);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
820 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
821
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
822 static void action_resource_rename(UiEvent *event, void *data) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
823 DavRenameOp *op = data;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
824 if(event->intval == 1) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
825 char *newname = event->eventdata;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
826 if(!newname || strlen(newname) == 0) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
827 ui_dialog(op->ui, .title = "Error", .content = "No name specified", .closebutton_label = "OK");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
828 dav_session_destroy(op->sn);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
829 return;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
830 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
831
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
832 char *s = strchr(newname, '/');
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
833 if(s) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
834 ui_dialog(op->ui, .title = "Error", .content = "Character '/' is not allowed", .closebutton_label = "OK");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
835 dav_session_destroy(op->sn);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
836 return;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
837 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
838
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
839 op->newname = dav_session_strdup(op->sn, newname);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
840
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
841 ui_job(op->ui, jobthr_rename, op, uithr_rename_finished, op);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
842 return;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
843 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
844 dav_session_destroy(op->sn);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
845 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
846
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
847 void davbrowser_rename(UiObject *ui, DavBrowser *browser, UiListSelection selection) {
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
848 DavSession *sn = dav_session_clone(browser->sn);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
849
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
850 DavResource *res = ui_list_get(browser->resources, selection.rows[0]);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
851
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
852 DavRenameOp *rename = dav_session_malloc(sn, sizeof(DavRenameOp));
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
853 memset(rename, 0, sizeof(DavRenameOp));
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
854 rename->browser = browser;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
855 rename->ui = ui;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
856 rename->sn = sn;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
857 rename->path = dav_session_strdup(sn, res->path);
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
858 rename->index = selection.rows[0];
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
859
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
860 rename->collection = browser->current;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
861 rename->collection_ctn = browser->res_counter;
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
862
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
863 ui_dialog(ui,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
864 .title = "Rename",
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
865 .content = res->name,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
866 .input = TRUE,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
867 .input_value = res->name,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
868 .result = action_resource_rename,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
869 .resultdata = rename,
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
870 .button1_label = "Rename",
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
871 .closebutton_label = "Cancel");
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
872 }
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
873
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
874
2fbb3cac05a5 implement rename
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
875
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
876 DavResourceViewer* dav_resourceviewer_create(UiObject *toplevel, DavSession *sn, const char *path, DavResourceViewType type) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
877 DavResourceViewer *doc = ui_document_new(sizeof(DavResourceViewer));
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
878 UiContext *ctx = ui_document_context(doc);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
879 CxMempool *mp = ui_cx_mempool(ctx);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
880 doc->obj = toplevel;
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
881 doc->ctx = ctx;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
882
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
883 doc->sn = dav_session_clone(sn);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
884 doc->dav_queue = ui_threadpool_create(1);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
885 cxMempoolRegister(mp, doc->dav_queue, (cx_destructor_func)ui_threadpool_destroy);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
886 doc->path = strdup(path);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
887 doc->type = type;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
888
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
889 doc->tabview = ui_int_new(ctx, "tabview");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
890 doc->loading = ui_int_new(ctx, "loading");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
891 doc->message = ui_string_new(ctx, "message");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
892
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
893 doc->text = ui_text_new(ctx, "text");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
894 doc->image = ui_generic_new(ctx, "image");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
895
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
896 doc->properties = ui_list_new(ctx, "properties");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
897
52
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
898 doc->info_url = ui_string_new(ctx, "info_url");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
899 doc->info_name = ui_string_new(ctx, "info_name");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
900 doc->info_type = ui_string_new(ctx, "info_type");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
901 doc->info_encrypted = ui_string_new(ctx, "info_encrypted");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
902 doc->info_etag = ui_string_new(ctx, "info_etag");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
903 doc->info_size = ui_string_new(ctx, "info_size");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
904
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
905 doc->property_type = ui_int_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
906 doc->property_ns = ui_string_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
907 doc->property_name = ui_string_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
908 doc->property_nsdef = ui_string_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
909 doc->property_value = ui_text_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
910 doc->property_errormsg = ui_string_new(ctx, NULL);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
911
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
912 return doc;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
913 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
914
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
915 static char* gen_tmp_download_filename(const char *name) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
916 char *dir = ui_getappdir();
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
917
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
918 unsigned char rd[8];
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
919 memset(rd, 0, 8);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
920 dav_rand_bytes(rd, 8);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
921 char *hex = util_hexstr(rd, 8);
77
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
922 cxmutstr tmp = cx_asprintf("%sdownload-%s-%s", dir, hex, name);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
923 return tmp.ptr;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
924 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
925
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
926 static int jobthr_resourceviewer_load(void *data) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
927 DavResourceViewer *doc = data;
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
928
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
929 DavResource *res = dav_resource_new(doc->sn, doc->path);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
930 doc->error = dav_load(res);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
931 if(!doc->error) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
932 doc->current = res;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
933
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
934 if(res->contentlength < DAV_RESOURCEVIEWER_PREVIEW_MAX_SIZE) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
935 if(doc->type == DAV_RESOURCE_VIEW_TEXT) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
936 doc->text_content = cxBufferCreate(NULL, res->contentlength, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
937 int err = dav_get_content(res, doc->text_content, (dav_write_func)cxBufferWrite);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
938 cxBufferPut(doc->text_content, 0);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
939 if(err) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
940 doc->error = err;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
941 doc->message_str = "Cannot load content"; // TODO: better message
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
942 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
943 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
944 char *tmp = gen_tmp_download_filename(res->name);
77
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
945 FILE *f = sys_fopen(tmp, "wb");
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
946 if(f) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
947 int err = dav_get_content(res, f, (dav_write_func)fwrite);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
948 if(!err) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
949 doc->tmp_file = tmp;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
950 } else {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
951 free(tmp);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
952 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
953 fclose(f);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
954 } else {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
955 free(tmp);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
956 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
957 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
958 } else {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
959 // TODO: add file too large message
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
960 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
961 } else {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
962 doc->message_str = "Cannot load properties"; // TODO: better message
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
963 dav_resource_free(res);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
964 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
965
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
966 return 0;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
967 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
968
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
969 static void resourceviewer_set_info(DavResourceViewer *doc) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
970 DavResource *res = doc->current;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
971 if(!res) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
972 return;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
973 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
974
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
975 char *url = util_concat_path(res->session->base_url, res->href);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
976 ui_set(doc->info_url, url);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
977 free(url);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
978
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
979 ui_set(doc->info_name, res->name);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
980
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
981 if(res->iscollection) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
982 ui_set(doc->info_type, "Collection");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
983 } else {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
984 if(res->contenttype) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
985 cxmutstr type = cx_asprintf("Resource (%s)", res->contenttype);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
986 ui_set(doc->info_type, type.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
987 free(type.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
988 } else {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
989 ui_set(doc->info_type, "Resource");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
990 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
991 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
992
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
993 char *keyprop = dav_get_string_property_ns(
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
994 res,
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
995 DAV_NS,
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
996 "crypto-key");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
997 if(keyprop) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
998 cxmutstr info_encrypted = cx_asprintf("Yes Key: %s", keyprop);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
999 ui_set(doc->info_encrypted, info_encrypted.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1000 free(info_encrypted.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1001 } else {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1002 ui_set(doc->info_encrypted, "No");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1003 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1004
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1005 char *etag = dav_get_string_property_ns(
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1006 res,
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1007 "DAV:",
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1008 "getetag");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1009 ui_set(doc->info_etag, etag);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1010
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1011 if(res->contentlength > 0) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1012 char *sz = util_size_str(FALSE, res->contentlength);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1013 cxmutstr size_str = cx_asprintf("%s (%" PRIu64 " bytes)", sz, res->contentlength);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1014 ui_set(doc->info_size, size_str.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1015 free(size_str.ptr);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1016 } else {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1017 ui_set(doc->info_size, "0");
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1018 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1019 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1020
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1021 static void resourceviewer_update_proplist(DavResourceViewer *doc) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1022 DavResource *res = doc->current;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1023 if(!res) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1024 return;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1025 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1026
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1027 size_t count = 0;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1028 DavPropName *properties = dav_get_property_names(res, &count);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1029 for(int i=0;i<count;i++) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1030 DavPropertyList *prop = ui_malloc(doc->ctx, sizeof(DavPropertyList));
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1031 prop->ns = properties[i].ns ? ui_strdup(doc->ctx, properties[i].ns) : NULL;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1032 prop->name = ui_strdup(doc->ctx, properties[i].name);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1033 prop->value_simplified = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1034 prop->value_full = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1035 prop->update = FALSE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1036 prop->isnew = FALSE;
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1037
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1038 DavXmlNode *xval = dav_get_property_ns(res, prop->ns, prop->name);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1039 prop->xml = xval;
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1040 if(xval) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1041 if(dav_xml_isstring(xval)) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1042 char *value = dav_xml_getstring(xval);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1043 if(value) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1044 prop->value_simplified = NULL;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1045 prop->value_full = ui_strdup(doc->ctx, value);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1046 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1047 } else {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1048 DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1049 cxmutstr value = cx_asprintf_a(ui_allocator(doc->ctx), "<%s>...</%s>", x->name, x->name);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1050 prop->value_simplified = value.ptr;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1051 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1052 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1053
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1054 ui_list_append(doc->properties, prop);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1055 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1056 doc->properties->update(doc->properties, 0);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1057 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1058
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1059 static void resourceviewer_load_finished(UiEvent *event, void *data) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1060 DavResourceViewer *doc = data;
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1061
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1062 if(doc->window_closed) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1063 dav_resourceviewer_destroy(doc);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1064 return;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1065 }
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1066
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1067 resourceviewer_set_info(doc);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1068 resourceviewer_update_proplist(doc);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1069
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1070 if(doc->type == DAV_RESOURCE_VIEW_TEXT) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1071 ui_set(doc->text, doc->text_content->space);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1072 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1073 ui_image_load_file(doc->image, doc->tmp_file);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1074 }
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1075
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1076 ui_set(doc->tabview, 1);
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1077
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1078 doc->loaded = TRUE;
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1079 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1080
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1081 void dav_resourceviewer_load(UiObject *ui, DavResourceViewer *res) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1082 ui_set(res->loading, 1);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1083 ui_set(res->message, "Loading...");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1084 ui_set(res->tabview, 0);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1085
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1086 ui_job(ui, jobthr_resourceviewer_load, res, resourceviewer_load_finished, res);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1087 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1088
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1089
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1090 typedef struct ResourceViewerUploadFile {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1091 UiObject *ui;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1092 DavSession *sn;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1093 char *path;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1094 cxmutstr text;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1095 int error;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1096 } ResourceViewerUploadFile;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1097
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1098 static int jobthr_upload_text(void *data) {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1099 ResourceViewerUploadFile *upload = data;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1100
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1101 DavResource *res = dav_resource_new(upload->sn, upload->path);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1102 dav_set_content_data(res, upload->text.ptr, upload->text.length);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1103 upload->error = dav_store(res);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1104 dav_resource_free(res);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1105
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1106 return 0;
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1107 }
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1108
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1109 static void uithr_upload_text_finished(UiEvent *event, void *data) {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1110 ResourceViewerUploadFile *upload = data;
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1111 ui_object_unref(event->obj);
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1112
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1113 if(upload->error) {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1114 cxmutstr errormsg = cx_asprintf("Upload failed: %d", upload->sn->error); // TODO: add full error message
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1115 ui_dialog(event->obj, .title = "Error", .content = errormsg.ptr, .closebutton_label = "OK");
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1116 free(errormsg.ptr);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1117 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1118 }
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1119
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1120 free(upload->text.ptr);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1121 free(upload);
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1122 }
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1123
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1124 static int jobthr_store_properties(void *data) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1125 DavResourceViewer *res = data;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1126 res->error = dav_store(res->current);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1127 return 0;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1128 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1129
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1130 static void uithr_store_properties_finished(UiEvent *event, void *data) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1131 DavResourceViewer *res = data;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1132 ui_object_unref(event->obj);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1133 if(res->error) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1134 cxmutstr errormsg = cx_asprintf("Proppatch failed: %d", res->sn->error); // TODO: add full error message
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1135 ui_dialog(event->obj, .title = "Error", .content = errormsg.ptr, .closebutton_label = "OK");
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1136 free(errormsg.ptr);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1137 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1138 res->properties_modified = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1139 } else {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1140 CxList *properties = res->properties->data;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1141 CxIterator i = cxListIterator(properties);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1142 cx_foreach(DavPropertyList *, prop, i) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1143 prop->update = FALSE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1144 prop->isnew = FALSE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1145 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1146 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1147 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1148
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1149 void dav_resourceviewer_save(UiObject *ui, DavResourceViewer *res) {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1150 if(res->type == DAV_RESOURCE_VIEW_TEXT) {
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1151 ResourceViewerUploadFile *upload = malloc(sizeof(ResourceViewerUploadFile));
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1152 upload->ui = ui;
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1153 upload->sn = res->sn;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1154 upload->path = res->current->path;
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1155 char *text = ui_get(res->text);
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1156 upload->text = cx_strdup(cx_str(text));
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1157 ui_object_ref(res->obj);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1158 ui_threadpool_job(res->dav_queue, ui, jobthr_upload_text, upload, uithr_upload_text_finished, upload);
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1159 }
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1160
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1161 if(res->properties_modified) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1162 CxList *properties = res->properties->data;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1163 CxIterator i = cxListIterator(properties);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1164 cx_foreach(DavPropertyList *, prop, i) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1165 if(prop->update) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1166 if(prop->value_full) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1167 // text
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1168 dav_set_string_property_ns(res->current, prop->ns, prop->name, prop->value_full);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1169 } else {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1170 // xml
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1171 dav_set_property_ns(res->current, prop->ns, prop->name, prop->xml);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1172 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1173 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1174 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1175
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1176 ui_object_ref(res->obj);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1177 ui_threadpool_job(res->dav_queue, ui, jobthr_store_properties, res, uithr_store_properties_finished, res);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1178 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1179
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1180 ui_unset_group(ui->ctx, RESOURCEVIEWER_STATE_MODIFIED);
78
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1181 }
ad7ced6cf00b implement resourceviewer textfile save button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
1182
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1183 void dav_resourceviewer_destroy(DavResourceViewer *res) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1184
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1185 }
91
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1186
97
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1187 void dav_resourceviewer_property_remove(DavResourceViewer *res, DavPropertyList *prop) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1188 if(!prop->isnew) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1189 dav_remove_property_ns(res->current, prop->ns, prop->name);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1190 ui_set_group(res->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1191 res->properties_modified = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1192 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1193
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1194 CxList *properties = res->properties->data;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1195 cxListFindRemove(properties, prop);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1196 ui_free(res->ctx, prop->ns);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1197 ui_free(res->ctx, prop->name);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1198 ui_free(res->ctx, prop->value_simplified);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1199 ui_free(res->ctx, prop->value_full);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1200 // prop->xml freed by DavSession
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1201 ui_free(res->ctx, prop);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1202 ui_list_update(res->properties);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1203 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1204
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1205 void dav_resourceviewer_property_update_text(DavResourceViewer *res, DavPropertyList *prop, const char *text) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1206 ui_free(res->ctx, prop->value_simplified);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1207 ui_free(res->ctx, prop->value_full);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1208 prop->xml = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1209 prop->value_full = ui_strdup(res->ctx, text);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1210 prop->value_simplified = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1211 prop->update = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1212
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1213 ui_set_group(res->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1214 res->properties_modified = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1215 ui_list_update(res->properties);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1216 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1217
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1218 void dav_resourceviewer_property_update_xml(DavResourceViewer *res, DavPropertyList *prop, DavXmlNode *xml) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1219
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1220 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1221
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1222 void dav_resourceviewer_property_add_text(DavResourceViewer *res, const char *ns, const char *name, const char *text) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1223 DavPropertyList *prop = ui_malloc(res->ctx, sizeof(DavPropertyList));
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1224 prop->ns = ui_strdup(res->ctx, ns);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1225 prop->name = ui_strdup(res->ctx, name);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1226 prop->value_simplified = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1227 prop->value_full = ui_strdup(res->ctx, text);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1228 prop->xml = NULL;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1229 prop->isnew = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1230 prop->update = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1231
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1232 ui_list_append(res->properties, prop);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1233 ui_set_group(res->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1234 res->properties_modified = TRUE;
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1235 ui_list_update(res->properties);
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1236 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1237
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1238 void dav_resourceviewer_property_add_xml(DavResourceViewer *res, const char *ns, const char *name, const char *nsdef, DavXmlNode *xml) {
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1239
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1240 }
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1241
5a3d27b8e6b0 implement UI for editing properties, relates to #497
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
1242
91
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1243
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1244 uint64_t dav_transfer_speed(TransferProgress *progress, time_t current) {
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1245 size_t bytes = progress->transferred_bytes - progress->speedtest_bytes;
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1246 time_t t = current - progress->speedtest_start;
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1247
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1248 progress->speedtest_start = current;
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1249 progress->speedtest_bytes = progress->transferred_bytes;
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1250
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1251 return bytes/t;
7ee944cf53de add transfer speed indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
1252 }

mercurial