32 |
32 |
33 #include <ui/stock.h> |
33 #include <ui/stock.h> |
34 #include <ui/dnd.h> |
34 #include <ui/dnd.h> |
35 |
35 |
36 #include <libidav/utils.h> |
36 #include <libidav/utils.h> |
|
37 |
|
38 #include <cx/printf.h> |
37 |
39 |
38 static UiIcon* folder_icon; |
40 static UiIcon* folder_icon; |
39 static UiIcon* file_icon; |
41 static UiIcon* file_icon; |
40 |
42 |
41 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data); |
43 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data); |
203 } |
205 } |
204 |
206 |
205 return NULL; |
207 return NULL; |
206 } |
208 } |
207 |
209 |
|
210 |
|
211 typedef struct AuthDialogWindow { |
|
212 UiString *user; |
|
213 UiString *password; |
|
214 } AuthDialogWindow; |
|
215 |
|
216 static void auth_dialog_action(UiEvent *event, void *data) { |
|
217 SessionAuthData *auth = data; |
|
218 AuthDialogWindow *wdata = event->window; |
|
219 int result = 0; |
|
220 if(event->intval == 4) { |
|
221 char *user = ui_get(wdata->user); |
|
222 char *password = ui_get(wdata->password); |
|
223 davbrowser_auth_set_user_pwd(auth, user, password); |
|
224 result = 1; |
|
225 } |
|
226 ui_condvar_signal(auth->cond, NULL, result); |
|
227 ui_close(event->obj); |
|
228 } |
|
229 |
|
230 void auth_dialog(SessionAuthData *auth) { |
|
231 UiObject *obj = ui_dialog_window(auth->obj, |
|
232 .title = "Authentication", |
|
233 .lbutton1 = "Cancel", |
|
234 .rbutton4 = "Connect", |
|
235 .default_button = 4, |
|
236 .show_closebutton = UI_OFF, |
|
237 .onclick = auth_dialog_action, |
|
238 .onclickdata = auth); |
|
239 |
|
240 AuthDialogWindow *wdata = ui_malloc(obj->ctx, sizeof(AuthDialogWindow)); |
|
241 wdata->user = ui_string_new(obj->ctx, NULL); |
|
242 wdata->password = ui_string_new(obj->ctx, NULL); |
|
243 obj->window = wdata; |
|
244 |
|
245 ui_grid(obj, .margin = 20, .columnspacing = 12, .rowspacing = 12) { |
|
246 cxmutstr heading = cx_asprintf("Authentication required for: %s", auth->sn->base_url); |
|
247 ui_llabel(obj, .label = heading.ptr, .colspan = 2); |
|
248 free(heading.ptr); |
|
249 ui_newline(obj); |
|
250 |
|
251 ui_llabel(obj, .label = "User"); |
|
252 ui_textfield(obj, .value = wdata->user, .hexpand = TRUE); |
|
253 ui_newline(obj); |
|
254 |
|
255 ui_llabel(obj, .label = "Password"); |
|
256 ui_passwordfield(obj, .value = wdata->password, .hexpand = TRUE); |
|
257 } |
|
258 |
|
259 if(auth->user) { |
|
260 ui_set(wdata->user, auth->user); |
|
261 } |
|
262 |
|
263 ui_show(obj); |
|
264 } |
|
265 |
|
266 |
|
267 |
208 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) { |
268 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) { |
209 cxstring fpath = cx_strn(full_path, len); |
269 cxstring fpath = cx_strn(full_path, len); |
210 int protocol = 0; |
270 int protocol = 0; |
211 if (cx_strcaseprefix(fpath, CX_STR("http://"))) { |
271 if (cx_strcaseprefix(fpath, CX_STR("http://"))) { |
212 protocol = 7; |
272 protocol = 7; |