From af7bed47e63ef589ddfacbe416e8f9d8b9535209 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 15 Dec 2022 19:24:02 +0100 Subject: [PATCH] [download] refresh_dialog in display_download Results are promising, lower CPU usage while displaying download info dialog. Need to check bittorrent. --- src/dialogs/download.c | 21 +++++++++++++-------- src/session/download.c | 11 +++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/dialogs/download.c b/src/dialogs/download.c index 73fb8049..f2fefbb8 100644 --- a/src/dialogs/download.c +++ b/src/dialogs/download.c @@ -228,12 +228,20 @@ download_dialog_layouter(struct dialog_data *dlg_data) mem_free(msg); } +static enum dlg_refresh_code +refresh_file_download(struct dialog_data *dlg_data, void *data) +{ + /* Always refresh (until we keep finished downloads) */ + return are_there_downloads() ? REFRESH_DIALOG : REFRESH_STOP; +} + void display_download(struct terminal *term, struct file_download *file_download, struct session *ses) { /* [gettext_accelerator_context(display_download)] */ struct dialog *dlg; + struct dialog_data *ret; if (!is_in_downloads_list(file_download)) return; @@ -282,9 +290,12 @@ display_download(struct terminal *term, struct file_download *file_download, add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler); #endif - do_dialog(term, dlg, getml(dlg, (void *) NULL)); -} + ret = do_dialog(term, dlg, getml(dlg, (void *) NULL)); + if (ret) { + refresh_dialog(ret, refresh_file_download, NULL); + } +} /* The download manager */ @@ -360,12 +371,6 @@ delete_file_download(struct listbox_item *item, int last) register_bottom_half(do_abort_download, file_download); } -static enum dlg_refresh_code -refresh_file_download(struct dialog_data *dlg_data, void *data) -{ - /* Always refresh (until we keep finished downloads) */ - return are_there_downloads() ? REFRESH_DIALOG : REFRESH_STOP; -} /* TODO: Make it configurable */ #define DOWNLOAD_METER_WIDTH 15 diff --git a/src/session/download.c b/src/session/download.c index c65fdbff..210df959 100644 --- a/src/session/download.c +++ b/src/session/download.c @@ -141,8 +141,12 @@ abort_download(struct file_download *file_download) if (file_download->ses) check_questions_queue(file_download->ses); - if (file_download->dlg_data) + if (file_download->dlg_data) { + if (file_download->dlg_data->dlg && file_download->dlg_data->dlg->refresh) { + kill_timer(&file_download->dlg_data->dlg->refresh->timer); + } cancel_dialog(file_download->dlg_data, NULL); + } cancel_download(&file_download->download, file_download->stop); if (file_download->uri) done_uri(file_download->uri); @@ -481,8 +485,6 @@ download_data_store(struct download *download, struct file_download *file_downlo if_assert_failed term = file_download->term = NULL; if (is_in_progress_state(download->state)) { - if (file_download->dlg_data) - redraw_dialog(file_download->dlg_data, 1); return; } @@ -600,9 +602,6 @@ download_data(struct download *download, struct file_download *file_download) file_download->uri = get_uri_reference(cached->redirect); file_download->download.state = connection_state(S_WAIT_REDIR); - if (file_download->dlg_data) - redraw_dialog(file_download->dlg_data, 1); - load_uri(file_download->uri, cached->uri, &file_download->download, PRI_DOWNLOAD, CACHE_MODE_NORMAL, download->progress ? download->progress->start : 0);