Add a missing phrase (LANG_CREDITS)
[kugel-rb/myfork.git] / apps / screens.c
blobe4eeb1f3836d7fa2b9eccf4edf605e2dee7bf950
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 int handle_usb_events(struct event_queue *q)
96 struct queue_event ev;
97 int next_update=0;
99 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
100 while(1)
102 queue_wait_w_tmo(q, &ev, HZ/4);
103 switch(ev.id)
105 case SYS_USB_DISCONNECTED:
106 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
107 return 0;
108 case SYS_TIMEOUT:
109 break;
111 #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) \
112 && defined(HAVE_USB_POWER)
113 if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON)
115 usb_storage_try_release_storage();
117 #endif
118 if(TIME_AFTER(current_tick,next_update))
120 if(usb_inserted()) {
121 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
122 led(mmc_usb_active(HZ));
123 #endif /* STORAGE_MMC */
124 gui_syncstatusbar_draw(&statusbars, false);
126 next_update=current_tick+HZ/2;
131 void usb_screen(void)
133 #ifdef USB_NONE
134 /* nothing here! */
135 #else
136 int i;
137 bool statusbar = global_settings.statusbar; /* force the statusbar */
138 global_settings.statusbar = true;
139 #if LCD_DEPTH > 1
140 show_main_backdrop();
141 #endif
142 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
143 show_remote_main_backdrop();
144 #endif
145 FOR_NB_SCREENS(i)
147 screens[i].backlight_on();
148 screens[i].clear_display();
149 #if NB_SCREENS > 1
150 if (i == SCREEN_REMOTE)
152 screens[i].bitmap(remote_usblogo,
153 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
154 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
155 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
157 else
159 #endif
160 #ifdef HAVE_LCD_BITMAP
161 screens[i].transparent_bitmap(usblogo,
162 (LCD_WIDTH-BMPWIDTH_usblogo),
163 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
164 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
165 #else
166 screens[i].double_height(false);
167 screens[i].puts_scroll(0, 0, "[USB Mode]");
168 status_set_param(false);
169 status_set_audio(false);
170 status_set_usb(true);
171 #endif /* HAVE_LCD_BITMAP */
172 #if NB_SCREENS > 1
174 #endif
175 screens[i].update();
178 #ifdef SIMULATOR
179 while (button_get(true) & BUTTON_REL);
180 #else
181 usb_acknowledge(SYS_USB_CONNECTED_ACK);
182 while(handle_usb_events(&button_queue));
183 #endif /* SIMULATOR */
184 #ifdef HAVE_LCD_CHARCELLS
185 status_set_usb(false);
186 #endif /* HAVE_LCD_CHARCELLS */
187 FOR_NB_SCREENS(i)
188 screens[i].backlight_on();
189 global_settings.statusbar = statusbar;
190 #endif /* USB_NONE */
193 #if (CONFIG_STORAGE & STORAGE_MMC)
194 int mmc_remove_request(void)
196 struct queue_event ev;
197 int i;
198 FOR_NB_SCREENS(i)
199 screens[i].clear_display();
200 splash(0, ID2P(LANG_REMOVE_MMC));
202 while (1)
204 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
205 switch (ev.id)
207 case SYS_HOTSWAP_EXTRACTED:
208 return SYS_HOTSWAP_EXTRACTED;
210 case SYS_USB_DISCONNECTED:
211 return SYS_USB_DISCONNECTED;
215 #endif
217 /* the charging screen is only used for archos targets */
218 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
220 #ifdef HAVE_LCD_BITMAP
221 static void charging_display_info(bool animate)
223 unsigned char charging_logo[36];
224 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
225 const int pox_y = 32;
226 static unsigned phase = 3;
227 unsigned i;
228 char buf[32];
229 (void)buf;
231 #ifdef NEED_ATA_POWER_BATT_MEASURE
232 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
233 #endif
235 int battv = battery_voltage();
236 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
237 (battv % 1000) / 10, battery_level());
238 lcd_puts(0, 7, buf);
241 #ifdef ARCHOS_RECORER
242 snprintf(buf, 32, "Charge mode:");
243 lcd_puts(0, 2, buf);
245 if (charge_state == CHARGING)
246 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
247 else if (charge_state == TOPOFF)
248 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
249 else if (charge_state == TRICKLE)
250 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
251 else
252 snprintf(buf, 32, "not charging");
254 lcd_puts(0, 3, buf);
255 if (!charger_enabled())
256 animate = false;
257 #endif /* ARCHOS_RECORER */
259 /* middle part */
260 memset(charging_logo+3, 0x00, 32);
261 charging_logo[0] = 0x3C;
262 charging_logo[1] = 0x24;
263 charging_logo[2] = charging_logo[35] = 0xFF;
265 if (!animate)
266 { /* draw the outline */
267 /* middle part */
268 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
269 sizeof(charging_logo), 8);
270 lcd_set_drawmode(DRMODE_FG);
271 /* upper line */
272 charging_logo[0] = charging_logo[1] = 0x00;
273 memset(charging_logo+2, 0x80, 34);
274 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
275 /* lower line */
276 memset(charging_logo+2, 0x01, 34);
277 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
278 sizeof(charging_logo), 8);
279 lcd_set_drawmode(DRMODE_SOLID);
281 else
282 { /* animate the middle part */
283 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
285 if ((i-phase) % 8 == 0)
286 { /* draw a "bubble" here */
287 unsigned bitpos;
288 bitpos = (phase + i/8) % 15; /* "bounce" effect */
289 if (bitpos > 7)
290 bitpos = 14 - bitpos;
291 charging_logo[i] = 0x01 << bitpos;
294 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
295 sizeof(charging_logo), 8);
296 phase++;
298 lcd_update();
300 #else /* not HAVE_LCD_BITMAP */
302 static unsigned long logo_chars[4];
303 static const unsigned char logo_pattern[] = {
304 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
305 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
306 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
307 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
310 static void logo_lock_patterns(bool on)
312 int i;
314 if (on)
316 for (i = 0; i < 4; i++)
317 logo_chars[i] = lcd_get_locked_pattern();
319 else
321 for (i = 0; i < 4; i++)
322 lcd_unlock_pattern(logo_chars[i]);
326 static void charging_display_info(bool animate)
328 int battv;
329 unsigned i, ypos;
330 static unsigned phase = 3;
331 char buf[32];
333 battv = battery_voltage();
334 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
335 lcd_puts(4, 1, buf);
337 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
339 if (!animate) /* build the screen */
341 lcd_double_height(false);
342 lcd_puts(0, 0, "[Charging]");
343 for (i = 0; i < 4; i++)
344 lcd_putc(i, 1, logo_chars[i]);
346 else /* animate the logo */
348 for (i = 3; i < MIN(19, phase); i++)
350 if ((i - phase) % 5 == 0)
351 { /* draw a "bubble" here */
352 ypos = (phase + i/5) % 9; /* "bounce" effect */
353 if (ypos > 4)
354 ypos = 8 - ypos;
355 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
358 phase++;
361 for (i = 0; i < 4; i++)
362 lcd_define_pattern(logo_chars[i], buf + 8 * i);
364 lcd_update();
366 #endif /* (not) HAVE_LCD_BITMAP */
368 /* blocks while charging, returns on event:
369 1 if charger cable was removed
370 2 if Off/Stop key was pressed
371 3 if On key was pressed
372 4 if USB was connected */
374 int charging_screen(void)
376 unsigned int button;
377 int rc = 0;
379 ide_power_enable(false); /* power down the disk, else would be spinning */
381 lcd_clear_display();
382 backlight_set_timeout(global_settings.backlight_timeout);
383 #ifdef HAVE_REMOTE_LCD
384 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
385 #endif
386 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
388 #ifdef HAVE_LCD_CHARCELLS
389 logo_lock_patterns(true);
390 #endif
391 charging_display_info(false);
395 gui_syncstatusbar_draw(&statusbars, false);
396 charging_display_info(true);
397 button = get_action(CONTEXT_STD,HZ/3);
398 if (button == ACTION_STD_OK)
399 rc = 2;
400 else if (usb_detect() == USB_INSERTED)
401 rc = 3;
402 else if (!charger_inserted())
403 rc = 1;
404 } while (!rc);
406 #ifdef HAVE_LCD_CHARCELLS
407 logo_lock_patterns(false);
408 #endif
409 return rc;
411 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
413 #if CONFIG_CHARGING
414 void charging_splash(void)
416 splash(2*HZ, str(LANG_BATTERY_CHARGE));
417 button_clear_queue();
419 #endif
422 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
424 /* little helper function for voice output */
425 static void say_time(int cursorpos, const struct tm *tm)
427 int value = 0;
428 int unit = 0;
430 if (!global_settings.talk_menu)
431 return;
433 switch(cursorpos)
435 case 0:
436 value = tm->tm_hour;
437 unit = UNIT_HOUR;
438 break;
439 case 1:
440 value = tm->tm_min;
441 unit = UNIT_MIN;
442 break;
443 case 2:
444 value = tm->tm_sec;
445 unit = UNIT_SEC;
446 break;
447 case 3:
448 value = tm->tm_year + 1900;
449 break;
450 case 5:
451 value = tm->tm_mday;
452 break;
455 if (cursorpos == 4) /* month */
456 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
457 else
458 talk_value(value, unit, false);
462 #define INDEX_X 0
463 #define INDEX_Y 1
465 #define SEPARATOR ":"
466 bool set_time_screen(const char* title, struct tm *tm)
468 bool done = false;
469 int button;
470 unsigned int i, j, s;
471 int cursorpos = 0;
472 unsigned int julianday;
473 unsigned int realyear;
474 unsigned int width;
475 unsigned int min, max;
476 unsigned int statusbar_height = 0;
477 unsigned int separator_width, weekday_width;
478 unsigned int prev_line_height;
479 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
480 unsigned char buffer[20];
481 struct viewport vp[NB_SCREENS];
482 int nb_lines;
484 /* 6 possible cursor possitions, 2 values stored for each: x, y */
485 unsigned int cursor[6][2];
487 int *valptr = NULL;
488 unsigned char *ptr[6];
490 if(global_settings.statusbar)
491 statusbar_height = STATUSBAR_HEIGHT;
493 /* speak selection when screen is entered */
494 say_time(cursorpos, tm);
496 while (!done) {
497 /* for easy acess in the drawing loop */
498 ptr[0] = buffer; /* hours */
499 ptr[1] = buffer + 3; /* minutes */
500 ptr[2] = buffer + 6; /* seconds */
501 ptr[3] = buffer + 9; /* year */
502 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
503 ptr[5] = buffer + 14; /* day of month */
505 /* calculate the number of days in febuary */
506 realyear = tm->tm_year + 1900;
507 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
508 daysinmonth[1] = 29;
509 else
510 daysinmonth[1] = 28;
512 /* fix day if month or year changed */
513 if (tm->tm_mday > daysinmonth[tm->tm_mon])
514 tm->tm_mday = daysinmonth[tm->tm_mon];
516 /* calculate day of week */
517 julianday = tm->tm_mday;
518 for(i = 0; (int)i < tm->tm_mon; i++) {
519 julianday += daysinmonth[i];
522 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
523 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
525 /* put all the numbers we want from the tm struct into
526 an easily printable buffer */
527 snprintf(buffer, sizeof(buffer),
528 "%02d " "%02d " "%02d " "%04d " "%02d",
529 tm->tm_hour, tm->tm_min, tm->tm_sec,
530 tm->tm_year+1900, tm->tm_mday);
532 /* convert spaces in the buffer to '\0' to make it possible to work
533 directly on the buffer */
534 for(i=0; i < sizeof(buffer); i++)
536 if(buffer[i] == ' ')
537 buffer[i] = '\0';
540 FOR_NB_SCREENS(s)
542 viewport_set_defaults(&vp[s], s);
543 screens[s].set_viewport(&vp[s]);
544 nb_lines = viewport_get_nb_lines(&vp[s]);
546 /* minimum lines needed is 2 + title line */
547 if (nb_lines < 4)
549 vp[s].font = FONT_SYSFIXED;
550 nb_lines = viewport_get_nb_lines(&vp[s]);
553 /* recalculate the positions and offsets */
554 if (nb_lines >= 3)
555 screens[s].getstringsize(title, NULL, &prev_line_height);
556 else
557 prev_line_height = 0;
559 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
561 /* weekday */
562 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
563 &weekday_width, NULL);
564 screens[s].getstringsize(" ", &separator_width, NULL);
566 for(i=0, j=0; i < 6; i++)
568 if(i==3) /* second row */
570 j = weekday_width + separator_width;
571 prev_line_height *= 2;
573 screens[s].getstringsize(ptr[i], &width, NULL);
574 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
575 cursor[i][INDEX_X] = j;
576 j += width + separator_width;
579 /* draw the screen */
580 screens[s].set_viewport(&vp[s]);
581 screens[s].clear_viewport();
582 /* display the screen title */
583 screens[s].puts_scroll(0, 0, title);
585 /* these are not selectable, so we draw them outside the loop */
586 /* name of the week day */
587 screens[s].putsxy(0, cursor[3][INDEX_Y],
588 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
590 /* draw the selected item with drawmode set to
591 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
592 items with drawmode DRMODE_SOLID */
593 for(i=0; i<6; i++)
595 if (cursorpos == (int)i)
596 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
598 screens[s].putsxy(cursor[i][INDEX_X],
599 cursor[i][INDEX_Y], ptr[i]);
601 vp[s].drawmode = DRMODE_SOLID;
603 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
604 cursor[0][INDEX_Y], SEPARATOR);
607 /* print help text */
608 if (nb_lines > 4)
609 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
610 if (nb_lines > 5)
611 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
612 screens[s].update_viewport();
613 screens[s].set_viewport(NULL);
616 /* set the most common numbers */
617 min = 0;
618 max = 59;
619 /* calculate the minimum and maximum for the number under cursor */
620 switch(cursorpos) {
621 case 0: /* hour */
622 max = 23;
623 valptr = &tm->tm_hour;
624 break;
625 case 1: /* minute */
626 valptr = &tm->tm_min;
627 break;
628 case 2: /* second */
629 valptr = &tm->tm_sec;
630 break;
631 case 3: /* year */
632 min = 1;
633 max = 200;
634 valptr = &tm->tm_year;
635 break;
636 case 4: /* month */
637 max = 11;
638 valptr = &tm->tm_mon;
639 break;
640 case 5: /* day */
641 min = 1;
642 max = daysinmonth[tm->tm_mon];
643 valptr = &tm->tm_mday;
644 break;
647 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
648 switch ( button ) {
649 case ACTION_STD_PREV:
650 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
651 say_time(cursorpos, tm);
652 break;
653 case ACTION_STD_NEXT:
654 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
655 say_time(cursorpos, tm);
656 break;
657 case ACTION_SETTINGS_INC:
658 case ACTION_SETTINGS_INCREPEAT:
659 *valptr = clamp_value_wrap(++(*valptr), max, min);
660 say_time(cursorpos, tm);
661 break;
662 case ACTION_SETTINGS_DEC:
663 case ACTION_SETTINGS_DECREPEAT:
664 *valptr = clamp_value_wrap(--(*valptr), max, min);
665 say_time(cursorpos, tm);
666 break;
668 case ACTION_STD_OK:
669 done = true;
670 break;
672 case ACTION_STD_CANCEL:
673 done = true;
674 tm->tm_year = -1;
675 break;
677 default:
678 if (default_event_handler(button) == SYS_USB_CONNECTED)
679 return true;
680 break;
683 return false;
685 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
687 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
688 bool shutdown_screen(void)
690 int button;
691 bool done = false;
692 long time_entered = current_tick;
694 lcd_stop_scroll();
696 splash(0, str(LANG_CONFIRM_SHUTDOWN));
698 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
700 button = get_action(CONTEXT_STD,HZ);
701 switch(button)
703 case ACTION_STD_CANCEL:
704 sys_poweroff();
705 break;
707 /* do nothing here, because ACTION_NONE might be caused
708 * by timeout or button release. In case of timeout the loop
709 * is terminated by TIME_BEFORE */
710 case ACTION_NONE:
711 break;
713 default:
714 if(default_event_handler(button) == SYS_USB_CONNECTED)
715 return true;
716 done = true;
717 break;
720 return false;
722 #endif
724 static const int id3_headers[]=
726 LANG_ID3_TITLE,
727 LANG_ID3_ARTIST,
728 LANG_ID3_ALBUM,
729 LANG_ID3_ALBUMARTIST,
730 LANG_ID3_GROUPING,
731 LANG_ID3_DISCNUM,
732 LANG_ID3_TRACKNUM,
733 LANG_ID3_COMMENT,
734 LANG_ID3_GENRE,
735 LANG_ID3_YEAR,
736 LANG_ID3_LENGTH,
737 LANG_ID3_PLAYLIST,
738 LANG_ID3_BITRATE,
739 LANG_ID3_FREQUENCY,
740 #if CONFIG_CODEC == SWCODEC
741 LANG_ID3_TRACK_GAIN,
742 LANG_ID3_ALBUM_GAIN,
743 #endif
744 LANG_ID3_PATH,
746 struct id3view_info {
747 struct mp3entry* id3;
748 int count;
749 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
751 static char * id3_get_info(int selected_item, void* data,
752 char *buffer, size_t buffer_len)
754 struct id3view_info *info = (struct id3view_info*)data;
755 struct mp3entry* id3 =info->id3;
756 int info_no=selected_item/2;
757 if(!(selected_item%2))
758 {/* header */
759 return( str(id3_headers[info->info_id[info_no]]));
761 else
762 {/* data */
764 char * val=NULL;
765 switch(info->info_id[info_no])
767 case 0:/*LANG_ID3_TITLE*/
768 val=id3->title;
769 break;
770 case 1:/*LANG_ID3_ARTIST*/
771 val=id3->artist;
772 break;
773 case 2:/*LANG_ID3_ALBUM*/
774 val=id3->album;
775 break;
776 case 3:/*LANG_ID3_ALBUMARTIST*/
777 val=id3->albumartist;
778 break;
779 case 4:/*LANG_ID3_GROUPING*/
780 val=id3->grouping;
781 break;
782 case 5:/*LANG_ID3_DISCNUM*/
783 if (id3->disc_string)
784 val = id3->disc_string;
785 else if (id3->discnum)
787 snprintf(buffer, buffer_len, "%d", id3->discnum);
788 val = buffer;
790 break;
791 case 6:/*LANG_ID3_TRACKNUM*/
792 if (id3->track_string)
793 val = id3->track_string;
794 else if (id3->tracknum)
796 snprintf(buffer, buffer_len, "%d", id3->tracknum);
797 val = buffer;
799 break;
800 case 7:/*LANG_ID3_COMMENT*/
801 val=id3->comment;
802 break;
803 case 8:/*LANG_ID3_GENRE*/
804 val = id3->genre_string;
805 break;
806 case 9:/*LANG_ID3_YEAR*/
807 if (id3->year_string)
808 val = id3->year_string;
809 else if (id3->year)
811 snprintf(buffer, buffer_len, "%d", id3->year);
812 val = buffer;
814 break;
815 case 10:/*LANG_ID3_LENGTH*/
816 format_time(buffer, buffer_len, id3->length);
817 val=buffer;
818 break;
819 case 11:/*LANG_ID3_PLAYLIST*/
820 snprintf(buffer, buffer_len, "%d/%d",
821 playlist_get_display_index(), playlist_amount());
822 val=buffer;
823 break;
824 case 12:/*LANG_ID3_BITRATE*/
825 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
826 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
827 val=buffer;
828 break;
829 case 13:/*LANG_ID3_FREQUENCY*/
830 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
831 val=buffer;
832 break;
833 #if CONFIG_CODEC == SWCODEC
834 case 14:/*LANG_ID3_TRACK_GAIN*/
835 val=id3->track_gain_string;
836 break;
837 case 15:/*LANG_ID3_ALBUM_GAIN*/
838 val=id3->album_gain_string;
839 break;
840 case 16:/*LANG_ID3_PATH*/
841 #else
842 case 14:/*LANG_ID3_PATH*/
843 #endif
844 val=id3->path;
845 break;
847 return val && *val ? val : NULL;
851 bool browse_id3(void)
853 struct gui_synclist id3_lists;
854 struct mp3entry* id3 = audio_current_track();
855 int key;
856 unsigned int i;
857 struct id3view_info info;
858 info.count = 0;
859 info.id3 = id3;
860 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
862 char temp[8];
863 info.info_id[i] = i;
864 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
865 info.info_id[info.count++] = i;
868 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
869 gui_synclist_set_nb_items(&id3_lists, info.count*2);
870 gui_synclist_draw(&id3_lists);
871 while (true) {
872 key = get_action(CONTEXT_LIST,HZ/2);
873 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
874 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
876 return(default_event_handler(key) == SYS_USB_CONNECTED);
881 static char* runtime_get_data(int selected_item, void* data,
882 char* buffer, size_t buffer_len)
884 (void)data;
885 int t;
886 switch (selected_item)
888 case 0: return str(LANG_RUNNING_TIME);
889 case 1: t = global_status.runtime; break;
890 case 2: return str(LANG_TOP_TIME);
891 case 3: t = global_status.topruntime; break;
892 default:
893 return "";
896 snprintf(buffer, buffer_len, "%dh %dm %ds",
897 t / 3600, (t % 3600) / 60, t % 60);
898 return buffer;
901 static int runtime_speak_data(int selected_item, void* data)
903 (void) data;
904 talk_ids(false,
905 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
906 TALK_ID((selected_item < 2) ? global_status.runtime
907 : global_status.topruntime, UNIT_TIME));
908 return 0;
912 bool view_runtime(void)
914 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
915 static const struct text_message message={lines, 1};
917 struct gui_synclist lists;
918 int action;
919 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
920 #if !defined(HAVE_LCD_CHARCELLS)
921 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
922 #else
923 gui_synclist_set_title(&lists, NULL, NOICON);
924 #endif
925 if(global_settings.talk_menu)
926 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
927 gui_synclist_set_icon_callback(&lists, NULL);
928 gui_synclist_set_nb_items(&lists, 4);
929 gui_synclist_speak_item(&lists);
930 while(1)
932 #if CONFIG_CHARGING
933 if (charger_inserted())
935 global_status.runtime = 0;
937 else
938 #endif
940 global_status.runtime += ((current_tick - lasttime) / HZ);
942 lasttime = current_tick;
943 gui_synclist_draw(&lists);
944 list_do_action(CONTEXT_STD, HZ,
945 &lists, &action, LIST_WRAP_UNLESS_HELD);
946 if(action == ACTION_STD_CANCEL)
947 break;
948 if(action == ACTION_STD_OK) {
949 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
951 if (!(gui_synclist_get_sel_pos(&lists)/2))
952 global_status.runtime = 0;
953 else
954 global_status.topruntime = 0;
955 gui_synclist_speak_item(&lists);
958 if(default_event_handler(action) == SYS_USB_CONNECTED)
959 return true;
961 return false;