Tue, 30 Jan 2024 11:58:11 +0100
don't change the path bar value if the new path is a prefix of the current path
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> |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
35 | static UiIcon* folder_icon; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
36 | static UiIcon* file_icon; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
37 | |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
38 | 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
|
39 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
40 | void window_init(void) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
41 | folder_icon = ui_foldericon(16); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
42 | file_icon = ui_fileicon(16); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
43 | } |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | UiObject* window_create(void) { |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | UiObject* obj = ui_window("iDAV", NULL); |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
7
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
48 | MainWindow* wdata = ui_malloc(obj->ctx, sizeof(MainWindow)); |
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
49 | memset(wdata, 0, sizeof(MainWindow)); |
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
50 | obj->window = wdata; |
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
51 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
52 | wdata->progress = ui_int_new(obj->ctx, "progress"); |
7
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
53 | |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | // navigation bar |
3
f154867f54dc
add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
55 | ui_hbox(obj, .fill = UI_OFF, .margin = 8) { |
f154867f54dc
add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
56 | ui_button(obj, .icon = "Back"); |
f154867f54dc
add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
57 | ui_button(obj, .icon = "Forward"); |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
59 | 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
|
60 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
61 | ui_progressspinner(obj, .value = wdata->progress); |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | // main content |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING, "Last Modified", UI_STRING, "Size", -1); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
66 | model->getvalue = (ui_getvaluefunc)window_resource_table_getvalue; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
67 | ui_table(obj, .fill = UI_ON, .model = model, .varname = "reslist"); |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | // status bar |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | ui_hbox(obj, .fill = UI_OFF) { |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | ui_label(obj, .label = ""); |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | } |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | ui_model_free(obj->ctx, model); |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | return obj; |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
78 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
79 | void* window_resource_table_getvalue(DavResource *res, int col) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
80 | switch (col) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
81 | case 0: { // icon |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
82 | return res->iscollection ? folder_icon : file_icon; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
83 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
84 | case 1: { // resource name |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
85 | return res->name; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
86 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
87 | case 2: { // type |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
88 | return ""; // TODO |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
89 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
90 | case 3: { // last modified |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
91 | return ""; // TODO |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
92 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
93 | case 4: { // size |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
94 | return ""; // TODO |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
95 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
96 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
97 | return NULL; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
98 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
99 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
100 | void window_progress(MainWindow *win, int on) { |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
101 | ui_set(win->progress, on); |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
102 | } |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
103 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
104 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
105 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
106 | 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
|
107 | cxstring fpath = cx_strn(full_path, len); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
108 | int protocol = 0; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
109 | if(cx_strcaseprefix(fpath, CX_STR("http://"))) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
110 | protocol = 7; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
111 | } else if (cx_strcaseprefix(fpath, CX_STR("https://"))) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
112 | protocol = 8; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
113 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
114 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
115 | size_t start = 0; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
116 | size_t end = 0; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
117 | for (size_t i = protocol; i < len; i++) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
118 | if (full_path[i] == '/') { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
119 | end = i; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
120 | break; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
121 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
122 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
123 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
124 | int skip = 0; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
125 | if (end == 0) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
126 | // no '/' found or first char is '/' |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
127 | end = len > 0 && full_path[0] == '/' ? 1 : len; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
128 | } else if (end + 1 <= len) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
129 | skip++; // skip first '/' |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
130 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
131 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
132 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
133 | cxmutstr base = cx_strdup(cx_strn(full_path, end)); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
134 | cxmutstr base_path = cx_strdup(cx_strcast(base)); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
135 | cxstring path = cx_strsubs(fpath, end+skip); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
136 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
137 | cxstring *pathelms; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
138 | size_t nelm = cx_strsplit_a(cxDefaultAllocator, path, CX_STR("/"), 4096, &pathelms); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
139 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
140 | if (nelm == 0) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
141 | *ret_nelm = 0; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
142 | return NULL; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
143 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
144 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
145 | UiPathElm* elms = (UiPathElm*)calloc(nelm + 1, sizeof(UiPathElm)); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
146 | size_t n = nelm + 1; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
147 | elms[0].name = base.ptr; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
148 | elms[0].name_len = base.length; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
149 | elms[0].path = base_path.ptr; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
150 | elms[0].path_len = base_path.length; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
151 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
152 | int j = 1; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
153 | for (int i = 0; i < nelm; i++) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
154 | cxstring c = pathelms[i]; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
155 | if (c.length == 0) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
156 | if (i == 0) { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
157 | c.length = 1; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
158 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
159 | else { |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
160 | n--; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
161 | continue; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
162 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
163 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
164 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
165 | cxmutstr m = cx_strdup(c); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
166 | elms[j].name = m.ptr; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
167 | elms[j].name_len = m.length; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
168 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
169 | size_t elm_path_len = c.ptr + c.length - full_path; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
170 | cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
171 | elms[j].path = elm_path.ptr; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
172 | elms[j].path_len = elm_path.length; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
173 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
174 | j++; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
175 | } |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
176 | *ret_nelm = n; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
177 | |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
178 | return elms; |
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
179 | } |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
180 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
181 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
182 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
183 | void action_path_selected(UiEvent *event, void *data) { |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
184 | DavBrowser *browser = event->document; |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
185 | char *path = event->eventdata; |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
186 | davbrowser_query_url(event->obj, browser, path); |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
187 | } |