builds: make clipv2/clip+/fuzev2 unstable
[kugel-rb.git] / apps / plugins / stats.c
blob3420579881b0c94a5df55c0b98b578735914d0a2
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"
23 PLUGIN_HEADER
25 static int files, dirs, musicfiles, 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 #define STATS_STOP BUTTON_POWER
97 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
98 #define STATS_STOP BUTTON_POWER
100 #elif CONFIG_KEYPAD == ONDAVX747_PAD
101 #define STATS_STOP BUTTON_POWER
102 #elif CONFIG_KEYPAD == ONDAVX777_PAD
103 #define STATS_STOP BUTTON_POWER
105 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
106 #define STATS_STOP BUTTON_REC
108 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
109 #define STATS_STOP BUTTON_REC
111 #else
112 #error No keymap defined!
113 #endif
115 /* TODO: Better get the exts from the filetypes var in tree.c */
116 const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg","oga",
117 "wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
118 "shn","aif","aiff","wma","wmv","asf","spx","ape","mac",
119 "sid","mod","nsf","nsfe","spc","adx","sap","rm","at3",
120 "ra","rmvb","oma","aa3","dmc","dlt","mpt","mpd","rmt",
121 "tmc","tm8","tm2","cm3","cmc","cmr","cms","mmf","au",
122 "snd","vox","w64"};
124 void prn(const char *str, int y)
126 rb->lcd_puts(0,y,str);
127 #ifdef HAVE_REMOTE_LCD
128 rb->lcd_remote_puts(0,y,str);
129 #endif
132 void update_screen(void)
134 char buf[32];
136 rb->lcd_clear_display();
137 #ifdef HAVE_REMOTE_LCD
138 rb->lcd_remote_clear_display();
139 #endif
141 #ifdef HAVE_LCD_BITMAP
142 rb->snprintf(buf, sizeof(buf), "Files: %d", files);
143 prn(buf,0);
144 rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
145 prn(buf,1);
146 rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
147 prn(buf,2);
148 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
149 prn(buf,3);
150 #else
151 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
152 prn(buf,0);
153 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
154 prn(buf,1);
155 #endif
157 rb->lcd_update();
158 #ifdef HAVE_REMOTE_LCD
159 rb->lcd_remote_update();
160 #endif
163 void traversedir(char* location, char* name)
165 int button;
166 struct dirent *entry;
167 DIR* dir;
168 char fullpath[MAX_PATH];
169 int files_in_dir = 0;
171 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
172 dir = rb->opendir(fullpath);
173 if (dir) {
174 entry = rb->readdir(dir);
175 while (entry) {
176 if (cancel)
177 break;
178 /* Skip .. and . */
179 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
181 if (entry->attribute & ATTR_DIRECTORY) {
182 traversedir(fullpath, entry->d_name);
183 dirs++;
185 else {
186 char *ptr = rb->strrchr(entry->d_name,'.');
187 files++; files_in_dir++;
188 /* Might want to only count .mp3, .ogg etc. */
189 if(ptr){
190 unsigned i;
191 ptr++;
192 for(i=0;i<sizeof(music_exts)/sizeof(char*);i++)
193 if(!rb->strcasecmp(ptr,music_exts[i])){
194 musicfiles++; break;
200 if (*rb->current_tick - lasttick > (HZ/2)) {
201 update_screen();
202 lasttick = *rb->current_tick;
203 button = rb->button_get(false);
204 if (button == STATS_STOP
205 #ifdef HAVE_REMOTE_LCD
206 || button == STATS_STOP_REMOTE
207 #endif
209 cancel = true;
210 break;
214 entry = rb->readdir(dir);
216 rb->closedir(dir);
218 if (largestdir < files_in_dir)
219 largestdir = files_in_dir;
222 enum plugin_status plugin_start(const void* parameter)
224 int button;
226 (void)parameter;
228 files = 0;
229 dirs = 0;
230 musicfiles = 0;
231 largestdir = 0;
232 cancel = false;
234 rb->splash(HZ, "Counting...");
235 update_screen();
236 lasttick = *rb->current_tick;
238 traversedir("", "");
239 if (cancel) {
240 rb->splash(HZ, "Aborted");
241 return PLUGIN_OK;
243 update_screen();
244 #ifdef HAVE_REMOTE_LCD
245 rb->remote_backlight_on();
246 #endif
247 rb->backlight_on();
248 rb->splash(HZ, "Done");
249 update_screen();
250 while (1) {
251 button = rb->button_get(true);
252 switch (button) {
253 #ifdef HAVE_REMOTE_LCD
254 case STATS_STOP_REMOTE:
255 #endif
256 case STATS_STOP:
257 return PLUGIN_OK;
258 break;
259 default:
260 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
261 return PLUGIN_USB_CONNECTED;
263 break;
266 return PLUGIN_OK;