ui: brings back text centering in modals | fixes error on exit | small clean-up
This commit is contained in:
+1
-2
@@ -20,8 +20,7 @@ void connect_to_server(app_t *app) {
|
|||||||
if (-1 ==
|
if (-1 ==
|
||||||
connect(app->params->sd, (struct sockaddr *)&server, sizeof(server))) {
|
connect(app->params->sd, (struct sockaddr *)&server, sizeof(server))) {
|
||||||
perror("connect");
|
perror("connect");
|
||||||
destroy_app(app);
|
destroy_app(app, 2);
|
||||||
exit(2);
|
|
||||||
}
|
}
|
||||||
app->params->is_connected = TRUE;
|
app->params->is_connected = TRUE;
|
||||||
print_bars(app);
|
print_bars(app);
|
||||||
|
|||||||
+1
-2
@@ -25,5 +25,4 @@ query.o: src/query.c src/client.h src/main.h src/types.h src/connection.h \
|
|||||||
src/ui/widget/../../common.h src/ui/widget/button.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/ui/widget/../../main.h src/ui/widget/group.h src/file_processor.h \
|
||||||
src/ui/widget/file_list.h src/server.h
|
src/ui/widget/file_list.h src/server.h
|
||||||
server.o: src/server.c src/main.h src/types.h src/ui.h
|
server.o: src/server.c src/main.h src/types.h
|
||||||
ui.o: src/ui.c
|
|
||||||
|
|||||||
+7
-3
@@ -57,7 +57,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
query_loop(app);
|
query_loop(app);
|
||||||
clear_params(¶ms);
|
clear_params(¶ms);
|
||||||
destroy_app(app);
|
destroy_app(app, 0);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,12 @@ int32_t process_user_input(app_t *app, callback_args_t *d_args) {
|
|||||||
c = wgetch(app->win);
|
c = wgetch(app->win);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case KEY_F(9):
|
case KEY_F(9):
|
||||||
destroy_app(app);
|
destroy_app(app, 0);
|
||||||
return ERR;
|
return OK;
|
||||||
|
case 'U':
|
||||||
|
case 'u':
|
||||||
|
app->query_args->state = S_UPLOAD_FILE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
d_args->data = (void *)&c;
|
d_args->data = (void *)&c;
|
||||||
app->active_callback(d_args);
|
app->active_callback(d_args);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ enum state {
|
|||||||
WAIT_REGISTER,
|
WAIT_REGISTER,
|
||||||
WAIT_REGISTER_CONFIRMATION,
|
WAIT_REGISTER_CONFIRMATION,
|
||||||
WAIT_CLIENT,
|
WAIT_CLIENT,
|
||||||
UPLOAD_FILE,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct p_file {
|
typedef struct p_file {
|
||||||
|
|||||||
@@ -144,7 +144,6 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
|||||||
case WAIT_REGISTER_CONFIRMATION:
|
case WAIT_REGISTER_CONFIRMATION:
|
||||||
wait_side(query_args);
|
wait_side(query_args);
|
||||||
break;
|
break;
|
||||||
case UPLOAD_FILE:
|
|
||||||
case S_ERR:
|
case S_ERR:
|
||||||
break;
|
break;
|
||||||
case S_FILE_LIST:
|
case S_FILE_LIST:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "ui.h"
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
uint32_t print_ask_list(char title[], const char *options[]) {
|
|
||||||
char c;
|
|
||||||
uint32_t i, answer;
|
|
||||||
|
|
||||||
printf("%s\n", title);
|
|
||||||
|
|
||||||
for (i = 0; options[i] != NULL; i++) {
|
|
||||||
printf("[%u] %s\n", i + 1, options[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
write(STDOUT_FILENO, "> ", sizeof "> ");
|
|
||||||
|
|
||||||
while (!scanf("%u", &answer) || answer > i) {
|
|
||||||
printf("Input format is not correct! You need to specify between 1 and "
|
|
||||||
"%u\n > ",
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
while ((c = getchar()) != '\n' && c != EOF);
|
|
||||||
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
uint32_t print_ask_list(char *title, const char *options[]);
|
|
||||||
+9
-10
@@ -5,6 +5,7 @@
|
|||||||
#include "modals/login_option.h"
|
#include "modals/login_option.h"
|
||||||
#include "modals/notification.h"
|
#include "modals/notification.h"
|
||||||
#include "modals/server_message.h"
|
#include "modals/server_message.h"
|
||||||
|
#include "modals/upload_dialogue.h"
|
||||||
#include "widget/dialogue.h"
|
#include "widget/dialogue.h"
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -90,12 +91,6 @@ void draw_borders(app_t *app) {
|
|||||||
box(app->win, 0, 0);
|
box(app->win, 0, 0);
|
||||||
box(app->left_win, 0, 0);
|
box(app->left_win, 0, 0);
|
||||||
box(app->right_win, 0, 0);
|
box(app->right_win, 0, 0);
|
||||||
|
|
||||||
/* refresh the windows */
|
|
||||||
wnoutrefresh(app->win);
|
|
||||||
wnoutrefresh(app->left_win);
|
|
||||||
wnoutrefresh(app->right_win);
|
|
||||||
doupdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_bars(app_t *app) {
|
void print_bars(app_t *app) {
|
||||||
@@ -120,7 +115,8 @@ void print_bars(app_t *app) {
|
|||||||
mvwprintw(app->win, 1, 2, "%s", top_text);
|
mvwprintw(app->win, 1, 2, "%s", top_text);
|
||||||
|
|
||||||
/* add content to the bottom bar */
|
/* add content to the bottom bar */
|
||||||
mvwprintw(app->win, app->coordinates.cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
mvwprintw(app->win, app->coordinates.cur_y - 2, 2,
|
||||||
|
"F1 - Help | U - upload | F9 - Quit");
|
||||||
|
|
||||||
wattroff(app->win, A_REVERSE);
|
wattroff(app->win, A_REVERSE);
|
||||||
}
|
}
|
||||||
@@ -161,16 +157,17 @@ void app_draw_modal(app_t *app) {
|
|||||||
case S_FILE_DOWNLOAD:
|
case S_FILE_DOWNLOAD:
|
||||||
init_dwn_pr_modal(app);
|
init_dwn_pr_modal(app);
|
||||||
break;
|
break;
|
||||||
|
case S_UPLOAD_FILE:
|
||||||
|
init_upload_dialogue_modal(app);
|
||||||
|
break;
|
||||||
case WAIT_SERVER_INIT:
|
case WAIT_SERVER_INIT:
|
||||||
case WAIT_SERVER:
|
case WAIT_SERVER:
|
||||||
case WAIT_REGISTER:
|
case WAIT_REGISTER:
|
||||||
case WAIT_REGISTER_CONFIRMATION:
|
case WAIT_REGISTER_CONFIRMATION:
|
||||||
case WAIT_CLIENT:
|
case WAIT_CLIENT:
|
||||||
case UPLOAD_FILE:
|
|
||||||
case S_FILE_LIST:
|
case S_FILE_LIST:
|
||||||
case S_FILE_SELECT:
|
case S_FILE_SELECT:
|
||||||
case S_UPLOAD_PARAMS:
|
case S_UPLOAD_PARAMS:
|
||||||
case S_UPLOAD_FILE:
|
|
||||||
case S_UPLOAD_REQUESTED:
|
case S_UPLOAD_REQUESTED:
|
||||||
case S_ASK_USER_BEFORE_LOGIN:
|
case S_ASK_USER_BEFORE_LOGIN:
|
||||||
case S_ERR:
|
case S_ERR:
|
||||||
@@ -191,7 +188,9 @@ void app_draw_modal(app_t *app) {
|
|||||||
draw_dialogue(&(app->modal));
|
draw_dialogue(&(app->modal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_app(app_t *app) {
|
void destroy_app(app_t *app, int32_t exit_code) {
|
||||||
delwin(app->win);
|
delwin(app->win);
|
||||||
endwin();
|
endwin();
|
||||||
|
app->win = NULL;
|
||||||
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ typedef struct {
|
|||||||
|
|
||||||
app_t *init_app();
|
app_t *init_app();
|
||||||
void init_nc();
|
void init_nc();
|
||||||
void destroy_app(app_t *app);
|
void destroy_app(app_t *app, int32_t exit_code);
|
||||||
void draw_borders(app_t *app);
|
void draw_borders(app_t *app);
|
||||||
void print_bars(app_t *app);
|
void print_bars(app_t *app);
|
||||||
void app_refresh(app_t *app);
|
void app_refresh(app_t *app);
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ void asa_modal_dialogue_callback(callback_args_t *args) {
|
|||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
destroy_app(app);
|
destroy_app(app, 0);
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void init_dwn_pr_modal_cb(callback_args_t *args) {
|
void dwn_pr_modal_cb(callback_args_t *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogue_t *init_dwn_pr_modal(app_t *app) {
|
dialogue_t *init_dwn_pr_modal(app_t *app) {
|
||||||
@@ -23,7 +23,7 @@ dialogue_t *init_dwn_pr_modal(app_t *app) {
|
|||||||
init_dialogue(&(app->modal), "Download", text, &(app->coordinates));
|
init_dialogue(&(app->modal), "Download", text, &(app->coordinates));
|
||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = init_dwn_pr_modal_cb;
|
d->w.callback = dwn_pr_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
|
|||||||
print_bars(app);
|
print_bars(app);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
destroy_app(app);
|
destroy_app(app, 0);
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#include "../app.h"
|
||||||
|
#include "../widget/dialogue.h"
|
||||||
|
#include "../widget/group.h"
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void upload_dialogue_modal_cb(callback_args_t *args) {
|
||||||
|
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.widget = app->active_widget;
|
||||||
|
dialogue_default_callback(&d_args);
|
||||||
|
if (response > -1) {
|
||||||
|
switch (response) {
|
||||||
|
case 0:
|
||||||
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogue_t *init_upload_dialogue_modal(app_t *app) {
|
||||||
|
if (app == NULL)
|
||||||
|
return NULL;
|
||||||
|
group_el_init_t content[] = {{.type = w_input,
|
||||||
|
.label = "File description",
|
||||||
|
.length = 30}, /* length is ignored */
|
||||||
|
{.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_end}};
|
||||||
|
|
||||||
|
app->modal.w.parent_win = &app->win;
|
||||||
|
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
|
||||||
|
&(app->coordinates));
|
||||||
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
|
d->w.callback = upload_dialogue_modal_cb;
|
||||||
|
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||||
|
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||||
|
|
||||||
|
app->query_args->progress_bar = d->g_content->elements[0].element;
|
||||||
|
app->query_args->active_dialogue = d;
|
||||||
|
|
||||||
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef UPLOAD_DIALOGUE_H
|
||||||
|
#define UPLOAD_DIALOGUE_H
|
||||||
|
|
||||||
|
#include "../widget/dialogue.h"
|
||||||
|
#include "../app.h"
|
||||||
|
|
||||||
|
dialogue_t *init_upload_dialogue_modal(app_t *app);
|
||||||
|
|
||||||
|
#endif
|
||||||
+2
-2
@@ -58,14 +58,14 @@ int32_t get_max_line_len(const char *text, uint32_t *line_count) {
|
|||||||
mvwprintw(win, line_v_pos, x, "%s", l_buf); \
|
mvwprintw(win, line_v_pos, x, "%s", l_buf); \
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t print_multiline_text(WINDOW *win, const char *_text, const uint32_t y,
|
uint32_t print_multiline_text(WINDOW *win, const char *_text,
|
||||||
|
const uint32_t win_width, const uint32_t y,
|
||||||
const uint32_t x, const uint16_t attrs) {
|
const uint32_t x, const uint16_t attrs) {
|
||||||
|
|
||||||
uint16_t line_v_pos = y;
|
uint16_t line_v_pos = y;
|
||||||
int32_t c_line_len = 0;
|
int32_t c_line_len = 0;
|
||||||
uint32_t m_line_len = 0;
|
uint32_t m_line_len = 0;
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
uint32_t win_width = getmaxx(win) - 2; /* -2: borders */
|
|
||||||
char l_buf[DIALOGUE_TEXT];
|
char l_buf[DIALOGUE_TEXT];
|
||||||
char *text = malloc(strlen(_text) + 1);
|
char *text = malloc(strlen(_text) + 1);
|
||||||
strcpy(text, _text);
|
strcpy(text, _text);
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ enum pmt_attrs {
|
|||||||
|
|
||||||
void init_widget(widget_t *w, widget_t *w_parent, WINDOW **win, char *title);
|
void init_widget(widget_t *w, widget_t *w_parent, WINDOW **win, char *title);
|
||||||
int32_t get_max_line_len(const char *text, uint32_t *line_count);
|
int32_t get_max_line_len(const char *text, uint32_t *line_count);
|
||||||
uint32_t print_multiline_text(WINDOW *win, const char *text, const uint32_t y,
|
uint32_t print_multiline_text(WINDOW *win, const char *text, const uint32_t win_width, const uint32_t y,
|
||||||
const uint32_t x, const uint16_t attrs);
|
const uint32_t x, const uint16_t attrs);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -239,7 +239,7 @@ int32_t draw_dialogue(dialogue_t *d) {
|
|||||||
/* text */
|
/* text */
|
||||||
wattroff(d->win, A_BOLD);
|
wattroff(d->win, A_BOLD);
|
||||||
/* mvwhline(d->win, d->w.y - 3, 1, 0, d->w.x - 2); */
|
/* mvwhline(d->win, d->w.y - 3, 1, 0, d->w.x - 2); */
|
||||||
print_multiline_text(d->win, d->text, 2, 1, PMT_ALIGN_CENTER);
|
print_multiline_text(d->win, d->text, d->w.x, 2, 1, PMT_ALIGN_CENTER);
|
||||||
wattroff(d->win, A_REVERSE);
|
wattroff(d->win, A_REVERSE);
|
||||||
|
|
||||||
if (d->g_content != NULL) {
|
if (d->g_content != NULL) {
|
||||||
|
|||||||
@@ -144,5 +144,5 @@ void draw_file_list(ui_file_list_t *fl_ui) {
|
|||||||
mvwprintw(i_win, p_y++, p_x, "Size: %zu", active_el->size);
|
mvwprintw(i_win, p_y++, p_x, "Size: %zu", active_el->size);
|
||||||
mvwprintw(i_win, p_y++, p_x, "Owner: %s", active_el->owner);
|
mvwprintw(i_win, p_y++, p_x, "Owner: %s", active_el->owner);
|
||||||
mvwprintw(i_win, p_y++, p_x, "Description: ");
|
mvwprintw(i_win, p_y++, p_x, "Description: ");
|
||||||
print_multiline_text(i_win, active_el->description, p_y, p_x, 0);
|
print_multiline_text(i_win, active_el->description, sz_x, p_y, p_x, 0);
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#define FILE_LIST_H
|
#define FILE_LIST_H
|
||||||
#include "../widget.h"
|
#include "../widget.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
widget_t w;
|
widget_t w;
|
||||||
fl_item_t **current;
|
fl_item_t **current;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
|||||||
w = &(((ui_progress_bar_t *)elements[i].element)->w);
|
w = &(((ui_progress_bar_t *)elements[i].element)->w);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// set dimensions
|
/* set dimensions */
|
||||||
elements[i].id = w->id;
|
elements[i].id = w->id;
|
||||||
if (direction == horizontal) {
|
if (direction == horizontal) {
|
||||||
w->m_x = group->w.m_x + 1 + group->w.x;
|
w->m_x = group->w.m_x + 1 + group->w.x;
|
||||||
|
|||||||
Reference in New Issue
Block a user