ui integration into event loop; login modals
This commit is contained in:
+7
-4
@@ -1,4 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "ui/app.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
@@ -10,13 +11,15 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void connect_to_server(int sd, params_t *params) {
|
||||
void connect_to_server(app_t *app) {
|
||||
struct sockaddr_in server;
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_addr.s_addr = params->addr;
|
||||
server.sin_port = params->port;
|
||||
if (-1 == connect(sd, (struct sockaddr *)&server, sizeof(server))) {
|
||||
server.sin_addr.s_addr = app->params->addr;
|
||||
server.sin_port = app->params->port;
|
||||
if (-1 ==
|
||||
connect(app->params->sd, (struct sockaddr *)&server, sizeof(server))) {
|
||||
perror("connect");
|
||||
destroy_app(app);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
#include "main.h"
|
||||
#include "ui/app.h"
|
||||
|
||||
void connect_to_server(int sd, params_t *params);
|
||||
void connect_to_server(app_t *params);
|
||||
void init_params(params_t *restrict);
|
||||
void clear_params(params_t *params);
|
||||
void get_ip_port(params_t *params, char *ip, char *port);
|
||||
|
||||
+17
-10
@@ -1,17 +1,24 @@
|
||||
client.o: src/client.c src/file_processor.h src/main.h src/types.h \
|
||||
src/client.h
|
||||
connection.o: src/connection.c src/main.h src/types.h
|
||||
connection.o: src/connection.c src/main.h src/types.h src/ui/app.h \
|
||||
src/ui/../common.h src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
||||
src/ui/widget/../../main.h src/ui/widget/../../common.h \
|
||||
src/ui/widget/button.h src/ui/widget/../../main.h src/ui/widget/group.h
|
||||
file_processor.o: src/file_processor.c src/client.h src/main.h \
|
||||
src/types.h src/query.h
|
||||
main.o: src/main.c src/connection.h src/main.h src/types.h src/ui/app.h \
|
||||
src/types.h src/query.h src/ui/app.h src/ui/../common.h \
|
||||
src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
||||
src/ui/widget/../../main.h src/ui/widget/../../common.h \
|
||||
src/ui/widget/button.h src/ui/widget/../../main.h src/ui/widget/group.h
|
||||
main.o: src/main.c src/connection.h src/main.h src/types.h src/ui/app.h \
|
||||
src/ui/../common.h src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
||||
src/ui/widget/../../main.h src/ui/widget/../../common.h \
|
||||
src/ui/widget/button.h src/ui/widget/../../main.h src/ui/widget/group.h \
|
||||
src/ui/../common.h src/ui/modals/ask_server_addr.h \
|
||||
src/ui/modals/../app.h src/ui/modals/../widget/dialogue.h \
|
||||
src/ui/modals/login.h src/ui/widget.h src/ui/widget/dialogue.h
|
||||
query.o: src/query.c src/file_processor.h src/main.h src/types.h \
|
||||
src/connection.h src/client.h src/server.h
|
||||
server.o: src/server.c src/client.h src/main.h src/types.h src/query.h \
|
||||
src/ui.h
|
||||
src/query.h src/ui/widget.h src/ui/widget/dialogue.h
|
||||
query.o: src/query.c src/client.h src/main.h src/types.h src/connection.h \
|
||||
src/ui/app.h src/ui/../common.h src/ui/widget/dialogue.h \
|
||||
src/ui/widget/../widget.h src/ui/widget/../../main.h \
|
||||
src/ui/widget/../../common.h src/ui/widget/button.h \
|
||||
src/ui/widget/../../main.h src/ui/widget/group.h src/file_processor.h \
|
||||
src/server.h
|
||||
server.o: src/server.c src/client.h src/main.h src/types.h src/ui.h
|
||||
ui.o: src/ui.c
|
||||
|
||||
+36
-80
@@ -11,20 +11,21 @@
|
||||
|
||||
#include "connection.h"
|
||||
#include "main.h"
|
||||
#include "query.h"
|
||||
#include "ui/app.h"
|
||||
#include "ui/modals/ask_server_addr.h"
|
||||
#include "ui/modals/login.h"
|
||||
#include "ui/widget.h"
|
||||
#include "ui/widget/dialogue.h"
|
||||
|
||||
uint32_t m_id = 0;
|
||||
|
||||
void event_loop(app_t *app);
|
||||
void app_refresh(app_t *app);
|
||||
int32_t process_user_input(app_t *app, callback_args_t *d_args);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
app_t *app;
|
||||
params_t params;
|
||||
query_args_t *q_args = malloc(sizeof(query_args_t));
|
||||
char buf[INBUFSIZE];
|
||||
|
||||
app = calloc(1, sizeof(app_t));
|
||||
|
||||
init_nc();
|
||||
@@ -37,89 +38,44 @@ int main(int argc, char **argv) {
|
||||
wrefresh(app->left_win);
|
||||
wrefresh(app->right_win);
|
||||
|
||||
// temporal
|
||||
app->modal.type = ask_server_addr;
|
||||
init_query_args(q_args, app->params);
|
||||
q_args->buf = malloc(INBUFSIZE);
|
||||
app->query_args = q_args;
|
||||
|
||||
event_loop(app);
|
||||
/* init client to connect to the server */
|
||||
app->params->sd = init_client();
|
||||
|
||||
if (params.addr == 0) {
|
||||
app->query_args->state = S_ASK_SEVER_IP;
|
||||
} else {
|
||||
connect_to_server(app);
|
||||
app->query_args->state = S_ASK_LOGIN_TYPE;
|
||||
}
|
||||
|
||||
query_loop(app);
|
||||
clear_params(¶ms);
|
||||
destroy_app(app);
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void app_draw_modal(app_t *app);
|
||||
|
||||
void event_loop(app_t *app) {
|
||||
int32_t process_user_input(app_t *app, callback_args_t *d_args) {
|
||||
int32_t c;
|
||||
|
||||
callback_args_t d_args = {.app = app,
|
||||
.win = NULL,
|
||||
.widget = NULL,
|
||||
.data = (void *)&c,
|
||||
.resp_data = NULL};
|
||||
c = wgetch(app->win);
|
||||
switch (c) {
|
||||
case KEY_F(9):
|
||||
destroy_app(app);
|
||||
return OK;
|
||||
default:
|
||||
if (app->modal.win != NULL) {
|
||||
d_args->data = (void *)&c;
|
||||
d_args->win = app->modal.win;
|
||||
d_args->widget = &(app->modal);
|
||||
app->modal.w.callback(d_args);
|
||||
}
|
||||
break;
|
||||
}
|
||||
app_draw_modal(app);
|
||||
app_refresh(app);
|
||||
for (;;) {
|
||||
c = wgetch(app->win);
|
||||
switch (c) {
|
||||
case KEY_F(9):
|
||||
destroy_app(app);
|
||||
return;
|
||||
default:
|
||||
if (app->modal.type != none) {
|
||||
d_args.win = app->modal.dialogue.win;
|
||||
d_args.widget = &(app->modal.dialogue);
|
||||
app->modal.dialogue.w.callback(&d_args);
|
||||
}
|
||||
break;
|
||||
}
|
||||
app_draw_modal(app);
|
||||
app_refresh(app);
|
||||
};
|
||||
return OK;
|
||||
}
|
||||
|
||||
void app_refresh(app_t *app) {
|
||||
draw_borders(app);
|
||||
|
||||
wnoutrefresh(app->win);
|
||||
wnoutrefresh(app->left_win);
|
||||
wnoutrefresh(app->right_win);
|
||||
if (app->modal.type != none) {
|
||||
if (app->modal.dialogue.is_initiated == 0) {
|
||||
app->modal.type = none;
|
||||
} else {
|
||||
wnoutrefresh(app->modal.dialogue.win);
|
||||
}
|
||||
}
|
||||
doupdate();
|
||||
}
|
||||
|
||||
void app_draw_modal(app_t *app) {
|
||||
if (app->modal.type != none && !app->modal.dialogue.is_initiated) {
|
||||
switch (app->modal.type) {
|
||||
case login:
|
||||
init_login_modal(app);
|
||||
break;
|
||||
case ask_server_addr:
|
||||
init_asa_modal(app);
|
||||
break;
|
||||
case none:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
draw_dialogue(&(app->modal.dialogue));
|
||||
}
|
||||
}
|
||||
|
||||
// int main(int argc, char *argv[]) {
|
||||
// params_t params;
|
||||
// init_params(¶ms);
|
||||
// analyze_args(argc, argv, ¶ms);
|
||||
// get_missing_params(¶ms);
|
||||
// int sd = init_client();
|
||||
// connect_to_server(sd, ¶ms);
|
||||
// query_loop(sd, ¶ms);
|
||||
// clear_params(¶ms);
|
||||
// return 0;
|
||||
// }
|
||||
@@ -20,9 +20,14 @@ typedef struct params {
|
||||
char *uname;
|
||||
char *pass;
|
||||
char privileges;
|
||||
int32_t sd;
|
||||
} params_t;
|
||||
|
||||
enum state {
|
||||
S_N_D,
|
||||
S_ASK_SEVER_IP,
|
||||
S_ASK_LOGIN_TYPE,
|
||||
S_ASK_LOGIN_USER,
|
||||
WAIT_SERVER_INIT,
|
||||
WAIT_SERVER,
|
||||
WAIT_REGISTER,
|
||||
|
||||
+51
-40
@@ -1,12 +1,9 @@
|
||||
#include "file_processor.h"
|
||||
#include "connection.h"
|
||||
#include "client.h"
|
||||
#include "main.h"
|
||||
#include "server.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <ncurses.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -19,34 +16,45 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void init_query_args(query_args_t *q_args, int sd, char *buf,
|
||||
enum state state, int buf_used, params_t *params);
|
||||
#include "client.h"
|
||||
#include "connection.h"
|
||||
#include "file_processor.h"
|
||||
#include "main.h"
|
||||
#include "server.h"
|
||||
#include "ui/app.h"
|
||||
|
||||
static void wait_side(query_args_t *q_args);
|
||||
void user_request_description(query_args_t *q_args);
|
||||
int process_query(query_args_t *query_args, file_args_t *file_args);
|
||||
int32_t process_user_input(app_t *app, callback_args_t *d_args);
|
||||
|
||||
void query_loop(int sd, params_t *params) {
|
||||
void query_loop(app_t *app) {
|
||||
query_args_t *query_args = app->query_args;
|
||||
fd_set readfds;
|
||||
|
||||
int32_t sd = app->params->sd;
|
||||
size_t qlen;
|
||||
int sr;
|
||||
char buf[INBUFSIZE];
|
||||
static file_args_t file_args;
|
||||
static query_args_t query_args;
|
||||
callback_args_t d_args = {
|
||||
.app = app, .win = NULL, .widget = NULL, .data = NULL, .resp_data = NULL};
|
||||
|
||||
init_query_args(&query_args, sd, buf, WAIT_SERVER_INIT, 0, params);
|
||||
init_file_args(&file_args);
|
||||
query_args->sd = sd;
|
||||
|
||||
for (;;) {
|
||||
/* update screen */
|
||||
app_draw_modal(app);
|
||||
app_refresh(app);
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(STDIN_FILENO, &readfds);
|
||||
FD_SET(sd, &readfds);
|
||||
int maxfd = sd;
|
||||
if (query_args.state == STATE_UPLOAD_FILE) {
|
||||
if (query_args.file != NULL) {
|
||||
FD_SET(query_args.file->fd, &readfds);
|
||||
if (query_args.file->fd > maxfd)
|
||||
maxfd = query_args.file->fd;
|
||||
if (query_args->state == STATE_UPLOAD_FILE) {
|
||||
if (query_args->file != NULL) {
|
||||
FD_SET(query_args->file->fd, &readfds);
|
||||
if (query_args->file->fd > maxfd)
|
||||
maxfd = query_args->file->fd;
|
||||
}
|
||||
}
|
||||
sr = select(maxfd + 1, &readfds, NULL, NULL, NULL);
|
||||
@@ -57,41 +65,41 @@ void query_loop(int sd, params_t *params) {
|
||||
|
||||
if (FD_ISSET(sd, &readfds)) {
|
||||
/* process request from the server */
|
||||
qlen = read(sd, buf, INBUFSIZE);
|
||||
qlen = read(sd, query_args->buf, INBUFSIZE);
|
||||
if (qlen == 0) {
|
||||
close_session(sd);
|
||||
printf("\n*** server closed the connection. ***\n");
|
||||
exit(1);
|
||||
} else {
|
||||
query_args.buf_used = qlen;
|
||||
query_args.from_server = 1;
|
||||
if (-1 == process_query(&query_args, &file_args)) {
|
||||
query_args->buf_used = qlen;
|
||||
query_args->from_server = 1;
|
||||
if (-1 == process_query(query_args, &file_args)) {
|
||||
close_session(sd);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (query_args.file && query_args.file->fd > -1 &&
|
||||
FD_ISSET(query_args.file->fd, &readfds)) {
|
||||
if (query_args->file && query_args->file->fd > -1 &&
|
||||
FD_ISSET(query_args->file->fd, &readfds)) {
|
||||
/* process upload/download */
|
||||
query_args.buf_used = read(query_args.file->fd, buf, INBUFSIZE);
|
||||
process_query(&query_args, &file_args);
|
||||
query_args->buf_used = read(query_args->file->fd, query_args->buf, INBUFSIZE);
|
||||
process_query(query_args, &file_args);
|
||||
}
|
||||
|
||||
if (FD_ISSET(STDIN_FILENO, &readfds)) {
|
||||
/* process request from the client */
|
||||
qlen = read(STDIN_FILENO, buf, INBUFSIZE);
|
||||
if (qlen == 0) {
|
||||
/* qlen = read(STDIN_FILENO, buf, INBUFSIZE); */
|
||||
/* if (qlen == 0) {
|
||||
close_session(sd);
|
||||
exit(0);
|
||||
} else {
|
||||
query_args.buf_used = qlen;
|
||||
query_args.from_server = 0;
|
||||
if (-1 == process_query(&query_args, &file_args)) {
|
||||
close_session(sd);
|
||||
exit(1);
|
||||
}
|
||||
} else { */
|
||||
/* query_args->buf_used = qlen;
|
||||
query_args->from_server = 0; */
|
||||
// if (-1 == process_query(&query_args, &file_args)) {
|
||||
if (-1 == process_user_input(app, &d_args)) {
|
||||
close_session(sd);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,6 +163,10 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
||||
case WAIT_REGISTER:
|
||||
wait_register(query_args);
|
||||
break;
|
||||
case S_ASK_SEVER_IP:
|
||||
case S_ASK_LOGIN_TYPE:
|
||||
case S_N_D:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -218,12 +230,11 @@ static void wait_side(query_args_t *q_args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_query_args(query_args_t *q_args, int sd, char *buf,
|
||||
enum state state, int buf_used, params_t *params) {
|
||||
q_args->buf = buf;
|
||||
q_args->sd = sd;
|
||||
q_args->state = state;
|
||||
q_args->buf_used = buf_used;
|
||||
void init_query_args(query_args_t *q_args, params_t *params) {
|
||||
q_args->buf = NULL;
|
||||
q_args->sd = -1;
|
||||
q_args->state = S_N_D;
|
||||
q_args->buf_used = 0;
|
||||
q_args->params = params;
|
||||
q_args->file = NULL;
|
||||
q_args->from_server = 0;
|
||||
|
||||
+4
-1
@@ -2,9 +2,12 @@
|
||||
#define QUERY_H
|
||||
|
||||
#include "main.h"
|
||||
void query_loop(int sd, params_t *);
|
||||
#include "ui/app.h"
|
||||
|
||||
void query_loop(app_t *);
|
||||
void wait_register(query_args_t *q_args);
|
||||
int process_query(query_args_t *query_args, file_args_t *file_args);
|
||||
int query_extract_from_buf(char *buf, int *buf_used, char **output_line);
|
||||
void init_query_args(query_args_t *q_args, params_t *params);
|
||||
|
||||
#endif
|
||||
+20
-21
@@ -1,6 +1,5 @@
|
||||
#include "client.h"
|
||||
#include "main.h"
|
||||
#include "query.h"
|
||||
#include "ui.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
@@ -29,26 +28,26 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
||||
|
||||
/* LOGIN */
|
||||
if (!strncmp(line, "login>", ws_pos)) {
|
||||
if (params->uname == NULL) {
|
||||
fflush(stdout);
|
||||
answer = print_ask_list("Select login type:", login_options);
|
||||
switch (answer) {
|
||||
case 1:
|
||||
ask_uname_and_password(q_args->params);
|
||||
break;
|
||||
case 2:
|
||||
params->uname = malloc(sizeof("anonymous"));
|
||||
strcpy(params->uname, "anonymous");
|
||||
q_args->state = WAIT_CLIENT;
|
||||
break;
|
||||
case 3:
|
||||
wait_register(q_args);
|
||||
return 3;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
write(q_args->sd, params->uname, strlen(params->uname));
|
||||
// if (params->uname == NULL) {
|
||||
// fflush(stdout);
|
||||
// answer = print_ask_list("Select login type:", login_options);
|
||||
// switch (answer) {
|
||||
// case 1:
|
||||
// ask_uname_and_password(q_args->params);
|
||||
// break;
|
||||
// case 2:
|
||||
// params->uname = malloc(sizeof("anonymous"));
|
||||
// strcpy(params->uname, "anonymous");
|
||||
// q_args->state = WAIT_CLIENT;
|
||||
// break;
|
||||
// case 3:
|
||||
// wait_register(q_args);
|
||||
// return 3;
|
||||
// default:
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
// write(q_args->sd, params->uname, strlen(params->uname));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+53
-3
@@ -1,7 +1,12 @@
|
||||
#include "app.h"
|
||||
#include "modals/ask_server_addr.h"
|
||||
#include "modals/login_credentials.h"
|
||||
#include "modals/login_option.h"
|
||||
// #include "action.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void ac_file(WINDOW *win, int is_action_w);
|
||||
|
||||
@@ -30,9 +35,8 @@ app_t *init_app() {
|
||||
_app->right_win = newwin(y_max - 4, action_w_x, 2, menu_w_x + 1);
|
||||
|
||||
// dialogue
|
||||
_app->modal.dialogue.win = NULL;
|
||||
_app->modal.dialogue.is_initiated = 0;
|
||||
_app->modal.type = none;
|
||||
_app->modal.win = NULL;
|
||||
_app->modal.is_initiated = 0;
|
||||
|
||||
// print decorative bars
|
||||
print_bars(_app);
|
||||
@@ -98,6 +102,52 @@ void print_bars(app_t *app) {
|
||||
|
||||
wattroff(app->win, A_REVERSE);
|
||||
}
|
||||
void app_refresh(app_t *app) {
|
||||
draw_borders(app);
|
||||
|
||||
wnoutrefresh(app->win);
|
||||
wnoutrefresh(app->left_win);
|
||||
wnoutrefresh(app->right_win);
|
||||
if (app->modal.win != NULL) {
|
||||
if (app->modal.is_initiated != 0) {
|
||||
wnoutrefresh(app->modal.win);
|
||||
}
|
||||
}
|
||||
doupdate();
|
||||
}
|
||||
|
||||
void app_draw_modal(app_t *app) {
|
||||
if (!app->modal.is_initiated) {
|
||||
switch (app->query_args->state) {
|
||||
case S_ASK_SEVER_IP:
|
||||
init_asa_modal(app);
|
||||
break;
|
||||
case S_ASK_LOGIN_TYPE:
|
||||
init_login_option_modal(app);
|
||||
break;
|
||||
case S_ASK_LOGIN_USER:
|
||||
init_login_credentials_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_N_D:
|
||||
return;
|
||||
}
|
||||
}
|
||||
draw_dialogue(&(app->modal));
|
||||
}
|
||||
|
||||
void destroy_app(app_t *app) {
|
||||
delwin(app->win);
|
||||
|
||||
+7
-5
@@ -1,8 +1,8 @@
|
||||
#ifndef N_APP_H
|
||||
#define N_APP_H
|
||||
|
||||
#include "widget/dialogue.h"
|
||||
#include "../common.h"
|
||||
#include "widget/dialogue.h"
|
||||
#include <ncurses.h>
|
||||
|
||||
typedef enum {
|
||||
@@ -20,12 +20,12 @@ typedef struct {
|
||||
WINDOW *win;
|
||||
WINDOW *left_win;
|
||||
WINDOW *right_win;
|
||||
struct {
|
||||
dialogue_e type;
|
||||
dialogue_t dialogue;
|
||||
} modal;
|
||||
dialogue_t modal;
|
||||
params_t *params;
|
||||
coordinates_t coordinates;
|
||||
query_args_t *query_args;
|
||||
file_args_t *file_args;
|
||||
int32_t read_fd;
|
||||
} app_t;
|
||||
|
||||
app_t *init_app();
|
||||
@@ -33,5 +33,7 @@ void init_nc();
|
||||
void destroy_app(app_t *app);
|
||||
void draw_borders(app_t *app);
|
||||
void print_bars(app_t *app);
|
||||
void app_refresh(app_t *app);
|
||||
void app_draw_modal(app_t *app);
|
||||
|
||||
#endif // N_APP_H
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "../../connection.h"
|
||||
#include "../app.h"
|
||||
#include "../widget/dialogue.h"
|
||||
#include "../widget/group.h"
|
||||
#include "../widget/input.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
@@ -28,8 +29,8 @@ void asa_modal_dialogue_callback(callback_args_t *args) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
get_ip_port(app->params, in_ip->value, in_port->value);
|
||||
connect_to_server(app);
|
||||
destroy_dialogue(d);
|
||||
app->modal.type = none;
|
||||
break;
|
||||
case 1:
|
||||
destroy_app(app);
|
||||
@@ -51,9 +52,9 @@ dialogue_t *init_asa_modal(app_t *app) {
|
||||
{.type = w_button, .label = "Cancel", .is_default = 0},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal.dialogue), "Connect to server",
|
||||
init_dialogue(&(app->modal), "Connect to server",
|
||||
"There is information needed", &(app->coordinates));
|
||||
dialogue_t *d = &(app->modal.dialogue);
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = asa_modal_dialogue_callback;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef LOGIN_MODAL_H
|
||||
#define LOGIN_MODAL_H
|
||||
|
||||
#include "../widget/dialogue.h"
|
||||
#include "../app.h"
|
||||
|
||||
dialogue_t *init_login_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "../app.h"
|
||||
#include "../widget/dialogue.h"
|
||||
#include "../widget/group.h"
|
||||
#include "../widget/input.h"
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void init_login_credentials_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;
|
||||
input_t *in_ip = d->g_content->elements[0].element;
|
||||
input_t *in_port = d->g_content->elements[1].element;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
app->query_args->state = S_ASK_LOGIN_USER;
|
||||
destroy_dialogue(d);
|
||||
break;
|
||||
case 1:
|
||||
destroy_app(app);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_login_credentials_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_input, .label = "Username", .length = 10},
|
||||
{.type = w_input, .label = "Password", .length = 10},
|
||||
{.type = w_end}};
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Login", .is_default = 1},
|
||||
{.type = w_button, .label = "Cancel", .is_default = 0},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Credentials",
|
||||
"There is information needed", &(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = init_login_credentials_modal_cb;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef LOGIN_CREDENTIALS_MODAL_H
|
||||
#define LOGIN_CREDENTIALS_MODAL_H
|
||||
|
||||
#include "../app.h"
|
||||
#include "../widget/dialogue.h"
|
||||
|
||||
dialogue_t *init_login_credentials_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -1,16 +1,17 @@
|
||||
#include "../app.h"
|
||||
#include "../widget/dialogue.h"
|
||||
#include "../widget/group.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdint.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 login_modal_group_callback(callback_args_t *args) {
|
||||
void login_modal_option_cb(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
@@ -24,13 +25,14 @@ void login_modal_group_callback(callback_args_t *args) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
// exit(0);
|
||||
destroy_dialogue(d);
|
||||
app->query_args->state = S_ASK_LOGIN_USER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_login_modal(app_t *app) {
|
||||
dialogue_t *init_login_option_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t children[] = {{.type = w_button, .label = "Anonymous"},
|
||||
@@ -38,14 +40,14 @@ dialogue_t *init_login_modal(app_t *app) {
|
||||
{.type = w_button, .label = "Register"},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal.dialogue), "Login",
|
||||
init_dialogue(&(app->modal), "Login",
|
||||
"Select your login "
|
||||
"option",
|
||||
&(app->coordinates));
|
||||
app->modal.dialogue.g_content =
|
||||
init_group(&(app->modal.dialogue.win), &(app->modal.dialogue.w), children,
|
||||
app->modal.g_content =
|
||||
init_group(&(app->modal.win), &(app->modal.w), children,
|
||||
horizontal);
|
||||
app->modal.dialogue.w.callback = login_modal_group_callback;
|
||||
app->modal.w.callback = login_modal_option_cb;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef LOGIN_OPTION_MODAL_H
|
||||
#define LOGIN_OPTION_MODAL_H
|
||||
|
||||
#include "../widget/dialogue.h"
|
||||
#include "../app.h"
|
||||
|
||||
dialogue_t *init_login_option_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -75,13 +75,17 @@ void dialogue_default_callback(callback_args_t *args) {
|
||||
if (d->active.type == g_action) {
|
||||
new_args.widget = new_args.widget = d->g_action;
|
||||
group_default_callback(&new_args);
|
||||
} else {
|
||||
} else if (d->g_action != NULL) {
|
||||
for (int i = 0; i < d->g_action->count; i++) {
|
||||
if (d->g_action->elements[i].is_default) {
|
||||
*resp_value = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* TODO: temp solution, improve */
|
||||
*resp_value = d->active.id - d->g_content->first_id;
|
||||
return;
|
||||
}
|
||||
draw_dialogue(d);
|
||||
break;
|
||||
@@ -222,8 +226,10 @@ int32_t draw_dialogue(dialogue_t *d) {
|
||||
}
|
||||
|
||||
/* move cursor */
|
||||
FIND_ACTIVE_ELEMENT(d->g_content, d->active.id, ae_ptr, ae_idx);
|
||||
if (ae_ptr == NULL)
|
||||
if (d->g_content != NULL) {
|
||||
FIND_ACTIVE_ELEMENT(d->g_content, d->active.id, ae_ptr, ae_idx);
|
||||
}
|
||||
if (ae_ptr == NULL && d->g_action != NULL)
|
||||
FIND_ACTIVE_ELEMENT(d->g_action, d->active.id, ae_ptr, ae_idx);
|
||||
|
||||
if (ae_ptr != NULL && ae_ptr->id == d->active.id) {
|
||||
|
||||
Reference in New Issue
Block a user