summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-12-15 03:07:18 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2022-12-16 01:44:05 -0500
commit28f768cb8421025c15f1970d2724d467f845f055 (patch)
tree9942124a1e8117605e10dd05a6dcf46b781872ae
parent31759c9e53761eac75a33d6d702d43c76d942ae8 (diff)
downloadrockbox-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
-rw-r--r--apps/onplay.c153
-rw-r--r--apps/onplay.h23
-rw-r--r--apps/settings_list.c6
3 files changed, 103 insertions, 79 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
1850struct 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. */
1862static struct hotkey_assignment hotkey_items[] = { 1854static 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 */ 1921const struct hotkey_assignment *get_hotkey(int action)
1903int 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 */
1916static int execute_hotkey(bool is_wps) 1932static 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
diff --git a/apps/onplay.h b/apps/onplay.h
index 80e0371eaf..98d93b368c 100644
--- a/apps/onplay.h
+++ b/apps/onplay.h
@@ -21,6 +21,10 @@
21#ifndef _ONPLAY_H_ 21#ifndef _ONPLAY_H_
22#define _ONPLAY_H_ 22#define _ONPLAY_H_
23 23
24#ifdef HAVE_HOTKEY
25#include "menu.h"
26#endif
27
24int onplay(char* file, int attr, int from_screen, bool hotkey); 28int onplay(char* file, int attr, int from_screen, bool hotkey);
25int get_onplay_context(void); 29int get_onplay_context(void);
26 30
@@ -37,15 +41,12 @@ enum {
37}; 41};
38 42
39#ifdef HAVE_HOTKEY 43#ifdef HAVE_HOTKEY
40int get_hotkey_lang_id(int action);
41 44
42enum hotkey_action { 45enum hotkey_action {
43 HOTKEY_OFF = 0, 46 HOTKEY_OFF = 0,
44 HOTKEY_VIEW_PLAYLIST, 47 HOTKEY_VIEW_PLAYLIST,
45 HOTKEY_PROPERTIES, 48 HOTKEY_PROPERTIES,
46#ifdef HAVE_TAGCACHE
47 HOTKEY_PICTUREFLOW, 49 HOTKEY_PICTUREFLOW,
48#endif
49 HOTKEY_SHOW_TRACK_INFO, 50 HOTKEY_SHOW_TRACK_INFO,
50 HOTKEY_PITCHSCREEN, 51 HOTKEY_PITCHSCREEN,
51 HOTKEY_OPEN_WITH, 52 HOTKEY_OPEN_WITH,
@@ -55,6 +56,22 @@ enum hotkey_action {
55 HOTKEY_INSERT, 56 HOTKEY_INSERT,
56 HOTKEY_INSERT_SHUFFLED, 57 HOTKEY_INSERT_SHUFFLED,
57}; 58};
59enum hotkey_flags {
60 HOTKEY_FLAG_NONE = 0x0,
61 HOTKEY_FLAG_WPS = 0x1,
62 HOTKEY_FLAG_TREE = 0x2,
63 HOTKEY_FLAG_NOSBS = 0x4,
64};
65
66struct hotkey_assignment {
67 int action; /* hotkey_action */
68 int lang_id; /* Language ID */
69 struct menu_func func; /* Function to run if this entry is selected */
70 int16_t return_code; /* What to return after the function is run. */
71 uint16_t flags; /* Flags what context, display options */
72}; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */
73
74const struct hotkey_assignment *get_hotkey(int action);
58#endif 75#endif
59 76
60/* needed for the playlist viewer.. eventually clean this up */ 77/* needed for the playlist viewer.. eventually clean this up */
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 4771306393..ae98ae0187 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -700,7 +700,7 @@ static void hotkey_callback(int var)
700{ 700{
701 if (get_current_activity() != ACTIVITY_QUICKSCREEN) 701 if (get_current_activity() != ACTIVITY_QUICKSCREEN)
702 { 702 {
703 if (get_hotkey_lang_id(var) == LANG_OPEN_PLUGIN) 703 if (get_hotkey(var)->action == HOTKEY_PLUGIN)
704 open_plugin_browse(ID2P(LANG_HOTKEY_WPS)); 704 open_plugin_browse(ID2P(LANG_HOTKEY_WPS));
705 } 705 }
706} 706}
@@ -710,12 +710,12 @@ static const char* hotkey_formatter(char* buffer, size_t buffer_size, int value,
710 (void)buffer; 710 (void)buffer;
711 (void)buffer_size; 711 (void)buffer_size;
712 (void)unit; 712 (void)unit;
713 return str(get_hotkey_lang_id(value)); 713 return str(get_hotkey(value)->lang_id);
714} 714}
715static int32_t hotkey_getlang(int value, int unit) 715static int32_t hotkey_getlang(int value, int unit)
716{ 716{
717 (void)unit; 717 (void)unit;
718 return get_hotkey_lang_id(value); 718 return get_hotkey(value)->lang_id;
719} 719}
720#endif /* HAVE_HOTKEY */ 720#endif /* HAVE_HOTKEY */
721 721