Split 8-bit-to-native conversion in bmp.c into a function, add support for plugging...
[kugel-rb.git] / apps / screens.c
blobd359f657a4191cf52d5052b035a0ca6008ca2566
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 "action.h"
46 #include "talk.h"
47 #include "misc.h"
48 #include "metadata.h"
49 #include "screens.h"
50 #include "debug.h"
51 #include "led.h"
52 #include "sound.h"
53 #include "splash.h"
54 #include "statusbar.h"
55 #include "screen_access.h"
56 #include "pcmbuf.h"
57 #include "list.h"
58 #include "yesno.h"
59 #include "backdrop.h"
60 #include "viewport.h"
62 #ifdef HAVE_LCD_BITMAP
63 #include "bitmaps/usblogo.h"
64 #endif
66 #ifdef HAVE_REMOTE_LCD
67 #include "bitmaps/remote_usblogo.h"
68 #endif
70 #if (CONFIG_STORAGE & STORAGE_MMC)
71 #include "ata_mmc.h"
72 #endif
73 #if CONFIG_CODEC == SWCODEC
74 #include "dsp.h"
75 #endif
77 #ifdef HAVE_LCD_BITMAP
78 #define SCROLLBAR_WIDTH 6
79 #endif
81 /* only used in set_time screen */
82 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
83 static int clamp_value_wrap(int value, int max, int min)
85 if (value > max)
86 return min;
87 if (value < min)
88 return max;
89 return value;
91 #endif
93 #ifndef SIMULATOR
94 static 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;
130 #endif
132 void usb_screen(void)
134 #ifdef USB_NONE
135 /* nothing here! */
136 #else
137 int i;
138 bool statusbar = global_settings.statusbar; /* force the statusbar */
139 global_settings.statusbar = true;
140 #if LCD_DEPTH > 1
141 show_main_backdrop();
142 #endif
143 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
144 show_remote_main_backdrop();
145 #endif
146 FOR_NB_SCREENS(i)
148 screens[i].backlight_on();
149 screens[i].clear_display();
150 #if NB_SCREENS > 1
151 if (i == SCREEN_REMOTE)
153 screens[i].bitmap(remote_usblogo,
154 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
155 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
156 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
158 else
160 #endif
161 #ifdef HAVE_LCD_BITMAP
162 screens[i].transparent_bitmap(usblogo,
163 (LCD_WIDTH-BMPWIDTH_usblogo),
164 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
165 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
166 #else
167 screens[i].double_height(false);
168 screens[i].puts_scroll(0, 0, "[USB Mode]");
169 status_set_param(false);
170 status_set_audio(false);
171 status_set_usb(true);
172 #endif /* HAVE_LCD_BITMAP */
173 #if NB_SCREENS > 1
175 #endif
176 screens[i].update();
179 #ifdef SIMULATOR
180 while (button_get(true) & BUTTON_REL);
181 #else
182 usb_acknowledge(SYS_USB_CONNECTED_ACK);
183 while(handle_usb_events(&button_queue));
184 #endif /* SIMULATOR */
185 #ifdef HAVE_LCD_CHARCELLS
186 status_set_usb(false);
187 #endif /* HAVE_LCD_CHARCELLS */
188 FOR_NB_SCREENS(i)
189 screens[i].backlight_on();
190 global_settings.statusbar = statusbar;
191 #endif /* USB_NONE */
194 #if (CONFIG_STORAGE & STORAGE_MMC)
195 int mmc_remove_request(void)
197 struct queue_event ev;
198 int i;
199 FOR_NB_SCREENS(i)
200 screens[i].clear_display();
201 splash(0, ID2P(LANG_REMOVE_MMC));
203 while (1)
205 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
206 switch (ev.id)
208 case SYS_HOTSWAP_EXTRACTED:
209 return SYS_HOTSWAP_EXTRACTED;
211 case SYS_USB_DISCONNECTED:
212 return SYS_USB_DISCONNECTED;
216 #endif
218 /* the charging screen is only used for archos targets */
219 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
221 #ifdef HAVE_LCD_BITMAP
222 static void charging_display_info(bool animate)
224 unsigned char charging_logo[36];
225 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
226 const int pox_y = 32;
227 static unsigned phase = 3;
228 unsigned i;
229 char buf[32];
230 (void)buf;
232 #ifdef NEED_ATA_POWER_BATT_MEASURE
233 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
234 #endif
236 int battv = battery_voltage();
237 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
238 (battv % 1000) / 10, battery_level());
239 lcd_puts(0, 7, buf);
242 #ifdef ARCHOS_RECORER
243 snprintf(buf, 32, "Charge mode:");
244 lcd_puts(0, 2, buf);
246 if (charge_state == CHARGING)
247 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
248 else if (charge_state == TOPOFF)
249 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
250 else if (charge_state == TRICKLE)
251 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
252 else
253 snprintf(buf, 32, "not charging");
255 lcd_puts(0, 3, buf);
256 if (!charger_enabled())
257 animate = false;
258 #endif /* ARCHOS_RECORER */
260 /* middle part */
261 memset(charging_logo+3, 0x00, 32);
262 charging_logo[0] = 0x3C;
263 charging_logo[1] = 0x24;
264 charging_logo[2] = charging_logo[35] = 0xFF;
266 if (!animate)
267 { /* draw the outline */
268 /* middle part */
269 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
270 sizeof(charging_logo), 8);
271 lcd_set_drawmode(DRMODE_FG);
272 /* upper line */
273 charging_logo[0] = charging_logo[1] = 0x00;
274 memset(charging_logo+2, 0x80, 34);
275 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
276 /* lower line */
277 memset(charging_logo+2, 0x01, 34);
278 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
279 sizeof(charging_logo), 8);
280 lcd_set_drawmode(DRMODE_SOLID);
282 else
283 { /* animate the middle part */
284 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
286 if ((i-phase) % 8 == 0)
287 { /* draw a "bubble" here */
288 unsigned bitpos;
289 bitpos = (phase + i/8) % 15; /* "bounce" effect */
290 if (bitpos > 7)
291 bitpos = 14 - bitpos;
292 charging_logo[i] = 0x01 << bitpos;
295 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
296 sizeof(charging_logo), 8);
297 phase++;
299 lcd_update();
301 #else /* not HAVE_LCD_BITMAP */
303 static unsigned long logo_chars[4];
304 static const unsigned char logo_pattern[] = {
305 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
306 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
307 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
308 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
311 static void logo_lock_patterns(bool on)
313 int i;
315 if (on)
317 for (i = 0; i < 4; i++)
318 logo_chars[i] = lcd_get_locked_pattern();
320 else
322 for (i = 0; i < 4; i++)
323 lcd_unlock_pattern(logo_chars[i]);
327 static void charging_display_info(bool animate)
329 int battv;
330 unsigned i, ypos;
331 static unsigned phase = 3;
332 char buf[32];
334 battv = battery_voltage();
335 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
336 lcd_puts(4, 1, buf);
338 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
340 if (!animate) /* build the screen */
342 lcd_double_height(false);
343 lcd_puts(0, 0, "[Charging]");
344 for (i = 0; i < 4; i++)
345 lcd_putc(i, 1, logo_chars[i]);
347 else /* animate the logo */
349 for (i = 3; i < MIN(19, phase); i++)
351 if ((i - phase) % 5 == 0)
352 { /* draw a "bubble" here */
353 ypos = (phase + i/5) % 9; /* "bounce" effect */
354 if (ypos > 4)
355 ypos = 8 - ypos;
356 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
359 phase++;
362 for (i = 0; i < 4; i++)
363 lcd_define_pattern(logo_chars[i], buf + 8 * i);
365 lcd_update();
367 #endif /* (not) HAVE_LCD_BITMAP */
369 /* blocks while charging, returns on event:
370 1 if charger cable was removed
371 2 if Off/Stop key was pressed
372 3 if On key was pressed
373 4 if USB was connected */
375 int charging_screen(void)
377 unsigned int button;
378 int rc = 0;
380 ide_power_enable(false); /* power down the disk, else would be spinning */
382 lcd_clear_display();
383 backlight_set_timeout(global_settings.backlight_timeout);
384 #ifdef HAVE_REMOTE_LCD
385 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
386 #endif
387 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
389 #ifdef HAVE_LCD_CHARCELLS
390 logo_lock_patterns(true);
391 #endif
392 charging_display_info(false);
396 gui_syncstatusbar_draw(&statusbars, false);
397 charging_display_info(true);
398 button = get_action(CONTEXT_STD,HZ/3);
399 if (button == ACTION_STD_OK)
400 rc = 2;
401 else if (usb_detect() == USB_INSERTED)
402 rc = 3;
403 else if (!charger_inserted())
404 rc = 1;
405 } while (!rc);
407 #ifdef HAVE_LCD_CHARCELLS
408 logo_lock_patterns(false);
409 #endif
410 return rc;
412 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
414 #if CONFIG_CHARGING
415 void charging_splash(void)
417 splash(2*HZ, str(LANG_BATTERY_CHARGE));
418 button_clear_queue();
420 #endif
423 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
425 /* little helper function for voice output */
426 static void say_time(int cursorpos, const struct tm *tm)
428 int value = 0;
429 int unit = 0;
431 if (!global_settings.talk_menu)
432 return;
434 switch(cursorpos)
436 case 0:
437 value = tm->tm_hour;
438 unit = UNIT_HOUR;
439 break;
440 case 1:
441 value = tm->tm_min;
442 unit = UNIT_MIN;
443 break;
444 case 2:
445 value = tm->tm_sec;
446 unit = UNIT_SEC;
447 break;
448 case 3:
449 value = tm->tm_year + 1900;
450 break;
451 case 5:
452 value = tm->tm_mday;
453 break;
456 if (cursorpos == 4) /* month */
457 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
458 else
459 talk_value(value, unit, false);
463 #define INDEX_X 0
464 #define INDEX_Y 1
466 #define SEPARATOR ":"
467 bool set_time_screen(const char* title, struct tm *tm)
469 bool done = false;
470 int button;
471 unsigned int i, j, s;
472 int cursorpos = 0;
473 unsigned int julianday;
474 unsigned int realyear;
475 unsigned int width;
476 unsigned int min, max;
477 unsigned int statusbar_height = 0;
478 unsigned int separator_width, weekday_width;
479 unsigned int prev_line_height;
480 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
481 unsigned char buffer[20];
482 struct viewport vp[NB_SCREENS];
483 int nb_lines;
485 /* 6 possible cursor possitions, 2 values stored for each: x, y */
486 unsigned int cursor[6][2];
488 int *valptr = NULL;
489 unsigned char *ptr[6];
491 if(global_settings.statusbar)
492 statusbar_height = STATUSBAR_HEIGHT;
494 /* speak selection when screen is entered */
495 say_time(cursorpos, tm);
497 while (!done) {
498 /* for easy acess in the drawing loop */
499 ptr[0] = buffer; /* hours */
500 ptr[1] = buffer + 3; /* minutes */
501 ptr[2] = buffer + 6; /* seconds */
502 ptr[3] = buffer + 9; /* year */
503 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
504 ptr[5] = buffer + 14; /* day of month */
506 /* calculate the number of days in febuary */
507 realyear = tm->tm_year + 1900;
508 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
509 daysinmonth[1] = 29;
510 else
511 daysinmonth[1] = 28;
513 /* fix day if month or year changed */
514 if (tm->tm_mday > daysinmonth[tm->tm_mon])
515 tm->tm_mday = daysinmonth[tm->tm_mon];
517 /* calculate day of week */
518 julianday = tm->tm_mday;
519 for(i = 0; (int)i < tm->tm_mon; i++) {
520 julianday += daysinmonth[i];
523 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
524 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
526 /* put all the numbers we want from the tm struct into
527 an easily printable buffer */
528 snprintf(buffer, sizeof(buffer),
529 "%02d " "%02d " "%02d " "%04d " "%02d",
530 tm->tm_hour, tm->tm_min, tm->tm_sec,
531 tm->tm_year+1900, tm->tm_mday);
533 /* convert spaces in the buffer to '\0' to make it possible to work
534 directly on the buffer */
535 for(i=0; i < sizeof(buffer); i++)
537 if(buffer[i] == ' ')
538 buffer[i] = '\0';
541 FOR_NB_SCREENS(s)
543 viewport_set_defaults(&vp[s], s);
544 screens[s].set_viewport(&vp[s]);
545 nb_lines = viewport_get_nb_lines(&vp[s]);
547 /* minimum lines needed is 2 + title line */
548 if (nb_lines < 4)
550 vp[s].font = FONT_SYSFIXED;
551 nb_lines = viewport_get_nb_lines(&vp[s]);
554 /* recalculate the positions and offsets */
555 if (nb_lines >= 3)
556 screens[s].getstringsize(title, NULL, &prev_line_height);
557 else
558 prev_line_height = 0;
560 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
562 /* weekday */
563 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
564 &weekday_width, NULL);
565 screens[s].getstringsize(" ", &separator_width, NULL);
567 for(i=0, j=0; i < 6; i++)
569 if(i==3) /* second row */
571 j = weekday_width + separator_width;
572 prev_line_height *= 2;
574 screens[s].getstringsize(ptr[i], &width, NULL);
575 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
576 cursor[i][INDEX_X] = j;
577 j += width + separator_width;
580 /* draw the screen */
581 screens[s].set_viewport(&vp[s]);
582 screens[s].clear_viewport();
583 /* display the screen title */
584 screens[s].puts_scroll(0, 0, title);
586 /* these are not selectable, so we draw them outside the loop */
587 /* name of the week day */
588 screens[s].putsxy(0, cursor[3][INDEX_Y],
589 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
591 /* draw the selected item with drawmode set to
592 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
593 items with drawmode DRMODE_SOLID */
594 for(i=0; i<6; i++)
596 if (cursorpos == (int)i)
597 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
599 screens[s].putsxy(cursor[i][INDEX_X],
600 cursor[i][INDEX_Y], ptr[i]);
602 vp[s].drawmode = DRMODE_SOLID;
604 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
605 cursor[0][INDEX_Y], SEPARATOR);
608 /* print help text */
609 if (nb_lines > 4)
610 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
611 if (nb_lines > 5)
612 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
613 screens[s].update_viewport();
614 screens[s].set_viewport(NULL);
617 /* set the most common numbers */
618 min = 0;
619 max = 59;
620 /* calculate the minimum and maximum for the number under cursor */
621 switch(cursorpos) {
622 case 0: /* hour */
623 max = 23;
624 valptr = &tm->tm_hour;
625 break;
626 case 1: /* minute */
627 valptr = &tm->tm_min;
628 break;
629 case 2: /* second */
630 valptr = &tm->tm_sec;
631 break;
632 case 3: /* year */
633 min = 1;
634 max = 200;
635 valptr = &tm->tm_year;
636 break;
637 case 4: /* month */
638 max = 11;
639 valptr = &tm->tm_mon;
640 break;
641 case 5: /* day */
642 min = 1;
643 max = daysinmonth[tm->tm_mon];
644 valptr = &tm->tm_mday;
645 break;
648 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
649 switch ( button ) {
650 case ACTION_STD_PREV:
651 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
652 say_time(cursorpos, tm);
653 break;
654 case ACTION_STD_NEXT:
655 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
656 say_time(cursorpos, tm);
657 break;
658 case ACTION_SETTINGS_INC:
659 case ACTION_SETTINGS_INCREPEAT:
660 *valptr = clamp_value_wrap(++(*valptr), max, min);
661 say_time(cursorpos, tm);
662 break;
663 case ACTION_SETTINGS_DEC:
664 case ACTION_SETTINGS_DECREPEAT:
665 *valptr = clamp_value_wrap(--(*valptr), max, min);
666 say_time(cursorpos, tm);
667 break;
669 case ACTION_STD_OK:
670 done = true;
671 break;
673 case ACTION_STD_CANCEL:
674 done = true;
675 tm->tm_year = -1;
676 break;
678 default:
679 if (default_event_handler(button) == SYS_USB_CONNECTED)
680 return true;
681 break;
684 return false;
686 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
688 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
689 bool shutdown_screen(void)
691 int button;
692 bool done = false;
693 long time_entered = current_tick;
695 lcd_stop_scroll();
697 splash(0, str(LANG_CONFIRM_SHUTDOWN));
699 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
701 button = get_action(CONTEXT_STD,HZ);
702 switch(button)
704 case ACTION_STD_CANCEL:
705 sys_poweroff();
706 break;
708 /* do nothing here, because ACTION_NONE might be caused
709 * by timeout or button release. In case of timeout the loop
710 * is terminated by TIME_BEFORE */
711 case ACTION_NONE:
712 break;
714 default:
715 if(default_event_handler(button) == SYS_USB_CONNECTED)
716 return true;
717 done = true;
718 break;
721 return false;
723 #endif
725 static const int id3_headers[]=
727 LANG_ID3_TITLE,
728 LANG_ID3_ARTIST,
729 LANG_ID3_ALBUM,
730 LANG_ID3_ALBUMARTIST,
731 LANG_ID3_GROUPING,
732 LANG_ID3_DISCNUM,
733 LANG_ID3_TRACKNUM,
734 LANG_ID3_COMMENT,
735 LANG_ID3_GENRE,
736 LANG_ID3_YEAR,
737 LANG_ID3_LENGTH,
738 LANG_ID3_PLAYLIST,
739 LANG_ID3_BITRATE,
740 LANG_ID3_FREQUENCY,
741 #if CONFIG_CODEC == SWCODEC
742 LANG_ID3_TRACK_GAIN,
743 LANG_ID3_ALBUM_GAIN,
744 #endif
745 LANG_ID3_PATH,
747 struct id3view_info {
748 struct mp3entry* id3;
749 int count;
750 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
752 static char * id3_get_info(int selected_item, void* data,
753 char *buffer, size_t buffer_len)
755 struct id3view_info *info = (struct id3view_info*)data;
756 struct mp3entry* id3 =info->id3;
757 int info_no=selected_item/2;
758 if(!(selected_item%2))
759 {/* header */
760 return( str(id3_headers[info->info_id[info_no]]));
762 else
763 {/* data */
765 char * val=NULL;
766 switch(info->info_id[info_no])
768 case 0:/*LANG_ID3_TITLE*/
769 val=id3->title;
770 break;
771 case 1:/*LANG_ID3_ARTIST*/
772 val=id3->artist;
773 break;
774 case 2:/*LANG_ID3_ALBUM*/
775 val=id3->album;
776 break;
777 case 3:/*LANG_ID3_ALBUMARTIST*/
778 val=id3->albumartist;
779 break;
780 case 4:/*LANG_ID3_GROUPING*/
781 val=id3->grouping;
782 break;
783 case 5:/*LANG_ID3_DISCNUM*/
784 if (id3->disc_string)
785 val = id3->disc_string;
786 else if (id3->discnum)
788 snprintf(buffer, buffer_len, "%d", id3->discnum);
789 val = buffer;
791 break;
792 case 6:/*LANG_ID3_TRACKNUM*/
793 if (id3->track_string)
794 val = id3->track_string;
795 else if (id3->tracknum)
797 snprintf(buffer, buffer_len, "%d", id3->tracknum);
798 val = buffer;
800 break;
801 case 7:/*LANG_ID3_COMMENT*/
802 val=id3->comment;
803 break;
804 case 8:/*LANG_ID3_GENRE*/
805 val = id3->genre_string;
806 break;
807 case 9:/*LANG_ID3_YEAR*/
808 if (id3->year_string)
809 val = id3->year_string;
810 else if (id3->year)
812 snprintf(buffer, buffer_len, "%d", id3->year);
813 val = buffer;
815 break;
816 case 10:/*LANG_ID3_LENGTH*/
817 format_time(buffer, buffer_len, id3->length);
818 val=buffer;
819 break;
820 case 11:/*LANG_ID3_PLAYLIST*/
821 snprintf(buffer, buffer_len, "%d/%d",
822 playlist_get_display_index(), playlist_amount());
823 val=buffer;
824 break;
825 case 12:/*LANG_ID3_BITRATE*/
826 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
827 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
828 val=buffer;
829 break;
830 case 13:/*LANG_ID3_FREQUENCY*/
831 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
832 val=buffer;
833 break;
834 #if CONFIG_CODEC == SWCODEC
835 case 14:/*LANG_ID3_TRACK_GAIN*/
836 val=id3->track_gain_string;
837 break;
838 case 15:/*LANG_ID3_ALBUM_GAIN*/
839 val=id3->album_gain_string;
840 break;
841 case 16:/*LANG_ID3_PATH*/
842 #else
843 case 14:/*LANG_ID3_PATH*/
844 #endif
845 val=id3->path;
846 break;
848 return val && *val ? val : NULL;
852 bool browse_id3(void)
854 struct gui_synclist id3_lists;
855 struct mp3entry* id3 = audio_current_track();
856 int key;
857 unsigned int i;
858 struct id3view_info info;
859 info.count = 0;
860 info.id3 = id3;
861 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
863 char temp[8];
864 info.info_id[i] = i;
865 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
866 info.info_id[info.count++] = i;
869 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
870 gui_synclist_set_nb_items(&id3_lists, info.count*2);
871 gui_synclist_draw(&id3_lists);
872 while (true) {
873 key = get_action(CONTEXT_LIST,HZ/2);
874 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
875 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
877 return(default_event_handler(key) == SYS_USB_CONNECTED);
882 static char* runtime_get_data(int selected_item, void* data,
883 char* buffer, size_t buffer_len)
885 (void)data;
886 int t;
887 switch (selected_item)
889 case 0: return str(LANG_RUNNING_TIME);
890 case 1: t = global_status.runtime; break;
891 case 2: return str(LANG_TOP_TIME);
892 case 3: t = global_status.topruntime; break;
893 default:
894 return "";
897 snprintf(buffer, buffer_len, "%dh %dm %ds",
898 t / 3600, (t % 3600) / 60, t % 60);
899 return buffer;
902 static int runtime_speak_data(int selected_item, void* data)
904 (void) data;
905 talk_ids(false,
906 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
907 TALK_ID((selected_item < 2) ? global_status.runtime
908 : global_status.topruntime, UNIT_TIME));
909 return 0;
913 bool view_runtime(void)
915 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
916 static const struct text_message message={lines, 1};
918 struct gui_synclist lists;
919 int action;
920 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
921 #if !defined(HAVE_LCD_CHARCELLS)
922 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
923 #else
924 gui_synclist_set_title(&lists, NULL, NOICON);
925 #endif
926 if(global_settings.talk_menu)
927 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
928 gui_synclist_set_icon_callback(&lists, NULL);
929 gui_synclist_set_nb_items(&lists, 4);
930 gui_synclist_speak_item(&lists);
931 while(1)
933 #if CONFIG_CHARGING
934 if (charger_inserted())
936 global_status.runtime = 0;
938 else
939 #endif
941 global_status.runtime += ((current_tick - lasttime) / HZ);
943 lasttime = current_tick;
944 gui_synclist_draw(&lists);
945 list_do_action(CONTEXT_STD, HZ,
946 &lists, &action, LIST_WRAP_UNLESS_HELD);
947 if(action == ACTION_STD_CANCEL)
948 break;
949 if(action == ACTION_STD_OK) {
950 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
952 if (!(gui_synclist_get_sel_pos(&lists)/2))
953 global_status.runtime = 0;
954 else
955 global_status.topruntime = 0;
956 gui_synclist_speak_item(&lists);
959 if(default_event_handler(action) == SYS_USB_CONNECTED)
960 return true;
962 return false;