ui: selection of upload file (needs next step realization)

This commit is contained in:
2026-01-20 15:17:40 +02:00
parent 167b5c635a
commit 83157a55f3
4 changed files with 45 additions and 13 deletions
+11 -2
View File
@@ -1,8 +1,11 @@
#include "../app.h"
#include "../widget/dialogue.h"
#include "../widget/group.h"
#include "../widget/fs_file_list.h"
#include <ncurses.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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.element = app->active_widget;
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) {
switch (response) {
case 0:
app->query_args->state = S_WAIT_SERVER;
break;
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;
}
}
@@ -35,8 +45,7 @@ dialogue_t *init_upload_dialogue_modal(app_t *app) {
{.type = w_end}};
group_el_init_t actions[] = {
{.type = w_button, .label = "Cancel", .is_default = 0},
{.type = w_end}};
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_end}};
app->modal.w.parent_win = &app->win;
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
+28 -9
View File
@@ -1,5 +1,6 @@
#include "fs_file_list.h"
#include "progress_bar.h"
#include "../app.h"
#include <dirent.h>
#include <errno.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);
}
}
if (d_current != NULL) d_current->next = f_start;
if (f_start != NULL) f_start->prev = d_current;
if (d_current != NULL)
d_current->next = f_start;
if (f_start != NULL)
f_start->prev = d_current;
return d_start;
}
void select_item(ui_fs_file_list_t *fui) {
char d_name[64] = "./";
void select_item(ui_fs_file_list_t *fui, int32_t *resp_data) {
char *bash_case = NULL;
char *selection = NULL;
size_t dp_current;
if (fui->current->d_type == DT_DIR) {
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 {
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_idx = 0;
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;
case '\n':
select_item(fui);
select_item(fui, (int32_t *) args->resp_data);
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, "");
fl_ui->current_idx = 0;
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->w.callback = fs_file_list_cb;
fl_ui->w.x = getmaxx(win_par) / 10 * 8;
+1 -1
View File
@@ -18,7 +18,7 @@ typedef struct {
fs_fl_item_t *start;
int32_t current_idx;
WINDOW *const* info_win;
char d_path[512];
char *d_path;
} ui_fs_file_list_t;
void draw_fs_file_list(ui_fs_file_list_t *fl_ui);