application/window.c

changeset 56
294d5515583a
parent 54
3ca3acefc66a
child 57
d5a7dbc945ef
--- a/application/window.c	Wed Oct 23 10:37:43 2024 +0200
+++ b/application/window.c	Wed Oct 23 17:40:45 2024 +0200
@@ -35,6 +35,8 @@
 
 #include <libidav/utils.h>
 
+#include <cx/printf.h>
+
 static UiIcon* folder_icon;
 static UiIcon* file_icon;
 
@@ -205,6 +207,64 @@
     return NULL;
 }
 
+
+typedef struct AuthDialogWindow {
+    UiString *user;
+    UiString *password;
+} AuthDialogWindow;
+
+static void auth_dialog_action(UiEvent *event, void *data) {
+    SessionAuthData *auth = data;
+    AuthDialogWindow *wdata = event->window;
+    int result = 0;
+    if(event->intval == 4) {
+        char *user = ui_get(wdata->user);
+        char *password = ui_get(wdata->password);
+        davbrowser_auth_set_user_pwd(auth, user, password);
+        result = 1;
+    }
+    ui_condvar_signal(auth->cond, NULL, result);
+    ui_close(event->obj);
+}
+
+void auth_dialog(SessionAuthData *auth) {
+    UiObject *obj = ui_dialog_window(auth->obj,
+            .title = "Authentication", 
+            .lbutton1 = "Cancel",
+            .rbutton4 = "Connect",
+            .default_button = 4,
+            .show_closebutton = UI_OFF,
+            .onclick = auth_dialog_action,
+            .onclickdata = auth);
+    
+    AuthDialogWindow *wdata = ui_malloc(obj->ctx, sizeof(AuthDialogWindow));
+    wdata->user = ui_string_new(obj->ctx, NULL);
+    wdata->password = ui_string_new(obj->ctx, NULL);
+    obj->window = wdata;
+    
+    ui_grid(obj, .margin = 20, .columnspacing = 12, .rowspacing = 12) {
+        cxmutstr heading = cx_asprintf("Authentication required for: %s", auth->sn->base_url);
+        ui_llabel(obj, .label = heading.ptr, .colspan = 2);
+        free(heading.ptr);
+        ui_newline(obj);
+        
+        ui_llabel(obj, .label = "User");
+        ui_textfield(obj, .value = wdata->user, .hexpand = TRUE);
+        ui_newline(obj);
+        
+        ui_llabel(obj, .label = "Password");
+        ui_passwordfield(obj, .value = wdata->password, .hexpand = TRUE);
+    }
+     
+    if(auth->user) {
+        ui_set(wdata->user, auth->user);
+    }
+    
+    ui_show(obj);
+}
+
+
+
 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) {
     cxstring fpath = cx_strn(full_path, len);
     int protocol = 0;

mercurial