Manual: change wording slightly in the USB charging section.
[kugel-rb.git] / apps / gui / statusbar-skinned.c
bloba5c751b804dab4c7eee05c3b521a1bf58ab1fc76
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 "action.h"
25 #include "system.h"
26 #include "settings.h"
27 #include "appevents.h"
28 #include "screens.h"
29 #include "screen_access.h"
30 #include "strlcpy.h"
31 #include "skin_parser.h"
32 #include "skin_buffer.h"
33 #include "skin_engine/skin_engine.h"
34 #include "skin_engine/wps_internals.h"
35 #include "viewport.h"
36 #include "statusbar.h"
37 #include "statusbar-skinned.h"
38 #include "debug.h"
39 #include "font.h"
40 #include "icon.h"
41 #include "option_select.h"
43 /* initial setup of wps_data */
44 static int update_delay = DEFAULT_UPDATE_DELAY;
46 static bool sbs_has_title[NB_SCREENS];
47 static char* sbs_title[NB_SCREENS];
48 static enum themable_icons sbs_icon[NB_SCREENS];
50 bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen)
52 sbs_title[screen] = title;
53 /* Icon_NOICON == -1 which the skin engine wants at position 1, so + 2 */
54 sbs_icon[screen] = icon + 2;
55 return sbs_has_title[screen];
58 void sb_skin_has_title(enum screen_type screen)
60 sbs_has_title[screen] = true;
63 const char* sb_get_title(enum screen_type screen)
65 return sbs_has_title[screen] ? sbs_title[screen] : NULL;
67 enum themable_icons sb_get_icon(enum screen_type screen)
69 return sbs_has_title[screen] ? sbs_icon[screen] : Icon_NOICON + 2;
72 int sb_preproccess(enum screen_type screen, struct wps_data *data)
74 (void)data;
75 int i;
76 FOR_NB_SCREENS(i)
77 sbs_has_title[i] = false;
78 viewportmanager_theme_enable(screen, false, NULL);
79 return 1;
81 int sb_postproccess(enum screen_type screen, struct wps_data *data)
83 if (data->wps_loaded)
85 /* hide the sb's default viewport because it has nasty effect with stuff
86 * not part of the statusbar,
87 * hence .sbs's without any other vps are unsupported*/
88 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, false, data);
89 struct skin_element *next_vp = data->tree->next;
91 if (vp)
93 if (!next_vp)
94 { /* no second viewport, let parsing fail */
95 return 0;
97 /* hide this viewport, forever */
98 vp->hidden_flags = VP_NEVER_VISIBLE;
100 sb_set_info_vp(screen, VP_DEFAULT_LABEL);
102 viewportmanager_theme_undo(screen, false);
103 return 1;
106 static char *infovp_label[NB_SCREENS];
107 static char *oldinfovp_label[NB_SCREENS];
108 void sb_set_info_vp(enum screen_type screen, char *label)
110 infovp_label[screen] = label;
113 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
115 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
116 if (oldinfovp_label[screen] &&
117 strcmp(oldinfovp_label[screen], infovp_label[screen]))
119 /* UI viewport changed, so force a redraw */
120 oldinfovp_label[screen] = infovp_label[screen];
121 viewportmanager_theme_enable(screen, false, NULL);
122 viewportmanager_theme_undo(screen, true);
124 return &find_viewport(infovp_label[screen], true, data)->vp;
127 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
128 int sb_get_backdrop(enum screen_type screen)
130 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
131 if (data->wps_loaded)
132 return data->backdrop_id;
133 else
134 return -1;
137 #endif
138 void sb_skin_update(enum screen_type screen, bool force)
140 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
141 static long next_update[NB_SCREENS] = {0};
142 int i = screen;
143 if (!data->wps_loaded)
144 return;
145 if (TIME_AFTER(current_tick, next_update[i]) || force)
147 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
148 /* currently, all remotes are readable without backlight
149 * so still update those */
150 if (lcd_active() || (i != SCREEN_MAIN))
151 #endif
153 bool full_update = skin_do_full_update(CUSTOM_STATUSBAR, screen);
154 skin_update(CUSTOM_STATUSBAR, screen, force ||
155 full_update ? SKIN_REFRESH_ALL : SKIN_REFRESH_NON_STATIC);
157 next_update[i] = current_tick + update_delay; /* don't update too often */
161 void do_sbs_update_callback(void *param)
163 (void)param;
164 /* the WPS handles changing the actual id3 data in the id3 pointers
165 * we imported, we just want a full update */
166 skin_request_full_update(CUSTOM_STATUSBAR);
167 /* force timeout in wps main loop, so that the update is instantly */
168 queue_post(&button_queue, BUTTON_NONE, 0);
171 void sb_skin_set_update_delay(int delay)
173 update_delay = delay;
176 /* This creates and loads a ".sbs" based on the user settings for:
177 * - regular statusbar
178 * - colours
179 * - ui viewport
180 * - backdrop
182 char* sb_create_from_settings(enum screen_type screen)
184 static char buf[128];
185 char *ptr, *ptr2;
186 int len, remaining = sizeof(buf);
187 int bar_position = statusbar_position(screen);
188 ptr = buf;
189 ptr[0] = '\0';
191 /* setup the inbuilt statusbar */
192 if (bar_position != STATUSBAR_OFF)
194 int y = 0, height = STATUSBAR_HEIGHT;
195 if (bar_position == STATUSBAR_BOTTOM)
197 y = screens[screen].lcdheight - STATUSBAR_HEIGHT;
199 len = snprintf(ptr, remaining, "%%V(0,%d,-,%d,0)\n%%wi\n",
200 y, height);
201 remaining -= len;
202 ptr += len;
204 /* %Vi viewport, colours handled by the parser */
205 #if NB_SCREENS > 1
206 if (screen == SCREEN_REMOTE)
207 ptr2 = global_settings.remote_ui_vp_config;
208 else
209 #endif
210 ptr2 = global_settings.ui_vp_config;
212 if (ptr2[0] && ptr2[0] != '-') /* from ui viewport setting */
214 char *comma = ptr;
215 int param_count = 0;
216 len = snprintf(ptr, remaining, "%%ax%%Vi(-,%s)\n", ptr2);
217 /* The config put the colours at the end of the viewport,
218 * they need to be stripped for the skin code though */
219 do {
220 param_count++;
221 comma = strchr(comma+1, ',');
223 } while (comma && param_count < 6);
224 if (comma)
226 char *end = comma;
227 char fg[8], bg[8];
228 int i = 0;
229 comma++;
230 while (*comma != ',')
231 fg[i++] = *comma++;
232 fg[i] = '\0'; comma++; i=0;
233 while (*comma != ')')
234 bg[i++] = *comma++;
235 bg[i] = '\0';
236 len += snprintf(end, remaining-len, ") %%Vf(%s) %%Vb(%s)\n", fg, bg);
239 else
241 int y = 0, height;
242 switch (bar_position)
244 case STATUSBAR_TOP:
245 y = STATUSBAR_HEIGHT;
246 case STATUSBAR_BOTTOM:
247 height = screens[screen].lcdheight - STATUSBAR_HEIGHT;
248 break;
249 default:
250 height = screens[screen].lcdheight;
252 len = snprintf(ptr, remaining, "%%ax%%Vi(-,0,%d,-,%d,1)\n",
253 y, height);
255 return buf;
258 void sb_skin_init(void)
260 int i;
261 FOR_NB_SCREENS(i)
263 oldinfovp_label[i] = NULL;
267 #ifdef HAVE_TOUCHSCREEN
268 static bool bypass_sb_touchregions = true;
269 void sb_bypass_touchregions(bool enable)
271 bypass_sb_touchregions = enable;
274 int sb_touch_to_button(int context)
276 struct touchregion *region;
277 static int last_context = -1;
278 int button, offset;
279 if (bypass_sb_touchregions)
280 return ACTION_TOUCHSCREEN;
282 if (last_context != context)
283 skin_disarm_touchregions(skin_get_gwps(CUSTOM_STATUSBAR, SCREEN_MAIN)->data);
284 last_context = context;
285 button = skin_get_touchaction(skin_get_gwps(CUSTOM_STATUSBAR, SCREEN_MAIN)->data,
286 &offset, &region);
288 switch (button)
290 #ifdef HAVE_VOLUME_IN_LIST
291 case ACTION_WPS_VOLUP:
292 return ACTION_LIST_VOLUP;
293 case ACTION_WPS_VOLDOWN:
294 return ACTION_LIST_VOLDOWN;
295 #endif
296 case ACTION_SETTINGS_INC:
297 case ACTION_SETTINGS_DEC:
299 const struct settings_list *setting = region->extradata;
300 option_select_next_val(setting, button == ACTION_SETTINGS_DEC, true);
302 return ACTION_REDRAW;
303 /* TODO */
305 return button;
307 #endif