plugins: properties: use UI viewport for displaying progress

Prevent switching to a fullscreen view when scanning
a directory, which could be a bit jarring, depending
on your theme of choice.

Also pop context menu activity immediately, without
refreshing, so it isn't redrawn when returning from
plugin.

Change-Id: I021e5880505e7f121163851ae732eb47509cc5d8
This commit is contained in:
Christian Soffke 2024-07-26 20:16:56 +02:00
parent 545271c4de
commit 70b96193e7
3 changed files with 88 additions and 80 deletions

View file

@ -806,6 +806,10 @@ static bool onplay_load_plugin(void *param)
if (!prepare_database_sel(param)) if (!prepare_database_sel(param))
return false; return false;
#endif #endif
if (get_current_activity() == ACTIVITY_CONTEXTMENU) /* get rid of parent activity */
pop_current_activity_without_refresh(); /* when called from ctxt menu */
int ret = filetype_load_plugin((const char*)param, selected_file.path); int ret = filetype_load_plugin((const char*)param, selected_file.path);
if (ret == PLUGIN_USB_CONNECTED) if (ret == PLUGIN_USB_CONNECTED)
onplay_result = ONPLAY_RELOAD_DIR; onplay_result = ONPLAY_RELOAD_DIR;

View file

@ -196,52 +196,45 @@ static const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
/* and videos */ /* and videos */
static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"}; static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
static void prn(const char *str, int y) static void display_dir_stats_vp(struct dir_stats *stats, struct viewport *vp,
struct screen *display)
{ {
rb->lcd_puts(0, y, str); static bool initialized;
#ifdef HAVE_REMOTE_LCD int32_t lang_size_unit;
rb->lcd_remote_puts(0, y, str); unsigned long display_size = human_size(stats->byte_count, &lang_size_unit);
#endif struct viewport *last_vp = display->set_viewport(vp);
display->clear_viewport();
if (initialized)
{
display->putsf(0, 0, "Files: %d (%lu %s)", stats->file_count,
display_size, rb->str(lang_size_unit));
display->putsf(0, 1, "Audio: %d", stats->audio_file_count);
if (stats->count_all)
{
display->putsf(0, 2, "Playlists: %d", stats->m3u_file_count);
display->putsf(0, 3, "Images: %d", stats->img_file_count);
display->putsf(0, 4, "Videos: %d", stats->vid_file_count);
display->putsf(0, 5, "Directories: %d", stats->dir_count);
display->putsf(0, 6, "Max files in Dir: %d", stats->max_files_in_dir);
}
else
display->putsf(0, 2, "Directories: %d", stats->dir_count);
}
else
initialized = true;
display->update_viewport();
display->set_viewport(last_vp);
} }
void display_dir_stats(struct dir_stats *stats) void display_dir_stats(struct dir_stats *stats)
{ {
char buf[32]; struct viewport vps[NB_SCREENS];
int32_t lang_size_unit; FOR_NB_SCREENS(i)
unsigned long display_size = human_size(stats->byte_count, &lang_size_unit);
rb->lcd_clear_display();
#ifdef HAVE_REMOTE_LCD
rb->lcd_remote_clear_display();
#endif
rb->snprintf(buf, sizeof(buf), "Files: %d (%lu %s)", stats->file_count,
display_size, rb->str(lang_size_unit));
prn(buf, 0);
rb->snprintf(buf, sizeof(buf), "Audio: %d", stats->audio_file_count);
prn(buf, 1);
if (stats->count_all)
{ {
rb->snprintf(buf, sizeof(buf), "Playlists: %d", stats->m3u_file_count); rb->viewport_set_defaults(&vps[i], i);
prn(buf, 2); display_dir_stats_vp(stats, &vps[i], rb->screens[i]);
rb->snprintf(buf, sizeof(buf), "Images: %d", stats->img_file_count);
prn(buf, 3);
rb->snprintf(buf, sizeof(buf), "Videos: %d", stats->vid_file_count);
prn(buf, 4);
rb->snprintf(buf, sizeof(buf), "Directories: %d", stats->dir_count);
prn(buf, 5);
rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d",
stats->max_files_in_dir);
prn(buf, 6);
} }
else
{
rb->snprintf(buf, sizeof(buf), "Directories: %d", stats->dir_count);
prn(buf, 2);
}
rb->lcd_update();
#ifdef HAVE_REMOTE_LCD
rb->lcd_remote_update();
#endif
} }
/* Recursively scans directories in search of files /* Recursively scans directories in search of files
@ -281,7 +274,6 @@ bool collect_dir_stats(struct dir_stats *stats, bool (*id3_cb)(const char*))
stats->dir_count++; /* new directory */ stats->dir_count++; /* new directory */
if (*rb->current_tick - last_displayed > (HZ/2)) if (*rb->current_tick - last_displayed > (HZ/2))
{ {
if (last_displayed)
display_dir_stats(stats); display_dir_stats(stats);
last_displayed = *(rb->current_tick); last_displayed = *(rb->current_tick);
} }

