UI: separate windows objects
This commit is contained in:
@@ -20,6 +20,7 @@ add_subdirectory(src/widget)
|
||||
add_subdirectory(src/modals)
|
||||
add_subdirectory(src/lib)
|
||||
add_subdirectory(src/utils)
|
||||
add_subdirectory(src/windows)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ target_link_libraries(zbbs-client-tui
|
||||
widget
|
||||
modals
|
||||
bstring
|
||||
windows
|
||||
utils
|
||||
${CURSES_LIBRARIES}
|
||||
)
|
||||
+2
-2
@@ -15,8 +15,8 @@ typedef struct {
|
||||
app->main_ui.ui = NULL; \
|
||||
app->main_ui.cb_refresh = NULL; \
|
||||
app->main_ui.cb_b_press = NULL; \
|
||||
app->main_ui.b_keys = NULL;
|
||||
|
||||
app->main_ui.b_keys = NULL; \
|
||||
app->main_ui.b_keys_len = 0;
|
||||
|
||||
struct action_key {
|
||||
char *const key;
|
||||
|
||||
@@ -30,9 +30,6 @@ void w_app_draw_modal(w_app_t *app) {
|
||||
case S_UPLOAD_FILE:
|
||||
m_load_pr_init(app, true);
|
||||
break;
|
||||
case S_UPLOAD_FILE_SELECT:
|
||||
m_upload_dialogue_init(app);
|
||||
break;
|
||||
case S_ASK_REGISTER:
|
||||
m_register_init(app);
|
||||
break;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <widget.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "file_processor.h"
|
||||
#include "main.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#ifndef FILE_PROCESSOR_H
|
||||
#define FILE_PROCESSOR_H
|
||||
#include "main.h"
|
||||
#include "widget/file_list.h"
|
||||
|
||||
void file_list(file_args_t *f_args, query_args_t *q_args);
|
||||
void file_download(file_args_t *f_args, query_args_t *q_args);
|
||||
|
||||
+2
-3
@@ -13,13 +13,12 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <widget.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "app.h"
|
||||
#include "connection.h"
|
||||
#include "file_list.h"
|
||||
#include "main_window.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "query.h"
|
||||
|
||||
uint32_t m_id = 0;
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ enum state {
|
||||
S_FILE_DOWNLOAD,
|
||||
S_UPLOAD_PARAMS,
|
||||
S_UPLOAD_FILE,
|
||||
S_UPLOAD_FILE_SELECT,
|
||||
/* S_UPLOAD_FILE_SELECT, */
|
||||
S_UPLOAD_REQUESTED,
|
||||
S_UPLOAD_SERVER_FINISHES,
|
||||
S_ASK_USER_BEFORE_LOGIN,
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@
|
||||
#include "notification.h"
|
||||
#include "register.h"
|
||||
#include "server_message.h"
|
||||
#include "upload_dialogue.h"
|
||||
// #include "upload_dialogue.h"
|
||||
#include "upload_props_dialogue.h"
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "../file_processor.h"
|
||||
/* #include "../file_processor.h"
|
||||
#include "group.h"
|
||||
#include "widget_core.h"
|
||||
#include <ncursesw/ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -13,8 +14,7 @@ void upload_dialogue_modal_cb(w_cb_args_t *args) {
|
||||
d_args.app = NULL;
|
||||
d_args.element = app->active_widget;
|
||||
w_dialogue_callback_default(&d_args);
|
||||
w_lfl_ui_t *fui =
|
||||
(w_lfl_ui_t *)d->g_content->elements[0].element;
|
||||
w_lfl_ui_t *fui = (w_lfl_ui_t *)d->g_content->elements[0].element;
|
||||
if (d_args.resp_data.code == cbrp_val) {
|
||||
switch (d_args.resp_data.val.val.num) {
|
||||
case 0:
|
||||
@@ -38,11 +38,12 @@ w_dialogue_t *m_upload_dialogue_init(w_app_t *app) {
|
||||
return NULL;
|
||||
w_group_el_init_t content[] = {
|
||||
// {.type = w_input, .label = "File description", .length = 30},
|
||||
{.type = w_fs_file_list, .label = "File", .length = 30},
|
||||
{.type = w_box, .label = "File", .length = 30},
|
||||
{.type = w_end}};
|
||||
|
||||
w_group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 0}, {.type = w_end}};
|
||||
{.type = w_button, .label = "Cancel", .is_default = false, .val.num = 0},
|
||||
{.type = w_end}};
|
||||
|
||||
app->modal.w.parent_win = &app->win;
|
||||
w_dialogue_init(&(app->modal), "Upload new file", "Enter essential data",
|
||||
@@ -60,4 +61,4 @@ w_dialogue_t *m_upload_dialogue_init(w_app_t *app) {
|
||||
w_dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
} */
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <modals.h>
|
||||
#include <widget.h>
|
||||
#include <widget_core.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "alert.h"
|
||||
#include "connection.h"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <widget.h>
|
||||
#include <windows.h>
|
||||
|
||||
void ask_uname_and_password(params_t *params);
|
||||
void ask_register(params_t *params, char *email);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "app.h"
|
||||
#include "file_list.h"
|
||||
#include <locale.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
+7
-14
@@ -9,8 +9,6 @@
|
||||
#include <widget.h>
|
||||
#include <widget_core.h>
|
||||
|
||||
#include "file_list.h"
|
||||
|
||||
void incr_active_id(w_dialogue_t *d) {
|
||||
w_g_el_t *active_el = NULL;
|
||||
while (true) {
|
||||
@@ -114,20 +112,14 @@ void w_dialogue_callback_default(w_cb_args_t *args) {
|
||||
}
|
||||
break;
|
||||
case KEY_UP:
|
||||
if (d->active_el->type == w_fs_file_list) {
|
||||
new_args.element = d->g_content;
|
||||
w_group_cb_default(&new_args);
|
||||
} else if (d->active_el->g_type == g_content &&
|
||||
if (d->active_el->g_type == g_content &&
|
||||
d->g_content->direction == vertical) {
|
||||
decr_active_id(d);
|
||||
args->resp_data.code = cbrc_none;
|
||||
}
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if (d->active_el->type == w_fs_file_list) {
|
||||
new_args.element = d->g_content;
|
||||
w_group_cb_default(&new_args);
|
||||
} else if (d->active_el->g_type == g_content &&
|
||||
if (d->active_el->g_type == g_content &&
|
||||
d->g_content->direction == vertical) {
|
||||
incr_active_id(d);
|
||||
args->resp_data.code = cbrc_none;
|
||||
@@ -144,8 +136,8 @@ void w_dialogue_callback_default(w_cb_args_t *args) {
|
||||
}
|
||||
}
|
||||
|
||||
void w_dialogue_init(w_dialogue_t *dialogue, const char title[], const char text[],
|
||||
coordinates_t *p_coordinates) {
|
||||
void w_dialogue_init(w_dialogue_t *dialogue, const char title[],
|
||||
const char text[], coordinates_t *p_coordinates) {
|
||||
uint32_t t_size = 0;
|
||||
dialogue->win = 0;
|
||||
dialogue->g_content = NULL;
|
||||
@@ -168,7 +160,8 @@ void w_dialogue_init(w_dialogue_t *dialogue, const char title[], const char text
|
||||
|
||||
/* variadic */
|
||||
void w_dialogue_vinit(w_dialogue_t *dialogue, const char title[],
|
||||
coordinates_t *p_coordinates, const char fmt[], va_list *v_args) {
|
||||
coordinates_t *p_coordinates, const char fmt[],
|
||||
va_list *v_args) {
|
||||
char f_text[DIALOGUE_TEXT];
|
||||
vsprintf(f_text, fmt, *v_args);
|
||||
w_dialogue_init(dialogue, title, f_text, p_coordinates);
|
||||
@@ -179,7 +172,7 @@ int group_init_active_id(w_group_t *g, w_dialogue_t *d) {
|
||||
|
||||
for (int i = 0; i < g->count; i++) {
|
||||
wt = g->elements[i].type;
|
||||
if (wt == w_button || wt == w_input || wt == w_fs_file_list ||
|
||||
if (wt == w_button || wt == w_input ||
|
||||
wt == w_checkbox) { /* Add here new types */
|
||||
d->active_el = g->elements + i;
|
||||
return 1;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "button.h"
|
||||
#include "checkbox.h"
|
||||
#include "d_array.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "input.h"
|
||||
#include "progress_bar.h"
|
||||
#include "widget_core.h"
|
||||
@@ -126,10 +125,6 @@ w_group_t *w_group_init(WINDOW **win, w_t *w_parent, w_group_el_init_t *children
|
||||
elements[i].element = w_pgb_ui_init(win, &(group->w));
|
||||
w = &(((w_pgb_ui_t *)elements[i].element)->w);
|
||||
break;
|
||||
case w_fs_file_list:
|
||||
elements[i].element = w_lfl_init(win, &(group->w));
|
||||
w = &(((w_pgb_ui_t *)elements[i].element)->w);
|
||||
break;
|
||||
case w_checkbox:
|
||||
elements[i].element = w_checkbox_init(win, &(group->w), children[i].label);
|
||||
w = &(((w_checkbox_t *)elements[i].element)->w);
|
||||
@@ -188,9 +183,6 @@ void w_group_draw(WINDOW *win, w_group_t *group, int32_t active_id) {
|
||||
case w_progress:
|
||||
w_pgb_ui_draw((w_pgb_ui_t *)el->element);
|
||||
break;
|
||||
case w_fs_file_list:
|
||||
w_lfl_draw((w_lfl_ui_t *)el->element);
|
||||
break;
|
||||
case w_checkbox:
|
||||
w_checkbox_draw((w_checkbox_t *)el->element, active_id);
|
||||
break;
|
||||
@@ -218,9 +210,6 @@ void w_group_destroy(w_group_t *group) {
|
||||
case w_progress:
|
||||
w_pgb_ui_destroy(el->element);
|
||||
break;
|
||||
case w_fs_file_list:
|
||||
w_lfl_destroy(el->element);
|
||||
break;
|
||||
case w_checkbox:
|
||||
w_checkbox_destroy(el->element);
|
||||
break;
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "app.h"
|
||||
#include "button.h"
|
||||
#include "dialogue.h"
|
||||
#include "file_list.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "group.h"
|
||||
#include "input.h"
|
||||
#include "progress_bar.h"
|
||||
|
||||
@@ -23,7 +23,6 @@ enum w_type {
|
||||
w_input,
|
||||
w_checkbox,
|
||||
w_progress,
|
||||
w_fs_file_list,
|
||||
};
|
||||
|
||||
enum w_val_type {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
add_library(windows STATIC)
|
||||
|
||||
file(GLOB M_SOURCES "*.c")
|
||||
|
||||
target_link_directories(windows
|
||||
PRIVATE
|
||||
"../widget/"
|
||||
"../widget_core/"
|
||||
"../lib/"
|
||||
"../utils/"
|
||||
)
|
||||
|
||||
target_link_libraries(windows
|
||||
PRIVATE
|
||||
widget
|
||||
widget_core
|
||||
bstring
|
||||
utils
|
||||
)
|
||||
|
||||
target_sources(windows
|
||||
PRIVATE
|
||||
${M_SOURCES}
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
windows.h
|
||||
)
|
||||
@@ -1,10 +1,6 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "file_list.h"
|
||||
#include "../file_processor.h"
|
||||
#include "../fs.h"
|
||||
#include "../server.h"
|
||||
#include "app.h"
|
||||
#include <bstrlib.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
@@ -15,7 +11,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "../main_window.h"
|
||||
#include "main_window.h"
|
||||
#include "file_list.h"
|
||||
#include "../file_processor.h"
|
||||
#include "../fs.h"
|
||||
#include "../server.h"
|
||||
|
||||
void w_fl_reset(w_ui_file_list_t *fl_ui);
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include <unistd.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include "../main_window.h"
|
||||
#include "../server.h"
|
||||
#include "main_window.h"
|
||||
#include "alert.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "widget_core.h"
|
||||
#include "../server.h"
|
||||
|
||||
// void w_fl_reset(w_lfl_ui_t *fl_ui);
|
||||
|
||||
@@ -377,20 +377,19 @@ void w_lfl_draw(w_lfl_ui_t *fui) {
|
||||
box(fui->win_list, 0, 0);
|
||||
box(fui->win_info, 0, 0);
|
||||
|
||||
wattrset(win, A_REVERSE); /* Match with modal background */
|
||||
do {
|
||||
if (p_y < 1) {
|
||||
p_y++;
|
||||
continue;
|
||||
}
|
||||
if (el == fui->current) {
|
||||
wattrset(win, COLOR_PAIR(3) | A_BOLD | A_REVERSE);
|
||||
wattrset(win, A_BOLD | A_REVERSE);
|
||||
}
|
||||
p_x = 1;
|
||||
p_x += u_utf8_curs_printw(win, p_y, p_x, el->name, sz_x);
|
||||
mvwprintw(win, p_y, p_x, "%*s", sz_x_f - p_x, "");
|
||||
if (el == fui->current) {
|
||||
wattroff(win, COLOR_PAIR(3) | A_BOLD);
|
||||
wattroff(win, A_BOLD | A_REVERSE);
|
||||
}
|
||||
p_y++;
|
||||
} while ((el = el->next) != NULL && p_y < sz_y_f);
|
||||
@@ -401,12 +400,13 @@ void w_lfl_draw(w_lfl_ui_t *fui) {
|
||||
mvwprintw(win, p_y, p_x, "%*s", sz_x_f - 1, "");
|
||||
}
|
||||
|
||||
wattroff(win, A_BOLD | A_REVERSE);
|
||||
wattrset(win, COLOR_PAIR(0));
|
||||
wattroff(win, A_BOLD);
|
||||
curs_set(false);
|
||||
}
|
||||
|
||||
void w_lfl_destroy(w_lfl_ui_t *fui) {
|
||||
fl_clear(&(fui->start), &(fui->current));
|
||||
free(fui);
|
||||
void w_lfl_destroy(w_lfl_ui_t **fui) {
|
||||
w_lfl_ui_t *f = *fui;
|
||||
fl_clear(&(f->start), &(f->current));
|
||||
free(*fui);
|
||||
*fui = NULL;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ typedef struct {
|
||||
} w_lfl_ui_t;
|
||||
|
||||
void w_lfl_draw(w_lfl_ui_t *fl_ui);
|
||||
void w_lfl_destroy(w_lfl_ui_t *fl_ui);
|
||||
void w_lfl_destroy(w_lfl_ui_t **fui);
|
||||
void w_lfl_reset(w_lfl_ui_t *fl_ui);
|
||||
w_lfl_ui_t *w_lfl_init(WINDOW **win, w_t *w_parent);
|
||||
w_lfl_ui_t *w_lfl_init_win(w_app_t *app);
|
||||
@@ -1,6 +1,9 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "main_window.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "server.h"
|
||||
#include "file_list.h"
|
||||
|
||||
void main_window_set(w_app_t *app, enum main_window_type type) {
|
||||
if (app->main_ui.ui != NULL) {
|
||||
@@ -40,11 +43,11 @@ void main_window_destroy(w_app_t *app) {
|
||||
switch (app->main_ui.type) {
|
||||
case mw_fl_server:
|
||||
w_fl_destroy((w_ui_file_list_t **)&(app->main_ui.ui));
|
||||
MAIN_UI_RESET(app);
|
||||
break;
|
||||
case mw_fl_local:
|
||||
/* TODO: delete fs_file_list */
|
||||
w_lfl_destroy((w_lfl_ui_t **)&(app->main_ui.ui));
|
||||
case mw_f_desc:
|
||||
break;
|
||||
}
|
||||
MAIN_UI_RESET(app);
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#ifndef MAIN_WINDOW_H
|
||||
#define MAIN_WINDOW_H
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#ifndef WINDOWS_H
|
||||
#define WINDOWS_H
|
||||
|
||||
#include "file_list.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "main_window.h"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user