summaryrefslogtreecommitdiff
path: root/apps/onplay.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/onplay.c')
-rw-r--r--apps/onplay.c163
1 files changed, 163 insertions, 0 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}