View file

@ -35,6 +35,7 @@ enum props_types {
static int props_type; static int props_type;
static struct gui_synclist properties_lists;
static struct mp3entry id3; static struct mp3entry id3;
static int mul_id3_count; static int mul_id3_count;
static int skipped_count; static int skipped_count;
@ -53,7 +54,7 @@ static int32_t lang_size_unit;
static struct tm tm; static struct tm tm;
#define NUM_FILE_PROPERTIES 5 #define NUM_FILE_PROPERTIES 5
#define NUM_PLAYLIST_PROPERTIES 1 + NUM_FILE_PROPERTIES #define NUM_PLAYLIST_PROPERTIES (1 + NUM_FILE_PROPERTIES)
static const unsigned char* const props_file[] = static const unsigned char* const props_file[] =
{ {
ID2P(LANG_PROPERTIES_PATH), str_dirname, ID2P(LANG_PROPERTIES_PATH), str_dirname,
@ -66,7 +67,7 @@ static const unsigned char* const props_file[] =
}; };
#define NUM_DIR_PROPERTIES 4 #define NUM_DIR_PROPERTIES 4
#define NUM_AUDIODIR_PROPERTIES 1 + NUM_DIR_PROPERTIES #define NUM_AUDIODIR_PROPERTIES (1 + NUM_DIR_PROPERTIES)
static const unsigned char* const props_dir[] = static const unsigned char* const props_dir[] =
{ {
ID2P(LANG_PROPERTIES_PATH), str_dirname, ID2P(LANG_PROPERTIES_PATH), str_dirname,
@ -220,21 +221,15 @@ static int speak_property_selection(int selected_item, void *data)
return 0; return 0;
} }
static int browse_file_or_dir(struct dir_stats *stats) static void setup_properties_list(struct dir_stats *stats)
{ {
struct gui_synclist properties_lists; int nb_props;
int button, nb_items;
if (props_type == PROPS_FILE) if (props_type == PROPS_FILE)
nb_items = NUM_FILE_PROPERTIES; nb_props = NUM_FILE_PROPERTIES;
else if (props_type == PROPS_PLAYLIST) else if (props_type == PROPS_PLAYLIST)
nb_items = NUM_PLAYLIST_PROPERTIES; nb_props = NUM_PLAYLIST_PROPERTIES;
else if (stats->audio_file_count)
nb_items = NUM_AUDIODIR_PROPERTIES;
else else
nb_items = NUM_DIR_PROPERTIES; nb_props = NUM_DIR_PROPERTIES;
nb_items *= 2;
rb->gui_synclist_init(&properties_lists, &get_props, stats, false, 2, NULL); rb->gui_synclist_init(&properties_lists, &get_props, stats, false, 2, NULL);
rb->gui_synclist_set_title(&properties_lists, rb->gui_synclist_set_title(&properties_lists,
@ -242,19 +237,24 @@ static int browse_file_or_dir(struct dir_stats *stats)
LANG_PROPERTIES_DIRECTORY_PROPERTIES : LANG_PROPERTIES_DIRECTORY_PROPERTIES :
LANG_PROPERTIES_FILE_PROPERTIES), LANG_PROPERTIES_FILE_PROPERTIES),
NOICON); NOICON);
rb->gui_synclist_set_icon_callback(&properties_lists, NULL);
if (rb->global_settings->talk_menu) if (rb->global_settings->talk_menu)
rb->gui_synclist_set_voice_callback(&properties_lists, speak_property_selection); rb->gui_synclist_set_voice_callback(&properties_lists, speak_property_selection);
rb->gui_synclist_set_nb_items(&properties_lists, nb_items); rb->gui_synclist_set_nb_items(&properties_lists, nb_props*2);
rb->gui_synclist_select_item(&properties_lists, 0); }
static int browse_file_or_dir(struct dir_stats *stats)
{
int button;
if (props_type == PROPS_DIR && stats->audio_file_count)
rb->gui_synclist_set_nb_items(&properties_lists, NUM_AUDIODIR_PROPERTIES*2);
rb->gui_synclist_draw(&properties_lists); rb->gui_synclist_draw(&properties_lists);
rb->gui_synclist_speak_item(&properties_lists); rb->gui_synclist_speak_item(&properties_lists);
while(true) while(true)
{ {
button = rb->get_action(CONTEXT_LIST, HZ); button = rb->get_action(CONTEXT_LIST, HZ);
/* HZ so the status bar redraws corectly */ /* HZ so the status bar redraws corectly */
if (rb->gui_synclist_do_button(&properties_lists,&button)) if (rb->gui_synclist_do_button(&properties_lists, &button))
continue; continue;
switch(button) switch(button)
{ {
@ -356,12 +356,14 @@ static bool assemble_track_info(const char *filename, struct dir_stats *stats)
enum plugin_status plugin_start(const void* parameter) enum plugin_status plugin_start(const void* parameter)
{ {
int ret; int ret = 0;
static struct dir_stats stats; static struct dir_stats stats;
const char *file = parameter; const char *file = parameter;
if(!parameter) if(!parameter)
return PLUGIN_ERROR; return PLUGIN_ERROR;
FOR_NB_SCREENS(i)
rb->viewportmanager_theme_enable(i, true, NULL);
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN
rb->touchscreen_set_mode(rb->global_settings->touch_mode); rb->touchscreen_set_mode(rb->global_settings->touch_mode);
#endif #endif
@ -374,34 +376,44 @@ enum plugin_status plugin_start(const void* parameter)
if(!determine_file_or_dir()) if(!determine_file_or_dir())
{ {
/* weird: we couldn't find the entry. This Should Never Happen (TM) */
rb->splashf(0, "File/Dir not found: %s", file); rb->splashf(0, "File/Dir not found: %s", file);
rb->action_userabort(TIMEOUT_BLOCK); rb->action_userabort(TIMEOUT_BLOCK);
return PLUGIN_OK; goto exit;
} }
if (props_type == PROPS_FILE && has_pl_extension(file)) if (props_type == PROPS_FILE)
{
if (has_pl_extension(file))
props_type = PROPS_PLAYLIST; props_type = PROPS_PLAYLIST;
if(!(props_type == PROPS_DIR ? ret = !file_properties(file);
dir_properties(file, &stats, NULL) : file_properties(file))) }
if (props_type != PROPS_ID3) /* i.e. not handled by browse_id3 */
{ {
setup_properties_list(&stats); /* Show title during dir scan */
if (props_type == PROPS_DIR)
ret = !dir_properties(file, &stats, NULL);
}
if (ret)
{
ret = 0;
if (!stats.canceled) if (!stats.canceled)
{ {
/* something went wrong (to do: tell user what it was (nesting,...) */ /* TODO: describe error */
rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); rb->splash(0, ID2P(LANG_PROPERTIES_FAIL));
rb->action_userabort(TIMEOUT_BLOCK); rb->action_userabort(TIMEOUT_BLOCK);
} }
return PLUGIN_OK; goto exit;
} }
} }
/* database table selected */ /* database table selected */
else if (rb->strcmp(file, MAKE_ACT_STR(ACTIVITY_DATABASEBROWSER)) else if (rb->strcmp(file, MAKE_ACT_STR(ACTIVITY_DATABASEBROWSER))
|| !assemble_track_info(NULL, NULL)) || !assemble_track_info(NULL, NULL))
return PLUGIN_ERROR; {
ret = -1;
FOR_NB_SCREENS(i) goto exit;
rb->viewportmanager_theme_enable(i, true, NULL); }
if (props_type == PROPS_ID3) if (props_type == PROPS_ID3)
ret = rb->browse_id3(&id3, 0, 0, &tm, 1); /* Track Info for single file */ ret = rb->browse_id3(&id3, 0, 0, &tm, 1); /* Track Info for single file */
@ -411,7 +423,7 @@ enum plugin_status plugin_start(const void* parameter)
ret = assemble_track_info(file, &stats) ? /* playlist or folder tracks */ ret = assemble_track_info(file, &stats) ? /* playlist or folder tracks */
rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) : rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) :
(stats.canceled ? 0 : -1); (stats.canceled ? 0 : -1);
exit:
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
rb->viewportmanager_theme_undo(i, false); rb->viewportmanager_theme_undo(i, false);