diff options
-rw-r--r-- | apps/plugins/random_folder_advance_config.c | 228 | ||||
-rw-r--r-- | docs/CREDITS | 1 |
2 files changed, 176 insertions, 53 deletions
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index 2b5e16603b..413dc029b4 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c | |||
@@ -28,6 +28,7 @@ static int dirs_count; | |||
28 | static int lasttick; | 28 | static int lasttick; |
29 | #define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat" | 29 | #define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat" |
30 | #define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt" | 30 | #define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt" |
31 | #define RFA_FILE_TEXT ROCKBOX_DIR "/folder_advance_list.txt" | ||
31 | #define MAX_REMOVED_DIRS 10 | 32 | #define MAX_REMOVED_DIRS 10 |
32 | 33 | ||
33 | char *buffer = NULL; | 34 | char *buffer = NULL; |
@@ -39,29 +40,6 @@ struct file_format { | |||
39 | char folder[][MAX_PATH]; | 40 | char folder[][MAX_PATH]; |
40 | }; | 41 | }; |
41 | struct file_format *list = NULL; | 42 | struct file_format *list = NULL; |
42 | #if CONFIG_KEYPAD == PLAYER_PAD | ||
43 | |||
44 | #elif (CONFIG_KEYPAD == RECORDER_PAD) \ | ||
45 | || (CONFIG_KEYPAD == ONDIO_PAD) | ||
46 | |||
47 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \ | ||
48 | || (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
49 | |||
50 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ | ||
51 | (CONFIG_KEYPAD == IPOD_3G_PAD) || \ | ||
52 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) | ||
53 | |||
54 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | ||
55 | |||
56 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD | ||
57 | |||
58 | #elif CONFIG_KEYPAD == GIGABEAT_PAD | ||
59 | |||
60 | #elif CONFIG_KEYPAD == SANSA_E200_PAD | ||
61 | |||
62 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD | ||
63 | |||
64 | #endif | ||
65 | 43 | ||
66 | void update_screen(bool clear) | 44 | void update_screen(bool clear) |
67 | { | 45 | { |
@@ -253,6 +231,7 @@ void generate(void) | |||
253 | rb->lseek(fd,0,SEEK_SET); | 231 | rb->lseek(fd,0,SEEK_SET); |
254 | rb->write(fd,&dirs_count,sizeof(int)); | 232 | rb->write(fd,&dirs_count,sizeof(int)); |
255 | rb->close(fd); | 233 | rb->close(fd); |
234 | rb->splash(HZ, "Done"); | ||
256 | } | 235 | } |
257 | char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len) | 236 | char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len) |
258 | { | 237 | { |
@@ -261,21 +240,63 @@ char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len) | |||
261 | return buf; | 240 | return buf; |
262 | } | 241 | } |
263 | 242 | ||
243 | int load_list(void) | ||
244 | { | ||
245 | int myfd = rb->open(RFA_FILE,O_RDONLY); | ||
246 | if (myfd < 0) | ||
247 | return -1; | ||
248 | buffer = rb->plugin_get_audio_buffer((size_t *)&buffer_size); | ||
249 | if (!buffer) | ||
250 | { | ||
251 | return -2; | ||
252 | } | ||
253 | |||
254 | rb->read(myfd,buffer,buffer_size); | ||
255 | rb->close(myfd); | ||
256 | list = (struct file_format *)buffer; | ||
257 | |||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | int save_list(void) | ||
262 | { | ||
263 | int myfd = rb->creat(RFA_FILE); | ||
264 | if (myfd < 0) | ||
265 | { | ||
266 | rb->splash(HZ, "Could Not Open " RFA_FILE); | ||
267 | return -1; | ||
268 | } | ||
269 | int dirs_count = 0, i = 0; | ||
270 | rb->write(myfd,&dirs_count,sizeof(int)); | ||
271 | for ( ;i<list->count;i++) | ||
272 | { | ||
273 | if (list->folder[i][0] != ' ') | ||
274 | { | ||
275 | dirs_count++; | ||
276 | rb->write(myfd,list->folder[i],MAX_PATH); | ||
277 | } | ||
278 | } | ||
279 | rb->lseek(myfd,0,SEEK_SET); | ||
280 | rb->write(myfd,&dirs_count,sizeof(int)); | ||
281 | rb->close(myfd); | ||
282 | |||
283 | return 1; | ||
284 | } | ||
285 | |||
264 | void edit_list(void) | 286 | void edit_list(void) |
265 | { | 287 | { |
266 | struct gui_synclist lists; | 288 | struct gui_synclist lists; |
267 | bool exit = false; | 289 | bool exit = false; |
268 | int button,i; | 290 | int button,i; |
269 | int selection; | 291 | int selection; |
270 | fd = rb->open(RFA_FILE,O_RDONLY); | 292 | |
271 | if (fd < 0) | 293 | /* load the dat file if not already done */ |
272 | return; | 294 | if ((list == NULL || list->count == 0) && (i = load_list()) != 0) |
273 | buffer = rb->plugin_get_audio_buffer((size_t *)&buffer_size); | 295 | { |
274 | if (!buffer) | 296 | rb->splash(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i); |
275 | return; | 297 | return; |
276 | rb->read(fd,buffer,buffer_size); | 298 | } |
277 | rb->close(fd); | 299 | |
278 | list = (struct file_format *)buffer; | ||
279 | dirs_count = list->count; | 300 | dirs_count = list->count; |
280 | 301 | ||
281 | rb->gui_synclist_init(&lists,list_get_name_cb,0, false, 1, NULL); | 302 | rb->gui_synclist_init(&lists,list_get_name_cb,0, false, 1, NULL); |
@@ -345,27 +366,7 @@ void edit_list(void) | |||
345 | switch (menu_show(m)) | 366 | switch (menu_show(m)) |
346 | { | 367 | { |
347 | case 0: | 368 | case 0: |
348 | exit = true; | 369 | save_list(); |
349 | rb->splash(HZ*2, "Saving " RFA_FILE); | ||
350 | fd = rb->open(RFA_FILE, O_CREAT|O_WRONLY); | ||
351 | if (fd < 0) | ||
352 | { | ||
353 | rb->splash(HZ, "Could Not Open " RFA_FILE); | ||
354 | break; | ||
355 | } | ||
356 | dirs_count = 0; | ||
357 | rb->write(fd,&dirs_count,sizeof(int)); | ||
358 | for (i=0;i<list->count;i++) | ||
359 | { | ||
360 | if (list->folder[i][0] != ' ') | ||
361 | { | ||
362 | dirs_count++; | ||
363 | rb->write(fd,list->folder[i],MAX_PATH); | ||
364 | } | ||
365 | } | ||
366 | rb->lseek(fd,0,SEEK_SET); | ||
367 | rb->write(fd,&dirs_count,sizeof(int)); | ||
368 | rb->close(fd); | ||
369 | case 1: | 370 | case 1: |
370 | exit = true; | 371 | exit = true; |
371 | } | 372 | } |
@@ -375,12 +376,107 @@ void edit_list(void) | |||
375 | } | 376 | } |
376 | } | 377 | } |
377 | } | 378 | } |
379 | |||
380 | int export_list_to_file_text(void) | ||
381 | { | ||
382 | int i = 0; | ||
383 | /* load the dat file if not already done */ | ||
384 | if ((list == NULL || list->count == 0) && (i = load_list()) != 0) | ||
385 | { | ||
386 | rb->splash(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i); | ||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | if (list->count <= 0) | ||
391 | { | ||
392 | rb->splash(HZ*2, "no dirs in list file: %s", RFA_FILE); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | /* create and open the file */ | ||
397 | int myfd = rb->creat(RFA_FILE_TEXT); | ||
398 | if (myfd < 0) | ||
399 | { | ||
400 | rb->splash(HZ*4, "failed to open: fd = %d, file = %s", | ||
401 | myfd, RFA_FILE_TEXT); | ||
402 | return -1; | ||
403 | } | ||
404 | |||
405 | /* write each directory to file */ | ||
406 | for (i = 0; i < list->count; i++) | ||
407 | { | ||
408 | if (list->folder[i][0] != ' ') | ||
409 | { | ||
410 | rb->fdprintf(myfd, "%s\n", list->folder[i]); | ||
411 | } | ||
412 | } | ||
413 | |||
414 | rb->close(myfd); | ||
415 | rb->splash(HZ, "Done"); | ||
416 | return 1; | ||
417 | } | ||
418 | |||
419 | int import_list_from_file_text(void) | ||
420 | { | ||
421 | char line[MAX_PATH]; | ||
422 | |||
423 | buffer = rb->plugin_get_audio_buffer((size_t *)&buffer_size); | ||
424 | if (buffer == NULL) | ||
425 | { | ||
426 | rb->splash(HZ*2, "failed to get audio buffer"); | ||
427 | return -1; | ||
428 | } | ||
429 | |||
430 | int myfd = rb->open(RFA_FILE_TEXT, O_RDONLY); | ||
431 | if (myfd < 0) | ||
432 | { | ||
433 | rb->splash(HZ*2, "failed to open: %s", RFA_FILE_TEXT); | ||
434 | return -1; | ||
435 | } | ||
436 | |||
437 | /* set the list structure, and initialize count */ | ||
438 | list = (struct file_format *)buffer; | ||
439 | list->count = 0; | ||
440 | |||
441 | while ((rb->read_line(myfd, line, MAX_PATH - 1)) > 0) | ||
442 | { | ||
443 | /* copy the dir name, and skip the newline */ | ||
444 | int len = rb->strlen(line); | ||
445 | /* remove CRs */ | ||
446 | if (len > 0) | ||
447 | { | ||
448 | if (line[len-1] == 0x0A || line[len-1] == 0x0D) | ||
449 | line[len-1] = 0x00; | ||
450 | if (len > 1 && | ||
451 | (line[len-2] == 0x0A || line[len-2] == 0x0D)) | ||
452 | line[len-2] = 0x00; | ||
453 | } | ||
454 | |||
455 | rb->strcpy(list->folder[list->count++], line); | ||
456 | } | ||
457 | |||
458 | rb->close(myfd); | ||
459 | |||
460 | if (list->count == 0) | ||
461 | { | ||
462 | load_list(); | ||
463 | } | ||
464 | else | ||
465 | { | ||
466 | save_list(); | ||
467 | } | ||
468 | rb->splash(HZ, "Done"); | ||
469 | return list->count; | ||
470 | } | ||
471 | |||
378 | int main_menu(void) | 472 | int main_menu(void) |
379 | { | 473 | { |
380 | int m; | 474 | int m; |
381 | static const struct menu_item items[] = { | 475 | static const struct menu_item items[] = { |
382 | { "Generate Folder List", NULL }, | 476 | { "Generate Folder List", NULL }, |
383 | { "Edit Folder List", NULL }, | 477 | { "Edit Folder List", NULL }, |
478 | { "Export List To Textfile", NULL }, | ||
479 | { "Import List From Textfile", NULL }, | ||
384 | { "Quit", NULL }, | 480 | { "Quit", NULL }, |
385 | }; | 481 | }; |
386 | m = menu_init(rb, items, sizeof(items) / sizeof(*items), | 482 | m = menu_init(rb, items, sizeof(items) / sizeof(*items), |
@@ -414,7 +510,33 @@ int main_menu(void) | |||
414 | #endif | 510 | #endif |
415 | rb->backlight_on(); | 511 | rb->backlight_on(); |
416 | break; | 512 | break; |
417 | case 2: | 513 | case 2: /* export to textfile */ |
514 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
515 | rb->cpu_boost(true); | ||
516 | #endif | ||
517 | export_list_to_file_text(); | ||
518 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
519 | rb->cpu_boost(false); | ||
520 | #endif | ||
521 | #ifdef HAVE_REMOTE_LCD | ||
522 | rb->remote_backlight_on(); | ||
523 | #endif | ||
524 | rb->backlight_on(); | ||
525 | break; | ||
526 | case 3: /* import from textfile */ | ||
527 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
528 | rb->cpu_boost(true); | ||
529 | #endif | ||
530 | import_list_from_file_text(); | ||
531 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
532 | rb->cpu_boost(false); | ||
533 | #endif | ||
534 | #ifdef HAVE_REMOTE_LCD | ||
535 | rb->remote_backlight_on(); | ||
536 | #endif | ||
537 | rb->backlight_on(); | ||
538 | break; | ||
539 | case 4: | ||
418 | menu_exit(m); | 540 | menu_exit(m); |
419 | return 1; | 541 | return 1; |
420 | } | 542 | } |
diff --git a/docs/CREDITS b/docs/CREDITS index 6118857b2e..d4cf0ad177 100644 --- a/docs/CREDITS +++ b/docs/CREDITS | |||
@@ -387,6 +387,7 @@ Martin Ritter | |||
387 | Justin Hannigan | 387 | Justin Hannigan |
388 | Tomasz Wasilczyk | 388 | Tomasz Wasilczyk |
389 | Kenjiro Arai | 389 | Kenjiro Arai |
390 | John Kaminar | ||
390 | 391 | ||
391 | 392 | ||
392 | The libmad team | 393 | The libmad team |