Remove .a files before running ar, to avoid problems with renamed files remaining...
[kugel-rb.git] / apps / screens.c
blob2bd77755691b5361d77a3e5bc8965b3114115c9a
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 gui_syncstatusbar_draw(&statusbars, true);
142 #ifdef SIMULATOR
143 while (button_get(true) & BUTTON_REL);
144 #else
145 usb_acknowledge(SYS_USB_CONNECTED_ACK);
146 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
147 if(usb_inserted()) {
148 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
149 led(mmc_usb_active(HZ));
150 #endif /* STORAGE_MMC */
151 gui_syncstatusbar_draw(&statusbars, false);
154 #endif /* SIMULATOR */
155 #ifdef HAVE_LCD_CHARCELLS
156 status_set_usb(false);
157 #endif /* HAVE_LCD_CHARCELLS */
158 FOR_NB_SCREENS(i)
159 screens[i].backlight_on();
160 global_settings.statusbar = statusbar;
161 #endif /* USB_NONE */
164 #if (CONFIG_STORAGE & STORAGE_MMC)
165 int mmc_remove_request(void)
167 struct queue_event ev;
168 int i;
169 FOR_NB_SCREENS(i)
170 screens[i].clear_display();
171 splash(0, ID2P(LANG_REMOVE_MMC));
173 while (1)
175 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
176 switch (ev.id)
178 case SYS_HOTSWAP_EXTRACTED:
179 return SYS_HOTSWAP_EXTRACTED;
181 case SYS_USB_DISCONNECTED:
182 return SYS_USB_DISCONNECTED;
186 #endif
188 /* the charging screen is only used for archos targets */
189 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
191 #ifdef HAVE_LCD_BITMAP
192 static void charging_display_info(bool animate)
194 unsigned char charging_logo[36];
195 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
196 const int pox_y = 32;
197 static unsigned phase = 3;
198 unsigned i;
199 char buf[32];
200 (void)buf;
202 #ifdef NEED_ATA_POWER_BATT_MEASURE
203 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
204 #endif
206 int battv = battery_voltage();
207 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
208 (battv % 1000) / 10, battery_level());
209 lcd_puts(0, 7, buf);
212 #if CONFIG_CHARGING == CHARGING_CONTROL
214 snprintf(buf, 32, "Charge mode:");
215 lcd_puts(0, 2, buf);
217 if (charge_state == CHARGING)
218 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
219 else if (charge_state == TOPOFF)
220 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
221 else if (charge_state == TRICKLE)
222 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
223 else
224 snprintf(buf, 32, "not charging");
226 lcd_puts(0, 3, buf);
227 if (!charger_enabled)
228 animate = false;
229 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
232 /* middle part */
233 memset(charging_logo+3, 0x00, 32);
234 charging_logo[0] = 0x3C;
235 charging_logo[1] = 0x24;
236 charging_logo[2] = charging_logo[35] = 0xFF;
238 if (!animate)
239 { /* draw the outline */
240 /* middle part */
241 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
242 sizeof(charging_logo), 8);
243 lcd_set_drawmode(DRMODE_FG);
244 /* upper line */
245 charging_logo[0] = charging_logo[1] = 0x00;
246 memset(charging_logo+2, 0x80, 34);
247 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
248 /* lower line */
249 memset(charging_logo+2, 0x01, 34);
250 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
251 sizeof(charging_logo), 8);
252 lcd_set_drawmode(DRMODE_SOLID);
254 else
255 { /* animate the middle part */
256 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
258 if ((i-phase) % 8 == 0)
259 { /* draw a "bubble" here */
260 unsigned bitpos;
261 bitpos = (phase + i/8) % 15; /* "bounce" effect */
262 if (bitpos > 7)
263 bitpos = 14 - bitpos;
264 charging_logo[i] = 0x01 << bitpos;
267 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
268 sizeof(charging_logo), 8);
269 phase++;
271 lcd_update();
273 #else /* not HAVE_LCD_BITMAP */
275 static unsigned long logo_chars[4];
276 static const unsigned char logo_pattern[] = {
277 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
278 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
279 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
280 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
283 static void logo_lock_patterns(bool on)
285 int i;
287 if (on)
289 for (i = 0; i < 4; i++)
290 logo_chars[i] = lcd_get_locked_pattern();
292 else
294 for (i = 0; i < 4; i++)
295 lcd_unlock_pattern(logo_chars[i]);
299 static void charging_display_info(bool animate)
301 int battv;
302 unsigned i, ypos;
303 static unsigned phase = 3;
304 char buf[32];
306 battv = battery_voltage();
307 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
308 lcd_puts(4, 1, buf);
310 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
312 if (!animate) /* build the screen */
314 lcd_double_height(false);
315 lcd_puts(0, 0, "[Charging]");
316 for (i = 0; i < 4; i++)
317 lcd_putc(i, 1, logo_chars[i]);
319 else /* animate the logo */
321 for (i = 3; i < MIN(19, phase); i++)
323 if ((i - phase) % 5 == 0)
324 { /* draw a "bubble" here */
325 ypos = (phase + i/5) % 9; /* "bounce" effect */
326 if (ypos > 4)
327 ypos = 8 - ypos;
328 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
331 phase++;
334 for (i = 0; i < 4; i++)
335 lcd_define_pattern(logo_chars[i], buf + 8 * i);
337 lcd_update();
339 #endif /* (not) HAVE_LCD_BITMAP */
341 /* blocks while charging, returns on event:
342 1 if charger cable was removed
343 2 if Off/Stop key was pressed
344 3 if On key was pressed
345 4 if USB was connected */
347 int charging_screen(void)
349 unsigned int button;
350 int rc = 0;
352 ide_power_enable(false); /* power down the disk, else would be spinning */
354 lcd_clear_display();
355 backlight_set_timeout(global_settings.backlight_timeout);
356 #ifdef HAVE_REMOTE_LCD
357 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
358 #endif
359 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
360 gui_syncstatusbar_draw(&statusbars, true);
362 #ifdef HAVE_LCD_CHARCELLS
363 logo_lock_patterns(true);
364 #endif
365 charging_display_info(false);
369 gui_syncstatusbar_draw(&statusbars, false);
370 charging_display_info(true);
371 button = get_action(CONTEXT_STD,HZ/3);
372 if (button == ACTION_STD_OK)
373 rc = 2;
374 else if (usb_detect() == USB_INSERTED)
375 rc = 3;
376 else if (!charger_inserted())
377 rc = 1;
378 } while (!rc);
380 #ifdef HAVE_LCD_CHARCELLS
381 logo_lock_patterns(false);
382 #endif
383 return rc;
385 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
387 #if CONFIG_CHARGING
388 void charging_splash(void)
390 splash(2*HZ, str(LANG_BATTERY_CHARGE));
391 button_clear_queue();
393 #endif
396 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
398 /* little helper function for voice output */
399 static void say_time(int cursorpos, const struct tm *tm)
401 int value = 0;
402 int unit = 0;
404 if (!global_settings.talk_menu)
405 return;
407 switch(cursorpos)
409 case 0:
410 value = tm->tm_hour;
411 unit = UNIT_HOUR;
412 break;
413 case 1:
414 value = tm->tm_min;
415 unit = UNIT_MIN;
416 break;
417 case 2:
418 value = tm->tm_sec;
419 unit = UNIT_SEC;
420 break;
421 case 3:
422 value = tm->tm_year + 1900;
423 break;
424 case 5:
425 value = tm->tm_mday;
426 break;
429 if (cursorpos == 4) /* month */
430 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
431 else
432 talk_value(value, unit, false);
436 #define INDEX_X 0
437 #define INDEX_Y 1
439 #define SEPARATOR ":"
440 bool set_time_screen(const char* title, struct tm *tm)
442 bool done = false;
443 int button;
444 unsigned int i, j, s;
445 int cursorpos = 0;
446 unsigned int julianday;
447 unsigned int realyear;
448 unsigned int width;
449 unsigned int min, max;
450 unsigned int statusbar_height = 0;
451 unsigned int separator_width, weekday_width;
452 unsigned int prev_line_height;
453 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
454 unsigned char buffer[20];
455 struct viewport vp[NB_SCREENS];
456 int nb_lines;
458 /* 6 possible cursor possitions, 2 values stored for each: x, y */
459 unsigned int cursor[6][2];
461 int *valptr = NULL;
462 unsigned char *ptr[6];
464 if(global_settings.statusbar)
465 statusbar_height = STATUSBAR_HEIGHT;
467 /* speak selection when screen is entered */
468 say_time(cursorpos, tm);
470 while (!done) {
471 /* for easy acess in the drawing loop */
472 ptr[0] = buffer; /* hours */
473 ptr[1] = buffer + 3; /* minutes */
474 ptr[2] = buffer + 6; /* seconds */
475 ptr[3] = buffer + 9; /* year */
476 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
477 ptr[5] = buffer + 14; /* day of month */
479 /* calculate the number of days in febuary */
480 realyear = tm->tm_year + 1900;
481 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
482 daysinmonth[1] = 29;
483 else
484 daysinmonth[1] = 28;
486 /* fix day if month or year changed */
487 if (tm->tm_mday > daysinmonth[tm->tm_mon])
488 tm->tm_mday = daysinmonth[tm->tm_mon];
490 /* calculate day of week */
491 julianday = tm->tm_mday;
492 for(i = 0; (int)i < tm->tm_mon; i++) {
493 julianday += daysinmonth[i];
496 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
497 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
499 /* put all the numbers we want from the tm struct into
500 an easily printable buffer */
501 snprintf(buffer, sizeof(buffer),
502 "%02d " "%02d " "%02d " "%04d " "%02d",
503 tm->tm_hour, tm->tm_min, tm->tm_sec,
504 tm->tm_year+1900, tm->tm_mday);
506 /* convert spaces in the buffer to '\0' to make it possible to work
507 directly on the buffer */
508 for(i=0; i < sizeof(buffer); i++)
510 if(buffer[i] == ' ')
511 buffer[i] = '\0';
514 FOR_NB_SCREENS(s)
516 viewport_set_defaults(&vp[s], s);
517 nb_lines = viewport_get_nb_lines(&vp[s]);
519 /* minimum lines needed is 2 + title line */
520 if (nb_lines < 4)
522 vp[s].font = FONT_SYSFIXED;
523 nb_lines = viewport_get_nb_lines(&vp[s]);
526 /* recalculate the positions and offsets */
527 if (nb_lines >= 3)
528 screens[s].getstringsize(title, NULL, &prev_line_height);
529 else
530 prev_line_height = 0;
532 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
534 /* weekday */
535 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
536 &weekday_width, NULL);
537 screens[s].getstringsize(" ", &separator_width, NULL);
539 for(i=0, j=0; i < 6; i++)
541 if(i==3) /* second row */
543 j = weekday_width + separator_width;;
544 prev_line_height *= 2;
546 screens[s].getstringsize(ptr[i], &width, NULL);
547 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
548 cursor[i][INDEX_X] = j;
549 j += width + separator_width;
552 /* draw the screen */
553 screens[s].set_viewport(&vp[s]);
554 screens[s].clear_viewport();
555 /* display the screen title */
556 screens[s].puts_scroll(0, 0, title);
558 /* these are not selectable, so we draw them outside the loop */
559 /* name of the week day */
560 screens[s].putsxy(0, cursor[3][INDEX_Y],
561 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
563 /* draw the selected item with drawmode set to
564 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
565 items with drawmode DRMODE_SOLID */
566 for(i=0; i<6; i++)
568 if (cursorpos == (int)i)
569 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
571 screens[s].putsxy(cursor[i][INDEX_X],
572 cursor[i][INDEX_Y], ptr[i]);
574 vp[s].drawmode = DRMODE_SOLID;
576 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
577 cursor[0][INDEX_Y], SEPARATOR);
580 /* print help text */
581 if (nb_lines > 4)
582 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
583 if (nb_lines > 5)
584 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
585 screens[s].update_viewport();
586 screens[s].set_viewport(NULL);
588 gui_syncstatusbar_draw(&statusbars, true);
590 /* set the most common numbers */
591 min = 0;
592 max = 59;
593 /* calculate the minimum and maximum for the number under cursor */
594 switch(cursorpos) {
595 case 0: /* hour */
596 max = 23;
597 valptr = &tm->tm_hour;
598 break;
599 case 1: /* minute */
600 valptr = &tm->tm_min;
601 break;
602 case 2: /* second */
603 valptr = &tm->tm_sec;
604 break;
605 case 3: /* year */
606 min = 1;
607 max = 200;
608 valptr = &tm->tm_year;
609 break;
610 case 4: /* month */
611 max = 11;
612 valptr = &tm->tm_mon;
613 break;
614 case 5: /* day */
615 min = 1;
616 max = daysinmonth[tm->tm_mon];
617 valptr = &tm->tm_mday;
618 break;
621 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
622 switch ( button ) {
623 case ACTION_STD_PREV:
624 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
625 say_time(cursorpos, tm);
626 break;
627 case ACTION_STD_NEXT:
628 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
629 say_time(cursorpos, tm);
630 break;
631 case ACTION_SETTINGS_INC:
632 case ACTION_SETTINGS_INCREPEAT:
633 *valptr = clamp_value_wrap(++(*valptr), max, min);
634 say_time(cursorpos, tm);
635 break;
636 case ACTION_SETTINGS_DEC:
637 case ACTION_SETTINGS_DECREPEAT:
638 *valptr = clamp_value_wrap(--(*valptr), max, min);
639 say_time(cursorpos, tm);
640 break;
642 case ACTION_STD_OK:
643 done = true;
644 break;
646 case ACTION_STD_CANCEL:
647 done = true;
648 tm->tm_year = -1;
649 break;
651 default:
652 if (default_event_handler(button) == SYS_USB_CONNECTED)
653 return true;
654 break;
657 return false;
659 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
661 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
662 bool shutdown_screen(void)
664 int button;
665 bool done = false;
666 long time_entered = current_tick;
668 lcd_stop_scroll();
670 splash(0, str(LANG_CONFIRM_SHUTDOWN));
672 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
674 button = get_action(CONTEXT_STD,HZ);
675 switch(button)
677 case ACTION_STD_CANCEL:
678 sys_poweroff();
679 break;
681 /* do nothing here, because ACTION_NONE might be caused
682 * by timeout or button release. In case of timeout the loop
683 * is terminated by TIME_BEFORE */
684 case ACTION_NONE:
685 break;
687 default:
688 if(default_event_handler(button) == SYS_USB_CONNECTED)
689 return true;
690 done = true;
691 break;
694 return false;
696 #endif
698 static const int id3_headers[]=
700 LANG_ID3_TITLE,
701 LANG_ID3_ARTIST,
702 LANG_ID3_ALBUM,
703 LANG_ID3_ALBUMARTIST,
704 LANG_ID3_GROUPING,
705 LANG_ID3_DISCNUM,
706 LANG_ID3_TRACKNUM,
707 LANG_ID3_COMMENT,
708 LANG_ID3_GENRE,
709 LANG_ID3_YEAR,
710 LANG_ID3_LENGTH,
711 LANG_ID3_PLAYLIST,
712 LANG_ID3_BITRATE,
713 LANG_ID3_FREQUENCY,
714 #if CONFIG_CODEC == SWCODEC
715 LANG_ID3_TRACK_GAIN,
716 LANG_ID3_ALBUM_GAIN,
717 #endif
718 LANG_ID3_PATH,
720 struct id3view_info {
721 struct mp3entry* id3;
722 int count;
723 int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])];
725 static char * id3_get_info(int selected_item, void* data,
726 char *buffer, size_t buffer_len)
728 struct id3view_info *info = (struct id3view_info*)data;
729 struct mp3entry* id3 =info->id3;
730 int info_no=selected_item/2;
731 if(!(selected_item%2))
732 {/* header */
733 return( str(id3_headers[info->info_id[info_no]]));
735 else
736 {/* data */
738 char * val=NULL;
739 switch(info->info_id[info_no])
741 case 0:/*LANG_ID3_TITLE*/
742 val=id3->title;
743 break;
744 case 1:/*LANG_ID3_ARTIST*/
745 val=id3->artist;
746 break;
747 case 2:/*LANG_ID3_ALBUM*/
748 val=id3->album;
749 break;
750 case 3:/*LANG_ID3_ALBUMARTIST*/
751 val=id3->albumartist;
752 break;
753 case 4:/*LANG_ID3_GROUPING*/
754 val=id3->grouping;
755 break;
756 case 5:/*LANG_ID3_DISCNUM*/
757 if (id3->disc_string)
758 val = id3->disc_string;
759 else if (id3->discnum)
761 snprintf(buffer, buffer_len, "%d", id3->discnum);
762 val = buffer;
764 break;
765 case 6:/*LANG_ID3_TRACKNUM*/
766 if (id3->track_string)
767 val = id3->track_string;
768 else if (id3->tracknum)
770 snprintf(buffer, buffer_len, "%d", id3->tracknum);
771 val = buffer;
773 break;
774 case 7:/*LANG_ID3_COMMENT*/
775 val=id3->comment;
776 break;
777 case 8:/*LANG_ID3_GENRE*/
778 val = id3->genre_string;
779 break;
780 case 9:/*LANG_ID3_YEAR*/
781 if (id3->year_string)
782 val = id3->year_string;
783 else if (id3->year)
785 snprintf(buffer, buffer_len, "%d", id3->year);
786 val = buffer;
788 break;
789 case 10:/*LANG_ID3_LENGTH*/
790 format_time(buffer, buffer_len, id3->length);
791 val=buffer;
792 break;
793 case 11:/*LANG_ID3_PLAYLIST*/
794 snprintf(buffer, buffer_len, "%d/%d",
795 playlist_get_display_index(), playlist_amount());
796 val=buffer;
797 break;
798 case 12:/*LANG_ID3_BITRATE*/
799 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
800 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
801 val=buffer;
802 break;
803 case 13:/*LANG_ID3_FREQUENCY*/
804 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
805 val=buffer;
806 break;
807 #if CONFIG_CODEC == SWCODEC
808 case 14:/*LANG_ID3_TRACK_GAIN*/
809 val=id3->track_gain_string;
810 break;
811 case 15:/*LANG_ID3_ALBUM_GAIN*/
812 val=id3->album_gain_string;
813 break;
814 case 16:/*LANG_ID3_PATH*/
815 #else
816 case 14:/*LANG_ID3_PATH*/
817 #endif
818 val=id3->path;
819 break;
821 return val && *val ? val : NULL;
825 bool browse_id3(void)
827 struct gui_synclist id3_lists;
828 struct mp3entry* id3 = audio_current_track();
829 int key;
830 unsigned int i;
831 struct id3view_info info;
832 info.count = 0;
833 info.id3 = id3;
834 for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++)
836 char temp[8];
837 info.info_id[i] = i;
838 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
839 info.info_id[info.count++] = i;
842 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
843 gui_synclist_set_nb_items(&id3_lists, info.count*2);
844 gui_synclist_draw(&id3_lists);
845 gui_syncstatusbar_draw(&statusbars, true);
846 while (true) {
847 gui_syncstatusbar_draw(&statusbars, false);
848 key = get_action(CONTEXT_LIST,HZ/2);
849 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
850 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
852 return(default_event_handler(key) == SYS_USB_CONNECTED);
857 static char* runtime_get_data(int selected_item, void* data,
858 char* buffer, size_t buffer_len)
860 (void)data;
861 int t;
862 switch (selected_item)
864 case 0: return str(LANG_RUNNING_TIME);
865 case 1: t = global_status.runtime; break;
866 case 2: return str(LANG_TOP_TIME);
867 case 3: t = global_status.topruntime; break;
868 default:
869 return "";
872 snprintf(buffer, buffer_len, "%dh %dm %ds",
873 t / 3600, (t % 3600) / 60, t % 60);
874 return buffer;
877 static int runtime_speak_data(int selected_item, void* data)
879 (void) data;
880 talk_ids(false,
881 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
882 TALK_ID((selected_item < 2) ? global_status.runtime
883 : global_status.topruntime, UNIT_TIME));
884 return 0;
888 bool view_runtime(void)
890 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
891 static const struct text_message message={lines, 1};
893 struct gui_synclist lists;
894 int action;
895 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
896 #if !defined(HAVE_LCD_CHARCELLS)
897 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
898 #else
899 gui_synclist_set_title(&lists, NULL, NOICON);
900 #endif
901 if(global_settings.talk_menu)
902 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
903 gui_synclist_set_icon_callback(&lists, NULL);
904 gui_synclist_set_nb_items(&lists, 4);
905 gui_synclist_speak_item(&lists);
906 while(1)
908 #if CONFIG_CHARGING
909 if (charger_inserted()
910 #ifdef HAVE_USB_POWER
911 || usb_powered()
912 #endif
915 global_status.runtime = 0;
917 else
918 #endif
920 global_status.runtime += ((current_tick - lasttime) / HZ);
922 lasttime = current_tick;
923 gui_synclist_draw(&lists);
924 gui_syncstatusbar_draw(&statusbars, true);
925 list_do_action(CONTEXT_STD, HZ,
926 &lists, &action, LIST_WRAP_UNLESS_HELD);
927 if(action == ACTION_STD_CANCEL)
928 break;
929 if(action == ACTION_STD_OK) {
930 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
932 if (!(gui_synclist_get_sel_pos(&lists)/2))
933 global_status.runtime = 0;
934 else
935 global_status.topruntime = 0;
936 gui_synclist_speak_item(&lists);
939 if(default_event_handler(action) == SYS_USB_CONNECTED)
940 return true;
942 return false;