Reverting parts of r19760 that was mistakenly committed.
[kugel-rb.git] / apps / screens.c
blob8a787a5ca190bdce10ab6043853a779056a9028d
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 void usb_screen(void)
96 #ifdef USB_NONE
97 /* nothing here! */
98 #else
99 int i;
100 bool statusbar = global_settings.statusbar; /* force the statusbar */
101 global_settings.statusbar = true;
102 #if LCD_DEPTH > 1
103 show_main_backdrop();
104 #endif
105 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
106 show_remote_main_backdrop();
107 #endif
108 FOR_NB_SCREENS(i)
110 screens[i].backlight_on();
111 screens[i].clear_display();
112 #if NB_SCREENS > 1
113 if (i == SCREEN_REMOTE)
115 screens[i].bitmap(remote_usblogo,
116 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
117 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
118 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
120 else
122 #endif
123 #ifdef HAVE_LCD_BITMAP
124 screens[i].transparent_bitmap(usblogo,
125 (LCD_WIDTH-BMPWIDTH_usblogo),
126 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
127 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
128 #else
129 screens[i].double_height(false);
130 screens[i].puts_scroll(0, 0, "[USB Mode]");
131 status_set_param(false);
132 status_set_audio(false);
133 status_set_usb(true);
134 #endif /* HAVE_LCD_BITMAP */
135 #if NB_SCREENS > 1
137 #endif
138 screens[i].update();
141 #ifdef SIMULATOR
142 while (button_get(true) & BUTTON_REL);
143 #else
144 usb_acknowledge(SYS_USB_CONNECTED_ACK);
145 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
146 if(usb_inserted()) {
147 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
148 led(mmc_usb_active(HZ));
149 #endif /* STORAGE_MMC */
150 gui_syncstatusbar_draw(&statusbars, false);
153 #endif /* SIMULATOR */
154 #ifdef HAVE_LCD_CHARCELLS
155 status_set_usb(false);
156 #endif /* HAVE_LCD_CHARCELLS */
157 FOR_NB_SCREENS(i)
158 screens[i].backlight_on();
159 global_settings.statusbar = statusbar;
160 #endif /* USB_NONE */
163 #if (CONFIG_STORAGE & STORAGE_MMC)
164 int mmc_remove_request(void)
166 struct queue_event ev;
167 int i;
168 FOR_NB_SCREENS(i)
169 screens[i].clear_display();
170 splash(0, ID2P(LANG_REMOVE_MMC));
172 while (1)
174 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
175 switch (ev.id)
177 case SYS_HOTSWAP_EXTRACTED:
178 return SYS_HOTSWAP_EXTRACTED;
180 case SYS_USB_DISCONNECTED:
181 return SYS_USB_DISCONNECTED;
185 #endif
187 /* the charging screen is only used for archos targets */
188 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
190 #ifdef HAVE_LCD_BITMAP
191 static void charging_display_info(bool animate)
193 unsigned char charging_logo[36];
194 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
195 const int pox_y = 32;
196 static unsigned phase = 3;
197 unsigned i;
198 char buf[32];
199 (void)buf;
201 #ifdef NEED_ATA_POWER_BATT_MEASURE
202 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
203 #endif
205 int battv = battery_voltage();
206 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
207 (battv % 1000) / 10, battery_level());
208 lcd_puts(0, 7, buf);
211 #ifdef ARCHOS_RECORER
212 snprintf(buf, 32, "Charge mode:");
213 lcd_puts(0, 2, buf);
215 if (charge_state == CHARGING)
216 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
217 else if (charge_state == TOPOFF)
218 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
219 else if (charge_state == TRICKLE)
220 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
221 else
222 snprintf(buf, 32, "not charging");
224 lcd_puts(0, 3, buf);
225 if (!charger_enabled())
226 animate = false;
227 #endif /* ARCHOS_RECORER */
229 /* middle part */
230 memset(charging_logo+3, 0x00, 32);
231 charging_logo[0] = 0x3C;
232 charging_logo[1] = 0x24;
233 charging_logo[2] = charging_logo[35] = 0xFF;
235 if (!animate)
236 { /* draw the outline */
237 /* middle part */
238 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
239 sizeof(charging_logo), 8);
240 lcd_set_drawmode(DRMODE_FG);
241 /* upper line */
242 charging_logo[0] = charging_logo[1] = 0x00;
243 memset(charging_logo+2, 0x80, 34);
244 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
245 /* lower line */
246 memset(charging_logo+2, 0x01, 34);
247 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
248 sizeof(charging_logo), 8);
249 lcd_set_drawmode(DRMODE_SOLID);
251 else
252 { /* animate the middle part */
253 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
255 if ((i-phase) % 8 == 0)
256 { /* draw a "bubble" here */
257 unsigned bitpos;
258 bitpos = (phase + i/8) % 15; /* "bounce" effect */
259 if (bitpos > 7)
260 bitpos = 14 - bitpos;
261 charging_logo[i] = 0x01 << bitpos;
264 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
265 sizeof(charging_logo), 8);
266 phase++;
268 lcd_update();
270 #else /* not HAVE_LCD_BITMAP */
272 static unsigned long logo_chars[4];
273 static const unsigned char logo_pattern[] = {
274 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
275 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
276 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
277 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
280 static void logo_lock_patterns(bool on)
282 int i;
284 if (on)
286 for (i = 0; i < 4; i++)
287 logo_chars[i] = lcd_get_locked_pattern();
289 else
291 for (i = 0; i < 4; i++)
292 lcd_unlock_pattern(logo_chars[i]);
296 static void charging_display_info(bool animate)
298 int battv;
299 unsigned i, ypos;
300 static unsigned phase = 3;
301 char buf[32];
303 battv = battery_voltage();
304 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
305 lcd_puts(4, 1, buf);
307 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
309 if (!animate) /* build the screen */
311 lcd_double_height(false);
312 lcd_puts(0, 0, "[Charging]");
313 for (i = 0; i < 4; i++)
314 lcd_putc(i, 1, logo_chars[i]);
316 else /* animate the logo */
318 for (i = 3; i < MIN(19, phase); i++)
320 if ((i - phase) % 5 == 0)
321 { /* draw a "bubble" here */
322 ypos = (phase + i/5) % 9; /* "bounce" effect */
323 if (ypos > 4)
324 ypos = 8 - ypos;
325 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
328 phase++;
331 for (i = 0; i < 4; i++)
332 lcd_define_pattern(logo_chars[i], buf + 8 * i);
334 lcd_update();
336 #endif /* (not) HAVE_LCD_BITMAP */
338 /* blocks while charging, returns on event:
339 1 if charger cable was removed
340 2 if Off/Stop key was pressed
341 3 if On key was pressed
342 4 if USB was connected */
344 int charging_screen(void)
346 unsigned int button;
347 int rc = 0;
349 ide_power_enable(false); /* power down the disk, else would be spinning */
351 lcd_clear_display();
352 backlight_set_timeout(global_settings.backlight_timeout);
353 #ifdef HAVE_REMOTE_LCD
354 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
355 #endif
356 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
358 #ifdef HAVE_LCD_CHARCELLS
359 logo_lock_patterns(true);
360 #endif
361 charging_display_info(false);
365 gui_syncstatusbar_draw(&statusbars, false);
366 charging_display_info(true);
367 button = get_action(CONTEXT_STD,HZ/3);
368 if (button == ACTION_STD_OK)
369 rc = 2;
370 else if (usb_detect() == USB_INSERTED)
371 rc = 3;
372 else if (!charger_inserted())
373 rc = 1;
374 } while (!rc);
376 #ifdef HAVE_LCD_CHARCELLS
377 logo_lock_patterns(false);
378 #endif
379 return rc;
381 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
383 #if CONFIG_CHARGING
384 void charging_splash(void)
386 splash(2*HZ, str(LANG_BATTERY_CHARGE));
387 button_clear_queue();
389 #endif
392 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
394 /* little helper function for voice output */
395 static void say_time(int cursorpos, const struct tm *tm)
397 int value = 0;
398 int unit = 0;
400 if (!global_settings.talk_menu)
401 return;
403 switch(cursorpos)
405 case 0:
406 value = tm->tm_hour;
407 unit = UNIT_HOUR;
408 break;
409 case 1:
410 value = tm->tm_min;
411 unit = UNIT_MIN;
412 break;
413 case 2:
414 value = tm->tm_sec;
415 unit = UNIT_SEC;
416 break;
417 case 3:
418 value = tm->tm_year + 1900;
419 break;
420 case 5:
421 value = tm->tm_mday;
422 break;
425 if (cursorpos == 4) /* month */
426 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
427 else
428 talk_value(value, unit, false);
432 #define INDEX_X 0
433 #define INDEX_Y 1
435 #define SEPARATOR ":"
436 bool set_time_screen(const char* title, struct tm *tm)
438 bool done = false;
439 int button;
440 unsigned int i, j, s;
441 int cursorpos = 0;
442 unsigned int julianday;
443 unsigned int realyear;
444 unsigned int width;
445 unsigned int min, max;
446 unsigned int statusbar_height = 0;
447 unsigned int separator_width, weekday_width;
448 unsigned int prev_line_height;
449 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
450 unsigned char buffer[20];
451 struct viewport vp[NB_SCREENS];
452 int nb_lines;
454 /* 6 possible cursor possitions, 2 values stored for each: x, y */
455 unsigned int cursor[6][2];
457 int *valptr = NULL;
458 unsigned char *ptr[6];
460 if(global_settings.statusbar)
461 statusbar_height = STATUSBAR_HEIGHT;
463 /* speak selection when screen is entered */
464 say_time(cursorpos, tm);
466 while (!done) {
467 /* for easy acess in the drawing loop */
468 ptr[0] = buffer; /* hours */
469 ptr[1] = buffer + 3; /* minutes */
470 ptr[2] = buffer + 6; /* seconds */
471 ptr[3] = buffer + 9; /* year */
472 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
473 ptr[5] = buffer + 14; /* day of month */
475 /* calculate the number of days in febuary */
476 realyear = tm->tm_year + 1900;
477 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
478 daysinmonth[1] = 29;
479 else
480 daysinmonth[1] = 28;
482 /* fix day if month or year changed */
483 if (tm->tm_mday > daysinmonth[tm->tm_mon])
484 tm->tm_mday = daysinmonth[tm->tm_mon];
486 /* calculate day of week */
487 julianday = tm->tm_mday;
488 for(i = 0; (int)i < tm->tm_mon; i++) {
489 julianday += daysinmonth[i];
492 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
493 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
495 /* put all the numbers we want from the tm struct into
496 an easily printable buffer */
497 snprintf(buffer, sizeof(buffer),
498 "%02d " "%02d " "%02d " "%04d " "%02d",
499 tm->tm_hour, tm->tm_min, tm->tm_sec,
500 tm->tm_year+1900, tm->tm_mday);
502 /* convert spaces in the buffer to '\0' to make it possible to work
503 directly on the buffer */
504 for(i=0; i < sizeof(buffer); i++)
506 if(buffer[i] == ' ')
507 buffer[i] = '\0';
510 FOR_NB_SCREENS(s)
512 viewport_set_defaults(&vp[s], s);
513 screens[s].set_viewport(&vp[s]);
514 nb_lines = viewport_get_nb_lines(&vp[s]);
516 /* minimum lines needed is 2 + title line */
517 if (nb_lines < 4)
519 vp[s].font = FONT_SYSFIXED;
520 nb_lines = viewport_get_nb_lines(&vp[s]);
523 /* recalculate the positions and offsets */
524 if (nb_lines >= 3)
525 screens[s].getstringsize(title, NULL, &prev_line_height);
526 else
527 prev_line_height = 0;
529 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
531 /* weekday */
532 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
533 &weekday_width, NULL);
534 screens[s].getstringsize(" ", &separator_width, NULL);
536 for(i=0, j=0; i < 6; i++)
538 if(i==3) /* second row */
540 j = weekday_width + separator_width;;
541 prev_line_height *= 2;
543 screens[s].getstringsize(ptr[i], &width, NULL);
544 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
545 cursor[i][INDEX_X] = j;
546 j += width + separator_width;
549 /* draw the screen */
550 screens[s].set_viewport(&vp[s]);
551 screens[s].clear_viewport();
552 /* display the screen title */
553 screens[s].puts_scroll(0, 0, title);
555 /* these are not selectable, so we draw them outside the loop */
556 /* name of the week day */
557 screens[s].putsxy(0, cursor[3][INDEX_Y],
558 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
560 /* draw the selected item with drawmode set to
561 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
562 items with drawmode DRMODE_SOLID */
563 for(i=0; i<6; i++)
565 if (cursorpos == (int)i)
566 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
568 screens[s].putsxy(cursor[i][INDEX_X],
569 cursor[i][INDEX_Y], ptr[i]);
571 vp[s].drawmode = DRMODE_SOLID;
573 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
574 cursor[0][INDEX_Y], SEPARATOR);
577 /* print help text */
578 if (nb_lines > 4)
579 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
580 if (nb_lines > 5)
581 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
582 screens[s].update_viewport();
583 screens[s].set_viewport(NULL);
586 /* set the most common numbers */
587 min = 0;
588 max = 59;
589 /* calculate the minimum and maximum for the number under cursor */
590 switch(cursorpos) {
591 case 0: /* hour */
592 max = 23;
593 valptr = &tm->tm_hour;
594 break;
595 case 1: /* minute */
596 valptr = &tm->tm_min;
597 break;
598 case 2: /* second */
599 valptr = &tm->tm_sec;
600 break;
601 case 3: /* year */
602 min = 1;
603 max = 200;
604 valptr = &tm->tm_year;
605 break;
606 case 4: /* month */
607 max = 11;
608 valptr = &tm->tm_mon;
609 break;
610 case 5: /* day */
611 min = 1;
612 max = daysinmonth[tm->tm_mon];
613 valptr = &tm->tm_mday;
614 break;
617 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
618 switch ( button ) {
619 case ACTION_STD_PREV:
620 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
621 say_time(cursorpos, tm);
622 break;
623 case ACTION_STD_NEXT:
624 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
625 say_time(cursorpos, tm);
626 break;
627 case ACTION_SETTINGS_INC:
628 case ACTION_SETTINGS_INCREPEAT:
629 *valptr = clamp_value_wrap(++(*valptr), max, min);
630 say_time(cursorpos, tm);
631 break;
632 case ACTION_SETTINGS_DEC:
633 case ACTION_SETTINGS_DECREPEAT:
634 *valptr = clamp_value_wrap(--(*valptr), max, min);
635 say_time(cursorpos, tm);
636 break;
638 case ACTION_STD_OK:
639 done = true;
640 break;
642 case ACTION_STD_CANCEL:
643 done = true;
644 tm->tm_year = -1;
645 break;
647 default:
648 if (default_event_handler(button) == SYS_USB_CONNECTED)
649 return true;
650 break;
653 return false;
655 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
657 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
658 bool shutdown_screen(void)
660 int button;
661 bool done = false;
662 long time_entered = current_tick;
664 lcd_stop_scroll();
666 splash(0, str(LANG_CONFIRM_SHUTDOWN));
668 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
670 button = get_action(CONTEXT_STD,HZ);
671 switch(button)
673 case ACTION_STD_CANCEL:
674 sys_poweroff();
675 break;
677 /* do nothing here, because ACTION_NONE might be caused
678 * by timeout or button release. In case of timeout the loop
679 * is terminated by TIME_BEFORE */
680 case ACTION_NONE:
681 break;
683 default:
684 if(default_event_handler(button) == SYS_USB_CONNECTED)
685 return true;
686 done = true;
687 break;
690 return false;
692 #endif
694 static const int id3_headers[]=
696 LANG_ID3_TITLE,
697 LANG_ID3_ARTIST,
698 LANG_ID3_ALBUM,
699 LANG_ID3_ALBUMARTIST,
700 LANG_ID3_GROUPING,
701 LANG_ID3_DISCNUM,
702 LANG_ID3_TRACKNUM,
703 LANG_ID3_COMMENT,
704 LANG_ID3_GENRE,
705 LANG_ID3_YEAR,
706 LANG_ID3_LENGTH,
707 LANG_ID3_PLAYLIST,
708 LANG_ID3_BITRATE,
709 LANG_ID3_FREQUENCY,
710 #if CONFIG_CODEC == SWCODEC
711 LANG_ID3_TRACK_GAIN,
712 LANG_ID3_ALBUM_GAIN,
713 #endif
714 LANG_ID3_PATH,
716 struct id3view_info {
717 struct mp3entry* id3;
718 int count;
719 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
721 static char * id3_get_info(int selected_item, void* data,
722 char *buffer, size_t buffer_len)
724 struct id3view_info *info = (struct id3view_info*)data;
725 struct mp3entry* id3 =info->id3;
726 int info_no=selected_item/2;
727 if(!(selected_item%2))
728 {/* header */
729 return( str(id3_headers[info->info_id[info_no]]));
731 else
732 {/* data */
734 char * val=NULL;
735 switch(info->info_id[info_no])
737 case 0:/*LANG_ID3_TITLE*/
738 val=id3->title;
739 break;
740 case 1:/*LANG_ID3_ARTIST*/
741 val=id3->artist;
742 break;
743 case 2:/*LANG_ID3_ALBUM*/
744 val=id3->album;
745 break;
746 case 3:/*LANG_ID3_ALBUMARTIST*/
747 val=id3->albumartist;
748 break;
749 case 4:/*LANG_ID3_GROUPING*/
750 val=id3->grouping;
751 break;
752 case 5:/*LANG_ID3_DISCNUM*/
753 if (id3->disc_string)
754 val = id3->disc_string;
755 else if (id3->discnum)
757 snprintf(buffer, buffer_len, "%d", id3->discnum);
758 val = buffer;
760 break;
761 case 6:/*LANG_ID3_TRACKNUM*/
762 if (id3->track_string)
763 val = id3->track_string;
764 else if (id3->tracknum)
766 snprintf(buffer, buffer_len, "%d", id3->tracknum);
767 val = buffer;
769 break;
770 case 7:/*LANG_ID3_COMMENT*/
771 val=id3->comment;
772 break;
773 case 8:/*LANG_ID3_GENRE*/
774 val = id3->genre_string;
775 break;
776 case 9:/*LANG_ID3_YEAR*/
777 if (id3->year_string)
778 val = id3->year_string;
779 else if (id3->year)
781 snprintf(buffer, buffer_len, "%d", id3->year);
782 val = buffer;
784 break;
785 case 10:/*LANG_ID3_LENGTH*/
786 format_time(buffer, buffer_len, id3->length);
787 val=buffer;
788 break;
789 case 11:/*LANG_ID3_PLAYLIST*/
790 snprintf(buffer, buffer_len, "%d/%d",
791 playlist_get_display_index(), playlist_amount());
792 val=buffer;
793 break;
794 case 12:/*LANG_ID3_BITRATE*/
795 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
796 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
797 val=buffer;
798 break;
799 case 13:/*LANG_ID3_FREQUENCY*/
800 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
801 val=buffer;
802 break;
803 #if CONFIG_CODEC == SWCODEC
804 case 14:/*LANG_ID3_TRACK_GAIN*/
805 val=id3->track_gain_string;
806 break;
807 case 15:/*LANG_ID3_ALBUM_GAIN*/
808 val=id3->album_gain_string;
809 break;
810 case 16:/*LANG_ID3_PATH*/
811 #else
812 case 14:/*LANG_ID3_PATH*/
813 #endif
814 val=id3->path;
815 break;
817 return val && *val ? val : NULL;
821 bool browse_id3(void)
823 struct gui_synclist id3_lists;
824 struct mp3entry* id3 = audio_current_track();
825 int key;
826 unsigned int i;
827 struct id3view_info info;
828 info.count = 0;
829 info.id3 = id3;
830 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
832 char temp[8];
833 info.info_id[i] = i;
834 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
835 info.info_id[info.count++] = i;
838 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
839 gui_synclist_set_nb_items(&id3_lists, info.count*2);
840 gui_synclist_draw(&id3_lists);
841 while (true) {
842 key = get_action(CONTEXT_LIST,HZ/2);
843 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
844 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
846 return(default_event_handler(key) == SYS_USB_CONNECTED);
851 static char* runtime_get_data(int selected_item, void* data,
852 char* buffer, size_t buffer_len)
854 (void)data;
855 int t;
856 switch (selected_item)
858 case 0: return str(LANG_RUNNING_TIME);
859 case 1: t = global_status.runtime; break;
860 case 2: return str(LANG_TOP_TIME);
861 case 3: t = global_status.topruntime; break;
862 default:
863 return "";
866 snprintf(buffer, buffer_len, "%dh %dm %ds",
867 t / 3600, (t % 3600) / 60, t % 60);
868 return buffer;
871 static int runtime_speak_data(int selected_item, void* data)
873 (void) data;
874 talk_ids(false,
875 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
876 TALK_ID((selected_item < 2) ? global_status.runtime
877 : global_status.topruntime, UNIT_TIME));
878 return 0;
882 bool view_runtime(void)
884 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
885 static const struct text_message message={lines, 1};
887 struct gui_synclist lists;
888 int action;
889 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
890 #if !defined(HAVE_LCD_CHARCELLS)
891 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
892 #else
893 gui_synclist_set_title(&lists, NULL, NOICON);
894 #endif
895 if(global_settings.talk_menu)
896 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
897 gui_synclist_set_icon_callback(&lists, NULL);
898 gui_synclist_set_nb_items(&lists, 4);
899 gui_synclist_speak_item(&lists);
900 while(1)
902 #if CONFIG_CHARGING
903 if (charger_inserted())
905 global_status.runtime = 0;
907 else
908 #endif
910 global_status.runtime += ((current_tick - lasttime) / HZ);
912 lasttime = current_tick;
913 gui_synclist_draw(&lists);
914 list_do_action(CONTEXT_STD, HZ,
915 &lists, &action, LIST_WRAP_UNLESS_HELD);
916 if(action == ACTION_STD_CANCEL)
917 break;
918 if(action == ACTION_STD_OK) {
919 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
921 if (!(gui_synclist_get_sel_pos(&lists)/2))
922 global_status.runtime = 0;
923 else
924 global_status.topruntime = 0;
925 gui_synclist_speak_item(&lists);
928 if(default_event_handler(action) == SYS_USB_CONNECTED)
929 return true;
931 return false;