Re-factor code for the plugins main menu item, enabling better icons in that menu.
[maemo-rb.git] / apps / menus / theme_menu.c
blobb483a7ef114dea403dece5dcf262e7abb058f986
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
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 <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "lang.h"
27 #include "action.h"
28 #include "settings.h"
29 #include "menu.h"
30 #include "tree.h"
31 #include "list.h"
32 #ifdef HAVE_LCD_BITMAP
33 #include "peakmeter.h"
34 #endif
35 #include "color_picker.h"
36 #include "lcd.h"
37 #include "lcd-remote.h"
38 #include "backdrop.h"
39 #include "exported_menus.h"
40 #include "appevents.h"
41 #include "viewport.h"
42 #include "statusbar-skinned.h"
43 #include "skin_engine/skin_engine.h"
45 #if LCD_DEPTH > 1
46 /**
47 * Menu to clear the backdrop image
49 static int clear_main_backdrop(void)
51 global_settings.backdrop_file[0] = '-';
52 global_settings.backdrop_file[1] = '\0';
53 skin_backdrop_load_setting();
54 viewportmanager_theme_enable(SCREEN_MAIN, false, NULL);
55 viewportmanager_theme_undo(SCREEN_MAIN, true);
56 settings_save();
57 return 0;
59 MENUITEM_FUNCTION(clear_main_bd, 0, ID2P(LANG_CLEAR_BACKDROP),
60 clear_main_backdrop, NULL, NULL, Icon_NOICON);
61 #endif
62 #ifdef HAVE_LCD_COLOR
64 enum Colors {
65 COLOR_FG = 0,
66 COLOR_BG,
67 COLOR_LSS,
68 COLOR_LSE,
69 COLOR_LST,
70 COLOR_COUNT
72 static struct colour_info
74 int *setting;
75 int lang_id;
76 } colors[COLOR_COUNT] = {
77 [COLOR_FG] = {&global_settings.fg_color, LANG_FOREGROUND_COLOR},
78 [COLOR_BG] = {&global_settings.bg_color, LANG_BACKGROUND_COLOR},
79 [COLOR_LSS] = {&global_settings.lss_color, LANG_SELECTOR_START_COLOR},
80 [COLOR_LSE] = {&global_settings.lse_color, LANG_SELECTOR_END_COLOR},
81 [COLOR_LST] = {&global_settings.lst_color, LANG_SELECTOR_TEXT_COLOR},
84 /**
85 * Menu for fore/back/selection colors
87 static int set_color_func(void* color)
89 int res, c = (intptr_t)color, banned_color=-1, old_color;
90 /* Don't let foreground be set the same as background and vice-versa */
91 if (c == COLOR_BG)
92 banned_color = *colors[COLOR_FG].setting;
93 else if (c == COLOR_FG)
94 banned_color = *colors[COLOR_BG].setting;
96 old_color = *colors[c].setting;
97 res = (int)set_color(&screens[SCREEN_MAIN],str(colors[c].lang_id),
98 colors[c].setting, banned_color);
99 if (old_color != *colors[c].setting)
101 settings_save();
102 settings_apply(false);
103 settings_apply_skins();
105 return res;
108 static int reset_color(void)
110 global_settings.fg_color = LCD_DEFAULT_FG;
111 global_settings.bg_color = LCD_DEFAULT_BG;
112 global_settings.lss_color = LCD_DEFAULT_LS;
113 global_settings.lse_color = LCD_DEFAULT_BG;
114 global_settings.lst_color = LCD_DEFAULT_FG;
116 settings_save();
117 settings_apply(false);
118 settings_apply_skins();
119 return 0;
121 MENUITEM_FUNCTION(set_bg_col, MENU_FUNC_USEPARAM, ID2P(LANG_BACKGROUND_COLOR),
122 set_color_func, (void*)COLOR_BG, NULL, Icon_NOICON);
123 MENUITEM_FUNCTION(set_fg_col, MENU_FUNC_USEPARAM, ID2P(LANG_FOREGROUND_COLOR),
124 set_color_func, (void*)COLOR_FG, NULL, Icon_NOICON);
125 MENUITEM_FUNCTION(set_lss_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_START_COLOR),
126 set_color_func, (void*)COLOR_LSS, NULL, Icon_NOICON);
127 MENUITEM_FUNCTION(set_lse_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_END_COLOR),
128 set_color_func, (void*)COLOR_LSE, NULL, Icon_NOICON);
129 MENUITEM_FUNCTION(set_lst_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_TEXT_COLOR),
130 set_color_func, (void*)COLOR_LST, NULL, Icon_NOICON);
131 MENUITEM_FUNCTION(reset_colors, 0, ID2P(LANG_RESET_COLORS),
132 reset_color, NULL, NULL, Icon_NOICON);
134 MAKE_MENU(lss_settings, ID2P(LANG_SELECTOR_COLOR_MENU),
135 NULL, Icon_NOICON,
136 &set_lss_col, &set_lse_col, &set_lst_col
139 /* now the actual menu */
140 MAKE_MENU(colors_settings, ID2P(LANG_COLORS_MENU),
141 NULL, Icon_Display_menu,
142 &lss_settings,
143 &set_bg_col, &set_fg_col, &reset_colors
146 #endif /* HAVE_LCD_COLOR */
147 /* LCD MENU */
148 /***********************************/
151 /************************************/
152 /* BARS MENU */
153 /* */
156 #ifdef HAVE_LCD_BITMAP
157 static int statusbar_callback_ex(int action,const struct menu_item_ex *this_item,
158 enum screen_type screen)
160 (void)this_item;
161 /* we save the old statusbar value here, so the old statusbars can get
162 * removed and cleared from the display properly on exiting
163 * (in gui_statusbar_changed() ) */
164 static enum statusbar_values old_bar[NB_SCREENS];
165 switch (action)
167 case ACTION_ENTER_MENUITEM:
168 old_bar[screen] = statusbar_position(screen);
169 break;
170 case ACTION_EXIT_MENUITEM:
171 if (old_bar[screen] != statusbar_position(screen))
172 settings_apply_skins();
173 break;
175 return ACTION_REDRAW;
178 #ifdef HAVE_REMOTE_LCD
179 static int statusbar_callback_remote(int action,const struct menu_item_ex *this_item)
181 return statusbar_callback_ex(action, this_item, SCREEN_REMOTE);
183 #endif
184 static int statusbar_callback(int action,const struct menu_item_ex *this_item)
186 return statusbar_callback_ex(action, this_item, SCREEN_MAIN);
189 #ifdef HAVE_BUTTONBAR
190 static int buttonbar_callback(int action, const struct menu_item_ex *this_item)
192 (void)this_item;
193 switch (action)
195 case ACTION_EXIT_MENUITEM:
196 viewportmanager_theme_changed(THEME_BUTTONBAR);
197 break;
199 return ACTION_REDRAW;
201 #endif
202 MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, NULL);
203 MENUITEM_SETTING(scrollbar_width, &global_settings.scrollbar_width, NULL);
204 MENUITEM_SETTING(statusbar, &global_settings.statusbar,
205 statusbar_callback);
206 #ifdef HAVE_REMOTE_LCD
207 MENUITEM_SETTING(remote_statusbar, &global_settings.remote_statusbar,
208 statusbar_callback_remote);
209 #endif
210 #ifdef HAVE_BUTTONBAR
211 MENUITEM_SETTING(buttonbar, &global_settings.buttonbar, buttonbar_callback);
212 #endif
213 MENUITEM_SETTING(volume_type, &global_settings.volume_type, NULL);
214 MENUITEM_SETTING(battery_display, &global_settings.battery_display, NULL);
215 MAKE_MENU(bars_menu, ID2P(LANG_BARS_MENU), 0, Icon_NOICON,
216 &scrollbar_item, &scrollbar_width, &statusbar,
217 #ifdef HAVE_REMOTE_LCD
218 &remote_statusbar,
219 #endif
220 #if CONFIG_KEYPAD == RECORDER_PAD
221 &buttonbar,
222 #endif
223 &volume_type, &battery_display);
224 #endif /* HAVE_LCD_BITMAP */
226 /* */
227 /* BARS MENU */
228 /************************************/
230 #ifdef HAVE_LCD_BITMAP
231 static struct browse_folder_info fonts = {FONT_DIR, SHOW_FONT};
232 static struct browse_folder_info sbs = {SBS_DIR, SHOW_SBS};
233 #if CONFIG_TUNER
234 static struct browse_folder_info fms = {WPS_DIR, SHOW_FMS};
235 #endif
236 #endif
237 static struct browse_folder_info wps = {WPS_DIR, SHOW_WPS};
238 #ifdef HAVE_REMOTE_LCD
239 static struct browse_folder_info rwps = {WPS_DIR, SHOW_RWPS};
240 static struct browse_folder_info rsbs = {SBS_DIR, SHOW_RSBS};
241 #if CONFIG_TUNER
242 static struct browse_folder_info rfms = {WPS_DIR, SHOW_RFMS};
243 #endif
244 #endif
245 static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG};
247 int browse_folder(void *param)
249 const char *ext, *setting;
250 int lang_id = -1;
251 char selected[MAX_FILENAME+10];
252 const struct browse_folder_info *info =
253 (const struct browse_folder_info*)param;
254 struct browse_context browse;
255 browse_context_init(&browse, info->show_options, 0,
256 NULL, NOICON, info->dir, NULL);
258 /* if we are in a special settings folder, center the current setting */
259 switch(info->show_options)
261 case SHOW_LNG:
262 ext = "lng";
263 if (global_settings.lang_file[0])
264 setting = global_settings.lang_file;
265 else
266 setting = "english";
267 lang_id = LANG_LANGUAGE;
268 break;
269 case SHOW_WPS:
270 ext = "wps";
271 setting = global_settings.wps_file;
272 lang_id = LANG_WHILE_PLAYING;
273 break;
274 #ifdef HAVE_LCD_BITMAP
275 case SHOW_FONT:
276 ext = "fnt";
277 setting = global_settings.font_file;
278 lang_id = LANG_CUSTOM_FONT;
279 break;
280 case SHOW_SBS:
281 ext = "sbs";
282 setting = global_settings.sbs_file;
283 lang_id = LANG_BASE_SKIN;
284 break;
285 #if CONFIG_TUNER
286 case SHOW_FMS:
287 ext = "fms";
288 setting = global_settings.fms_file;
289 lang_id = LANG_RADIOSCREEN;
290 break;
291 #endif /* CONFIG_TUNER */
292 #endif
293 #ifdef HAVE_REMOTE_LCD
294 case SHOW_RWPS:
295 ext = "rwps";
296 setting = global_settings.rwps_file;
297 lang_id = LANG_REMOTE_WHILE_PLAYING;
298 break;
299 case SHOW_RSBS:
300 ext = "rsbs";
301 setting = global_settings.rsbs_file;
302 lang_id = LANG_REMOTE_BASE_SKIN;
303 break;
304 #if CONFIG_TUNER
305 case SHOW_RFMS:
306 ext = "rfms";
307 setting = global_settings.rfms_file;
308 lang_id = LANG_REMOTE_RADIOSCREEN;
309 break;
310 #endif /* CONFIG_TUNER */
311 #endif
312 default:
313 ext = setting = NULL;
314 break;
317 /* If we've found a file to center on, do it */
318 if (setting)
320 /* if setting != NULL, ext is initialized */
321 snprintf(selected, sizeof(selected), "%s.%s", setting, ext);
322 browse.selected = selected;
323 browse.icon = Icon_Questionmark;
324 browse.title = str(lang_id);
327 return rockbox_browse(&browse);
330 #ifdef HAVE_LCD_BITMAP
331 MENUITEM_FUNCTION(browse_fonts, MENU_FUNC_USEPARAM,
332 ID2P(LANG_CUSTOM_FONT),
333 browse_folder, (void*)&fonts, NULL, Icon_Font);
335 MENUITEM_FUNCTION(browse_sbs, MENU_FUNC_USEPARAM,
336 ID2P(LANG_BASE_SKIN),
337 browse_folder, (void*)&sbs, NULL, Icon_Wps);
338 #if CONFIG_TUNER
339 MENUITEM_FUNCTION(browse_fms, MENU_FUNC_USEPARAM,
340 ID2P(LANG_RADIOSCREEN),
341 browse_folder, (void*)&fms, NULL, Icon_Wps);
342 #endif
343 #endif
344 MENUITEM_FUNCTION(browse_wps, MENU_FUNC_USEPARAM,
345 ID2P(LANG_WHILE_PLAYING),
346 browse_folder, (void*)&wps, NULL, Icon_Wps);
347 #ifdef HAVE_REMOTE_LCD
348 MENUITEM_FUNCTION(browse_rwps, MENU_FUNC_USEPARAM,
349 ID2P(LANG_REMOTE_WHILE_PLAYING),
350 browse_folder, (void*)&rwps, NULL, Icon_Wps);
351 MENUITEM_FUNCTION(browse_rsbs, MENU_FUNC_USEPARAM,
352 ID2P(LANG_REMOTE_BASE_SKIN),
353 browse_folder, (void*)&rsbs, NULL, Icon_Wps);
354 #if CONFIG_TUNER
355 MENUITEM_FUNCTION(browse_rfms, MENU_FUNC_USEPARAM,
356 ID2P(LANG_REMOTE_RADIOSCREEN),
357 browse_folder, (void*)&rfms, NULL, Icon_Wps);
358 #endif
359 #endif
361 MENUITEM_SETTING(show_icons, &global_settings.show_icons, NULL);
362 MENUITEM_FUNCTION(browse_themes, MENU_FUNC_USEPARAM,
363 ID2P(LANG_CUSTOM_THEME),
364 browse_folder, (void*)&themes, NULL, Icon_Config);
365 #ifdef HAVE_LCD_BITMAP
366 MENUITEM_SETTING(cursor_style, &global_settings.cursor_style, NULL);
367 #endif
369 MAKE_MENU(theme_menu, ID2P(LANG_THEME_MENU),
370 NULL, Icon_Wps,
371 &browse_themes,
372 #ifdef HAVE_LCD_BITMAP
373 &browse_fonts,
374 #endif
375 &browse_wps,
376 #ifdef HAVE_REMOTE_LCD
377 &browse_rwps,
378 #endif
379 #if CONFIG_TUNER
380 &browse_fms,
381 #ifdef HAVE_REMOTE_LCD
382 &browse_rfms,
383 #endif
384 #endif
385 #ifdef HAVE_LCD_BITMAP
386 &browse_sbs,
387 #endif
388 #ifdef HAVE_REMOTE_LCD
389 &browse_rsbs,
390 #endif
391 &show_icons,
392 #if LCD_DEPTH > 1
393 &clear_main_bd,
394 #endif
395 #ifdef HAVE_LCD_BITMAP
396 &bars_menu,
397 &cursor_style,
398 #endif
399 #ifdef HAVE_LCD_COLOR
400 &colors_settings,
401 #endif