Fix red introduced with r20610.
[kugel-rb/myfork.git] / apps / screens.c
blob887927486d822d03987ea8284d2c5f7e1c94ae33
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn 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 ****************************************************************************/
22 #include <stdbool.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "backlight.h"
26 #include "action.h"
27 #include "lcd.h"
28 #ifdef HAVE_REMOTE_LCD
29 #include "lcd-remote.h"
30 #endif
31 #include "lang.h"
32 #include "icons.h"
33 #include "font.h"
34 #include "audio.h"
35 #include "mp3_playback.h"
36 #include "usb.h"
37 #include "settings.h"
38 #include "status.h"
39 #include "playlist.h"
40 #include "sprintf.h"
41 #include "kernel.h"
42 #include "power.h"
43 #include "system.h"
44 #include "powermgmt.h"
45 #include "adc.h"
46 #include "action.h"
47 #include "talk.h"
48 #include "misc.h"
49 #include "metadata.h"
50 #include "screens.h"
51 #include "debug.h"
52 #include "led.h"
53 #include "sound.h"
54 #include "splash.h"
55 #include "statusbar.h"
56 #include "screen_access.h"
57 #include "pcmbuf.h"
58 #include "list.h"
59 #include "yesno.h"
60 #include "backdrop.h"
61 #include "viewport.h"
63 #ifdef HAVE_LCD_BITMAP
64 #include "bitmaps/usblogo.h"
65 #endif
67 #ifdef HAVE_REMOTE_LCD
68 #include "bitmaps/remote_usblogo.h"
69 #endif
71 #if (CONFIG_STORAGE & STORAGE_MMC)
72 #include "ata_mmc.h"
73 #endif
74 #if CONFIG_CODEC == SWCODEC
75 #include "dsp.h"
76 #endif
78 #ifdef HAVE_LCD_BITMAP
79 #define SCROLLBAR_WIDTH 6
80 #endif
82 /* only used in set_time screen */
83 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
84 static int clamp_value_wrap(int value, int max, int min)
86 if (value > max)
87 return min;
88 if (value < min)
89 return max;
90 return value;
92 #endif
94 #ifndef SIMULATOR
95 static int handle_usb_events(struct event_queue *q)
97 struct queue_event ev;
98 int next_update=0;
100 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
101 while(1)
103 queue_wait_w_tmo(q, &ev, HZ/4);
104 switch(ev.id)
106 case SYS_USB_DISCONNECTED:
107 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
108 return 0;
109 case SYS_TIMEOUT:
110 break;
112 #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) \
113 && defined(HAVE_USB_POWER)
114 if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON)
116 usb_storage_try_release_storage();
118 #endif
119 if(TIME_AFTER(current_tick,next_update))
121 if(usb_inserted()) {
122 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
123 led(mmc_usb_active(HZ));
124 #endif /* STORAGE_MMC */
125 gui_syncstatusbar_draw(&statusbars, false);
127 next_update=current_tick+HZ/2;
131 #endif
133 void usb_screen(void)
135 #ifdef USB_NONE
136 /* nothing here! */
137 #else
138 int i;
139 bool statusbar = global_settings.statusbar; /* force the statusbar */
140 global_settings.statusbar = true;
141 #if LCD_DEPTH > 1
142 show_main_backdrop();
143 #endif
144 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
145 show_remote_main_backdrop();
146 #endif
147 FOR_NB_SCREENS(i)
149 screens[i].backlight_on();
150 screens[i].clear_display();
151 #if NB_SCREENS > 1
152 if (i == SCREEN_REMOTE)
154 screens[i].bitmap(remote_usblogo,
155 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
156 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
157 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
159 else
161 #endif
162 #ifdef HAVE_LCD_BITMAP
163 screens[i].transparent_bitmap(usblogo,
164 (LCD_WIDTH-BMPWIDTH_usblogo),
165 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
166 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
167 #else
168 screens[i].double_height(false);
169 screens[i].puts_scroll(0, 0, "[USB Mode]");
170 status_set_param(false);
171 status_set_audio(false);
172 status_set_usb(true);
173 #endif /* HAVE_LCD_BITMAP */
174 #if NB_SCREENS > 1
176 #endif
177 screens[i].update();
180 #ifdef SIMULATOR
181 while (button_get(true) & BUTTON_REL);
182 #else
183 usb_acknowledge(SYS_USB_CONNECTED_ACK);
184 while(handle_usb_events(&button_queue));
185 #endif /* SIMULATOR */
186 #ifdef HAVE_LCD_CHARCELLS
187 status_set_usb(false);
188 #endif /* HAVE_LCD_CHARCELLS */
189 FOR_NB_SCREENS(i)
190 screens[i].backlight_on();
191 global_settings.statusbar = statusbar;
192 #endif /* USB_NONE */
195 #if (CONFIG_STORAGE & STORAGE_MMC)
196 int mmc_remove_request(void)
198 struct queue_event ev;
199 int i;
200 FOR_NB_SCREENS(i)
201 screens[i].clear_display();
202 splash(0, ID2P(LANG_REMOVE_MMC));
204 while (1)
206 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
207 switch (ev.id)
209 case SYS_HOTSWAP_EXTRACTED:
210 return SYS_HOTSWAP_EXTRACTED;
212 case SYS_USB_DISCONNECTED:
213 return SYS_USB_DISCONNECTED;
217 #endif
219 /* the charging screen is only used for archos targets */
220 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
222 #ifdef HAVE_LCD_BITMAP
223 static void charging_display_info(bool animate)
225 unsigned char charging_logo[36];
226 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
227 const int pox_y = 32;
228 static unsigned phase = 3;
229 unsigned i;
230 char buf[32];
231 (void)buf;
233 #ifdef NEED_ATA_POWER_BATT_MEASURE
234 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
235 #endif
237 int battv = battery_voltage();
238 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
239 (battv % 1000) / 10, battery_level());
240 lcd_puts(0, 7, buf);
243 #ifdef ARCHOS_RECORER
244 snprintf(buf, 32, "Charge mode:");
245 lcd_puts(0, 2, buf);
247 if (charge_state == CHARGING)
248 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
249 else if (charge_state == TOPOFF)
250 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
251 else if (charge_state == TRICKLE)
252 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
253 else
254 snprintf(buf, 32, "not charging");
256 lcd_puts(0, 3, buf);
257 if (!charger_enabled())
258 animate = false;
259 #endif /* ARCHOS_RECORER */
261 /* middle part */
262 memset(charging_logo+3, 0x00, 32);
263 charging_logo[0] = 0x3C;
264 charging_logo[1] = 0x24;
265 charging_logo[2] = charging_logo[35] = 0xFF;
267 if (!animate)
268 { /* draw the outline */
269 /* middle part */
270 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
271 sizeof(charging_logo), 8);
272 lcd_set_drawmode(DRMODE_FG);
273 /* upper line */
274 charging_logo[0] = charging_logo[1] = 0x00;
275 memset(charging_logo+2, 0x80, 34);
276 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
277 /* lower line */
278 memset(charging_logo+2, 0x01, 34);
279 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
280 sizeof(charging_logo), 8);
281 lcd_set_drawmode(DRMODE_SOLID);
283 else
284 { /* animate the middle part */
285 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
287 if ((i-phase) % 8 == 0)
288 { /* draw a "bubble" here */
289 unsigned bitpos;
290 bitpos = (phase + i/8) % 15; /* "bounce" effect */
291 if (bitpos > 7)
292 bitpos = 14 - bitpos;
293 charging_logo[i] = 0x01 << bitpos;
296 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
297 sizeof(charging_logo), 8);
298 phase++;
300 lcd_update();
302 #else /* not HAVE_LCD_BITMAP */
304 static unsigned long logo_chars[4];
305 static const unsigned char logo_pattern[] = {
306 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
307 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
308 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
309 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
312 static void logo_lock_patterns(bool on)
314 int i;
316 if (on)
318 for (i = 0; i < 4; i++)
319 logo_chars[i] = lcd_get_locked_pattern();
321 else
323 for (i = 0; i < 4; i++)
324 lcd_unlock_pattern(logo_chars[i]);
328 static void charging_display_info(bool animate)
330 int battv;
331 unsigned i, ypos;
332 static unsigned phase = 3;
333 char buf[32];
335 battv = battery_voltage();
336 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
337 lcd_puts(4, 1, buf);
339 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
341 if (!animate) /* build the screen */
343 lcd_double_height(false);
344 lcd_puts(0, 0, "[Charging]");
345 for (i = 0; i < 4; i++)
346 lcd_putc(i, 1, logo_chars[i]);
348 else /* animate the logo */
350 for (i = 3; i < MIN(19, phase); i++)
352 if ((i - phase) % 5 == 0)
353 { /* draw a "bubble" here */
354 ypos = (phase + i/5) % 9; /* "bounce" effect */
355 if (ypos > 4)
356 ypos = 8 - ypos;
357 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
360 phase++;
363 for (i = 0; i < 4; i++)
364 lcd_define_pattern(logo_chars[i], buf + 8 * i);
366 lcd_update();
368 #endif /* (not) HAVE_LCD_BITMAP */
370 /* blocks while charging, returns on event:
371 1 if charger cable was removed
372 2 if Off/Stop key was pressed
373 3 if On key was pressed
374 4 if USB was connected */
376 int charging_screen(void)
378 unsigned int button;
379 int rc = 0;
381 ide_power_enable(false); /* power down the disk, else would be spinning */
383 lcd_clear_display();
384 backlight_set_timeout(global_settings.backlight_timeout);
385 #ifdef HAVE_REMOTE_LCD
386 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
387 #endif
388 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
390 #ifdef HAVE_LCD_CHARCELLS
391 logo_lock_patterns(true);
392 #endif
393 charging_display_info(false);
397 gui_syncstatusbar_draw(&statusbars, false);
398 charging_display_info(true);
399 button = get_action(CONTEXT_STD,HZ/3);
400 if (button == ACTION_STD_OK)
401 rc = 2;
402 else if (usb_detect() == USB_INSERTED)
403 rc = 3;
404 else if (!charger_inserted())
405 rc = 1;
406 } while (!rc);
408 #ifdef HAVE_LCD_CHARCELLS
409 logo_lock_patterns(false);
410 #endif
411 return rc;
413 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
415 #if CONFIG_CHARGING
416 void charging_splash(void)
418 splash(2*HZ, str(LANG_BATTERY_CHARGE));
419 button_clear_queue();
421 #endif
424 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
426 /* little helper function for voice output */
427 static void say_time(int cursorpos, const struct tm *tm)
429 int value = 0;
430 int unit = 0;
432 if (!global_settings.talk_menu)
433 return;
435 switch(cursorpos)
437 case 0:
438 value = tm->tm_hour;
439 unit = UNIT_HOUR;
440 break;
441 case 1:
442 value = tm->tm_min;
443 unit = UNIT_MIN;
444 break;
445 case 2:
446 value = tm->tm_sec;
447 unit = UNIT_SEC;
448 break;
449 case 3:
450 value = tm->tm_year + 1900;
451 break;
452 case 5:
453 value = tm->tm_mday;
454 break;
457 if (cursorpos == 4) /* month */
458 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
459 else
460 talk_value(value, unit, false);
464 #define INDEX_X 0
465 #define INDEX_Y 1
467 #define SEPARATOR ":"
468 bool set_time_screen(const char* title, struct tm *tm)
470 bool done = false;
471 int button;
472 unsigned int i, j, s;
473 int cursorpos = 0;
474 unsigned int julianday;
475 unsigned int realyear;
476 unsigned int width;
477 unsigned int min, max;
478 unsigned int statusbar_height = 0;
479 unsigned int separator_width, weekday_width;
480 unsigned int prev_line_height;
481 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
482 unsigned char buffer[20];
483 struct viewport vp[NB_SCREENS];
484 int nb_lines;
486 /* 6 possible cursor possitions, 2 values stored for each: x, y */
487 unsigned int cursor[6][2];
489 int *valptr = NULL;
490 unsigned char *ptr[6];
492 if(global_settings.statusbar)
493 statusbar_height = STATUSBAR_HEIGHT;
495 /* speak selection when screen is entered */
496 say_time(cursorpos, tm);
498 while (!done) {
499 /* for easy acess in the drawing loop */
500 ptr[0] = buffer; /* hours */
501 ptr[1] = buffer + 3; /* minutes */
502 ptr[2] = buffer + 6; /* seconds */
503 ptr[3] = buffer + 9; /* year */
504 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
505 ptr[5] = buffer + 14; /* day of month */
507 /* calculate the number of days in febuary */
508 realyear = tm->tm_year + 1900;
509 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
510 daysinmonth[1] = 29;
511 else
512 daysinmonth[1] = 28;
514 /* fix day if month or year changed */
515 if (tm->tm_mday > daysinmonth[tm->tm_mon])
516 tm->tm_mday = daysinmonth[tm->tm_mon];
518 /* calculate day of week */
519 julianday = tm->tm_mday;
520 for(i = 0; (int)i < tm->tm_mon; i++) {
521 julianday += daysinmonth[i];
524 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
525 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
527 /* put all the numbers we want from the tm struct into
528 an easily printable buffer */
529 snprintf(buffer, sizeof(buffer),
530 "%02d " "%02d " "%02d " "%04d " "%02d",
531 tm->tm_hour, tm->tm_min, tm->tm_sec,
532 tm->tm_year+1900, tm->tm_mday);
534 /* convert spaces in the buffer to '\0' to make it possible to work
535 directly on the buffer */
536 for(i=0; i < sizeof(buffer); i++)
538 if(buffer[i] == ' ')
539 buffer[i] = '\0';
542 FOR_NB_SCREENS(s)
544 viewport_set_defaults(&vp[s], s);
545 screens[s].set_viewport(&vp[s]);
546 nb_lines = viewport_get_nb_lines(&vp[s]);
548 /* minimum lines needed is 2 + title line */
549 if (nb_lines < 4)
551 vp[s].font = FONT_SYSFIXED;
552 nb_lines = viewport_get_nb_lines(&vp[s]);
555 /* recalculate the positions and offsets */
556 if (nb_lines >= 3)
557 screens[s].getstringsize(title, NULL, &prev_line_height);
558 else
559 prev_line_height = 0;
561 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
563 /* weekday */
564 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
565 &weekday_width, NULL);
566 screens[s].getstringsize(" ", &separator_width, NULL);
568 for(i=0, j=0; i < 6; i++)
570 if(i==3) /* second row */
572 j = weekday_width + separator_width;
573 prev_line_height *= 2;
575 screens[s].getstringsize(ptr[i], &width, NULL);
576 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
577 cursor[i][INDEX_X] = j;
578 j += width + separator_width;
581 /* draw the screen */
582 screens[s].set_viewport(&vp[s]);
583 screens[s].clear_viewport();
584 /* display the screen title */
585 screens[s].puts_scroll(0, 0, title);
587 /* these are not selectable, so we draw them outside the loop */
588 /* name of the week day */
589 screens[s].putsxy(0, cursor[3][INDEX_Y],
590 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
592 /* draw the selected item with drawmode set to
593 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
594 items with drawmode DRMODE_SOLID */
595 for(i=0; i<6; i++)
597 if (cursorpos == (int)i)
598 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
600 screens[s].putsxy(cursor[i][INDEX_X],
601 cursor[i][INDEX_Y], ptr[i]);
603 vp[s].drawmode = DRMODE_SOLID;
605 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
606 cursor[0][INDEX_Y], SEPARATOR);
609 /* print help text */
610 if (nb_lines > 4)
611 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
612 if (nb_lines > 5)
613 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
614 screens[s].update_viewport();
615 screens[s].set_viewport(NULL);
618 /* set the most common numbers */
619 min = 0;
620 max = 59;
621 /* calculate the minimum and maximum for the number under cursor */
622 switch(cursorpos) {
623 case 0: /* hour */
624 max = 23;
625 valptr = &tm->tm_hour;
626 break;
627 case 1: /* minute */
628 valptr = &tm->tm_min;
629 break;
630 case 2: /* second */
631 valptr = &tm->tm_sec;
632 break;
633 case 3: /* year */
634 min = 1;
635 max = 200;
636 valptr = &tm->tm_year;
637 break;
638 case 4: /* month */
639 max = 11;
640 valptr = &tm->tm_mon;
641 break;
642 case 5: /* day */
643 min = 1;
644 max = daysinmonth[tm->tm_mon];
645 valptr = &tm->tm_mday;
646 break;
649 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
650 switch ( button ) {
651 case ACTION_STD_PREV:
652 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
653 say_time(cursorpos, tm);
654 break;
655 case ACTION_STD_NEXT:
656 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
657 say_time(cursorpos, tm);
658 break;
659 case ACTION_SETTINGS_INC:
660 case ACTION_SETTINGS_INCREPEAT:
661 *valptr = clamp_value_wrap(++(*valptr), max, min);
662 say_time(cursorpos, tm);
663 break;
664 case ACTION_SETTINGS_DEC:
665 case ACTION_SETTINGS_DECREPEAT:
666 *valptr = clamp_value_wrap(--(*valptr), max, min);
667 say_time(cursorpos, tm);
668 break;
670 case ACTION_STD_OK:
671 done = true;
672 break;
674 case ACTION_STD_CANCEL:
675 done = true;
676 tm->tm_year = -1;
677 break;
679 default:
680 if (default_event_handler(button) == SYS_USB_CONNECTED)
681 return true;
682 break;
685 return false;
687 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
689 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
690 bool shutdown_screen(void)
692 int button;
693 bool done = false;
694 long time_entered = current_tick;
696 lcd_stop_scroll();
698 splash(0, str(LANG_CONFIRM_SHUTDOWN));
700 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
702 button = get_action(CONTEXT_STD,HZ);
703 switch(button)
705 case ACTION_STD_CANCEL:
706 sys_poweroff();
707 break;
709 /* do nothing here, because ACTION_NONE might be caused
710 * by timeout or button release. In case of timeout the loop
711 * is terminated by TIME_BEFORE */
712 case ACTION_NONE:
713 break;
715 default:
716 if(default_event_handler(button) == SYS_USB_CONNECTED)
717 return true;
718 done = true;
719 break;
722 return false;
724 #endif
726 static const int id3_headers[]=
728 LANG_ID3_TITLE,
729 LANG_ID3_ARTIST,
730 LANG_ID3_ALBUM,
731 LANG_ID3_ALBUMARTIST,
732 LANG_ID3_GROUPING,
733 LANG_ID3_DISCNUM,
734 LANG_ID3_TRACKNUM,
735 LANG_ID3_COMMENT,
736 LANG_ID3_GENRE,
737 LANG_ID3_YEAR,
738 LANG_ID3_LENGTH,
739 LANG_ID3_PLAYLIST,
740 LANG_ID3_BITRATE,
741 LANG_ID3_FREQUENCY,
742 #if CONFIG_CODEC == SWCODEC
743 LANG_ID3_TRACK_GAIN,
744 LANG_ID3_ALBUM_GAIN,
745 #endif
746 LANG_ID3_PATH,
748 struct id3view_info {
749 struct mp3entry* id3;
750 int count;
751 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
753 static char * id3_get_info(int selected_item, void* data,
754 char *buffer, size_t buffer_len)
756 struct id3view_info *info = (struct id3view_info*)data;
757 struct mp3entry* id3 =info->id3;
758 int info_no=selected_item/2;
759 if(!(selected_item%2))
760 {/* header */
761 return( str(id3_headers[info->info_id[info_no]]));
763 else
764 {/* data */
766 char * val=NULL;
767 switch(info->info_id[info_no])
769 case 0:/*LANG_ID3_TITLE*/
770 val=id3->title;
771 break;
772 case 1:/*LANG_ID3_ARTIST*/
773 val=id3->artist;
774 break;
775 case 2:/*LANG_ID3_ALBUM*/
776 val=id3->album;
777 break;
778 case 3:/*LANG_ID3_ALBUMARTIST*/
779 val=id3->albumartist;
780 break;
781 case 4:/*LANG_ID3_GROUPING*/
782 val=id3->grouping;
783 break;
784 case 5:/*LANG_ID3_DISCNUM*/
785 if (id3->disc_string)
786 val = id3->disc_string;
787 else if (id3->discnum)
789 snprintf(buffer, buffer_len, "%d", id3->discnum);
790 val = buffer;
792 break;
793 case 6:/*LANG_ID3_TRACKNUM*/
794 if (id3->track_string)
795 val = id3->track_string;
796 else if (id3->tracknum)
798 snprintf(buffer, buffer_len, "%d", id3->tracknum);
799 val = buffer;
801 break;
802 case 7:/*LANG_ID3_COMMENT*/
803 val=id3->comment;
804 break;
805 case 8:/*LANG_ID3_GENRE*/
806 val = id3->genre_string;
807 break;
808 case 9:/*LANG_ID3_YEAR*/
809 if (id3->year_string)
810 val = id3->year_string;
811 else if (id3->year)
813 snprintf(buffer, buffer_len, "%d", id3->year);
814 val = buffer;
816 break;
817 case 10:/*LANG_ID3_LENGTH*/
818 format_time(buffer, buffer_len, id3->length);
819 val=buffer;
820 break;
821 case 11:/*LANG_ID3_PLAYLIST*/
822 snprintf(buffer, buffer_len, "%d/%d",
823 playlist_get_display_index(), playlist_amount());
824 val=buffer;
825 break;
826 case 12:/*LANG_ID3_BITRATE*/
827 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
828 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
829 val=buffer;
830 break;
831 case 13:/*LANG_ID3_FREQUENCY*/
832 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
833 val=buffer;
834 break;
835 #if CONFIG_CODEC == SWCODEC
836 case 14:/*LANG_ID3_TRACK_GAIN*/
837 val=id3->track_gain_string;
838 break;
839 case 15:/*LANG_ID3_ALBUM_GAIN*/
840 val=id3->album_gain_string;
841 break;
842 case 16:/*LANG_ID3_PATH*/
843 #else
844 case 14:/*LANG_ID3_PATH*/
845 #endif
846 val=id3->path;
847 break;
849 return val && *val ? val : NULL;
853 bool browse_id3(void)
855 struct gui_synclist id3_lists;
856 struct mp3entry* id3 = audio_current_track();
857 int key;
858 unsigned int i;
859 struct id3view_info info;
860 info.count = 0;
861 info.id3 = id3;
862 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
864 char temp[8];
865 info.info_id[i] = i;
866 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
867 info.info_id[info.count++] = i;
870 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
871 gui_synclist_set_nb_items(&id3_lists, info.count*2);
872 gui_synclist_draw(&id3_lists);
873 while (true) {
874 key = get_action(CONTEXT_LIST,HZ/2);
875 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
876 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
878 return(default_event_handler(key) == SYS_USB_CONNECTED);
883 static char* runtime_get_data(int selected_item, void* data,
884 char* buffer, size_t buffer_len)
886 (void)data;
887 int t;
888 switch (selected_item)
890 case 0: return str(LANG_RUNNING_TIME);
891 case 1: t = global_status.runtime; break;
892 case 2: return str(LANG_TOP_TIME);
893 case 3: t = global_status.topruntime; break;
894 default:
895 return "";
898 snprintf(buffer, buffer_len, "%dh %dm %ds",
899 t / 3600, (t % 3600) / 60, t % 60);
900 return buffer;
903 static int runtime_speak_data(int selected_item, void* data)
905 (void) data;
906 talk_ids(false,
907 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
908 TALK_ID((selected_item < 2) ? global_status.runtime
909 : global_status.topruntime, UNIT_TIME));
910 return 0;
914 bool view_runtime(void)
916 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
917 static const struct text_message message={lines, 1};
919 struct gui_synclist lists;
920 int action;
921 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
922 #if !defined(HAVE_LCD_CHARCELLS)
923 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
924 #else
925 gui_synclist_set_title(&lists, NULL, NOICON);
926 #endif
927 if(global_settings.talk_menu)
928 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
929 gui_synclist_set_icon_callback(&lists, NULL);
930 gui_synclist_set_nb_items(&lists, 4);
931 gui_synclist_speak_item(&lists);
932 while(1)
934 #if CONFIG_CHARGING
935 if (charger_inserted())
937 global_status.runtime = 0;
939 else
940 #endif
942 global_status.runtime += ((current_tick - lasttime) / HZ);
944 lasttime = current_tick;
945 gui_synclist_draw(&lists);
946 list_do_action(CONTEXT_STD, HZ,
947 &lists, &action, LIST_WRAP_UNLESS_HELD);
948 if(action == ACTION_STD_CANCEL)
949 break;
950 if(action == ACTION_STD_OK) {
951 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
953 if (!(gui_synclist_get_sel_pos(&lists)/2))
954 global_status.runtime = 0;
955 else
956 global_status.topruntime = 0;
957 gui_synclist_speak_item(&lists);
960 if(default_event_handler(action) == SYS_USB_CONNECTED)
961 return true;
963 return false;