application/window.c

Tue, 11 Jun 2024 21:45:39 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 11 Jun 2024 21:45:39 +0200
changeset 38
acd8c4a9d3fe
parent 37
9b754f1b7e16
child 40
af5c2bfe0f21
permissions
-rw-r--r--

fix path textfield

2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
fbdfaacc4182 update ucx, libidav and add first gui code
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
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "window.h"
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
31 #include "davcontroller.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
32
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ui/stock.h>
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
34 #include <ui/dnd.h>
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
36 #include <libidav/utils.h>
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
37
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
38 static UiIcon* folder_icon;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
39 static UiIcon* file_icon;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
40
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
41 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data);
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
42
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
43 void window_init(void) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
44 folder_icon = ui_foldericon(16);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
45 file_icon = ui_fileicon(16);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
46 }
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 UiObject* window_create(void) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
49 UiObject* obj = ui_window("iDAV", NULL);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
50 ui_window_size(obj, 900, 700);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
52 MainWindow* wdata = ui_malloc(obj->ctx, sizeof (MainWindow));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
53 memset(wdata, 0, sizeof (MainWindow));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
54 obj->window = wdata;
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
55
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
56 wdata->progress = ui_int_new(obj->ctx, "progress");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
57
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
58 // navigation bar
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
59
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
60 ui_hbox(obj, .fill = UI_OFF, .margin = 8) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
61 ui_button(obj, .icon = UI_ICON_GO_BACK, .onclick = action_go_back);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
62 ui_button(obj, .icon = UI_ICON_GO_FORWARD, .onclick = action_go_forward);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
64 ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .onactivate = action_path_selected, .varname = "path");
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
65
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
66 ui_progressspinner(obj, .value = wdata->progress);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
67 }
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
69 // main content
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
70 UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING_FREE, "Last Modified", UI_STRING_FREE, "Size", -1);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
71 model->getvalue = (ui_getvaluefunc) window_resource_table_getvalue;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
72 ui_table(obj, .fill = UI_ON, .model = model, .onactivate = action_list_activate, .ondrop = action_dnd_drop, .varname = "reslist");
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
74 // status bar
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
76 ui_hbox(obj, .fill = UI_OFF) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
77 ui_label(obj, .label = "");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
78 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
79
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
80 return obj;
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
82
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
83 void* window_resource_table_getvalue(DavResource *res, int col) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
84 switch (col) {
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
85 case 0: { // icon
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
86 return res->iscollection ? folder_icon : file_icon;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
87 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
88 case 1: { // resource name
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
89 return res->name;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
90 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
91 case 2: { // type
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
92 return res->iscollection ? "Collection" : (res->contenttype ? res->contenttype : "Resource");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
93 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
94 case 3: { // last modified
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
95 return util_date_str(res->lastmodified);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
96 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
97 case 4: { // size
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
98 return util_size_str(res->iscollection, res->contentlength);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
99 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
100 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
101 return NULL;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
102 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
103
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
104 void window_progress(MainWindow *win, int on) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
105 ui_set(win->progress, on);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
106 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
107
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
108 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
109 cxstring fpath = cx_strn(full_path, len);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
110 int protocol = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
111 if (cx_strcaseprefix(fpath, CX_STR("http://"))) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
112 protocol = 7;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
113 } else if (cx_strcaseprefix(fpath, CX_STR("https://"))) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
114 protocol = 8;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
115 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
116
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
117 size_t start = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
118 size_t end = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
119 for (size_t i = protocol; i < len; i++) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
120 if (full_path[i] == '/') {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
121 end = i;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
122 break;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
123 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
124 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
125
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
126 int skip = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
127 if (end == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
128 // no '/' found or first char is '/'
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
129 end = len > 0 && full_path[0] == '/' ? 1 : len;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
130 } else if (end + 1 <= len) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
131 skip++; // skip first '/'
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
132 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
133
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
134
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
135 cxmutstr base = cx_strdup(cx_strn(full_path, end));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
136 cxmutstr base_path = cx_strdup(cx_strcast(base));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
137 cxstring path = cx_strsubs(fpath, end + skip);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
138
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
139 cxstring *pathelms;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
140 size_t nelm = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
141
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
142 if (path.length > 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
143 nelm = cx_strsplit_a(cxDefaultAllocator, path, CX_STR("/"), 4096, &pathelms);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
144 if (nelm == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
145 *ret_nelm = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
146 return NULL;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
147 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
148 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
149
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
150 UiPathElm* elms = (UiPathElm*) calloc(nelm + 1, sizeof (UiPathElm));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
151 size_t n = nelm + 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
152 elms[0].name = base.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
153 elms[0].name_len = base.length;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
154 elms[0].path = base_path.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
155 elms[0].path_len = base_path.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
156
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
157 int j = 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
158 for (int i = 0; i < nelm; i++) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
159 cxstring c = pathelms[i];
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
160 if (c.length == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
161 if (i == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
162 c.length = 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
163 } else {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
164 n--;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
165 continue;
34
98e041f2f9a2 fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
166 }
98e041f2f9a2 fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
167 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
168
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
169 cxmutstr m = cx_strdup(c);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
170 elms[j].name = m.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
171 elms[j].name_len = m.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
172
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
173 size_t elm_path_len = c.ptr + c.length - full_path;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
174 cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
175 elms[j].path = elm_path.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
176 elms[j].path_len = elm_path.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
177
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
178 j++;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
179 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
180 *ret_nelm = n;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
181
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
182 return elms;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
183 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
184
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
185 void action_go_back(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
186 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
187 davbrowser_navigation_back(event->obj, browser);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
188 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
189
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
190 void action_go_forward(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
191 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
192 davbrowser_navigation_forward(event->obj, browser);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
193 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
194
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
195 void action_path_selected(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
196 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
197 char *path = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
198 if (path && strlen(path) > 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
199 davbrowser_query_url(event->obj, browser, path);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
200 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
201 }
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
202
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
203 void action_list_activate(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
204 UiListSelection *selection = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
205 DavBrowser *browser = event->document;
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
206
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
207 if (selection->count == 1) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
208 DavResource *res = ui_list_get(browser->resources, selection->rows[0]);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
209 if (res) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
210 if (res->iscollection) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
211 davbrowser_query_path(event->obj, browser, res->path);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
212 } else {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
213 // TODO
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
214 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
215 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
216 }
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
217 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
218
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
219 void action_dnd_drop(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
220 UiListDnd *listdnd = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
221 UiDnD *dnd = listdnd->dnd;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
222 UiFileList files = ui_selection_geturis(dnd);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
223
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
224 davbrowser_upload_files(event->obj, event->document, files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
225 }

mercurial