summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/onplay.c163
-rw-r--r--apps/onplay.h24
-rw-r--r--apps/tree.c305
-rw-r--r--apps/tree.h11
4 files changed, 208 insertions, 295 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
new file mode 100644
index 0000000000..571caa403b
--- /dev/null
+++ b/apps/onplay.c
@@ -0,0 +1,163 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <stdbool.h>
23
24#include "lcd.h"
25#include "dir.h"
26#include "file.h"
27#include "mpeg.h"
28#include "menu.h"
29#include "lang.h"
30#include "playlist.h"
31#include "button.h"
32#include "kernel.h"
33#include "keyboard.h"
34
35static char* selected_file = NULL;
36static bool reload_dir = false;
37
38static bool queue_file(void)
39{
40 queue_add(selected_file);
41 return false;
42}
43
44static bool delete_file(void)
45{
46 bool exit = false;
47
48 lcd_clear_display();
49 lcd_puts(0,0,str(LANG_REALLY_DELETE));
50 lcd_puts_scroll(0,1,selected_file);
51
52 while (!exit) {
53 int btn = button_get(true);
54 switch (btn) {
55 case BUTTON_PLAY:
56 case BUTTON_PLAY | BUTTON_REL:
57 if (!remove(selected_file)) {
58 reload_dir = true;
59 lcd_clear_display();
60 lcd_puts_scroll(0,0,selected_file);
61 lcd_puts(0,1,str(LANG_DELETED));
62 lcd_update();
63 sleep(HZ);
64 exit = true;
65 }
66 break;
67
68 default:
69 /* ignore button releases */
70 if (!(btn & BUTTON_REL))
71 exit = true;
72 break;
73 }
74 }
75 return false;
76}
77
78static bool rename_file(void)
79{
80 char newname[MAX_PATH];
81 char* ptr = strrchr(selected_file, '/') + 1;
82 int pathlen = (ptr - selected_file);
83 strncpy(newname, selected_file, sizeof newname);
84 if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
85 if (!strlen(selected_file+pathlen) ||
86 (rename(selected_file, newname) < 0)) {
87 lcd_clear_display();
88 lcd_puts(0,0,str(LANG_RENAME));
89 lcd_puts(0,1,str(LANG_FAILED));
90 lcd_update();
91 sleep(HZ*2);
92 }
93 else
94 reload_dir = true;
95 }
96
97 return false;
98}
99
100extern int d_1;
101extern int d_2;
102
103static void xingupdate(int percent)
104{
105 char buf[32];
106
107 snprintf(buf, 32, "%d%%", percent);
108 lcd_puts(0, 3, buf);
109 snprintf(buf, 32, "%x", d_1);
110 lcd_puts(0, 4, buf);
111 snprintf(buf, 32, "%x", d_2);
112 lcd_puts(0, 5, buf);
113 lcd_update();
114}
115
116static bool vbr_fix(void)
117{
118 char buf[32];
119 unsigned long start_tick;
120 unsigned long end_tick;
121
122 lcd_clear_display();
123 lcd_puts(0, 0, selected_file);
124 lcd_update();
125
126 start_tick = current_tick;
127 mpeg_create_xing_header(selected_file, xingupdate);
128 end_tick = current_tick;
129
130 snprintf(buf, 32, "%d ticks", (int)(end_tick - start_tick));
131 lcd_puts(0, 1, buf);
132 snprintf(buf, 32, "%d seconds", (int)(end_tick - start_tick)/HZ);
133 lcd_puts(0, 2, buf);
134 lcd_update();
135
136 return false;
137}
138
139int onplay(char* file, int attr)
140{
141 struct menu_items menu[5]; /* increase this if you add entries! */
142 int m, i=0, result;
143
144 selected_file = file;
145
146 if (mpeg_status() & MPEG_STATUS_PLAY)
147 menu[i++] = (struct menu_items) { str(LANG_QUEUE), queue_file };
148
149 if (!(attr & ATTR_DIRECTORY))
150 menu[i++] = (struct menu_items) { str(LANG_DELETE), delete_file };
151
152 menu[i++] = (struct menu_items) { str(LANG_RENAME), rename_file };
153 menu[i++] = (struct menu_items) { "VBRfix", vbr_fix };
154
155 /* DIY menu handling, since we want to exit after selection */
156 m = menu_init( menu, i );
157 result = menu_show(m);
158 if (result >= 0)
159 menu[result].function();
160 menu_exit(m);
161
162 return reload_dir;
163}
diff --git a/apps/onplay.h b/apps/onplay.h
new file mode 100644
index 0000000000..8540aaf2c7
--- /dev/null
+++ b/apps/onplay.h
@@ -0,0 +1,24 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _ONPLAY_H_
20#define _ONPLAY_H_
21
22int onplay(char* file, int attr);
23
24#endif
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;
diff --git a/apps/tree.h b/apps/tree.h
index 6b8879001f..a1e132f775 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -21,6 +21,17 @@
21 21
22#include <stdbool.h> 22#include <stdbool.h>
23 23
24/* using attribute not used by FAT */
25#define TREE_ATTR_MPA 0x40 /* mpeg audio file */
26#define TREE_ATTR_M3U 0x80 /* playlist */
27#define TREE_ATTR_WPS 0x100 /* wps config file */
28#define TREE_ATTR_MOD 0x200 /* firmware file */
29#define TREE_ATTR_CFG 0x400 /* config file */
30#define TREE_ATTR_TXT 0x500 /* text file */
31#define TREE_ATTR_FONT 0x800 /* font file */
32#define TREE_ATTR_LNG 0x1000 /* binary lang file */
33#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
34
24void browse_root(void); 35void browse_root(void);
25void set_current_file(char *path); 36void set_current_file(char *path);
26bool dirbrowse(char *root); 37bool dirbrowse(char *root);