Fix reds. No need for #ifdef to save buttons anymore.
[maemo-rb.git] / apps / screens.c
blob8d4585f7b3688314d4466d8c1c5691bbbeba83ce
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 #include "lang.h"
29 #include "icons.h"
30 #include "font.h"
31 #include "audio.h"
32 #include "mp3_playback.h"
33 #include "usb.h"
34 #include "settings.h"
35 #include "status.h"
36 #include "playlist.h"
37 #include "kernel.h"
38 #include "power.h"
39 #include "system.h"
40 #include "powermgmt.h"
41 #include "talk.h"
42 #include "misc.h"
43 #include "metadata.h"
44 #include "screens.h"
45 #include "debug.h"
46 #include "led.h"
47 #include "sound.h"
48 #include "splash.h"
49 #include "statusbar.h"
50 #include "screen_access.h"
51 #include "list.h"
52 #include "yesno.h"
53 #include "backdrop.h"
54 #include "viewport.h"
55 #include "language.h"
56 #include "replaygain.h"
58 #if CONFIG_CODEC == SWCODEC
59 #include "dsp.h"
60 #endif
62 #if defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
63 #include "adc.h"
64 #endif
66 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
67 int mmc_remove_request(void)
69 struct queue_event ev;
70 FOR_NB_SCREENS(i)
71 screens[i].clear_display();
72 splash(0, ID2P(LANG_REMOVE_MMC));
74 while (1)
76 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
77 switch (ev.id)
79 case SYS_HOTSWAP_EXTRACTED:
80 return SYS_HOTSWAP_EXTRACTED;
82 case SYS_USB_DISCONNECTED:
83 return SYS_USB_DISCONNECTED;
87 #endif
89 /* the charging screen is only used for archos targets */
90 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
92 #ifdef HAVE_LCD_BITMAP
93 static void charging_display_info(bool animate)
95 unsigned char charging_logo[36];
96 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
97 const int pox_y = 32;
98 static unsigned phase = 3;
99 unsigned i;
101 #if !defined(NEED_ATA_POWER_BATT_MEASURE)
103 int battv = battery_voltage();
104 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
105 (battv % 1000) / 10, battery_level());
107 #elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
108 /* IDE power is normally off here, so display input current instead */
109 lcd_putsf(7, 7, "%dmA ",
110 (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000);
111 #endif
113 #ifdef ARCHOS_RECORDER
114 lcd_puts(0, 2, "Charge mode:");
116 const char *s;
117 if (charge_state == CHARGING)
118 s = str(LANG_BATTERY_CHARGE);
119 else if (charge_state == TOPOFF)
120 s = str(LANG_BATTERY_TOPOFF_CHARGE);
121 else if (charge_state == TRICKLE)
122 s = str(LANG_BATTERY_TRICKLE_CHARGE);
123 else
124 s = "not charging";
126 lcd_puts(0, 3, s);
127 if (!charger_enabled())
128 animate = false;
129 #endif /* ARCHOS_RECORDER */
131 /* middle part */
132 memset(charging_logo+3, 0x00, 32);
133 charging_logo[0] = 0x3C;
134 charging_logo[1] = 0x24;
135 charging_logo[2] = charging_logo[35] = 0xFF;
137 if (!animate)
138 { /* draw the outline */
139 /* middle part */
140 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
141 sizeof(charging_logo), 8);
142 lcd_set_drawmode(DRMODE_FG);
143 /* upper line */
144 charging_logo[0] = charging_logo[1] = 0x00;
145 memset(charging_logo+2, 0x80, 34);
146 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
147 /* lower line */
148 memset(charging_logo+2, 0x01, 34);
149 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
150 sizeof(charging_logo), 8);
151 lcd_set_drawmode(DRMODE_SOLID);
153 else
154 { /* animate the middle part */
155 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
157 if ((i-phase) % 8 == 0)
158 { /* draw a "bubble" here */
159 unsigned bitpos;
160 bitpos = (phase + i/8) % 15; /* "bounce" effect */
161 if (bitpos > 7)
162 bitpos = 14 - bitpos;
163 charging_logo[i] = BIT_N(bitpos);
166 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
167 sizeof(charging_logo), 8);
168 phase++;
170 lcd_update();
172 #else /* not HAVE_LCD_BITMAP */
174 static unsigned long logo_chars[4];
175 static const unsigned char logo_pattern[] = {
176 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
177 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
178 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
179 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
182 static void logo_lock_patterns(bool on)
184 int i;
186 if (on)
188 for (i = 0; i < 4; i++)
189 logo_chars[i] = lcd_get_locked_pattern();
191 else
193 for (i = 0; i < 4; i++)
194 lcd_unlock_pattern(logo_chars[i]);
198 static void charging_display_info(bool animate)
200 int battv;
201 unsigned i, ypos;
202 static unsigned phase = 3;
203 char buf[32];
205 battv = battery_voltage();
206 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
208 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
210 if (!animate) /* build the screen */
212 lcd_double_height(false);
213 lcd_puts(0, 0, "[Charging]");
214 for (i = 0; i < 4; i++)
215 lcd_putc(i, 1, logo_chars[i]);
217 else /* animate the logo */
219 for (i = 3; i < MIN(19, phase); i++)
221 if ((i - phase) % 5 == 0)
222 { /* draw a "bubble" here */
223 ypos = (phase + i/5) % 9; /* "bounce" effect */
224 if (ypos > 4)
225 ypos = 8 - ypos;
226 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
229 phase++;
232 for (i = 0; i < 4; i++)
233 lcd_define_pattern(logo_chars[i], buf + 8 * i);
235 lcd_update();
237 #endif /* (not) HAVE_LCD_BITMAP */
239 /* blocks while charging, returns on event:
240 1 if charger cable was removed
241 2 if Off/Stop key was pressed
242 3 if On key was pressed
243 4 if USB was connected */
245 int charging_screen(void)
247 unsigned int button;
248 int rc = 0;
250 ide_power_enable(false); /* power down the disk, else would be spinning */
252 lcd_clear_display();
253 backlight_set_timeout(global_settings.backlight_timeout);
254 #ifdef HAVE_REMOTE_LCD
255 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
256 #endif
257 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
259 #ifdef HAVE_LCD_CHARCELLS
260 logo_lock_patterns(true);
261 #endif
262 charging_display_info(false);
266 gui_syncstatusbar_draw(&statusbars, false);
267 charging_display_info(true);
268 button = get_action(CONTEXT_STD,HZ/3);
269 if (button == ACTION_STD_OK)
270 rc = 2;
271 else if (usb_detect() == USB_INSERTED)
272 rc = 3;
273 /* do not depend on power management thread here */
274 else if (!(power_input_status() & POWER_INPUT_MAIN_CHARGER))
275 rc = 1;
276 } while (!rc);
278 #ifdef HAVE_LCD_CHARCELLS
279 logo_lock_patterns(false);
280 #endif
281 return rc;
283 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
285 #if CONFIG_CHARGING
286 void charging_splash(void)
288 splash(2*HZ, str(LANG_BATTERY_CHARGE));
289 button_clear_queue();
291 #endif
294 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
296 /* little helper function for voice output */
297 static void say_time(int cursorpos, const struct tm *tm)
299 int value = 0;
300 int unit = 0;
302 if (!global_settings.talk_menu)
303 return;
305 switch(cursorpos)
307 case 0:
308 value = tm->tm_hour;
309 unit = UNIT_HOUR;
310 break;
311 case 1:
312 value = tm->tm_min;
313 unit = UNIT_MIN;
314 break;
315 case 2:
316 value = tm->tm_sec;
317 unit = UNIT_SEC;
318 break;
319 case 3:
320 value = tm->tm_year + 1900;
321 break;
322 case 5:
323 value = tm->tm_mday;
324 break;
327 if (cursorpos == 4) /* month */
328 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
329 else
330 talk_value(value, unit, false);
334 #define INDEX_X 0
335 #define INDEX_Y 1
337 #define SEPARATOR ":"
339 #define IDX_HOURS 0
340 #define IDX_MINUTES 1
341 #define IDX_SECONDS 2
342 #define IDX_YEAR 3
343 #define IDX_MONTH 4
344 #define IDX_DAY 5
346 #define OFF_HOURS 0
347 #define OFF_MINUTES 3
348 #define OFF_SECONDS 6
349 #define OFF_YEAR 9
350 #define OFF_DAY 14
352 bool set_time_screen(const char* title, struct tm *tm)
354 struct viewport viewports[NB_SCREENS];
355 bool done = false, usb = false;
356 int cursorpos = 0;
357 unsigned char offsets_ptr[] =
358 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
360 if (lang_is_rtl())
362 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
363 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
364 offsets_ptr[IDX_YEAR] = OFF_DAY;
365 offsets_ptr[IDX_DAY] = OFF_YEAR;
368 /* speak selection when screen is entered */
369 say_time(cursorpos, tm);
371 #ifdef HAVE_TOUCHSCREEN
372 enum touchscreen_mode old_mode = touchscreen_get_mode();
373 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
374 #endif
375 while (!done) {
376 int button;
377 unsigned int i, realyear, min, max;
378 unsigned char *ptr[6];
379 unsigned char buffer[20];
380 int *valptr = NULL;
381 static unsigned char daysinmonth[] =
382 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
384 /* for easy acess in the drawing loop */
385 for (i = 0; i < 6; i++)
386 ptr[i] = buffer + offsets_ptr[i];
387 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
389 /* calculate the number of days in febuary */
390 realyear = tm->tm_year + 1900;
391 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
392 daysinmonth[1] = 29;
393 else
394 daysinmonth[1] = 28;
396 /* fix day if month or year changed */
397 if (tm->tm_mday > daysinmonth[tm->tm_mon])
398 tm->tm_mday = daysinmonth[tm->tm_mon];
400 /* calculate day of week */
401 set_day_of_week(tm);
403 /* put all the numbers we want from the tm struct into
404 an easily printable buffer */
405 snprintf(buffer, sizeof(buffer),
406 "%02d " "%02d " "%02d " "%04d " "%02d",
407 tm->tm_hour, tm->tm_min, tm->tm_sec,
408 tm->tm_year+1900, tm->tm_mday);
410 /* convert spaces in the buffer to '\0' to make it possible to work
411 directly on the buffer */
412 for(i=0; i < sizeof(buffer); i++)
414 if(buffer[i] == ' ')
415 buffer[i] = '\0';
418 FOR_NB_SCREENS(s)
420 int pos, nb_lines;
421 unsigned int separator_width, weekday_width;
422 unsigned int j, width, prev_line_height;
423 /* 6 possible cursor possitions, 2 values stored for each: x, y */
424 unsigned int cursor[6][2];
425 struct viewport *vp = &viewports[s];
426 struct screen *screen = &screens[s];
427 static unsigned char rtl_idx[] =
428 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
430 viewport_set_defaults(vp, s);
431 screen->set_viewport(vp);
432 nb_lines = viewport_get_nb_lines(vp);
434 /* minimum lines needed is 2 + title line */
435 if (nb_lines < 4)
437 vp->font = FONT_SYSFIXED;
438 nb_lines = viewport_get_nb_lines(vp);
441 /* recalculate the positions and offsets */
442 if (nb_lines >= 3)
443 screen->getstringsize(title, NULL, &prev_line_height);
444 else
445 prev_line_height = 0;
447 screen->getstringsize(SEPARATOR, &separator_width, NULL);
449 /* weekday */
450 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
451 &weekday_width, NULL);
452 screen->getstringsize(" ", &separator_width, NULL);
454 for(i=0, j=0; i < 6; i++)
456 if(i==3) /* second row */
458 j = weekday_width + separator_width;
459 prev_line_height *= 2;
461 screen->getstringsize(ptr[i], &width, NULL);
462 cursor[i][INDEX_Y] = prev_line_height;
463 cursor[i][INDEX_X] = j;
464 j += width + separator_width;
467 /* draw the screen */
468 screen->set_viewport(vp);
469 screen->clear_viewport();
470 /* display the screen title */
471 screen->puts_scroll(0, 0, title);
473 /* these are not selectable, so we draw them outside the loop */
474 /* name of the week day */
475 screen->putsxy(0, cursor[3][INDEX_Y],
476 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
478 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
479 /* draw the selected item with drawmode set to
480 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
481 items with drawmode DRMODE_SOLID */
482 for(i=0; i<6; i++)
484 if (pos == (int)i)
485 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
487 screen->putsxy(cursor[i][INDEX_X],
488 cursor[i][INDEX_Y], ptr[i]);
490 vp->drawmode = DRMODE_SOLID;
492 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
493 cursor[0][INDEX_Y], SEPARATOR);
496 /* print help text */
497 if (nb_lines > 4)
498 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
499 if (nb_lines > 5)
500 screen->puts(0, 5, str(LANG_TIME_REVERT));
501 screen->update_viewport();
502 screen->set_viewport(NULL);
505 /* set the most common numbers */
506 min = 0;
507 max = 59;
508 /* calculate the minimum and maximum for the number under cursor */
509 switch(cursorpos) {
510 case 0: /* hour */
511 max = 23;
512 valptr = &tm->tm_hour;
513 break;
514 case 1: /* minute */
515 valptr = &tm->tm_min;
516 break;
517 case 2: /* second */
518 valptr = &tm->tm_sec;
519 break;
520 case 3: /* year */
521 min = 1;
522 max = 200;
523 valptr = &tm->tm_year;
524 break;
525 case 4: /* month */
526 max = 11;
527 valptr = &tm->tm_mon;
528 break;
529 case 5: /* day */
530 min = 1;
531 max = daysinmonth[tm->tm_mon];
532 valptr = &tm->tm_mday;
533 break;
536 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
537 switch ( button ) {
538 case ACTION_STD_PREV:
539 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
540 say_time(cursorpos, tm);
541 break;
542 case ACTION_STD_NEXT:
543 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
544 say_time(cursorpos, tm);
545 break;
546 case ACTION_SETTINGS_INC:
547 case ACTION_SETTINGS_INCREPEAT:
548 *valptr = clamp_value_wrap(++(*valptr), max, min);
549 say_time(cursorpos, tm);
550 break;
551 case ACTION_SETTINGS_DEC:
552 case ACTION_SETTINGS_DECREPEAT:
553 *valptr = clamp_value_wrap(--(*valptr), max, min);
554 say_time(cursorpos, tm);
555 break;
557 case ACTION_STD_OK:
558 done = true;
559 break;
561 case ACTION_STD_CANCEL:
562 done = true;
563 tm->tm_year = -1;
564 break;
566 default:
567 if (default_event_handler(button) == SYS_USB_CONNECTED)
568 done = usb = true;
569 break;
572 FOR_NB_SCREENS(s)
573 screens[s].scroll_stop(&viewports[s]);
574 #ifdef HAVE_TOUCHSCREEN
575 touchscreen_set_mode(old_mode);
576 #endif
577 return usb;
579 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
581 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
582 bool shutdown_screen(void)
584 int button;
585 bool done = false;
586 long time_entered = current_tick;
588 lcd_stop_scroll();
590 splash(0, str(LANG_CONFIRM_SHUTDOWN));
592 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
594 button = get_action(CONTEXT_STD,HZ);
595 switch(button)
597 case ACTION_STD_CANCEL:
598 sys_poweroff();
599 break;
601 /* do nothing here, because ACTION_NONE might be caused
602 * by timeout or button release. In case of timeout the loop
603 * is terminated by TIME_BEFORE */
604 case ACTION_NONE:
605 break;
607 default:
608 if(default_event_handler(button) == SYS_USB_CONNECTED)
609 return true;
610 done = true;
611 break;
614 return false;
616 #endif
618 static const int id3_headers[]=
620 LANG_ID3_TITLE,
621 LANG_ID3_ARTIST,
622 LANG_ID3_COMPOSER,
623 LANG_ID3_ALBUM,
624 LANG_ID3_ALBUMARTIST,
625 LANG_ID3_GROUPING,
626 LANG_ID3_DISCNUM,
627 LANG_ID3_TRACKNUM,
628 LANG_ID3_COMMENT,
629 LANG_ID3_GENRE,
630 LANG_ID3_YEAR,
631 LANG_ID3_LENGTH,
632 LANG_ID3_PLAYLIST,
633 LANG_ID3_BITRATE,
634 LANG_ID3_FREQUENCY,
635 #if CONFIG_CODEC == SWCODEC
636 LANG_ID3_TRACK_GAIN,
637 LANG_ID3_ALBUM_GAIN,
638 #endif
639 LANG_FILESIZE,
640 LANG_ID3_PATH,
643 struct id3view_info {
644 struct mp3entry* id3;
645 int count;
646 int info_id[ARRAYLEN(id3_headers)];
649 static const char* id3_get_info(int selected_item, void* data,
650 char *buffer, size_t buffer_len)
652 struct id3view_info *info = (struct id3view_info*)data;
653 struct mp3entry* id3 =info->id3;
654 int info_no=selected_item/2;
655 if(!(selected_item%2))
656 {/* header */
657 snprintf(buffer, buffer_len,
658 "[%s]", str(id3_headers[info->info_id[info_no]]));
659 return buffer;
661 else
662 {/* data */
664 char * val=NULL;
665 switch(id3_headers[info->info_id[info_no]])
667 case LANG_ID3_TITLE:
668 val=id3->title;
669 break;
670 case LANG_ID3_ARTIST:
671 val=id3->artist;
672 break;
673 case LANG_ID3_ALBUM:
674 val=id3->album;
675 break;
676 case LANG_ID3_ALBUMARTIST:
677 val=id3->albumartist;
678 break;
679 case LANG_ID3_GROUPING:
680 val=id3->grouping;
681 break;
682 case LANG_ID3_DISCNUM:
683 if (id3->disc_string)
684 val = id3->disc_string;
685 else if (id3->discnum)
687 snprintf(buffer, buffer_len, "%d", id3->discnum);
688 val = buffer;
690 break;
691 case LANG_ID3_TRACKNUM:
692 if (id3->track_string)
693 val = id3->track_string;
694 else if (id3->tracknum)
696 snprintf(buffer, buffer_len, "%d", id3->tracknum);
697 val = buffer;
699 break;
700 case LANG_ID3_COMMENT:
701 if (!id3->comment)
702 return NULL;
703 snprintf(buffer, buffer_len, "%s", id3->comment);
704 val=buffer;
705 break;
706 case LANG_ID3_GENRE:
707 val = id3->genre_string;
708 break;
709 case LANG_ID3_YEAR:
710 if (id3->year_string)
711 val = id3->year_string;
712 else if (id3->year)
714 snprintf(buffer, buffer_len, "%d", id3->year);
715 val = buffer;
717 break;
718 case LANG_ID3_LENGTH:
719 format_time(buffer, buffer_len, id3->length);
720 val=buffer;
721 break;
722 case LANG_ID3_PLAYLIST:
723 snprintf(buffer, buffer_len, "%d/%d",
724 playlist_get_display_index(), playlist_amount());
725 val=buffer;
726 break;
727 case LANG_ID3_BITRATE:
728 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
729 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
730 val=buffer;
731 break;
732 case LANG_ID3_FREQUENCY:
733 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
734 val=buffer;
735 break;
736 #if CONFIG_CODEC == SWCODEC
737 case LANG_ID3_TRACK_GAIN:
738 replaygain_itoa(buffer, buffer_len, id3->track_level);
739 val=(id3->track_level) ? buffer : NULL; /* only show level!=0 */
740 break;
741 case LANG_ID3_ALBUM_GAIN:
742 replaygain_itoa(buffer, buffer_len, id3->album_level);
743 val=(id3->album_level) ? buffer : NULL; /* only show level!=0 */
744 break;
745 #endif
746 case LANG_ID3_PATH:
747 val=id3->path;
748 break;
749 case LANG_ID3_COMPOSER:
750 val=id3->composer;
751 break;
752 case LANG_FILESIZE: /* not LANG_ID3_FILESIZE because the string is shared */
753 output_dyn_value(buffer, buffer_len, id3->filesize, byte_units, true);
754 val=buffer;
755 break;
757 return val && *val ? val : NULL;
761 bool browse_id3(void)
763 struct gui_synclist id3_lists;
764 struct mp3entry* id3 = audio_current_track();
765 int key;
766 unsigned int i;
767 struct id3view_info info;
768 info.count = 0;
769 info.id3 = id3;
770 for (i = 0; i < ARRAYLEN(id3_headers); i++)
772 char temp[8];
773 info.info_id[i] = i;
774 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
775 info.info_id[info.count++] = i;
778 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
779 gui_synclist_set_nb_items(&id3_lists, info.count*2);
780 gui_synclist_draw(&id3_lists);
781 while (true) {
782 key = get_action(CONTEXT_LIST,HZ/2);
783 if(!gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
785 if (key == ACTION_STD_OK || key == ACTION_STD_CANCEL)
786 return false;
787 else if (key == ACTION_STD_MENU ||
788 default_event_handler(key) == SYS_USB_CONNECTED)
789 return true;
794 static const char* runtime_get_data(int selected_item, void* data,
795 char* buffer, size_t buffer_len)
797 (void)data;
798 int t;
799 switch (selected_item)
801 case 0: return str(LANG_RUNNING_TIME);
802 case 1: t = global_status.runtime; break;
803 case 2: return str(LANG_TOP_TIME);
804 case 3: t = global_status.topruntime; break;
805 default:
806 return "";
809 snprintf(buffer, buffer_len, "%dh %dm %ds",
810 t / 3600, (t % 3600) / 60, t % 60);
811 return buffer;
814 static int runtime_speak_data(int selected_item, void* data)
816 (void) data;
817 talk_ids(false,
818 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
819 TALK_ID((selected_item < 2) ? global_status.runtime
820 : global_status.topruntime, UNIT_TIME));
821 return 0;
825 bool view_runtime(void)
827 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
828 static const struct text_message message={lines, 1};
830 struct gui_synclist lists;
831 int action;
832 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
833 #if !defined(HAVE_LCD_CHARCELLS)
834 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
835 #else
836 gui_synclist_set_title(&lists, NULL, NOICON);
837 #endif
838 if(global_settings.talk_menu)
839 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
840 gui_synclist_set_icon_callback(&lists, NULL);
841 gui_synclist_set_nb_items(&lists, 4);
842 gui_synclist_speak_item(&lists);
843 while(1)
845 global_status.runtime += ((current_tick - lasttime) / HZ);
847 lasttime = current_tick;
848 gui_synclist_draw(&lists);
849 list_do_action(CONTEXT_STD, HZ,
850 &lists, &action, LIST_WRAP_UNLESS_HELD);
851 if(action == ACTION_STD_CANCEL)
852 break;
853 if(action == ACTION_STD_OK) {
854 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
856 if (!(gui_synclist_get_sel_pos(&lists)/2))
857 global_status.runtime = 0;
858 else
859 global_status.topruntime = 0;
860 gui_synclist_speak_item(&lists);
863 if(default_event_handler(action) == SYS_USB_CONNECTED)
864 return true;
866 return false;
869 #ifdef HAVE_TOUCHSCREEN
870 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
871 struct screen* screen)
873 int action;
874 short ts_x, ts_y;
876 /* Draw a cross */
877 screen->drawline(x - 10, y, x - 2, y);
878 screen->drawline(x + 2, y, x + 10, y);
879 screen->drawline(x, y - 10, x, y - 2);
880 screen->drawline(x, y + 2, x, y + 10);
881 screen->update();
883 /* Wait for a touchscreen press */
884 while(true)
886 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
887 if(action == ACTION_TOUCHSCREEN)
889 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
890 break;
892 else if(action == ACTION_STD_CANCEL)
893 return -1;
896 cal->x[i][0] = ts_x;
897 cal->y[i][0] = ts_y;
898 cal->x[i][1] = x;
899 cal->y[i][1] = y;
901 return 0;
905 int calibrate(void)
907 short points[3][2] = {
908 {LCD_WIDTH/10, LCD_HEIGHT/10},
909 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
910 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
912 struct screen* screen = &screens[SCREEN_MAIN];
913 enum touchscreen_mode old_mode = touchscreen_get_mode();
914 struct touchscreen_calibration cal;
915 int i, ret = 0;
917 /* hide the statusbar */
918 viewportmanager_theme_enable(SCREEN_MAIN, false, NULL);
920 touchscreen_disable_mapping(); /* set raw mode */
921 touchscreen_set_mode(TOUCHSCREEN_POINT);
923 for(i=0; i<3; i++)
925 screen->clear_display();
927 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
929 ret = -1;
930 break;
934 if(ret == 0)
935 touchscreen_calibrate(&cal);
936 else
937 touchscreen_reset_mapping();
939 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
940 sizeof(struct touchscreen_parameter));
942 touchscreen_set_mode(old_mode);
943 viewportmanager_theme_undo(SCREEN_MAIN, false);
945 settings_save();
946 return ret;
949 int reset_mapping(void)
951 touchscreen_reset_mapping();
953 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
954 sizeof(struct touchscreen_parameter));
956 settings_save();
957 return 0;
959 #endif