diff options
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 212 |
1 files changed, 126 insertions, 86 deletions
diff --git a/apps/settings.c b/apps/settings.c index bb550ac929..1f8f15be1e 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -68,7 +68,6 @@ | |||
68 | #include "sound.h" | 68 | #include "sound.h" |
69 | #include "rbunicode.h" | 69 | #include "rbunicode.h" |
70 | #include "dircache.h" | 70 | #include "dircache.h" |
71 | #include "select.h" | ||
72 | #include "statusbar.h" | 71 | #include "statusbar.h" |
73 | #include "splash.h" | 72 | #include "splash.h" |
74 | #include "list.h" | 73 | #include "list.h" |
@@ -1852,113 +1851,154 @@ void talk_unit(int unit, int value) | |||
1852 | } | 1851 | } |
1853 | } | 1852 | } |
1854 | 1853 | ||
1855 | bool set_int(const unsigned char* string, | 1854 | struct value_setting_data { |
1856 | const char* unit, | 1855 | enum optiontype type; |
1857 | int voice_unit, | 1856 | /* used for "value" settings.. */ |
1858 | int* variable, | 1857 | int max; |
1859 | void (*function)(int), | 1858 | int step; |
1860 | int step, | 1859 | int voice_unit; |
1861 | int min, | 1860 | const char * unit; |
1862 | int max, | 1861 | void (*formatter)(char* dest, int dest_length, |
1863 | void (*formatter)(char*, int, int, const char*) ) | 1862 | int variable, const char* unit); |
1863 | /* used for BOOL and "choice" settings */ | ||
1864 | struct opt_items* options; | ||
1865 | }; | ||
1866 | |||
1867 | char * value_setting_get_name_cb(int selected_item,void * data, char *buffer) | ||
1864 | { | 1868 | { |
1865 | int button; | 1869 | struct value_setting_data* cb_data = |
1866 | int oldvalue=*variable; | 1870 | (struct value_setting_data*)data; |
1867 | struct gui_select select; | 1871 | if (cb_data->type == INT && !cb_data->options) |
1868 | gui_select_init_numeric(&select, (char *)string, *variable, min, max, step, unit, | ||
1869 | formatter); | ||
1870 | gui_syncselect_draw(&select); | ||
1871 | talk_unit(voice_unit, *variable); | ||
1872 | while (!select.validated) | ||
1873 | { | 1872 | { |
1874 | button = button_get_w_tmo(HZ/2); | 1873 | int item = cb_data->max -(selected_item*cb_data->step); |
1875 | if(gui_syncselect_do_button(&select, button)) | 1874 | if (cb_data->formatter) |
1876 | { | 1875 | cb_data->formatter(buffer, MAX_PATH,item,cb_data->unit); |
1877 | *variable=select.options.option; | 1876 | else |
1878 | gui_syncselect_draw(&select); | 1877 | snprintf(buffer, MAX_PATH,"%d %s",item,cb_data->unit); |
1879 | talk_unit(voice_unit, *variable); | ||
1880 | if ( function ) | ||
1881 | function(*variable); | ||
1882 | } | ||
1883 | gui_syncstatusbar_draw(&statusbars, false); | ||
1884 | if(select.canceled) | ||
1885 | { | ||
1886 | *variable=oldvalue; | ||
1887 | if ( function ) | ||
1888 | function(*variable); | ||
1889 | return false; | ||
1890 | } | ||
1891 | if(default_event_handler(button) == SYS_USB_CONNECTED) | ||
1892 | return true; | ||
1893 | } | 1878 | } |
1894 | return false; | 1879 | else strcpy(buffer,P2STR(cb_data->options[selected_item].string)); |
1895 | } | 1880 | return buffer; |
1896 | 1881 | } | |
1897 | /* NOTE: the 'type' parameter specifies the actual type of the variable | ||
1898 | that 'variable' points to. not the value within. Only variables with | ||
1899 | type 'bool' should use parameter BOOL. | ||
1900 | |||
1901 | The type separation is necessary since int and bool are fundamentally | ||
1902 | different and bit-incompatible types and can not share the same access | ||
1903 | code. */ | ||
1904 | |||
1905 | #define set_type_fromint(type, dest, value) \ | ||
1906 | if (type == INT) \ | ||
1907 | *(int *)dest=value; \ | ||
1908 | else \ | ||
1909 | *(bool *)dest=value?true:false | ||
1910 | |||
1911 | #define type_fromvoidptr(type, value) \ | 1882 | #define type_fromvoidptr(type, value) \ |
1912 | (type == INT)? \ | 1883 | (type == INT)? \ |
1913 | (int)(*(int*)(value)) \ | 1884 | (int)(*(int*)(value)) \ |
1914 | : \ | 1885 | : \ |
1915 | (bool)(*(bool*)(value)) | 1886 | (bool)(*(bool*)(value)) |
1916 | 1887 | bool do_set_setting(const unsigned char* string, void *variable, | |
1917 | #define get_int_fromtype(type, var) \ | 1888 | int nb_items,int selected, |
1918 | (type == INT)?*(int *)var:(*(bool *)var?1:0) | 1889 | struct value_setting_data *cb_data, |
1919 | 1890 | void (*function)(int)) | |
1920 | bool set_option(const char* string, void* variable, enum optiontype type, | ||
1921 | const struct opt_items* options, int numoptions, void (*function)(int)) | ||
1922 | { | 1891 | { |
1923 | int button; | 1892 | int button; |
1893 | bool done = false; | ||
1894 | struct gui_synclist lists; | ||
1924 | int oldvalue; | 1895 | int oldvalue; |
1925 | /* oldvalue=*variable; */ | 1896 | |
1926 | oldvalue=get_int_fromtype(type, variable); | 1897 | if (cb_data->type == INT) |
1927 | struct gui_select select; | 1898 | oldvalue = *(int*)variable; |
1928 | gui_select_init_items(&select, string, oldvalue, options, numoptions); | 1899 | else oldvalue = *(bool*)variable; |
1929 | gui_syncselect_draw(&select); | 1900 | |
1901 | gui_synclist_init(&lists,value_setting_get_name_cb,(void*)cb_data,false,1); | ||
1902 | gui_synclist_set_title(&lists, (char*)string); | ||
1903 | gui_synclist_set_icon_callback(&lists,NULL); | ||
1904 | gui_synclist_set_nb_items(&lists,nb_items); | ||
1905 | gui_synclist_limit_scroll(&lists,true); | ||
1906 | gui_synclist_select_item(&lists, selected); | ||
1907 | |||
1930 | if (global_settings.talk_menu) | 1908 | if (global_settings.talk_menu) |
1931 | talk_id(options[select.options.option].voice_id, true); | ||
1932 | |||
1933 | while ( !select.validated ) | ||
1934 | { | 1909 | { |
1935 | gui_syncstatusbar_draw(&statusbars, true); | 1910 | if (cb_data->type == INT && !cb_data->options) |
1936 | button = button_get_w_tmo(HZ/2); | 1911 | talk_unit(cb_data->voice_unit, *(int*)variable); |
1937 | select.options.limit_loop = false; | 1912 | else talk_id(cb_data->options[selected].voice_id, false); |
1938 | if(gui_syncselect_do_button(&select, button)) | 1913 | } |
1914 | |||
1915 | gui_synclist_draw(&lists); | ||
1916 | while (!done) | ||
1917 | { | ||
1918 | |||
1919 | button = button_get(true); | ||
1920 | if (button == BUTTON_NONE) | ||
1921 | continue; | ||
1922 | |||
1923 | if (gui_synclist_do_button(&lists,button)) | ||
1939 | { | 1924 | { |
1940 | /* *variable = gui_select_get_selected(&select) */ | ||
1941 | set_type_fromint(type, variable, select.options.option); | ||
1942 | gui_syncselect_draw(&select); | ||
1943 | if (global_settings.talk_menu) | 1925 | if (global_settings.talk_menu) |
1944 | talk_id(options[select.options.option].voice_id, false); | 1926 | { |
1945 | if ( function ) | 1927 | int value; |
1946 | function(type_fromvoidptr(type, variable)); | 1928 | if (cb_data->type == INT && !cb_data->options) |
1929 | { | ||
1930 | value = cb_data->max - | ||
1931 | gui_synclist_get_sel_pos(&lists)*cb_data->step; | ||
1932 | talk_unit(cb_data->voice_unit, value); | ||
1933 | } | ||
1934 | else | ||
1935 | { | ||
1936 | value = gui_synclist_get_sel_pos(&lists); | ||
1937 | talk_id(cb_data->options[value].voice_id, false); | ||
1938 | } | ||
1939 | } | ||
1940 | if (cb_data->type == INT && !cb_data->options) | ||
1941 | *(int*)variable = cb_data->max - | ||
1942 | gui_synclist_get_sel_pos(&lists)*cb_data->step; | ||
1943 | else if (cb_data->type == BOOL) | ||
1944 | *(bool*)variable = gui_synclist_get_sel_pos(&lists) ? true : false; | ||
1945 | else *(int*)variable = gui_synclist_get_sel_pos(&lists); | ||
1946 | } | ||
1947 | else if (button == SETTINGS_CANCEL) | ||
1948 | { | ||
1949 | gui_syncsplash(HZ/2,true,str(LANG_MENU_SETTING_CANCEL)); | ||
1950 | if (cb_data->type == INT) | ||
1951 | *(int*)variable = oldvalue; | ||
1952 | else *(bool*)variable = (bool)oldvalue; | ||
1953 | done = true; | ||
1947 | } | 1954 | } |
1948 | gui_syncstatusbar_draw(&statusbars, false); | 1955 | else if (button == SETTINGS_OK) |
1949 | if(select.canceled) | ||
1950 | { | 1956 | { |
1951 | /* *variable=oldvalue; */ | 1957 | done = true; |
1952 | set_type_fromint(type, variable, oldvalue); | ||
1953 | if ( function ) | ||
1954 | function(type_fromvoidptr(type, variable)); | ||
1955 | return false; | ||
1956 | } | 1958 | } |
1957 | if(default_event_handler(button) == SYS_USB_CONNECTED) | 1959 | else if(default_event_handler(button) == SYS_USB_CONNECTED) |
1958 | return true; | 1960 | return true; |
1961 | gui_syncstatusbar_draw(&statusbars, false); | ||
1962 | if ( function ) | ||
1963 | function(type_fromvoidptr(cb_data->type,variable)); | ||
1959 | } | 1964 | } |
1960 | return false; | 1965 | return false; |
1961 | } | 1966 | } |
1967 | bool set_int(const unsigned char* string, | ||
1968 | const char* unit, | ||
1969 | int voice_unit, | ||
1970 | int* variable, | ||
1971 | void (*function)(int), | ||
1972 | int step, | ||
1973 | int min, | ||
1974 | int max, | ||
1975 | void (*formatter)(char*, int, int, const char*) ) | ||
1976 | { | ||
1977 | struct value_setting_data data = { | ||
1978 | INT,max, step, voice_unit,unit,formatter,NULL }; | ||
1979 | return do_set_setting(string,variable,(max-min)/step + 1, | ||
1980 | (max-*variable)/step, &data,function); | ||
1981 | } | ||
1982 | |||
1983 | /* NOTE: the 'type' parameter specifies the actual type of the variable | ||
1984 | that 'variable' points to. not the value within. Only variables with | ||
1985 | type 'bool' should use parameter BOOL. | ||
1986 | |||
1987 | The type separation is necessary since int and bool are fundamentally | ||
1988 | different and bit-incompatible types and can not share the same access | ||
1989 | code. */ | ||
1990 | bool set_option(const char* string, void* variable, enum optiontype type, | ||
1991 | const struct opt_items* options, int numoptions, void (*function)(int)) | ||
1992 | { | ||
1993 | struct value_setting_data data = { | ||
1994 | type,0, 0, 0,NULL,NULL,(struct opt_items*)options }; | ||
1995 | int selected; | ||
1996 | if (type == BOOL) | ||
1997 | selected = *(bool*)variable ? 1 : 0; | ||
1998 | else selected = *(int*)variable; | ||
1999 | return do_set_setting(string,variable,numoptions, | ||
2000 | selected, &data,function); | ||
2001 | } | ||
1962 | 2002 | ||
1963 | #ifdef HAVE_RECORDING | 2003 | #ifdef HAVE_RECORDING |
1964 | /* This array holds the record timer interval lengths, in seconds */ | 2004 | /* This array holds the record timer interval lengths, in seconds */ |