diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/stats.c | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c index 1b5eeb2553..1e538f90b4 100644 --- a/apps/plugins/stats.c +++ b/apps/plugins/stats.c | |||
@@ -21,7 +21,7 @@ | |||
21 | PLUGIN_HEADER | 21 | PLUGIN_HEADER |
22 | 22 | ||
23 | static struct plugin_api* rb; | 23 | static struct plugin_api* rb; |
24 | static int files, dirs; | 24 | static int files, dirs, musicfiles; |
25 | static int lasttick; | 25 | static int lasttick; |
26 | static bool abort; | 26 | static bool abort; |
27 | #ifdef HAVE_LCD_BITMAP | 27 | #ifdef HAVE_LCD_BITMAP |
@@ -42,24 +42,53 @@ static int fontwidth, fontheight; | |||
42 | #else | 42 | #else |
43 | #define STATS_STOP BUTTON_OFF | 43 | #define STATS_STOP BUTTON_OFF |
44 | #endif | 44 | #endif |
45 | #ifdef HAVE_REMOTE_LCD | ||
46 | #define STATS_STOP_REMOTE BUTTON_RC_STOP | ||
47 | #endif | ||
48 | |||
49 | /* TODO: Better get the exts from the filetypes var in tree.c */ | ||
50 | const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg", | ||
51 | "wav","flac","ac3","a52","mpc","wv","m4a","mp4","shn", | ||
52 | "aif","aiff"}; | ||
53 | |||
54 | void prn(const char *str, int y) | ||
55 | { | ||
56 | #ifdef HAVE_LCD_BITMAP | ||
57 | rb->lcd_putsxy(0,y,str); | ||
58 | #ifdef HAVE_REMOTE_LCD | ||
59 | rb->lcd_remote_putsxy(0,y,str); | ||
60 | #endif | ||
61 | #else | ||
62 | rb->lcd_puts(0,y,str); | ||
63 | #endif | ||
64 | } | ||
45 | 65 | ||
46 | void update_screen(void) | 66 | void update_screen(void) |
47 | { | 67 | { |
48 | char buf[15]; | 68 | char buf[15]; |
49 | #ifdef HAVE_LCD_BITMAP | 69 | #ifdef HAVE_LCD_BITMAP |
50 | rb->lcd_clear_display(); | 70 | rb->lcd_clear_display(); |
51 | rb->lcd_putsxy(0,0,"Files:"); | 71 | #ifdef HAVE_REMOTE_LCD |
52 | rb->lcd_putsxy(0,fontheight,"Dirs:"); | 72 | rb->lcd_remote_clear_display(); |
53 | rb->snprintf(buf, sizeof(buf), "%d", files); | 73 | #endif |
54 | rb->lcd_putsxy(fontwidth,0,buf); | 74 | |
55 | rb->snprintf(buf, sizeof(buf), "%d", dirs); | 75 | rb->snprintf(buf, sizeof(buf), "Files: %d", files); |
56 | rb->lcd_putsxy(fontwidth,fontheight,buf); | 76 | prn(buf,0); |
77 | |||
78 | rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles); | ||
79 | prn(buf,fontheight); | ||
80 | |||
81 | rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs); | ||
82 | prn(buf,fontheight*2); | ||
57 | rb->lcd_update(); | 83 | rb->lcd_update(); |
84 | #ifdef HAVE_REMOTE_LCD | ||
85 | rb->lcd_remote_update(); | ||
86 | #endif | ||
58 | #else | 87 | #else |
59 | rb->snprintf(buf, sizeof(buf), "Files:%5d", files); | 88 | rb->snprintf(buf, sizeof(buf), "Files:%5d", files); |
60 | rb->lcd_puts(0,0,buf); | 89 | prn(buf,0); |
61 | rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs); | 90 | rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs); |
62 | rb->lcd_puts(0,1,buf); | 91 | prn(buf,1); |
63 | #endif | 92 | #endif |
64 | } | 93 | } |
65 | 94 | ||
@@ -82,17 +111,32 @@ void traversedir(char* location, char* name) | |||
82 | { | 111 | { |
83 | if (entry->attribute & ATTR_DIRECTORY) { | 112 | if (entry->attribute & ATTR_DIRECTORY) { |
84 | traversedir(fullpath, entry->d_name); | 113 | traversedir(fullpath, entry->d_name); |
85 | dirs += 1; | 114 | dirs++; |
86 | } | 115 | } |
87 | else | 116 | else { |
88 | /* Might want to only count .mp3, .ogg etc. */ | 117 | char *ptr = rb->strrchr(entry->d_name,'.'); |
89 | files++; | 118 | files++; |
119 | /* Might want to only count .mp3, .ogg etc. */ | ||
120 | if(ptr){ | ||
121 | unsigned i; | ||
122 | ptr++; | ||
123 | for(i=0;i<sizeof(music_exts)/sizeof(char*);i++) | ||
124 | if(!rb->strcasecmp(ptr,music_exts[i])){ | ||
125 | musicfiles++; break; | ||
126 | } | ||
127 | |||
128 | } | ||
129 | } | ||
90 | } | 130 | } |
91 | if (*rb->current_tick - lasttick > (HZ/2)) { | 131 | if (*rb->current_tick - lasttick > (HZ/2)) { |
92 | update_screen(); | 132 | update_screen(); |
93 | lasttick = *rb->current_tick; | 133 | lasttick = *rb->current_tick; |
94 | button = rb->button_get(false); | 134 | button = rb->button_get(false); |
95 | if (button == STATS_STOP) { | 135 | if (button == STATS_STOP |
136 | #ifdef HAVE_REMOTE_LCD | ||
137 | || button == STATS_STOP_REMOTE | ||
138 | #endif | ||
139 | ) { | ||
96 | abort = true; | 140 | abort = true; |
97 | break; | 141 | break; |
98 | } | 142 | } |
@@ -113,12 +157,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
113 | rb = api; | 157 | rb = api; |
114 | files = 0; | 158 | files = 0; |
115 | dirs = 0; | 159 | dirs = 0; |
160 | musicfiles = 0; | ||
116 | abort = false; | 161 | abort = false; |
117 | 162 | ||
118 | #ifdef HAVE_LCD_BITMAP | 163 | #ifdef HAVE_LCD_BITMAP |
119 | rb->lcd_getstringsize("Files: ", &fontwidth, &fontheight); | 164 | rb->lcd_getstringsize("Files: ", &fontwidth, &fontheight); |
120 | #endif | 165 | #endif |
121 | rb->splash(HZ, true, "Counting.."); | 166 | rb->splash(HZ, true, "Counting..."); |
122 | update_screen(); | 167 | update_screen(); |
123 | lasttick = *rb->current_tick; | 168 | lasttick = *rb->current_tick; |
124 | 169 | ||
@@ -128,11 +173,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
128 | return PLUGIN_OK; | 173 | return PLUGIN_OK; |
129 | } | 174 | } |
130 | update_screen(); | 175 | update_screen(); |
176 | #ifdef HAVE_REMOTE_LCD | ||
177 | rb->remote_backlight_on(); | ||
178 | #endif | ||
179 | rb->backlight_on(); | ||
131 | rb->splash(HZ, true, "Done"); | 180 | rb->splash(HZ, true, "Done"); |
132 | update_screen(); | 181 | update_screen(); |
133 | button = rb->button_get(true); | 182 | button = rb->button_get(true); |
134 | while (1) { | 183 | while (1) { |
135 | switch (button) { | 184 | switch (button) { |
185 | #ifdef HAVE_REMOTE_LCD | ||
186 | case STATS_STOP_REMOTE: | ||
187 | #endif | ||
136 | case STATS_STOP: | 188 | case STATS_STOP: |
137 | return PLUGIN_OK; | 189 | return PLUGIN_OK; |
138 | break; | 190 | break; |