From 403e00a93690387ff4c9df7d4d3e57ec5280c210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sun, 25 Oct 2015 00:37:59 +0700 Subject: [PATCH] (XMB) Implement another tab to launch a directory scan --- menu/cbs/menu_cbs_left.c | 1 + menu/cbs/menu_cbs_right.c | 2 +- menu/drivers/xmb.c | 158 ++++++++++++++++---------------------- menu/intl/menu_hash_us.c | 2 + menu/menu.h | 1 + menu/menu_displaylist.c | 30 +++++++- menu/menu_displaylist.h | 1 + menu/menu_hash.h | 1 + 8 files changed, 103 insertions(+), 93 deletions(-) diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 6d49179a98..9a8ef0e5fa 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -477,6 +477,7 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs, case MENU_VALUE_HORIZONTAL_MENU: case MENU_VALUE_MAIN_MENU: case MENU_VALUE_HISTORY_TAB: + case MENU_VALUE_ADD_TAB: BIND_ACTION_LEFT(cbs, action_left_mainmenu); break; default: diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index f9011a4170..4d35f62aa9 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -164,7 +164,7 @@ static int action_right_mainmenu(unsigned type, const char *label, if (list_size == 1) { menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); - if (menu_driver_list_get_selection() != (menu_driver_list_get_size(MENU_LIST_HORIZONTAL) + 2)) + if (menu_driver_list_get_selection() != (menu_driver_list_get_size(MENU_LIST_HORIZONTAL) + 3)) push_list = 1; } else diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index fa6cb720b0..a0d501cabd 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -95,6 +95,7 @@ enum XMB_TEXTURE_SWITCH_OFF, XMB_TEXTURE_CLOCK, XMB_TEXTURE_POINTER, + XMB_TEXTURE_ADD, XMB_TEXTURE_LAST }; @@ -102,10 +103,11 @@ enum { XMB_SYSTEM_TAB_MAIN = 0, XMB_SYSTEM_TAB_SETTINGS, - XMB_SYSTEM_TAB_HISTORY + XMB_SYSTEM_TAB_HISTORY, + XMB_SYSTEM_TAB_ADD }; -#define XMB_SYSTEM_TAB_END XMB_SYSTEM_TAB_HISTORY +#define XMB_SYSTEM_TAB_END XMB_SYSTEM_TAB_ADD struct xmb_texture_item { @@ -235,6 +237,7 @@ typedef struct xmb_handle xmb_node_t main_menu_node; xmb_node_t settings_tab_node; xmb_node_t history_tab_node; + xmb_node_t add_tab_node; bool prevent_populate; gfx_font_raster_block_t raster_block; @@ -774,7 +777,7 @@ static xmb_node_t *xmb_node_allocate_userdata(xmb_handle_t *xmb, unsigned i) node->alpha = xmb->categories.passive.alpha; node->zoom = xmb->categories.passive.zoom; - if ((i + 2) == xmb->categories.active.idx) + if ((i + XMB_SYSTEM_TAB_END) == xmb->categories.active.idx) { node->alpha = xmb->categories.active.alpha; node->zoom = xmb->categories.active.zoom; @@ -871,57 +874,62 @@ static void xmb_list_switch_new(xmb_handle_t *xmb, static void xmb_set_title(xmb_handle_t *xmb) { - switch (xmb->categories.selection_ptr) + if (xmb->categories.selection_ptr <= XMB_SYSTEM_TAB_END) { - case 0: - case 1: - case 2: - menu_entries_get_title(xmb->title_name, sizeof(xmb->title_name)); + menu_entries_get_title(xmb->title_name, sizeof(xmb->title_name)); + } + else + { + const char *path = NULL; + menu_entries_get_at_offset( + xmb->horizontal_list, + xmb->categories.selection_ptr - (XMB_SYSTEM_TAB_END + 1), + &path, NULL, NULL, NULL, NULL); + + if (!path) + return; + + strlcpy(xmb->title_name, path, sizeof(xmb->title_name)); + + path_remove_extension(xmb->title_name); + } +} + +static xmb_node_t* xmb_get_node(xmb_handle_t *xmb, unsigned i) +{ + xmb_node_t *node = NULL; + + switch (i) + { + case XMB_SYSTEM_TAB_SETTINGS: + node = &xmb->settings_tab_node; + break; + case XMB_SYSTEM_TAB_HISTORY: + node = &xmb->history_tab_node; + break; + case XMB_SYSTEM_TAB_ADD: + node = &xmb->add_tab_node; break; default: - { - const char *path = NULL; - menu_entries_get_at_offset( - xmb->horizontal_list, - xmb->categories.selection_ptr - (XMB_SYSTEM_TAB_END + 1), - &path, NULL, NULL, NULL, NULL); - - if (!path) - return; - - strlcpy(xmb->title_name, path, sizeof(xmb->title_name)); - - path_remove_extension(xmb->title_name); - } + node = &xmb->main_menu_node; + if (i > XMB_SYSTEM_TAB_END) + node = xmb_get_userdata_from_horizontal_list(xmb, i - (XMB_SYSTEM_TAB_END + 1)); break; } + + return node; } static void xmb_list_switch_horizontal_list(xmb_handle_t *xmb, menu_handle_t *menu) { unsigned j; - size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + 2; + size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END; for (j = 0; j <= list_size; j++) { float ia = xmb->categories.passive.alpha; float iz = xmb->categories.passive.zoom; - xmb_node_t *node = NULL; - - switch (j) - { - case XMB_SYSTEM_TAB_SETTINGS: - node = &xmb->settings_tab_node; - break; - case XMB_SYSTEM_TAB_HISTORY: - node = &xmb->history_tab_node; - break; - default: - node = &xmb->main_menu_node; - if (j > XMB_SYSTEM_TAB_END) - node = xmb_get_userdata_from_horizontal_list(xmb, j - (XMB_SYSTEM_TAB_END + 1)); - break; - } + xmb_node_t *node = xmb_get_node(xmb, j); if (!node) continue; @@ -980,27 +988,12 @@ static void xmb_list_switch(xmb_handle_t *xmb) static void xmb_list_open_horizontal_list(xmb_handle_t *xmb, menu_handle_t *menu) { unsigned j; - size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + 2; + size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END; for (j = 0; j <= list_size; j++) { float ia = 0; - xmb_node_t *node = NULL; - - switch (j) - { - case XMB_SYSTEM_TAB_SETTINGS: - node = &xmb->settings_tab_node; - break; - case XMB_SYSTEM_TAB_HISTORY: - node = &xmb->history_tab_node; - break; - default: - node = &xmb->main_menu_node; - if (j > XMB_SYSTEM_TAB_END) - node = xmb_get_userdata_from_horizontal_list(xmb, j - (XMB_SYSTEM_TAB_END + 1)); - break; - } + xmb_node_t *node = xmb_get_node(xmb, j); if (!node) continue; @@ -1504,26 +1497,11 @@ static void xmb_frame_horizontal_list(xmb_handle_t *xmb, GRfloat *color) { unsigned i; - size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + 2; + size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END; for (i = 0; i <= list_size; i++) { - xmb_node_t *node = NULL; - - switch (i) - { - case XMB_SYSTEM_TAB_SETTINGS: - node = &xmb->settings_tab_node; - break; - case XMB_SYSTEM_TAB_HISTORY: - node = &xmb->history_tab_node; - break; - default: - node = &xmb->main_menu_node; - if (i > XMB_SYSTEM_TAB_END) - node = xmb_get_userdata_from_horizontal_list(xmb, i - (XMB_SYSTEM_TAB_END + 1)); - break; - } + xmb_node_t *node = xmb_get_node(xmb, i); if (!node) continue; @@ -2029,26 +2007,11 @@ static bool xmb_load_image(void *data, menu_image_type_t type) static void xmb_toggle_horizontal_list(xmb_handle_t *xmb, menu_handle_t *menu) { unsigned i; - size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + 2; + size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END; for (i = 0; i <= list_size; i++) { - xmb_node_t *node = &xmb->main_menu_node; - - switch (i) - { - case XMB_SYSTEM_TAB_SETTINGS: - node = &xmb->settings_tab_node; - break; - case XMB_SYSTEM_TAB_HISTORY: - node = &xmb->history_tab_node; - break; - default: - node = &xmb->main_menu_node; - if (i > XMB_SYSTEM_TAB_END) - node = xmb_get_userdata_from_horizontal_list(xmb, i - (XMB_SYSTEM_TAB_END + 1)); - break; - } + xmb_node_t *node = xmb_get_node(xmb, i); if (!node) continue; @@ -2238,6 +2201,9 @@ static void xmb_context_reset_textures(xmb_handle_t *xmb, const char *iconpath) case XMB_TEXTURE_SWITCH_OFF: fill_pathname_join(path, iconpath, "off.png", sizeof(path)); break; + case XMB_TEXTURE_ADD: + fill_pathname_join(path, iconpath, "add.png", sizeof(path)); + break; } if (path[0] == '\0' || !path_file_exists(path)) @@ -2262,6 +2228,10 @@ static void xmb_context_reset_textures(xmb_handle_t *xmb, const char *iconpath) xmb->history_tab_node.icon = xmb->textures.list[XMB_TEXTURE_HISTORY].id; xmb->history_tab_node.alpha = xmb->categories.active.alpha; xmb->history_tab_node.zoom = xmb->categories.active.zoom; + + xmb->add_tab_node.icon = xmb->textures.list[XMB_TEXTURE_ADD].id; + xmb->add_tab_node.alpha = xmb->categories.active.alpha; + xmb->add_tab_node.zoom = xmb->categories.active.zoom; } static void xmb_context_reset_background(const char *iconpath) @@ -2504,7 +2474,7 @@ static void xmb_list_cache(menu_list_type_t type, unsigned action) break; } - list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + 2; + list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END; if (xmb->categories.selection_ptr > list_size) { xmb->categories.selection_ptr = list_size; @@ -2537,6 +2507,12 @@ static void xmb_list_cache(menu_list_type_t type, unsigned action) menu_stack->list[stack_size - 1].type = MENU_HISTORY_TAB; break; + case XMB_SYSTEM_TAB_ADD: + menu_stack->list[stack_size - 1].label = + strdup(menu_hash_to_str(MENU_VALUE_ADD_TAB)); + menu_stack->list[stack_size - 1].type = + MENU_ADD_TAB; + break; default: menu_stack->list[stack_size - 1].label = strdup(menu_hash_to_str(MENU_VALUE_HORIZONTAL_MENU)); diff --git a/menu/intl/menu_hash_us.c b/menu/intl/menu_hash_us.c index 1fabdc7566..9fe66bd744 100644 --- a/menu/intl/menu_hash_us.c +++ b/menu/intl/menu_hash_us.c @@ -768,6 +768,8 @@ const char *menu_hash_to_str_us(uint32_t hash) return "Settings tab"; case MENU_VALUE_HISTORY_TAB: return "History tab"; + case MENU_VALUE_ADD_TAB: + return "Add tab"; case MENU_LABEL_VALUE_NO_SETTINGS_FOUND: return "No settings found."; case MENU_LABEL_VALUE_NO_PERFORMANCE_COUNTERS: diff --git a/menu/menu.h b/menu/menu.h index ab237d116b..1aeffcc692 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -100,6 +100,7 @@ typedef enum MENU_SETTINGS, MENU_SETTINGS_TAB, MENU_HISTORY_TAB, + MENU_ADD_TAB, MENU_SETTING_DRIVER, MENU_SETTING_ACTION, MENU_SETTING_ACTION_RUN, diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 0814e54125..7149b25cb3 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1593,7 +1593,7 @@ static int menu_displaylist_parse_horizontal_list(menu_displaylist_info_t *info) settings_t *settings = config_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr(); struct item_file *item = (struct item_file*) - menu_driver_list_get_entry(MENU_LIST_HORIZONTAL, menu_driver_list_get_selection() - 3); + menu_driver_list_get_entry(MENU_LIST_HORIZONTAL, menu_driver_list_get_selection() - 4); if (!item) return -1; @@ -1814,6 +1814,22 @@ static int menu_displaylist_parse_add_content_list(menu_displaylist_info_t *info return 0; } +static int menu_displaylist_parse_scan_directory_list(menu_displaylist_info_t *info) +{ + global_t *global = global_get_ptr(); + + (void)global; + +#ifdef HAVE_LIBRETRODB + menu_entries_push(info->list, + menu_hash_to_str(MENU_LABEL_VALUE_SCAN_DIRECTORY), + menu_hash_to_str(MENU_LABEL_SCAN_DIRECTORY), + MENU_SETTING_ACTION, 0, 0); +#endif + + return 0; +} + static int menu_displaylist_parse_load_content_list(menu_displaylist_info_t *info) { global_t *global = global_get_ptr(); @@ -2266,6 +2282,7 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) case DISPLAYLIST_CONTENT_SETTINGS: case DISPLAYLIST_INFORMATION_LIST: case DISPLAYLIST_ADD_CONTENT_LIST: + case DISPLAYLIST_SCAN_DIRECTORY_LIST: case DISPLAYLIST_LOAD_CONTENT_LIST: case DISPLAYLIST_USER_BINDS_LIST: case DISPLAYLIST_ACCOUNTS_LIST: @@ -2566,6 +2583,12 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) case DISPLAYLIST_ADD_CONTENT_LIST: ret = menu_displaylist_parse_add_content_list(info); + info->need_push = true; + info->need_refresh = true; + break; + case DISPLAYLIST_SCAN_DIRECTORY_LIST: + ret = menu_displaylist_parse_scan_directory_list(info); + info->need_push = true; info->need_refresh = true; break; @@ -3003,6 +3026,11 @@ int menu_displaylist_push(file_list_t *list, file_list_t *menu_list) return -1; menu_displaylist_push_list_process(&info); return 0; + case MENU_VALUE_ADD_TAB: + if (menu_displaylist_push_list(&info, DISPLAYLIST_SCAN_DIRECTORY_LIST) != 0) + return -1; + menu_displaylist_push_list_process(&info); + return 0; case MENU_VALUE_HORIZONTAL_MENU: if (menu_displaylist_push_list(&info, DISPLAYLIST_HORIZONTAL) != 0) return -1; diff --git a/menu/menu_displaylist.h b/menu/menu_displaylist.h index 07caec69a6..e6f88c4254 100644 --- a/menu/menu_displaylist.h +++ b/menu/menu_displaylist.h @@ -105,6 +105,7 @@ enum DISPLAYLIST_OPTIONS_DISK, DISPLAYLIST_OPTIONS_SHADERS, DISPLAYLIST_ADD_CONTENT_LIST, + DISPLAYLIST_SCAN_DIRECTORY_LIST, DISPLAYLIST_ARCHIVE_ACTION, DISPLAYLIST_ARCHIVE_ACTION_DETECT_CORE, DISPLAYLIST_CORE_CONTENT diff --git a/menu/menu_hash.h b/menu/menu_hash.h index a6fb425a85..19af87b5c7 100644 --- a/menu/menu_hash.h +++ b/menu/menu_hash.h @@ -564,6 +564,7 @@ extern "C" { #define MENU_VALUE_HORIZONTAL_MENU 0x35761704U #define MENU_VALUE_SETTINGS_TAB 0x6548d16dU #define MENU_VALUE_HISTORY_TAB 0xea9b0ceeU +#define MENU_VALUE_ADD_TAB 0x7fb20225U #define MENU_VALUE_MAIN_MENU 0x1625971fU #define MENU_LABEL_VALUE_SETTINGS 0x8aca3ff6U #define MENU_VALUE_INPUT_SETTINGS 0xddd30846U