Fix FS#5317. mp3_encoder does now properly encode mono files. Still there is a bug...
[maemo-rb.git] / apps / logfdisp.c
blob8547778f645ea15a486e67f16456b36d55393b9f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #ifdef ROCKBOX_HAS_LOGF
24 #include <file.h>
25 #include <timefuncs.h>
26 #include <string.h>
27 #include <kernel.h>
28 #include <action.h>
30 #include <lcd.h>
31 #include <font.h>
32 #include "menu.h"
33 #include "logf.h"
34 #include "settings.h"
35 #include "logfdisp.h"
36 #include "action.h"
37 #include "splash.h"
39 #ifdef HAVE_LCD_BITMAP
40 int compute_nb_lines(int w, struct font* font)
42 int i, nb_lines;
43 int cur_x, delta_x;
45 if(logfindex == 0 && !logfwrap)
46 return 0;
48 if(logfwrap)
49 i = logfindex;
50 else
51 i = 0;
53 cur_x = 0;
54 nb_lines = 0;
56 do {
57 if(logfbuffer[i] == '\0')
59 cur_x = 0;
60 nb_lines++;
62 else
64 /* does character fit on this line ? */
65 delta_x = font_get_width(font, logfbuffer[i]);
67 if(cur_x + delta_x > w)
69 cur_x = 0;
70 nb_lines++;
73 /* update pointer */
74 cur_x += delta_x;
77 i++;
78 if(i >= MAX_LOGF_SIZE)
79 i = 0;
80 } while(i != logfindex);
82 return nb_lines;
85 bool logfdisplay(void)
87 int action;
88 int w, h, i, index;
89 int fontnr;
90 int cur_x, cur_y, delta_y, delta_x;
91 struct font* font;
92 int user_index;/* user_index will be number of the first line to display (warning: line!=logf entry) */
93 char buf[2];
95 fontnr = lcd_getfont();
96 font = font_get(fontnr);
98 /* get the horizontal size of each line */
99 font_getstringsize("A", NULL, &delta_y, fontnr);
101 buf[1] = '\0';
102 w = LCD_WIDTH;
103 h = LCD_HEIGHT;
104 /* start at the end of the log */
105 user_index = compute_nb_lines(w, font) - h/delta_y -1; /* if negative, will be set 0 to zero later */
107 do {
108 lcd_clear_display();
110 if(user_index < 0)
111 user_index = 0;
113 if(logfwrap)
114 i = logfindex;
115 else
116 i = 0;
118 index = 0;
119 cur_x = 0;
120 cur_y = 0;
122 /* nothing to print ? */
123 if(logfindex == 0 && !logfwrap)
124 goto end_print;
126 do {
127 if(logfbuffer[i] == '\0')
129 /* should be display a newline ? */
130 if(index >= user_index)
131 cur_y += delta_y;
132 cur_x = 0;
133 index++;
135 else
137 /* does character fit on this line ? */
138 delta_x = font_get_width(font, logfbuffer[i]);
140 if(cur_x + delta_x > w)
142 /* should be display a newline ? */
143 if(index >= user_index)
144 cur_y += delta_y;
145 cur_x = 0;
146 index++;
149 /* should we print character ? */
150 if(index >= user_index)
152 buf[0] = logfbuffer[i];
153 lcd_putsxy(cur_x, cur_y, buf);
156 /* update pointer */
157 cur_x += delta_x;
160 /* did we fill the screen ? */
161 if(cur_y > h)
162 break;
164 i++;
165 if(i >= MAX_LOGF_SIZE)
166 i = 0;
167 } while(i != logfindex);
169 end_print:
170 lcd_update();
172 action = get_action(CONTEXT_STD, HZ);
173 switch( action )
175 case ACTION_STD_NEXT:
176 case ACTION_STD_NEXTREPEAT:
177 user_index++;
178 break;
179 case ACTION_STD_PREV:
180 case ACTION_STD_PREVREPEAT:
181 user_index--;
182 break;
183 case ACTION_STD_OK:
184 user_index = 0;
185 break;
186 #ifdef HAVE_TOUCHSCREEN
187 case ACTION_TOUCHSCREEN:
189 short x, y;
190 static int prev_y;
192 action = action_get_touchscreen_press(&x, &y);
194 if(action & BUTTON_REL)
195 prev_y = 0;
196 else
198 if(prev_y != 0)
199 user_index += (prev_y - y) / delta_y;
201 prev_y = y;
204 #endif
205 default:
206 break;
208 } while(action != ACTION_STD_CANCEL);
210 return false;
212 #else /* HAVE_LCD_BITMAP */
213 bool logfdisplay(void)
216 /* TODO: implement a browser for charcell bitmaps */
217 return false;
219 #endif /* HAVE_LCD_BITMAP */
221 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
222 * entries will be "reversed" so that the most recently logged entry is on the
223 * top of the file */
224 bool logfdump(void)
226 int fd;
228 splashf(HZ, "Log File Dumped");
230 /* nothing to print ? */
231 if(logfindex == 0 && !logfwrap)
232 /* nothing is logged just yet */
233 return false;
235 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666);
236 if(-1 != fd) {
237 int i;
239 if(logfwrap)
240 i = logfindex;
241 else
242 i = 0;
244 do {
245 if(logfbuffer[i]=='\0')
246 fdprintf(fd, "\n");
247 else
248 fdprintf(fd, "%c", logfbuffer[i]);
250 i++;
251 if(i >= MAX_LOGF_SIZE)
252 i = 0;
253 } while(i != logfindex);
255 close(fd);
257 return false;
260 #endif /* ROCKBOX_HAS_LOGF */