updates file list->fl_clear, gets rid of **current and **start pointers in w_ui_file_list_t
This commit is contained in:
+19
-20
@@ -27,7 +27,10 @@
|
|||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
||||||
static void fl_add(dlist_t *fl_list, char *q_line);
|
static void fl_add(dlist_t *fl_list, char *q_line);
|
||||||
void fl_clear(fl_item_t **start, fl_item_t **current);
|
static bool fl_rm_cb(void *_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
void fl_clear(dlist_t *dlist) { dlist_clear_list(dlist, fl_rm_cb); }
|
||||||
|
|
||||||
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) {
|
||||||
int32_t qlen;
|
int32_t qlen;
|
||||||
@@ -68,7 +71,8 @@ void file_list(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
|
|
||||||
static bool fl_add_cb(void *_dst, void *_src);
|
static bool fl_add_cb(void *_dst, void *_src);
|
||||||
|
|
||||||
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *l_selected) {
|
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args,
|
||||||
|
fl_item_t *l_selected) {
|
||||||
fl_item_t *f_selected =
|
fl_item_t *f_selected =
|
||||||
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
@@ -89,7 +93,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *l_s
|
|||||||
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->f_list);
|
||||||
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) {
|
||||||
server_send_string(q_args, "error: %s\n", f_selected->name);
|
server_send_string(q_args, "error: %s\n", f_selected->name);
|
||||||
@@ -378,6 +382,18 @@ static bool fl_add_cb(void *_dst, void *_src) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool fl_rm_cb(void *_ptr) {
|
||||||
|
fl_item_t *ptr = _ptr;
|
||||||
|
if (ptr->description != NULL)
|
||||||
|
free(ptr->description);
|
||||||
|
if (ptr->name != NULL)
|
||||||
|
free(ptr->name);
|
||||||
|
if (ptr->owner != NULL)
|
||||||
|
free(ptr->owner);
|
||||||
|
free(ptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* work with file list */
|
/* work with file list */
|
||||||
static void fl_add(dlist_t *fl_list, char *q_line) {
|
static void fl_add(dlist_t *fl_list, char *q_line) {
|
||||||
fl_item_t f_item;
|
fl_item_t f_item;
|
||||||
@@ -392,21 +408,4 @@ static void fl_add(dlist_t *fl_list, char *q_line) {
|
|||||||
fl_q_extract(&f_item, q_line);
|
fl_q_extract(&f_item, q_line);
|
||||||
|
|
||||||
dlist_add(fl_list, &f_item, fl_item_t, fl_add_cb, false);
|
dlist_add(fl_list, &f_item, fl_item_t, fl_add_cb, false);
|
||||||
}
|
|
||||||
|
|
||||||
void fl_clear(fl_item_t **start, fl_item_t **arg_current) {
|
|
||||||
if (*start == NULL)
|
|
||||||
return;
|
|
||||||
fl_item_t *next, *current;
|
|
||||||
current = *start;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (current->description != NULL) {
|
|
||||||
free(current->description);
|
|
||||||
}
|
|
||||||
free(current->name);
|
|
||||||
free(current);
|
|
||||||
} while ((current = next) != NULL);
|
|
||||||
*start = NULL;
|
|
||||||
*arg_current = NULL;
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ int file_upload_request(char *, query_args_t *q_args);
|
|||||||
int file_upload_start(query_args_t *q_args);
|
int file_upload_start(query_args_t *q_args);
|
||||||
int file_upload(query_args_t *q_args);
|
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(dlist_t *dlist);
|
||||||
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *ptr);
|
int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *ptr);
|
||||||
void clear_file_in_query(query_args_t *q_args);
|
void clear_file_in_query(query_args_t *q_args);
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -2,10 +2,10 @@
|
|||||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||||
|
|
||||||
#include "file_list.h"
|
#include "file_list.h"
|
||||||
|
#include "main_window.h"
|
||||||
|
#include "dlist.h"
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
#include "dlist.h"
|
|
||||||
#include "main_window.h"
|
|
||||||
#include <bstrlib.h>
|
#include <bstrlib.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -216,13 +216,13 @@ void *w_fl_init(app_t *app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void w_fl_destroy(w_ui_file_list_t **fui) {
|
void w_fl_destroy(w_ui_file_list_t **fui) {
|
||||||
fl_clear((*fui)->start, (*fui)->current);
|
fl_clear((*fui)->f_list);
|
||||||
free(*fui);
|
free(*fui);
|
||||||
*fui = NULL;
|
*fui = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void w_fl_reset(w_ui_file_list_t *fl_ui) {
|
void w_fl_reset(w_ui_file_list_t *fl_ui) {
|
||||||
fl_clear(fl_ui->start, fl_ui->current);
|
fl_clear(fl_ui->f_list);
|
||||||
fl_ui->current_idx = 0;
|
fl_ui->current_idx = 0;
|
||||||
fl_ui->current_page = 0;
|
fl_ui->current_page = 0;
|
||||||
fl_ui->pages = 0;
|
fl_ui->pages = 0;
|
||||||
@@ -256,11 +256,6 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
|||||||
int32_t cur_el_idx = 0;
|
int32_t cur_el_idx = 0;
|
||||||
box(fui->win_list, 0, 0);
|
box(fui->win_list, 0, 0);
|
||||||
|
|
||||||
if (fui->start != NULL) {
|
|
||||||
el = *(fui->start);
|
|
||||||
active_el = el;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fui->activate_last) {
|
if (fui->activate_last) {
|
||||||
fui->current_idx = fui->max_lines - 1;
|
fui->current_idx = fui->max_lines - 1;
|
||||||
fui->activate_last = false;
|
fui->activate_last = false;
|
||||||
@@ -297,7 +292,7 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
|||||||
int32_t p_len;
|
int32_t p_len;
|
||||||
|
|
||||||
if (!fui->active_search && fui->search_key->slen > 0 &&
|
if (!fui->active_search && fui->search_key->slen > 0 &&
|
||||||
*(fui->start) == NULL) {
|
fui->f_list->start == NULL) {
|
||||||
bstring text = bfromStatic("[No data to show]");
|
bstring text = bfromStatic("[No data to show]");
|
||||||
for (; p_y < (sz_y_f / 2); p_y++) {
|
for (; p_y < (sz_y_f / 2); p_y++) {
|
||||||
mvwprintw(win, p_y, p_x, "%*s", sz_x - 1, "");
|
mvwprintw(win, p_y, p_x, "%*s", sz_x - 1, "");
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
w_t w;
|
w_t w;
|
||||||
fl_item_t **current;
|
|
||||||
fl_item_t **start;
|
|
||||||
dlist_t *f_list;
|
dlist_t *f_list;
|
||||||
dlist_node_t *f_selected;
|
dlist_node_t *f_selected;
|
||||||
int32_t current_idx;
|
int32_t current_idx;
|
||||||
|
|||||||
Reference in New Issue
Block a user