ui: server message
This commit is contained in:
+14
-9
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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; \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user