1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
11 * 2010 Jonathan Gordon
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
32 #include "skin_buffer.h"
33 #include "skin_parser.h"
34 #include "tag_table.h"
44 #define lang_is_rtl() (false)
56 #include "wps_internals.h"
57 #include "skin_engine.h"
59 #include "settings_list.h"
64 #include "skin_fonts.h"
66 #ifdef HAVE_LCD_BITMAP
75 #include "statusbar-skinned.h"
77 #define WPS_ERROR_INVALID_PARAM -1
80 static bool isdefault(struct skin_tag_parameter
*param
)
82 return param
->type
== DEFAULT
;
86 /* which screen are we parsing for? */
87 static enum screen_type curr_screen
;
89 /* the current viewport */
90 static struct skin_element
*curr_viewport_element
;
91 static struct skin_viewport
*curr_vp
;
93 static struct line
*curr_line
;
95 static int follow_lang_direction
= 0;
97 typedef int (*parse_function
)(struct skin_element
*element
,
98 struct wps_token
*token
,
99 struct wps_data
*wps_data
);
101 #ifdef HAVE_LCD_BITMAP
102 /* add a skin_token_list item to the list chain. ALWAYS appended because some of the
103 * chains require the order to be kept.
105 static void add_to_ll_chain(struct skin_token_list
**list
, struct skin_token_list
*item
)
111 struct skin_token_list
*t
= *list
;
121 void *skin_find_item(const char *label
, enum skin_find_what what
,
122 struct wps_data
*data
)
124 const char *itemlabel
= NULL
;
126 struct skin_token_list
*linkedlist
;
127 struct skin_element
*vplist
;
129 bool isvplist
= false;
135 list
.vplist
= data
->tree
;
138 #ifdef HAVE_LCD_BITMAP
139 case SKIN_FIND_IMAGE
:
140 list
.linkedlist
= data
->images
;
143 #ifdef HAVE_TOUCHSCREEN
144 case SKIN_FIND_TOUCHREGION
:
145 list
.linkedlist
= data
->touchregions
;
148 #ifdef HAVE_SKIN_VARIABLES
150 list
.linkedlist
= data
->skinvars
;
155 while (list
.linkedlist
)
162 ret
= list
.vplist
->data
;
163 itemlabel
= ((struct skin_viewport
*)ret
)->label
;
164 skip
= !(((struct skin_viewport
*)ret
)->is_infovp
==
165 (what
==SKIN_FIND_UIVP
));
167 #ifdef HAVE_LCD_BITMAP
168 case SKIN_FIND_IMAGE
:
169 ret
= list
.linkedlist
->token
->value
.data
;
170 itemlabel
= ((struct gui_img
*)ret
)->label
;
173 #ifdef HAVE_TOUCHSCREEN
174 case SKIN_FIND_TOUCHREGION
:
175 ret
= list
.linkedlist
->token
->value
.data
;
176 itemlabel
= ((struct touchregion
*)ret
)->label
;
179 #ifdef HAVE_SKIN_VARIABLES
181 ret
= list
.linkedlist
->token
->value
.data
;
182 itemlabel
= ((struct skin_var
*)ret
)->label
;
187 if (!skip
&& itemlabel
&& !strcmp(itemlabel
, label
))
191 list
.vplist
= list
.vplist
->next
;
193 list
.linkedlist
= list
.linkedlist
->next
;
198 #ifdef HAVE_LCD_BITMAP
200 /* create and init a new wpsll item.
201 * passing NULL to token will alloc a new one.
202 * You should only pass NULL for the token when the token type (table above)
203 * is WPS_NO_TOKEN which means it is not stored automatically in the skins token array
205 static struct skin_token_list
*new_skin_token_list_item(struct wps_token
*token
,
208 struct skin_token_list
*llitem
=
209 (struct skin_token_list
*)skin_buffer_alloc(sizeof(struct skin_token_list
));
211 token
= (struct wps_token
*)skin_buffer_alloc(sizeof(struct wps_token
));
212 if (!llitem
|| !token
)
215 llitem
->token
= token
;
217 llitem
->token
->value
.data
= token_data
;
221 static int parse_statusbar_tags(struct skin_element
* element
,
222 struct wps_token
*token
,
223 struct wps_data
*wps_data
)
226 if (token
->type
== SKIN_TOKEN_DRAW_INBUILTBAR
)
228 token
->value
.data
= (void*)&curr_vp
->vp
;
232 struct skin_element
*def_vp
= wps_data
->tree
;
233 struct skin_viewport
*default_vp
= def_vp
->data
;
234 if (def_vp
->params_count
== 0)
236 wps_data
->wps_sb_tag
= true;
237 wps_data
->show_sb_on_wps
= (token
->type
== SKIN_TOKEN_ENABLE_THEME
);
239 if (wps_data
->show_sb_on_wps
)
241 viewport_set_defaults(&default_vp
->vp
, curr_screen
);
245 viewport_set_fullscreen(&default_vp
->vp
, curr_screen
);
247 #ifdef HAVE_REMOTE_LCD
248 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
249 * This parser requires font 1 to always be the UI font,
250 * so force it back to FONT_UI and handle the screen number at the end */
251 default_vp
->vp
.font
= FONT_UI
;
257 static int get_image_id(int c
)
259 if(c
>= 'a' && c
<= 'z')
261 else if(c
>= 'A' && c
<= 'Z')
267 char *get_image_filename(const char *start
, const char* bmpdir
,
268 char *buf
, int buf_size
)
270 snprintf(buf
, buf_size
, "%s/%s", bmpdir
, start
);
275 static int parse_image_display(struct skin_element
*element
,
276 struct wps_token
*token
,
277 struct wps_data
*wps_data
)
279 char *label
= element
->params
[0].data
.text
;
280 char sublabel
= '\0';
283 struct image_display
*id
= skin_buffer_alloc(sizeof(struct image_display
));
285 if (element
->params_count
== 1 && strlen(label
) <= 2)
287 /* backwards compatability. Allow %xd(Aa) to still work */
292 img
= skin_find_item(label
, SKIN_FIND_IMAGE
, wps_data
);
295 return WPS_ERROR_INVALID_PARAM
;
300 if (img
->using_preloaded_icons
)
302 token
->type
= SKIN_TOKEN_IMAGE_DISPLAY_LISTICON
;
305 if (element
->params_count
> 1)
307 if (element
->params
[1].type
== CODE
)
308 id
->token
= element
->params
[1].data
.code
->data
;
309 /* specify a number. 1 being the first subimage (i.e top) NOT 0 */
310 else if (element
->params
[1].type
== INTEGER
)
311 id
->subimage
= element
->params
[1].data
.number
- 1;
312 if (element
->params_count
> 2)
313 id
->offset
= element
->params
[2].data
.number
;
317 if ((subimage
= get_image_id(sublabel
)) != -1)
319 if (subimage
>= img
->num_subimages
)
320 return WPS_ERROR_INVALID_PARAM
;
321 id
->subimage
= subimage
;
326 token
->value
.data
= id
;
330 static int parse_image_load(struct skin_element
*element
,
331 struct wps_token
*token
,
332 struct wps_data
*wps_data
)
334 const char* filename
;
339 /* format: %x(n,filename.bmp,x,y)
340 or %xl(n,filename.bmp,x,y)
341 or %xl(n,filename.bmp,x,y,num_subimages)
344 id
= element
->params
[0].data
.text
;
345 filename
= element
->params
[1].data
.text
;
346 x
= element
->params
[2].data
.number
;
347 y
= element
->params
[3].data
.number
;
349 /* check the image number and load state */
350 if(skin_find_item(id
, SKIN_FIND_IMAGE
, wps_data
))
352 /* Invalid image ID */
353 return WPS_ERROR_INVALID_PARAM
;
355 img
= (struct gui_img
*)skin_buffer_alloc(sizeof(struct gui_img
));
357 return WPS_ERROR_INVALID_PARAM
;
358 /* save a pointer to the filename */
359 img
->bm
.data
= (char*)filename
;
363 img
->num_subimages
= 1;
364 img
->always_display
= false;
366 img
->using_preloaded_icons
= false;
368 /* save current viewport */
369 img
->vp
= &curr_vp
->vp
;
371 if (token
->type
== SKIN_TOKEN_IMAGE_DISPLAY
)
373 img
->always_display
= true;
375 else if (element
->params_count
== 5)
377 img
->num_subimages
= element
->params
[4].data
.number
;
378 if (img
->num_subimages
<= 0)
379 return WPS_ERROR_INVALID_PARAM
;
382 if (!strcmp(img
->bm
.data
, "__list_icons__"))
384 img
->num_subimages
= Icon_Last_Themeable
;
385 img
->using_preloaded_icons
= true;
388 struct skin_token_list
*item
=
389 (struct skin_token_list
*)new_skin_token_list_item(NULL
, img
);
391 return WPS_ERROR_INVALID_PARAM
;
392 add_to_ll_chain(&wps_data
->images
, item
);
397 int id
; /* the id from font_load */
398 char *name
; /* filename without path and extension */
399 int glyphs
; /* how many glyphs to reserve room for */
401 static struct skin_font skinfonts
[MAXUSERFONTS
];
402 static int parse_font_load(struct skin_element
*element
,
403 struct wps_token
*token
,
404 struct wps_data
*wps_data
)
406 (void)wps_data
; (void)token
;
407 int id
= element
->params
[0].data
.number
;
408 char *filename
= element
->params
[1].data
.text
;
412 if(element
->params_count
> 2)
413 glyphs
= element
->params
[2].data
.number
;
415 glyphs
= GLYPHS_TO_CACHE
;
416 #if defined(DEBUG) || defined(SIMULATOR)
417 if (skinfonts
[id
-FONT_FIRSTUSERFONT
].name
!= NULL
)
419 DEBUGF("font id %d already being used\n", id
);
422 /* make sure the filename contains .fnt,
423 * we dont actually use it, but require it anyway */
424 ptr
= strchr(filename
, '.');
425 if (!ptr
|| strncmp(ptr
, ".fnt", 4))
426 return WPS_ERROR_INVALID_PARAM
;
427 skinfonts
[id
-FONT_FIRSTUSERFONT
].id
= -1;
428 skinfonts
[id
-FONT_FIRSTUSERFONT
].name
= filename
;
429 skinfonts
[id
-FONT_FIRSTUSERFONT
].glyphs
= glyphs
;
435 #ifdef HAVE_LCD_BITMAP
437 static int parse_playlistview(struct skin_element
*element
,
438 struct wps_token
*token
,
439 struct wps_data
*wps_data
)
442 struct playlistviewer
*viewer
=
443 (struct playlistviewer
*)skin_buffer_alloc(sizeof(struct playlistviewer
));
445 return WPS_ERROR_INVALID_PARAM
;
446 viewer
->vp
= &curr_vp
->vp
;
447 viewer
->show_icons
= true;
448 viewer
->start_offset
= element
->params
[0].data
.number
;
449 viewer
->line
= element
->params
[1].data
.code
;
451 token
->value
.data
= (void*)viewer
;
457 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
459 static int parse_viewportcolour(struct skin_element
*element
,
460 struct wps_token
*token
,
461 struct wps_data
*wps_data
)
464 struct skin_tag_parameter
*param
= element
->params
;
465 struct viewport_colour
*colour
=
466 (struct viewport_colour
*)skin_buffer_alloc(sizeof(struct viewport_colour
));
469 if (isdefault(param
))
471 colour
->colour
= get_viewport_default_colour(curr_screen
,
472 token
->type
== SKIN_TOKEN_VIEWPORT_FGCOLOUR
);
476 if (!parse_color(curr_screen
, param
->data
.text
, &colour
->colour
))
479 colour
->vp
= &curr_vp
->vp
;
480 token
->value
.data
= colour
;
481 if (element
->line
== curr_viewport_element
->line
)
483 if (token
->type
== SKIN_TOKEN_VIEWPORT_FGCOLOUR
)
485 curr_vp
->start_fgcolour
= colour
->colour
;
486 curr_vp
->vp
.fg_pattern
= colour
->colour
;
490 curr_vp
->start_bgcolour
= colour
->colour
;
491 curr_vp
->vp
.bg_pattern
= colour
->colour
;
497 static int parse_image_special(struct skin_element
*element
,
498 struct wps_token
*token
,
499 struct wps_data
*wps_data
)
501 (void)wps_data
; /* kill warning */
506 if (token
->type
== SKIN_TOKEN_IMAGE_BACKDROP
)
508 if (isdefault(&element
->params
[0]))
514 filename
= element
->params
[0].data
.text
;
515 /* format: %X(filename.bmp) or %X(d) */
516 if (!strcmp(filename
, "d"))
519 wps_data
->backdrop
= filename
;
527 #endif /* HAVE_LCD_BITMAP */
529 static int parse_setting_and_lang(struct skin_element
*element
,
530 struct wps_token
*token
,
531 struct wps_data
*wps_data
)
533 /* NOTE: both the string validations that happen in here will
534 * automatically PASS on checkwps because its too hard to get
535 * settings_list.c and english.lang built for it.
536 * If that ever changes remove the #ifndef __PCTOOL__'s here
539 char *temp
= element
->params
[0].data
.text
;
542 if (token
->type
== SKIN_TOKEN_TRANSLATEDSTRING
)
545 i
= lang_english_to_id(temp
);
547 return WPS_ERROR_INVALID_PARAM
;
552 /* Find the setting */
553 for (i
=0; i
<nb_settings
; i
++)
554 if (settings
[i
].cfg_name
&&
555 !strcmp(settings
[i
].cfg_name
, temp
))
558 if (i
== nb_settings
)
559 return WPS_ERROR_INVALID_PARAM
;
562 /* Store the setting number */
566 static int parse_logical_if(struct skin_element
*element
,
567 struct wps_token
*token
,
568 struct wps_data
*wps_data
)
571 char *op
= element
->params
[1].data
.text
;
572 struct logical_if
*lif
= skin_buffer_alloc(sizeof(struct logical_if
));
575 token
->value
.data
= lif
;
576 lif
->token
= element
->params
[0].data
.code
->data
;
578 if (!strncmp(op
, "=", 1))
580 else if (!strncmp(op
, "!=", 2))
581 lif
->op
= IF_NOTEQUALS
;
582 else if (!strncmp(op
, ">=", 2))
583 lif
->op
= IF_GREATERTHAN_EQ
;
584 else if (!strncmp(op
, "<=", 2))
585 lif
->op
= IF_LESSTHAN_EQ
;
586 else if (!strncmp(op
, ">", 2))
587 lif
->op
= IF_GREATERTHAN
;
588 else if (!strncmp(op
, "<", 1))
589 lif
->op
= IF_LESSTHAN
;
591 memcpy(&lif
->operand
, &element
->params
[2], sizeof(lif
->operand
));
592 if (element
->params_count
> 3)
593 lif
->num_options
= element
->params
[3].data
.number
;
595 lif
->num_options
= TOKEN_VALUE_ONLY
;
600 static int parse_timeout_tag(struct skin_element
*element
,
601 struct wps_token
*token
,
602 struct wps_data
*wps_data
)
606 if (element
->params_count
== 0)
610 case SKIN_TOKEN_SUBLINE_TIMEOUT
:
612 case SKIN_TOKEN_BUTTON_VOLUME
:
613 case SKIN_TOKEN_TRACK_STARTING
:
614 case SKIN_TOKEN_TRACK_ENDING
:
622 val
= element
->params
[0].data
.number
;
623 token
->value
.i
= val
* TIMEOUT_UNIT
;
627 static int parse_progressbar_tag(struct skin_element
* element
,
628 struct wps_token
*token
,
629 struct wps_data
*wps_data
)
631 #ifdef HAVE_LCD_BITMAP
632 struct progressbar
*pb
;
633 struct viewport
*vp
= &curr_vp
->vp
;
634 struct skin_tag_parameter
*param
= element
->params
;
636 char *image_filename
= NULL
;
638 if (element
->params_count
== 0 &&
639 element
->tag
->type
!= SKIN_TOKEN_PROGRESSBAR
)
640 return 0; /* nothing to do */
641 pb
= (struct progressbar
*)skin_buffer_alloc(sizeof(struct progressbar
));
643 token
->value
.data
= pb
;
646 return WPS_ERROR_INVALID_PARAM
;
648 pb
->follow_lang_direction
= follow_lang_direction
> 0;
654 pb
->invert_fill_direction
= false;
655 pb
->horizontal
= true;
657 if (element
->params_count
== 0)
660 pb
->width
= vp
->width
;
661 pb
->height
= SYSFONT_HEIGHT
-2;
662 pb
->y
= -1; /* Will be computed during the rendering */
663 pb
->type
= element
->tag
->type
;
667 /* (x, y, width, height, ...) */
668 if (!isdefault(param
))
669 pb
->x
= param
->data
.number
;
674 if (!isdefault(param
))
675 pb
->y
= param
->data
.number
;
677 pb
->y
= -1; /* computed at rendering */
680 if (!isdefault(param
))
681 pb
->width
= param
->data
.number
;
683 pb
->width
= vp
->width
- pb
->x
;
686 if (!isdefault(param
))
688 /* A zero height makes no sense - reject it */
689 if (param
->data
.number
== 0)
690 return WPS_ERROR_INVALID_PARAM
;
692 pb
->height
= param
->data
.number
;
696 if (vp
->font
> FONT_UI
)
697 pb
->height
= -1; /* calculate at display time */
701 pb
->height
= font_get(vp
->font
)->height
;
707 /* optional params, first is the image filename if it isnt recognised as a keyword */
710 if (isdefault(&element
->params
[curr_param
]))
716 pb
->horizontal
= pb
->width
> pb
->height
;
717 while (curr_param
< element
->params_count
)
720 if (!strcmp(param
->data
.text
, "invert"))
721 pb
->invert_fill_direction
= true;
722 else if (!strcmp(param
->data
.text
, "nofill"))
724 else if (!strcmp(param
->data
.text
, "nobar"))
726 else if (!strcmp(param
->data
.text
, "slider"))
728 if (curr_param
+1 < element
->params_count
)
732 pb
->slider
= skin_find_item(param
->data
.text
,
733 SKIN_FIND_IMAGE
, wps_data
);
735 else /* option needs the next param */
738 else if (!strcmp(param
->data
.text
, "image"))
740 if (curr_param
+1 < element
->params_count
)
744 image_filename
= param
->data
.text
;
747 else /* option needs the next param */
750 else if (!strcmp(param
->data
.text
, "backdrop"))
752 if (curr_param
+1 < element
->params_count
)
756 pb
->backdrop
= skin_find_item(param
->data
.text
,
757 SKIN_FIND_IMAGE
, wps_data
);
760 else /* option needs the next param */
763 else if (!strcmp(param
->data
.text
, "vertical"))
765 pb
->horizontal
= false;
766 if (isdefault(&element
->params
[3]))
767 pb
->height
= vp
->height
- pb
->y
;
769 else if (!strcmp(param
->data
.text
, "horizontal"))
770 pb
->horizontal
= true;
771 else if (curr_param
== 4)
772 image_filename
= param
->data
.text
;
779 pb
->image
= skin_find_item(image_filename
, SKIN_FIND_IMAGE
, wps_data
);
780 if (!pb
->image
) /* load later */
782 struct gui_img
* img
= (struct gui_img
*)skin_buffer_alloc(sizeof(struct gui_img
));
784 return WPS_ERROR_INVALID_PARAM
;
785 /* save a pointer to the filename */
786 img
->bm
.data
= (char*)image_filename
;
787 img
->label
= image_filename
;
790 img
->num_subimages
= 1;
791 img
->always_display
= false;
793 img
->using_preloaded_icons
= false;
794 img
->vp
= &curr_vp
->vp
;
795 struct skin_token_list
*item
=
796 (struct skin_token_list
*)new_skin_token_list_item(NULL
, img
);
798 return WPS_ERROR_INVALID_PARAM
;
799 add_to_ll_chain(&wps_data
->images
, item
);
804 if (token
->type
== SKIN_TOKEN_VOLUME
)
805 token
->type
= SKIN_TOKEN_VOLUMEBAR
;
806 else if (token
->type
== SKIN_TOKEN_BATTERY_PERCENT
)
807 token
->type
= SKIN_TOKEN_BATTERY_PERCENTBAR
;
808 else if (token
->type
== SKIN_TOKEN_TUNER_RSSI
)
809 token
->type
= SKIN_TOKEN_TUNER_RSSI_BAR
;
810 else if (token
->type
== SKIN_TOKEN_PEAKMETER_LEFT
)
811 token
->type
= SKIN_TOKEN_PEAKMETER_LEFTBAR
;
812 else if (token
->type
== SKIN_TOKEN_PEAKMETER_RIGHT
)
813 token
->type
= SKIN_TOKEN_PEAKMETER_RIGHTBAR
;
814 pb
->type
= token
->type
;
820 if (token
->type
== SKIN_TOKEN_PROGRESSBAR
||
821 token
->type
== SKIN_TOKEN_PLAYER_PROGRESSBAR
)
823 wps_data
->full_line_progressbar
=
824 token
->type
== SKIN_TOKEN_PLAYER_PROGRESSBAR
;
832 static int parse_albumart_load(struct skin_element
* element
,
833 struct wps_token
*token
,
834 struct wps_data
*wps_data
)
836 struct dim dimensions
;
838 bool swap_for_rtl
= lang_is_rtl() && follow_lang_direction
;
839 struct skin_albumart
*aa
=
840 (struct skin_albumart
*)skin_buffer_alloc(sizeof(struct skin_albumart
));
841 (void)token
; /* silence warning */
845 /* reset albumart info in wps */
848 aa
->xalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
849 aa
->yalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
851 aa
->x
= element
->params
[0].data
.number
;
852 aa
->y
= element
->params
[1].data
.number
;
853 aa
->width
= element
->params
[2].data
.number
;
854 aa
->height
= element
->params
[3].data
.number
;
856 aa
->vp
= &curr_vp
->vp
;
857 aa
->draw_handle
= -1;
859 /* if we got here, we parsed everything ok .. ! */
862 else if (aa
->width
> LCD_WIDTH
)
863 aa
->width
= LCD_WIDTH
;
867 else if (aa
->height
> LCD_HEIGHT
)
868 aa
->height
= LCD_HEIGHT
;
871 aa
->x
= LCD_WIDTH
- (aa
->x
+ aa
->width
);
873 aa
->state
= WPS_ALBUMART_LOAD
;
874 wps_data
->albumart
= aa
;
876 dimensions
.width
= aa
->width
;
877 dimensions
.height
= aa
->height
;
879 albumart_slot
= playback_claim_aa_slot(&dimensions
);
881 if (0 <= albumart_slot
)
882 wps_data
->playback_aa_slot
= albumart_slot
;
884 if (element
->params_count
> 4 && !isdefault(&element
->params
[4]))
886 switch (*element
->params
[4].data
.text
)
891 aa
->xalign
= WPS_ALBUMART_ALIGN_RIGHT
;
893 aa
->xalign
= WPS_ALBUMART_ALIGN_LEFT
;
897 aa
->xalign
= WPS_ALBUMART_ALIGN_CENTER
;
902 aa
->xalign
= WPS_ALBUMART_ALIGN_LEFT
;
904 aa
->xalign
= WPS_ALBUMART_ALIGN_RIGHT
;
908 if (element
->params_count
> 5 && !isdefault(&element
->params
[5]))
910 switch (*element
->params
[5].data
.text
)
914 aa
->yalign
= WPS_ALBUMART_ALIGN_TOP
;
918 aa
->yalign
= WPS_ALBUMART_ALIGN_CENTER
;
922 aa
->yalign
= WPS_ALBUMART_ALIGN_BOTTOM
;
929 #endif /* HAVE_ALBUMART */
930 #ifdef HAVE_SKIN_VARIABLES
931 static struct skin_var
* find_or_add_var(const char* label
,
932 struct wps_data
*data
)
934 struct skin_var
* ret
= skin_find_item(label
, SKIN_VARIABLE
, data
);
937 ret
= (struct skin_var
*)skin_buffer_alloc(sizeof(struct skin_var
));
942 ret
->last_changed
= 0xffff;
943 struct skin_token_list
*item
= new_skin_token_list_item(NULL
, ret
);
946 add_to_ll_chain(&data
->skinvars
, item
);
950 static int parse_skinvar( struct skin_element
*element
,
951 struct wps_token
*token
,
952 struct wps_data
*wps_data
)
954 const char* label
= element
->params
[0].data
.text
;
955 struct skin_var
* var
= find_or_add_var(label
, wps_data
);
957 return WPS_ERROR_INVALID_PARAM
;
960 case SKIN_TOKEN_VAR_GETVAL
:
961 token
->value
.data
= var
;
963 case SKIN_TOKEN_VAR_SET
:
965 struct skin_var_changer
*data
=
966 (struct skin_var_changer
*)skin_buffer_alloc(
967 sizeof(struct skin_var_changer
));
969 return WPS_ERROR_INVALID_PARAM
;
971 data
->newval
= element
->params
[2].data
.number
;
973 if (!strcmp(element
->params
[1].data
.text
, "set"))
975 else if (!strcmp(element
->params
[1].data
.text
, "inc"))
977 data
->direct
= false;
979 else if (!strcmp(element
->params
[1].data
.text
, "dec"))
981 data
->direct
= false;
984 if (element
->params_count
> 3)
985 data
->max
= element
->params
[3].data
.number
;
986 token
->value
.data
= data
;
989 case SKIN_TOKEN_VAR_TIMEOUT
:
991 struct skin_var_lastchange
*data
=
992 (struct skin_var_lastchange
*)skin_buffer_alloc(
993 sizeof(struct skin_var_lastchange
));
995 return WPS_ERROR_INVALID_PARAM
;
998 if (element
->params_count
> 1)
999 data
->timeout
= element
->params
[1].data
.number
;
1000 data
->timeout
*= TIMEOUT_UNIT
;
1001 token
->value
.data
= data
;
1004 default: /* kill the warning */
1009 #endif /* HAVE_SKIN_VARIABLES */
1010 #ifdef HAVE_TOUCHSCREEN
1011 static int parse_lasttouch(struct skin_element
*element
,
1012 struct wps_token
*token
,
1013 struct wps_data
*wps_data
)
1015 struct touchregion_lastpress
*data
=
1016 (struct touchregion_lastpress
*)skin_buffer_alloc(
1017 sizeof(struct touchregion_lastpress
));
1020 return WPS_ERROR_INVALID_PARAM
;
1021 data
->region
= NULL
;
1024 for (i
=0; i
<element
->params_count
; i
++)
1026 if (element
->params
[i
].type
== STRING
)
1027 data
->region
= skin_find_item(element
->params
[i
].data
.text
,
1028 SKIN_FIND_TOUCHREGION
, wps_data
);
1029 else if (element
->params
[i
].type
== INTEGER
||
1030 element
->params
[i
].type
== DECIMAL
)
1031 data
->timeout
= element
->params
[i
].data
.number
;
1034 data
->timeout
*= TIMEOUT_UNIT
;
1035 token
->value
.data
= data
;
1039 struct touchaction
{const char* s
; int action
;};
1040 static const struct touchaction touchactions
[] = {
1041 /* generic actions, convert to screen actions on use */
1042 {"none", ACTION_TOUCHSCREEN
}, {"lock", ACTION_TOUCH_SOFTLOCK
},
1043 {"prev", ACTION_STD_PREV
}, {"next", ACTION_STD_NEXT
},
1044 {"rwd", ACTION_STD_PREVREPEAT
}, {"ffwd", ACTION_STD_NEXTREPEAT
},
1045 {"hotkey", ACTION_STD_HOTKEY
}, {"select", ACTION_STD_OK
},
1046 {"menu", ACTION_STD_MENU
}, {"cancel", ACTION_STD_CANCEL
},
1047 {"contextmenu", ACTION_STD_CONTEXT
},{"quickscreen", ACTION_STD_QUICKSCREEN
},
1049 /* list/tree actions */
1050 { "resumeplayback", ACTION_TREE_WPS
}, /* returns to previous music, WPS/FM */
1051 /* not really WPS specific, but no equivilant ACTION_STD_* */
1052 {"voldown", ACTION_WPS_VOLDOWN
}, {"volup", ACTION_WPS_VOLUP
},
1053 {"mute", ACTION_TOUCH_MUTE
},
1055 /* generic settings changers */
1056 {"setting_inc", ACTION_SETTINGS_INC
}, {"setting_dec", ACTION_SETTINGS_DEC
},
1057 {"setting_set", ACTION_SETTINGS_SET
},
1059 /* WPS specific actions */
1060 {"wps_prev", ACTION_WPS_SKIPPREV
}, {"wps_next", ACTION_WPS_SKIPNEXT
},
1061 {"browse", ACTION_WPS_BROWSE
},
1062 {"play", ACTION_WPS_PLAY
}, {"stop", ACTION_WPS_STOP
},
1063 {"shuffle", ACTION_TOUCH_SHUFFLE
}, {"repmode", ACTION_TOUCH_REPMODE
},
1064 {"pitch", ACTION_WPS_PITCHSCREEN
}, {"playlist", ACTION_WPS_VIEW_PLAYLIST
},
1067 /* FM screen actions */
1068 /* Also allow browse, play, stop from WPS codes */
1069 {"mode", ACTION_FM_MODE
}, {"record", ACTION_FM_RECORD
},
1070 {"presets", ACTION_FM_PRESET
},
1074 static int parse_touchregion(struct skin_element
*element
,
1075 struct wps_token
*token
,
1076 struct wps_data
*wps_data
)
1081 struct touchregion
*region
= NULL
;
1083 const char pb_string
[] = "progressbar";
1084 const char vol_string
[] = "volume";
1087 /* format: %T([label,], x,y,width,height,action[, ...])
1088 * if action starts with & the area must be held to happen
1092 region
= (struct touchregion
*)skin_buffer_alloc(sizeof(struct touchregion
));
1094 return WPS_ERROR_INVALID_PARAM
;
1096 /* should probably do some bounds checking here with the viewport... but later */
1097 region
->action
= ACTION_NONE
;
1099 if (element
->params
[0].type
== STRING
)
1101 region
->label
= element
->params
[0].data
.text
;
1103 /* "[SI]III[SI]|SS" is the param list. There MUST be 4 numbers
1104 * followed by at least one string. Verify that here */
1105 if (element
->params_count
< 6 ||
1106 element
->params
[4].type
!= INTEGER
)
1107 return WPS_ERROR_INVALID_PARAM
;
1111 region
->label
= NULL
;
1115 region
->x
= element
->params
[p
++].data
.number
;
1116 region
->y
= element
->params
[p
++].data
.number
;
1117 region
->width
= element
->params
[p
++].data
.number
;
1118 region
->height
= element
->params
[p
++].data
.number
;
1119 region
->wvp
= curr_vp
;
1120 region
->armed
= false;
1121 region
->reverse_bar
= false;
1123 region
->last_press
= 0xffff;
1124 region
->press_length
= PRESS
;
1125 region
->allow_while_locked
= false;
1126 action
= element
->params
[p
++].data
.text
;
1128 strcpy(temp
, action
);
1134 region
->reverse_bar
= true;
1139 region
->allow_while_locked
= true;
1142 if(!strcmp(pb_string
, action
))
1143 region
->action
= ACTION_TOUCH_SCROLLBAR
;
1144 else if(!strcmp(vol_string
, action
))
1145 region
->action
= ACTION_TOUCH_VOLUME
;
1151 region
->press_length
= LONG_PRESS
;
1153 else if(*action
== '&')
1156 region
->press_length
= REPEAT
;
1159 region
->press_length
= PRESS
;
1161 imax
= ARRAYLEN(touchactions
);
1162 for (i
= 0; i
< imax
; i
++)
1164 /* try to match with one of our touchregion screens */
1165 if (!strcmp(touchactions
[i
].s
, action
))
1167 region
->action
= touchactions
[i
].action
;
1168 if (region
->action
== ACTION_SETTINGS_INC
||
1169 region
->action
== ACTION_SETTINGS_DEC
||
1170 region
->action
== ACTION_SETTINGS_SET
)
1172 if (element
->params_count
< p
+1)
1174 return WPS_ERROR_INVALID_PARAM
;
1178 char *name
= element
->params
[p
].data
.text
;
1180 /* Find the setting */
1181 for (j
=0; j
<nb_settings
; j
++)
1182 if (settings
[j
].cfg_name
&&
1183 !strcmp(settings
[j
].cfg_name
, name
))
1186 return WPS_ERROR_INVALID_PARAM
;
1187 region
->setting_data
.setting
= (void*)&settings
[j
];
1188 if (region
->action
== ACTION_SETTINGS_SET
)
1192 struct touchsetting
*setting
=
1193 ®ion
->setting_data
;
1194 if (element
->params_count
< p
+2)
1195 return WPS_ERROR_INVALID_PARAM
;
1197 text
= element
->params
[p
+1].data
.text
;
1198 switch (settings
[j
].flags
&F_T_MASK
)
1201 setting
->value
.text
= text
;
1205 if (settings
[j
].cfg_vals
== NULL
)
1207 setting
->value
.number
= atoi(text
);
1209 else if (cfg_string_to_int(j
, &temp
, text
))
1211 if (settings
[j
].flags
&F_TABLE_SETTING
)
1212 setting
->value
.number
=
1213 settings
[j
].table_setting
->values
[temp
];
1215 setting
->value
.number
= temp
;
1218 return WPS_ERROR_INVALID_PARAM
;
1221 if (cfg_string_to_int(j
, &temp
, text
))
1223 setting
->value
.number
= temp
;
1226 return WPS_ERROR_INVALID_PARAM
;
1229 return WPS_ERROR_INVALID_PARAM
;
1231 #endif /* __PCTOOL__ */
1238 if (region
->action
== ACTION_NONE
)
1239 return WPS_ERROR_INVALID_PARAM
;
1241 struct skin_token_list
*item
= new_skin_token_list_item(NULL
, region
);
1243 return WPS_ERROR_INVALID_PARAM
;
1244 add_to_ll_chain(&wps_data
->touchregions
, item
);
1246 if (region
->action
== ACTION_TOUCH_MUTE
)
1248 region
->value
= global_settings
.volume
;
1256 static bool check_feature_tag(const int type
)
1260 case SKIN_TOKEN_RTC_PRESENT
:
1266 case SKIN_TOKEN_HAVE_RECORDING
:
1267 #ifdef HAVE_RECORDING
1272 case SKIN_TOKEN_HAVE_TUNER
:
1274 if (radio_hardware_present())
1278 case SKIN_TOKEN_HAVE_TOUCH
:
1279 #ifdef HAVE_TOUCHSCREEN
1286 case SKIN_TOKEN_HAVE_RDS
:
1291 #endif /* HAVE_RDS_CAP */
1292 #endif /* CONFIG_TUNER */
1293 default: /* not a tag we care about, just don't skip */
1299 * initial setup of wps_data; does reset everything
1300 * except fields which need to survive, i.e.
1303 static void skin_data_reset(struct wps_data
*wps_data
)
1305 wps_data
->tree
= NULL
;
1306 #ifdef HAVE_LCD_BITMAP
1307 wps_data
->images
= NULL
;
1309 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1310 if (wps_data
->backdrop_id
>= 0)
1311 skin_backdrop_unload(wps_data
->backdrop_id
);
1312 wps_data
->backdrop
= NULL
;
1314 #ifdef HAVE_TOUCHSCREEN
1315 wps_data
->touchregions
= NULL
;
1317 #ifdef HAVE_SKIN_VARIABLES
1318 wps_data
->skinvars
= NULL
;
1320 #ifdef HAVE_ALBUMART
1321 wps_data
->albumart
= NULL
;
1322 if (wps_data
->playback_aa_slot
>= 0)
1324 playback_release_aa_slot(wps_data
->playback_aa_slot
);
1325 wps_data
->playback_aa_slot
= -1;
1329 #ifdef HAVE_LCD_BITMAP
1330 wps_data
->peak_meter_enabled
= false;
1331 wps_data
->wps_sb_tag
= false;
1332 wps_data
->show_sb_on_wps
= false;
1333 #else /* HAVE_LCD_CHARCELLS */
1336 for (i
= 0; i
< 8; i
++)
1338 wps_data
->wps_progress_pat
[i
] = 0;
1340 wps_data
->full_line_progressbar
= false;
1342 wps_data
->wps_loaded
= false;
1345 #ifdef HAVE_LCD_BITMAP
1346 static bool load_skin_bmp(struct wps_data
*wps_data
, struct bitmap
*bitmap
, char* bmpdir
)
1348 (void)wps_data
; /* only needed for remote targets */
1349 char img_path
[MAX_PATH
];
1351 get_image_filename(bitmap
->data
, bmpdir
,
1352 img_path
, sizeof(img_path
));
1354 /* load the image */
1356 #ifdef HAVE_REMOTE_LCD
1357 if (curr_screen
== SCREEN_REMOTE
)
1358 format
= FORMAT_ANY
|FORMAT_REMOTE
;
1361 format
= FORMAT_ANY
|FORMAT_TRANSPARENT
;
1363 fd
= open(img_path
, O_RDONLY
);
1366 DEBUGF("Couldn't open %s\n", img_path
);
1369 size_t buf_size
= read_bmp_fd(fd
, bitmap
, 0,
1370 format
|FORMAT_RETURN_SIZE
, NULL
);
1371 char* imgbuf
= (char*)skin_buffer_alloc(buf_size
);
1375 DEBUGF("Not enough skin buffer: need %zd more.\n",
1376 buf_size
- skin_buffer_freespace());
1381 lseek(fd
, 0, SEEK_SET
);
1382 bitmap
->data
= imgbuf
;
1383 int ret
= read_bmp_fd(fd
, bitmap
, buf_size
, format
, NULL
);
1392 /* Abort if we can't load an image */
1393 DEBUGF("Couldn't load '%s'\n", img_path
);
1398 static bool load_skin_bitmaps(struct wps_data
*wps_data
, char *bmpdir
)
1400 struct skin_token_list
*list
;
1401 bool retval
= true; /* return false if a single image failed to load */
1403 /* regular images */
1404 list
= wps_data
->images
;
1407 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
1410 if (img
->using_preloaded_icons
)
1413 list
->token
->type
= SKIN_TOKEN_IMAGE_DISPLAY_LISTICON
;
1417 img
->loaded
= load_skin_bmp(wps_data
, &img
->bm
, bmpdir
);
1419 img
->subimage_height
= img
->bm
.height
/ img
->num_subimages
;
1427 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1428 wps_data
->backdrop_id
= skin_backdrop_assign(wps_data
->backdrop
, bmpdir
, curr_screen
);
1429 #endif /* has backdrop support */
1433 static bool skin_load_fonts(struct wps_data
*data
)
1435 /* don't spit out after the first failue to aid debugging */
1436 bool success
= true;
1437 struct skin_element
*vp_list
;
1439 /* walk though each viewport and assign its font */
1440 for(vp_list
= data
->tree
; vp_list
; vp_list
= vp_list
->next
)
1442 /* first, find the viewports that have a non-sys/ui-font font */
1443 struct skin_viewport
*skin_vp
=
1444 (struct skin_viewport
*)vp_list
->data
;
1445 struct viewport
*vp
= &skin_vp
->vp
;
1448 if (vp
->font
<= FONT_UI
)
1449 { /* the usual case -> built-in fonts */
1450 #ifdef HAVE_REMOTE_LCD
1451 if (vp
->font
== FONT_UI
)
1452 vp
->font
+= curr_screen
;
1458 /* now find the corresponding skin_font */
1459 struct skin_font
*font
= &skinfonts
[font_id
-FONT_FIRSTUSERFONT
];
1464 DEBUGF("font %d not specified\n", font_id
);
1470 /* load the font - will handle loading the same font again if
1471 * multiple viewports use the same */
1474 char *dot
= strchr(font
->name
, '.');
1476 font
->id
= skin_font_load(font
->name
,
1477 skinfonts
[font_id
-FONT_FIRSTUSERFONT
].glyphs
);
1482 DEBUGF("Unable to load font %d: '%s.fnt'\n",
1483 font_id
, font
->name
);
1484 font
->name
= NULL
; /* to stop trying to load it again if we fail */
1490 /* finally, assign the font_id to the viewport */
1491 vp
->font
= font
->id
;
1496 #endif /* HAVE_LCD_BITMAP */
1497 static int convert_viewport(struct wps_data
*data
, struct skin_element
* element
)
1499 struct skin_viewport
*skin_vp
=
1500 (struct skin_viewport
*)skin_buffer_alloc(sizeof(struct skin_viewport
));
1501 struct screen
*display
= &screens
[curr_screen
];
1504 return CALLBACK_ERROR
;
1506 skin_vp
->hidden_flags
= 0;
1507 skin_vp
->label
= NULL
;
1508 skin_vp
->is_infovp
= false;
1509 element
->data
= skin_vp
;
1511 curr_viewport_element
= element
;
1513 viewport_set_defaults(&skin_vp
->vp
, curr_screen
);
1514 #ifdef HAVE_REMOTE_LCD
1515 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
1516 * This parser requires font 1 to always be the UI font,
1517 * so force it back to FONT_UI and handle the screen number at the end */
1518 skin_vp
->vp
.font
= FONT_UI
;
1521 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1522 skin_vp
->start_fgcolour
= skin_vp
->vp
.fg_pattern
;
1523 skin_vp
->start_bgcolour
= skin_vp
->vp
.bg_pattern
;
1527 struct skin_tag_parameter
*param
= element
->params
;
1528 if (element
->params_count
== 0) /* default viewport */
1530 if (!data
->tree
) /* first viewport in the skin */
1531 data
->tree
= element
;
1532 skin_vp
->label
= VP_DEFAULT_LABEL
;
1536 if (element
->params_count
== 6)
1538 if (element
->tag
->type
== SKIN_TOKEN_UIVIEWPORT_LOAD
)
1540 skin_vp
->is_infovp
= true;
1541 if (isdefault(param
))
1543 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1544 skin_vp
->label
= VP_DEFAULT_LABEL
;
1548 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1549 skin_vp
->label
= param
->data
.text
;
1554 skin_vp
->hidden_flags
= VP_DRAW_HIDEABLE
|VP_DRAW_HIDDEN
;
1555 skin_vp
->label
= param
->data
.text
;
1560 if (!isdefault(param
))
1562 skin_vp
->vp
.x
= param
->data
.number
;
1563 if (param
->data
.number
< 0)
1564 skin_vp
->vp
.x
+= display
->lcdwidth
;
1568 if (!isdefault(param
))
1570 skin_vp
->vp
.y
= param
->data
.number
;
1571 if (param
->data
.number
< 0)
1572 skin_vp
->vp
.y
+= display
->lcdheight
;
1576 if (!isdefault(param
))
1578 skin_vp
->vp
.width
= param
->data
.number
;
1579 if (param
->data
.number
< 0)
1580 skin_vp
->vp
.width
= (skin_vp
->vp
.width
+ display
->lcdwidth
) - skin_vp
->vp
.x
;
1584 skin_vp
->vp
.width
= display
->lcdwidth
- skin_vp
->vp
.x
;
1588 if (!isdefault(param
))
1590 skin_vp
->vp
.height
= param
->data
.number
;
1591 if (param
->data
.number
< 0)
1592 skin_vp
->vp
.height
= (skin_vp
->vp
.height
+ display
->lcdheight
) - skin_vp
->vp
.y
;
1596 skin_vp
->vp
.height
= display
->lcdheight
- skin_vp
->vp
.y
;
1599 #ifdef HAVE_LCD_BITMAP
1601 if (!isdefault(param
))
1603 skin_vp
->vp
.font
= param
->data
.number
;
1606 if ((unsigned) skin_vp
->vp
.x
>= (unsigned) display
->lcdwidth
||
1607 skin_vp
->vp
.width
+ skin_vp
->vp
.x
> display
->lcdwidth
||
1608 (unsigned) skin_vp
->vp
.y
>= (unsigned) display
->lcdheight
||
1609 skin_vp
->vp
.height
+ skin_vp
->vp
.y
> display
->lcdheight
)
1610 return CALLBACK_ERROR
;
1615 static int skin_element_callback(struct skin_element
* element
, void* data
)
1617 struct wps_data
*wps_data
= (struct wps_data
*)data
;
1618 struct wps_token
*token
;
1619 parse_function function
= NULL
;
1621 switch (element
->type
)
1623 /* IMPORTANT: element params are shared, so copy them if needed
1624 * or use then NOW, dont presume they have a long lifespan
1628 token
= (struct wps_token
*)skin_buffer_alloc(sizeof(struct wps_token
));
1629 memset(token
, 0, sizeof(*token
));
1630 token
->type
= element
->tag
->type
;
1632 if (element
->tag
->flags
&SKIN_RTC_REFRESH
)
1635 curr_line
->update_mode
|= SKIN_REFRESH_DYNAMIC
;
1637 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1641 curr_line
->update_mode
|= element
->tag
->flags
&SKIN_REFRESH_ALL
;
1643 element
->data
= token
;
1645 /* Some tags need special handling for the tag, so add them here */
1646 switch (token
->type
)
1648 case SKIN_TOKEN_ALIGN_LANGDIRECTION
:
1649 follow_lang_direction
= 2;
1651 case SKIN_TOKEN_LOGICAL_IF
:
1652 function
= parse_logical_if
;
1654 case SKIN_TOKEN_PROGRESSBAR
:
1655 case SKIN_TOKEN_VOLUME
:
1656 case SKIN_TOKEN_BATTERY_PERCENT
:
1657 case SKIN_TOKEN_PLAYER_PROGRESSBAR
:
1658 case SKIN_TOKEN_PEAKMETER_LEFT
:
1659 case SKIN_TOKEN_PEAKMETER_RIGHT
:
1660 #ifdef HAVE_RADIO_RSSI
1661 case SKIN_TOKEN_TUNER_RSSI
:
1663 function
= parse_progressbar_tag
;
1665 case SKIN_TOKEN_SUBLINE_TIMEOUT
:
1666 case SKIN_TOKEN_BUTTON_VOLUME
:
1667 case SKIN_TOKEN_TRACK_STARTING
:
1668 case SKIN_TOKEN_TRACK_ENDING
:
1669 function
= parse_timeout_tag
;
1671 #ifdef HAVE_LCD_BITMAP
1672 case SKIN_TOKEN_DISABLE_THEME
:
1673 case SKIN_TOKEN_ENABLE_THEME
:
1674 case SKIN_TOKEN_DRAW_INBUILTBAR
:
1675 function
= parse_statusbar_tags
;
1677 case SKIN_TOKEN_LIST_TITLE_TEXT
:
1679 sb_skin_has_title(curr_screen
);
1683 case SKIN_TOKEN_FILE_DIRECTORY
:
1684 token
->value
.i
= element
->params
[0].data
.number
;
1686 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1687 case SKIN_TOKEN_VIEWPORT_FGCOLOUR
:
1688 case SKIN_TOKEN_VIEWPORT_BGCOLOUR
:
1689 function
= parse_viewportcolour
;
1691 case SKIN_TOKEN_IMAGE_BACKDROP
:
1692 function
= parse_image_special
;
1695 case SKIN_TOKEN_TRANSLATEDSTRING
:
1696 case SKIN_TOKEN_SETTING
:
1697 function
= parse_setting_and_lang
;
1699 #ifdef HAVE_LCD_BITMAP
1700 case SKIN_TOKEN_VIEWPORT_CUSTOMLIST
:
1701 function
= parse_playlistview
;
1703 case SKIN_TOKEN_LOAD_FONT
:
1704 function
= parse_font_load
;
1706 case SKIN_TOKEN_VIEWPORT_ENABLE
:
1707 case SKIN_TOKEN_UIVIEWPORT_ENABLE
:
1708 token
->value
.data
= element
->params
[0].data
.text
;
1710 case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY
:
1711 function
= parse_image_display
;
1713 case SKIN_TOKEN_IMAGE_PRELOAD
:
1714 case SKIN_TOKEN_IMAGE_DISPLAY
:
1715 function
= parse_image_load
;
1718 #ifdef HAVE_TOUCHSCREEN
1719 case SKIN_TOKEN_TOUCHREGION
:
1720 function
= parse_touchregion
;
1722 case SKIN_TOKEN_LASTTOUCH
:
1723 function
= parse_lasttouch
;
1726 #ifdef HAVE_ALBUMART
1727 case SKIN_TOKEN_ALBUMART_DISPLAY
:
1728 if (wps_data
->albumart
)
1729 wps_data
->albumart
->vp
= &curr_vp
->vp
;
1731 case SKIN_TOKEN_ALBUMART_LOAD
:
1732 function
= parse_albumart_load
;
1735 #ifdef HAVE_SKIN_VARIABLES
1736 case SKIN_TOKEN_VAR_SET
:
1737 case SKIN_TOKEN_VAR_GETVAL
:
1738 case SKIN_TOKEN_VAR_TIMEOUT
:
1739 function
= parse_skinvar
;
1747 if (function(element
, token
, wps_data
) < 0)
1748 return CALLBACK_ERROR
;
1750 /* tags that start with 'F', 'I' or 'D' are for the next file */
1751 if ( *(element
->tag
->name
) == 'I' || *(element
->tag
->name
) == 'F' ||
1752 *(element
->tag
->name
) == 'D')
1754 if (follow_lang_direction
> 0 )
1755 follow_lang_direction
--;
1759 return convert_viewport(wps_data
, element
);
1763 (struct line
*)skin_buffer_alloc(sizeof(struct line
));
1764 line
->update_mode
= SKIN_REFRESH_STATIC
;
1766 element
->data
= line
;
1769 case LINE_ALTERNATOR
:
1771 struct line_alternator
*alternator
=
1772 (struct line_alternator
*)skin_buffer_alloc(sizeof(struct line_alternator
));
1773 alternator
->current_line
= 0;
1775 alternator
->next_change_tick
= current_tick
;
1777 element
->data
= alternator
;
1782 struct conditional
*conditional
=
1783 (struct conditional
*)skin_buffer_alloc(sizeof(struct conditional
));
1784 conditional
->last_value
= -1;
1785 conditional
->token
= element
->data
;
1786 element
->data
= conditional
;
1787 if (!check_feature_tag(element
->tag
->type
))
1789 return FEATURE_NOT_AVAILABLE
;
1794 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1802 /* to setup up the wps-data from a format-buffer (isfile = false)
1803 from a (wps-)file (isfile = true)*/
1804 bool skin_data_load(enum screen_type screen
, struct wps_data
*wps_data
,
1805 const char *buf
, bool isfile
)
1807 char *wps_buffer
= NULL
;
1808 if (!wps_data
|| !buf
)
1810 #ifdef HAVE_ALBUMART
1812 struct mp3entry
*curtrack
;
1814 struct skin_albumart old_aa
= {.state
= WPS_ALBUMART_NONE
};
1815 if (wps_data
->albumart
)
1817 old_aa
.state
= wps_data
->albumart
->state
;
1818 old_aa
.height
= wps_data
->albumart
->height
;
1819 old_aa
.width
= wps_data
->albumart
->width
;
1822 #ifdef HAVE_LCD_BITMAP
1824 for (i
=0;i
<MAXUSERFONTS
;i
++)
1826 skinfonts
[i
].id
= -1;
1827 skinfonts
[i
].name
= NULL
;
1830 #ifdef DEBUG_SKIN_ENGINE
1831 if (isfile
&& debug_wps
)
1833 DEBUGF("\n=====================\nLoading '%s'\n=====================\n", buf
);
1838 skin_data_reset(wps_data
);
1839 wps_data
->wps_loaded
= false;
1840 curr_screen
= screen
;
1843 curr_viewport_element
= NULL
;
1847 int fd
= open_utf8(buf
, O_RDONLY
);
1852 /* get buffer space from the plugin buffer */
1853 size_t buffersize
= 0;
1854 wps_buffer
= (char *)plugin_get_buffer(&buffersize
);
1859 /* copy the file's content to the buffer for parsing,
1860 ensuring that every line ends with a newline char. */
1861 unsigned int start
= 0;
1862 while(read_line(fd
, wps_buffer
+ start
, buffersize
- start
) > 0)
1864 start
+= strlen(wps_buffer
+ start
);
1865 if (start
< buffersize
- 1)
1867 wps_buffer
[start
++] = '\n';
1868 wps_buffer
[start
] = 0;
1877 wps_buffer
= (char*)buf
;
1879 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1880 wps_data
->backdrop
= "-";
1881 wps_data
->backdrop_id
= -1;
1883 /* parse the skin source */
1885 skin_buffer_save_position();
1887 wps_data
->tree
= skin_parse(wps_buffer
, skin_element_callback
, wps_data
);
1888 if (!wps_data
->tree
) {
1889 skin_data_reset(wps_data
);
1891 skin_buffer_restore_position();
1896 #ifdef HAVE_LCD_BITMAP
1897 char bmpdir
[MAX_PATH
];
1900 /* get the bitmap dir */
1901 char *dot
= strrchr(buf
, '.');
1902 strlcpy(bmpdir
, buf
, dot
- buf
+ 1);
1906 snprintf(bmpdir
, MAX_PATH
, "%s", BACKDROP_DIR
);
1908 /* load the bitmaps that were found by the parsing */
1909 if (!load_skin_bitmaps(wps_data
, bmpdir
) ||
1910 !skin_load_fonts(wps_data
))
1912 skin_data_reset(wps_data
);
1914 skin_buffer_restore_position();
1919 #if defined(HAVE_ALBUMART) && !defined(__PCTOOL__)
1920 status
= audio_status();
1921 if (status
& AUDIO_STATUS_PLAY
)
1923 struct skin_albumart
*aa
= wps_data
->albumart
;
1924 if (aa
&& ((aa
->state
&& !old_aa
.state
) ||
1926 (((old_aa
.height
!= aa
->height
) ||
1927 (old_aa
.width
!= aa
->width
))))))
1929 curtrack
= audio_current_track();
1930 offset
= curtrack
->offset
;
1932 if (!(status
& AUDIO_STATUS_PAUSE
))
1937 wps_data
->wps_loaded
= true;
1938 #ifdef DEBUG_SKIN_ENGINE
1939 // if (isfile && debug_wps)
1940 // debug_skin_usage();