diff --git a/CMakeLists.txt b/CMakeLists.txt index f034140..7fb08a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9808ff..5523a2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ target_link_libraries(zbbs-client-tui widget modals bstring + windows utils ${CURSES_LIBRARIES} ) \ No newline at end of file diff --git a/src/common.h b/src/common.h index 99c5c77..e2956ff 100644 --- a/src/common.h +++ b/src/common.h @@ -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; diff --git a/src/draw_modal.c b/src/draw_modal.c index e250a2c..454df71 100644 --- a/src/draw_modal.c +++ b/src/draw_modal.c @@ -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; diff --git a/src/file_processor.c b/src/file_processor.c index 43883d2..28b15ac 100644 --- a/src/file_processor.c +++ b/src/file_processor.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "file_processor.h" #include "main.h" diff --git a/src/file_processor.h b/src/file_processor.h index 0244689..200645d 100644 --- a/src/file_processor.h +++ b/src/file_processor.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); diff --git a/src/main.c b/src/main.c index b6f77d1..d69cc4f 100644 --- a/src/main.c +++ b/src/main.c @@ -13,13 +13,12 @@ #include #include #include +#include +#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; diff --git a/src/main.h b/src/main.h index 1a5fa0b..67f156b 100644 --- a/src/main.h +++ b/src/main.h @@ -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, diff --git a/src/modals/modals.h b/src/modals/modals.h index 84d659c..96330e1 100644 --- a/src/modals/modals.h +++ b/src/modals/modals.h @@ -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 \ No newline at end of file diff --git a/src/modals/upload_dialogue.c b/src/modals/upload_dialogue.c index 630975c..2bc920b 100644 --- a/src/modals/upload_dialogue.c +++ b/src/modals/upload_dialogue.c @@ -1,5 +1,6 @@ -#include "../file_processor.h" +/* #include "../file_processor.h" #include "group.h" +#include "widget_core.h" #include #include #include @@ -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,26 +38,27 @@ 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", - &(app->coordinates)); + &(app->coordinates)); w_dialogue_t *d = &(app->modal); d->w.callback = upload_dialogue_modal_cb; d->g_content = w_group_init(&(d->win), &(d->w), content, &(d->id_map), - horizontal, g_content); + horizontal, g_content); d->g_action = w_group_init(&(d->win), &(d->w), actions, &(d->id_map), - horizontal, g_action); + horizontal, g_action); app->query_args->active_dialogue = d; w_dialogue_init_active_id(d); return NULL; -} \ No newline at end of file +} */ \ No newline at end of file diff --git a/src/query.c b/src/query.c index 38a0b6d..de44ea3 100644 --- a/src/query.c +++ b/src/query.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "alert.h" #include "connection.h" diff --git a/src/server.c b/src/server.c index 8cd227c..c81c325 100644 --- a/src/server.c +++ b/src/server.c @@ -18,6 +18,7 @@ #include #include #include +#include void ask_uname_and_password(params_t *params); void ask_register(params_t *params, char *email); diff --git a/src/widget/app.c b/src/widget/app.c index d58dc22..fb79822 100644 --- a/src/widget/app.c +++ b/src/widget/app.c @@ -2,7 +2,6 @@ /* Copyright (c) 2026 Oleksandr Zhylin */ #include "app.h" -#include "file_list.h" #include #include #include diff --git a/src/widget/dialogue.c b/src/widget/dialogue.c index e35a147..a61255d 100644 --- a/src/widget/dialogue.c +++ b/src/widget/dialogue.c @@ -9,8 +9,6 @@ #include #include -#include "file_list.h" - void incr_active_id(w_dialogue_t *d) { w_g_el_t *active_el = NULL; while (true) { @@ -114,21 +112,15 @@ 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 && - d->g_content->direction == vertical) { + 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 && - d->g_content->direction == vertical) { + 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; @@ -319,7 +312,7 @@ void w_dialogue_destroy(w_dialogue_t *d, void *_app) { d->win = NULL; d->is_initiated = 0; d->needs_destroy = false; - app->active_callback = (w_cb_t) app->main_ui.cb_b_press; + app->active_callback = (w_cb_t)app->main_ui.cb_b_press; app->query_args->active_dialogue = NULL; u_d_arr_ptr_free(&(d->id_map)); w_app_refresh(app); diff --git a/src/widget/group.c b/src/widget/group.c index 589fe2b..6c160bd 100644 --- a/src/widget/group.c +++ b/src/widget/group.c @@ -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; diff --git a/src/widget/widget.h b/src/widget/widget.h index db16e0b..1a2cbe3 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -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" diff --git a/src/widget_core/widget_core.h b/src/widget_core/widget_core.h index 69d59f2..37a75af 100644 --- a/src/widget_core/widget_core.h +++ b/src/widget_core/widget_core.h @@ -23,7 +23,6 @@ enum w_type { w_input, w_checkbox, w_progress, - w_fs_file_list, }; enum w_val_type { diff --git a/src/windows/CMakeLists.txt b/src/windows/CMakeLists.txt new file mode 100644 index 0000000..ea2e816 --- /dev/null +++ b/src/windows/CMakeLists.txt @@ -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 +) \ No newline at end of file diff --git a/src/widget/file_list.c b/src/windows/file_list.c similarity index 99% rename from src/widget/file_list.c rename to src/windows/file_list.c index 3cbc7a2..5abb0ad 100644 --- a/src/widget/file_list.c +++ b/src/windows/file_list.c @@ -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 #include @@ -15,7 +11,11 @@ #include #include #include -#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); diff --git a/src/widget/file_list.h b/src/windows/file_list.h similarity index 100% rename from src/widget/file_list.h rename to src/windows/file_list.h diff --git a/src/widget/fs_file_list.c b/src/windows/fs_file_list.c similarity index 96% rename from src/widget/fs_file_list.c rename to src/windows/fs_file_list.c index a3b5e83..7bb9acb 100644 --- a/src/widget/fs_file_list.c +++ b/src/windows/fs_file_list.c @@ -14,11 +14,11 @@ #include #include -#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; } \ No newline at end of file diff --git a/src/widget/fs_file_list.h b/src/windows/fs_file_list.h similarity index 95% rename from src/widget/fs_file_list.h rename to src/windows/fs_file_list.h index 88a5055..8a5e34b 100644 --- a/src/widget/fs_file_list.h +++ b/src/windows/fs_file_list.h @@ -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); diff --git a/src/main_window.c b/src/windows/main_window.c similarity index 84% rename from src/main_window.c rename to src/windows/main_window.c index c18197f..2173976 100644 --- a/src/main_window.c +++ b/src/windows/main_window.c @@ -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); } \ No newline at end of file diff --git a/src/main_window.h b/src/windows/main_window.h similarity index 73% rename from src/main_window.h rename to src/windows/main_window.h index 4707cdf..600c781 100644 --- a/src/main_window.h +++ b/src/windows/main_window.h @@ -1,3 +1,6 @@ +/* SPDX-License-Identifier: MIT */ +/* Copyright (c) 2026 Oleksandr Zhylin */ + #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H diff --git a/src/windows/windows.h b/src/windows/windows.h new file mode 100644 index 0000000..53ec300 --- /dev/null +++ b/src/windows/windows.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 \ No newline at end of file