Minor corrections to the .colours file editing; added .colours to the list of support...
[kugel-rb.git] / apps / plugins / stats.c
blob346d4206c2bd626a3962aa08d226ba03b57c9ee1
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 abort;
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 #define STATS_STOP BUTTON_PLAY
50 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
51 #define STATS_STOP BUTTON_POWER
52 #define STATS_STOP_REMOTE BUTTON_RC_PLAY
54 #elif CONFIG_KEYPAD == GIGABEAT_PAD
55 #define STATS_STOP BUTTON_POWER
57 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
58 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
59 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
60 (CONFIG_KEYPAD == SANSA_M200_PAD)
61 #define STATS_STOP BUTTON_POWER
63 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
64 /* FIXME:
65 #define STATS_STOP BUTTON_HOME */
66 #define STATS_STOP BUTTON_DOWN
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
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
80 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
81 #define STATS_STOP BUTTON_REC
82 #define STATS_STOP_REMOTE BUTTON_RC_REC
84 #elif CONFIG_KEYPAD == COWOND2_PAD
85 #define STATS_STOP BUTTON_POWER
87 #elif CONFIG_KEYPAD == IAUDIO67_PAD
88 #define STATS_STOP BUTTON_POWER
90 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
91 #define STATS_STOP BUTTON_BACK
93 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
94 #define STATS_STOP BUTTON_POWER
96 #else
97 #error No keymap defined!
98 #endif
100 /* TODO: Better get the exts from the filetypes var in tree.c */
101 const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg",
102 "wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
103 "shn","aif","aiff","wma","wmv","spx","ape","adx",
104 "sid","mod","nsf","nsfe","spc","asf","mac"};
106 void prn(const char *str, int y)
108 rb->lcd_puts(0,y,str);
109 #ifdef HAVE_REMOTE_LCD
110 rb->lcd_remote_puts(0,y,str);
111 #endif
114 void update_screen(void)
116 char buf[32];
118 rb->lcd_clear_display();
119 #ifdef HAVE_REMOTE_LCD
120 rb->lcd_remote_clear_display();
121 #endif
123 #ifdef HAVE_LCD_BITMAP
124 rb->snprintf(buf, sizeof(buf), "Files: %d", files);
125 prn(buf,0);
126 rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
127 prn(buf,1);
128 rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
129 prn(buf,2);
130 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
131 prn(buf,3);
132 #else
133 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
134 prn(buf,0);
135 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
136 prn(buf,1);
137 #endif
139 rb->lcd_update();
140 #ifdef HAVE_REMOTE_LCD
141 rb->lcd_remote_update();
142 #endif
145 void traversedir(char* location, char* name)
147 int button;
148 struct dirent *entry;
149 DIR* dir;
150 char fullpath[MAX_PATH];
151 int files_in_dir = 0;
153 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
154 dir = rb->opendir(fullpath);
155 if (dir) {
156 entry = rb->readdir(dir);
157 while (entry) {
158 if (abort == true)
159 break;
160 /* Skip .. and . */
161 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
163 if (entry->attribute & ATTR_DIRECTORY) {
164 traversedir(fullpath, entry->d_name);
165 dirs++;
167 else {
168 char *ptr = rb->strrchr(entry->d_name,'.');
169 files++; files_in_dir++;
170 /* Might want to only count .mp3, .ogg etc. */
171 if(ptr){
172 unsigned i;
173 ptr++;
174 for(i=0;i<sizeof(music_exts)/sizeof(char*);i++)
175 if(!rb->strcasecmp(ptr,music_exts[i])){
176 musicfiles++; break;
182 if (*rb->current_tick - lasttick > (HZ/2)) {
183 update_screen();
184 lasttick = *rb->current_tick;
185 button = rb->button_get(false);
186 if (button == STATS_STOP
187 #ifdef HAVE_REMOTE_LCD
188 || button == STATS_STOP_REMOTE
189 #endif
191 abort = true;
192 break;
196 entry = rb->readdir(dir);
198 rb->closedir(dir);
200 if (largestdir < files_in_dir)
201 largestdir = files_in_dir;
204 enum plugin_status plugin_start(const void* parameter)
206 int button;
208 (void)parameter;
210 files = 0;
211 dirs = 0;
212 musicfiles = 0;
213 largestdir = 0;
214 abort = false;
216 rb->splash(HZ, "Counting...");
217 update_screen();
218 lasttick = *rb->current_tick;
220 traversedir("", "");
221 if (abort == true) {
222 rb->splash(HZ, "Aborted");
223 return PLUGIN_OK;
225 update_screen();
226 #ifdef HAVE_REMOTE_LCD
227 rb->remote_backlight_on();
228 #endif
229 rb->backlight_on();
230 rb->splash(HZ, "Done");
231 update_screen();
232 while (1) {
233 button = rb->button_get(true);
234 switch (button) {
235 #ifdef HAVE_REMOTE_LCD
236 case STATS_STOP_REMOTE:
237 #endif
238 case STATS_STOP:
239 return PLUGIN_OK;
240 break;
241 default:
242 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
243 return PLUGIN_USB_CONNECTED;
245 break;
248 return PLUGIN_OK;