summaryrefslogtreecommitdiff
path: root/apps/plugins/stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/stats.c')
-rw-r--r--apps/plugins/stats.c207
1 files changed, 22 insertions, 185 deletions
diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c
index b48259a0e4..8a511bea42 100644
--- a/apps/plugins/stats.c
+++ b/apps/plugins/stats.c
@@ -19,184 +19,27 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "plugin.h" 21#include "plugin.h"
22#include "lib/pluginlib_actions.h" 22#include "lib/mul_id3.h" /* collect_dir_stats & display_dir_stats */
23 23
24
25static int files, dirs, audiofiles, m3ufiles, imagefiles, videofiles, largestdir;
26static int lasttick;
27static bool cancel;
28
29
30/* we use PLA */
31#define STATS_STOP PLA_EXIT
32
33#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
34 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
35 || (CONFIG_KEYPAD == IPOD_4G_PAD)
36#define STATS_STOP2 PLA_UP
37#else
38#define STATS_STOP2 PLA_CANCEL
39#endif
40
41/* this set the context to use with PLA */
42static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
43
44/* we don't have yet a filetype attribute for image files */
45static const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
46
47/* neither for video ones */
48static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
49
50static void prn(const char *str, int y)
51{
52 rb->lcd_puts(0,y,str);
53#ifdef HAVE_REMOTE_LCD
54 rb->lcd_remote_puts(0,y,str);
55#endif
56}
57
58static void update_screen(void)
59{
60 char buf[32];
61
62 rb->lcd_clear_display();
63#ifdef HAVE_REMOTE_LCD
64 rb->lcd_remote_clear_display();
65#endif
66
67 rb->snprintf(buf, sizeof(buf), "Total Files: %d", files);
68 prn(buf,0);
69 rb->snprintf(buf, sizeof(buf), "Audio: %d", audiofiles);
70 prn(buf,1);
71 rb->snprintf(buf, sizeof(buf), "Playlists: %d", m3ufiles);
72 prn(buf,2);
73 rb->snprintf(buf, sizeof(buf), "Images: %d", imagefiles);
74 prn(buf,3);
75 rb->snprintf(buf, sizeof(buf), "Videos: %d", videofiles);
76 prn(buf,4);
77 rb->snprintf(buf, sizeof(buf), "Directories: %d", dirs);
78 prn(buf,5);
79 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
80 prn(buf,6);
81
82 rb->lcd_update();
83#ifdef HAVE_REMOTE_LCD
84 rb->lcd_remote_update();
85#endif
86}
87
88static void traversedir(char* location, char* name)
89{
90 int button;
91 struct dirent *entry;
92 DIR* dir;
93 char fullpath[MAX_PATH];
94 int files_in_dir = 0;
95
96 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
97 dir = rb->opendir(fullpath);
98 if (dir) {
99 entry = rb->readdir(dir);
100 while (entry) {
101 if (cancel)
102 break;
103 /* Skip .. and . */
104 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
105 {
106 struct dirinfo info = rb->dir_get_info(dir, entry);
107 if (info.attribute & ATTR_DIRECTORY) {
108 traversedir(fullpath, entry->d_name);
109 dirs++;
110 }
111 else {
112 files_in_dir++; files++;
113
114 /* get the filetype from the filename */
115 int attr = rb->filetype_get_attr(entry->d_name);
116 switch (attr & FILE_ATTR_MASK)
117 {
118 case FILE_ATTR_AUDIO:
119 audiofiles++;
120 break;
121
122 case FILE_ATTR_M3U:
123 m3ufiles++;
124 break;
125
126 default:
127 {
128 /* use hardcoded filetype_exts to count
129 * image and video files until we get
130 * new attributes added to filetypes.h */
131 char *ptr = rb->strrchr(entry->d_name,'.');
132 if(ptr) {
133 unsigned i;
134 ptr++;
135 for(i=0;i<ARRAYLEN(image_exts);i++) {
136 if(!rb->strcasecmp(ptr,image_exts[i])) {
137 imagefiles++; break;
138 }
139 }
140
141 if (i >= ARRAYLEN(image_exts)) {
142 /* not found above - try video files */
143 for(i=0;i<ARRAYLEN(video_exts);i++) {
144 if(!rb->strcasecmp(ptr,video_exts[i])) {
145 videofiles++; break;
146 }
147 }
148 }
149 }
150 } /* default: */
151 } /* switch */
152 }
153 }
154
155 if (*rb->current_tick - lasttick > (HZ/2)) {
156 update_screen();
157 lasttick = *rb->current_tick;
158 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
159 ARRAYLEN(plugin_contexts));
160 if (button == STATS_STOP || button == STATS_STOP2) {
161 cancel = true;
162 break;
163 }
164 }
165
166 entry = rb->readdir(dir);
167 }
168 rb->closedir(dir);
169 }
170 if (largestdir < files_in_dir)
171 largestdir = files_in_dir;
172}
173
174/* this is the plugin entry point */
175enum plugin_status plugin_start(const void* parameter) 24enum plugin_status plugin_start(const void* parameter)
176{ 25{
177 int button;
178
179 (void)parameter; 26 (void)parameter;
180 27 int button, success;
181 files = 0; 28 static struct dir_stats stats;
182 dirs = 0; 29 stats.dirname[0] = '/';
183 audiofiles = 0; 30 stats.count_all = true;
184 m3ufiles = 0; 31#ifdef HAVE_ADJUSTABLE_CPU_FREQ
185 imagefiles = 0; 32 rb->cpu_boost(true);
186 videofiles = 0; 33#endif
187 largestdir = 0; 34 display_dir_stats(&stats);
188 cancel = false; 35 success = collect_dir_stats(&stats, NULL);
189 36#ifdef HAVE_ADJUSTABLE_CPU_FREQ
190 rb->splash(HZ, "Counting..."); 37 rb->cpu_boost(false);
191 update_screen(); 38#endif
192 lasttick = *rb->current_tick; 39 if (!success)
193
194 traversedir("", "");
195 if (cancel) {
196 rb->splash(HZ, "Aborted");
197 return PLUGIN_OK; 40 return PLUGIN_OK;
198 } 41
199 update_screen(); 42 display_dir_stats(&stats);
200#ifdef HAVE_BACKLIGHT 43#ifdef HAVE_BACKLIGHT
201#ifdef HAVE_REMOTE_LCD 44#ifdef HAVE_REMOTE_LCD
202 rb->remote_backlight_on(); 45 rb->remote_backlight_on();
@@ -204,21 +47,15 @@ enum plugin_status plugin_start(const void* parameter)
204 rb->backlight_on(); 47 rb->backlight_on();
205#endif 48#endif
206 rb->splash(HZ, "Done"); 49 rb->splash(HZ, "Done");
207 update_screen(); 50 display_dir_stats(&stats);
208 while (1) { 51 while (1) {
209 52 switch (button = rb->get_action(CONTEXT_STD, TIMEOUT_BLOCK))
210 button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, 53 {
211 ARRAYLEN(plugin_contexts)); 54 case ACTION_STD_CANCEL:
212 switch (button) {
213 case STATS_STOP:
214 case STATS_STOP2:
215 return PLUGIN_OK; 55 return PLUGIN_OK;
216 break;
217 default: 56 default:
218 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 57 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
219 return PLUGIN_USB_CONNECTED; 58 return PLUGIN_USB_CONNECTED;
220 }
221 break;
222 } 59 }
223 } 60 }
224 return PLUGIN_OK; 61 return PLUGIN_OK;