ui: server message

This commit is contained in:
2025-12-16 16:40:18 +02:00
parent ba33bab4d1
commit b5d638bbc9
13 changed files with 151 additions and 60 deletions
+14 -9
View File
@@ -2,6 +2,8 @@
#include "modals/ask_server_addr.h"
#include "modals/login_credentials.h"
#include "modals/login_option.h"
#include "modals/server_message.h"
// #include "modals/server_message.h"
// #include "action.h"
#include <ncurses.h>
#include <stdio.h>
@@ -128,20 +130,24 @@ void app_draw_modal(app_t *app) {
case S_ASK_LOGIN_USER:
init_login_credentials_modal(app);
break;
case S_PRINT_SERVER_MESSAGE:
init_server_message_modal(app);
break;
case WAIT_SERVER_INIT:
case WAIT_SERVER:
case WAIT_REGISTER:
case WAIT_REGISTER_CONFIRMATION:
case WAIT_CLIENT:
case UPLOAD_FILE:
case STATE_FILE_LIST:
case STATE_FILE_SELECT:
case STATE_FILE_DOWNLOAD:
case STATE_UPLOAD_PARAMS:
case STATE_UPLOAD_FILE:
case STATE_UPLOAD_REQUESTED:
case STATE_ASK_USER_BEFORE_LOGIN:
case STATE_ERR:
case S_FILE_LIST:
case S_FILE_SELECT:
case S_FILE_DOWNLOAD:
case S_UPLOAD_PARAMS:
case S_UPLOAD_FILE:
case S_UPLOAD_REQUESTED:
case S_ASK_USER_BEFORE_LOGIN:
case S_ERR:
case S_WAIT_SERVER:
case S_N_D:
return;
}
@@ -151,6 +157,5 @@ void app_draw_modal(app_t *app) {
void destroy_app(app_t *app) {
delwin(app->win);
// free(app);
endwin();
}
+1
View File
@@ -31,6 +31,7 @@ void asa_modal_dialogue_callback(callback_args_t *args) {
get_ip_port(app->params, in_ip->value, in_port->value);
connect_to_server(app);
destroy_dialogue(d);
app->query_args->state = S_WAIT_SERVER;
break;
case 1:
destroy_app(app);
+52
View File
@@ -0,0 +1,52 @@
#include <ncurses.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "../app.h"
#include "../widget/dialogue.h"
#include "../widget/group.h"
typedef struct {
button_t *element;
enum w_type type;
} group_bt_t;
void server_message_modal_cb(callback_args_t *args) {
int32_t response;
callback_args_t d_args;
app_t *app = args->app;
dialogue_t *d = (dialogue_t *)args->widget;
memcpy(&d_args, args, sizeof(callback_args_t));
d_args.app = NULL;
d_args.resp_data = &response;
dialogue_default_callback(&d_args);
if (response > -1) {
switch (response) {
case 0:
destroy_dialogue(d);
// TODO: macros
free(app->query_args->server_message.text);
app->query_args->server_message.capacity = 0;
app->query_args->server_message.size = 0;
app->query_args->state = S_ASK_LOGIN_USER;
break;
}
}
}
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}, {.type = w_end}};
init_dialogue(&(app->modal), "Server response",
app->query_args->server_message.text, &(app->coordinates));
app->modal.g_action =
init_group(&(app->modal.win), &(app->modal.w), children, horizontal);
app->modal.w.callback = server_message_modal_cb;
dialogue_init_active_id(&(app->modal));
return NULL;
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef SERVER_MESSAGE_H
#define SERVER_MESSAGE_H
#include "../widget/dialogue.h"
#include "../app.h"
void *init_server_message_modal(app_t *app);
#endif
+1 -1
View File
@@ -155,7 +155,7 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
group->w.m_y = y; \
if (line_max_len < group->w.x) { \
line_max_len = group->w.x; \
group->w.m_x = 0; /* when uses box */ \
group->w.m_x = 0; \
} else { \
group->w.m_x = (line_max_len - group->w.x) / 2; \
} \