ui: file upload basic process (need improvement)
This commit is contained in:
+4
-4
@@ -7,12 +7,12 @@ connection.o: src/connection.c src/main.h src/types.h src/ui/app.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/ui/widget/../../main.h src/ui/widget/group.h
|
||||||
file_processor.o: src/file_processor.c src/client.h src/main.h \
|
file_processor.o: src/file_processor.c src/client.h src/main.h \
|
||||||
src/types.h src/query.h src/ui/app.h src/ui/../common.h src/ui/widget.h \
|
src/types.h src/file_processor.h src/ui/widget/file_list.h \
|
||||||
src/ui/../main.h src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
src/ui/widget/../widget.h src/ui/widget/../../main.h src/query.h \
|
||||||
|
src/ui/app.h src/ui/../common.h src/ui/widget.h src/ui/widget/dialogue.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/ui/widget/../../main.h src/ui/widget/group.h \
|
||||||
src/ui/widget/dialogue.h src/ui/widget/file_list.h \
|
src/ui/widget/dialogue.h src/ui/widget/progress_bar.h
|
||||||
src/ui/widget/progress_bar.h
|
|
||||||
fs.o: src/fs.c
|
fs.o: src/fs.c
|
||||||
main.o: src/main.c src/connection.h src/main.h src/types.h src/ui/app.h \
|
main.o: src/main.c src/connection.h src/main.h src/types.h src/ui/app.h \
|
||||||
src/ui/../common.h src/ui/widget.h src/ui/../main.h \
|
src/ui/../common.h src/ui/widget.h src/ui/../main.h \
|
||||||
|
|||||||
+7
-15
@@ -15,6 +15,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "file_processor.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "ui/widget/dialogue.h"
|
#include "ui/widget/dialogue.h"
|
||||||
@@ -25,8 +26,6 @@ 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);
|
||||||
|
|
||||||
static void clear_file_in_query(query_args_t *q_args);
|
|
||||||
|
|
||||||
void file_list(file_args_t *f_args, query_args_t *q_args) {
|
void file_list(file_args_t *f_args, query_args_t *q_args) {
|
||||||
uint32_t qlen;
|
uint32_t qlen;
|
||||||
char *query = NULL;
|
char *query = NULL;
|
||||||
@@ -229,7 +228,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* obsolete */
|
||||||
int32_t file_upload_request(char *query, query_args_t *q_args) {
|
int32_t file_upload_request(char *query, query_args_t *q_args) {
|
||||||
char qbuf[INBUFSIZE];
|
char qbuf[INBUFSIZE];
|
||||||
char fpath[512];
|
char fpath[512];
|
||||||
@@ -277,6 +276,7 @@ int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args) {
|
|||||||
strcpy(q_args->file->name, fname);
|
strcpy(q_args->file->name, fname);
|
||||||
q_args->file->size = fsize;
|
q_args->file->size = fsize;
|
||||||
q_args->file->rest = fsize;
|
q_args->file->rest = fsize;
|
||||||
|
q_args->file->description = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,13 +292,6 @@ 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 size_t it_int = 0;
|
|
||||||
static int it_count = 0;
|
|
||||||
|
|
||||||
if (it_int == 0) {
|
|
||||||
it_int = (q_args->file->size / INBUFSIZE / 100) * 10; // every 10%
|
|
||||||
} */
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -310,17 +303,16 @@ int32_t file_upload(query_args_t *q_args) {
|
|||||||
q_args->file->rest -= wlen;
|
q_args->file->rest -= wlen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* file upload is finished */
|
/* TODO: уведомление пользователю */
|
||||||
printf("Upload of %s is finished.\n", q_args->file->name);
|
|
||||||
/* TODO: ждать ответа от сервера */
|
|
||||||
clear_file_in_query(q_args);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_file_in_query(query_args_t *q_args) {
|
void clear_file_in_query(query_args_t *q_args) {
|
||||||
free(q_args->file->name);
|
free(q_args->file->name);
|
||||||
|
free(q_args->file->path);
|
||||||
|
free(q_args->file->description);
|
||||||
free(q_args->file);
|
free(q_args->file);
|
||||||
q_args->file = NULL;
|
q_args->file = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ int file_upload(query_args_t *q_args);
|
|||||||
int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args);
|
int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args);
|
||||||
void fl_clear(fl_item_t **start, fl_item_t **arg_current);
|
void fl_clear(fl_item_t **start, fl_item_t **arg_current);
|
||||||
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx);
|
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx);
|
||||||
|
void clear_file_in_query(query_args_t *q_args);
|
||||||
#endif
|
#endif
|
||||||
+3
-1
@@ -71,8 +71,10 @@ int32_t process_user_input(app_t *app, callback_args_t *d_args) {
|
|||||||
return OK;
|
return OK;
|
||||||
case 'U':
|
case 'U':
|
||||||
case 'u':
|
case 'u':
|
||||||
app->query_args->state = S_UPLOAD_FILE;
|
if (!app->modal.is_initiated) {
|
||||||
|
app->query_args->state = S_UPLOAD_FILE_SELECT;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
d_args->data = (void *)&c;
|
d_args->data = (void *)&c;
|
||||||
app->active_callback(d_args);
|
app->active_callback(d_args);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ enum state {
|
|||||||
S_FILE_DOWNLOAD,
|
S_FILE_DOWNLOAD,
|
||||||
S_UPLOAD_PARAMS,
|
S_UPLOAD_PARAMS,
|
||||||
S_UPLOAD_FILE,
|
S_UPLOAD_FILE,
|
||||||
|
S_UPLOAD_FILE_SELECT,
|
||||||
S_UPLOAD_REQUESTED,
|
S_UPLOAD_REQUESTED,
|
||||||
S_ASK_USER_BEFORE_LOGIN,
|
S_ASK_USER_BEFORE_LOGIN,
|
||||||
S_ERR,
|
S_ERR,
|
||||||
@@ -53,6 +54,7 @@ enum state {
|
|||||||
typedef struct p_file {
|
typedef struct p_file {
|
||||||
char *name;
|
char *name;
|
||||||
char *path;
|
char *path;
|
||||||
|
char *description;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t rest;
|
size_t rest;
|
||||||
int fd;
|
int fd;
|
||||||
|
|||||||
+5
-29
@@ -163,7 +163,6 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
|||||||
if (!file_upload_start(query_args)) {
|
if (!file_upload_start(query_args)) {
|
||||||
query_args->state = S_UPLOAD_FILE;
|
query_args->state = S_UPLOAD_FILE;
|
||||||
} else {
|
} else {
|
||||||
print_prompt(query_args->params);
|
|
||||||
query_args->state = WAIT_CLIENT;
|
query_args->state = WAIT_CLIENT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -172,8 +171,8 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
|||||||
if (file_upload(query_args)) {
|
if (file_upload(query_args)) {
|
||||||
/* upload finishes */
|
/* upload finishes */
|
||||||
user_request_description(query_args);
|
user_request_description(query_args);
|
||||||
print_prompt(query_args->params);
|
clear_file_in_query(query_args);
|
||||||
query_args->state = WAIT_CLIENT;
|
query_args->state = S_WAIT_SERVER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_ASK_USER_BEFORE_LOGIN:
|
case S_ASK_USER_BEFORE_LOGIN:
|
||||||
@@ -266,30 +265,7 @@ void init_query_args(query_args_t *q_args, params_t *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void user_request_description(query_args_t *q_args) {
|
void user_request_description(query_args_t *q_args) {
|
||||||
printf("File description > ");
|
strcat(q_args->file->description, "\n\n:END:\n");
|
||||||
fflush(stdout);
|
write(q_args->sd, q_args->file->description,
|
||||||
char buf[INBUFSIZE]; /* пока ограничение на буфер */
|
strlen(q_args->file->description)-1);
|
||||||
char *line_buf = NULL;
|
|
||||||
int blen = 0;
|
|
||||||
int line_len = 0;
|
|
||||||
size_t ll;
|
|
||||||
while (blen < INBUFSIZE - 6) { /* reserve space for ":END:\n" */
|
|
||||||
line_len = getline(&line_buf, &ll, stdin);
|
|
||||||
if (line_len == 1) {
|
|
||||||
/* free(line); -> не работает */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (blen == 0) {
|
|
||||||
strcpy(buf, line_buf);
|
|
||||||
} else {
|
|
||||||
strcat(buf, line_buf);
|
|
||||||
}
|
|
||||||
free(line_buf);
|
|
||||||
line_buf = NULL;
|
|
||||||
blen += line_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(buf, ":END:\n");
|
|
||||||
blen += 6;
|
|
||||||
write(q_args->sd, buf, blen);
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -157,7 +157,7 @@ void app_draw_modal(app_t *app) {
|
|||||||
case S_FILE_DOWNLOAD:
|
case S_FILE_DOWNLOAD:
|
||||||
init_dwn_pr_modal(app);
|
init_dwn_pr_modal(app);
|
||||||
break;
|
break;
|
||||||
case S_UPLOAD_FILE:
|
case S_UPLOAD_FILE_SELECT:
|
||||||
init_upload_dialogue_modal(app);
|
init_upload_dialogue_modal(app);
|
||||||
break;
|
break;
|
||||||
case S_UPLOAD_PARAMS:
|
case S_UPLOAD_PARAMS:
|
||||||
@@ -176,6 +176,7 @@ 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 {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void upload_dialogue_modal_cb(callback_args_t *args) {
|
void upload_dialogue_modal_cb(callback_args_t *args) {
|
||||||
int32_t response;
|
int32_t response = -1;
|
||||||
callback_args_t d_args;
|
callback_args_t d_args;
|
||||||
app_t *app = args->app;
|
app_t *app = args->app;
|
||||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "../app.h"
|
#include "../app.h"
|
||||||
#include "../widget/dialogue.h"
|
#include "../widget/dialogue.h"
|
||||||
#include "../widget/fs_file_list.h"
|
|
||||||
#include "../widget/group.h"
|
#include "../widget/group.h"
|
||||||
|
#include "../widget/input.h"
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -10,8 +10,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void upload_props_dialogue_modal_cb(callback_args_t *args) {
|
void upload_props_dialogue_modal_cb(callback_args_t *args) {
|
||||||
/* TODO: finish */
|
int32_t response = -1;
|
||||||
int32_t response;
|
|
||||||
callback_args_t d_args;
|
callback_args_t d_args;
|
||||||
app_t *app = args->app;
|
app_t *app = args->app;
|
||||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||||
@@ -22,9 +21,21 @@ void upload_props_dialogue_modal_cb(callback_args_t *args) {
|
|||||||
dialogue_default_callback(&d_args);
|
dialogue_default_callback(&d_args);
|
||||||
char query[256];
|
char query[256];
|
||||||
int32_t query_len = 0;
|
int32_t query_len = 0;
|
||||||
|
input_t *desc_input = (input_t *)d->g_content->elements[0].element;
|
||||||
if (response > -1) {
|
if (response > -1) {
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 0:
|
case 0:
|
||||||
|
query_len =
|
||||||
|
sprintf(query, "file upload \"%s\" %zu 1\n",
|
||||||
|
app->query_args->file->name, app->query_args->file->size);
|
||||||
|
app->query_args->file->description =
|
||||||
|
malloc(desc_input->value_len + 9); /* reserve space for \n:END:\n */
|
||||||
|
strcpy(app->query_args->file->description, desc_input->value);
|
||||||
|
destroy_dialogue(d, app);
|
||||||
|
app->query_args->state = S_UPLOAD_REQUESTED;
|
||||||
|
write(app->query_args->sd, query, query_len);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
if (app->query_args->file->name != NULL)
|
if (app->query_args->file->name != NULL)
|
||||||
free(app->query_args->file->name);
|
free(app->query_args->file->name);
|
||||||
if (app->query_args->file->path != NULL)
|
if (app->query_args->file->path != NULL)
|
||||||
@@ -33,12 +44,6 @@ void upload_props_dialogue_modal_cb(callback_args_t *args) {
|
|||||||
app->query_args->file = NULL;
|
app->query_args->file = NULL;
|
||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
break;
|
break;
|
||||||
case 1:
|
|
||||||
query_len = sprintf(query, "file upload \"%s\" %zu 1\n", app->query_args->file->name, app->query_args->file->size);
|
|
||||||
destroy_dialogue(d, app);
|
|
||||||
app->query_args->state = S_UPLOAD_REQUESTED;
|
|
||||||
write(app->query_args->sd, query, query_len+1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +56,10 @@ dialogue_t *init_upload_props_dialogue_modal(app_t *app) {
|
|||||||
{.type = w_end}};
|
{.type = w_end}};
|
||||||
|
|
||||||
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 = "Upload", .is_default = 1},
|
||||||
|
{.type = w_button, .label = "Cancel", .is_default = 0},
|
||||||
|
{.type = w_end},
|
||||||
|
};
|
||||||
|
|
||||||
app->modal.w.parent_win = &app->win;
|
app->modal.w.parent_win = &app->win;
|
||||||
init_dialogue(&(app->modal), "Description for the file",
|
init_dialogue(&(app->modal), "Description for the file",
|
||||||
|
|||||||
Reference in New Issue
Block a user