diff options
author | Henrik Backe <henrik@backe.eu> | 2005-03-07 20:40:36 +0000 |
---|---|---|
committer | Henrik Backe <henrik@backe.eu> | 2005-03-07 20:40:36 +0000 |
commit | ea98c14cd0de39b82faa2f587a54f386050ea815 (patch) | |
tree | a3da8a708d3436853cc9c48ee62da6a7614fb410 /apps/filetypes.c | |
parent | 6c19c8529ceeec2fdc52704b788796c853231790 (diff) | |
download | rockbox-ea98c14cd0de39b82faa2f587a54f386050ea815.tar.gz rockbox-ea98c14cd0de39b82faa2f587a54f386050ea815.zip |
Remove double entries in the "open with" menu.
Memory management is also improved, no redundant saving
of plugins and extensions. Entries without extension and/or
icon in viewers.config is also supported.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6166 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r-- | apps/filetypes.c | 193 |
1 files changed, 144 insertions, 49 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index 68540802b0..b76ea27a8c 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -73,6 +73,9 @@ static char string_buffer[STRING_BUFFER_SIZE]; | |||
73 | /* prototypes */ | 73 | /* prototypes */ |
74 | #ifdef HAVE_LCD_BITMAP | 74 | #ifdef HAVE_LCD_BITMAP |
75 | static char* string2icon(const char*); | 75 | static char* string2icon(const char*); |
76 | static int add_plugin(char*,char*); | ||
77 | #else | ||
78 | static int add_plugin(char*); | ||
76 | #endif | 79 | #endif |
77 | static char* get_string(const char*); | 80 | static char* get_string(const char*); |
78 | static int find_attr_index(int); | 81 | static int find_attr_index(int); |
@@ -426,6 +429,69 @@ static void scan_plugins(void) | |||
426 | closedir(dir); | 429 | closedir(dir); |
427 | } | 430 | } |
428 | 431 | ||
432 | #ifdef HAVE_LCD_BITMAP | ||
433 | static int add_plugin(char *plugin, char *icon) | ||
434 | #else | ||
435 | static int add_plugin(char *plugin) | ||
436 | #endif | ||
437 | { | ||
438 | char *cp; | ||
439 | int i; | ||
440 | |||
441 | if (!plugin) | ||
442 | return 0; | ||
443 | |||
444 | cp=strrchr(plugin, '.'); | ||
445 | if (cp) | ||
446 | *cp='\0'; | ||
447 | |||
448 | for (i=first_soft_filetype; i < cnt_filetypes; i++) | ||
449 | { | ||
450 | if (filetypes[i].plugin) | ||
451 | { | ||
452 | if (!strcasecmp(plugin, filetypes[i].plugin)) | ||
453 | { | ||
454 | #ifdef HAVE_LCD_BITMAP | ||
455 | if (filetypes[i].icon == NULL && icon) | ||
456 | { | ||
457 | cp = string2icon(icon); | ||
458 | if (cp) | ||
459 | filetypes[cnt_filetypes].icon = cp; | ||
460 | else | ||
461 | return 0; | ||
462 | } | ||
463 | #endif | ||
464 | return i; | ||
465 | } | ||
466 | } | ||
467 | } | ||
468 | |||
469 | /* new plugin */ | ||
470 | cp = get_string(plugin); | ||
471 | if (cp) | ||
472 | { | ||
473 | filetypes[cnt_filetypes].plugin = cp; | ||
474 | #ifdef HAVE_LCD_BITMAP | ||
475 | /* add icon */ | ||
476 | if (icon) | ||
477 | { | ||
478 | cp = string2icon(icon); | ||
479 | if (cp) | ||
480 | filetypes[cnt_filetypes].icon = cp; | ||
481 | else | ||
482 | return 0; | ||
483 | } | ||
484 | #endif | ||
485 | } | ||
486 | else | ||
487 | { | ||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | cnt_filetypes++; | ||
492 | return cnt_filetypes - 1; | ||
493 | } | ||
494 | |||
429 | /* read config file (or cahe file) */ | 495 | /* read config file (or cahe file) */ |
430 | bool read_config(const char* file) | 496 | bool read_config(const char* file) |
431 | { | 497 | { |
@@ -436,7 +502,7 @@ bool read_config(const char* file) | |||
436 | #endif | 502 | #endif |
437 | last}; | 503 | last}; |
438 | 504 | ||
439 | int i; | 505 | int i,ix; |
440 | int fd; | 506 | int fd; |
441 | char* end; | 507 | char* end; |
442 | char* cp; | 508 | char* cp; |
@@ -491,91 +557,120 @@ bool read_config(const char* file) | |||
491 | } | 557 | } |
492 | } | 558 | } |
493 | str[i] = strtok_r(NULL, ",", &end); | 559 | str[i] = strtok_r(NULL, ",", &end); |
560 | if (str[i]) | ||
561 | if (!strlen(str[i])) | ||
562 | str[i]=NULL; | ||
494 | i++; | 563 | i++; |
495 | } | 564 | } |
496 | 565 | ||
497 | /* bail out if no icon and no plugin */ | 566 | /* bail out if no icon and no plugin */ |
498 | if ((!str[plugin] || !strlen(str[plugin])) && | 567 | if (!str[plugin] |
499 | #ifdef HAVE_LCD_BITMAP | 568 | #ifdef HAVE_LCD_BITMAP |
500 | (!str[icon] || !strlen(str[icon])) && | 569 | && !str[icon] |
501 | #endif | 570 | #endif |
502 | strlen(str[extension])) | 571 | ) |
503 | continue; | 572 | continue; |
504 | 573 | ||
505 | /* bail out if no plugin and icon is incorrect*/ | 574 | /* bail out if no plugin and icon is incorrect*/ |
506 | if ((!str[plugin] || !strlen(str[plugin])) && | 575 | if (!str[plugin] |
507 | #ifdef HAVE_LCD_BITMAP | 576 | #ifdef HAVE_LCD_BITMAP |
508 | (strlen(str[icon]) != ICON_LENGTH*2) && | 577 | && strlen(str[icon]) != ICON_LENGTH*2 |
509 | #endif | 578 | #endif |
510 | strlen(str[extension])) | 579 | ) |
511 | continue; | 580 | continue; |
512 | 581 | ||
513 | /* bail out if no icon and no plugin and no extension*/ | 582 | /* bail out if no icon and no plugin and no extension*/ |
514 | if ((!str[plugin] || !strlen(str[plugin])) && | 583 | if (!str[plugin] && |
515 | #ifdef HAVE_LCD_BITMAP | 584 | #ifdef HAVE_LCD_BITMAP |
516 | (!str[icon] || !strlen(str[icon])) && | 585 | !str[icon] && |
517 | #endif | 586 | #endif |
518 | (!str[extension] || !strlen(str[extension]))) | 587 | !str[extension]) |
588 | continue; | ||
589 | |||
590 | /* bail out if we are not able to start plugin from onplay.c ?*/ | ||
591 | if (str[plugin]) | ||
592 | { | ||
593 | if (strlen(str[plugin]) > MAX_PLUGIN_LENGTH) | ||
594 | { | ||
595 | splash(HZ, true, str(LANG_FILETYPES_PLUGIN_NAME_LONG)); | ||
596 | str[plugin] = NULL; | ||
597 | continue; | ||
598 | } | ||
599 | } | ||
600 | |||
601 | ix=0; | ||
602 | /* if extension already exist don't add a new one */ | ||
603 | for (i=0; i < cnt_exttypes; i++) | ||
604 | { | ||
605 | if (!strcasecmp(str[extension],exttypes[i].extension)) | ||
606 | { | ||
607 | #ifdef HAVE_LCD_BITMAP | ||
608 | ix=add_plugin(str[plugin],NULL); | ||
609 | if (ix) | ||
610 | { | ||
611 | if (str[icon] && filetypes[ix].icon == NULL) | ||
612 | { | ||
613 | if (exttypes[i].type->icon == NULL) | ||
614 | { | ||
615 | cp = string2icon(str[icon]); | ||
616 | if (cp) | ||
617 | exttypes[i].type->icon = cp; | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | #else | ||
622 | ix=add_plugin(str[plugin]); | ||
623 | #endif | ||
624 | if (exttypes[i].type == NULL) | ||
625 | { | ||
626 | exttypes[i].type = &filetypes[ix]; | ||
627 | } | ||
628 | break; | ||
629 | } | ||
630 | } | ||
631 | if (ix) | ||
519 | continue; | 632 | continue; |
520 | 633 | ||
521 | /* add extension */ | 634 | /* add extension */ |
522 | if (str[extension]) | 635 | if (str[extension]) |
523 | { | 636 | { |
524 | if (strlen(str[extension])) | 637 | #ifdef HAVE_LCD_BITMAP |
638 | ix=add_plugin(str[plugin],str[icon]); | ||
639 | #else | ||
640 | ix=add_plugin(str[plugin]); | ||
641 | #endif | ||
642 | if (ix) | ||
525 | { | 643 | { |
526 | cp=get_string(str[extension]); | 644 | cp=get_string(str[extension]); |
527 | if (cp) | 645 | if (cp) |
528 | { | 646 | { |
529 | exttypes[cnt_exttypes].type = &filetypes[cnt_filetypes]; | ||
530 | exttypes[cnt_exttypes].extension = cp; | 647 | exttypes[cnt_exttypes].extension = cp; |
648 | |||
649 | exttypes[cnt_exttypes].type = &filetypes[ix]; | ||
531 | cnt_exttypes++; | 650 | cnt_exttypes++; |
651 | filetypes[i].no_extension=false; | ||
532 | } | 652 | } |
533 | else | 653 | else |
534 | break; | ||
535 | |||
536 | #ifdef HAVE_LCD_BITMAP | ||
537 | /* add icon */ | ||
538 | if (str[icon]) | ||
539 | { | 654 | { |
540 | cp = string2icon(str[icon]); | 655 | break; |
541 | if (cp) | ||
542 | filetypes[cnt_filetypes].icon = cp; | ||
543 | else | ||
544 | break; | ||
545 | } | 656 | } |
546 | #endif | ||
547 | } | 657 | } |
548 | } | 658 | else |
549 | |||
550 | /* are we able to start plugin from onplay.c ?*/ | ||
551 | if (str[plugin]) | ||
552 | { | ||
553 | if (strlen(str[plugin]) > MAX_PLUGIN_LENGTH) | ||
554 | { | 659 | { |
555 | splash(HZ, true, str(LANG_FILETYPES_PLUGIN_NAME_LONG)); | 660 | break; |
556 | str[plugin] = NULL; | ||
557 | } | 661 | } |
558 | } | 662 | } |
559 | 663 | else | |
560 | /* add plugin */ | ||
561 | if (str[plugin]) | ||
562 | { | 664 | { |
563 | if (strlen(str[plugin])) | 665 | #ifdef HAVE_LCD_BITMAP |
564 | { | 666 | ix=add_plugin(str[plugin],str[icon]); |
565 | cp=strrchr(str[plugin], '.'); | 667 | #else |
566 | if (cp) | 668 | ix=add_plugin(str[plugin]); |
567 | *cp='\0'; | 669 | #endif |
568 | 670 | filetypes[ix].no_extension=true; | |
569 | cp = get_string(str[plugin]); | 671 | if (!i) |
570 | if (cp) | 672 | break; |
571 | filetypes[cnt_filetypes].plugin = cp; | ||
572 | else | ||
573 | break; | ||
574 | } | ||
575 | } | 673 | } |
576 | |||
577 | if (filetypes[cnt_filetypes].plugin) | ||
578 | cnt_filetypes++; | ||
579 | } | 674 | } |
580 | close(fd); | 675 | close(fd); |
581 | 676 | ||