No need to have this variable global anymore.
[kugel-rb.git] / apps / gui / statusbar-skinned.c
blob7b2aae81f52e0a4ee19af6e7a8358165ac2425c4
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"
37 /* currently only one wps_state is needed */
38 extern struct wps_state wps_state; /* from wps.c */
39 static struct gui_wps sb_skin[NB_SCREENS] = {{ .data = NULL }};
40 static struct wps_data sb_skin_data[NB_SCREENS] = {{ .wps_loaded = 0 }};
41 static struct wps_sync_data sb_skin_sync_data = { .do_full_update = false };
43 /* initial setup of wps_data */
44 static void sb_skin_update(void*);
45 static bool loaded_ok[NB_SCREENS] = { false };
46 static int update_delay = DEFAULT_UPDATE_DELAY;
49 void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile)
51 struct wps_data *data = sb_skin[screen].data;
53 int success;
54 success = buf && skin_data_load(data, buf, isfile);
56 if (success)
57 { /* hide the sb's default viewport because it has nasty effect with stuff
58 * not part of the statusbar,
59 * hence .sbs's without any other vps are unsupported*/
60 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, data);
61 struct skin_token_list *next_vp = data->viewports->next;
63 if (!next_vp)
64 { /* no second viewport, let parsing fail */
65 success = false;
67 /* hide this viewport, forever */
68 vp->hidden_flags = VP_NEVER_VISIBLE;
71 if (!success)
72 remove_event(GUI_EVENT_ACTIONUPDATE, sb_skin_update);
74 #ifdef HAVE_REMOVE_LCD
75 data->remote_wps = !(screen == SCREEN_MAIN);
76 #endif
77 loaded_ok[screen] = success;
80 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
82 return &find_viewport(VP_INFO_LABEL, sb_skin[screen].data)->vp;
85 inline bool sb_skin_get_state(enum screen_type screen)
87 int skinbars = sb_skin[screen].sync_data->statusbars;
88 return loaded_ok[screen] && (skinbars & VP_SB_ONSCREEN(screen));
92 static void do_update_callback(void *param)
94 (void)param;
95 /* the WPS handles changing the actual id3 data in the id3 pointers
96 * we imported, we just want a full update */
97 sb_skin_sync_data.do_full_update = true;
98 /* force timeout in wps main loop, so that the update is instantly */
99 queue_post(&button_queue, BUTTON_NONE, 0);
103 void sb_skin_set_state(int state, enum screen_type screen)
105 sb_skin[screen].sync_data->do_full_update = true;
106 int skinbars = sb_skin[screen].sync_data->statusbars;
107 if (state)
109 skinbars |= VP_SB_ONSCREEN(screen);
111 else
113 skinbars &= ~VP_SB_ONSCREEN(screen);
116 if (skinbars)
118 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
119 add_event(LCD_EVENT_ACTIVATION, false, do_update_callback);
120 #endif
121 add_event(GUI_EVENT_ACTIONUPDATE, false, sb_skin_update);
123 else
125 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
126 add_event(LCD_EVENT_ACTIVATION, false, do_update_callback);
127 #endif
128 remove_event(GUI_EVENT_ACTIONUPDATE, sb_skin_update);
131 sb_skin[screen].sync_data->statusbars = skinbars;
134 static void sb_skin_update(void* param)
136 static long next_update = 0;
137 int i;
138 int forced_draw = param || sb_skin[SCREEN_MAIN].sync_data->do_full_update;
139 if (TIME_AFTER(current_tick, next_update) || forced_draw)
141 FOR_NB_SCREENS(i)
143 if (sb_skin_get_state(i))
145 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
146 /* currently, all remotes are readable without backlight
147 * so still update those */
148 if (lcd_active() || (i != SCREEN_MAIN))
149 #endif
150 skin_update(&sb_skin[i], forced_draw?
151 WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC);
154 next_update = current_tick + update_delay; /* don't update too often */
155 sb_skin[SCREEN_MAIN].sync_data->do_full_update = false;
159 void sb_skin_set_update_delay(int delay)
161 update_delay = delay;
165 void sb_skin_init(void)
167 int i;
168 FOR_NB_SCREENS(i)
170 #ifdef HAVE_ALBUMART
171 sb_skin_data[i].albumart = NULL;
172 sb_skin_data[i].playback_aa_slot = -1;
173 #endif
174 #ifdef HAVE_REMOTE_LCD
175 sb_skin_data[i].remote_wps = (i == SCREEN_REMOTE);
176 #endif
177 sb_skin[i].data = &sb_skin_data[i];
178 sb_skin[i].display = &screens[i];
179 /* Currently no seperate wps_state needed/possible
180 so use the only available ( "global" ) one */
181 sb_skin[i].state = &wps_state;
182 sb_skin_sync_data.statusbars = VP_SB_HIDE_ALL;
183 sb_skin[i].sync_data = &sb_skin_sync_data;
185 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, do_update_callback);
186 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, do_update_callback);