Fix the mechanism to fail to parse skins if images fail to load and fix having no...
[kugel-rb.git] / apps / gui / statusbar-skinned.c
blobf5458fb252303c6f40e9d500187a16b840cabd96
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
24 #include "system.h"
25 #include "settings.h"
26 #include "appevents.h"
27 #include "screens.h"
28 #include "screen_access.h"
29 #include "skin_engine/skin_engine.h"
30 #include "skin_engine/wps_internals.h"
31 #include "viewport.h"
32 #include "statusbar.h"
33 #include "statusbar-skinned.h"
34 #include "debug.h"
35 #include "font.h"
38 /* currently only one wps_state is needed */
39 extern struct wps_state wps_state; /* from wps.c */
40 static struct gui_wps sb_skin[NB_SCREENS] = {{ .data = NULL }};
41 static struct wps_data sb_skin_data[NB_SCREENS] = {{ .wps_loaded = 0 }};
42 static struct wps_sync_data sb_skin_sync_data = { .do_full_update = false };
44 /* initial setup of wps_data */
45 static int update_delay = DEFAULT_UPDATE_DELAY;
48 void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile)
50 struct wps_data *data = sb_skin[screen].data;
52 int success;
53 success = buf && skin_data_load(screen, data, buf, isfile);
55 if (success)
56 { /* hide the sb's default viewport because it has nasty effect with stuff
57 * not part of the statusbar,
58 * hence .sbs's without any other vps are unsupported*/
59 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, data);
60 struct skin_token_list *next_vp = data->viewports->next;
62 if (!next_vp)
63 { /* no second viewport, let parsing fail */
64 success = false;
66 /* hide this viewport, forever */
67 vp->hidden_flags = VP_NEVER_VISIBLE;
70 if (!success && isfile)
71 sb_create_from_settings(screen);
74 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
76 return &find_viewport(VP_INFO_LABEL, sb_skin[screen].data)->vp;
79 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
80 char* sb_get_backdrop(enum screen_type screen)
82 return sb_skin[screen].data->backdrop;
85 bool sb_set_backdrop(enum screen_type screen, char* filename)
87 if (!filename)
89 sb_skin[screen].data->backdrop = NULL;
90 return true;
92 else if (!sb_skin[screen].data->backdrop)
94 /* need to make room on the buffer */
95 size_t buf_size;
96 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
97 if (screen == SCREEN_REMOTE)
98 buf_size = REMOTE_LCD_BACKDROP_BYTES;
99 else
100 #endif
101 buf_size = LCD_BACKDROP_BYTES;
102 sb_skin[screen].data->backdrop = skin_buffer_alloc(buf_size);
103 if (!sb_skin[screen].data->backdrop)
104 return false;
107 if (!screens[screen].backdrop_load(filename, sb_skin[screen].data->backdrop))
108 sb_skin[screen].data->backdrop = NULL;
109 return sb_skin[screen].data->backdrop != NULL;
112 #endif
113 void sb_skin_update(enum screen_type screen, bool force)
115 static long next_update = 0;
116 int i = screen;
117 if (TIME_AFTER(current_tick, next_update) || force)
119 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
120 /* currently, all remotes are readable without backlight
121 * so still update those */
122 if (lcd_active() || (i != SCREEN_MAIN))
123 #endif
124 skin_update(&sb_skin[i], force?
125 WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC);
126 next_update = current_tick + update_delay; /* don't update too often */
127 sb_skin[SCREEN_MAIN].sync_data->do_full_update = false;
131 void do_sbs_update_callback(void *param)
133 (void)param;
134 /* the WPS handles changing the actual id3 data in the id3 pointers
135 * we imported, we just want a full update */
136 sb_skin_sync_data.do_full_update = true;
137 /* force timeout in wps main loop, so that the update is instantly */
138 queue_post(&button_queue, BUTTON_NONE, 0);
141 void sb_skin_set_update_delay(int delay)
143 update_delay = delay;
146 /* This creates and loads a ".sbs" based on the user settings for:
147 * - regular statusbar
148 * - colours
149 * - ui viewport
150 * - backdrop
152 void sb_create_from_settings(enum screen_type screen)
154 char buf[128], *ptr, *ptr2;
155 int len, remaining = sizeof(buf);
157 ptr = buf;
158 ptr[0] = '\0';
160 /* %Vi viewport, colours handled by the parser */
161 #if NB_SCREENS > 1
162 if (screen == SCREEN_REMOTE)
163 ptr2 = global_settings.remote_ui_vp_config;
164 else
165 #endif
166 ptr2 = global_settings.ui_vp_config;
168 if (ptr2[0] && ptr2[0] != '-') /* from ui viewport setting */
170 len = snprintf(ptr, remaining, "%%ax%%Vi|%s|\n", ptr2);
171 while ((ptr2 = strchr(ptr, ',')))
172 *ptr2 = '|';
174 else
176 int y = 0, height;
177 switch (statusbar_position(screen))
179 case STATUSBAR_TOP:
180 y = STATUSBAR_HEIGHT;
181 case STATUSBAR_BOTTOM:
182 height = screens[screen].lcdheight - STATUSBAR_HEIGHT;
183 break;
184 default:
185 height = screens[screen].lcdheight;
187 len = snprintf(ptr, remaining, "%%ax%%Vi|0|%d|-|%d|1|-|-|\n",
188 y, height);
190 sb_skin_data_load(screen, buf, false);
193 void sb_skin_init(void)
195 int i;
196 FOR_NB_SCREENS(i)
198 #ifdef HAVE_ALBUMART
199 sb_skin_data[i].albumart = NULL;
200 sb_skin_data[i].playback_aa_slot = -1;
201 #endif
202 sb_skin[i].data = &sb_skin_data[i];
203 sb_skin[i].display = &screens[i];
204 /* Currently no seperate wps_state needed/possible
205 so use the only available ( "global" ) one */
206 sb_skin[i].state = &wps_state;
207 sb_skin[i].sync_data = &sb_skin_sync_data;