skin tags: fix the id3 track/disc numbers in conditionals
[maemo-rb.git] / apps / screens.c
blobd02f29b4fe0dfc873f53e4aee9e2919aa8533457
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 defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
59 #include "adc.h"
60 #endif
62 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
63 int mmc_remove_request(void)
65 struct queue_event ev;
66 FOR_NB_SCREENS(i)
67 screens[i].clear_display();
68 splash(0, ID2P(LANG_REMOVE_MMC));
70 while (1)
72 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
73 switch (ev.id)
75 case SYS_HOTSWAP_EXTRACTED:
76 return SYS_HOTSWAP_EXTRACTED;
78 case SYS_USB_DISCONNECTED:
79 return SYS_USB_DISCONNECTED;
83 #endif
85 /* the charging screen is only used for archos targets */
86 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
88 #ifdef HAVE_LCD_BITMAP
89 static void charging_display_info(bool animate)
91 unsigned char charging_logo[36];
92 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
93 const int pox_y = 32;
94 static unsigned phase = 3;
95 unsigned i;
97 #if !defined(NEED_ATA_POWER_BATT_MEASURE)
99 int battv = battery_voltage();
100 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000,
101 (battv % 1000) / 10, battery_level());
103 #elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
104 /* IDE power is normally off here, so display input current instead */
105 lcd_putsf(7, 7, "%dmA ",
106 (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000);
107 #endif
109 #ifdef ARCHOS_RECORDER
110 lcd_puts(0, 2, "Charge mode:");
112 const char *s;
113 if (charge_state == CHARGING)
114 s = str(LANG_BATTERY_CHARGE);
115 else if (charge_state == TOPOFF)
116 s = str(LANG_BATTERY_TOPOFF_CHARGE);
117 else if (charge_state == TRICKLE)
118 s = str(LANG_BATTERY_TRICKLE_CHARGE);
119 else
120 s = "not charging";
122 lcd_puts(0, 3, s);
123 if (!charger_enabled())
124 animate = false;
125 #endif /* ARCHOS_RECORDER */
127 /* middle part */
128 memset(charging_logo+3, 0x00, 32);
129 charging_logo[0] = 0x3C;
130 charging_logo[1] = 0x24;
131 charging_logo[2] = charging_logo[35] = 0xFF;
133 if (!animate)
134 { /* draw the outline */
135 /* middle part */
136 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
137 sizeof(charging_logo), 8);
138 lcd_set_drawmode(DRMODE_FG);
139 /* upper line */
140 charging_logo[0] = charging_logo[1] = 0x00;
141 memset(charging_logo+2, 0x80, 34);
142 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
143 /* lower line */
144 memset(charging_logo+2, 0x01, 34);
145 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
146 sizeof(charging_logo), 8);
147 lcd_set_drawmode(DRMODE_SOLID);
149 else
150 { /* animate the middle part */
151 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
153 if ((i-phase) % 8 == 0)
154 { /* draw a "bubble" here */
155 unsigned bitpos;
156 bitpos = (phase + i/8) % 15; /* "bounce" effect */
157 if (bitpos > 7)
158 bitpos = 14 - bitpos;
159 charging_logo[i] = BIT_N(bitpos);
162 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
163 sizeof(charging_logo), 8);
164 phase++;
166 lcd_update();
168 #else /* not HAVE_LCD_BITMAP */
170 static unsigned long logo_chars[4];
171 static const unsigned char logo_pattern[] = {
172 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
173 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
174 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
175 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
178 static void logo_lock_patterns(bool on)
180 int i;
182 if (on)
184 for (i = 0; i < 4; i++)
185 logo_chars[i] = lcd_get_locked_pattern();
187 else
189 for (i = 0; i < 4; i++)
190 lcd_unlock_pattern(logo_chars[i]);
194 static void charging_display_info(bool animate)
196 int battv;
197 unsigned i, ypos;
198 static unsigned phase = 3;
199 char buf[32];
201 battv = battery_voltage();
202 lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10);
204 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
206 if (!animate) /* build the screen */
208 lcd_double_height(false);
209 lcd_puts(0, 0, "[Charging]");
210 for (i = 0; i < 4; i++)
211 lcd_putc(i, 1, logo_chars[i]);
213 else /* animate the logo */
215 for (i = 3; i < MIN(19, phase); i++)
217 if ((i - phase) % 5 == 0)
218 { /* draw a "bubble" here */
219 ypos = (phase + i/5) % 9; /* "bounce" effect */
220 if (ypos > 4)
221 ypos = 8 - ypos;
222 buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5);
225 phase++;
228 for (i = 0; i < 4; i++)
229 lcd_define_pattern(logo_chars[i], buf + 8 * i);
231 lcd_update();
233 #endif /* (not) HAVE_LCD_BITMAP */
235 /* blocks while charging, returns on event:
236 1 if charger cable was removed
237 2 if Off/Stop key was pressed
238 3 if On key was pressed
239 4 if USB was connected */
241 int charging_screen(void)
243 unsigned int button;
244 int rc = 0;
246 ide_power_enable(false); /* power down the disk, else would be spinning */
248 lcd_clear_display();
249 backlight_set_timeout(global_settings.backlight_timeout);
250 #ifdef HAVE_REMOTE_LCD
251 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
252 #endif
253 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
255 #ifdef HAVE_LCD_CHARCELLS
256 logo_lock_patterns(true);
257 #endif
258 charging_display_info(false);
262 gui_syncstatusbar_draw(&statusbars, false);
263 charging_display_info(true);
264 button = get_action(CONTEXT_STD,HZ/3);
265 if (button == ACTION_STD_OK)
266 rc = 2;
267 else if (usb_detect() == USB_INSERTED)
268 rc = 3;
269 /* do not depend on power management thread here */
270 else if (!(power_input_status() & POWER_INPUT_MAIN_CHARGER))
271 rc = 1;
272 } while (!rc);
274 #ifdef HAVE_LCD_CHARCELLS
275 logo_lock_patterns(false);
276 #endif
277 return rc;
279 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
281 #if CONFIG_CHARGING
282 void charging_splash(void)
284 splash(2*HZ, str(LANG_BATTERY_CHARGE));
285 button_clear_queue();
287 #endif
290 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
292 /* little helper function for voice output */
293 static void say_time(int cursorpos, const struct tm *tm)
295 int value = 0;
296 int unit = 0;
298 if (!global_settings.talk_menu)
299 return;
301 switch(cursorpos)
303 case 0:
304 value = tm->tm_hour;
305 unit = UNIT_HOUR;
306 break;
307 case 1:
308 value = tm->tm_min;
309 unit = UNIT_MIN;
310 break;
311 case 2:
312 value = tm->tm_sec;
313 unit = UNIT_SEC;
314 break;
315 case 3:
316 value = tm->tm_year + 1900;
317 break;
318 case 5:
319 value = tm->tm_mday;
320 break;
323 if (cursorpos == 4) /* month */
324 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
325 else
326 talk_value(value, unit, false);
330 #define INDEX_X 0
331 #define INDEX_Y 1
333 #define SEPARATOR ":"
335 #define IDX_HOURS 0
336 #define IDX_MINUTES 1
337 #define IDX_SECONDS 2
338 #define IDX_YEAR 3
339 #define IDX_MONTH 4
340 #define IDX_DAY 5
342 #define OFF_HOURS 0
343 #define OFF_MINUTES 3
344 #define OFF_SECONDS 6
345 #define OFF_YEAR 9
346 #define OFF_DAY 14
348 bool set_time_screen(const char* title, struct tm *tm)
350 struct viewport viewports[NB_SCREENS];
351 bool done = false, usb = false;
352 int cursorpos = 0;
353 unsigned char offsets_ptr[] =
354 { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY };
356 if (lang_is_rtl())
358 offsets_ptr[IDX_HOURS] = OFF_SECONDS;
359 offsets_ptr[IDX_SECONDS] = OFF_HOURS;
360 offsets_ptr[IDX_YEAR] = OFF_DAY;
361 offsets_ptr[IDX_DAY] = OFF_YEAR;
364 /* speak selection when screen is entered */
365 say_time(cursorpos, tm);
367 #ifdef HAVE_TOUCHSCREEN
368 enum touchscreen_mode old_mode = touchscreen_get_mode();
369 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
370 #endif
371 while (!done) {
372 int button;
373 unsigned int i, realyear, min, max;
374 unsigned char *ptr[6];
375 unsigned char buffer[20];
376 int *valptr = NULL;
377 static unsigned char daysinmonth[] =
378 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
380 /* for easy acess in the drawing loop */
381 for (i = 0; i < 6; i++)
382 ptr[i] = buffer + offsets_ptr[i];
383 ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */
385 /* calculate the number of days in febuary */
386 realyear = tm->tm_year + 1900;
387 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
388 daysinmonth[1] = 29;
389 else
390 daysinmonth[1] = 28;
392 /* fix day if month or year changed */
393 if (tm->tm_mday > daysinmonth[tm->tm_mon])
394 tm->tm_mday = daysinmonth[tm->tm_mon];
396 /* calculate day of week */
397 set_day_of_week(tm);
399 /* put all the numbers we want from the tm struct into
400 an easily printable buffer */
401 snprintf(buffer, sizeof(buffer),
402 "%02d " "%02d " "%02d " "%04d " "%02d",
403 tm->tm_hour, tm->tm_min, tm->tm_sec,
404 tm->tm_year+1900, tm->tm_mday);
406 /* convert spaces in the buffer to '\0' to make it possible to work
407 directly on the buffer */
408 for(i=0; i < sizeof(buffer); i++)
410 if(buffer[i] == ' ')
411 buffer[i] = '\0';
414 FOR_NB_SCREENS(s)
416 int pos, nb_lines;
417 unsigned int separator_width, weekday_width;
418 unsigned int j, width, prev_line_height;
419 /* 6 possible cursor possitions, 2 values stored for each: x, y */
420 unsigned int cursor[6][2];
421 struct viewport *vp = &viewports[s];
422 struct screen *screen = &screens[s];
423 static unsigned char rtl_idx[] =
424 { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR };
426 viewport_set_defaults(vp, s);
427 screen->set_viewport(vp);
428 nb_lines = viewport_get_nb_lines(vp);
430 /* minimum lines needed is 2 + title line */
431 if (nb_lines < 4)
433 vp->font = FONT_SYSFIXED;
434 nb_lines = viewport_get_nb_lines(vp);
437 /* recalculate the positions and offsets */
438 if (nb_lines >= 3)
439 screen->getstringsize(title, NULL, &prev_line_height);
440 else
441 prev_line_height = 0;
443 screen->getstringsize(SEPARATOR, &separator_width, NULL);
445 /* weekday */
446 screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
447 &weekday_width, NULL);
448 screen->getstringsize(" ", &separator_width, NULL);
450 for(i=0, j=0; i < 6; i++)
452 if(i==3) /* second row */
454 j = weekday_width + separator_width;
455 prev_line_height *= 2;
457 screen->getstringsize(ptr[i], &width, NULL);
458 cursor[i][INDEX_Y] = prev_line_height;
459 cursor[i][INDEX_X] = j;
460 j += width + separator_width;
463 /* draw the screen */
464 screen->set_viewport(vp);
465 screen->clear_viewport();
466 /* display the screen title */
467 screen->puts_scroll(0, 0, title);
469 /* these are not selectable, so we draw them outside the loop */
470 /* name of the week day */
471 screen->putsxy(0, cursor[3][INDEX_Y],
472 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
474 pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos;
475 /* draw the selected item with drawmode set to
476 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
477 items with drawmode DRMODE_SOLID */
478 for(i=0; i<6; i++)
480 if (pos == (int)i)
481 vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
483 screen->putsxy(cursor[i][INDEX_X],
484 cursor[i][INDEX_Y], ptr[i]);
486 vp->drawmode = DRMODE_SOLID;
488 screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
489 cursor[0][INDEX_Y], SEPARATOR);
492 /* print help text */
493 if (nb_lines > 4)
494 screen->puts(0, 4, str(LANG_TIME_SET_BUTTON));
495 if (nb_lines > 5)
496 screen->puts(0, 5, str(LANG_TIME_REVERT));
497 screen->update_viewport();
498 screen->set_viewport(NULL);
501 /* set the most common numbers */
502 min = 0;
503 max = 59;
504 /* calculate the minimum and maximum for the number under cursor */
505 switch(cursorpos) {
506 case 0: /* hour */
507 max = 23;
508 valptr = &tm->tm_hour;
509 break;
510 case 1: /* minute */
511 valptr = &tm->tm_min;
512 break;
513 case 2: /* second */
514 valptr = &tm->tm_sec;
515 break;
516 case 3: /* year */
517 min = 1;
518 max = 200;
519 valptr = &tm->tm_year;
520 break;
521 case 4: /* month */
522 max = 11;
523 valptr = &tm->tm_mon;
524 break;
525 case 5: /* day */
526 min = 1;
527 max = daysinmonth[tm->tm_mon];
528 valptr = &tm->tm_mday;
529 break;
532 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
533 switch ( button ) {
534 case ACTION_STD_PREV:
535 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
536 say_time(cursorpos, tm);
537 break;
538 case ACTION_STD_NEXT:
539 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
540 say_time(cursorpos, tm);
541 break;
542 case ACTION_SETTINGS_INC:
543 case ACTION_SETTINGS_INCREPEAT:
544 *valptr = clamp_value_wrap(++(*valptr), max, min);
545 say_time(cursorpos, tm);
546 break;
547 case ACTION_SETTINGS_DEC:
548 case ACTION_SETTINGS_DECREPEAT:
549 *valptr = clamp_value_wrap(--(*valptr), max, min);
550 say_time(cursorpos, tm);
551 break;
553 case ACTION_STD_OK:
554 done = true;
555 break;
557 case ACTION_STD_CANCEL:
558 done = true;
559 tm->tm_year = -1;
560 break;
562 default:
563 if (default_event_handler(button) == SYS_USB_CONNECTED)
564 done = usb = true;
565 break;
568 FOR_NB_SCREENS(s)
569 screens[s].scroll_stop(&viewports[s]);
570 #ifdef HAVE_TOUCHSCREEN
571 touchscreen_set_mode(old_mode);
572 #endif
573 return usb;
575 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
577 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
578 bool shutdown_screen(void)
580 int button;
581 bool done = false;
582 long time_entered = current_tick;
584 lcd_stop_scroll();
586 splash(0, str(LANG_CONFIRM_SHUTDOWN));
588 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
590 button = get_action(CONTEXT_STD,HZ);
591 switch(button)
593 case ACTION_STD_CANCEL:
594 sys_poweroff();
595 break;
597 /* do nothing here, because ACTION_NONE might be caused
598 * by timeout or button release. In case of timeout the loop
599 * is terminated by TIME_BEFORE */
600 case ACTION_NONE:
601 break;
603 default:
604 if(default_event_handler(button) == SYS_USB_CONNECTED)
605 return true;
606 done = true;
607 break;
610 return false;
612 #endif
614 static const int id3_headers[]=
616 LANG_ID3_TITLE,
617 LANG_ID3_ARTIST,
618 LANG_ID3_COMPOSER,
619 LANG_ID3_ALBUM,
620 LANG_ID3_ALBUMARTIST,
621 LANG_ID3_GROUPING,
622 LANG_ID3_DISCNUM,
623 LANG_ID3_TRACKNUM,
624 LANG_ID3_COMMENT,
625 LANG_ID3_GENRE,
626 LANG_ID3_YEAR,
627 LANG_ID3_LENGTH,
628 LANG_ID3_PLAYLIST,
629 LANG_ID3_BITRATE,
630 LANG_ID3_FREQUENCY,
631 #if CONFIG_CODEC == SWCODEC
632 LANG_ID3_TRACK_GAIN,
633 LANG_ID3_ALBUM_GAIN,
634 #endif
635 LANG_FILESIZE,
636 LANG_ID3_PATH,
639 struct id3view_info {
640 struct mp3entry* id3;
641 int count;
642 int info_id[ARRAYLEN(id3_headers)];
645 static const char* id3_get_info(int selected_item, void* data,
646 char *buffer, size_t buffer_len)
648 struct id3view_info *info = (struct id3view_info*)data;
649 struct mp3entry* id3 =info->id3;
650 int info_no=selected_item/2;
651 if(!(selected_item%2))
652 {/* header */
653 snprintf(buffer, buffer_len,
654 "[%s]", str(id3_headers[info->info_id[info_no]]));
655 return buffer;
657 else
658 {/* data */
660 char * val=NULL;
661 switch(id3_headers[info->info_id[info_no]])
663 case LANG_ID3_TITLE:
664 val=id3->title;
665 break;
666 case LANG_ID3_ARTIST:
667 val=id3->artist;
668 break;
669 case LANG_ID3_ALBUM:
670 val=id3->album;
671 break;
672 case LANG_ID3_ALBUMARTIST:
673 val=id3->albumartist;
674 break;
675 case LANG_ID3_GROUPING:
676 val=id3->grouping;
677 break;
678 case LANG_ID3_DISCNUM:
679 if (id3->disc_string)
680 val = id3->disc_string;
681 else if (id3->discnum)
683 snprintf(buffer, buffer_len, "%d", id3->discnum);
684 val = buffer;
686 break;
687 case LANG_ID3_TRACKNUM:
688 if (id3->track_string)
689 val = id3->track_string;
690 else if (id3->tracknum)
692 snprintf(buffer, buffer_len, "%d", id3->tracknum);
693 val = buffer;
695 break;
696 case LANG_ID3_COMMENT:
697 if (!id3->comment)
698 return NULL;
699 snprintf(buffer, buffer_len, "%s", id3->comment);
700 val=buffer;
701 break;
702 case LANG_ID3_GENRE:
703 val = id3->genre_string;
704 break;
705 case LANG_ID3_YEAR:
706 if (id3->year_string)
707 val = id3->year_string;
708 else if (id3->year)
710 snprintf(buffer, buffer_len, "%d", id3->year);
711 val = buffer;
713 break;
714 case LANG_ID3_LENGTH:
715 format_time(buffer, buffer_len, id3->length);
716 val=buffer;
717 break;
718 case LANG_ID3_PLAYLIST:
719 snprintf(buffer, buffer_len, "%d/%d",
720 playlist_get_display_index(), playlist_amount());
721 val=buffer;
722 break;
723 case LANG_ID3_BITRATE:
724 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
725 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
726 val=buffer;
727 break;
728 case LANG_ID3_FREQUENCY:
729 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
730 val=buffer;
731 break;
732 #if CONFIG_CODEC == SWCODEC
733 case LANG_ID3_TRACK_GAIN:
734 replaygain_itoa(buffer, buffer_len, id3->track_level);
735 val=(id3->track_level) ? buffer : NULL; /* only show level!=0 */
736 break;
737 case LANG_ID3_ALBUM_GAIN:
738 replaygain_itoa(buffer, buffer_len, id3->album_level);
739 val=(id3->album_level) ? buffer : NULL; /* only show level!=0 */
740 break;
741 #endif
742 case LANG_ID3_PATH:
743 val=id3->path;
744 break;
745 case LANG_ID3_COMPOSER:
746 val=id3->composer;
747 break;
748 case LANG_FILESIZE: /* not LANG_ID3_FILESIZE because the string is shared */
749 output_dyn_value(buffer, buffer_len, id3->filesize, byte_units, true);
750 val=buffer;
751 break;
753 return val && *val ? val : NULL;
757 bool browse_id3(void)
759 struct gui_synclist id3_lists;
760 struct mp3entry* id3 = audio_current_track();
761 int key;
762 unsigned int i;
763 struct id3view_info info;
764 info.count = 0;
765 info.id3 = id3;
766 bool ret = false;
767 push_current_activity(ACTIVITY_ID3SCREEN);
768 for (i = 0; i < ARRAYLEN(id3_headers); i++)
770 char temp[8];
771 info.info_id[i] = i;
772 if (id3_get_info((i*2)+1, &info, temp, 8) != NULL)
773 info.info_id[info.count++] = i;
776 gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL);
777 gui_synclist_set_nb_items(&id3_lists, info.count*2);
778 gui_synclist_draw(&id3_lists);
779 while (true) {
780 key = get_action(CONTEXT_LIST,HZ/2);
781 if(!gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
783 if (key == ACTION_STD_OK || key == ACTION_STD_CANCEL)
785 ret = false;
786 break;
788 else if (key == ACTION_STD_MENU ||
789 default_event_handler(key) == SYS_USB_CONNECTED)
791 ret = true;
792 break;
797 pop_current_activity();
798 return ret;
801 static const char* runtime_get_data(int selected_item, void* data,
802 char* buffer, size_t buffer_len)
804 (void)data;
805 int t;
806 switch (selected_item)
808 case 0: return str(LANG_RUNNING_TIME);
809 case 1: t = global_status.runtime; break;
810 case 2: return str(LANG_TOP_TIME);
811 case 3: t = global_status.topruntime; break;
812 default:
813 return "";
816 snprintf(buffer, buffer_len, "%dh %dm %ds",
817 t / 3600, (t % 3600) / 60, t % 60);
818 return buffer;
821 static int runtime_speak_data(int selected_item, void* data)
823 (void) data;
824 talk_ids(false,
825 (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME,
826 TALK_ID((selected_item < 2) ? global_status.runtime
827 : global_status.topruntime, UNIT_TIME));
828 return 0;
832 bool view_runtime(void)
834 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
835 static const struct text_message message={lines, 1};
837 struct gui_synclist lists;
838 int action;
839 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
840 #if !defined(HAVE_LCD_CHARCELLS)
841 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
842 #else
843 gui_synclist_set_title(&lists, NULL, NOICON);
844 #endif
845 if(global_settings.talk_menu)
846 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
847 gui_synclist_set_icon_callback(&lists, NULL);
848 gui_synclist_set_nb_items(&lists, 4);
849 gui_synclist_speak_item(&lists);
850 while(1)
852 global_status.runtime += ((current_tick - lasttime) / HZ);
854 lasttime = current_tick;
855 gui_synclist_draw(&lists);
856 list_do_action(CONTEXT_STD, HZ,
857 &lists, &action, LIST_WRAP_UNLESS_HELD);
858 if(action == ACTION_STD_CANCEL)
859 break;
860 if(action == ACTION_STD_OK) {
861 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
863 if (!(gui_synclist_get_sel_pos(&lists)/2))
864 global_status.runtime = 0;
865 else
866 global_status.topruntime = 0;
867 gui_synclist_speak_item(&lists);
870 if(default_event_handler(action) == SYS_USB_CONNECTED)
871 return true;
873 return false;
876 #ifdef HAVE_TOUCHSCREEN
877 static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
878 struct screen* screen)
880 int action;
881 short ts_x, ts_y;
883 /* Draw a cross */
884 screen->drawline(x - 10, y, x - 2, y);
885 screen->drawline(x + 2, y, x + 10, y);
886 screen->drawline(x, y - 10, x, y - 2);
887 screen->drawline(x, y + 2, x, y + 10);
888 screen->update();
890 /* Wait for a touchscreen press */
891 while(true)
893 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
894 if(action == ACTION_TOUCHSCREEN)
896 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
897 break;
899 else if(action == ACTION_STD_CANCEL)
900 return -1;
903 cal->x[i][0] = ts_x;
904 cal->y[i][0] = ts_y;
905 cal->x[i][1] = x;
906 cal->y[i][1] = y;
908 return 0;
912 int calibrate(void)
914 short points[3][2] = {
915 {LCD_WIDTH/10, LCD_HEIGHT/10},
916 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
917 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
919 struct screen* screen = &screens[SCREEN_MAIN];
920 enum touchscreen_mode old_mode = touchscreen_get_mode();
921 struct touchscreen_calibration cal;
922 int i, ret = 0;
924 /* hide the statusbar */
925 viewportmanager_theme_enable(SCREEN_MAIN, false, NULL);
927 touchscreen_disable_mapping(); /* set raw mode */
928 touchscreen_set_mode(TOUCHSCREEN_POINT);
930 for(i=0; i<3; i++)
932 screen->clear_display();
934 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
936 ret = -1;
937 break;
941 if(ret == 0)
942 touchscreen_calibrate(&cal);
943 else
944 touchscreen_reset_mapping();
946 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
947 sizeof(struct touchscreen_parameter));
949 touchscreen_set_mode(old_mode);
950 viewportmanager_theme_undo(SCREEN_MAIN, false);
952 settings_save();
953 return ret;
956 int reset_mapping(void)
958 touchscreen_reset_mapping();
960 memcpy(&global_settings.ts_calibration_data, &calibration_parameters,
961 sizeof(struct touchscreen_parameter));
963 settings_save();
964 return 0;
966 #endif