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 ****************************************************************************/
22 #include "lib/pluginlib_actions.h"
25 static int files
, dirs
, audiofiles
, m3ufiles
, imagefiles
, videofiles
, largestdir
;
31 #define STATS_STOP PLA_EXIT
32 #define STATS_STOP2 PLA_CANCEL
33 /* this set the context to use with PLA */
34 static const struct button_mapping
*plugin_contexts
[] = { pla_main_ctx
};
36 /* we don't have yet a filetype attribute for image files */
37 static const char *image_exts
[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
39 /* neither for video ones */
40 static const char *video_exts
[] = {"mpg","mpeg","mpv","m2v"};
42 static void prn(const char *str
, int y
)
44 rb
->lcd_puts(0,y
,str
);
45 #ifdef HAVE_REMOTE_LCD
46 rb
->lcd_remote_puts(0,y
,str
);
50 static void update_screen(void)
54 rb
->lcd_clear_display();
55 #ifdef HAVE_REMOTE_LCD
56 rb
->lcd_remote_clear_display();
59 #ifdef HAVE_LCD_BITMAP
60 rb
->snprintf(buf
, sizeof(buf
), "Total Files: %d", files
);
62 rb
->snprintf(buf
, sizeof(buf
), "Audio: %d", audiofiles
);
64 rb
->snprintf(buf
, sizeof(buf
), "Playlists: %d", m3ufiles
);
66 rb
->snprintf(buf
, sizeof(buf
), "Images: %d", imagefiles
);
68 rb
->snprintf(buf
, sizeof(buf
), "Videos: %d", videofiles
);
70 rb
->snprintf(buf
, sizeof(buf
), "Directories: %d", dirs
);
72 rb
->snprintf(buf
, sizeof(buf
), "Max files in Dir: %d", largestdir
);
75 rb
->snprintf(buf
, sizeof(buf
), "Files:%5d", files
);
77 rb
->snprintf(buf
, sizeof(buf
), "Dirs: %5d", dirs
);
82 #ifdef HAVE_REMOTE_LCD
83 rb
->lcd_remote_update();
87 static void traversedir(char* location
, char* name
)
92 char fullpath
[MAX_PATH
];
95 rb
->snprintf(fullpath
, sizeof(fullpath
), "%s/%s", location
, name
);
96 dir
= rb
->opendir(fullpath
);
98 entry
= rb
->readdir(dir
);
103 if (rb
->strcmp(entry
->d_name
, ".") && rb
->strcmp(entry
->d_name
, ".."))
105 struct dirinfo info
= rb
->dir_get_info(dir
, entry
);
106 if (info
.attribute
& ATTR_DIRECTORY
) {
107 traversedir(fullpath
, entry
->d_name
);
111 files_in_dir
++; files
++;
113 /* get the filetype from the filename */
114 int attr
= rb
->filetype_get_attr(entry
->d_name
);
115 switch (attr
& FILE_ATTR_MASK
)
117 case FILE_ATTR_AUDIO
:
127 /* use hardcoded filetype_exts to count
128 * image and video files until we get
129 * new attributes added to filetypes.h */
130 char *ptr
= rb
->strrchr(entry
->d_name
,'.');
134 for(i
=0;i
<ARRAYLEN(image_exts
);i
++) {
135 if(!rb
->strcasecmp(ptr
,image_exts
[i
])) {
140 if (i
>= ARRAYLEN(image_exts
)) {
141 /* not found above - try video files */
142 for(i
=0;i
<ARRAYLEN(video_exts
);i
++) {
143 if(!rb
->strcasecmp(ptr
,video_exts
[i
])) {
154 if (*rb
->current_tick
- lasttick
> (HZ
/2)) {
156 lasttick
= *rb
->current_tick
;
157 button
= pluginlib_getaction(TIMEOUT_NOBLOCK
, plugin_contexts
,
158 ARRAYLEN(plugin_contexts
));
159 if (button
== STATS_STOP
) {
165 entry
= rb
->readdir(dir
);
169 if (largestdir
< files_in_dir
)
170 largestdir
= files_in_dir
;
173 /* this is the plugin entry point */
174 enum plugin_status
plugin_start(const void* parameter
)
189 rb
->splash(HZ
, "Counting...");
191 lasttick
= *rb
->current_tick
;
195 rb
->splash(HZ
, "Aborted");
199 #ifdef HAVE_REMOTE_LCD
200 rb
->remote_backlight_on();
203 rb
->splash(HZ
, "Done");
207 button
= pluginlib_getaction(TIMEOUT_BLOCK
, plugin_contexts
,
208 ARRAYLEN(plugin_contexts
));
215 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
216 return PLUGIN_USB_CONNECTED
;