Android: no need to keep RockboxPCM_class around
[maemo-rb.git] / apps / plugins / stats.c
blob07f2f8efb88847af416bbabdad8147ae1d251af5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "plugin.h"
25 static int files, dirs, audiofiles, m3ufiles, imagefiles, videofiles, largestdir;
26 static int lasttick;
27 static bool cancel;
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 #define STATS_STOP BUTTON_POWER
64 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
65 #define STATS_STOP BUTTON_HOME
67 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
68 #define STATS_STOP BUTTON_POWER
70 #elif CONFIG_KEYPAD == MROBE500_PAD
71 #define STATS_STOP BUTTON_POWER
72 #define STATS_STOP_REMOTE BUTTON_RC_DOWN
74 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
75 #define STATS_STOP BUTTON_BACK
77 #elif CONFIG_KEYPAD == MROBE100_PAD
78 #define STATS_STOP BUTTON_POWER
79 #define STATS_STOP_REMOTE BUTTON_RC_DOWN
81 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
82 #define STATS_STOP BUTTON_REC
83 #define STATS_STOP_REMOTE BUTTON_RC_REC
85 #elif CONFIG_KEYPAD == COWON_D2_PAD
86 #define STATS_STOP BUTTON_POWER
88 #elif CONFIG_KEYPAD == IAUDIO67_PAD
89 #define STATS_STOP BUTTON_POWER
91 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
92 #define STATS_STOP BUTTON_BACK
94 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
95 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD) || \
96 (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
97 #define STATS_STOP BUTTON_POWER
99 #elif CONFIG_KEYPAD == ONDAVX747_PAD
100 #define STATS_STOP BUTTON_POWER
101 #elif CONFIG_KEYPAD == ONDAVX777_PAD
102 #define STATS_STOP BUTTON_POWER
104 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
105 #define STATS_STOP BUTTON_REC
107 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
108 #define STATS_STOP BUTTON_REC
110 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
111 #define STATS_STOP BUTTON_REC
113 #else
114 #error No keymap defined!
115 #endif
117 /* we don't have yet a filetype attribute for image files */
118 const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
120 /* neither for video ones */
121 const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
123 void prn(const char *str, int y)
125 rb->lcd_puts(0,y,str);
126 #ifdef HAVE_REMOTE_LCD
127 rb->lcd_remote_puts(0,y,str);
128 #endif
131 void update_screen(void)
133 char buf[32];
135 rb->lcd_clear_display();
136 #ifdef HAVE_REMOTE_LCD
137 rb->lcd_remote_clear_display();
138 #endif
140 #ifdef HAVE_LCD_BITMAP
141 rb->snprintf(buf, sizeof(buf), "Total Files: %d", files);
142 prn(buf,0);
143 rb->snprintf(buf, sizeof(buf), "Audio: %d", audiofiles);
144 prn(buf,1);
145 rb->snprintf(buf, sizeof(buf), "Playlists: %d", m3ufiles);
146 prn(buf,2);
147 rb->snprintf(buf, sizeof(buf), "Images: %d", imagefiles);
148 prn(buf,3);
149 rb->snprintf(buf, sizeof(buf), "Videos: %d", videofiles);
150 prn(buf,4);
151 rb->snprintf(buf, sizeof(buf), "Directories: %d", dirs);
152 prn(buf,5);
153 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
154 prn(buf,6);
155 #else
156 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
157 prn(buf,0);
158 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
159 prn(buf,1);
160 #endif
162 rb->lcd_update();
163 #ifdef HAVE_REMOTE_LCD
164 rb->lcd_remote_update();
165 #endif
168 void traversedir(char* location, char* name)
170 int button;
171 struct dirent *entry;
172 DIR* dir;
173 char fullpath[MAX_PATH];
174 int files_in_dir = 0;
176 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
177 dir = rb->opendir(fullpath);
178 if (dir) {
179 entry = rb->readdir(dir);
180 while (entry) {
181 if (cancel)
182 break;
183 /* Skip .. and . */
184 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
186 struct dirinfo info = rb->dir_get_info(dir, entry);
187 if (info.attribute & ATTR_DIRECTORY) {
188 traversedir(fullpath, entry->d_name);
189 dirs++;
191 else {
192 files_in_dir++; files++;
194 /* get the filetype from the filename */
195 int attr = rb->filetype_get_attr(entry->d_name);
196 switch (attr & FILE_ATTR_MASK)
198 case FILE_ATTR_AUDIO:
199 audiofiles++;
200 break;
202 case FILE_ATTR_M3U:
203 m3ufiles++;
204 break;
206 default:
208 /* use hardcoded filetype_exts to count
209 * image and video files until we get
210 * new attributes added to filetypes.h */
211 char *ptr = rb->strrchr(entry->d_name,'.');
212 if(ptr) {
213 unsigned i;
214 ptr++;
215 for(i=0;i<ARRAYLEN(image_exts);i++) {
216 if(!rb->strcasecmp(ptr,image_exts[i])) {
217 imagefiles++; break;
221 if (i >= ARRAYLEN(image_exts)) {
222 /* not found above - try video files */
223 for(i=0;i<ARRAYLEN(video_exts);i++) {
224 if(!rb->strcasecmp(ptr,video_exts[i])) {
225 videofiles++; break;
230 } /* default: */
231 } /* switch */
235 if (*rb->current_tick - lasttick > (HZ/2)) {
236 update_screen();
237 lasttick = *rb->current_tick;
238 button = rb->button_get(false);
239 if (button == STATS_STOP
240 #ifdef HAVE_REMOTE_LCD
241 || button == STATS_STOP_REMOTE
242 #endif
244 cancel = true;
245 break;
249 entry = rb->readdir(dir);
251 rb->closedir(dir);
253 if (largestdir < files_in_dir)
254 largestdir = files_in_dir;
257 /* this is the plugin entry point */
258 enum plugin_status plugin_start(const void* parameter)
260 int button;
262 (void)parameter;
264 files = 0;
265 dirs = 0;
266 audiofiles = 0;
267 m3ufiles = 0;
268 imagefiles = 0;
269 videofiles = 0;
270 largestdir = 0;
271 cancel = false;
273 rb->splash(HZ, "Counting...");
274 update_screen();
275 lasttick = *rb->current_tick;
277 traversedir("", "");
278 if (cancel) {
279 rb->splash(HZ, "Aborted");
280 return PLUGIN_OK;
282 update_screen();
283 #ifdef HAVE_REMOTE_LCD
284 rb->remote_backlight_on();
285 #endif
286 rb->backlight_on();
287 rb->splash(HZ, "Done");
288 update_screen();
289 while (1) {
290 button = rb->button_get(true);
291 switch (button) {
292 #ifdef HAVE_REMOTE_LCD
293 case STATS_STOP_REMOTE:
294 #endif
295 case STATS_STOP:
296 return PLUGIN_OK;
297 break;
298 default:
299 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
300 return PLUGIN_USB_CONNECTED;
302 break;
305 return PLUGIN_OK;