ui: optimization of dialogue refresh
This commit is contained in:
+12
-8
@@ -1,9 +1,3 @@
|
|||||||
#include "client.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "query.h"
|
|
||||||
#include "ui/widget/dialogue.h"
|
|
||||||
#include "ui/widget/file_list.h"
|
|
||||||
#include "ui/widget/progress_bar.h"
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -20,6 +14,13 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "client.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "query.h"
|
||||||
|
#include "ui/widget/dialogue.h"
|
||||||
|
#include "ui/widget/file_list.h"
|
||||||
|
#include "ui/widget/progress_bar.h"
|
||||||
|
|
||||||
static void fl_add(fl_item_t **cur, fl_item_t **start, char *fname);
|
static void fl_add(fl_item_t **cur, fl_item_t **start, char *fname);
|
||||||
fl_item_t *fl_select(fl_item_t *start, int num);
|
fl_item_t *fl_select(fl_item_t *start, int num);
|
||||||
void fl_clear(fl_item_t **start, fl_item_t **current);
|
void fl_clear(fl_item_t **start, fl_item_t **current);
|
||||||
@@ -158,7 +159,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx) {
|
|||||||
f_selected->name = NULL;
|
f_selected->name = NULL;
|
||||||
sprintf(file_path, "%s/%s", DOWNLOADS_DIR, l_selected->name);
|
sprintf(file_path, "%s/%s", DOWNLOADS_DIR, l_selected->name);
|
||||||
f_selected->name = strdup(l_selected->name);
|
f_selected->name = strdup(l_selected->name);
|
||||||
fl_clear(&f_args->l_start, &f_args->l_current);
|
/* fl_clear(&f_args->l_start, &f_args->l_current); */
|
||||||
f_args->file_d = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
f_args->file_d = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
if (f_args->file_d == -1) {
|
if (f_args->file_d == -1) {
|
||||||
qlen = sprintf(send_buf, "error: %s\n", f_selected->name);
|
qlen = sprintf(send_buf, "error: %s\n", f_selected->name);
|
||||||
@@ -181,7 +182,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
static uint32_t it_count = 0;
|
static uint32_t it_count = 0;
|
||||||
static size_t it_interval = 0;
|
static size_t it_interval = 0;
|
||||||
if (it_interval == 0) {
|
if (it_interval == 0) {
|
||||||
it_interval = (f_selected->size / INBUFSIZE / 100) * 1; /* every 1% */
|
it_interval = (f_selected->size / INBUFSIZE / 100) * 5; /* every 1% */
|
||||||
if (it_interval == 0)
|
if (it_interval == 0)
|
||||||
it_interval = 1;
|
it_interval = 1;
|
||||||
}
|
}
|
||||||
@@ -189,6 +190,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
static size_t size_rest = 0;
|
static size_t size_rest = 0;
|
||||||
uint32_t progress = (f_selected->size - size_rest) * 100 / f_selected->size;
|
uint32_t progress = (f_selected->size - size_rest) * 100 / f_selected->size;
|
||||||
ui_progress_bar_t *pb = (ui_progress_bar_t *)q_args->progress_bar;
|
ui_progress_bar_t *pb = (ui_progress_bar_t *)q_args->progress_bar;
|
||||||
|
dialogue_t *d = (dialogue_t *)q_args->active_dialogue;
|
||||||
|
|
||||||
if (size_rest == 0)
|
if (size_rest == 0)
|
||||||
size_rest = f_selected->size;
|
size_rest = f_selected->size;
|
||||||
@@ -197,6 +199,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
it_count++;
|
it_count++;
|
||||||
if (!(it_count % it_interval)) {
|
if (!(it_count % it_interval)) {
|
||||||
pb->procent = progress;
|
pb->procent = progress;
|
||||||
|
d->needs_update = true;
|
||||||
}
|
}
|
||||||
if (it_count % it_interval)
|
if (it_count % it_interval)
|
||||||
q_args->buf_used = 0;
|
q_args->buf_used = 0;
|
||||||
@@ -211,6 +214,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
f_selected->size = 0;
|
f_selected->size = 0;
|
||||||
close(f_args->file_d);
|
close(f_args->file_d);
|
||||||
free(f_selected->name);
|
free(f_selected->name);
|
||||||
|
d->needs_destroy = true;
|
||||||
q_args->state = WAIT_CLIENT;
|
q_args->state = WAIT_CLIENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ typedef struct query_args {
|
|||||||
} server_message;
|
} server_message;
|
||||||
void *file_list_ui; /* TODO: find solution to insert actual type without recursion */
|
void *file_list_ui; /* TODO: find solution to insert actual type without recursion */
|
||||||
void *progress_bar;
|
void *progress_bar;
|
||||||
|
void *active_dialogue;
|
||||||
} query_args_t;
|
} query_args_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -262,6 +262,7 @@ void init_query_args(query_args_t *q_args, params_t *params) {
|
|||||||
q_args->server_message.size = 0;
|
q_args->server_message.size = 0;
|
||||||
q_args->next_server_command = NULL;
|
q_args->next_server_command = NULL;
|
||||||
q_args->progress_bar = NULL;
|
q_args->progress_bar = NULL;
|
||||||
|
q_args->active_dialogue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_request_description(query_args_t *q_args) {
|
void user_request_description(query_args_t *q_args) {
|
||||||
|
|||||||
+8
-3
@@ -4,9 +4,7 @@
|
|||||||
#include "modals/login_credentials.h"
|
#include "modals/login_credentials.h"
|
||||||
#include "modals/login_option.h"
|
#include "modals/login_option.h"
|
||||||
#include "modals/server_message.h"
|
#include "modals/server_message.h"
|
||||||
#include "widget/progress_bar.h"
|
#include "widget/dialogue.h"
|
||||||
// #include "modals/server_message.h"
|
|
||||||
// #include "action.h"
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -84,6 +82,9 @@ void init_nc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_borders(app_t *app) {
|
void draw_borders(app_t *app) {
|
||||||
|
if (app->modal.win != NULL && !app->modal.needs_update) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
clear();
|
clear();
|
||||||
box(app->win, 0, 0);
|
box(app->win, 0, 0);
|
||||||
box(app->left_win, 0, 0);
|
box(app->left_win, 0, 0);
|
||||||
@@ -178,7 +179,11 @@ void app_draw_modal(app_t *app) {
|
|||||||
app->active_win_type = aw_modal;
|
app->active_win_type = aw_modal;
|
||||||
app->active_widget = &(app->modal);
|
app->active_widget = &(app->modal);
|
||||||
}
|
}
|
||||||
|
if (app->modal.needs_destroy) {
|
||||||
|
destroy_dialogue(&(app->modal), app);
|
||||||
|
} else {
|
||||||
draw_dialogue(&(app->modal));
|
draw_dialogue(&(app->modal));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_app(app_t *app) {
|
void destroy_app(app_t *app) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ dialogue_t *init_dwn_pr_modal(app_t *app) {
|
|||||||
d->g_action = init_group(&(d->win), &(d->w), actions, 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->progress_bar = d->g_content->elements[0].element;
|
||||||
|
app->query_args->active_dialogue = d;
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ void dialogue_default_callback(callback_args_t *args) {
|
|||||||
memcpy(&new_args, args, sizeof(callback_args_t));
|
memcpy(&new_args, args, sizeof(callback_args_t));
|
||||||
new_args.active_id = d->active.id;
|
new_args.active_id = d->active.id;
|
||||||
int32_t diff;
|
int32_t diff;
|
||||||
|
d->needs_update = true;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
case '\t':
|
case '\t':
|
||||||
@@ -61,7 +62,7 @@ void dialogue_default_callback(callback_args_t *args) {
|
|||||||
INCR_ACTIVE_ID(d, g_action, g_content);
|
INCR_ACTIVE_ID(d, g_action, g_content);
|
||||||
}
|
}
|
||||||
*resp_value = -1;
|
*resp_value = -1;
|
||||||
draw_dialogue(d);
|
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
if (d->active.type == g_content) {
|
if (d->active.type == g_content) {
|
||||||
@@ -70,7 +71,7 @@ void dialogue_default_callback(callback_args_t *args) {
|
|||||||
DECR_ACTIVE_ID(d, g_action, g_content);
|
DECR_ACTIVE_ID(d, g_action, g_content);
|
||||||
}
|
}
|
||||||
*resp_value = -1;
|
*resp_value = -1;
|
||||||
draw_dialogue(d);
|
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
if (d->active.type == g_action) {
|
if (d->active.type == g_action) {
|
||||||
@@ -88,15 +89,15 @@ void dialogue_default_callback(callback_args_t *args) {
|
|||||||
*resp_value = d->active.id - d->g_content->first_id;
|
*resp_value = d->active.id - d->g_content->first_id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
draw_dialogue(d);
|
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
CH_GROUP(d, g_action, g_content);
|
CH_GROUP(d, g_action, g_content);
|
||||||
draw_dialogue(d);
|
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
CH_GROUP(d, g_content, g_action);
|
CH_GROUP(d, g_content, g_action);
|
||||||
draw_dialogue(d);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* run callback function */
|
/* run callback function */
|
||||||
@@ -106,9 +107,6 @@ void dialogue_default_callback(callback_args_t *args) {
|
|||||||
new_args.widget = new_args.widget = d->g_action;
|
new_args.widget = new_args.widget = d->g_action;
|
||||||
}
|
}
|
||||||
group_default_callback(&new_args);
|
group_default_callback(&new_args);
|
||||||
if (*resp_value == -1) {
|
|
||||||
draw_dialogue(d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +118,9 @@ void init_dialogue(dialogue_t *dialogue, const char title[], const char text[],
|
|||||||
dialogue->w.y = 0;
|
dialogue->w.y = 0;
|
||||||
dialogue->p_coordinates = p_coordinates;
|
dialogue->p_coordinates = p_coordinates;
|
||||||
dialogue->w.callback = dialogue_default_callback;
|
dialogue->w.callback = dialogue_default_callback;
|
||||||
dialogue->is_initiated = 1;
|
dialogue->is_initiated = true;
|
||||||
|
dialogue->needs_update = true;
|
||||||
|
dialogue->needs_destroy = false;
|
||||||
strcpy(dialogue->w.title, title);
|
strcpy(dialogue->w.title, title);
|
||||||
strcpy(dialogue->text, text);
|
strcpy(dialogue->text, text);
|
||||||
}
|
}
|
||||||
@@ -166,6 +166,10 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
|
|||||||
int32_t draw_dialogue(dialogue_t *d) {
|
int32_t draw_dialogue(dialogue_t *d) {
|
||||||
if (!d->is_initiated)
|
if (!d->is_initiated)
|
||||||
return -1;
|
return -1;
|
||||||
|
else if (!d->needs_update) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
group_el_t *ae_ptr = NULL; /* active element */
|
group_el_t *ae_ptr = NULL; /* active element */
|
||||||
uint32_t ae_idx; /* active element */
|
uint32_t ae_idx; /* active element */
|
||||||
/* count dimensions */
|
/* count dimensions */
|
||||||
@@ -196,6 +200,7 @@ int32_t draw_dialogue(dialogue_t *d) {
|
|||||||
if (d->win == NULL) {
|
if (d->win == NULL) {
|
||||||
d->win = newwin(y, x, d->w.m_y, d->w.m_x);
|
d->win = newwin(y, x, d->w.m_y, d->w.m_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
wattrset(d->win, COLOR_PAIR(0) | A_BOLD | A_REVERSE);
|
wattrset(d->win, COLOR_PAIR(0) | A_BOLD | A_REVERSE);
|
||||||
|
|
||||||
/* background */
|
/* background */
|
||||||
@@ -215,6 +220,7 @@ int32_t draw_dialogue(dialogue_t *d) {
|
|||||||
/* 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, d->w.x, 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) {
|
||||||
draw_group(d->win, d->g_content, d->active.id, &(d->w));
|
draw_group(d->win, d->g_content, d->active.id, &(d->w));
|
||||||
}
|
}
|
||||||
@@ -247,6 +253,8 @@ int32_t draw_dialogue(dialogue_t *d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->needs_update = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -264,4 +272,5 @@ void destroy_dialogue(dialogue_t *d, void *_app) {
|
|||||||
app->active_win_type = aw_left;
|
app->active_win_type = aw_left;
|
||||||
app->active_win = app->left_win;
|
app->active_win = app->left_win;
|
||||||
app->active_callback = file_list_cb;
|
app->active_callback = file_list_cb;
|
||||||
|
app->query_args->active_dialogue = NULL;
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@ typedef struct {
|
|||||||
} active;
|
} active;
|
||||||
char text[DIALOGUE_TEXT];
|
char text[DIALOGUE_TEXT];
|
||||||
uint32_t is_initiated : 1;
|
uint32_t is_initiated : 1;
|
||||||
|
uint32_t needs_update : 1;
|
||||||
|
uint32_t needs_destroy: 1;
|
||||||
coordinates_t *p_coordinates;
|
coordinates_t *p_coordinates;
|
||||||
} dialogue_t;
|
} dialogue_t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user