2005-08-20 19:56:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Jonas Haggqvist
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-08-20 19:56:01 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
static const struct plugin_api* rb;
|
2007-07-31 12:57:22 +00:00
|
|
|
static int files, dirs, musicfiles, largestdir;
|
2005-08-20 19:56:01 +00:00
|
|
|
static int lasttick;
|
|
|
|
static bool abort;
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_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
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-01-18 11:09:06 +00:00
|
|
|
#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
|
2007-05-19 23:38:09 +00:00
|
|
|
#define STATS_STOP BUTTON_POWER
|
2006-07-28 07:35:45 +00:00
|
|
|
|
2007-09-20 10:49:48 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_C200_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2007-10-23 15:40:51 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
2008-02-17 12:23:02 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
|
|
|
|
#define STATS_STOP BUTTON_BACK
|
2008-03-01 22:55:09 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == MROBE100_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define STATS_STOP BUTTON_REC
|
|
|
|
#define STATS_STOP_REMOTE BUTTON_RC_REC
|
|
|
|
|
2008-03-22 22:03:34 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWOND2_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
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",
|
2008-06-21 19:58:26 +00:00
|
|
|
"shn","aif","aiff","wma","wmv","spx","ape","adx",
|
|
|
|
"sid","mod","nsf","nsfe","spc","asf","mac"};
|
2006-04-02 20:47:42 +00:00
|
|
|
|
|
|
|
void prn(const char *str, int y)
|
|
|
|
{
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_puts(0,y,str);
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_remote_puts(0,y,str);
|
2006-04-02 20:47:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-08-20 19:56:01 +00:00
|
|
|
|
|
|
|
void update_screen(void)
|
|
|
|
{
|
2007-07-31 12:57:22 +00:00
|
|
|
char buf[32];
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2005-08-20 19:56:01 +00:00
|
|
|
rb->lcd_clear_display();
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_clear_display();
|
|
|
|
#endif
|
2007-04-06 22:55:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-04-02 20:47:42 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Files: %d", files);
|
|
|
|
prn(buf,0);
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
|
2007-04-06 22:55:00 +00:00
|
|
|
prn(buf,1);
|
2006-04-02 20:47:42 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
|
2007-04-06 22:55:00 +00:00
|
|
|
prn(buf,2);
|
2007-07-31 12:57:22 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
|
|
|
|
prn(buf,3);
|
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
|
2007-04-06 22:55:00 +00:00
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_update();
|
|
|
|
#endif
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void traversedir(char* location, char* name)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR* dir;
|
|
|
|
char fullpath[MAX_PATH];
|
2007-07-31 12:57:22 +00:00
|
|
|
int files_in_dir = 0;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
|
|
|
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,'.');
|
2007-07-31 12:57:22 +00:00
|
|
|
files++; files_in_dir++;
|
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);
|
|
|
|
}
|
2007-07-31 12:57:22 +00:00
|
|
|
if (largestdir < files_in_dir)
|
|
|
|
largestdir = files_in_dir;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
|
2005-08-20 19:56:01 +00:00
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
rb = api;
|
|
|
|
files = 0;
|
|
|
|
dirs = 0;
|
2006-04-02 20:47:42 +00:00
|
|
|
musicfiles = 0;
|
2007-07-31 12:57:22 +00:00
|
|
|
largestdir = 0;
|
2005-08-20 19:56:01 +00:00
|
|
|
abort = false;
|
|
|
|
|
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();
|
|
|
|
while (1) {
|
2008-06-29 06:48:07 +00:00
|
|
|
button = rb->button_get(true);
|
2005-08-20 19:56:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 06:48:07 +00:00
|
|
|
return PLUGIN_OK;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|