From edcacaa787d770cd5b944c18082b5b80128f7e4e Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 3 Nov 2008 11:11:07 +0000 Subject: [PATCH] FS#9515 - customisable quickscreen. Allows you to choose which setting you want displayed on the quickscreen. Allows almost every available setting. (change the options in settings > general settings > quickscreen items) Not every setting will work perfectly, some might need aditional handling if the change doesnt take effect straight away (let us know which are problematic so they can be fixed) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18984 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/quickscreen.c | 164 +++++++++++++++++++++++++++++++++++-- apps/gui/quickscreen.h | 2 +- apps/lang/english.lang | 68 +++++++++++++++ apps/menus/settings_menu.c | 22 +++++ apps/settings.h | 6 ++ apps/settings_list.c | 53 ++++++++++++ apps/settings_list.h | 4 +- 7 files changed, 309 insertions(+), 10 deletions(-) diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 0bfe746661..189a1e5989 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -37,6 +37,8 @@ #include "audio.h" #include "quickscreen.h" #include "talk.h" +#include "list.h" +#include "splash.h" static struct viewport vps[NB_SCREENS][QUICKSCREEN_ITEM_COUNT]; static struct viewport vp_icons[NB_SCREENS]; @@ -113,7 +115,7 @@ static void quickscreen_fix_viewports(struct gui_quickscreen *qs, vps[screen][QUICKSCREEN_RIGHT].width = width; /* shrink the icons vp by a few pixels if there is room so the arrows - arnt' drawn right next to the text */ + aren't drawn right next to the text */ if (vp_icons[screen].width > CENTER_ICONAREA_WIDTH+8) { vp_icons[screen].width -= 8; @@ -320,18 +322,31 @@ bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter) cond_talk_ids_fq(VOICE_OK); return changed; } - +static bool is_setting_quickscreenable(const struct settings_list *setting); +static inline const struct settings_list *get_setting(int gs_value, + const struct settings_list *defaultval) +{ + if (gs_value != -1 && gs_value < nb_settings && + is_setting_quickscreenable(&settings[gs_value])) + return &settings[gs_value]; + return defaultval; +} bool quick_screen_quick(int button_enter) { struct gui_quickscreen qs; bool oldshuffle = global_settings.playlist_shuffle; int oldrepeat = global_settings.repeat_mode; - qs.items[QUICKSCREEN_LEFT] = - find_setting(&global_settings.playlist_shuffle, NULL); - qs.items[QUICKSCREEN_RIGHT] = - find_setting(&global_settings.repeat_mode, NULL); - qs.items[QUICKSCREEN_BOTTOM] = - find_setting(&global_settings.dirfilter, NULL); + + qs.items[QUICKSCREEN_LEFT] = + get_setting(global_settings.qs_item_left, + find_setting(&global_settings.playlist_shuffle, NULL)); + qs.items[QUICKSCREEN_RIGHT] = + get_setting(global_settings.qs_item_right, + find_setting(&global_settings.repeat_mode, NULL)); + qs.items[QUICKSCREEN_BOTTOM] = + get_setting(global_settings.qs_item_bottom, + find_setting(&global_settings.dirfilter, NULL)); + qs.callback = NULL; if (gui_syncquickscreen_run(&qs, button_enter)) { @@ -378,3 +393,136 @@ bool quick_screen_f3(int button_enter) } #endif /* BUTTON_F3 */ +/* stuff to make the quickscreen configurable */ +static bool is_setting_quickscreenable(const struct settings_list *setting) +{ + /* to keep things simple, only settings which have a lang_id set are ok */ + if (setting->lang_id < 0 || (setting->flags&F_BANFROMQS)) + return false; + switch (setting->flags&F_T_MASK) + { + case F_T_BOOL: + return true; + case F_T_INT: + case F_T_UINT: + return (setting->RESERVED != NULL); + default: + return false; + } +} + +const struct settings_list *find_setting_from_index(int index) +{ + int count = -1, i; + const struct settings_list *setting = &settings[0]; + for(i=0;ilang_id), setting->cfg_name); + return buffer; +} +static int quickscreen_setter_speak_item(int selected_item, void * data) +{ + (void)data; + talk_id(find_setting_from_index(selected_item)->lang_id, true); + return 0; +} +static int quickscreen_setter_action_callback(int action, + struct gui_synclist *lists) +{ + const struct settings_list *temp = lists->data; + switch (action) + { + case ACTION_STD_OK: + /* ok, quit */ + return ACTION_STD_CANCEL; + case ACTION_STD_CONTEXT: /* real settings use this to reset to default */ + { + int i=0, count=0; + reset_setting(temp, temp->setting); + for(i=0;isetting == i) + { + gui_synclist_select_item(lists, count-1); + break; + } + } + return ACTION_REDRAW; + } + } + return action; +} +int quickscreen_set_option(void *data) +{ + int valid_settings_count = 0; + int i, newval = 0, oldval, *setting = NULL; + struct simplelist_info info; + switch ((intptr_t)data) + { + case QUICKSCREEN_LEFT: + setting = &global_settings.qs_item_left; + break; + case QUICKSCREEN_RIGHT: + setting = &global_settings.qs_item_right; + break; + case QUICKSCREEN_BOTTOM: + setting = &global_settings.qs_item_bottom; + break; + } + oldval = *setting; + for(i=0;i + + id: LANG_QS_ITEMS + desc: used for the submenu name for the quickscreen items + user: + + *: none + quickscreen: "Quickscreen Items" + + + *: none + quickscreen: "Quickscreen Items" + + + *: none + quickscreen: "Quickscreen Items" + + + + id: LANG_LEFT + desc: used for the submenu name for the quickscreen items + user: + + *: none + quickscreen: "Left" + + + *: none + quickscreen: "Left" + + + *: none + quickscreen: "Left" + + + + id: LANG_RIGHT + desc: used for the submenu name for the quickscreen items + user: + + *: none + quickscreen: "Right" + + + *: none + quickscreen: "Right" + + + *: none + quickscreen: "Right" + + + + id: LANG_BOTTOM + desc: used for the submenu name for the quickscreen items + user: + + *: none + quickscreen: "Bottom" + + + *: none + quickscreen: "Bottom" + + + *: none + quickscreen: "Bottom" + + diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 60fc9c0cc0..1610cfbef1 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -49,6 +49,7 @@ #if CONFIG_RTC #include "screens.h" #endif +#include "quickscreen.h" /***********************************/ /* TAGCACHE MENU */ @@ -486,7 +487,25 @@ MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice, /* VOICE MENU */ /***********************************/ +#ifdef HAVE_QUICKSCREEN /***********************************/ +/* CUSTOMISABLE QUICKSCREEN CODE */ + +MENUITEM_FUNCTION(qs_left_item, MENU_FUNC_USEPARAM, ID2P(LANG_LEFT), + (menu_function)quickscreen_set_option, (intptr_t*)QUICKSCREEN_LEFT, NULL, + Icon_Menu_setting); +MENUITEM_FUNCTION(qs_right_item, MENU_FUNC_USEPARAM, ID2P(LANG_RIGHT), + (menu_function)quickscreen_set_option, (intptr_t*)QUICKSCREEN_RIGHT, NULL, + Icon_Menu_setting); +MENUITEM_FUNCTION(qs_bottom_item, MENU_FUNC_USEPARAM, ID2P(LANG_BOTTOM), + (menu_function)quickscreen_set_option, (intptr_t*)QUICKSCREEN_BOTTOM, NULL, + Icon_Menu_setting); + +MAKE_MENU(quickscreen_settings, ID2P(LANG_QS_ITEMS), NULL, Icon_Config, + &qs_left_item, &qs_right_item, &qs_bottom_item); +/* CUSTOMISABLE QUICKSCREEN CODE */ +/***********************************/ +#endif /***********************************/ /* SETTINGS MENU */ @@ -500,6 +519,9 @@ MENUITEM_FUNCTION(browse_langs, 0, ID2P(LANG_LANGUAGE), language_browse, MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0, Icon_General_settings_menu, &playlist_settings, &file_menu, +#ifdef HAVE_QUICKSCREEN + &quickscreen_settings, +#endif #ifdef HAVE_TAGCACHE &tagcache_menu, #endif diff --git a/apps/settings.h b/apps/settings.h index 8c206053aa..8448059308 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -751,6 +751,12 @@ struct user_settings #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING int touchpad_sensitivity; #endif +#ifdef HAVE_QUICKSCREEN + /* these are split because settings_list cant handle arrays */ + int qs_item_left; + int qs_item_right; + int qs_item_bottom; +#endif }; /** global variables **/ diff --git a/apps/settings_list.c b/apps/settings_list.c index 99a4601a3f..7bdf4f4ce9 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -409,6 +409,45 @@ static int32_t jumpscroll_getlang(int value, int unit) } #endif /* HAVE_LCD_CHARCELLS */ +#ifdef HAVE_QUICKSCREEN +int find_setting_by_name(char*name) +{ + int i = 0; + const struct settings_list *setting; + while (icfg_name && !strcmp(setting->cfg_name, name)) + { + return i; + } + i++; + } + return -1; +} +void qs_load_from_cfg(void* var, char*value) +{ + *(int*)var = find_setting_by_name(value); +} +char* qs_write_to_cfg(void* setting, char*buf, int buf_len) +{ + const struct settings_list *var = &settings[*(int*)setting]; + strncpy(buf, var->cfg_name, buf_len); + return buf; +} +bool qs_is_changed(void* setting, void* defaultval) +{ + int i = *(int*)setting; + if (i < 0 || i >= nb_settings) + return false; + const struct settings_list *var = &settings[i]; + return var != find_setting(defaultval, NULL); +} +void qs_set_default(void* setting, void* defaultval) +{ + find_setting(defaultval, (int*)setting); +} +#endif const struct settings_list settings[] = { /* sound settings */ SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), @@ -1372,6 +1411,20 @@ const struct settings_list settings[] = { "touchpad sensitivity", "normal,high", touchpad_set_sensitivity, 2, ID2P(LANG_NORMAL), ID2P(LANG_HIGH)), #endif +#ifdef HAVE_QUICKSCREEN + CUSTOM_SETTING(0, qs_item_left, LANG_LEFT, + &global_settings.playlist_shuffle, "qs left", + qs_load_from_cfg, qs_write_to_cfg, + qs_is_changed, qs_set_default), + CUSTOM_SETTING(0, qs_item_right, LANG_RIGHT, + &global_settings.repeat_mode, "qs right", + qs_load_from_cfg, qs_write_to_cfg, + qs_is_changed, qs_set_default), + CUSTOM_SETTING(0, qs_item_bottom, LANG_BOTTOM, + &global_settings.dirfilter, "qs bottom", + qs_load_from_cfg, qs_write_to_cfg, + qs_is_changed, qs_set_default), +#endif }; const int nb_settings = sizeof(settings)/sizeof(*settings); diff --git a/apps/settings_list.h b/apps/settings_list.h index 60e3f7f0c7..1bc529c7d9 100644 --- a/apps/settings_list.h +++ b/apps/settings_list.h @@ -152,8 +152,10 @@ struct custom_setting { #define F_PADTITLE 0x800 /* pad the title with spaces to force it to scroll */ #define F_NO_WRAP 0x1000 /* used if the list should not wrap */ +#define F_BANFROMQS 0x80000000 /* ban the setting from the quickscreen items */ + struct settings_list { - uint32_t flags; /* ____ _SER TFFF NNN_ _ATW PTVC IFRB STTT */ + uint32_t flags; /* B___ _SER TFFF NNN_ _ATW PTVC IFRB STTT */ void *setting; int lang_id; /* -1 for none */ union storage_type default_val;