ui: alert; anonymous login; registration (not finished)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
## Features:
|
||||
- [x] Search files
|
||||
- [x] Correct spacing in the search bar
|
||||
- [ ] Finish registration
|
||||
- [ ] Privilege settings for files
|
||||
- [ ] Files removal
|
||||
- [ ] Encryption
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "modals/server_message.h"
|
||||
#include "modals/upload_dialogue.h"
|
||||
#include "modals/upload_props_dialogue.h"
|
||||
#include "modals/register.h"
|
||||
#include "widget/dialogue.h"
|
||||
#include "main.h"
|
||||
|
||||
@@ -37,6 +38,9 @@ void app_draw_modal(app_t *app) {
|
||||
case S_UPLOAD_FILE_SELECT:
|
||||
init_upload_dialogue_modal(app);
|
||||
break;
|
||||
case S_ASK_REGISTER:
|
||||
init_register_modal(app);
|
||||
break;
|
||||
case S_UPLOAD_PARAMS:
|
||||
init_upload_props_dialogue_modal(app);
|
||||
break;
|
||||
|
||||
@@ -24,10 +24,12 @@ typedef struct params {
|
||||
} params_t;
|
||||
|
||||
enum state {
|
||||
/* TUI-based */
|
||||
S_N_D,
|
||||
S_ASK_SEVER_IP,
|
||||
S_ASK_LOGIN_TYPE,
|
||||
S_ASK_LOGIN_USER,
|
||||
S_ASK_REGISTER,
|
||||
S_WAIT_SERVER,
|
||||
S_PRINT_SERVER_MESSAGE,
|
||||
S_FILE_LIST,
|
||||
@@ -40,6 +42,8 @@ enum state {
|
||||
S_ASK_USER_BEFORE_LOGIN,
|
||||
S_ERR,
|
||||
S_NEXT_ACTION,
|
||||
S_WAIT_REGISTER_CONFIRMATION,
|
||||
/* Legacy */
|
||||
WAIT_SERVER_INIT,
|
||||
WAIT_SERVER,
|
||||
WAIT_REGISTER,
|
||||
@@ -76,6 +80,7 @@ typedef struct query_args {
|
||||
int32_t buf_used;
|
||||
p_file_t *file;
|
||||
enum state state;
|
||||
enum state next_state;
|
||||
char *buf;
|
||||
uint32_t from_server : 1;
|
||||
params_t *params;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "app.h"
|
||||
#include "dialogue.h"
|
||||
#include "widget_core.h"
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void init_alert_cb(callback_args_t *args) {
|
||||
//
|
||||
}
|
||||
|
||||
void alert(app_t *app, const char *message) {
|
||||
if (app == NULL)
|
||||
return;
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "OK", .is_default = 1}, {.type = w_end}};
|
||||
|
||||
dialogue_t *d = malloc(sizeof(dialogue_t));
|
||||
|
||||
init_dialogue(d, "Alert", message, &(app->coordinates));
|
||||
|
||||
d->w.callback = init_alert_cb;
|
||||
d->g_content = NULL;
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
d->color_scheme = dc_alert;
|
||||
|
||||
draw_dialogue(d);
|
||||
wrefresh(d->win);
|
||||
int c = 0;
|
||||
|
||||
while ((c = wgetch(d->win))) {
|
||||
if (c == '\n') break;
|
||||
}
|
||||
|
||||
destroy_group(d->g_action);
|
||||
delwin(d->win);
|
||||
free(d);
|
||||
app_refresh(app);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifndef ALERT_H
|
||||
#define ALERT_H
|
||||
#include "app.h"
|
||||
void alert(app_t *app, const char *message);
|
||||
#endif
|
||||
@@ -59,7 +59,7 @@ dialogue_t *init_login_credentials_modal(app_t *app) {
|
||||
{.type = w_button, .label = "Cancel", .is_default = false},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Credentials", "There is information needed",
|
||||
init_dialogue(&(app->modal), "Login", "Your login credentials",
|
||||
&(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <widget.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -22,11 +24,21 @@ void login_modal_option_cb(callback_args_t *args) {
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
d->needs_destroy = true;
|
||||
app->params->uname = malloc(sizeof "anonymous");
|
||||
strcpy(app->params->uname, "anonymous");
|
||||
write(app->params->sd, app->params->uname, sizeof "anonymous"-1);
|
||||
app->query_args->state = S_WAIT_SERVER;
|
||||
print_bars(app);
|
||||
break;
|
||||
case 1:
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_ASK_LOGIN_USER;
|
||||
break;
|
||||
case 2:
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_ASK_REGISTER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
#include "alert.h"
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void init_register_modal_cb(callback_args_t *args) {
|
||||
char query[256];
|
||||
int32_t qlen = 0;
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
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;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
if (strcmp(in_pass->value, in_pass_r->value)) {
|
||||
alert(app, "Your passwords do not match");
|
||||
in_pass->value[0] = '\0';
|
||||
in_pass->value_len = 0;
|
||||
in_pass_r->value[0] = '\0';
|
||||
in_pass_r->value_len = 0;
|
||||
return;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
write(app->params->sd, query, qlen);
|
||||
app->query_args->state = S_WAIT_REGISTER_CONFIRMATION;
|
||||
/* d->needs_destroy = true;
|
||||
print_bars(app); */
|
||||
break;
|
||||
case 1:
|
||||
destroy_app(app, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_register_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_input, .label = "Username", .length = 15},
|
||||
{.type = w_input,
|
||||
.label = "Password",
|
||||
.length = 15,
|
||||
.is_hidden_value = true},
|
||||
{.type = w_input,
|
||||
.label = "Password (repeat)",
|
||||
.length = 15,
|
||||
.is_hidden_value = true},
|
||||
{.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_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Credentials", "There is information needed",
|
||||
&(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = init_register_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,8 @@
|
||||
#ifndef REGISTER_MODAL_H
|
||||
#define REGISTER_MODAL_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_register_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -143,6 +143,7 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
||||
case S_NEXT_ACTION:
|
||||
case S_WAIT_SERVER:
|
||||
case WAIT_REGISTER_CONFIRMATION:
|
||||
case S_WAIT_REGISTER_CONFIRMATION:
|
||||
wait_side(query_args);
|
||||
break;
|
||||
case S_ERR:
|
||||
|
||||
+3
-3
@@ -1,5 +1,6 @@
|
||||
#include "main.h"
|
||||
#include "widget/file_list.h"
|
||||
#include "modals/alert.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -69,7 +70,7 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
||||
}
|
||||
|
||||
/* REGISTER CONFIRMATION */
|
||||
if (q_args->state == WAIT_REGISTER_CONFIRMATION) {
|
||||
if (q_args->state == S_WAIT_REGISTER_CONFIRMATION) {
|
||||
if (!strcmp(line, "ok")) {
|
||||
sprintf(query, "file list %u %u\n%n", fui->max_lines, fui->current_page,
|
||||
&q_len);
|
||||
@@ -77,8 +78,7 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
||||
q_args->state = S_FILE_LIST;
|
||||
return 0;
|
||||
} else {
|
||||
write(STDOUT_FILENO, line, strlen(line));
|
||||
q_args->state = WAIT_REGISTER;
|
||||
PRINT_SRV_MESSAGE(q_args, l_len, line)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ void init_nc() {
|
||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(modal_color_pair, COLOR_BLUE, COLOR_WHITE);
|
||||
init_pair(4, COLOR_CYAN, COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ typedef struct {
|
||||
coordinates_t coordinates;
|
||||
query_args_t *query_args;
|
||||
file_args_t *file_args;
|
||||
int32_t read_fd;
|
||||
active_win_t active_win_type;
|
||||
void (*active_callback)(callback_args_t *args);
|
||||
WINDOW *active_win;
|
||||
|
||||
@@ -173,6 +173,7 @@ void init_dialogue(dialogue_t *dialogue, const char title[], const char text[],
|
||||
dialogue->is_initiated = true;
|
||||
dialogue->needs_update = true;
|
||||
dialogue->needs_destroy = false;
|
||||
dialogue->color_scheme = dc_normal;
|
||||
strcpy(dialogue->w.title, title);
|
||||
strcpy(dialogue->text, text);
|
||||
}
|
||||
@@ -284,7 +285,14 @@ int32_t draw_dialogue(dialogue_t *d) {
|
||||
d->win = newwin(y, x, d->w.m_y, d->w.m_x);
|
||||
}
|
||||
|
||||
wattrset(d->win, COLOR_PAIR(0) | A_BOLD | A_REVERSE);
|
||||
switch (d->color_scheme) {
|
||||
case dc_normal:
|
||||
wattrset(d->win, COLOR_PAIR(0) | A_BOLD | A_REVERSE);
|
||||
break;
|
||||
case dc_alert:
|
||||
wattrset(d->win, COLOR_PAIR(4) | A_BOLD | A_REVERSE);
|
||||
break;
|
||||
}
|
||||
|
||||
/* background */
|
||||
for (int yp = 1; yp < d->w.y - 1; yp++) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <widget_core.h>
|
||||
|
||||
enum g_type { g_content, g_action };
|
||||
enum d_color_scheme { dc_normal, dc_alert };
|
||||
|
||||
typedef struct {
|
||||
widget_t w;
|
||||
@@ -21,8 +22,9 @@ typedef struct {
|
||||
char text[DIALOGUE_TEXT];
|
||||
uint32_t is_initiated : 1;
|
||||
uint32_t needs_update : 1;
|
||||
uint32_t needs_destroy: 1;
|
||||
uint32_t needs_destroy : 1;
|
||||
coordinates_t *p_coordinates;
|
||||
enum d_color_scheme color_scheme;
|
||||
} dialogue_t;
|
||||
|
||||
void init_dialogue(dialogue_t *d, const char title[], const char text[],
|
||||
|
||||
Reference in New Issue
Block a user