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
;
118 /* traverse the image linked-list for an image */
119 struct gui_img
* find_image(const char *label
, struct wps_data
*data
)
121 struct skin_token_list
*list
= data
->images
;
124 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
125 if (!strcmp(img
->label
,label
))
134 /* traverse the viewport linked list for a viewport */
135 struct skin_viewport
* find_viewport(const char *label
, bool uivp
, struct wps_data
*data
)
137 struct skin_element
*list
= data
->tree
;
140 struct skin_viewport
*vp
= (struct skin_viewport
*)list
->data
;
141 if (vp
->label
&& (vp
->is_infovp
== uivp
) &&
142 !strcmp(vp
->label
, label
))
149 #ifdef HAVE_LCD_BITMAP
151 /* create and init a new wpsll item.
152 * passing NULL to token will alloc a new one.
153 * You should only pass NULL for the token when the token type (table above)
154 * is WPS_NO_TOKEN which means it is not stored automatically in the skins token array
156 static struct skin_token_list
*new_skin_token_list_item(struct wps_token
*token
,
159 struct skin_token_list
*llitem
=
160 (struct skin_token_list
*)skin_buffer_alloc(sizeof(struct skin_token_list
));
162 token
= (struct wps_token
*)skin_buffer_alloc(sizeof(struct wps_token
));
163 if (!llitem
|| !token
)
166 llitem
->token
= token
;
168 llitem
->token
->value
.data
= token_data
;
172 static int parse_statusbar_tags(struct skin_element
* element
,
173 struct wps_token
*token
,
174 struct wps_data
*wps_data
)
177 if (token
->type
== SKIN_TOKEN_DRAW_INBUILTBAR
)
179 token
->value
.data
= (void*)&curr_vp
->vp
;
183 struct skin_element
*def_vp
= wps_data
->tree
;
184 struct skin_viewport
*default_vp
= def_vp
->data
;
185 if (def_vp
->params_count
== 0)
187 wps_data
->wps_sb_tag
= true;
188 wps_data
->show_sb_on_wps
= (token
->type
== SKIN_TOKEN_ENABLE_THEME
);
190 if (wps_data
->show_sb_on_wps
)
192 viewport_set_defaults(&default_vp
->vp
, curr_screen
);
196 viewport_set_fullscreen(&default_vp
->vp
, curr_screen
);
198 #ifdef HAVE_REMOTE_LCD
199 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
200 * This parser requires font 1 to always be the UI font,
201 * so force it back to FONT_UI and handle the screen number at the end */
202 default_vp
->vp
.font
= FONT_UI
;
208 static int get_image_id(int c
)
210 if(c
>= 'a' && c
<= 'z')
212 else if(c
>= 'A' && c
<= 'Z')
218 char *get_image_filename(const char *start
, const char* bmpdir
,
219 char *buf
, int buf_size
)
221 snprintf(buf
, buf_size
, "%s/%s", bmpdir
, start
);
226 static int parse_image_display(struct skin_element
*element
,
227 struct wps_token
*token
,
228 struct wps_data
*wps_data
)
230 char *label
= element
->params
[0].data
.text
;
231 char sublabel
= '\0';
234 struct image_display
*id
= skin_buffer_alloc(sizeof(struct image_display
));
236 if (element
->params_count
== 1 && strlen(label
) <= 2)
238 /* backwards compatability. Allow %xd(Aa) to still work */
243 img
= find_image(label
, wps_data
);
246 return WPS_ERROR_INVALID_PARAM
;
251 if (img
->using_preloaded_icons
)
253 token
->type
= SKIN_TOKEN_IMAGE_DISPLAY_LISTICON
;
256 if (element
->params_count
> 1)
258 if (element
->params
[1].type
== CODE
)
259 id
->token
= element
->params
[1].data
.code
->data
;
260 /* specify a number. 1 being the first subimage (i.e top) NOT 0 */
261 else if (element
->params
[1].type
== INTEGER
)
262 id
->subimage
= element
->params
[1].data
.number
- 1;
263 if (element
->params_count
> 2)
264 id
->offset
= element
->params
[2].data
.number
;
268 if ((subimage
= get_image_id(sublabel
)) != -1)
270 if (subimage
>= img
->num_subimages
)
271 return WPS_ERROR_INVALID_PARAM
;
272 id
->subimage
= subimage
;
277 token
->value
.data
= id
;
281 static int parse_image_load(struct skin_element
*element
,
282 struct wps_token
*token
,
283 struct wps_data
*wps_data
)
285 const char* filename
;
290 /* format: %x(n,filename.bmp,x,y)
291 or %xl(n,filename.bmp,x,y)
292 or %xl(n,filename.bmp,x,y,num_subimages)
295 id
= element
->params
[0].data
.text
;
296 filename
= element
->params
[1].data
.text
;
297 x
= element
->params
[2].data
.number
;
298 y
= element
->params
[3].data
.number
;
300 /* check the image number and load state */
301 if(find_image(id
, wps_data
))
303 /* Invalid image ID */
304 return WPS_ERROR_INVALID_PARAM
;
306 img
= (struct gui_img
*)skin_buffer_alloc(sizeof(struct gui_img
));
308 return WPS_ERROR_INVALID_PARAM
;
309 /* save a pointer to the filename */
310 img
->bm
.data
= (char*)filename
;
314 img
->num_subimages
= 1;
315 img
->always_display
= false;
317 img
->using_preloaded_icons
= false;
319 /* save current viewport */
320 img
->vp
= &curr_vp
->vp
;
322 if (token
->type
== SKIN_TOKEN_IMAGE_DISPLAY
)
324 img
->always_display
= true;
326 else if (element
->params_count
== 5)
328 img
->num_subimages
= element
->params
[4].data
.number
;
329 if (img
->num_subimages
<= 0)
330 return WPS_ERROR_INVALID_PARAM
;
333 if (!strcmp(img
->bm
.data
, "__list_icons__"))
335 img
->num_subimages
= Icon_Last_Themeable
;
336 img
->using_preloaded_icons
= true;
339 struct skin_token_list
*item
=
340 (struct skin_token_list
*)new_skin_token_list_item(NULL
, img
);
342 return WPS_ERROR_INVALID_PARAM
;
343 add_to_ll_chain(&wps_data
->images
, item
);
348 int id
; /* the id from font_load */
349 char *name
; /* filename without path and extension */
350 int glyphs
; /* how many glyphs to reserve room for */
352 static struct skin_font skinfonts
[MAXUSERFONTS
];
353 static int parse_font_load(struct skin_element
*element
,
354 struct wps_token
*token
,
355 struct wps_data
*wps_data
)
357 (void)wps_data
; (void)token
;
358 int id
= element
->params
[0].data
.number
;
359 char *filename
= element
->params
[1].data
.text
;
363 if(element
->params_count
> 2)
364 glyphs
= element
->params
[2].data
.number
;
366 glyphs
= GLYPHS_TO_CACHE
;
367 #if defined(DEBUG) || defined(SIMULATOR)
368 if (skinfonts
[id
-FONT_FIRSTUSERFONT
].name
!= NULL
)
370 DEBUGF("font id %d already being used\n", id
);
373 /* make sure the filename contains .fnt,
374 * we dont actually use it, but require it anyway */
375 ptr
= strchr(filename
, '.');
376 if (!ptr
|| strncmp(ptr
, ".fnt", 4))
377 return WPS_ERROR_INVALID_PARAM
;
378 skinfonts
[id
-FONT_FIRSTUSERFONT
].id
= -1;
379 skinfonts
[id
-FONT_FIRSTUSERFONT
].name
= filename
;
380 skinfonts
[id
-FONT_FIRSTUSERFONT
].glyphs
= glyphs
;
386 #ifdef HAVE_LCD_BITMAP
388 static int parse_playlistview(struct skin_element
*element
,
389 struct wps_token
*token
,
390 struct wps_data
*wps_data
)
393 struct playlistviewer
*viewer
=
394 (struct playlistviewer
*)skin_buffer_alloc(sizeof(struct playlistviewer
));
396 return WPS_ERROR_INVALID_PARAM
;
397 viewer
->vp
= &curr_vp
->vp
;
398 viewer
->show_icons
= true;
399 viewer
->start_offset
= element
->params
[0].data
.number
;
400 viewer
->line
= element
->params
[1].data
.code
;
402 token
->value
.data
= (void*)viewer
;
408 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
410 static int parse_viewportcolour(struct skin_element
*element
,
411 struct wps_token
*token
,
412 struct wps_data
*wps_data
)
415 struct skin_tag_parameter
*param
= element
->params
;
416 struct viewport_colour
*colour
=
417 (struct viewport_colour
*)skin_buffer_alloc(sizeof(struct viewport_colour
));
420 if (isdefault(param
))
422 colour
->colour
= get_viewport_default_colour(curr_screen
,
423 token
->type
== SKIN_TOKEN_VIEWPORT_FGCOLOUR
);
427 if (!parse_color(curr_screen
, param
->data
.text
, &colour
->colour
))
430 colour
->vp
= &curr_vp
->vp
;
431 token
->value
.data
= colour
;
432 if (element
->line
== curr_viewport_element
->line
)
434 if (token
->type
== SKIN_TOKEN_VIEWPORT_FGCOLOUR
)
436 curr_vp
->start_fgcolour
= colour
->colour
;
437 curr_vp
->vp
.fg_pattern
= colour
->colour
;
441 curr_vp
->start_bgcolour
= colour
->colour
;
442 curr_vp
->vp
.bg_pattern
= colour
->colour
;
448 static int parse_image_special(struct skin_element
*element
,
449 struct wps_token
*token
,
450 struct wps_data
*wps_data
)
452 (void)wps_data
; /* kill warning */
457 if (token
->type
== SKIN_TOKEN_IMAGE_BACKDROP
)
459 if (isdefault(&element
->params
[0]))
465 filename
= element
->params
[0].data
.text
;
466 /* format: %X(filename.bmp) or %X(d) */
467 if (!strcmp(filename
, "d"))
470 wps_data
->backdrop
= filename
;
478 #endif /* HAVE_LCD_BITMAP */
480 static int parse_setting_and_lang(struct skin_element
*element
,
481 struct wps_token
*token
,
482 struct wps_data
*wps_data
)
484 /* NOTE: both the string validations that happen in here will
485 * automatically PASS on checkwps because its too hard to get
486 * settings_list.c and english.lang built for it.
487 * If that ever changes remove the #ifndef __PCTOOL__'s here
490 char *temp
= element
->params
[0].data
.text
;
493 if (token
->type
== SKIN_TOKEN_TRANSLATEDSTRING
)
496 i
= lang_english_to_id(temp
);
498 return WPS_ERROR_INVALID_PARAM
;
503 /* Find the setting */
504 for (i
=0; i
<nb_settings
; i
++)
505 if (settings
[i
].cfg_name
&&
506 !strcmp(settings
[i
].cfg_name
, temp
))
509 if (i
== nb_settings
)
510 return WPS_ERROR_INVALID_PARAM
;
513 /* Store the setting number */
517 static int parse_logical_if(struct skin_element
*element
,
518 struct wps_token
*token
,
519 struct wps_data
*wps_data
)
522 char *op
= element
->params
[1].data
.text
;
523 struct logical_if
*lif
= skin_buffer_alloc(sizeof(struct logical_if
));
526 token
->value
.data
= lif
;
527 lif
->token
= element
->params
[0].data
.code
->data
;
529 if (!strcmp(op
, "="))
531 if (!strcmp(op
, "!="))
532 lif
->op
= IF_NOTEQUALS
;
533 if (!strcmp(op
, "<"))
534 lif
->op
= IF_LESSTHAN
;
535 if (!strcmp(op
, "<="))
536 lif
->op
= IF_LESSTHAN_EQ
;
537 if (!strcmp(op
, ">"))
538 lif
->op
= IF_GREATERTHAN
;
539 if (!strcmp(op
, ">="))
540 lif
->op
= IF_GREATERTHAN_EQ
;
542 memcpy(&lif
->operand
, &element
->params
[2], sizeof(lif
->operand
));
543 if (element
->params_count
> 3)
544 lif
->num_options
= element
->params
[3].data
.number
;
546 lif
->num_options
= TOKEN_VALUE_ONLY
;
550 static int parse_timeout_tag(struct skin_element
*element
,
551 struct wps_token
*token
,
552 struct wps_data
*wps_data
)
556 if (element
->params_count
== 0)
560 case SKIN_TOKEN_SUBLINE_TIMEOUT
:
562 case SKIN_TOKEN_BUTTON_VOLUME
:
563 case SKIN_TOKEN_TRACK_STARTING
:
564 case SKIN_TOKEN_TRACK_ENDING
:
565 case SKIN_TOKEN_LASTTOUCH
:
573 val
= element
->params
[0].data
.number
;
574 token
->value
.i
= val
* TIMEOUT_UNIT
;
578 static int parse_progressbar_tag(struct skin_element
* element
,
579 struct wps_token
*token
,
580 struct wps_data
*wps_data
)
582 #ifdef HAVE_LCD_BITMAP
583 struct progressbar
*pb
;
584 struct viewport
*vp
= &curr_vp
->vp
;
585 struct skin_tag_parameter
*param
= element
->params
;
587 char *image_filename
= NULL
;
589 if (element
->params_count
== 0 &&
590 element
->tag
->type
!= SKIN_TOKEN_PROGRESSBAR
)
591 return 0; /* nothing to do */
592 pb
= (struct progressbar
*)skin_buffer_alloc(sizeof(struct progressbar
));
594 token
->value
.data
= pb
;
597 return WPS_ERROR_INVALID_PARAM
;
599 pb
->follow_lang_direction
= follow_lang_direction
> 0;
604 pb
->invert_fill_direction
= false;
605 pb
->horizontal
= true;
607 if (element
->params_count
== 0)
610 pb
->width
= vp
->width
;
611 pb
->height
= SYSFONT_HEIGHT
-2;
612 pb
->y
= -1; /* Will be computed during the rendering */
613 pb
->type
= element
->tag
->type
;
617 /* (x, y, width, height, ...) */
618 if (!isdefault(param
))
619 pb
->x
= param
->data
.number
;
624 if (!isdefault(param
))
625 pb
->y
= param
->data
.number
;
627 pb
->y
= -1; /* computed at rendering */
630 if (!isdefault(param
))
631 pb
->width
= param
->data
.number
;
633 pb
->width
= vp
->width
- pb
->x
;
636 if (!isdefault(param
))
638 /* A zero height makes no sense - reject it */
639 if (param
->data
.number
== 0)
640 return WPS_ERROR_INVALID_PARAM
;
642 pb
->height
= param
->data
.number
;
646 if (vp
->font
> FONT_UI
)
647 pb
->height
= -1; /* calculate at display time */
651 pb
->height
= font_get(vp
->font
)->height
;
657 /* optional params, first is the image filename if it isnt recognised as a keyword */
660 if (isdefault(&element
->params
[curr_param
]))
666 pb
->horizontal
= pb
->width
> pb
->height
;
667 while (curr_param
< element
->params_count
)
670 if (!strcmp(param
->data
.text
, "invert"))
671 pb
->invert_fill_direction
= true;
672 else if (!strcmp(param
->data
.text
, "nofill"))
674 else if (!strcmp(param
->data
.text
, "nobar"))
676 else if (!strcmp(param
->data
.text
, "slider"))
678 if (curr_param
+1 < element
->params_count
)
682 pb
->slider
= find_image(param
->data
.text
, wps_data
);
684 else /* option needs the next param */
687 else if (!strcmp(param
->data
.text
, "image"))
689 if (curr_param
+1 < element
->params_count
)
693 image_filename
= param
->data
.text
;
696 else /* option needs the next param */
699 else if (!strcmp(param
->data
.text
, "vertical"))
701 pb
->horizontal
= false;
702 if (isdefault(&element
->params
[3]))
703 pb
->height
= vp
->height
- pb
->y
;
705 else if (!strcmp(param
->data
.text
, "horizontal"))
706 pb
->horizontal
= true;
707 else if (curr_param
== 4)
708 image_filename
= param
->data
.text
;
715 pb
->image
= find_image(image_filename
, wps_data
);
716 if (!pb
->image
) /* load later */
718 struct gui_img
* img
= (struct gui_img
*)skin_buffer_alloc(sizeof(struct gui_img
));
720 return WPS_ERROR_INVALID_PARAM
;
721 /* save a pointer to the filename */
722 img
->bm
.data
= (char*)image_filename
;
723 img
->label
= image_filename
;
726 img
->num_subimages
= 1;
727 img
->always_display
= false;
729 img
->using_preloaded_icons
= false;
730 img
->vp
= &curr_vp
->vp
;
731 struct skin_token_list
*item
=
732 (struct skin_token_list
*)new_skin_token_list_item(NULL
, img
);
734 return WPS_ERROR_INVALID_PARAM
;
735 add_to_ll_chain(&wps_data
->images
, item
);
741 if (token
->type
== SKIN_TOKEN_VOLUME
)
742 token
->type
= SKIN_TOKEN_VOLUMEBAR
;
743 else if (token
->type
== SKIN_TOKEN_BATTERY_PERCENT
)
744 token
->type
= SKIN_TOKEN_BATTERY_PERCENTBAR
;
745 pb
->type
= token
->type
;
751 if (token
->type
== SKIN_TOKEN_PROGRESSBAR
||
752 token
->type
== SKIN_TOKEN_PLAYER_PROGRESSBAR
)
754 wps_data
->full_line_progressbar
=
755 token
->type
== SKIN_TOKEN_PLAYER_PROGRESSBAR
;
763 static int parse_albumart_load(struct skin_element
* element
,
764 struct wps_token
*token
,
765 struct wps_data
*wps_data
)
767 struct dim dimensions
;
769 bool swap_for_rtl
= lang_is_rtl() && follow_lang_direction
;
770 struct skin_albumart
*aa
=
771 (struct skin_albumart
*)skin_buffer_alloc(sizeof(struct skin_albumart
));
772 (void)token
; /* silence warning */
776 /* reset albumart info in wps */
779 aa
->xalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
780 aa
->yalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
782 aa
->x
= element
->params
[0].data
.number
;
783 aa
->y
= element
->params
[1].data
.number
;
784 aa
->width
= element
->params
[2].data
.number
;
785 aa
->height
= element
->params
[3].data
.number
;
787 aa
->vp
= &curr_vp
->vp
;
788 aa
->draw_handle
= -1;
790 /* if we got here, we parsed everything ok .. ! */
793 else if (aa
->width
> LCD_WIDTH
)
794 aa
->width
= LCD_WIDTH
;
798 else if (aa
->height
> LCD_HEIGHT
)
799 aa
->height
= LCD_HEIGHT
;
802 aa
->x
= LCD_WIDTH
- (aa
->x
+ aa
->width
);
804 aa
->state
= WPS_ALBUMART_LOAD
;
805 wps_data
->albumart
= aa
;
807 dimensions
.width
= aa
->width
;
808 dimensions
.height
= aa
->height
;
810 albumart_slot
= playback_claim_aa_slot(&dimensions
);
812 if (0 <= albumart_slot
)
813 wps_data
->playback_aa_slot
= albumart_slot
;
815 if (element
->params_count
> 4 && !isdefault(&element
->params
[4]))
817 switch (*element
->params
[4].data
.text
)
822 aa
->xalign
= WPS_ALBUMART_ALIGN_RIGHT
;
824 aa
->xalign
= WPS_ALBUMART_ALIGN_LEFT
;
828 aa
->xalign
= WPS_ALBUMART_ALIGN_CENTER
;
833 aa
->xalign
= WPS_ALBUMART_ALIGN_LEFT
;
835 aa
->xalign
= WPS_ALBUMART_ALIGN_RIGHT
;
839 if (element
->params_count
> 5 && !isdefault(&element
->params
[5]))
841 switch (*element
->params
[5].data
.text
)
845 aa
->yalign
= WPS_ALBUMART_ALIGN_TOP
;
849 aa
->yalign
= WPS_ALBUMART_ALIGN_CENTER
;
853 aa
->yalign
= WPS_ALBUMART_ALIGN_BOTTOM
;
860 #endif /* HAVE_ALBUMART */
862 #ifdef HAVE_TOUCHSCREEN
864 struct touchaction
{const char* s
; int action
;};
865 static const struct touchaction touchactions
[] = {
866 /* generic actions, convert to screen actions on use */
867 {"prev", ACTION_STD_PREV
}, {"next", ACTION_STD_NEXT
},
868 {"rwd", ACTION_STD_PREVREPEAT
}, {"ffwd", ACTION_STD_NEXTREPEAT
},
869 {"hotkey", ACTION_STD_HOTKEY
}, {"select", ACTION_STD_OK
},
870 {"menu", ACTION_STD_MENU
}, {"cancel", ACTION_STD_CANCEL
},
871 {"contextmenu", ACTION_STD_CONTEXT
},{"quickscreen", ACTION_STD_QUICKSCREEN
},
873 /* list/tree actions */
874 { "resumeplayback", ACTION_TREE_WPS
}, /* returns to previous music, WPS/FM */
875 /* not really WPS specific, but no equivilant ACTION_STD_* */
876 {"voldown", ACTION_WPS_VOLDOWN
}, {"volup", ACTION_WPS_VOLUP
},
878 /* generic settings changers */
879 {"setting_inc", ACTION_SETTINGS_INC
}, {"setting_dec", ACTION_SETTINGS_DEC
},
881 /* WPS specific actions */
882 {"browse", ACTION_WPS_BROWSE
},
883 {"play", ACTION_WPS_PLAY
}, {"stop", ACTION_WPS_STOP
},
884 {"shuffle", ACTION_TOUCH_SHUFFLE
}, {"repmode", ACTION_TOUCH_REPMODE
},
885 {"pitch", ACTION_WPS_PITCHSCREEN
}, {"playlist", ACTION_WPS_VIEW_PLAYLIST
},
888 /* FM screen actions */
889 /* Also allow browse, play, stop from WPS codes */
890 {"mode", ACTION_FM_MODE
}, {"record", ACTION_FM_RECORD
},
891 {"presets", ACTION_FM_PRESET
},
895 static int parse_touchregion(struct skin_element
*element
,
896 struct wps_token
*token
,
897 struct wps_data
*wps_data
)
901 struct touchregion
*region
= NULL
;
903 const char pb_string
[] = "progressbar";
904 const char vol_string
[] = "volume";
907 /* format: %T(x,y,width,height,action)
908 * if action starts with & the area must be held to happen
910 * play - play/pause playback
911 * stop - stop playback, exit the wps
914 * ffwd - seek forward
915 * rwd - seek backwards
916 * menu - go back to the main menu
917 * browse - go back to the file/db browser
918 * shuffle - toggle shuffle mode
919 * repmode - cycle the repeat mode
920 * quickscreen - go into the quickscreen
921 * contextmenu - open the context menu
922 * playlist - go into the playlist
923 * pitch - go into the pitchscreen
924 * volup - increase volume by one step
925 * voldown - decrease volume by one step
929 region
= (struct touchregion
*)skin_buffer_alloc(sizeof(struct touchregion
));
931 return WPS_ERROR_INVALID_PARAM
;
933 /* should probably do some bounds checking here with the viewport... but later */
934 region
->action
= ACTION_NONE
;
935 region
->x
= element
->params
[0].data
.number
;
936 region
->y
= element
->params
[1].data
.number
;
937 region
->width
= element
->params
[2].data
.number
;
938 region
->height
= element
->params
[3].data
.number
;
939 region
->wvp
= curr_vp
;
940 region
->armed
= false;
941 region
->reverse_bar
= false;
942 region
->extradata
= NULL
;
943 action
= element
->params
[4].data
.text
;
945 strcpy(temp
, action
);
950 region
->reverse_bar
= true;
954 if(!strcmp(pb_string
, action
))
955 region
->type
= WPS_TOUCHREGION_SCROLLBAR
;
956 else if(!strcmp(vol_string
, action
))
957 region
->type
= WPS_TOUCHREGION_VOLUME
;
960 region
->type
= WPS_TOUCHREGION_ACTION
;
965 region
->repeat
= true;
968 region
->repeat
= false;
970 imax
= ARRAYLEN(touchactions
);
971 for (i
= 0; i
< imax
; i
++)
973 /* try to match with one of our touchregion screens */
974 if (!strcmp(touchactions
[i
].s
, action
))
976 region
->action
= touchactions
[i
].action
;
977 if (region
->action
== ACTION_SETTINGS_INC
||
978 region
->action
== ACTION_SETTINGS_DEC
)
980 if (element
->params_count
< 6)
982 return WPS_ERROR_INVALID_PARAM
;
986 char *name
= element
->params
[5].data
.text
;
988 /* Find the setting */
989 for (j
=0; j
<nb_settings
; j
++)
990 if (settings
[j
].cfg_name
&&
991 !strcmp(settings
[j
].cfg_name
, name
))
994 return WPS_ERROR_INVALID_PARAM
;
995 region
->extradata
= (void*)&settings
[j
];
1001 if (region
->action
== ACTION_NONE
)
1002 return WPS_ERROR_INVALID_PARAM
;
1004 struct skin_token_list
*item
= new_skin_token_list_item(NULL
, region
);
1006 return WPS_ERROR_INVALID_PARAM
;
1007 add_to_ll_chain(&wps_data
->touchregions
, item
);
1012 static bool check_feature_tag(const int type
)
1016 case SKIN_TOKEN_RTC_PRESENT
:
1022 case SKIN_TOKEN_HAVE_RECORDING
:
1023 #ifdef HAVE_RECORDING
1028 case SKIN_TOKEN_HAVE_TUNER
:
1030 if (radio_hardware_present())
1034 case SKIN_TOKEN_HAVE_TOUCH
:
1035 #ifdef HAVE_TOUCHSCREEN
1042 case SKIN_TOKEN_HAVE_RDS
:
1047 #endif /* HAVE_RDS_CAP */
1048 #endif /* CONFIG_TUNER */
1049 default: /* not a tag we care about, just don't skip */
1055 * initial setup of wps_data; does reset everything
1056 * except fields which need to survive, i.e.
1059 static void skin_data_reset(struct wps_data
*wps_data
)
1061 wps_data
->tree
= NULL
;
1062 #ifdef HAVE_LCD_BITMAP
1063 wps_data
->images
= NULL
;
1065 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1066 if (wps_data
->backdrop_id
>= 0)
1067 skin_backdrop_unload(wps_data
->backdrop_id
);
1068 wps_data
->backdrop
= NULL
;
1070 #ifdef HAVE_TOUCHSCREEN
1071 wps_data
->touchregions
= NULL
;
1073 #ifdef HAVE_ALBUMART
1074 wps_data
->albumart
= NULL
;
1075 if (wps_data
->playback_aa_slot
>= 0)
1077 playback_release_aa_slot(wps_data
->playback_aa_slot
);
1078 wps_data
->playback_aa_slot
= -1;
1082 #ifdef HAVE_LCD_BITMAP
1083 wps_data
->peak_meter_enabled
= false;
1084 wps_data
->wps_sb_tag
= false;
1085 wps_data
->show_sb_on_wps
= false;
1086 #else /* HAVE_LCD_CHARCELLS */
1089 for (i
= 0; i
< 8; i
++)
1091 wps_data
->wps_progress_pat
[i
] = 0;
1093 wps_data
->full_line_progressbar
= false;
1095 wps_data
->wps_loaded
= false;
1098 #ifdef HAVE_LCD_BITMAP
1099 static bool load_skin_bmp(struct wps_data
*wps_data
, struct bitmap
*bitmap
, char* bmpdir
)
1101 (void)wps_data
; /* only needed for remote targets */
1102 char img_path
[MAX_PATH
];
1104 get_image_filename(bitmap
->data
, bmpdir
,
1105 img_path
, sizeof(img_path
));
1107 /* load the image */
1109 #ifdef HAVE_REMOTE_LCD
1110 if (curr_screen
== SCREEN_REMOTE
)
1111 format
= FORMAT_ANY
|FORMAT_REMOTE
;
1114 format
= FORMAT_ANY
|FORMAT_TRANSPARENT
;
1116 fd
= open(img_path
, O_RDONLY
);
1119 size_t buf_size
= read_bmp_fd(fd
, bitmap
, 0,
1120 format
|FORMAT_RETURN_SIZE
, NULL
);
1121 char* imgbuf
= (char*)skin_buffer_alloc(buf_size
);
1127 lseek(fd
, 0, SEEK_SET
);
1128 bitmap
->data
= imgbuf
;
1129 int ret
= read_bmp_fd(fd
, bitmap
, buf_size
, format
, NULL
);
1138 /* Abort if we can't load an image */
1139 DEBUGF("Couldn't load '%s'\n", img_path
);
1144 static bool load_skin_bitmaps(struct wps_data
*wps_data
, char *bmpdir
)
1146 struct skin_token_list
*list
;
1147 bool retval
= true; /* return false if a single image failed to load */
1149 /* regular images */
1150 list
= wps_data
->images
;
1153 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
1156 if (img
->using_preloaded_icons
)
1159 list
->token
->type
= SKIN_TOKEN_IMAGE_DISPLAY_LISTICON
;
1163 img
->loaded
= load_skin_bmp(wps_data
, &img
->bm
, bmpdir
);
1165 img
->subimage_height
= img
->bm
.height
/ img
->num_subimages
;
1173 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1174 wps_data
->backdrop_id
= skin_backdrop_assign(wps_data
->backdrop
, bmpdir
, curr_screen
);
1175 #endif /* has backdrop support */
1179 static bool skin_load_fonts(struct wps_data
*data
)
1181 /* don't spit out after the first failue to aid debugging */
1182 bool success
= true;
1183 struct skin_element
*vp_list
;
1185 /* walk though each viewport and assign its font */
1186 for(vp_list
= data
->tree
; vp_list
; vp_list
= vp_list
->next
)
1188 /* first, find the viewports that have a non-sys/ui-font font */
1189 struct skin_viewport
*skin_vp
=
1190 (struct skin_viewport
*)vp_list
->data
;
1191 struct viewport
*vp
= &skin_vp
->vp
;
1194 if (vp
->font
<= FONT_UI
)
1195 { /* the usual case -> built-in fonts */
1196 #ifdef HAVE_REMOTE_LCD
1197 if (vp
->font
== FONT_UI
)
1198 vp
->font
+= curr_screen
;
1204 /* now find the corresponding skin_font */
1205 struct skin_font
*font
= &skinfonts
[font_id
-FONT_FIRSTUSERFONT
];
1210 DEBUGF("font %d not specified\n", font_id
);
1216 /* load the font - will handle loading the same font again if
1217 * multiple viewports use the same */
1220 char *dot
= strchr(font
->name
, '.');
1222 font
->id
= skin_font_load(font
->name
,
1223 skinfonts
[font_id
-FONT_FIRSTUSERFONT
].glyphs
);
1228 DEBUGF("Unable to load font %d: '%s.fnt'\n",
1229 font_id
, font
->name
);
1230 font
->name
= NULL
; /* to stop trying to load it again if we fail */
1236 /* finally, assign the font_id to the viewport */
1237 vp
->font
= font
->id
;
1242 #endif /* HAVE_LCD_BITMAP */
1243 static int convert_viewport(struct wps_data
*data
, struct skin_element
* element
)
1245 struct skin_viewport
*skin_vp
=
1246 (struct skin_viewport
*)skin_buffer_alloc(sizeof(struct skin_viewport
));
1247 struct screen
*display
= &screens
[curr_screen
];
1250 return CALLBACK_ERROR
;
1252 skin_vp
->hidden_flags
= 0;
1253 skin_vp
->label
= NULL
;
1254 skin_vp
->is_infovp
= false;
1255 element
->data
= skin_vp
;
1257 curr_viewport_element
= element
;
1259 viewport_set_defaults(&skin_vp
->vp
, curr_screen
);
1260 #ifdef HAVE_REMOTE_LCD
1261 /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
1262 * This parser requires font 1 to always be the UI font,
1263 * so force it back to FONT_UI and handle the screen number at the end */
1264 skin_vp
->vp
.font
= FONT_UI
;
1267 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1268 skin_vp
->start_fgcolour
= skin_vp
->vp
.fg_pattern
;
1269 skin_vp
->start_bgcolour
= skin_vp
->vp
.bg_pattern
;
1273 struct skin_tag_parameter
*param
= element
->params
;
1274 if (element
->params_count
== 0) /* default viewport */
1276 if (!data
->tree
) /* first viewport in the skin */
1277 data
->tree
= element
;
1278 skin_vp
->label
= VP_DEFAULT_LABEL
;
1282 if (element
->params_count
== 6)
1284 if (element
->tag
->type
== SKIN_TOKEN_UIVIEWPORT_LOAD
)
1286 skin_vp
->is_infovp
= true;
1287 if (isdefault(param
))
1289 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1290 skin_vp
->label
= VP_DEFAULT_LABEL
;
1294 skin_vp
->hidden_flags
= VP_NEVER_VISIBLE
;
1295 skin_vp
->label
= param
->data
.text
;
1300 skin_vp
->hidden_flags
= VP_DRAW_HIDEABLE
|VP_DRAW_HIDDEN
;
1301 skin_vp
->label
= param
->data
.text
;
1306 if (!isdefault(param
))
1308 skin_vp
->vp
.x
= param
->data
.number
;
1309 if (param
->data
.number
< 0)
1310 skin_vp
->vp
.x
+= display
->lcdwidth
;
1314 if (!isdefault(param
))
1316 skin_vp
->vp
.y
= param
->data
.number
;
1317 if (param
->data
.number
< 0)
1318 skin_vp
->vp
.y
+= display
->lcdheight
;
1322 if (!isdefault(param
))
1324 skin_vp
->vp
.width
= param
->data
.number
;
1325 if (param
->data
.number
< 0)
1326 skin_vp
->vp
.width
= (skin_vp
->vp
.width
+ display
->lcdwidth
) - skin_vp
->vp
.x
;
1330 skin_vp
->vp
.width
= display
->lcdwidth
- skin_vp
->vp
.x
;
1334 if (!isdefault(param
))
1336 skin_vp
->vp
.height
= param
->data
.number
;
1337 if (param
->data
.number
< 0)
1338 skin_vp
->vp
.height
= (skin_vp
->vp
.height
+ display
->lcdheight
) - skin_vp
->vp
.y
;
1342 skin_vp
->vp
.height
= display
->lcdheight
- skin_vp
->vp
.y
;
1345 #ifdef HAVE_LCD_BITMAP
1347 if (!isdefault(param
))
1349 skin_vp
->vp
.font
= param
->data
.number
;
1352 if ((unsigned) skin_vp
->vp
.x
>= (unsigned) display
->lcdwidth
||
1353 skin_vp
->vp
.width
+ skin_vp
->vp
.x
> display
->lcdwidth
||
1354 (unsigned) skin_vp
->vp
.y
>= (unsigned) display
->lcdheight
||
1355 skin_vp
->vp
.height
+ skin_vp
->vp
.y
> display
->lcdheight
)
1356 return CALLBACK_ERROR
;
1361 static int skin_element_callback(struct skin_element
* element
, void* data
)
1363 struct wps_data
*wps_data
= (struct wps_data
*)data
;
1364 struct wps_token
*token
;
1365 parse_function function
= NULL
;
1367 switch (element
->type
)
1369 /* IMPORTANT: element params are shared, so copy them if needed
1370 * or use then NOW, dont presume they have a long lifespan
1374 token
= (struct wps_token
*)skin_buffer_alloc(sizeof(struct wps_token
));
1375 memset(token
, 0, sizeof(*token
));
1376 token
->type
= element
->tag
->type
;
1378 if (element
->tag
->flags
&SKIN_RTC_REFRESH
)
1381 curr_line
->update_mode
|= SKIN_REFRESH_DYNAMIC
;
1383 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1387 curr_line
->update_mode
|= element
->tag
->flags
&SKIN_REFRESH_ALL
;
1389 element
->data
= token
;
1391 /* Some tags need special handling for the tag, so add them here */
1392 switch (token
->type
)
1394 case SKIN_TOKEN_ALIGN_LANGDIRECTION
:
1395 follow_lang_direction
= 2;
1397 case SKIN_TOKEN_LOGICAL_IF
:
1398 function
= parse_logical_if
;
1400 case SKIN_TOKEN_PROGRESSBAR
:
1401 case SKIN_TOKEN_VOLUME
:
1402 case SKIN_TOKEN_BATTERY_PERCENT
:
1403 case SKIN_TOKEN_PLAYER_PROGRESSBAR
:
1404 function
= parse_progressbar_tag
;
1406 case SKIN_TOKEN_SUBLINE_TIMEOUT
:
1407 case SKIN_TOKEN_BUTTON_VOLUME
:
1408 case SKIN_TOKEN_TRACK_STARTING
:
1409 case SKIN_TOKEN_TRACK_ENDING
:
1410 case SKIN_TOKEN_LASTTOUCH
:
1411 function
= parse_timeout_tag
;
1413 #ifdef HAVE_LCD_BITMAP
1414 case SKIN_TOKEN_DISABLE_THEME
:
1415 case SKIN_TOKEN_ENABLE_THEME
:
1416 case SKIN_TOKEN_DRAW_INBUILTBAR
:
1417 function
= parse_statusbar_tags
;
1419 case SKIN_TOKEN_LIST_TITLE_TEXT
:
1421 sb_skin_has_title(curr_screen
);
1425 case SKIN_TOKEN_FILE_DIRECTORY
:
1426 token
->value
.i
= element
->params
[0].data
.number
;
1428 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1429 case SKIN_TOKEN_VIEWPORT_FGCOLOUR
:
1430 case SKIN_TOKEN_VIEWPORT_BGCOLOUR
:
1431 function
= parse_viewportcolour
;
1433 case SKIN_TOKEN_IMAGE_BACKDROP
:
1434 function
= parse_image_special
;
1437 case SKIN_TOKEN_TRANSLATEDSTRING
:
1438 case SKIN_TOKEN_SETTING
:
1439 function
= parse_setting_and_lang
;
1441 #ifdef HAVE_LCD_BITMAP
1442 case SKIN_TOKEN_VIEWPORT_CUSTOMLIST
:
1443 function
= parse_playlistview
;
1445 case SKIN_TOKEN_LOAD_FONT
:
1446 function
= parse_font_load
;
1448 case SKIN_TOKEN_VIEWPORT_ENABLE
:
1449 case SKIN_TOKEN_UIVIEWPORT_ENABLE
:
1450 token
->value
.data
= element
->params
[0].data
.text
;
1452 case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY
:
1453 function
= parse_image_display
;
1455 case SKIN_TOKEN_IMAGE_PRELOAD
:
1456 case SKIN_TOKEN_IMAGE_DISPLAY
:
1457 function
= parse_image_load
;
1460 #ifdef HAVE_TOUCHSCREEN
1461 case SKIN_TOKEN_TOUCHREGION
:
1462 function
= parse_touchregion
;
1465 #ifdef HAVE_ALBUMART
1466 case SKIN_TOKEN_ALBUMART_DISPLAY
:
1467 if (wps_data
->albumart
)
1468 wps_data
->albumart
->vp
= &curr_vp
->vp
;
1470 case SKIN_TOKEN_ALBUMART_LOAD
:
1471 function
= parse_albumart_load
;
1479 if (function(element
, token
, wps_data
) < 0)
1480 return CALLBACK_ERROR
;
1482 /* tags that start with 'F', 'I' or 'D' are for the next file */
1483 if ( *(element
->tag
->name
) == 'I' || *(element
->tag
->name
) == 'F' ||
1484 *(element
->tag
->name
) == 'D')
1486 if (follow_lang_direction
> 0 )
1487 follow_lang_direction
--;
1491 return convert_viewport(wps_data
, element
);
1495 (struct line
*)skin_buffer_alloc(sizeof(struct line
));
1496 line
->update_mode
= SKIN_REFRESH_STATIC
;
1498 element
->data
= line
;
1501 case LINE_ALTERNATOR
:
1503 struct line_alternator
*alternator
=
1504 (struct line_alternator
*)skin_buffer_alloc(sizeof(struct line_alternator
));
1505 alternator
->current_line
= 0;
1507 alternator
->next_change_tick
= current_tick
;
1509 element
->data
= alternator
;
1514 struct conditional
*conditional
=
1515 (struct conditional
*)skin_buffer_alloc(sizeof(struct conditional
));
1516 conditional
->last_value
= -1;
1517 conditional
->token
= element
->data
;
1518 element
->data
= conditional
;
1519 if (!check_feature_tag(element
->tag
->type
))
1521 return FEATURE_NOT_AVAILABLE
;
1526 curr_line
->update_mode
|= SKIN_REFRESH_STATIC
;
1534 /* to setup up the wps-data from a format-buffer (isfile = false)
1535 from a (wps-)file (isfile = true)*/
1536 bool skin_data_load(enum screen_type screen
, struct wps_data
*wps_data
,
1537 const char *buf
, bool isfile
)
1539 char *wps_buffer
= NULL
;
1540 if (!wps_data
|| !buf
)
1542 #ifdef HAVE_ALBUMART
1544 struct mp3entry
*curtrack
;
1546 struct skin_albumart old_aa
= {.state
= WPS_ALBUMART_NONE
};
1547 if (wps_data
->albumart
)
1549 old_aa
.state
= wps_data
->albumart
->state
;
1550 old_aa
.height
= wps_data
->albumart
->height
;
1551 old_aa
.width
= wps_data
->albumart
->width
;
1554 #ifdef HAVE_LCD_BITMAP
1556 for (i
=0;i
<MAXUSERFONTS
;i
++)
1558 skinfonts
[i
].id
= -1;
1559 skinfonts
[i
].name
= NULL
;
1562 #ifdef DEBUG_SKIN_ENGINE
1563 if (isfile
&& debug_wps
)
1565 DEBUGF("\n=====================\nLoading '%s'\n=====================\n", buf
);
1570 skin_data_reset(wps_data
);
1571 wps_data
->wps_loaded
= false;
1572 curr_screen
= screen
;
1575 curr_viewport_element
= NULL
;
1579 int fd
= open_utf8(buf
, O_RDONLY
);
1584 /* get buffer space from the plugin buffer */
1585 size_t buffersize
= 0;
1586 wps_buffer
= (char *)plugin_get_buffer(&buffersize
);
1591 /* copy the file's content to the buffer for parsing,
1592 ensuring that every line ends with a newline char. */
1593 unsigned int start
= 0;
1594 while(read_line(fd
, wps_buffer
+ start
, buffersize
- start
) > 0)
1596 start
+= strlen(wps_buffer
+ start
);
1597 if (start
< buffersize
- 1)
1599 wps_buffer
[start
++] = '\n';
1600 wps_buffer
[start
] = 0;
1609 wps_buffer
= (char*)buf
;
1611 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1612 wps_data
->backdrop
= "-";
1613 wps_data
->backdrop_id
= -1;
1615 /* parse the skin source */
1617 skin_buffer_save_position();
1619 wps_data
->tree
= skin_parse(wps_buffer
, skin_element_callback
, wps_data
);
1620 if (!wps_data
->tree
) {
1621 skin_data_reset(wps_data
);
1623 skin_buffer_restore_position();
1628 #ifdef HAVE_LCD_BITMAP
1629 char bmpdir
[MAX_PATH
];
1632 /* get the bitmap dir */
1633 char *dot
= strrchr(buf
, '.');
1634 strlcpy(bmpdir
, buf
, dot
- buf
+ 1);
1637 { /* fall back to backdrop dir for built-in themes */
1638 /* no get_user_file_path(), assuming we ship bmps for built-in themes */
1639 snprintf(bmpdir
, MAX_PATH
, "%s", BACKDROP_DIR
);
1641 /* load the bitmaps that were found by the parsing */
1642 if (!load_skin_bitmaps(wps_data
, bmpdir
) ||
1643 !skin_load_fonts(wps_data
))
1645 skin_data_reset(wps_data
);
1647 skin_buffer_restore_position();
1652 #if defined(HAVE_ALBUMART) && !defined(__PCTOOL__)
1653 status
= audio_status();
1654 if (status
& AUDIO_STATUS_PLAY
)
1656 struct skin_albumart
*aa
= wps_data
->albumart
;
1657 if (aa
&& ((aa
->state
&& !old_aa
.state
) ||
1659 (((old_aa
.height
!= aa
->height
) ||
1660 (old_aa
.width
!= aa
->width
))))))
1662 curtrack
= audio_current_track();
1663 offset
= curtrack
->offset
;
1665 if (!(status
& AUDIO_STATUS_PAUSE
))
1670 wps_data
->wps_loaded
= true;
1671 #ifdef DEBUG_SKIN_ENGINE
1672 // if (isfile && debug_wps)
1673 // debug_skin_usage();