mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2025-01-01 06:23:38 +01:00
jfileselect: visualize errors
This commit is contained in:
parent
ef71bc11c0
commit
bea113f09e
2 changed files with 38 additions and 16 deletions
|
@ -30,6 +30,8 @@ typedef struct {
|
||||||
void *entries;
|
void *entries;
|
||||||
/* Number of entries in the current folder */
|
/* Number of entries in the current folder */
|
||||||
int entry_count;
|
int entry_count;
|
||||||
|
/* Error code for loaded folder */
|
||||||
|
int folder_error;
|
||||||
|
|
||||||
/* Full path to file last selected with EXE */
|
/* Full path to file last selected with EXE */
|
||||||
char *selected_file;
|
char *selected_file;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/* Type identifier for jfileselect */
|
/* Type identifier for jfileselect */
|
||||||
|
@ -52,6 +53,7 @@ jfileselect *jfileselect_create(void *parent)
|
||||||
fs->path = NULL;
|
fs->path = NULL;
|
||||||
fs->entries = NULL;
|
fs->entries = NULL;
|
||||||
fs->entry_count = 0;
|
fs->entry_count = 0;
|
||||||
|
fs->folder_error = 0;
|
||||||
|
|
||||||
fs->selected_file = NULL;
|
fs->selected_file = NULL;
|
||||||
fs->saveas_input = input;
|
fs->saveas_input = input;
|
||||||
|
@ -215,11 +217,15 @@ static int compare_entries(void const *i1_0, void const *i2_0)
|
||||||
static bool load_folder_switch(jfileselect *fs, char *path)
|
static bool load_folder_switch(jfileselect *fs, char *path)
|
||||||
{
|
{
|
||||||
set_finfo(fs, NULL, 0);
|
set_finfo(fs, NULL, 0);
|
||||||
|
free(fs->path);
|
||||||
|
fs->path = path;
|
||||||
|
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
DIR *dp = opendir(path);
|
DIR *dp = opendir(path);
|
||||||
if(!dp)
|
if(!dp) {
|
||||||
|
fs->folder_error = errno;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Count entries */
|
/* Count entries */
|
||||||
int n = count_accepted_entries(fs, dp) + fs->saveas;
|
int n = count_accepted_entries(fs, dp) + fs->saveas;
|
||||||
|
@ -228,6 +234,7 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
||||||
struct fileinfo *finfo = malloc(n * sizeof *finfo);
|
struct fileinfo *finfo = malloc(n * sizeof *finfo);
|
||||||
if(n && !finfo) {
|
if(n && !finfo) {
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
fs->folder_error = errno;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +253,7 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
||||||
for(int j = 0; j < i; j++) free(finfo[j].name);
|
for(int j = 0; j < i; j++) free(finfo[j].name);
|
||||||
free(finfo);
|
free(finfo);
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
fs->folder_error = errno;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +265,9 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
||||||
finfo[i].size = count_accepted_entries(fs, sub);
|
finfo[i].size = count_accepted_entries(fs, sub);
|
||||||
closedir(sub);
|
closedir(sub);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
finfo[i].size = -errno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -278,18 +289,20 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
||||||
qsort(finfo, n, sizeof *finfo, compare_entries);
|
qsort(finfo, n, sizeof *finfo, compare_entries);
|
||||||
|
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
free(fs->path);
|
|
||||||
fs->path = path;
|
|
||||||
set_finfo(fs, finfo, n);
|
set_finfo(fs, finfo, n);
|
||||||
fs->widget.update = true;
|
fs->folder_error = 0;
|
||||||
|
|
||||||
jwidget_emit(fs, (jevent){ .type = JFILESELECT_LOADED });
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_folder(jfileselect *fs, char *path)
|
static bool load_folder(jfileselect *fs, char *path)
|
||||||
{
|
{
|
||||||
return gint_world_switch(GINT_CALL(load_folder_switch, (void *)fs, path));
|
bool ok =
|
||||||
|
gint_world_switch(GINT_CALL(load_folder_switch, (void *)fs, path));
|
||||||
|
|
||||||
|
fs->widget.update = true;
|
||||||
|
jwidget_emit(fs, (jevent){ .type = JFILESELECT_LOADED });
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jfileselect_browse(jfileselect *fs, char const *path)
|
bool jfileselect_browse(jfileselect *fs, char const *path)
|
||||||
|
@ -298,8 +311,7 @@ bool jfileselect_browse(jfileselect *fs, char const *path)
|
||||||
if(!path_copy)
|
if(!path_copy)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!load_folder(fs, path_copy))
|
bool ok = load_folder(fs, path_copy);
|
||||||
return false;
|
|
||||||
|
|
||||||
free(fs->selected_file);
|
free(fs->selected_file);
|
||||||
fs->selected_file = NULL;
|
fs->selected_file = NULL;
|
||||||
|
@ -307,7 +319,7 @@ bool jfileselect_browse(jfileselect *fs, char const *path)
|
||||||
fs->cursor = 0;
|
fs->cursor = 0;
|
||||||
fs->scroll = 0;
|
fs->scroll = 0;
|
||||||
stop_input(fs);
|
stop_input(fs);
|
||||||
return true;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
char const *jfileselect_selected_file(jfileselect *fs)
|
char const *jfileselect_selected_file(jfileselect *fs)
|
||||||
|
@ -362,14 +374,18 @@ static void jfileselect_poly_layout(void *fs0)
|
||||||
static void generate_info_string(char *str, bool isfolder, int size)
|
static void generate_info_string(char *str, bool isfolder, int size)
|
||||||
{
|
{
|
||||||
#ifdef FX9860G
|
#ifdef FX9860G
|
||||||
if(isfolder)
|
if(size < 0)
|
||||||
|
sprintf(str, "E%d", -size);
|
||||||
|
else if(isfolder)
|
||||||
sprintf(str, "%d/", size);
|
sprintf(str, "%d/", size);
|
||||||
else if(size < 10000) /* 10 kB */
|
else if(size < 10000) /* 10 kB */
|
||||||
sprintf(str, "%d", size);
|
sprintf(str, "%d", size);
|
||||||
else
|
else
|
||||||
sprintf(str, "%dk", size / 1000);
|
sprintf(str, "%dk", size / 1000);
|
||||||
#else
|
#else
|
||||||
if(isfolder)
|
if(size < 0)
|
||||||
|
sprintf(str, "E%d", -size);
|
||||||
|
else if(isfolder)
|
||||||
sprintf(str, "%d entries", size);
|
sprintf(str, "%d entries", size);
|
||||||
else
|
else
|
||||||
sprintf(str, "%d B", size);
|
sprintf(str, "%d B", size);
|
||||||
|
@ -379,8 +395,6 @@ static void generate_info_string(char *str, bool isfolder, int size)
|
||||||
static void jfileselect_poly_render(void *fs0, int x, int y)
|
static void jfileselect_poly_render(void *fs0, int x, int y)
|
||||||
{
|
{
|
||||||
jfileselect *fs = fs0;
|
jfileselect *fs = fs0;
|
||||||
if(!fs->path)
|
|
||||||
return;
|
|
||||||
|
|
||||||
font_t const *old_font = dfont(fs->font);
|
font_t const *old_font = dfont(fs->font);
|
||||||
int line_height = fs->font->line_height + fs->line_spacing;
|
int line_height = fs->font->line_height + fs->line_spacing;
|
||||||
|
@ -393,9 +407,15 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
||||||
&& fs->scrollbar_width > 0;
|
&& fs->scrollbar_width > 0;
|
||||||
int entry_width = cw - (scrollbar ? 2 * fs->scrollbar_width : 0);
|
int entry_width = cw - (scrollbar ? 2 * fs->scrollbar_width : 0);
|
||||||
|
|
||||||
|
if(fs->folder_error) {
|
||||||
|
int text_y = y + (fs->line_spacing + 0) / 2;
|
||||||
|
dprint(x, text_y, C_BLACK, "(E%d)", fs->folder_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!fs->entries || fs->entry_count == 0) {
|
if(!fs->entries || fs->entry_count == 0) {
|
||||||
int text_y = y + (fs->line_spacing + 0) / 2;
|
int text_y = y + (fs->line_spacing + 0) / 2;
|
||||||
dprint(x+2, text_y, C_BLACK, "(No entries)");
|
dprint(x, text_y, C_BLACK, "(No entries)");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < fs->visible_lines && i < fs->entry_count; i++) {
|
for(int i = 0; i < fs->visible_lines && i < fs->entry_count; i++) {
|
||||||
|
@ -422,7 +442,7 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
dprint(x+2, text_y, fg, "%s%s", info->name, isfolder ? "/" : "");
|
dprint(x+2, text_y, fg, "%s%s", info->name, isfolder ? "/" : "");
|
||||||
if(fs->show_file_size && info->size >= 0) {
|
if(fs->show_file_size) {
|
||||||
char str[32];
|
char str[32];
|
||||||
generate_info_string(str, isfolder, info->size);
|
generate_info_string(str, isfolder, info->size);
|
||||||
dtext_opt(x + entry_width - 3, text_y, fg, C_NONE, DTEXT_RIGHT,
|
dtext_opt(x + entry_width - 3, text_y, fg, C_NONE, DTEXT_RIGHT,
|
||||||
|
|
Loading…
Reference in a new issue