ui: finished (kinda) file upload
This commit is contained in:
@@ -14,6 +14,6 @@ TODO:
|
|||||||
|
|
||||||
UPLOAD:
|
UPLOAD:
|
||||||
- [ ] Progress bar
|
- [ ] Progress bar
|
||||||
- [ ] Show notifications and messages from the server (universal way)
|
- [x] Show notifications and messages from the server (universal way)
|
||||||
use notification or something
|
use notification or something
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -25,5 +25,5 @@ query.o: src/query.c src/client.h src/main.h src/types.h src/connection.h \
|
|||||||
src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
||||||
src/ui/widget/../../common.h src/ui/widget/button.h \
|
src/ui/widget/../../common.h src/ui/widget/button.h \
|
||||||
src/ui/widget/../../main.h src/ui/widget/group.h src/file_processor.h \
|
src/ui/widget/../../main.h src/ui/widget/group.h src/file_processor.h \
|
||||||
src/ui/widget/file_list.h src/server.h
|
src/ui/widget/file_list.h src/server.h src/ui/widget/dialogue.h
|
||||||
server.o: src/server.c src/main.h src/types.h
|
server.o: src/server.c src/main.h src/types.h
|
||||||
|
|||||||
+20
-3
@@ -204,9 +204,9 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
if (!(it_count % it_interval)) {
|
if (!(it_count % it_interval)) {
|
||||||
pb->procent = progress;
|
pb->procent = progress;
|
||||||
d->needs_update = true;
|
d->needs_update = true;
|
||||||
}
|
} else {
|
||||||
if (it_count % it_interval)
|
|
||||||
q_args->buf_used = 0;
|
q_args->buf_used = 0;
|
||||||
|
}
|
||||||
if (size_rest < qlen) {
|
if (size_rest < qlen) {
|
||||||
size_rest = 0;
|
size_rest = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -292,18 +292,35 @@ int32_t file_upload_start(query_args_t *q_args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t file_upload(query_args_t *q_args) {
|
int32_t file_upload(query_args_t *q_args) {
|
||||||
|
static uint32_t it_count = 0;
|
||||||
|
static size_t it_interval = 0;
|
||||||
|
if (it_interval == 0) {
|
||||||
|
it_interval = (q_args->file->size / INBUFSIZE / 100) * 5; /* every 1% */
|
||||||
|
if (it_interval == 0)
|
||||||
|
it_interval = 1;
|
||||||
|
}
|
||||||
|
uint32_t progress =
|
||||||
|
(q_args->file->size - q_args->file->rest) * 100 / q_args->file->size;
|
||||||
|
ui_progress_bar_t *pb = (ui_progress_bar_t *)q_args->progress_bar;
|
||||||
|
dialogue_t *d = (dialogue_t *)q_args->active_dialogue;
|
||||||
if (q_args->buf_used > 0) {
|
if (q_args->buf_used > 0) {
|
||||||
int wlen = write(q_args->sd, q_args->buf, q_args->buf_used);
|
int wlen = write(q_args->sd, q_args->buf, q_args->buf_used);
|
||||||
if (q_args->buf_used != wlen) {
|
if (q_args->buf_used != wlen) {
|
||||||
/* TODO: ошибка */
|
/* TODO: ошибка */
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
it_count++;
|
||||||
|
if (!(it_count % it_interval)) {
|
||||||
|
pb->procent = progress;
|
||||||
|
d->needs_update = true;
|
||||||
|
}
|
||||||
q_args->buf[0] = 0;
|
q_args->buf[0] = 0;
|
||||||
q_args->buf_used = 0;
|
q_args->buf_used = 0;
|
||||||
q_args->file->rest -= wlen;
|
q_args->file->rest -= wlen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* TODO: уведомление пользователю */
|
it_count = 0;
|
||||||
|
it_interval = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+8
-2
@@ -22,6 +22,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "ui/app.h"
|
#include "ui/app.h"
|
||||||
|
#include "ui/widget/dialogue.h"
|
||||||
|
|
||||||
static void wait_side(query_args_t *q_args);
|
static void wait_side(query_args_t *q_args);
|
||||||
void user_request_description(query_args_t *q_args);
|
void user_request_description(query_args_t *q_args);
|
||||||
@@ -44,6 +45,9 @@ void query_loop(app_t *app) {
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* update screen */
|
/* update screen */
|
||||||
|
if (query_args->state == S_WAIT_SERVER && app->modal.is_initiated) {
|
||||||
|
destroy_dialogue(&(app->modal), app);
|
||||||
|
}
|
||||||
app_draw_modal(app);
|
app_draw_modal(app);
|
||||||
app_refresh(app);
|
app_refresh(app);
|
||||||
|
|
||||||
@@ -134,7 +138,7 @@ void wait_register(query_args_t *q_args) {
|
|||||||
|
|
||||||
int process_query(query_args_t *query_args, file_args_t *file_args) {
|
int process_query(query_args_t *query_args, file_args_t *file_args) {
|
||||||
query_args->buf[query_args->buf_used] = 0;
|
query_args->buf[query_args->buf_used] = 0;
|
||||||
|
int32_t res = 0;
|
||||||
switch (query_args->state) {
|
switch (query_args->state) {
|
||||||
case WAIT_SERVER:
|
case WAIT_SERVER:
|
||||||
case WAIT_SERVER_INIT:
|
case WAIT_SERVER_INIT:
|
||||||
@@ -168,11 +172,13 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
|||||||
break;
|
break;
|
||||||
case S_UPLOAD_PARAMS:
|
case S_UPLOAD_PARAMS:
|
||||||
case S_UPLOAD_FILE:
|
case S_UPLOAD_FILE:
|
||||||
if (file_upload(query_args)) {
|
if ((res = file_upload(query_args)) == 1) {
|
||||||
/* upload finishes */
|
/* upload finishes */
|
||||||
user_request_description(query_args);
|
user_request_description(query_args);
|
||||||
clear_file_in_query(query_args);
|
clear_file_in_query(query_args);
|
||||||
query_args->state = S_WAIT_SERVER;
|
query_args->state = S_WAIT_SERVER;
|
||||||
|
} else if (res == -1) {
|
||||||
|
/* TODO: Error */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_ASK_USER_BEFORE_LOGIN:
|
case S_ASK_USER_BEFORE_LOGIN:
|
||||||
|
|||||||
+8
-9
@@ -14,7 +14,7 @@
|
|||||||
void ask_uname_and_password(params_t *params);
|
void ask_uname_and_password(params_t *params);
|
||||||
void ask_register(params_t *params, char *email);
|
void ask_register(params_t *params, char *email);
|
||||||
|
|
||||||
#define PRINT_SRV_MESSAGE(q_args) \
|
#define PRINT_SRV_MESSAGE(q_args, l_len, line) \
|
||||||
if (q_args->server_message.size > 0) { \
|
if (q_args->server_message.size > 0) { \
|
||||||
q_args->state = S_PRINT_SERVER_MESSAGE; \
|
q_args->state = S_PRINT_SERVER_MESSAGE; \
|
||||||
q_args->next_server_command = malloc(l_len + 1); \
|
q_args->next_server_command = malloc(l_len + 1); \
|
||||||
@@ -36,7 +36,7 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
|||||||
/* LOGIN */
|
/* LOGIN */
|
||||||
if (!strncmp(line, "login>", ws_pos)) {
|
if (!strncmp(line, "login>", ws_pos)) {
|
||||||
if (q_args->server_message.size > 0) {
|
if (q_args->server_message.size > 0) {
|
||||||
PRINT_SRV_MESSAGE(q_args);
|
PRINT_SRV_MESSAGE(q_args, l_len, line);
|
||||||
}
|
}
|
||||||
if (q_args->params->uname != NULL && q_args->params->pass != NULL) {
|
if (q_args->params->uname != NULL && q_args->params->pass != NULL) {
|
||||||
write(params->sd, q_args->params->uname, strlen(q_args->params->uname));
|
write(params->sd, q_args->params->uname, strlen(q_args->params->uname));
|
||||||
@@ -110,13 +110,12 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
|||||||
strncat(q_args->server_message.text, line, l_len);
|
strncat(q_args->server_message.text, line, l_len);
|
||||||
q_args->server_message.text[q_args->server_message.size + l_len] = 0;
|
q_args->server_message.text[q_args->server_message.size + l_len] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
char *end_char = strchr(q_args->server_message.text, '\04'); /* Search for the end of the notification */
|
||||||
/* char buf[INBUFSIZE + sizeof("server: ")] = "server: ";
|
if (end_char != NULL) {
|
||||||
strcat(buf, line);
|
*end_char = '\0'; /* Don't show this symbol */
|
||||||
write(STDOUT_FILENO, buf, l_len + sizeof("server: "));
|
q_args->state = S_PRINT_SERVER_MESSAGE;
|
||||||
if (q_args->state == WAIT_CLIENT) {
|
q_args->server_message.size--;
|
||||||
print_prompt(q_args->params);
|
}
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+4
-2
@@ -155,7 +155,10 @@ void app_draw_modal(app_t *app) {
|
|||||||
init_server_message_modal(app);
|
init_server_message_modal(app);
|
||||||
break;
|
break;
|
||||||
case S_FILE_DOWNLOAD:
|
case S_FILE_DOWNLOAD:
|
||||||
init_dwn_pr_modal(app);
|
init_dwn_pr_modal(app, false);
|
||||||
|
break;
|
||||||
|
case S_UPLOAD_FILE:
|
||||||
|
init_dwn_pr_modal(app, true);
|
||||||
break;
|
break;
|
||||||
case S_UPLOAD_FILE_SELECT:
|
case S_UPLOAD_FILE_SELECT:
|
||||||
init_upload_dialogue_modal(app);
|
init_upload_dialogue_modal(app);
|
||||||
@@ -176,7 +179,6 @@ void app_draw_modal(app_t *app) {
|
|||||||
case S_WAIT_SERVER:
|
case S_WAIT_SERVER:
|
||||||
case S_N_D:
|
case S_N_D:
|
||||||
case S_NEXT_ACTION:
|
case S_NEXT_ACTION:
|
||||||
case S_UPLOAD_FILE:
|
|
||||||
if (app->query_args->notification != NULL) {
|
if (app->query_args->notification != NULL) {
|
||||||
init_notification_modal(app);
|
init_notification_modal(app);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,22 +5,24 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void dwn_pr_modal_cb(callback_args_t *args) {
|
void dwn_pr_modal_cb(callback_args_t *args) {}
|
||||||
}
|
|
||||||
|
|
||||||
dialogue_t *init_dwn_pr_modal(app_t *app) {
|
dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload) {
|
||||||
if (app == NULL)
|
if (app == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
group_el_init_t content[] = {{.type = w_progress, .label = "", .length = 30}, /* length is ignored */
|
group_el_init_t content[] = {
|
||||||
{.type = w_end}};
|
{.type = w_progress, .label = "", .length = 30}, /* length is ignored */
|
||||||
|
{.type = w_end}};
|
||||||
|
|
||||||
char text[256];
|
char text[256];
|
||||||
sprintf(text, "Downloading file: %s", app->file_args->f_selected.name);
|
sprintf(text, "%s file: %s", is_upload ? "Uploading" : "Downloading",
|
||||||
|
is_upload ? app->query_args->file->name : app->file_args->f_selected.name);
|
||||||
group_el_init_t actions[] = {
|
group_el_init_t actions[] = {
|
||||||
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_end}};
|
{.type = w_button, .label = "Cancel", .is_default = 1}, {.type = w_end}};
|
||||||
|
|
||||||
app->modal.w.parent_win = &app->win;
|
app->modal.w.parent_win = &app->win;
|
||||||
init_dialogue(&(app->modal), "Download", text, &(app->coordinates));
|
init_dialogue(&(app->modal), is_upload ? "Upload" : "Download", text,
|
||||||
|
&(app->coordinates));
|
||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = dwn_pr_modal_cb;
|
d->w.callback = dwn_pr_modal_cb;
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
#include "../widget/dialogue.h"
|
#include "../widget/dialogue.h"
|
||||||
#include "../app.h"
|
#include "../app.h"
|
||||||
|
|
||||||
dialogue_t *init_dwn_pr_modal(app_t *app);
|
dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -28,6 +28,7 @@ void server_message_modal_cb(callback_args_t *args) {
|
|||||||
destroy_dialogue(d, app);
|
destroy_dialogue(d, app);
|
||||||
/* TODO: macros */
|
/* TODO: macros */
|
||||||
free(app->query_args->server_message.text);
|
free(app->query_args->server_message.text);
|
||||||
|
app->query_args->server_message.text = NULL;
|
||||||
app->query_args->server_message.capacity = 0;
|
app->query_args->server_message.capacity = 0;
|
||||||
app->query_args->server_message.size = 0;
|
app->query_args->server_message.size = 0;
|
||||||
app->query_args->state = S_NEXT_ACTION;
|
app->query_args->state = S_NEXT_ACTION;
|
||||||
|
|||||||
@@ -187,10 +187,12 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
|
|||||||
dialogue->active.type = g_content;
|
dialogue->active.type = g_content;
|
||||||
widget_t *w = (widget_t *)dialogue->g_content->elements[i].element;
|
widget_t *w = (widget_t *)dialogue->g_content->elements[i].element;
|
||||||
dialogue->active.id = w->id;
|
dialogue->active.id = w->id;
|
||||||
break;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (dialogue->g_action != NULL) {
|
}
|
||||||
|
if (dialogue->g_action != NULL) {
|
||||||
for (int i = 0; i < dialogue->g_action->count; i++) {
|
for (int i = 0; i < dialogue->g_action->count; i++) {
|
||||||
widget_type = dialogue->g_action->elements[i].type;
|
widget_type = dialogue->g_action->elements[i].type;
|
||||||
if (widget_type == w_button || widget_type == w_input ||
|
if (widget_type == w_button || widget_type == w_input ||
|
||||||
@@ -198,12 +200,41 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
|
|||||||
dialogue->active.type = g_action;
|
dialogue->active.type = g_action;
|
||||||
widget_t *w = (widget_t *)dialogue->g_action->elements[i].element;
|
widget_t *w = (widget_t *)dialogue->g_action->elements[i].element;
|
||||||
dialogue->active.id = w->id;
|
dialogue->active.id = w->id;
|
||||||
break;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void dialogue_init_active_id(dialogue_t *dialogue) {
|
||||||
|
// enum w_type widget_type;
|
||||||
|
|
||||||
|
// if (dialogue->g_content != NULL) {
|
||||||
|
// for (int i = 0; i < dialogue->g_content->count; i++) {
|
||||||
|
// widget_type = dialogue->g_content->elements[i].type;
|
||||||
|
// if (widget_type == w_button || widget_type == w_input ||
|
||||||
|
// widget_type == w_fs_file_list) { /* Add here new types */
|
||||||
|
// dialogue->active.type = g_content;
|
||||||
|
// widget_t *w = (widget_t *)dialogue->g_content->elements[i].element;
|
||||||
|
// dialogue->active.id = w->id;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else if (dialogue->g_action != NULL) {
|
||||||
|
// for (int i = 0; i < dialogue->g_action->count; i++) {
|
||||||
|
// widget_type = dialogue->g_action->elements[i].type;
|
||||||
|
// if (widget_type == w_button || widget_type == w_input ||
|
||||||
|
// widget_type == w_fs_file_list) {
|
||||||
|
// dialogue->active.type = g_action;
|
||||||
|
// widget_t *w = (widget_t *)dialogue->g_action->elements[i].element;
|
||||||
|
// dialogue->active.id = w->id;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
#define DETECT_GROUP_SIZE(group, line_max_len, y, x) \
|
#define DETECT_GROUP_SIZE(group, line_max_len, y, x) \
|
||||||
if (group) { \
|
if (group) { \
|
||||||
group->w.m_y = y; \
|
group->w.m_y = y; \
|
||||||
|
|||||||
Reference in New Issue
Block a user