revert r25271 which caused more problems than it tried to fix
[kugel-rb.git] / apps / gui / statusbar-skinned.c
blob0902950599cee66bd48ad25781ab05af07a79338
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"
36 #include "icon.h"
39 /* currently only one wps_state is needed */
40 extern struct wps_state wps_state; /* from wps.c */
41 static struct gui_wps sb_skin[NB_SCREENS] = {{ .data = NULL }};
42 static struct wps_data sb_skin_data[NB_SCREENS] = {{ .wps_loaded = 0 }};
43 static struct wps_sync_data sb_skin_sync_data = { .do_full_update = false };
45 /* initial setup of wps_data */
46 static int update_delay = DEFAULT_UPDATE_DELAY;
48 bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen)
50 int i;
51 bool retval = false;
52 for(i=0; i<sb_skin_data[screen].num_tokens; i++)
54 if (sb_skin_data[screen].tokens[i].type == WPS_TOKEN_LIST_TITLE_TEXT)
56 sb_skin_data[screen].tokens[i].value.data = title;
57 retval = true;
59 else if (sb_skin_data[screen].tokens[i].type == WPS_TOKEN_LIST_TITLE_ICON)
61 /* Icon_NOICON == -1 which the skin engine wants at position 1, so + 2 */
62 sb_skin_data[screen].tokens[i].value.i = icon+2;
65 return retval;
69 void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile)
71 struct wps_data *data = sb_skin[screen].data;
73 int success;
74 success = buf && skin_data_load(screen, data, buf, isfile);
76 if (success)
77 { /* hide the sb's default viewport because it has nasty effect with stuff
78 * not part of the statusbar,
79 * hence .sbs's without any other vps are unsupported*/
80 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, data);
81 struct skin_token_list *next_vp = data->viewports->next;
83 if (!next_vp)
84 { /* no second viewport, let parsing fail */
85 success = false;
87 /* hide this viewport, forever */
88 vp->hidden_flags = VP_NEVER_VISIBLE;
91 if (!success && isfile)
92 sb_create_from_settings(screen);
95 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
97 return &find_viewport(VP_INFO_LABEL, sb_skin[screen].data)->vp;
100 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
101 char* sb_get_backdrop(enum screen_type screen)
103 return sb_skin[screen].data->backdrop;
106 bool sb_set_backdrop(enum screen_type screen, char* filename)
108 if (!filename)
110 sb_skin[screen].data->backdrop = NULL;
111 return true;
113 else if (!sb_skin[screen].data->backdrop)
115 /* need to make room on the buffer */
116 size_t buf_size;
117 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
118 if (screen == SCREEN_REMOTE)
119 buf_size = REMOTE_LCD_BACKDROP_BYTES;
120 else
121 #endif
122 buf_size = LCD_BACKDROP_BYTES;
123 sb_skin[screen].data->backdrop = skin_buffer_alloc(buf_size);
124 if (!sb_skin[screen].data->backdrop)
125 return false;
128 if (!screens[screen].backdrop_load(filename, sb_skin[screen].data->backdrop))
129 sb_skin[screen].data->backdrop = NULL;
130 return sb_skin[screen].data->backdrop != NULL;
133 #endif
134 void sb_skin_update(enum screen_type screen, bool force)
136 static long next_update = 0;
137 int i = screen;
138 if (TIME_AFTER(current_tick, next_update) || force)
140 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
141 /* currently, all remotes are readable without backlight
142 * so still update those */
143 if (lcd_active() || (i != SCREEN_MAIN))
144 #endif
145 skin_update(&sb_skin[i], force?
146 WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC);
147 next_update = current_tick + update_delay; /* don't update too often */
148 sb_skin[SCREEN_MAIN].sync_data->do_full_update = false;
152 void do_sbs_update_callback(void *param)
154 (void)param;
155 /* the WPS handles changing the actual id3 data in the id3 pointers
156 * we imported, we just want a full update */
157 sb_skin_sync_data.do_full_update = true;
158 /* force timeout in wps main loop, so that the update is instantly */
159 queue_post(&button_queue, BUTTON_NONE, 0);
162 void sb_skin_set_update_delay(int delay)
164 update_delay = delay;
167 /* This creates and loads a ".sbs" based on the user settings for:
168 * - regular statusbar
169 * - colours
170 * - ui viewport
171 * - backdrop
173 void sb_create_from_settings(enum screen_type screen)
175 char buf[128], *ptr, *ptr2;
176 int len, remaining = sizeof(buf);
177 int bar_position = statusbar_position(screen);
178 ptr = buf;
179 ptr[0] = '\0';
181 /* setup the inbuilt statusbar */
182 if (bar_position != STATUSBAR_OFF)
184 int y = 0, height = STATUSBAR_HEIGHT;
185 if (bar_position == STATUSBAR_BOTTOM)
187 y = screens[screen].lcdheight - STATUSBAR_HEIGHT;
189 len = snprintf(ptr, remaining, "%%V|0|%d|-|%d|0|-|-|\n%%wi\n",
190 y, height);
191 remaining -= len;
192 ptr += len;
194 /* %Vi viewport, colours handled by the parser */
195 #if NB_SCREENS > 1
196 if (screen == SCREEN_REMOTE)
197 ptr2 = global_settings.remote_ui_vp_config;
198 else
199 #endif
200 ptr2 = global_settings.ui_vp_config;
202 if (ptr2[0] && ptr2[0] != '-') /* from ui viewport setting */
204 len = snprintf(ptr, remaining, "%%ax%%Vi|%s|\n", ptr2);
205 while ((ptr2 = strchr(ptr, ',')))
206 *ptr2 = '|';
208 else
210 int y = 0, height;
211 switch (bar_position)
213 case STATUSBAR_TOP:
214 y = STATUSBAR_HEIGHT;
215 case STATUSBAR_BOTTOM:
216 height = screens[screen].lcdheight - STATUSBAR_HEIGHT;
217 break;
218 default:
219 height = screens[screen].lcdheight;
221 len = snprintf(ptr, remaining, "%%ax%%Vi|0|%d|-|%d|1|-|-|\n",
222 y, height);
224 sb_skin_data_load(screen, buf, false);
227 void sb_skin_init(void)
229 int i;
230 FOR_NB_SCREENS(i)
232 #ifdef HAVE_ALBUMART
233 sb_skin_data[i].albumart = NULL;
234 sb_skin_data[i].playback_aa_slot = -1;
235 #endif
236 sb_skin[i].data = &sb_skin_data[i];
237 sb_skin[i].display = &screens[i];
238 /* Currently no seperate wps_state needed/possible
239 so use the only available ( "global" ) one */
240 sb_skin[i].state = &wps_state;
241 sb_skin[i].sync_data = &sb_skin_sync_data;