diff options
Diffstat (limited to 'apps/plugins/text_viewer/text_viewer.c')
-rw-r--r-- | apps/plugins/text_viewer/text_viewer.c | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c new file mode 100644 index 0000000000..7150498b56 --- /dev/null +++ b/apps/plugins/text_viewer/text_viewer.c | |||
@@ -0,0 +1,210 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Gilles Roux | ||
11 | * 2003 Garrett Derner | ||
12 | * 2010 Yoshihisa Uchida | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | #include "plugin.h" | ||
24 | #include "tv_action.h" | ||
25 | #include "tv_button.h" | ||
26 | #include "tv_preferences.h" | ||
27 | |||
28 | PLUGIN_HEADER | ||
29 | |||
30 | enum plugin_status plugin_start(const void* file) | ||
31 | { | ||
32 | int button; | ||
33 | int lastbutton = BUTTON_NONE; | ||
34 | bool autoscroll = false; | ||
35 | long old_tick; | ||
36 | bool done = false; | ||
37 | bool display_update = true; | ||
38 | const struct tv_preferences *prefs = tv_get_preferences(); | ||
39 | |||
40 | old_tick = *rb->current_tick; | ||
41 | |||
42 | if (!file) | ||
43 | return PLUGIN_ERROR; | ||
44 | |||
45 | if (!tv_init(file)) { | ||
46 | rb->splash(HZ, "Error opening file"); | ||
47 | return PLUGIN_ERROR; | ||
48 | } | ||
49 | |||
50 | #if LCD_DEPTH > 1 | ||
51 | rb->lcd_set_backdrop(NULL); | ||
52 | #endif | ||
53 | |||
54 | while (!done) { | ||
55 | |||
56 | if (display_update) | ||
57 | tv_draw(); | ||
58 | |||
59 | display_update = true; | ||
60 | |||
61 | button = rb->button_get_w_tmo(HZ/10); | ||
62 | |||
63 | switch (button) { | ||
64 | case TV_MENU: | ||
65 | #ifdef TV_MENU2 | ||
66 | case TV_MENU2: | ||
67 | #endif | ||
68 | { | ||
69 | enum tv_menu_result res = tv_menu(); | ||
70 | |||
71 | if (res != TV_MENU_RESULT_EXIT_MENU) | ||
72 | { | ||
73 | tv_exit(NULL); | ||
74 | done = true; | ||
75 | if (res == TV_MENU_RESULT_ATTACHED_USB) | ||
76 | return PLUGIN_USB_CONNECTED; | ||
77 | } | ||
78 | } | ||
79 | break; | ||
80 | |||
81 | case TV_AUTOSCROLL: | ||
82 | #ifdef TV_AUTOSCROLL_PRE | ||
83 | if (lastbutton != TV_AUTOSCROLL_PRE) | ||
84 | break; | ||
85 | #endif | ||
86 | autoscroll = !autoscroll; | ||
87 | break; | ||
88 | |||
89 | case TV_SCROLL_UP: | ||
90 | case TV_SCROLL_UP | BUTTON_REPEAT: | ||
91 | #ifdef TV_SCROLL_UP2 | ||
92 | case TV_SCROLL_UP2: | ||
93 | case TV_SCROLL_UP2 | BUTTON_REPEAT: | ||
94 | #endif | ||
95 | tv_scroll_up(TV_VERTICAL_SCROLL_PREFS); | ||
96 | old_tick = *rb->current_tick; | ||
97 | break; | ||
98 | |||
99 | case TV_SCROLL_DOWN: | ||
100 | case TV_SCROLL_DOWN | BUTTON_REPEAT: | ||
101 | #ifdef TV_PAGE_DOWN2 | ||
102 | case TV_SCROLL_DOWN2: | ||
103 | case TV_SCROLL_DOWN2 | BUTTON_REPEAT: | ||
104 | #endif | ||
105 | tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); | ||
106 | old_tick = *rb->current_tick; | ||
107 | break; | ||
108 | |||
109 | case TV_SCREEN_LEFT: | ||
110 | case TV_SCREEN_LEFT | BUTTON_REPEAT: | ||
111 | if (prefs->view_mode == WIDE) | ||
112 | { | ||
113 | /* Screen left */ | ||
114 | tv_scroll_left(TV_HORIZONTAL_SCROLL_WINDOW); | ||
115 | } | ||
116 | else { /* prefs->view_mode == NARROW */ | ||
117 | /* scroll to previous page */ | ||
118 | tv_scroll_up(TV_VERTICAL_SCROLL_PAGE); | ||
119 | #if 0 | ||
120 | /* Top of file */ | ||
121 | tv_top(); | ||
122 | #endif | ||
123 | } | ||
124 | break; | ||
125 | |||
126 | case TV_SCREEN_RIGHT: | ||
127 | case TV_SCREEN_RIGHT | BUTTON_REPEAT: | ||
128 | if (prefs->view_mode == WIDE) | ||
129 | { | ||
130 | /* Screen right */ | ||
131 | tv_scroll_right(TV_HORIZONTAL_SCROLL_WINDOW); | ||
132 | } | ||
133 | else { /* prefs->view_mode == NARROW */ | ||
134 | /* scroll to next page */ | ||
135 | tv_scroll_down(TV_VERTICAL_SCROLL_PAGE); | ||
136 | #if 0 | ||
137 | /* Bottom of file */ | ||
138 | tv_bottom(); | ||
139 | #endif | ||
140 | } | ||
141 | break; | ||
142 | |||
143 | #ifdef TV_LINE_UP | ||
144 | case TV_LINE_UP: | ||
145 | case TV_LINE_UP | BUTTON_REPEAT: | ||
146 | /* Scroll up one line */ | ||
147 | tv_scroll_up(TV_VERTICAL_SCROLL_LINE); | ||
148 | old_tick = *rb->current_tick; | ||
149 | break; | ||
150 | |||
151 | case TV_LINE_DOWN: | ||
152 | case TV_LINE_DOWN | BUTTON_REPEAT: | ||
153 | /* Scroll down one line */ | ||
154 | tv_scroll_down(TV_VERTICAL_SCROLL_LINE); | ||
155 | old_tick = *rb->current_tick; | ||
156 | break; | ||
157 | #endif | ||
158 | #ifdef TV_COLUMN_LEFT | ||
159 | case TV_COLUMN_LEFT: | ||
160 | case TV_COLUMN_LEFT | BUTTON_REPEAT: | ||
161 | /* Scroll left one column */ | ||
162 | tv_scroll_left(TV_HORIZONTAL_SCROLL_COLUMN); | ||
163 | break; | ||
164 | |||
165 | case TV_COLUMN_RIGHT: | ||
166 | case TV_COLUMN_RIGHT | BUTTON_REPEAT: | ||
167 | /* Scroll right one column */ | ||
168 | tv_scroll_right(TV_HORIZONTAL_SCROLL_COLUMN); | ||
169 | break; | ||
170 | #endif | ||
171 | |||
172 | #ifdef TV_RC_QUIT | ||
173 | case TV_RC_QUIT: | ||
174 | #endif | ||
175 | case TV_QUIT: | ||
176 | #ifdef TV_QUIT2 | ||
177 | case TV_QUIT2: | ||
178 | #endif | ||
179 | tv_exit(NULL); | ||
180 | done = true; | ||
181 | break; | ||
182 | |||
183 | case TV_BOOKMARK: | ||
184 | tv_add_or_remove_bookmark(); | ||
185 | break; | ||
186 | |||
187 | default: | ||
188 | if (rb->default_event_handler_ex(button, tv_exit, NULL) | ||
189 | == SYS_USB_CONNECTED) | ||
190 | return PLUGIN_USB_CONNECTED; | ||
191 | display_update = false; | ||
192 | break; | ||
193 | } | ||
194 | if (button != BUTTON_NONE) | ||
195 | { | ||
196 | lastbutton = button; | ||
197 | rb->yield(); | ||
198 | } | ||
199 | if (autoscroll) | ||
200 | { | ||
201 | if(old_tick <= *rb->current_tick - (110 - prefs->autoscroll_speed * 10)) | ||
202 | { | ||
203 | tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); | ||
204 | old_tick = *rb->current_tick; | ||
205 | display_update = true; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | return PLUGIN_OK; | ||
210 | } | ||