ui: selection of upload file (needs next step realization)
This commit is contained in:
+5
-1
@@ -13,6 +13,9 @@
|
|||||||
#define DIALOGUE_TITLE 64
|
#define DIALOGUE_TITLE 64
|
||||||
#define DIALOGUE_TEXT 4096
|
#define DIALOGUE_TEXT 4096
|
||||||
#define INPUT_TEXT DIALOGUE_TITLE
|
#define INPUT_TEXT DIALOGUE_TITLE
|
||||||
|
#ifndef __USE_GNU
|
||||||
|
#define __USE_GNU 1
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct params {
|
typedef struct params {
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
@@ -49,6 +52,7 @@ enum state {
|
|||||||
|
|
||||||
typedef struct p_file {
|
typedef struct p_file {
|
||||||
char *name;
|
char *name;
|
||||||
|
char *path;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t rest;
|
size_t rest;
|
||||||
int fd;
|
int fd;
|
||||||
@@ -83,7 +87,7 @@ typedef struct query_args {
|
|||||||
uint64_t capacity;
|
uint64_t capacity;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
} 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 void pointers */
|
||||||
void *progress_bar;
|
void *progress_bar;
|
||||||
void *active_dialogue;
|
void *active_dialogue;
|
||||||
char *notification;
|
char *notification;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#include "../app.h"
|
#include "../app.h"
|
||||||
#include "../widget/dialogue.h"
|
#include "../widget/dialogue.h"
|
||||||
#include "../widget/group.h"
|
#include "../widget/group.h"
|
||||||
|
#include "../widget/fs_file_list.h"
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void upload_dialogue_modal_cb(callback_args_t *args) {
|
void upload_dialogue_modal_cb(callback_args_t *args) {
|
||||||
@@ -15,12 +18,19 @@ void upload_dialogue_modal_cb(callback_args_t *args) {
|
|||||||
d_args.resp_data = &response;
|
d_args.resp_data = &response;
|
||||||
d_args.element = app->active_widget;
|
d_args.element = app->active_widget;
|
||||||
dialogue_default_callback(&d_args);
|
dialogue_default_callback(&d_args);
|
||||||
|
ui_fs_file_list_t *fui = (ui_fs_file_list_t *) d->g_content->elements[0].element;
|
||||||
if (response > -1) {
|
if (response > -1) {
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 0:
|
case 0:
|
||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
app->query_args->file = malloc(sizeof(p_file_t));
|
||||||
|
app->query_args->file->path = malloc(strlen(fui->d_path) + strlen(fui->current->name) + 2);
|
||||||
|
strcpy(app->query_args->file->path, fui->current->name);
|
||||||
|
sprintf(app->query_args->file->path, "%s/%s", fui->d_path, fui->current->name);
|
||||||
|
destroy_dialogue(d, app);
|
||||||
|
app->query_args->state = S_UPLOAD_PARAMS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +45,7 @@ dialogue_t *init_upload_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_button, .label = "Cancel", .is_default = 0}, {.type = w_end}};
|
||||||
{.type = w_end}};
|
|
||||||
|
|
||||||
app->modal.w.parent_win = &app->win;
|
app->modal.w.parent_win = &app->win;
|
||||||
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
|
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "fs_file_list.h"
|
#include "fs_file_list.h"
|
||||||
#include "progress_bar.h"
|
#include "progress_bar.h"
|
||||||
|
#include "../app.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
@@ -79,22 +80,39 @@ fs_fl_item_t *get_files_from_fs(char *path) {
|
|||||||
fl_add(&f_start, &f_current, &f_args);
|
fl_add(&f_start, &f_current, &f_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d_current != NULL) d_current->next = f_start;
|
if (d_current != NULL)
|
||||||
if (f_start != NULL) f_start->prev = d_current;
|
d_current->next = f_start;
|
||||||
|
if (f_start != NULL)
|
||||||
|
f_start->prev = d_current;
|
||||||
return d_start;
|
return d_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_item(ui_fs_file_list_t *fui) {
|
void select_item(ui_fs_file_list_t *fui, int32_t *resp_data) {
|
||||||
char d_name[64] = "./";
|
char *bash_case = NULL;
|
||||||
|
char *selection = NULL;
|
||||||
|
size_t dp_current;
|
||||||
if (fui->current->d_type == DT_DIR) {
|
if (fui->current->d_type == DT_DIR) {
|
||||||
if (!strcmp("/..", fui->current->name)) {
|
if (!strcmp("/..", fui->current->name)) {
|
||||||
/* TODO: slice the last "/abc" */
|
bash_case = strrchr(fui->d_path, '/');
|
||||||
|
if (bash_case != NULL) {
|
||||||
|
*bash_case = '\0';
|
||||||
|
fl_clear(&(fui->start), &(fui->current));
|
||||||
|
fui->start = get_files_from_fs(fui->d_path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
strcat(d_name, fui->current->name + 1); /* skip "/" in the name */
|
dp_current = strlen(fui->d_path);
|
||||||
|
selection = fui->current->name + 1;
|
||||||
|
fui->d_path =
|
||||||
|
realloc(fui->d_path, dp_current + strlen(selection) + 2);
|
||||||
|
sprintf(fui->d_path, "%s/%s", fui->d_path, selection);
|
||||||
|
fl_clear(&(fui->start), &(fui->current));
|
||||||
|
fui->start = get_files_from_fs(fui->d_path);
|
||||||
}
|
}
|
||||||
fui->start = get_files_from_fs(d_name);
|
|
||||||
fui->current = fui->start;
|
fui->current = fui->start;
|
||||||
|
fui->current_idx = 0;
|
||||||
draw_fs_file_list(fui);
|
draw_fs_file_list(fui);
|
||||||
|
} else if (fui->current->d_type == DT_REG) {
|
||||||
|
*resp_data = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +138,7 @@ void fs_file_list_cb(callback_args_t *args) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
select_item(fui);
|
select_item(fui, (int32_t *) args->resp_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +149,8 @@ ui_fs_file_list_t *init_fs_file_list(WINDOW **win, widget_t *w_parent) {
|
|||||||
init_widget(&(fl_ui->w), w_parent, win, "");
|
init_widget(&(fl_ui->w), w_parent, win, "");
|
||||||
fl_ui->current_idx = 0;
|
fl_ui->current_idx = 0;
|
||||||
fl_ui->info_win = NULL;
|
fl_ui->info_win = NULL;
|
||||||
fl_ui->start = get_files_from_fs("./");
|
fl_ui->d_path = get_current_dir_name();
|
||||||
|
fl_ui->start = get_files_from_fs(fl_ui->d_path);
|
||||||
fl_ui->current = fl_ui->start;
|
fl_ui->current = fl_ui->start;
|
||||||
fl_ui->w.callback = fs_file_list_cb;
|
fl_ui->w.callback = fs_file_list_cb;
|
||||||
fl_ui->w.x = getmaxx(win_par) / 10 * 8;
|
fl_ui->w.x = getmaxx(win_par) / 10 * 8;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ typedef struct {
|
|||||||
fs_fl_item_t *start;
|
fs_fl_item_t *start;
|
||||||
int32_t current_idx;
|
int32_t current_idx;
|
||||||
WINDOW *const* info_win;
|
WINDOW *const* info_win;
|
||||||
char d_path[512];
|
char *d_path;
|
||||||
} ui_fs_file_list_t;
|
} ui_fs_file_list_t;
|
||||||
|
|
||||||
void draw_fs_file_list(ui_fs_file_list_t *fl_ui);
|
void draw_fs_file_list(ui_fs_file_list_t *fl_ui);
|
||||||
|
|||||||
Reference in New Issue
Block a user