diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-12-15 03:07:18 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-12-16 01:44:05 -0500 |
commit | 28f768cb8421025c15f1970d2724d467f845f055 (patch) | |
tree | 9942124a1e8117605e10dd05a6dcf46b781872ae /apps/onplay.c | |
parent | 31759c9e53761eac75a33d6d702d43c76d942ae8 (diff) | |
download | rockbox-28f768cb8421025c15f1970d2724d467f845f055.tar.gz rockbox-28f768cb8421025c15f1970d2724d467f845f055.zip |
onplay hotkey add flags
idea here as discussed with chris_s is to allow flags
in the hotkey_assignment struct to change how items are displayed
Change-Id: Id4cf1d79fbe3ff8f5590b9a863fccf00ddd457f9
Diffstat (limited to 'apps/onplay.c')
-rw-r--r-- | apps/onplay.c | 153 |
1 files changed, 80 insertions, 73 deletions
diff --git a/apps/onplay.c b/apps/onplay.c index 0fae795fb3..f89c3c9474 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -1846,106 +1846,113 @@ static int hotkey_wps_run_plugin(void) | |||
1846 | open_plugin_run(ID2P(LANG_HOTKEY_WPS)); | 1846 | open_plugin_run(ID2P(LANG_HOTKEY_WPS)); |
1847 | return ONPLAY_OK; | 1847 | return ONPLAY_OK; |
1848 | } | 1848 | } |
1849 | |||
1850 | struct hotkey_assignment { | ||
1851 | int action; /* hotkey_action */ | ||
1852 | int lang_id; /* Language ID */ | ||
1853 | struct menu_func func; /* Function to run if this entry is selected */ | ||
1854 | int return_code; /* What to return after the function is run. */ | ||
1855 | }; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */ | ||
1856 | |||
1857 | #define HOTKEY_FUNC(func, param) {{(void *)func}, param} | 1849 | #define HOTKEY_FUNC(func, param) {{(void *)func}, param} |
1858 | 1850 | ||
1859 | /* Any desired hotkey functions go here, in the enum in onplay.h, | 1851 | /* Any desired hotkey functions go here, in the enum in onplay.h, |
1860 | and in the settings menu in settings_list.c. The order here | 1852 | and in the settings menu in settings_list.c. The order here |
1861 | is not important. */ | 1853 | is not important. */ |
1862 | static struct hotkey_assignment hotkey_items[] = { | 1854 | static const struct hotkey_assignment hotkey_items[] = { |
1863 | { HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST, | 1855 | [0]{ .action = HOTKEY_OFF, |
1864 | HOTKEY_FUNC(NULL, NULL), | 1856 | .lang_id = LANG_OFF, |
1865 | ONPLAY_PLAYLIST }, | 1857 | .func = HOTKEY_FUNC(NULL,NULL), |
1866 | { HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO, | 1858 | .return_code = ONPLAY_RELOAD_DIR, |
1867 | HOTKEY_FUNC(browse_id3_wrapper, NULL), | 1859 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, |
1868 | ONPLAY_RELOAD_DIR }, | 1860 | { .action = HOTKEY_VIEW_PLAYLIST, |
1861 | .lang_id = LANG_VIEW_DYNAMIC_PLAYLIST, | ||
1862 | .func = HOTKEY_FUNC(NULL, NULL), | ||
1863 | .return_code = ONPLAY_PLAYLIST, | ||
1864 | .flags = HOTKEY_FLAG_WPS }, | ||
1865 | { .action = HOTKEY_SHOW_TRACK_INFO, | ||
1866 | .lang_id = LANG_MENU_SHOW_ID3_INFO, | ||
1867 | .func = HOTKEY_FUNC(browse_id3_wrapper, NULL), | ||
1868 | .return_code = ONPLAY_RELOAD_DIR, | ||
1869 | .flags = HOTKEY_FLAG_WPS }, | ||
1869 | #ifdef HAVE_PITCHCONTROL | 1870 | #ifdef HAVE_PITCHCONTROL |
1870 | { HOTKEY_PITCHSCREEN, LANG_PITCH, | 1871 | { .action = HOTKEY_PITCHSCREEN, |
1871 | HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), | 1872 | .lang_id = LANG_PITCH, |
1872 | ONPLAY_RELOAD_DIR }, | 1873 | .func = HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), |
1874 | .return_code = ONPLAY_RELOAD_DIR, | ||
1875 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, | ||
1873 | #endif | 1876 | #endif |
1874 | { HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH, | 1877 | { .action = HOTKEY_OPEN_WITH, |
1875 | HOTKEY_FUNC(hotkey_open_with, NULL), | 1878 | .lang_id = LANG_ONPLAY_OPEN_WITH, |
1876 | ONPLAY_RELOAD_DIR }, | 1879 | .func = HOTKEY_FUNC(hotkey_open_with, NULL), |
1877 | { HOTKEY_DELETE, LANG_DELETE, | 1880 | .return_code = ONPLAY_RELOAD_DIR, |
1878 | HOTKEY_FUNC(hotkey_delete_item, NULL), | 1881 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, |
1879 | ONPLAY_RELOAD_DIR }, | 1882 | { .action = HOTKEY_DELETE, |
1880 | { HOTKEY_INSERT, LANG_INSERT, | 1883 | .lang_id = LANG_DELETE, |
1881 | HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), | 1884 | .func = HOTKEY_FUNC(hotkey_delete_item, NULL), |
1882 | ONPLAY_RELOAD_DIR }, | 1885 | .return_code = ONPLAY_RELOAD_DIR, |
1883 | { HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED, | 1886 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, |
1884 | HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL), | 1887 | { .action = HOTKEY_INSERT, |
1885 | ONPLAY_FUNC_RETURN }, | 1888 | .lang_id = LANG_INSERT, |
1886 | { HOTKEY_PLUGIN, LANG_OPEN_PLUGIN, | 1889 | .func = HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), |
1887 | HOTKEY_FUNC(hotkey_wps_run_plugin, NULL), | 1890 | .return_code = ONPLAY_RELOAD_DIR, |
1888 | ONPLAY_FUNC_RETURN }, | 1891 | .flags = HOTKEY_FLAG_TREE }, |
1889 | { HOTKEY_BOOKMARK, LANG_BOOKMARK_MENU_CREATE, | 1892 | { .action = HOTKEY_INSERT_SHUFFLED, |
1890 | HOTKEY_FUNC(bookmark_create_menu, NULL), | 1893 | .lang_id = LANG_INSERT_SHUFFLED, |
1891 | ONPLAY_OK }, | 1894 | .func = HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL), |
1892 | { HOTKEY_PROPERTIES, LANG_PROPERTIES, | 1895 | .return_code = ONPLAY_FUNC_RETURN, |
1893 | HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), | 1896 | .flags = HOTKEY_FLAG_TREE }, |
1894 | ONPLAY_FUNC_RETURN }, | 1897 | { .action = HOTKEY_PLUGIN, |
1898 | .lang_id = LANG_OPEN_PLUGIN, | ||
1899 | .func = HOTKEY_FUNC(hotkey_wps_run_plugin, NULL), | ||
1900 | .return_code = ONPLAY_FUNC_RETURN, | ||
1901 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, | ||
1902 | { .action = HOTKEY_BOOKMARK, | ||
1903 | .lang_id = LANG_BOOKMARK_MENU_CREATE, | ||
1904 | .func = HOTKEY_FUNC(bookmark_create_menu, NULL), | ||
1905 | .return_code = ONPLAY_OK, | ||
1906 | .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, | ||
1907 | { .action = HOTKEY_PROPERTIES, | ||
1908 | .lang_id = LANG_PROPERTIES, | ||
1909 | .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), | ||
1910 | .return_code = ONPLAY_FUNC_RETURN, | ||
1911 | .flags = HOTKEY_FLAG_TREE }, | ||
1895 | #ifdef HAVE_TAGCACHE | 1912 | #ifdef HAVE_TAGCACHE |
1896 | { HOTKEY_PICTUREFLOW, LANG_ONPLAY_PICTUREFLOW, | 1913 | { .action = HOTKEY_PICTUREFLOW, |
1897 | HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"), | 1914 | .lang_id = LANG_ONPLAY_PICTUREFLOW, |
1898 | ONPLAY_FUNC_RETURN }, | 1915 | .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"), |
1916 | .return_code = ONPLAY_FUNC_RETURN, | ||
1917 | .flags = HOTKEY_FLAG_TREE }, | ||
1899 | #endif | 1918 | #endif |
1900 | }; | 1919 | }; |
1901 | 1920 | ||
1902 | /* Return the language ID for this action */ | 1921 | const struct hotkey_assignment *get_hotkey(int action) |
1903 | int get_hotkey_lang_id(int action) | ||
1904 | { | 1922 | { |
1905 | int i = ARRAYLEN(hotkey_items); | 1923 | for (size_t i = ARRAYLEN(hotkey_items) - 1; i < ARRAYLEN(hotkey_items); i--) |
1906 | while (i--) | ||
1907 | { | 1924 | { |
1908 | if (hotkey_items[i].action == action) | 1925 | if (hotkey_items[i].action == action) |
1909 | return hotkey_items[i].lang_id; | 1926 | return &hotkey_items[i]; |
1910 | } | 1927 | } |
1911 | 1928 | return &hotkey_items[0]; /* no valid hotkey set, return HOTKEY_OFF*/ | |
1912 | return LANG_OFF; | ||
1913 | } | 1929 | } |
1914 | 1930 | ||
1915 | /* Execute the hotkey function, if listed */ | 1931 | /* Execute the hotkey function, if listed */ |
1916 | static int execute_hotkey(bool is_wps) | 1932 | static int execute_hotkey(bool is_wps) |
1917 | { | 1933 | { |
1918 | int i = ARRAYLEN(hotkey_items); | ||
1919 | struct hotkey_assignment *this_item; | ||
1920 | const int action = (is_wps ? global_settings.hotkey_wps : | 1934 | const int action = (is_wps ? global_settings.hotkey_wps : |
1921 | global_settings.hotkey_tree); | 1935 | global_settings.hotkey_tree); |
1922 | 1936 | ||
1923 | /* search assignment struct for a match for the hotkey setting */ | 1937 | /* search assignment struct for a match for the hotkey setting */ |
1924 | while (i--) | 1938 | const struct hotkey_assignment *this_item = get_hotkey(action); |
1925 | { | ||
1926 | this_item = &hotkey_items[i]; | ||
1927 | if (this_item->action == action) | ||
1928 | { | ||
1929 | /* run the associated function (with optional param), if any */ | ||
1930 | const struct menu_func func = this_item->func; | ||
1931 | int func_return = ONPLAY_RELOAD_DIR; | ||
1932 | if (func.function != NULL) | ||
1933 | { | ||
1934 | if (func.param != NULL) | ||
1935 | func_return = (*func.function_w_param)(func.param); | ||
1936 | else | ||
1937 | func_return = (*func.function)(); | ||
1938 | } | ||
1939 | const int return_code = this_item->return_code; | ||
1940 | 1939 | ||
1941 | if (return_code == ONPLAY_FUNC_RETURN) | 1940 | /* run the associated function (with optional param), if any */ |
1942 | return func_return; /* Use value returned by function */ | 1941 | const struct menu_func func = this_item->func; |
1943 | return return_code; /* or return the associated value */ | 1942 | |
1944 | } | 1943 | int func_return = ONPLAY_RELOAD_DIR; |
1944 | if (func.function != NULL) | ||
1945 | { | ||
1946 | if (func.param != NULL) | ||
1947 | func_return = (*func.function_w_param)(func.param); | ||
1948 | else | ||
1949 | func_return = (*func.function)(); | ||
1945 | } | 1950 | } |
1951 | const int return_code = this_item->return_code; | ||
1946 | 1952 | ||
1947 | /* no valid hotkey set, ignore hotkey */ | 1953 | if (return_code == ONPLAY_FUNC_RETURN) |
1948 | return ONPLAY_RELOAD_DIR; | 1954 | return func_return; /* Use value returned by function */ |
1955 | return return_code; /* or return the associated value */ | ||
1949 | } | 1956 | } |
1950 | #endif /* HOTKEY */ | 1957 | #endif /* HOTKEY */ |
1951 | 1958 | ||