1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Jonas Haggqvist
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 static int files
, dirs
, audiofiles
, m3ufiles
, imagefiles
, videofiles
, largestdir
;
29 #if CONFIG_KEYPAD == PLAYER_PAD
30 #define STATS_STOP BUTTON_STOP
32 #elif (CONFIG_KEYPAD == RECORDER_PAD) \
33 || (CONFIG_KEYPAD == ONDIO_PAD) \
34 || (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
35 #define STATS_STOP BUTTON_OFF
37 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
38 || (CONFIG_KEYPAD == IRIVER_H300_PAD)
39 #define STATS_STOP BUTTON_OFF
40 #define STATS_STOP_REMOTE BUTTON_RC_STOP
42 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
44 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
45 #define STATS_STOP BUTTON_MENU
47 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) || \
48 (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
49 #define STATS_STOP BUTTON_PLAY
51 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
52 #define STATS_STOP BUTTON_POWER
53 #define STATS_STOP_REMOTE BUTTON_RC_PLAY
55 #elif CONFIG_KEYPAD == GIGABEAT_PAD
56 #define STATS_STOP BUTTON_POWER
58 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
59 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
60 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
61 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
62 (CONFIG_KEYPAD == SANSA_CONNECT_PAD)
63 #define STATS_STOP BUTTON_POWER
65 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
66 #define STATS_STOP BUTTON_HOME
68 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
69 #define STATS_STOP BUTTON_POWER
71 #elif CONFIG_KEYPAD == MROBE500_PAD
72 #define STATS_STOP BUTTON_POWER
73 #define STATS_STOP_REMOTE BUTTON_RC_DOWN
75 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \
76 CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
77 #define STATS_STOP BUTTON_BACK
79 #elif CONFIG_KEYPAD == MROBE100_PAD
80 #define STATS_STOP BUTTON_POWER
81 #define STATS_STOP_REMOTE BUTTON_RC_DOWN
83 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
84 #define STATS_STOP BUTTON_REC
85 #define STATS_STOP_REMOTE BUTTON_RC_REC
87 #elif CONFIG_KEYPAD == COWON_D2_PAD
88 #define STATS_STOP BUTTON_POWER
90 #elif CONFIG_KEYPAD == IAUDIO67_PAD
91 #define STATS_STOP BUTTON_POWER
93 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
94 #define STATS_STOP BUTTON_BACK
96 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
97 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD) || \
98 (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
99 #define STATS_STOP BUTTON_POWER
101 #elif CONFIG_KEYPAD == ONDAVX747_PAD
102 #define STATS_STOP BUTTON_POWER
103 #elif CONFIG_KEYPAD == ONDAVX777_PAD
104 #define STATS_STOP BUTTON_POWER
106 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
107 #define STATS_STOP BUTTON_REC
109 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
110 #define STATS_STOP BUTTON_REC
112 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
113 #define STATS_STOP BUTTON_REC
115 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
116 #define STATS_STOP BUTTON_BACK
119 #error No keymap defined!
122 /* we don't have yet a filetype attribute for image files */
123 static const char *image_exts
[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
125 /* neither for video ones */
126 static const char *video_exts
[] = {"mpg","mpeg","mpv","m2v"};
128 static void prn(const char *str
, int y
)
130 rb
->lcd_puts(0,y
,str
);
131 #ifdef HAVE_REMOTE_LCD
132 rb
->lcd_remote_puts(0,y
,str
);
136 static void update_screen(void)
140 rb
->lcd_clear_display();
141 #ifdef HAVE_REMOTE_LCD
142 rb
->lcd_remote_clear_display();
145 #ifdef HAVE_LCD_BITMAP
146 rb
->snprintf(buf
, sizeof(buf
), "Total Files: %d", files
);
148 rb
->snprintf(buf
, sizeof(buf
), "Audio: %d", audiofiles
);
150 rb
->snprintf(buf
, sizeof(buf
), "Playlists: %d", m3ufiles
);
152 rb
->snprintf(buf
, sizeof(buf
), "Images: %d", imagefiles
);
154 rb
->snprintf(buf
, sizeof(buf
), "Videos: %d", videofiles
);
156 rb
->snprintf(buf
, sizeof(buf
), "Directories: %d", dirs
);
158 rb
->snprintf(buf
, sizeof(buf
), "Max files in Dir: %d", largestdir
);
161 rb
->snprintf(buf
, sizeof(buf
), "Files:%5d", files
);
163 rb
->snprintf(buf
, sizeof(buf
), "Dirs: %5d", dirs
);
168 #ifdef HAVE_REMOTE_LCD
169 rb
->lcd_remote_update();
173 static void traversedir(char* location
, char* name
)
176 struct dirent
*entry
;
178 char fullpath
[MAX_PATH
];
179 int files_in_dir
= 0;
181 rb
->snprintf(fullpath
, sizeof(fullpath
), "%s/%s", location
, name
);
182 dir
= rb
->opendir(fullpath
);
184 entry
= rb
->readdir(dir
);
189 if (rb
->strcmp(entry
->d_name
, ".") && rb
->strcmp(entry
->d_name
, ".."))
191 struct dirinfo info
= rb
->dir_get_info(dir
, entry
);
192 if (info
.attribute
& ATTR_DIRECTORY
) {
193 traversedir(fullpath
, entry
->d_name
);
197 files_in_dir
++; files
++;
199 /* get the filetype from the filename */
200 int attr
= rb
->filetype_get_attr(entry
->d_name
);
201 switch (attr
& FILE_ATTR_MASK
)
203 case FILE_ATTR_AUDIO
:
213 /* use hardcoded filetype_exts to count
214 * image and video files until we get
215 * new attributes added to filetypes.h */
216 char *ptr
= rb
->strrchr(entry
->d_name
,'.');
220 for(i
=0;i
<ARRAYLEN(image_exts
);i
++) {
221 if(!rb
->strcasecmp(ptr
,image_exts
[i
])) {
226 if (i
>= ARRAYLEN(image_exts
)) {
227 /* not found above - try video files */
228 for(i
=0;i
<ARRAYLEN(video_exts
);i
++) {
229 if(!rb
->strcasecmp(ptr
,video_exts
[i
])) {
240 if (*rb
->current_tick
- lasttick
> (HZ
/2)) {
242 lasttick
= *rb
->current_tick
;
243 button
= rb
->button_get(false);
244 if (button
== STATS_STOP
245 #ifdef HAVE_REMOTE_LCD
246 || button
== STATS_STOP_REMOTE
254 entry
= rb
->readdir(dir
);
258 if (largestdir
< files_in_dir
)
259 largestdir
= files_in_dir
;
262 /* this is the plugin entry point */
263 enum plugin_status
plugin_start(const void* parameter
)
278 rb
->splash(HZ
, "Counting...");
280 lasttick
= *rb
->current_tick
;
284 rb
->splash(HZ
, "Aborted");
288 #ifdef HAVE_REMOTE_LCD
289 rb
->remote_backlight_on();
292 rb
->splash(HZ
, "Done");
295 button
= rb
->button_get(true);
297 #ifdef HAVE_REMOTE_LCD
298 case STATS_STOP_REMOTE
:
304 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
305 return PLUGIN_USB_CONNECTED
;