mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-12 14:42:31 -05:00
plugins: extract redundant functionality from stats/properties
Also: - Enables cpu boosting for Stats (*much* faster on some players) - Displays file size in Stats Change-Id: I888ba054e1f8c2985fbf8dca36e11e6ef130e7ca
This commit is contained in:
parent
6d19214eeb
commit
545271c4de
5 changed files with 252 additions and 337 deletions
|
|
@ -19,184 +19,27 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "plugin.h"
|
||||
#include "lib/pluginlib_actions.h"
|
||||
#include "lib/mul_id3.h" /* collect_dir_stats & display_dir_stats */
|
||||
|
||||
|
||||
static int files, dirs, audiofiles, m3ufiles, imagefiles, videofiles, largestdir;
|
||||
static int lasttick;
|
||||
static bool cancel;
|
||||
|
||||
|
||||
/* we use PLA */
|
||||
#define STATS_STOP PLA_EXIT
|
||||
|
||||
#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
|
||||
|| (CONFIG_KEYPAD == IPOD_3G_PAD) \
|
||||
|| (CONFIG_KEYPAD == IPOD_4G_PAD)
|
||||
#define STATS_STOP2 PLA_UP
|
||||
#else
|
||||
#define STATS_STOP2 PLA_CANCEL
|
||||
#endif
|
||||
|
||||
/* this set the context to use with PLA */
|
||||
static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
|
||||
|
||||
/* we don't have yet a filetype attribute for image files */
|
||||
static const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
|
||||
|
||||
/* neither for video ones */
|
||||
static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
|
||||
|
||||
static void prn(const char *str, int y)
|
||||
{
|
||||
rb->lcd_puts(0,y,str);
|
||||
#ifdef HAVE_REMOTE_LCD
|
||||
rb->lcd_remote_puts(0,y,str);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void update_screen(void)
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
rb->lcd_clear_display();
|
||||
#ifdef HAVE_REMOTE_LCD
|
||||
rb->lcd_remote_clear_display();
|
||||
#endif
|
||||
|
||||
rb->snprintf(buf, sizeof(buf), "Total Files: %d", files);
|
||||
prn(buf,0);
|
||||
rb->snprintf(buf, sizeof(buf), "Audio: %d", audiofiles);
|
||||
prn(buf,1);
|
||||
rb->snprintf(buf, sizeof(buf), "Playlists: %d", m3ufiles);
|
||||
prn(buf,2);
|
||||
rb->snprintf(buf, sizeof(buf), "Images: %d", imagefiles);
|
||||
prn(buf,3);
|
||||
rb->snprintf(buf, sizeof(buf), "Videos: %d", videofiles);
|
||||
prn(buf,4);
|
||||
rb->snprintf(buf, sizeof(buf), "Directories: %d", dirs);
|
||||
prn(buf,5);
|
||||
rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
|
||||
prn(buf,6);
|
||||
|
||||
rb->lcd_update();
|
||||
#ifdef HAVE_REMOTE_LCD
|
||||
rb->lcd_remote_update();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void traversedir(char* location, char* name)
|
||||
{
|
||||
int button;
|
||||
struct dirent *entry;
|
||||
DIR* dir;
|
||||
char fullpath[MAX_PATH];
|
||||
int files_in_dir = 0;
|
||||
|
||||
rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
|
||||
dir = rb->opendir(fullpath);
|
||||
if (dir) {
|
||||
entry = rb->readdir(dir);
|
||||
while (entry) {
|
||||
if (cancel)
|
||||
break;
|
||||
/* Skip .. and . */
|
||||
if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
|
||||
{
|
||||
struct dirinfo info = rb->dir_get_info(dir, entry);
|
||||
if (info.attribute & ATTR_DIRECTORY) {
|
||||
traversedir(fullpath, entry->d_name);
|
||||
dirs++;
|
||||
}
|
||||
else {
|
||||
files_in_dir++; files++;
|
||||
|
||||
/* get the filetype from the filename */
|
||||
int attr = rb->filetype_get_attr(entry->d_name);
|
||||
switch (attr & FILE_ATTR_MASK)
|
||||
{
|
||||
case FILE_ATTR_AUDIO:
|
||||
audiofiles++;
|
||||
break;
|
||||
|
||||
case FILE_ATTR_M3U:
|
||||
m3ufiles++;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
/* use hardcoded filetype_exts to count
|
||||
* image and video files until we get
|
||||
* new attributes added to filetypes.h */
|
||||
char *ptr = rb->strrchr(entry->d_name,'.');
|
||||
if(ptr) {
|
||||
unsigned i;
|
||||
ptr++;
|
||||
for(i=0;i<ARRAYLEN(image_exts);i++) {
|
||||
if(!rb->strcasecmp(ptr,image_exts[i])) {
|
||||
imagefiles++; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ARRAYLEN(image_exts)) {
|
||||
/* not found above - try video files */
|
||||
for(i=0;i<ARRAYLEN(video_exts);i++) {
|
||||
if(!rb->strcasecmp(ptr,video_exts[i])) {
|
||||
videofiles++; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* default: */
|
||||
} /* switch */
|
||||
}
|
||||
}
|
||||
|
||||
if (*rb->current_tick - lasttick > (HZ/2)) {
|
||||
update_screen();
|
||||
lasttick = *rb->current_tick;
|
||||
button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
|
||||
ARRAYLEN(plugin_contexts));
|
||||
if (button == STATS_STOP || button == STATS_STOP2) {
|
||||
cancel = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
entry = rb->readdir(dir);
|
||||
}
|
||||
rb->closedir(dir);
|
||||
}
|
||||
if (largestdir < files_in_dir)
|
||||
largestdir = files_in_dir;
|
||||
}
|
||||
|
||||
/* this is the plugin entry point */
|
||||
enum plugin_status plugin_start(const void* parameter)
|
||||
{
|
||||
int button;
|
||||
|
||||
{
|
||||
(void)parameter;
|
||||
|
||||
files = 0;
|
||||
dirs = 0;
|
||||
audiofiles = 0;
|
||||
m3ufiles = 0;
|
||||
imagefiles = 0;
|
||||
videofiles = 0;
|
||||
largestdir = 0;
|
||||
cancel = false;
|
||||
|
||||
rb->splash(HZ, "Counting...");
|
||||
update_screen();
|
||||
lasttick = *rb->current_tick;
|
||||
|
||||
traversedir("", "");
|
||||
if (cancel) {
|
||||
rb->splash(HZ, "Aborted");
|
||||
int button, success;
|
||||
static struct dir_stats stats;
|
||||
stats.dirname[0] = '/';
|
||||
stats.count_all = true;
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
rb->cpu_boost(true);
|
||||
#endif
|
||||
display_dir_stats(&stats);
|
||||
success = collect_dir_stats(&stats, NULL);
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
rb->cpu_boost(false);
|
||||
#endif
|
||||
if (!success)
|
||||
return PLUGIN_OK;
|
||||
}
|
||||
update_screen();
|
||||
|
||||
display_dir_stats(&stats);
|
||||
#ifdef HAVE_BACKLIGHT
|
||||
#ifdef HAVE_REMOTE_LCD
|
||||
rb->remote_backlight_on();
|
||||
|
|
@ -204,21 +47,15 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
rb->backlight_on();
|
||||
#endif
|
||||
rb->splash(HZ, "Done");
|
||||
update_screen();
|
||||
display_dir_stats(&stats);
|
||||
while (1) {
|
||||
|
||||
button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts,
|
||||
ARRAYLEN(plugin_contexts));
|
||||
switch (button) {
|
||||
case STATS_STOP:
|
||||
case STATS_STOP2:
|
||||
switch (button = rb->get_action(CONTEXT_STD, TIMEOUT_BLOCK))
|
||||
{
|
||||
case ACTION_STD_CANCEL:
|
||||
return PLUGIN_OK;
|
||||
break;
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PLUGIN_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue