Czech language: Some minor terminology changes by Marek Salaba FS#11935
[kugel-rb.git] / apps / gui / statusbar-skinned.c
blob29e8d1a92aa06bddbe136a0d2de75dec30f5a45b
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"
42 #ifdef HAVE_TOUCHSCREEN
43 #include "sound.h"
44 #include "misc.h"
45 #endif
47 /* initial setup of wps_data */
48 static int update_delay = DEFAULT_UPDATE_DELAY;
50 static bool sbs_has_title[NB_SCREENS];
51 static char* sbs_title[NB_SCREENS];
52 static enum themable_icons sbs_icon[NB_SCREENS];
54 bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen)
56 sbs_title[screen] = title;
57 /* Icon_NOICON == -1 which the skin engine wants at position 1, so + 2 */
58 sbs_icon[screen] = icon + 2;
59 return sbs_has_title[screen];
62 void sb_skin_has_title(enum screen_type screen)
64 sbs_has_title[screen] = true;
67 const char* sb_get_title(enum screen_type screen)
69 return sbs_has_title[screen] ? sbs_title[screen] : NULL;
71 enum themable_icons sb_get_icon(enum screen_type screen)
73 return sbs_has_title[screen] ? sbs_icon[screen] : Icon_NOICON + 2;
76 int sb_preproccess(enum screen_type screen, struct wps_data *data)
78 (void)data;
79 sbs_has_title[screen] = false;
80 viewportmanager_theme_enable(screen, false, NULL);
81 return 1;
83 int sb_postproccess(enum screen_type screen, struct wps_data *data)
85 if (data->wps_loaded)
87 /* hide the sb's default viewport because it has nasty effect with stuff
88 * not part of the statusbar,
89 * hence .sbs's without any other vps are unsupported*/
90 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, false, data);
91 struct skin_element *next_vp = data->tree->next;
93 if (vp)
95 if (!next_vp)
96 { /* no second viewport, let parsing fail */
97 return 0;
99 /* hide this viewport, forever */
100 vp->hidden_flags = VP_NEVER_VISIBLE;
102 sb_set_info_vp(screen, VP_DEFAULT_LABEL);
104 viewportmanager_theme_undo(screen, false);
105 return 1;
108 static char *infovp_label[NB_SCREENS];
109 static char *oldinfovp_label[NB_SCREENS];
110 void sb_set_info_vp(enum screen_type screen, char *label)
112 infovp_label[screen] = label;
115 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
117 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
118 if (oldinfovp_label[screen] &&
119 strcmp(oldinfovp_label[screen], infovp_label[screen]))
121 /* UI viewport changed, so force a redraw */
122 oldinfovp_label[screen] = infovp_label[screen];
123 viewportmanager_theme_enable(screen, false, NULL);
124 viewportmanager_theme_undo(screen, true);
126 return &find_viewport(infovp_label[screen], true, data)->vp;
129 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
130 int sb_get_backdrop(enum screen_type screen)
132 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
133 if (data->wps_loaded)
134 return data->backdrop_id;
135 else
136 return -1;
139 #endif
140 void sb_skin_update(enum screen_type screen, bool force)
142 struct wps_data *data = skin_get_gwps(CUSTOM_STATUSBAR, screen)->data;
143 static long next_update[NB_SCREENS] = {0};
144 int i = screen;
145 if (!data->wps_loaded)
146 return;
147 if (TIME_AFTER(current_tick, next_update[i]) || force)
149 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
150 /* currently, all remotes are readable without backlight
151 * so still update those */
152 if (lcd_active() || (i != SCREEN_MAIN))
153 #endif
155 bool full_update = skin_do_full_update(CUSTOM_STATUSBAR, screen);
156 skin_update(CUSTOM_STATUSBAR, screen, force ||
157 full_update ? SKIN_REFRESH_ALL : SKIN_REFRESH_NON_STATIC);
159 next_update[i] = current_tick + update_delay; /* don't update too often */
163 void do_sbs_update_callback(void *param)
165 (void)param;
166 /* the WPS handles changing the actual id3 data in the id3 pointers
167 * we imported, we just want a full update */
168 skin_request_full_update(CUSTOM_STATUSBAR);
169 /* force timeout in wps main loop, so that the update is instantly */
170 queue_post(&button_queue, BUTTON_NONE, 0);
173 void sb_skin_set_update_delay(int delay)
175 update_delay = delay;
178 /* This creates and loads a ".sbs" based on the user settings for:
179 * - regular statusbar
180 * - colours
181 * - ui viewport
182 * - backdrop
184 char* sb_create_from_settings(enum screen_type screen)
186 static char buf[128];
187 char *ptr, *ptr2;
188 int len, remaining = sizeof(buf);
189 int bar_position = statusbar_position(screen);
190 ptr = buf;
191 ptr[0] = '\0';
193 /* setup the inbuilt statusbar */
194 if (bar_position != STATUSBAR_OFF)
196 int y = 0, height = STATUSBAR_HEIGHT;
197 if (bar_position == STATUSBAR_BOTTOM)
199 y = screens[screen].lcdheight - STATUSBAR_HEIGHT;
201 len = snprintf(ptr, remaining, "%%V(0,%d,-,%d,0)\n%%wi\n",
202 y, height);
203 remaining -= len;
204 ptr += len;
206 /* %Vi viewport, colours handled by the parser */
207 #if NB_SCREENS > 1
208 if (screen == SCREEN_REMOTE)
209 ptr2 = global_settings.remote_ui_vp_config;
210 else
211 #endif
212 ptr2 = global_settings.ui_vp_config;
214 if (ptr2[0] && ptr2[0] != '-') /* from ui viewport setting */
216 char *comma = ptr;
217 int param_count = 0;
218 len = snprintf(ptr, remaining, "%%ax%%Vi(-,%s)\n", ptr2);
219 /* The config put the colours at the end of the viewport,
220 * they need to be stripped for the skin code though */
221 do {
222 param_count++;
223 comma = strchr(comma+1, ',');
225 } while (comma && param_count < 6);
226 if (comma)
228 char *end = comma;
229 char fg[8], bg[8];
230 int i = 0;
231 comma++;
232 while (*comma != ',')
233 fg[i++] = *comma++;
234 fg[i] = '\0'; comma++; i=0;
235 while (*comma != ')')
236 bg[i++] = *comma++;
237 bg[i] = '\0';
238 len += snprintf(end, remaining-len, ") %%Vf(%s) %%Vb(%s)\n", fg, bg);
241 else
243 int y = 0, height;
244 switch (bar_position)
246 case STATUSBAR_TOP:
247 y = STATUSBAR_HEIGHT;
248 case STATUSBAR_BOTTOM:
249 height = screens[screen].lcdheight - STATUSBAR_HEIGHT;
250 break;
251 default:
252 height = screens[screen].lcdheight;
254 len = snprintf(ptr, remaining, "%%ax%%Vi(-,0,%d,-,%d,1)\n",
255 y, height);
257 return buf;
260 void sb_skin_init(void)
262 int i;
263 FOR_NB_SCREENS(i)
265 oldinfovp_label[i] = NULL;
269 #ifdef HAVE_TOUCHSCREEN
270 static bool bypass_sb_touchregions = true;
271 void sb_bypass_touchregions(bool enable)
273 bypass_sb_touchregions = enable;
276 int sb_touch_to_button(int context)
278 struct touchregion *region;
279 static int last_context = -1;
280 int button, offset;
281 if (bypass_sb_touchregions)
282 return ACTION_TOUCHSCREEN;
284 if (last_context != context)
285 skin_disarm_touchregions(skin_get_gwps(CUSTOM_STATUSBAR, SCREEN_MAIN)->data);
286 last_context = context;
287 button = skin_get_touchaction(skin_get_gwps(CUSTOM_STATUSBAR, SCREEN_MAIN)->data,
288 &offset, &region);
290 switch (button)
292 #ifdef HAVE_VOLUME_IN_LIST
293 case ACTION_WPS_VOLUP:
294 return ACTION_LIST_VOLUP;
295 case ACTION_WPS_VOLDOWN:
296 return ACTION_LIST_VOLDOWN;
297 #endif
298 case ACTION_SETTINGS_INC:
299 case ACTION_SETTINGS_DEC:
301 const struct settings_list *setting = region->data;
302 option_select_next_val(setting, button == ACTION_SETTINGS_DEC, true);
304 return ACTION_REDRAW;
305 case ACTION_TOUCH_MUTE:
307 const int min_vol = sound_min(SOUND_VOLUME);
308 if (global_settings.volume == min_vol)
309 global_settings.volume = region->value;
310 else
312 region->value = global_settings.volume;
313 global_settings.volume = min_vol;
315 setvol();
317 return ACTION_REDRAW;
318 /* TODO */
320 return button;
322 #endif