summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c305
1 files changed, 10 insertions, 295 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 8fbe6ad404..acb53e5071 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -50,6 +50,7 @@
50#include "language.h" 50#include "language.h"
51#include "screens.h" 51#include "screens.h"
52#include "keyboard.h" 52#include "keyboard.h"
53#include "onplay.h"
53 54
54#ifdef HAVE_LCD_BITMAP 55#ifdef HAVE_LCD_BITMAP
55#include "widgets.h" 56#include "widgets.h"
@@ -142,17 +143,6 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6];
142#define TREE_MENU BUTTON_MENU 143#define TREE_MENU BUTTON_MENU
143#endif /* HAVE_RECORDER_KEYPAD */ 144#endif /* HAVE_RECORDER_KEYPAD */
144 145
145/* using attribute not used by FAT */
146#define TREE_ATTR_MPA 0x40 /* mpeg audio file */
147#define TREE_ATTR_M3U 0x80 /* playlist */
148#define TREE_ATTR_WPS 0x100 /* wps config file */
149#define TREE_ATTR_MOD 0x200 /* firmware file */
150#define TREE_ATTR_CFG 0x400 /* config file */
151#define TREE_ATTR_TXT 0x500 /* text file */
152#define TREE_ATTR_FONT 0x800 /* font file */
153#define TREE_ATTR_LNG 0x1000 /* binary lang file */
154#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
155
156static int build_playlist(int start_index) 146static int build_playlist(int start_index)
157{ 147{
158 int i; 148 int i;
@@ -652,289 +642,6 @@ void set_current_file(char *path)
652 } 642 }
653} 643}
654 644
655#ifdef HAVE_LCD_BITMAP
656extern int d_1;
657extern int d_2;
658
659void xingupdate(int percent)
660{
661 char buf[32];
662
663 snprintf(buf, 32, "%d%%", percent);
664 lcd_puts(0, 3, buf);
665 snprintf(buf, 32, "%x", d_1);
666 lcd_puts(0, 4, buf);
667 snprintf(buf, 32, "%x", d_2);
668 lcd_puts(0, 5, buf);
669 lcd_update();
670}
671
672void do_xing(char *filename)
673{
674 char buf2[32];
675 unsigned long start_tick;
676 unsigned long end_tick;
677
678 lcd_clear_display();
679 lcd_puts(0, 0, filename);
680 lcd_update();
681 start_tick = current_tick;
682 mpeg_create_xing_header(filename, xingupdate);
683 end_tick = current_tick;
684 snprintf(buf2, 32, "%d ticks", (int)(end_tick - start_tick));
685 lcd_puts(0, 1, buf2);
686 snprintf(buf2, 32, "%d seconds", (int)(end_tick - start_tick)/HZ);
687 lcd_puts(0, 2, buf2);
688 lcd_update();
689}
690
691static int onplay_screen(char* dir, char* file)
692{
693 bool exit = false;
694 bool used = false;
695 bool playing = mpeg_status() & MPEG_STATUS_PLAY;
696 char buf[MAX_PATH];
697 struct entry* f = &dircache[dirstart + dircursor];
698 bool isdir = f->attr & ATTR_DIRECTORY;
699
700 if (dir[1])
701 snprintf(buf, sizeof buf, "%s/%s", dir, file);
702 else
703 snprintf(buf, sizeof buf, "/%s", file);
704
705 lcd_clear_display();
706
707 {
708 int w,h;
709 char* ptr;
710
711 lcd_setfont(FONT_SYSFIXED);
712
713 if (playing) {
714 ptr = str(LANG_QUEUE);
715 lcd_getstringsize(ptr,&w,&h);
716 lcd_putsxy((LCD_WIDTH-w)/2, h*2, ptr);
717 lcd_bitmap(bitmap_icons_7x8[Icon_Play],
718 LCD_WIDTH/2 - 3, LCD_HEIGHT/2 - 4, 7, 8, true);
719 }
720
721 /* don't delete directories */
722 if (!isdir) {
723 ptr = str(LANG_DELETE);
724 lcd_getstringsize(ptr,&w,&h);
725 lcd_putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h/2, ptr);
726 lcd_bitmap(bitmap_icons_7x8[Icon_FastForward],
727 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8, true);
728 }
729
730 ptr = str(LANG_RENAME);
731 lcd_getstringsize(ptr,&w,&h);
732 lcd_putsxy(0, LCD_HEIGHT/2 - h/2, ptr);
733 lcd_bitmap(bitmap_icons_7x8[Icon_FastBackward],
734 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8, true);
735
736 ptr = "VBR Fix";
737 lcd_getstringsize(ptr,&w,&h);
738 lcd_putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
739 lcd_bitmap(bitmap_icons_7x8[Icon_DownArrow],
740 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8, true);
741 }
742 lcd_update();
743
744
745 while (!exit) {
746 switch (button_get(true)) {
747 case BUTTON_LEFT:
748 case BUTTON_ON | BUTTON_LEFT: {
749 char newname[MAX_PATH];
750 char* ptr = strrchr(buf, '/') + 1;
751 int pathlen = (ptr - buf);
752 strncpy(newname, buf, sizeof newname);
753 if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
754 if (!strlen(buf+pathlen) || (rename(buf, newname) < 0)) {
755 lcd_clear_display();
756 lcd_puts(0,0,str(LANG_RENAME));
757 lcd_puts(0,1,str(LANG_FAILED));
758 lcd_update();
759 sleep(HZ*2);
760 }
761 else
762 reload_dir = true;
763 }
764 exit = true;
765 break;
766 }
767
768 case BUTTON_RIGHT:
769 case BUTTON_ON | BUTTON_RIGHT:
770 /* don't delete directories */
771 if (isdir)
772 break;
773 lcd_clear_display();
774 lcd_puts(0,0,str(LANG_REALLY_DELETE));
775 lcd_puts_scroll(0,1,file);
776 lcd_puts(0,3,str(LANG_RESUME_CONFIRM_RECORDER));
777 lcd_puts(0,4,str(LANG_RESUME_CANCEL_RECORDER));
778 lcd_update();
779 while (!exit) {
780 int btn = button_get(true);
781 switch (btn) {
782 case BUTTON_PLAY:
783 case BUTTON_PLAY | BUTTON_REL:
784 if (!remove(buf)) {
785 reload_dir = true;
786 lcd_clear_display();
787 lcd_puts_scroll(0,0,file);
788 lcd_puts(0,1,str(LANG_DELETED));
789 lcd_update();
790 sleep(HZ);
791 exit = true;
792 }
793 break;
794
795 default:
796 /* ignore button releases */
797 if (!(btn & BUTTON_REL))
798 exit = true;
799 break;
800 }
801 }
802 break;
803
804 case BUTTON_DOWN:
805 case BUTTON_ON | BUTTON_DOWN:
806 do_xing(buf);
807// exit = true;
808 break;
809
810 case BUTTON_PLAY:
811 case BUTTON_ON | BUTTON_PLAY: {
812 if (playing)
813 queue_add(buf);
814 exit = true;
815 break;
816 }
817
818 case BUTTON_ON | BUTTON_REL:
819 used = true;
820 break;
821
822 case BUTTON_ON:
823 if (used)
824 exit = true;
825 break;
826
827 case BUTTON_OFF:
828 exit = true;
829 break;
830 }
831 }
832
833 lcd_setfont(FONT_UI);
834
835 return false;
836}
837
838#else
839
840static int onplay_screen(char* dir, char* file)
841{
842 bool exit = false;
843 bool playing = mpeg_status() & MPEG_STATUS_PLAY;
844 char buf[MAX_PATH];
845 struct entry* f = &dircache[dirstart + dircursor];
846 bool isdir = f->attr & ATTR_DIRECTORY;
847 struct menu_items items[3];
848 int ids[3];
849 int lastitem=0;
850 int m_handle;
851 int selected;
852
853 if (dir[1])
854 snprintf(buf, sizeof buf, "%s/%s", dir, file);
855 else
856 snprintf(buf, sizeof buf, "/%s", file);
857
858 if (playing) {
859 items[lastitem].desc=str(LANG_QUEUE);
860 ids[lastitem]=1;
861 lastitem++;
862 }
863
864 items[lastitem].desc=str(LANG_RENAME);
865 ids[lastitem]=2;
866 lastitem++;
867
868 /* don't delete directories */
869 if (!isdir) {
870 items[lastitem].desc=str(LANG_DELETE);
871 ids[lastitem]=3;
872 lastitem++;
873 }
874 m_handle=menu_init(items, lastitem);
875
876 selected=menu_show(m_handle);
877 if (selected>=0) {
878 switch(ids[selected]) {
879 case 1:
880 if (playing)
881 queue_add(buf);
882 break;
883
884 case 2: {
885 char newname[MAX_PATH];
886 char* ptr = strrchr(buf, '/') + 1;
887 int pathlen = (ptr - buf);
888 strncpy(newname, buf, sizeof newname);
889 if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
890 if (rename(buf, newname) < 0) {
891 lcd_clear_display();
892 lcd_puts(0,0,str(LANG_RENAME));
893 lcd_puts(0,1,str(LANG_FAILED));
894 lcd_update();
895 sleep(HZ*2);
896 }
897 else
898 reload_dir = true;
899 }
900 }
901 break;
902
903 case 3:
904 lcd_clear_display();
905 lcd_puts_scroll(0,0,file);
906 lcd_puts(0,1,str(LANG_REALLY_DELETE));
907 lcd_update();
908 while (!exit) {
909 int btn = button_get(true);
910 switch (btn) {
911 case BUTTON_PLAY:
912 if (!remove(buf)) {
913 reload_dir = true;
914 lcd_clear_display();
915 lcd_puts_scroll(0,0,file);
916 lcd_puts(0,1,str(LANG_DELETED));
917 lcd_update();
918 sleep(HZ);
919 exit = true;
920 }
921 break;
922
923 default:
924 /* ignore button releases */
925 if (!(btn & BUTTON_REL))
926 exit = true;
927 break;
928 }
929 }
930 break;
931 }
932 }
933 menu_exit(m_handle);
934 return false;
935}
936#endif
937
938static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) 645static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
939{ 646{
940 bool exit = false; 647 bool exit = false;
@@ -942,6 +649,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
942 649
943 int dirstart = *ds; 650 int dirstart = *ds;
944 int dircursor = *dc; 651 int dircursor = *dc;
652 char buf[MAX_PATH];
945 653
946 while (!exit) { 654 while (!exit) {
947 switch (button_get(true)) { 655 switch (button_get(true)) {
@@ -975,7 +683,14 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
975 683
976 case BUTTON_PLAY: 684 case BUTTON_PLAY:
977 case BUTTON_ON | BUTTON_PLAY: 685 case BUTTON_ON | BUTTON_PLAY:
978 onplay_screen(currdir, dircache[dircursor+dirstart].name); 686 if (currdir[1])
687 snprintf(buf, sizeof buf, "%s/%s",
688 currdir, dircache[dircursor+dirstart].name);
689 else
690 snprintf(buf, sizeof buf, "/%s",
691 dircache[dircursor+dirstart].name);
692 if (onplay(buf, dircache[dircursor+dirstart].attr))
693 reload_dir = 1;
979 exit = true; 694 exit = true;
980 used = true; 695 used = true;
981 break; 696 break;