Fix FS#10486 - "fuze screen not drawn correctly on backlight turn-on if playlist...
[kugel-rb/myfork.git] / apps / plugins / stats.c
blob495523738c5d1491101c5070af7182a78a3c2458
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 (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 == COWOND2_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 == ONDAVX747_PAD
98 #define STATS_STOP BUTTON_POWER
100 #else
101 #error No keymap defined!
102 #endif
104 /* TODO: Better get the exts from the filetypes var in tree.c */
105 const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg",
106 "wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
107 "shn","aif","aiff","wma","wmv","spx","ape","adx",
108 "sid","mod","nsf","nsfe","spc","asf","mac"};
110 void prn(const char *str, int y)
112 rb->lcd_puts(0,y,str);
113 #ifdef HAVE_REMOTE_LCD
114 rb->lcd_remote_puts(0,y,str);
115 #endif
118 void update_screen(void)
120 char buf[32];
122 rb->lcd_clear_display();
123 #ifdef HAVE_REMOTE_LCD
124 rb->lcd_remote_clear_display();
125 #endif
127 #ifdef HAVE_LCD_BITMAP
128 rb->snprintf(buf, sizeof(buf), "Files: %d", files);
129 prn(buf,0);
130 rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
131 prn(buf,1);
132 rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
133 prn(buf,2);
134 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
135 prn(buf,3);
136 #else
137 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
138 prn(buf,0);
139 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
140 prn(buf,1);
141 #endif
143 rb->lcd_update();
144 #ifdef HAVE_REMOTE_LCD
145 rb->lcd_remote_update();
146 #endif
149 void traversedir(char* location, char* name)
151 int button;
152 struct dirent *entry;
153 DIR* dir;
154 char fullpath[MAX_PATH];
155 int files_in_dir = 0;
157 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
158 dir = rb->opendir(fullpath);
159 if (dir) {
160 entry = rb->readdir(dir);
161 while (entry) {
162 if (abort == true)
163 break;
164 /* Skip .. and . */
165 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
167 if (entry->attribute & ATTR_DIRECTORY) {
168 traversedir(fullpath, entry->d_name);
169 dirs++;
171 else {
172 char *ptr = rb->strrchr(entry->d_name,'.');
173 files++; files_in_dir++;
174 /* Might want to only count .mp3, .ogg etc. */
175 if(ptr){
176 unsigned i;
177 ptr++;
178 for(i=0;i<sizeof(music_exts)/sizeof(char*);i++)
179 if(!rb->strcasecmp(ptr,music_exts[i])){
180 musicfiles++; break;
186 if (*rb->current_tick - lasttick > (HZ/2)) {
187 update_screen();
188 lasttick = *rb->current_tick;
189 button = rb->button_get(false);
190 if (button == STATS_STOP
191 #ifdef HAVE_REMOTE_LCD
192 || button == STATS_STOP_REMOTE
193 #endif
195 abort = true;
196 break;
200 entry = rb->readdir(dir);
202 rb->closedir(dir);
204 if (largestdir < files_in_dir)
205 largestdir = files_in_dir;
208 enum plugin_status plugin_start(const void* parameter)
210 int button;
212 (void)parameter;
214 files = 0;
215 dirs = 0;
216 musicfiles = 0;
217 largestdir = 0;
218 abort = false;
220 rb->splash(HZ, "Counting...");
221 update_screen();
222 lasttick = *rb->current_tick;
224 traversedir("", "");
225 if (abort == true) {
226 rb->splash(HZ, "Aborted");
227 return PLUGIN_OK;
229 update_screen();
230 #ifdef HAVE_REMOTE_LCD
231 rb->remote_backlight_on();
232 #endif
233 rb->backlight_on();
234 rb->splash(HZ, "Done");
235 update_screen();
236 while (1) {
237 button = rb->button_get(true);
238 switch (button) {
239 #ifdef HAVE_REMOTE_LCD
240 case STATS_STOP_REMOTE:
241 #endif
242 case STATS_STOP:
243 return PLUGIN_OK;
244 break;
245 default:
246 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
247 return PLUGIN_USB_CONNECTED;
249 break;
252 return PLUGIN_OK;