From 8c87c46c46d0c75eb69973fc64abcca0f28c4721 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Thu, 28 May 2026 16:44:44 +0300 Subject: [PATCH] +Cancel download [needs to test] --- TODO.md | 7 ++++--- src/draw_modal.c | 2 +- src/file_processor.c | 2 +- src/main.h | 2 +- src/modals/load_pr.c | 29 ++++++++++++++++++++++++----- src/query.c | 9 +-------- src/utils/utils.h | 7 +++++++ src/widget/dialogue.c | 4 ++-- 8 files changed, 41 insertions(+), 21 deletions(-) diff --git a/TODO.md b/TODO.md index 92535be..ac18a5d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,13 @@ # TODO: ## Current: +- [ ] Break line automatically in modal widgets +- [ ] Cancel upload/download +- [ ] Show download/upload progress in percentages - [ ] File upload multiline description (window) - [ ] Separate common structures in the common.h - [ ] Sorting in the file list -- [ ] Cancel upload/download -- [ ] Break line automatically in modal widgets -- [ ] Show download/upload progress in percentages +- [ ] Resume download - [x] Input: fix non-Latin letters - [x] Get rid of unsigned integers - [x] Check registration / enter server name again diff --git a/src/draw_modal.c b/src/draw_modal.c index 2a702d4..5ef0d46 100644 --- a/src/draw_modal.c +++ b/src/draw_modal.c @@ -28,7 +28,7 @@ void app_draw_modal(app_t *app) { case S_PRINT_SERVER_MESSAGE: m_server_message_init(app); break; - case S_FILE_DOWNLOAD: + case S_DOWNLOAD_FILE: m_load_pr_init(app, false); break; case S_UPLOAD_FILE: diff --git a/src/file_processor.c b/src/file_processor.c index 9446ada..68bd868 100644 --- a/src/file_processor.c +++ b/src/file_processor.c @@ -101,7 +101,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx) { return -2; } server_send_string(q_args, "file download [%s]\n", f_selected->name); - q_args->state = S_FILE_DOWNLOAD; + q_args->state = S_DOWNLOAD_FILE; free(file_path); return OK; } diff --git a/src/main.h b/src/main.h index f4adaba..74a824f 100644 --- a/src/main.h +++ b/src/main.h @@ -42,7 +42,7 @@ enum state { S_FILE_LIST, S_WAIT_PASS, /* S_FILE_SELECT, */ - S_FILE_DOWNLOAD, + S_DOWNLOAD_FILE, S_UPLOAD_PARAMS, S_UPLOAD_FILE, /* S_UPLOAD_FILE_SELECT, */ diff --git a/src/modals/load_pr.c b/src/modals/load_pr.c index 49a72f8..9ed9ab5 100644 --- a/src/modals/load_pr.c +++ b/src/modals/load_pr.c @@ -1,24 +1,43 @@ +#include "../server.h" #include "alert.h" #include "dialogue.h" #include "group.h" +#include "utils.h" +#include "../windows/file_list.h" #include #include #include +#include #include void dwn_pr_modal_cb(w_cb_args_t *args) { /* only cancel action */ int32_t key = *((int32_t *)args->data); + if (key != '\n') { return; } + app_t *app = args->app; + w_dialogue_t *d = &(app->modal); /* TODO: forward actual file name */ - bool response = w_bool_ask("Cancel file load", "Yes", "No", false, - "You're going to cancel download\n Are you sure?", - app->query_args->file->name); - if (response) { - app->query_args->file->signal = sig_cancel; + if (app->query_args->state == S_UPLOAD_FILE) { + bool response = w_bool_ask("Cancel file upload", "Yes", "No", false, + "You're going to cancel upload\n Are you sure?"); + if (response) { + app->query_args->file->signal = sig_cancel; + } + } else if (app->query_args->state == S_DOWNLOAD_FILE) { + w_ui_file_list_t *fui = (w_ui_file_list_t *)app->query_args->main_ui->ui; + bool response = + w_bool_ask("Cancel file download", "Yes", "No", false, + "You're going to cancel download\n Are you sure?"); + server_send_string(app->query_args, "cancel\n"); + FILE_CLEAN(app); + d->needs_destroy = true; + app->query_args->state = S_FILE_LIST; + server_send_string(app->query_args, "file list %d %d\n", fui->max_lines, + fui->current_page); } } diff --git a/src/query.c b/src/query.c index e8358f6..32970fc 100644 --- a/src/query.c +++ b/src/query.c @@ -45,13 +45,6 @@ int32_t process_user_input(app_t *app, w_cb_args_t *d_args); app_destroy(app, exit_code); \ } -#define FILE_CLEAN(app) \ - if (app->query_args->file != NULL) { \ - FREE_MLC(app->query_args->file->name); \ - FREE_MLC(app->query_args->file->path); \ - FREE_MLC(app->query_args->file); \ - } - void query_loop(app_t *app) { query_args_t *query_args = app->query_args; fd_set readfds; @@ -183,7 +176,7 @@ int process_query(app_t *app) { case S_FILE_LIST: file_list(file_args, query_args); break; - case S_FILE_DOWNLOAD: + case S_DOWNLOAD_FILE: file_download(file_args, query_args); break; case S_UPLOAD_REQUESTED: diff --git a/src/utils/utils.h b/src/utils/utils.h index 6971a76..9fa510b 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -9,4 +9,11 @@ free(arg); \ arg = NULL; \ } + +#define FILE_CLEAN(app) \ + if (app->query_args->file != NULL) { \ + FREE_MLC(app->query_args->file->name); \ + FREE_MLC(app->query_args->file->path); \ + FREE_MLC(app->query_args->file); \ + } #endif \ No newline at end of file diff --git a/src/widget/dialogue.c b/src/widget/dialogue.c index b3db66f..f9d0a99 100644 --- a/src/widget/dialogue.c +++ b/src/widget/dialogue.c @@ -60,7 +60,7 @@ static void decr_active_id(w_dialogue_t *d) { } static void case_callback(w_cb_args_t *args, w_cb_args_t *new_args) { - w_dialogue_t *d = (void *)args->element; + w_dialogue_t *d = args->element; /* run callback function */ if (d->active_el->g_type == g_content) { new_args->element = d->g_content; @@ -74,7 +74,7 @@ static void case_callback(w_cb_args_t *args, w_cb_args_t *new_args) { } void w_dialogue_callback_default(w_cb_args_t *args) { - w_dialogue_t *d = (void *)args->element; + w_dialogue_t *d = args->element; int32_t key = *((int32_t *)args->data); w_cb_args_t new_args; memcpy(&new_args, args, sizeof(w_cb_args_t));