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 data
->timeout
= element
->params
[i
].data
.number
;
1033 data
->timeout
*= TIMEOUT_UNIT
;
1034 token
->value
.data
= data
;
1038 struct touchaction
{const char* s
; int action
;};
1039 static const struct touchaction touchactions
[] = {
1040 /* generic actions, convert to screen actions on use */
1041 {"none", ACTION_TOUCHSCREEN
},
1042 {"prev", ACTION_STD_PREV
}, {"next", ACTION_STD_NEXT
},
1043 {"rwd", ACTION_STD_PREVREPEAT
}, {"ffwd", ACTION_STD_NEXTREPEAT
},
1044 {"hotkey", ACTION_STD_HOTKEY
}, {"select", ACTION_STD_OK
},
1045 {"menu", ACTION_STD_MENU
}, {"cancel", ACTION_STD_CANCEL
},
1046 {"contextmenu", ACTION_STD_CONTEXT
},{"quickscreen", ACTION_STD_QUICKSCREEN
},
1048 /* list/tree actions */
1049 { "resumeplayback", ACTION_TREE_WPS
}, /* returns to previous music, WPS/FM */
1050 /* not really WPS specific, but no equivilant ACTION_STD_* */
1051 {"voldown", ACTION_WPS_VOLDOWN
}, {"volup", ACTION_WPS_VOLUP
},
1052 {"mute", ACTION_TOUCH_MUTE
},
1054 /* generic settings changers */
1055 {"setting_inc", ACTION_SETTINGS_INC
}, {"setting_dec", ACTION_SETTINGS_DEC
},
1056 {"setting_set", ACTION_SETTINGS_SET
},
1058 /* WPS specific actions */
1059 {"wps_prev", ACTION_WPS_SKIPPREV
}, {"wps_next", ACTION_WPS_SKIPNEXT
},
1060 {"browse", ACTION_WPS_BROWSE
},
1061 {"play", ACTION_WPS_PLAY
}, {"stop", ACTION_WPS_STOP
},
1062 {"shuffle", ACTION_TOUCH_SHUFFLE
}, {"repmode", ACTION_TOUCH_REPMODE
},
1063 {"pitch", ACTION_WPS_PITCHSCREEN
}, {"playlist", ACTION_WPS_VIEW_PLAYLIST
},
1066 /* FM screen actions */
1067 /* Also allow browse, play, stop from WPS codes */
1068 {"mode", ACTION_FM_MODE
}, {"record", ACTION_FM_RECORD
},
1069 {"presets", ACTION_FM_PRESET
},
1073 static int parse_touchregion(struct skin_element
*element
,
1074 struct wps_token
*token
,
1075 struct wps_data
*wps_data
)
1080 struct touchregion
*region
= NULL
;
1082 const char pb_string
[] = "progressbar";
1083 const char vol_string
[] = "volume";
1086 /* format: %T([label,], x,y,width,height,action[, ...])
1087 * if action starts with & the area must be held to happen
1091 region
= (struct touchregion
*)skin_buffer_alloc(sizeof(struct touchregion
));
1093 return WPS_ERROR_INVALID_PARAM
;
1095 /* should probably do some bounds checking here with the viewport... but later */
1096 region
->action
= ACTION_NONE
;
1098 if (element
->params
[0].type
== STRING
)
1100 region
->label
= element
->params
[0].data
.text
;
1102 /* "[SI]III[SI]|SS" is the param list. There MUST be 4 numbers
1103 * followed by at least one string. Verify that here */
1104 if (element
->params_count
< 6 ||
1105 element
->params
[4].type
!= INTEGER
)
1106 return WPS_ERROR_INVALID_PARAM
;
1110 region
->label
= NULL
;
1114 region
->x
= element
->params
[p
++].data
.number
;
1115 region
->y
= element
->params
[p
++].data
.number
;
1116 region
->width
= element
->params
[p
++].data
.number
;
1117 region
->height
= element
->params
[p
++].data
.number
;
1118 region
->wvp
= curr_vp
;
1119 region
->armed
= false;
1120 region
->reverse_bar
= false;
1122 region
->last_press
= 0xffff;
1123 region
->press_length
= PRESS
;
1124 action
= element
->params
[p
++].data
.text
;
1126 strcpy(temp
, action
);
1131 region
->reverse_bar
= true;
1135 if(!strcmp(pb_string
, action
))
1136 region
->action
= ACTION_TOUCH_SCROLLBAR
;
1137 else if(!strcmp(vol_string
, action
))
1138 region
->action
= ACTION_TOUCH_VOLUME
;
1144 region
->press_length
= LONG_PRESS
;
1146 else if(*action
== '*')
1149 region
->press_length
= REPEAT
;
1152 region
->press_length
= PRESS
;
1154 imax
= ARRAYLEN(touchactions
);
1155 for (i
= 0; i
< imax
; i
++)
1157 /* try to match with one of our touchregion screens */
1158 if (!strcmp(touchactions
[i
].s
, action
))
1160 region
->action
= touchactions
[i
].action
;
1161 if (region
->action
== ACTION_SETTINGS_INC
||
1162 region
->action
== ACTION_SETTINGS_DEC
||
1163 region
->action
== ACTION_SETTINGS_SET
)
1165 if (element
->params_count
< p
+1)
1167 return WPS_ERROR_INVALID_PARAM
;
1171 char *name
= element
->params
[p
].data
.text
;
1173 /* Find the setting */
1174 for (j
=0; j
<nb_settings
; j
++)
1175 if (settings
[j
].cfg_name
&&
1176 !strcmp(settings
[j
].cfg_name
, name
))
1179 return WPS_ERROR_INVALID_PARAM
;
1180 region
->setting_data
.setting
= (void*)&settings
[j
];
1181 if (region
->action
== ACTION_SETTINGS_SET
)
1185 struct touchsetting
*setting
=
1186 ®ion
->setting_data
;
1187 if (element
->params_count
< p
+2)
1188 return WPS_ERROR_INVALID_PARAM
;
1190 text
= element
->params
[p
+1].data
.text
;
1191 switch (settings
[j
].flags
&F_T_MASK
)
1194 setting
->value
.text
= text
;
1198 if (settings
[j
].cfg_vals
== NULL
)
1200 setting
->value
.number
= atoi(text
);
1202 else if (cfg_string_to_int(j
, &temp
, text
))
1204 if (settings
[j
].flags
&F_TABLE_SETTING
)
1205 setting
->value
.number
=
1206 settings
[j
].table_setting
->values
[temp
];
1208 setting
->value
.number
= temp
;
1211 return WPS_ERROR_INVALID_PARAM
;
1214 if (cfg_string_to_int(j
, &temp
, text
))
1216 setting
->value
.number
= temp
;
1219 return WPS_ERROR_INVALID_PARAM
;
1222 return WPS_ERROR_INVALID_PARAM
;
1224 #endif /* __PCTOOL__ */
1231 if (region
->action
== ACTION_NONE
)
1232 return WPS_ERROR_INVALID_PARAM
;
1234 struct skin_token_list
*item
= new_skin_token_list_item(NULL
, region
);
1236 return WPS_ERROR_INVALID_PARAM
;
1237 add_to_ll_chain(&wps_data
->touchregions
, item
);
1239 if (region
->action
== ACTION_TOUCH_MUTE
)
1241 region
->value
= global_settings
.volume
;
1249 static bool check_feature_tag(const int type
)
1253 case SKIN_TOKEN_RTC_PRESENT
:
1259 case SKIN_TOKEN_HAVE_RECORDING
:
1260 #ifdef HAVE_RECORDING
1265 case SKIN_TOKEN_HAVE_TUNER
:
1267 if (radio_hardware_present())
1271 case SKIN_TOKEN_HAVE_TOUCH
:
1272 #ifdef HAVE_TOUCHSCREEN
1279 case SKIN_TOKEN_HAVE_RDS
:
1284 #endif /* HAVE_RDS_CAP */
1285 #endif /* CONFIG_TUNER */
1286 default: /* not a tag we care about, just don't skip */
1292 * initial setup of wps_data; does reset everything
1293 * except fields which need to survive, i.e.
1296 static void skin_data_reset(struct wps_data
*wps_data
)
1298 wps_data
->tree
= NULL
;
1299 #ifdef HAVE_LCD_BITMAP
1300 wps_data
->images
= NULL
;
1302 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1303 if (wps_data
->backdrop_id
>= 0)
1304 skin_backdrop_unload(wps_data
->backdrop_id
);
1305 wps_data
->backdrop
= NULL
;
1307 #ifdef HAVE_TOUCHSCREEN
1308 wps_data
->touchregions
= NULL
;
1310 #ifdef HAVE_SKIN_VARIABLES
1311 wps_data
->skinvars
= NULL
;
1313 #ifdef HAVE_ALBUMART
1314 wps_data
->albumart
= NULL
;
1315 if (wps_data
->playback_aa_slot
>= 0)
1317 playback_release_aa_slot(wps_data
->playback_aa_slot
);
1318 wps_data
->playback_aa_slot
= -1;
1322 #ifdef HAVE_LCD_BITMAP
1323 wps_data
->peak_meter_enabled
= false;
1324 wps_data
->wps_sb_tag
= false;
1325 wps_data
->show_sb_on_wps
= false;
1326 #else /* HAVE_LCD_CHARCELLS */
1329 for (i
= 0; i
< 8; i
++)
1331 wps_data
->wps_progress_pat
[i
] = 0;
1333 wps_data
->full_line_progressbar
= false;
1335 wps_data
->wps_loaded
= false;
1338 #ifdef HAVE_LCD_BITMAP
1339 static bool load_skin_bmp(struct wps_data
*wps_data
, struct bitmap
*bitmap
, char* bmpdir
)
1341 (void)wps_data
; /* only needed for remote targets */
1342 char img_path
[MAX_PATH
];
1344 get_image_filename(bitmap
->data
, bmpdir
,
1345 img_path
, sizeof(img_path
));
1347 /* load the image */
1349 #ifdef HAVE_REMOTE_LCD
1350 if (curr_screen
== SCREEN_REMOTE
)
1351 format
= FORMAT_ANY
|FORMAT_REMOTE
;
1354 format
= FORMAT_ANY
|FORMAT_TRANSPARENT
;
1356 fd
= open(img_path
, O_RDONLY
);
1359 DEBUGF("Couldn't open %s\n", img_path
);
1362 size_t buf_size
= read_bmp_fd(fd
, bitmap
, 0,
1363 format
|FORMAT_RETURN_SIZE
, NULL
);
1364 char* imgbuf
= (char*)skin_buffer_alloc(buf_size
);
1368 DEBUGF("Not enough skin buffer: need %zd more.\n",
1369 buf_size
- skin_buffer_freespace());
1374 lseek(fd
, 0, SEEK_SET
);
1375 bitmap
->data
= imgbuf
;
1376 int ret
= read_bmp_fd(fd
, bitmap
, buf_size
, format
, NULL
);
1385 /* Abort if we can't load an image */
1386 DEBUGF("Couldn't load '%s'\n", img_path
);
1391 static bool load_skin_bitmaps(struct wps_data
*wps_data
, char *bmpdir
)
1393 struct skin_token_list
*list
;
1394 bool retval
= true; /* return false if a single image failed to load */
1396 /* regular images */
1397 list
= wps_data
->images
;
1400 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
1403 if (img
->using_preloaded_icons
)
1406 list
->token
->type
= SKIN_TOKEN_IMAGE_DISPLAY_LISTICON
;
1410 img
->loaded
= load_skin_bmp(wps_data
, &img
->bm
, bmpdir
);
1412 img
->subimage_height
= img
->bm
.height
/ img
->num_subimages
;
1420 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1421 wps_data
->backdrop_id
= skin_backdrop_assign(wps_data
->backdrop
, bmpdir
, curr_screen
);
1422 #endif /* has backdrop support */
1426 static bool skin_load_fonts(struct wps_data
*data
)
1428 /* don't spit out after the first failue to aid debugging */
1429 bool success
= true;
1430 struct skin_element
*vp_list
;
1432 /* walk though each viewport and assign its font */
1433 for(vp_list
= data
->tree
; vp_list
; vp_list
= vp_list
->next
)
1435 /* first, find the viewports that have a non-sys/ui-font font */
1436 struct skin_viewport
*skin_vp
=
1437 (struct skin_viewport
*)vp_list
->data
;
1438 struct viewport
*vp
= &skin_vp
->vp
;
1441 if (vp
->font
<= FONT_UI
)
1442 { /* the usual case -> built-in fonts */
1443 #ifdef HAVE_REMOTE_LCD
1444 if (vp
->font
== FONT_UI
)
1445 vp
->font
+= curr_screen
;
1451 /* now find the corresponding skin_font */
1452 struct skin_font
*font
= &skinfonts
[font_id
-FONT_FIRSTUSERFONT
];
1457 DEBUGF("font %d not specified\n", font_id
);
1463 /* load the font - will handle loading the same font again if
1464 * multiple viewports use the same */
1467 char *dot
= strchr(font
->name
, '.');
1469 font
->id
= skin_font_load(font
->name
,
1470 skinfonts
[font_id
-FONT_FIRSTUSERFONT
].glyphs
);
1475 DEBUGF("Unable to load font %d: '%s.fnt'\n",
1476 font_id
, font
->name
);
1477 font
->name
= NULL
; /* to stop trying to load it again if we fail */
1483 /* finally, assign the font_id to the viewport */
1484 vp
->font
= font
->id
;
1489 #endif /* HAVE_LCD_BITMAP */
1490 static int convert_viewport(struct wps_data
*data
, struct skin_element
* element
)
1492 struct skin_viewport
*skin_vp
=
1493 (struct skin_viewport
*)skin_buffer_alloc(sizeof(struct skin_viewport
));
1494 struct screen
*display
= &screens
[curr_screen
];
1497 return CALLBACK_ERROR
;
1499 skin_vp
->hidden_flags
= 0;
1500 skin_vp
->label
= NULL
;
1501 skin_vp
->is_infovp
= false;
1502 element
->data
= skin_vp
;
1504 curr_viewport_element
= element
;
1506 viewport_set_defaults(&skin_vp
->vp
, curr_screen
);
1507 #ifdef HAVE_REMOTE_LCD
1508 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
1509 * This parser requires font 1 to always be the UI font,
1510 * so force it back to FONT_UI and handle the screen number at the end */
1511 skin_vp
->vp
.font
= FONT_UI
;
1514 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1515 skin_vp
->start_fgcolour
= skin_vp
->vp
.fg_pattern
;
1516 skin_vp
->start_bgcolour
= skin_vp
->vp
.bg_pattern
;
1520 struct skin_tag_parameter
*param
= element
->params
;
1521 if (element
->params_count
== 0) /* default viewport */
1523 if (!data
->tree
) /* first viewport in the skin */
1524 data
->tree
= element
;
1525 skin_vp
->label
= VP_DEFAULT_LABEL
;
1529 if (element
->params_count
== 6)
1531 if (element
->tag
->type
== SKIN_TOKEN_UIVIEWPORT_LOAD
)
1533 skin_vp
->is_infovp
= true;
1534 if (isdefault(param
))
1536 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1537 skin_vp
->label
= VP_DEFAULT_LABEL
;
1541 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1542 skin_vp
->label
= param
->data
.text
;
1547 skin_vp
->hidden_flags
= VP_DRAW_HIDEABLE
|VP_DRAW_HIDDEN
;
1548 skin_vp
->label
= param
->data
.text
;
1553 if (!isdefault(param
))
1555 skin_vp
->vp
.x
= param
->data
.number
;
1556 if (param
->data
.number
< 0)
1557 skin_vp
->vp
.x
+= display
->lcdwidth
;
1561 if (!isdefault(param
))
1563 skin_vp
->vp
.y
= param
->data
.number
;
1564 if (param
->data
.number
< 0)
1565 skin_vp
->vp
.y
+= display
->lcdheight
;
1569 if (!isdefault(param
))
1571 skin_vp
->vp
.width
= param
->data
.number
;
1572 if (param
->data
.number
< 0)
1573 skin_vp
->vp
.width
= (skin_vp
->vp
.width
+ display
->lcdwidth
) - skin_vp
->vp
.x
;
1577 skin_vp
->vp
.width
= display
->lcdwidth
- skin_vp
->vp
.x
;
1581 if (!isdefault(param
))
1583 skin_vp
->vp
.height
= param
->data
.number
;
1584 if (param
->data
.number
< 0)
1585 skin_vp
->vp
.height
= (skin_vp
->vp
.height
+ display
->lcdheight
) - skin_vp
->vp
.y
;
1589 skin_vp
->vp
.height
= display
->lcdheight
- skin_vp
->vp
.y
;
1592 #ifdef HAVE_LCD_BITMAP
1594 if (!isdefault(param
))
1596 skin_vp
->vp
.font
= param
->data
.number
;
1599 if ((unsigned) skin_vp
->vp
.x
>= (unsigned) display
->lcdwidth
||
1600 skin_vp
->vp
.width
+ skin_vp
->vp
.x
> display
->lcdwidth
||
1601 (unsigned) skin_vp
->vp
.y
>= (unsigned) display
->lcdheight
||
1602 skin_vp
->vp
.height
+ skin_vp
->vp
.y
> display
->lcdheight
)
1603 return CALLBACK_ERROR
;
1608 static int skin_element_callback(struct skin_element
* element
, void* data
)
1610 struct wps_data
*wps_data
= (struct wps_data
*)data
;
1611 struct wps_token
*token
;
1612 parse_function function
= NULL
;
1614 switch (element
->type
)
1616 /* IMPORTANT: element params are shared, so copy them if needed
1617 * or use then NOW, dont presume they have a long lifespan
1621 token
= (struct wps_token
*)skin_buffer_alloc(sizeof(struct wps_token
));
1622 memset(token
, 0, sizeof(*token
));
1623 token
->type
= element
->tag
->type
;
1625 if (element
->tag
->flags
&SKIN_RTC_REFRESH
)
1628 curr_line
->update_mode
|= SKIN_REFRESH_DYNAMIC
;
1630 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1634 curr_line
->update_mode
|= element
->tag
->flags
&SKIN_REFRESH_ALL
;
1636 element
->data
= token
;
1638 /* Some tags need special handling for the tag, so add them here */
1639 switch (token
->type
)
1641 case SKIN_TOKEN_ALIGN_LANGDIRECTION
:
1642 follow_lang_direction
= 2;
1644 case SKIN_TOKEN_LOGICAL_IF
:
1645 function
= parse_logical_if
;
1647 case SKIN_TOKEN_PROGRESSBAR
:
1648 case SKIN_TOKEN_VOLUME
:
1649 case SKIN_TOKEN_BATTERY_PERCENT
:
1650 case SKIN_TOKEN_PLAYER_PROGRESSBAR
:
1651 case SKIN_TOKEN_PEAKMETER_LEFT
:
1652 case SKIN_TOKEN_PEAKMETER_RIGHT
:
1653 #ifdef HAVE_RADIO_RSSI
1654 case SKIN_TOKEN_TUNER_RSSI
:
1656 function
= parse_progressbar_tag
;
1658 case SKIN_TOKEN_SUBLINE_TIMEOUT
:
1659 case SKIN_TOKEN_BUTTON_VOLUME
:
1660 case SKIN_TOKEN_TRACK_STARTING
:
1661 case SKIN_TOKEN_TRACK_ENDING
:
1662 function
= parse_timeout_tag
;
1664 #ifdef HAVE_LCD_BITMAP
1665 case SKIN_TOKEN_DISABLE_THEME
:
1666 case SKIN_TOKEN_ENABLE_THEME
:
1667 case SKIN_TOKEN_DRAW_INBUILTBAR
:
1668 function
= parse_statusbar_tags
;
1670 case SKIN_TOKEN_LIST_TITLE_TEXT
:
1672 sb_skin_has_title(curr_screen
);
1676 case SKIN_TOKEN_FILE_DIRECTORY
:
1677 token
->value
.i
= element
->params
[0].data
.number
;
1679 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1680 case SKIN_TOKEN_VIEWPORT_FGCOLOUR
:
1681 case SKIN_TOKEN_VIEWPORT_BGCOLOUR
:
1682 function
= parse_viewportcolour
;
1684 case SKIN_TOKEN_IMAGE_BACKDROP
:
1685 function
= parse_image_special
;
1688 case SKIN_TOKEN_TRANSLATEDSTRING
:
1689 case SKIN_TOKEN_SETTING
:
1690 function
= parse_setting_and_lang
;
1692 #ifdef HAVE_LCD_BITMAP
1693 case SKIN_TOKEN_VIEWPORT_CUSTOMLIST
:
1694 function
= parse_playlistview
;
1696 case SKIN_TOKEN_LOAD_FONT
:
1697 function
= parse_font_load
;
1699 case SKIN_TOKEN_VIEWPORT_ENABLE
:
1700 case SKIN_TOKEN_UIVIEWPORT_ENABLE
:
1701 token
->value
.data
= element
->params
[0].data
.text
;
1703 case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY
:
1704 function
= parse_image_display
;
1706 case SKIN_TOKEN_IMAGE_PRELOAD
:
1707 case SKIN_TOKEN_IMAGE_DISPLAY
:
1708 function
= parse_image_load
;
1711 #ifdef HAVE_TOUCHSCREEN
1712 case SKIN_TOKEN_TOUCHREGION
:
1713 function
= parse_touchregion
;
1715 case SKIN_TOKEN_LASTTOUCH
:
1716 function
= parse_lasttouch
;
1719 #ifdef HAVE_ALBUMART
1720 case SKIN_TOKEN_ALBUMART_DISPLAY
:
1721 if (wps_data
->albumart
)
1722 wps_data
->albumart
->vp
= &curr_vp
->vp
;
1724 case SKIN_TOKEN_ALBUMART_LOAD
:
1725 function
= parse_albumart_load
;
1728 #ifdef HAVE_SKIN_VARIABLES
1729 case SKIN_TOKEN_VAR_SET
:
1730 case SKIN_TOKEN_VAR_GETVAL
:
1731 case SKIN_TOKEN_VAR_TIMEOUT
:
1732 function
= parse_skinvar
;
1740 if (function(element
, token
, wps_data
) < 0)
1741 return CALLBACK_ERROR
;
1743 /* tags that start with 'F', 'I' or 'D' are for the next file */
1744 if ( *(element
->tag
->name
) == 'I' || *(element
->tag
->name
) == 'F' ||
1745 *(element
->tag
->name
) == 'D')
1747 if (follow_lang_direction
> 0 )
1748 follow_lang_direction
--;
1752 return convert_viewport(wps_data
, element
);
1756 (struct line
*)skin_buffer_alloc(sizeof(struct line
));
1757 line
->update_mode
= SKIN_REFRESH_STATIC
;
1759 element
->data
= line
;
1762 case LINE_ALTERNATOR
:
1764 struct line_alternator
*alternator
=
1765 (struct line_alternator
*)skin_buffer_alloc(sizeof(struct line_alternator
));
1766 alternator
->current_line
= 0;
1768 alternator
->next_change_tick
= current_tick
;
1770 element
->data
= alternator
;
1775 struct conditional
*conditional
=
1776 (struct conditional
*)skin_buffer_alloc(sizeof(struct conditional
));
1777 conditional
->last_value
= -1;
1778 conditional
->token
= element
->data
;
1779 element
->data
= conditional
;
1780 if (!check_feature_tag(element
->tag
->type
))
1782 return FEATURE_NOT_AVAILABLE
;
1787 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1795 /* to setup up the wps-data from a format-buffer (isfile = false)
1796 from a (wps-)file (isfile = true)*/
1797 bool skin_data_load(enum screen_type screen
, struct wps_data
*wps_data
,
1798 const char *buf
, bool isfile
)
1800 char *wps_buffer
= NULL
;
1801 if (!wps_data
|| !buf
)
1803 #ifdef HAVE_ALBUMART
1805 struct mp3entry
*curtrack
;
1807 struct skin_albumart old_aa
= {.state
= WPS_ALBUMART_NONE
};
1808 if (wps_data
->albumart
)
1810 old_aa
.state
= wps_data
->albumart
->state
;
1811 old_aa
.height
= wps_data
->albumart
->height
;
1812 old_aa
.width
= wps_data
->albumart
->width
;
1815 #ifdef HAVE_LCD_BITMAP
1817 for (i
=0;i
<MAXUSERFONTS
;i
++)
1819 skinfonts
[i
].id
= -1;
1820 skinfonts
[i
].name
= NULL
;
1823 #ifdef DEBUG_SKIN_ENGINE
1824 if (isfile
&& debug_wps
)
1826 DEBUGF("\n=====================\nLoading '%s'\n=====================\n", buf
);
1831 skin_data_reset(wps_data
);
1832 wps_data
->wps_loaded
= false;
1833 curr_screen
= screen
;
1836 curr_viewport_element
= NULL
;
1840 int fd
= open_utf8(buf
, O_RDONLY
);
1845 /* get buffer space from the plugin buffer */
1846 size_t buffersize
= 0;
1847 wps_buffer
= (char *)plugin_get_buffer(&buffersize
);
1852 /* copy the file's content to the buffer for parsing,
1853 ensuring that every line ends with a newline char. */
1854 unsigned int start
= 0;
1855 while(read_line(fd
, wps_buffer
+ start
, buffersize
- start
) > 0)
1857 start
+= strlen(wps_buffer
+ start
);
1858 if (start
< buffersize
- 1)
1860 wps_buffer
[start
++] = '\n';
1861 wps_buffer
[start
] = 0;
1870 wps_buffer
= (char*)buf
;
1872 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1873 wps_data
->backdrop
= "-";
1874 wps_data
->backdrop_id
= -1;
1876 /* parse the skin source */
1878 skin_buffer_save_position();
1880 wps_data
->tree
= skin_parse(wps_buffer
, skin_element_callback
, wps_data
);
1881 if (!wps_data
->tree
) {
1882 skin_data_reset(wps_data
);
1884 skin_buffer_restore_position();
1889 #ifdef HAVE_LCD_BITMAP
1890 char bmpdir
[MAX_PATH
];
1893 /* get the bitmap dir */
1894 char *dot
= strrchr(buf
, '.');
1895 strlcpy(bmpdir
, buf
, dot
- buf
+ 1);
1899 snprintf(bmpdir
, MAX_PATH
, "%s", BACKDROP_DIR
);
1901 /* load the bitmaps that were found by the parsing */
1902 if (!load_skin_bitmaps(wps_data
, bmpdir
) ||
1903 !skin_load_fonts(wps_data
))
1905 skin_data_reset(wps_data
);
1907 skin_buffer_restore_position();
1912 #if defined(HAVE_ALBUMART) && !defined(__PCTOOL__)
1913 status
= audio_status();
1914 if (status
& AUDIO_STATUS_PLAY
)
1916 struct skin_albumart
*aa
= wps_data
->albumart
;
1917 if (aa
&& ((aa
->state
&& !old_aa
.state
) ||
1919 (((old_aa
.height
!= aa
->height
) ||
1920 (old_aa
.width
!= aa
->width
))))))
1922 curtrack
= audio_current_track();
1923 offset
= curtrack
->offset
;
1925 if (!(status
& AUDIO_STATUS_PAUSE
))
1930 wps_data
->wps_loaded
= true;
1931 #ifdef DEBUG_SKIN_ENGINE
1932 // if (isfile && debug_wps)
1933 // debug_skin_usage();