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"
|
|
|
|
|
2010-08-23 16:56:49 +00:00
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
|
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;
|
2010-05-06 21:04:40 +00:00
|
|
|
static bool cancel;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SAMSUNG_YH_PAD)
|
2006-01-12 00:35:50 +00:00
|
|
|
#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) || \
|
2008-12-12 19:50:49 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_C200_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_M200_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2009-01-04 23:33:15 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
|
2009-04-10 17:28:26 +00:00
|
|
|
#define STATS_STOP BUTTON_HOME
|
2009-01-04 23:33:15 +00:00
|
|
|
|
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
|
2009-04-11 07:23:56 +00:00
|
|
|
#define STATS_STOP_REMOTE BUTTON_RC_DOWN
|
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
|
2009-07-26 14:26:14 +00:00
|
|
|
#define STATS_STOP_REMOTE BUTTON_RC_DOWN
|
2008-03-01 22:55:09 +00:00
|
|
|
|
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
|
|
|
|
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWON_D2_PAD
|
2008-03-22 22:03:34 +00:00
|
|
|
#define STATS_STOP BUTTON_POWER
|
2008-10-07 16:38:28 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define STATS_STOP BUTTON_BACK
|
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2009-12-02 01:56:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
|
|
|
|
2009-04-07 23:41:44 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
2009-08-31 21:11:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX777_PAD
|
|
|
|
#define STATS_STOP BUTTON_POWER
|
2009-04-07 23:41:44 +00:00
|
|
|
|
2010-02-11 22:40:17 +00:00
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define STATS_STOP BUTTON_REC
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
#define STATS_STOP BUTTON_REC
|
|
|
|
|
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 */
|
2010-02-27 14:23:30 +00:00
|
|
|
const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg","oga",
|
2006-12-08 13:55:14 +00:00
|
|
|
"wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
|
2010-02-27 14:23:30 +00:00
|
|
|
"shn","aif","aiff","wma","wmv","asf","spx","ape","mac",
|
2010-02-27 14:33:01 +00:00
|
|
|
"sid","mod","nsf","nsfe","spc","adx","sap","rm","at3",
|
2010-02-27 14:23:30 +00:00
|
|
|
"ra","rmvb","oma","aa3","dmc","dlt","mpt","mpd","rmt",
|
2010-03-25 04:49:14 +00:00
|
|
|
"tmc","tm8","tm2","cm3","cmc","cmr","cms","mmf","au",
|
|
|
|
"snd","vox","w64"};
|
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) {
|
2010-05-06 21:04:40 +00:00
|
|
|
if (cancel)
|
2005-08-20 19:56:01 +00:00
|
|
|
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
|
|
|
|
) {
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = true;
|
2005-08-20 19:56:01 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2005-08-20 19:56:01 +00:00
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
files = 0;
|
|
|
|
dirs = 0;
|
2006-04-02 20:47:42 +00:00
|
|
|
musicfiles = 0;
|
2007-07-31 12:57:22 +00:00
|
|
|
largestdir = 0;
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = false;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
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("", "");
|
2010-05-06 21:04:40 +00:00
|
|
|
if (cancel) {
|
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
|
|
|
}
|