2005-08-20 19:56:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Jonas Haggqvist
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2005-08-20 19:56:01 +00:00
|
|
|
static struct plugin_api* rb;
|
2006-04-02 20:47:42 +00:00
|
|
|
static int files, dirs, musicfiles;
|
2005-08-20 19:56:01 +00:00
|
|
|
static int lasttick;
|
|
|
|
static bool abort;
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static int fontwidth, fontheight;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_KEYPAD == PLAYER_PAD
|
|
|
|
#define STATS_STOP BUTTON_STOP
|
2006-07-28 07:35:45 +00:00
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == RECORDER_PAD) \
|
2007-01-14 13:48:09 +00:00
|
|
|
|| (CONFIG_KEYPAD == ONDIO_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
|
2006-07-28 07:35:45 +00:00
|
|
|
#define STATS_STOP BUTTON_OFF
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
#define STATS_STOP BUTTON_OFF
|
|
|
|
#define STATS_STOP_REMOTE BUTTON_RC_STOP
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_3G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define STATS_STOP BUTTON_MENU
|
2006-07-28 07:35:45 +00:00
|
|
|
|
2006-01-12 00:35:50 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
#define STATS_STOP BUTTON_PLAY
|
2006-07-28 07:35:45 +00:00
|
|
|
|
2006-01-18 11:09:06 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
2006-07-28 07:35:45 +00:00
|
|
|
#define STATS_STOP_REMOTE BUTTON_RC_PLAY
|
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
|
|
|
#define STATS_STOP BUTTON_A
|
2006-07-28 07:35:45 +00:00
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_E200_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2006-04-02 20:47:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO: Better get the exts from the filetypes var in tree.c */
|
|
|
|
const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg",
|
2006-12-08 13:55:14 +00:00
|
|
|
"wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
|
|
|
|
"shn","aif","aiff"};
|
2006-04-02 20:47:42 +00:00
|
|
|
|
|
|
|
void prn(const char *str, int y)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_putsxy(0,y,str);
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_putsxy(0,y,str);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
rb->lcd_puts(0,y,str);
|
|
|
|
#endif
|
|
|
|
}
|
2005-08-20 19:56:01 +00:00
|
|
|
|
|
|
|
void update_screen(void)
|
|
|
|
{
|
|
|
|
char buf[15];
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_clear_display();
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_clear_display();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Files: %d", files);
|
|
|
|
prn(buf,0);
|
|
|
|
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
|
|
|
|
prn(buf,fontheight);
|
|
|
|
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
|
|
|
|
prn(buf,fontheight*2);
|
2005-08-20 19:56:01 +00:00
|
|
|
rb->lcd_update();
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_update();
|
|
|
|
#endif
|
2005-08-20 19:56:01 +00:00
|
|
|
#else
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
|
2006-04-02 20:47:42 +00:00
|
|
|
prn(buf,0);
|
2005-08-20 19:56:01 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
|
2006-04-02 20:47:42 +00:00
|
|
|
prn(buf,1);
|
2005-08-20 19:56:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void traversedir(char* location, char* name)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR* dir;
|
|
|
|
char fullpath[MAX_PATH];
|
|
|
|
|
|
|
|
rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
|
|
|
|
dir = rb->opendir(fullpath);
|
|
|
|
if (dir) {
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
while (entry) {
|
|
|
|
if (abort == true)
|
|
|
|
break;
|
|
|
|
/* Skip .. and . */
|
|
|
|
if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
|
|
|
|
{
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY) {
|
|
|
|
traversedir(fullpath, entry->d_name);
|
2006-04-02 20:47:42 +00:00
|
|
|
dirs++;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
2006-04-02 20:47:42 +00:00
|
|
|
else {
|
|
|
|
char *ptr = rb->strrchr(entry->d_name,'.');
|
2005-08-20 19:56:01 +00:00
|
|
|
files++;
|
2006-04-02 20:47:42 +00:00
|
|
|
/* Might want to only count .mp3, .ogg etc. */
|
|
|
|
if(ptr){
|
|
|
|
unsigned i;
|
|
|
|
ptr++;
|
|
|
|
for(i=0;i<sizeof(music_exts)/sizeof(char*);i++)
|
|
|
|
if(!rb->strcasecmp(ptr,music_exts[i])){
|
|
|
|
musicfiles++; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
|
|
|
if (*rb->current_tick - lasttick > (HZ/2)) {
|
|
|
|
update_screen();
|
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
button = rb->button_get(false);
|
2006-04-02 20:47:42 +00:00
|
|
|
if (button == STATS_STOP
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|| button == STATS_STOP_REMOTE
|
|
|
|
#endif
|
|
|
|
) {
|
2005-08-20 19:56:01 +00:00
|
|
|
abort = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
rb = api;
|
|
|
|
files = 0;
|
|
|
|
dirs = 0;
|
2006-04-02 20:47:42 +00:00
|
|
|
musicfiles = 0;
|
2005-08-20 19:56:01 +00:00
|
|
|
abort = false;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_getstringsize("Files: ", &fontwidth, &fontheight);
|
|
|
|
#endif
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Counting...");
|
2005-08-20 19:56:01 +00:00
|
|
|
update_screen();
|
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
|
|
|
|
traversedir("", "");
|
|
|
|
if (abort == true) {
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Aborted");
|
2005-08-20 19:56:01 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2005-09-02 22:25:25 +00:00
|
|
|
update_screen();
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->remote_backlight_on();
|
|
|
|
#endif
|
|
|
|
rb->backlight_on();
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Done");
|
2005-08-20 19:56:01 +00:00
|
|
|
update_screen();
|
|
|
|
button = rb->button_get(true);
|
|
|
|
while (1) {
|
|
|
|
switch (button) {
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
case STATS_STOP_REMOTE:
|
|
|
|
#endif
|
2005-08-20 19:56:01 +00:00
|
|
|
case STATS_STOP:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
}
|