ui: finishes nested groups; +email field in registration modal

This commit is contained in:
2026-02-26 15:07:04 +02:00
parent b10766f6e3
commit 8f6ec355e7
14 changed files with 71 additions and 64 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ void notification(const char *title, const char *message,
return;
group_el_init_t actions[] = {
{.type = w_button, .label = "OK", .is_default = 1}, {.type = w_end}};
{.type = w_button, .label = "OK", .is_default = true}, {.type = w_end}};
dialogue_t *d = malloc(sizeof(dialogue_t));
+3 -10
View File
@@ -1,17 +1,10 @@
#include <stdint.h>
#include <string.h>
#include <ncurses.h>
// #include "../app.h"
// #include "../widget/dialogue.h"
// #include "../widget/group.h"
// #include "../widget/input.h"
// #include "../widget/button.h"
#include <widget.h>
#include <widget_core.h>
#include "../connection.h"
#include "group.h"
#include "widget_core.h"
typedef struct {
button_t *element;
@@ -51,8 +44,8 @@ dialogue_t *init_asa_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Connect", .is_default = 1},
{.type = w_button, .label = "Cancel", .is_default = 0},
{.type = w_button, .label = "Connect", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}};
init_dialogue(&(app->modal), "Connect to server",
+1 -1
View File
@@ -17,7 +17,7 @@ dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload) {
sprintf(text, "%s file: %s", is_upload ? "Uploading" : "Downloading",
is_upload ? app->query_args->file->name : app->file_args->f_selected.name);
group_el_init_t actions[] = {
{.type = w_button, .label = "Cancel", .is_default = 1}, {.type = w_end}};
{.type = w_button, .label = "Cancel", .is_default = true, .val.num = 1}, {.type = w_end}};
app->modal.w.parent_win = &app->win;
init_dialogue(&(app->modal), is_upload ? "Upload" : "Download", text,
+4 -4
View File
@@ -24,7 +24,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val) {
switch (d_args.resp_data.val.val.num) {
case 0:
case 1:
app->params->uname = malloc(in_name->value_len + 1);
app->params->pass = malloc(in_pass->value_len + 1);
strncpy(app->params->uname, in_name->value, in_name->value_len);
@@ -36,7 +36,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
d->needs_destroy = true;
print_bars(app);
break;
case 1:
case 2:
app->query_args->state = S_ASK_LOGIN_TYPE;
app->modal.needs_destroy = true;
}
@@ -55,8 +55,8 @@ dialogue_t *init_login_credentials_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Login", .is_default = true},
{.type = w_button, .label = "Cancel", .is_default = false},
{.type = w_button, .label = "Login", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}};
init_dialogue(&(app->modal), "Login", "Your login credentials",
+6 -6
View File
@@ -22,7 +22,7 @@ void login_modal_option_cb(callback_args_t *args) {
dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val) {
switch (d_args.resp_data.val.val.num) {
case 0:
case 1:
d->needs_destroy = true;
app->params->uname = malloc(sizeof "anonymous");
strcpy(app->params->uname, "anonymous");
@@ -30,11 +30,11 @@ void login_modal_option_cb(callback_args_t *args) {
app->query_args->state = S_WAIT_SERVER;
print_bars(app);
break;
case 1:
case 2:
d->needs_destroy = true;
app->query_args->state = S_ASK_LOGIN_USER;
break;
case 2:
case 3:
d->needs_destroy = true;
app->query_args->state = S_ASK_REGISTER;
break;
@@ -45,9 +45,9 @@ void login_modal_option_cb(callback_args_t *args) {
dialogue_t *init_login_option_modal(app_t *app) {
if (app == NULL)
return NULL;
group_el_init_t children[] = {{.type = w_button, .label = "Anonymous"},
{.type = w_button, .label = "User"},
{.type = w_button, .label = "Register"},
group_el_init_t children[] = {{.type = w_button, .label = "Anonymous", .val.num = 1},
{.type = w_button, .label = "User", .val.num = 2},
{.type = w_button, .label = "Register", .val.num = 3},
{.type = w_end}};
init_dialogue(&(app->modal), "Login",
+1 -1
View File
@@ -29,7 +29,7 @@ dialogue_t *init_notification_modal(app_t *app) {
return NULL;
group_el_init_t actions[] = {
{.type = w_button, .label = "OK", .is_default = 1, .val.num = 1},
{.type = w_button, .label = "OK", .is_default = true, .val.num = 1},
{.type = w_end}};
init_dialogue(&(app->modal), "Notification", app->query_args->notification,
+12 -9
View File
@@ -25,14 +25,17 @@ void init_register_modal_cb(callback_args_t *args) {
memcpy(&d_args, args, sizeof(callback_args_t));
d_args.app = NULL;
d_args.element = app->active_widget;
input_t *in_name = d->g_content->elements[0].element;
input_t *in_pass = d->g_content->elements[1].element;
input_t *in_pass_r = d->g_content->elements[2].element;
group_t *g_email_user = d->g_content->elements[0].element;
group_t *g_passwords = d->g_content->elements[1].element;
input_t *in_name = g_email_user->elements[0].element;
input_t *in_email = g_email_user->elements[1].element;
input_t *in_pass = g_passwords->elements[0].element;
input_t *in_pass_r = g_passwords->elements[1].element;
dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val &&
d_args.resp_data.val.type == val_num) {
switch (d_args.resp_data.val.val.num) {
case 0:
case 1:
if (strcmp(in_pass->value, in_pass_r->value)) {
alert("Your passwords do not match");
in_pass->value[0] = '\0';
@@ -47,12 +50,12 @@ void init_register_modal_cb(callback_args_t *args) {
app->params->uname[in_name->value_len] = 0;
strncpy(app->params->pass, in_pass->value, in_pass->value_len);
app->params->pass[in_pass->value_len] = 0;
sprintf(query, "register %s %s\n%n", app->params->uname,
app->params->pass, &qlen);
sprintf(query, "register %s %s %*s\n%n", app->params->uname,
app->params->pass, (int) in_email->value_len, in_email->value, &qlen);
write(app->params->sd, query, qlen);
app->query_args->state = S_WAIT_REGISTER_CONFIRMATION;
break;
case 1:
case 2:
app->query_args->state = S_ASK_LOGIN_TYPE;
app->modal.needs_destroy = true;
}
@@ -83,8 +86,8 @@ dialogue_t *init_register_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Register", .is_default = true},
{.type = w_button, .label = "Cancel", .is_default = false},
{.type = w_button, .label = "Register", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}};
init_dialogue(&(app->modal), "Credentials", "There is information needed",
+1 -1
View File
@@ -38,7 +38,7 @@ void *init_server_message_modal(app_t *app) {
if (app == NULL)
return NULL;
group_el_init_t children[] = {
{.type = w_button, .label = "OK", .is_default = 1, .val.num = 1}, {.type = w_end}};
{.type = w_button, .label = "OK", .is_default = true, .val.num = 1}, {.type = w_end}};
init_dialogue(&(app->modal), "Server response",
app->query_args->server_message.text, &(app->coordinates));
+1 -1
View File
@@ -42,7 +42,7 @@ dialogue_t *init_upload_dialogue_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_end}};
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 0}, {.type = w_end}};
app->modal.w.parent_win = &app->win;
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
+2 -2
View File
@@ -52,8 +52,8 @@ dialogue_t *init_upload_props_dialogue_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Upload", .is_default = 1},
{.type = w_button, .label = "Cancel", .is_default = 0},
{.type = w_button, .label = "Upload", .is_default = true},
{.type = w_button, .label = "Cancel", .is_default = false},
{.type = w_end},
};