33 #include <ui/stock.h> |
33 #include <ui/stock.h> |
34 |
34 |
35 static UiIcon* folder_icon; |
35 static UiIcon* folder_icon; |
36 static UiIcon* file_icon; |
36 static UiIcon* file_icon; |
37 |
37 |
|
38 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data); |
|
39 |
38 void window_init(void) { |
40 void window_init(void) { |
39 folder_icon = ui_foldericon(16); |
41 folder_icon = ui_foldericon(16); |
40 file_icon = ui_fileicon(16); |
42 file_icon = ui_fileicon(16); |
41 } |
43 } |
42 |
44 |
52 // navigation bar |
54 // navigation bar |
53 ui_hbox(obj, .fill = UI_OFF, .margin = 8) { |
55 ui_hbox(obj, .fill = UI_OFF, .margin = 8) { |
54 ui_button(obj, .icon = "Back"); |
56 ui_button(obj, .icon = "Back"); |
55 ui_button(obj, .icon = "Forward"); |
57 ui_button(obj, .icon = "Forward"); |
56 |
58 |
57 ui_path_textfield(obj, .fill = UI_ON, .varname = "path"); |
59 ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .varname = "path"); |
58 |
60 |
59 ui_progressspinner(obj, .value = wdata->progress); |
61 ui_progressspinner(obj, .value = wdata->progress); |
60 } |
62 } |
61 |
63 |
62 // main content |
64 // main content |
96 } |
98 } |
97 |
99 |
98 void window_progress(MainWindow *win, int on) { |
100 void window_progress(MainWindow *win, int on) { |
99 ui_set(win->progress, on); |
101 ui_set(win->progress, on); |
100 } |
102 } |
|
103 |
|
104 |
|
105 |
|
106 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) { |
|
107 cxstring fpath = cx_strn(full_path, len); |
|
108 int protocol = 0; |
|
109 if(cx_strcaseprefix(fpath, CX_STR("http://"))) { |
|
110 protocol = 7; |
|
111 } else if (cx_strcaseprefix(fpath, CX_STR("https://"))) { |
|
112 protocol = 8; |
|
113 } |
|
114 |
|
115 size_t start = 0; |
|
116 size_t end = 0; |
|
117 for (size_t i = protocol; i < len; i++) { |
|
118 if (full_path[i] == '/') { |
|
119 end = i; |
|
120 break; |
|
121 } |
|
122 } |
|
123 |
|
124 int skip = 0; |
|
125 if (end == 0) { |
|
126 // no '/' found or first char is '/' |
|
127 end = len > 0 && full_path[0] == '/' ? 1 : len; |
|
128 } else if (end + 1 <= len) { |
|
129 skip++; // skip first '/' |
|
130 } |
|
131 |
|
132 |
|
133 cxmutstr base = cx_strdup(cx_strn(full_path, end)); |
|
134 cxmutstr base_path = cx_strdup(cx_strcast(base)); |
|
135 cxstring path = cx_strsubs(fpath, end+skip); |
|
136 |
|
137 cxstring *pathelms; |
|
138 size_t nelm = cx_strsplit_a(cxDefaultAllocator, path, CX_STR("/"), 4096, &pathelms); |
|
139 |
|
140 if (nelm == 0) { |
|
141 *ret_nelm = 0; |
|
142 return NULL; |
|
143 } |
|
144 |
|
145 UiPathElm* elms = (UiPathElm*)calloc(nelm + 1, sizeof(UiPathElm)); |
|
146 size_t n = nelm + 1; |
|
147 elms[0].name = base.ptr; |
|
148 elms[0].name_len = base.length; |
|
149 elms[0].path = base_path.ptr; |
|
150 elms[0].path_len = base_path.length; |
|
151 |
|
152 int j = 1; |
|
153 for (int i = 0; i < nelm; i++) { |
|
154 cxstring c = pathelms[i]; |
|
155 if (c.length == 0) { |
|
156 if (i == 0) { |
|
157 c.length = 1; |
|
158 } |
|
159 else { |
|
160 n--; |
|
161 continue; |
|
162 } |
|
163 } |
|
164 |
|
165 cxmutstr m = cx_strdup(c); |
|
166 elms[j].name = m.ptr; |
|
167 elms[j].name_len = m.length; |
|
168 |
|
169 size_t elm_path_len = c.ptr + c.length - full_path; |
|
170 cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); |
|
171 elms[j].path = elm_path.ptr; |
|
172 elms[j].path_len = elm_path.length; |
|
173 |
|
174 j++; |
|
175 } |
|
176 *ret_nelm = n; |
|
177 |
|
178 return elms; |
|
179 } |