From 53804dfa168d0a2a894b1f6dfa3ac5a08649219f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 15 Oct 2014 08:04:10 +0200 Subject: [PATCH] (Menu) Implement deferred push callback --- frontend/menu/backend/menu_backend.h | 2 + frontend/menu/menu_entries.c | 73 +-------- frontend/menu/menu_entries_cbs.c | 220 +++++++++++++++++++++++++++ 3 files changed, 225 insertions(+), 70 deletions(-) diff --git a/frontend/menu/backend/menu_backend.h b/frontend/menu/backend/menu_backend.h index 1bf1f7fd7a..e93dae9535 100644 --- a/frontend/menu/backend/menu_backend.h +++ b/frontend/menu/backend/menu_backend.h @@ -7,6 +7,8 @@ extern "C" { typedef struct menu_file_list_cbs { + int (*action_deferred_push)(void *data, void *userdata, const char + *path, const char *label, unsigned type); int (*action_ok)(const char *path, const char *label, unsigned type, size_t index); int (*action_start)(unsigned type, const char *label, unsigned action); diff --git a/frontend/menu/menu_entries.c b/frontend/menu/menu_entries.c index 5663051191..42fd66c292 100644 --- a/frontend/menu/menu_entries.c +++ b/frontend/menu/menu_entries.c @@ -17,7 +17,6 @@ #include "menu_entries.h" #include "menu_action.h" #include "../../settings_data.h" -#include "../../file_ext.h" #include "../../performance.h" static void entries_refresh(file_list_t *list) @@ -784,90 +783,24 @@ static int menu_parse_check(const char *label, unsigned menu_type) return 0; } - int menu_entries_deferred_push(file_list_t *list, file_list_t *menu_list) { - unsigned type = 0, default_type_plain = MENU_FILE_PLAIN; + unsigned type = 0; const char *path = NULL; const char *label = NULL; - const char *exts = NULL; menu_file_list_cbs_t *cbs = NULL; - char ext_buf[PATH_MAX]; file_list_get_last(menu_list, &path, &label, &type); -#if 0 - RARCH_LOG("label: %s\n", label); -#endif - if (((menu_parse_check(label, type)) == -1)) return push_list(driver.menu, list, path, label, type); cbs = (menu_file_list_cbs_t*) file_list_get_last_actiondata(menu_list); - (void)cbs; - - //RARCH_LOG("LABEL: %s\n", label); - if (!strcmp(label, "core_list")) - exts = EXT_EXECUTABLES; - else if (!strcmp(label, "configurations")) - { - exts = "cfg"; - default_type_plain = MENU_FILE_CONFIG; - } - else if (!strcmp(label, "video_shader_preset")) - { - exts = "cgp|glslp"; - default_type_plain = MENU_FILE_SHADER_PRESET; - } - else if (!strcmp(label, "video_shader_pass")) - { - exts = "cg|glsl"; - default_type_plain = MENU_FILE_SHADER; - } - else if (!strcmp(label, "video_filter")) - { - exts = "filt"; - default_type_plain = MENU_FILE_VIDEOFILTER; - } - else if (!strcmp(label, "audio_dsp_plugin")) - { - exts = "dsp"; - default_type_plain = MENU_FILE_AUDIOFILTER; - } - else if (!strcmp(label, "input_overlay")) - { - exts = "cfg"; - default_type_plain = MENU_FILE_OVERLAY; - } - else if (!strcmp(label, "video_font_path")) - { - exts = "ttf"; - default_type_plain = MENU_FILE_FONT; - } - else if (!strcmp(label, "game_history_path")) - exts = "cfg"; - else if (menu_common_type_is(label, type) == MENU_FILE_DIRECTORY) - exts = ""; /* we ignore files anyway */ - else if (!strcmp(label, "detect_core_list")) - exts = g_extern.core_info ? core_info_list_get_all_extensions( - g_extern.core_info) : ""; - else if (g_extern.menu.info.valid_extensions) - { - exts = ext_buf; - if (*g_extern.menu.info.valid_extensions) - snprintf(ext_buf, sizeof(ext_buf), "%s", - g_extern.menu.info.valid_extensions); - else - *ext_buf = '\0'; - } - else - exts = g_extern.system.valid_extensions; - - menu_entries_parse_list(list, menu_list, path, label, - type, default_type_plain, exts); + if (cbs->action_deferred_push) + return cbs->action_deferred_push(list, menu_list, path, label, type); return 0; } diff --git a/frontend/menu/menu_entries_cbs.c b/frontend/menu/menu_entries_cbs.c index 6b702ce1f3..e4f53aa006 100644 --- a/frontend/menu/menu_entries_cbs.c +++ b/frontend/menu/menu_entries_cbs.c @@ -21,6 +21,7 @@ #include "menu_shader.h" #include "backend/menu_backend.h" +#include "../../file_ext.h" #include "../../config.def.h" #include "../../performance.h" @@ -1309,6 +1310,191 @@ static int action_start_bind(unsigned type, const char *label, return 0; } +static int deferred_push_core_list(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_PLAIN, EXT_EXECUTABLES); + + return 0; +} + +static int deferred_push_configurations(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_CONFIG, "cfg"); + + return 0; +} + +static int deferred_push_video_shader_preset(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_SHADER_PRESET, "cgp|glslp"); + + return 0; +} + +static int deferred_push_video_shader_pass(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_SHADER, "cg|glsl"); + + return 0; +} + +static int deferred_push_video_filter(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_VIDEOFILTER, "filt"); + + return 0; +} + +static int deferred_push_audio_dsp_plugin(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_AUDIOFILTER, "dsp"); + + return 0; +} + +static int deferred_push_input_overlay(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_OVERLAY, "cfg"); + + return 0; +} + +static int deferred_push_video_font_path(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_FONT, "ttf"); + + return 0; +} + +static int deferred_push_content_history_path(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_PLAIN, "cfg"); + + return 0; +} + +static int deferred_push_detect_core_list(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + const char *exts = NULL; + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + exts = g_extern.core_info ? core_info_list_get_all_extensions( + g_extern.core_info) : ""; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_PLAIN, exts); + + return 0; +} + +static int deferred_push_default(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + char ext_buf[PATH_MAX]; + const char *exts = NULL; + file_list_t *list = (file_list_t*)data; + file_list_t *menu_list = (file_list_t*)userdata; + + if (!list || !menu_list) + return -1; + + if (menu_common_type_is(label, type) == MENU_FILE_DIRECTORY) + exts = ""; /* we ignore files anyway */ + else if (g_extern.menu.info.valid_extensions) + { + exts = ext_buf; + if (*g_extern.menu.info.valid_extensions) + snprintf(ext_buf, sizeof(ext_buf), "%s", + g_extern.menu.info.valid_extensions); + else + *ext_buf = '\0'; + } + else + exts = g_extern.system.valid_extensions; + + menu_entries_parse_list(list, menu_list, path, label, + type, MENU_FILE_PLAIN, exts); + + return 0; +} + /* Bind the OK callback function */ static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs, @@ -1516,6 +1702,39 @@ static void menu_entries_cbs_init_bind_toggle(menu_file_list_cbs_t *cbs, } } +static void menu_entries_cbs_init_bind_deferred_push(menu_file_list_cbs_t *cbs, + const char *path, const char *label, unsigned type, size_t index) +{ + const char *menu_label = NULL; + if (!cbs || !driver.menu) + return; + + file_list_get_last(driver.menu->menu_stack, NULL, &menu_label, NULL); + + cbs->action_deferred_push = deferred_push_default; + + if (!strcmp(label, "core_list")) + cbs->action_deferred_push = deferred_push_core_list; + else if (!strcmp(label, "configurations")) + cbs->action_deferred_push = deferred_push_configurations; + else if (!strcmp(label, "video_shader_preset")) + cbs->action_deferred_push = deferred_push_video_shader_preset; + else if (!strcmp(label, "video_shader_pass")) + cbs->action_deferred_push = deferred_push_video_shader_pass; + else if (!strcmp(label, "video_filter")) + cbs->action_deferred_push = deferred_push_video_filter; + else if (!strcmp(label, "audio_dsp_plugin")) + cbs->action_deferred_push = deferred_push_audio_dsp_plugin; + else if (!strcmp(label, "input_overlay")) + cbs->action_deferred_push = deferred_push_input_overlay; + else if (!strcmp(label, "video_font_path")) + cbs->action_deferred_push = deferred_push_video_font_path; + else if (!strcmp(label, "game_history_path")) + cbs->action_deferred_push = deferred_push_content_history_path; + else if (!strcmp(label, "detect_core_list")) + cbs->action_deferred_push = deferred_push_detect_core_list; +} + void menu_entries_cbs_init(void *data, const char *path, const char *label, unsigned type, size_t index) @@ -1533,5 +1752,6 @@ void menu_entries_cbs_init(void *data, menu_entries_cbs_init_bind_ok(cbs, path, label, type, index); menu_entries_cbs_init_bind_start(cbs, path, label, type, index); menu_entries_cbs_init_bind_toggle(cbs, path, label, type, index); + menu_entries_cbs_init_bind_deferred_push(cbs, path, label, type, index); } }