Index: main_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/main_menu.c,v retrieving revision 1.101 diff -u -r1.101 main_menu.c --- main_menu.c 12 Apr 2004 13:03:52 -0000 1.101 +++ main_menu.c 13 Apr 2004 12:35:42 -0000 @@ -271,7 +271,7 @@ return false; } -static bool plugin_browse(void) +bool plugin_browse(void) { return rockbox_browse(PLUGIN_DIR, SHOW_PLUGINS); } Index: onplay.c =================================================================== RCS file: /cvsroot/rockbox/apps/onplay.c,v retrieving revision 1.27 diff -u -r1.27 onplay.c --- onplay.c 8 Apr 2004 06:38:56 -0000 1.27 +++ onplay.c 13 Apr 2004 12:36:08 -0000 @@ -138,7 +138,7 @@ } /* Sub-menu for playlist options */ -static bool playlist_options(void) +bool playlist_options(void) { struct menu_item items[7]; struct playlist_args args[7]; /* increase these 2 if you add entries! */ Index: screens.c =================================================================== RCS file: /cvsroot/rockbox/apps/screens.c,v retrieving revision 1.42 diff -u -r1.42 screens.c --- screens.c 12 Mar 2004 10:17:30 -0000 1.42 +++ screens.c 13 Apr 2004 12:36:39 -0000 @@ -432,7 +432,7 @@ { bool exit = false; bool used = false; - int w, h, key; + int w, h; char buf[32]; int oldrepeat = global_settings.repeat_mode; @@ -537,17 +537,8 @@ LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8, true); lcd_update(); - key = button_get(true); - - /* - * This is a temporary kludge so that the F2 & F3 menus operate in exactly - * the same manner up until the full F2/F3 configurable menus are complete - */ - - if( key == BUTTON_LEFT || key == BUTTON_RIGHT || key == BUTTON_DOWN || key == ( BUTTON_LEFT | BUTTON_REPEAT ) || key == ( BUTTON_RIGHT | BUTTON_REPEAT ) || key == ( BUTTON_DOWN | BUTTON_REPEAT ) ) - key = button | key; - - switch (key) { + + switch (button_get(true)) { case BUTTON_F2 | BUTTON_LEFT: case BUTTON_F2 | BUTTON_LEFT | BUTTON_REPEAT: global_settings.playlist_shuffle = @@ -579,6 +570,7 @@ used = true; break; + case BUTTON_F3 | BUTTON_LEFT: case BUTTON_F3 | BUTTON_LEFT | BUTTON_REPEAT: global_settings.scrollbar = !global_settings.scrollbar; @@ -592,7 +584,7 @@ break; case BUTTON_F3 | BUTTON_DOWN: - case BUTTON_F3 | BUTTON_DOWN | BUTTON_REPEAT: + case BUTTON_F3 | BUTTON_DOWN | BUTTON_REPEAT: case BUTTON_F3 | BUTTON_UP: case BUTTON_F3 | BUTTON_UP | BUTTON_REPEAT: global_settings.flip_display = !global_settings.flip_display; @@ -601,14 +593,15 @@ used = true; break; - case BUTTON_F3 | BUTTON_REL: case BUTTON_F2 | BUTTON_REL: - - if( used ) - exit = true; + case BUTTON_F3 | BUTTON_REL: - used = true; + if ( used ) + exit = true; + else + return context_keys(context, button); + used = true; break; case BUTTON_OFF | BUTTON_REPEAT: Index: settings.c =================================================================== RCS file: /cvsroot/rockbox/apps/settings.c,v retrieving revision 1.200 diff -u -r1.200 settings.c --- settings.c 12 Apr 2004 12:29:44 -0000 1.200 +++ settings.c 13 Apr 2004 12:37:10 -0000 @@ -882,7 +882,7 @@ settings_save(); } -static void set_sound(char* value, int type, int* setting) +void set_sound_option(char* value, int type, int* setting) { int num = atoi(value); @@ -904,7 +904,7 @@ #endif } -static void set_cfg_bool(bool* variable, char* value) +void set_cfg_bool(bool* variable, char* value) { /* look for the 'n' in 'on' */ if ((value[1] & 0xdf) == 'N') @@ -955,13 +955,13 @@ continue; if (!strcasecmp(name, "volume")) - set_sound(value, SOUND_VOLUME, &global_settings.volume); + set_sound_option(value, SOUND_VOLUME, &global_settings.volume); else if (!strcasecmp(name, "bass")) - set_sound(value, SOUND_BASS, &global_settings.bass); + set_sound_option(value, SOUND_BASS, &global_settings.bass); else if (!strcasecmp(name, "treble")) - set_sound(value, SOUND_TREBLE, &global_settings.treble); + set_sound_option(value, SOUND_TREBLE, &global_settings.treble); else if (!strcasecmp(name, "balance")) - set_sound(value, SOUND_BALANCE, &global_settings.balance); + set_sound_option(value, SOUND_BALANCE, &global_settings.balance); else if (!strcasecmp(name, "channels")) { static char* options[] = { "stereo","stereo narrow","mono","mono left", @@ -1099,19 +1099,19 @@ #endif #ifdef HAVE_MAS3587F else if (!strcasecmp(name, "loudness")) - set_sound(value, SOUND_LOUDNESS, &global_settings.loudness); + set_sound_option(value, SOUND_LOUDNESS, &global_settings.loudness); else if (!strcasecmp(name, "bass boost")) - set_sound(value, SOUND_SUPERBASS, &global_settings.bass_boost); + set_sound_option(value, SOUND_SUPERBASS, &global_settings.bass_boost); else if (!strcasecmp(name, "auto volume")) { static char* options[] = {"off", "2", "4", "8" }; set_cfg_option(&global_settings.avc, value, options, 4); } else if (!strcasecmp(name, "rec mic gain")) - set_sound(value, SOUND_MIC_GAIN, &global_settings.rec_mic_gain); + set_sound_option(value, SOUND_MIC_GAIN, &global_settings.rec_mic_gain); else if (!strcasecmp(name, "rec left gain")) - set_sound(value, SOUND_LEFT_GAIN, &global_settings.rec_left_gain); + set_sound_option(value, SOUND_LEFT_GAIN, &global_settings.rec_left_gain); else if (!strcasecmp(name, "rec right gain")) - set_sound(value, SOUND_RIGHT_GAIN, &global_settings.rec_right_gain); + set_sound_option(value, SOUND_RIGHT_GAIN, &global_settings.rec_right_gain); else if (!strcasecmp(name, "rec quality")) set_cfg_int(&global_settings.rec_quality, value, 0, 7); else if (!strcasecmp(name, "rec timesplit")){ Index: settings_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/settings_menu.c,v retrieving revision 1.139 diff -u -r1.139 settings_menu.c --- settings_menu.c 9 Apr 2004 22:55:39 -0000 1.139 +++ settings_menu.c 13 Apr 2004 12:37:19 -0000 @@ -428,7 +428,7 @@ } #endif /* HAVE_LCD_BITMAP */ -static bool shuffle(void) +bool shuffle(void) { return set_bool( str(LANG_SHUFFLE), &global_settings.playlist_shuffle ); } @@ -869,7 +869,7 @@ return rockbox_browse(ROCKBOX_DIR, SHOW_WPS); } -static bool custom_cfg_browse(void) +bool custom_cfg_browse(void) { return rockbox_browse(ROCKBOX_DIR, SHOW_CFG); } Index: sound_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/sound_menu.c,v retrieving revision 1.51 diff -u -r1.51 sound_menu.c --- sound_menu.c 27 Mar 2004 00:11:01 -0000 1.51 +++ sound_menu.c 13 Apr 2004 12:37:21 -0000 @@ -148,7 +148,7 @@ return false; } -static bool volume(void) +bool volume(void) { return set_sound(str(LANG_VOLUME), &global_settings.volume, SOUND_VOLUME); } Index: main_menu.h =================================================================== RCS file: /cvsroot/rockbox/apps/main_menu.h,v retrieving revision 1.4 diff -u -r1.4 main_menu.h --- main_menu.h 24 Sep 2002 17:22:11 -0000 1.4 +++ main_menu.h 13 Apr 2004 12:39:22 -0000 @@ -23,5 +23,6 @@ extern int show_logo(void); extern bool main_menu(void); +bool plugin_browse(void); #endif Index: onplay.h =================================================================== RCS file: /cvsroot/rockbox/apps/onplay.h,v retrieving revision 1.2 diff -u -r1.2 onplay.h --- onplay.h 1 Jul 2003 21:03:28 -0000 1.2 +++ onplay.h 13 Apr 2004 12:39:26 -0000 @@ -20,6 +20,7 @@ #define _ONPLAY_H_ int onplay(char* file, int attr); +bool playlist_options(void); enum { ONPLAY_OK, Index: settings.h =================================================================== RCS file: /cvsroot/rockbox/apps/settings.h,v retrieving revision 1.105 diff -u -r1.105 settings.h --- settings.h 27 Mar 2004 00:11:01 -0000 1.105 +++ settings.h 13 Apr 2004 12:39:32 -0000 @@ -224,7 +224,7 @@ void settings_apply(void); void settings_apply_pm_range(void); void settings_display(void); - +void set_sound_option(char* value, int type, int* setting); bool settings_load_config(char* file); bool settings_save_config(void); bool set_bool_options(char* string, bool* variable, @@ -240,6 +240,8 @@ bool set_time(char* string, int timedate[]); int read_line(int fd, char* buffer, int buffer_size); void set_file(char* filename, char* setting, int maxlen); + +void set_cfg_bool(bool* variable, char* value); #ifdef HAVE_MAS3587F unsigned int rec_timesplit_seconds(void); Index: settings_menu.h =================================================================== RCS file: /cvsroot/rockbox/apps/settings_menu.h,v retrieving revision 1.5 diff -u -r1.5 settings_menu.h --- settings_menu.h 24 Sep 2002 17:22:11 -0000 1.5 +++ settings_menu.h 13 Apr 2004 12:39:32 -0000 @@ -22,5 +22,7 @@ #include "menu.h" bool settings_menu(void); +bool custom_cfg_browse(void); +bool shuffle(void); #endif Index: sound_menu.h =================================================================== RCS file: /cvsroot/rockbox/apps/sound_menu.h,v retrieving revision 1.5 diff -u -r1.5 sound_menu.h --- sound_menu.h 20 Nov 2003 00:33:43 -0000 1.5 +++ sound_menu.h 13 Apr 2004 12:39:32 -0000 @@ -22,6 +22,8 @@ #include "menu.h" bool sound_menu(void); +bool volume(void); + bool recording_menu(bool no_source); #endif --- /dev/null 2004-04-13 22:16:04.000000000 +0930 +++ action.c 2004-04-13 21:58:24.000000000 +0930 @@ -0,0 +1,333 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2004 Brent Coutts + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include "action.h" +#include "atoi.h" +#include "bookmark.h" +#include "ctype.h" +#include "button.h" +#include "debug.h" +#include "debug_menu.h" +#include "file.h" +#include "lang.h" +#include "lcd.h" +#include "main_menu.h" +#include "menu.h" +#include "misc.h" +#include "mp3_playback.h" +#include "playlist_menu.h" +#include "playlist_viewer.h" +#include "plugin.h" +#include "recording.h" +#include "screens.h" +#include "settings.h" +#include "settings_menu.h" +#include "sleeptimer.h" +#include "sound_menu.h" +#include "sprintf.h" +#include "string.h" +#include "tree.h" +#include "wps.h" + +static bool action_plugin(int const context, char* pluginparam); +static bool action_volume(int const context, char* setting); +static bool action_cfg(int const context, char* cfg); +static bool action_shuffle(const int context, char* setting); + +struct action_list +{ + int action; + bool (*function)(int const, char*); + int lang; +} actions[] = { + { ACTION_VOLUME ,action_volume ,LANG_VOLUME }, + { ACTION_PLUGINS ,action_plugin ,LANG_PLUGINS }, + { ACTION_CFG ,action_cfg ,LANG_CUSTOM_CFG }, + { ACTION_SHUFFLE ,action_shuffle ,LANG_SHUFFLE } +}; + +#ifdef HAVE_MAS3587F +#include "recording.h" +#endif + +#ifdef HAVE_FMRADIO +#include "radio.h" +#endif + +#define KEYPAD_MAP "/.rockbox/keypad.map" + +static bool alltrue() +{ + return true; +} + +/* + * This function receives a pointer to a menu item that already contains an action code. + * It determines the description and function pointer + */ + +bool context_keys(int context, int keycode) +{ + /* + This function maintains a static list of context / keycode combinations + It is on a rolling list of the last 10 context / keycode combinations + */ + + bool result = false; + int fhandle, i, entry, count, cursor; + int action = 0; + char line[128]; + char* field; + char* end; + static bool configurable = false; + static int current = 0; + struct menu_item items[16]; + +#define MAX_ENTRIES 10 + + struct menus + { + int action; + char desc[20]; + char setting[64]; + }; + + static + struct list + { + int context; + int keycode; + struct menus menu[16]; + int count; + } + entries[MAX_ENTRIES]; + + /* + firstly, search through the entries to see if there's already an entry for this + context and keycode + */ + + for( entry=0 ; entry 0 ) + { + /* ignore comment and blank lines */ + if( line[ 0 ] == '#' || line[ 0 ] == '\0' ) + configurable = (!strcasecmp(line, "#configure=yes")); + else + { + /* get the context first */ + field = strtok_r(line, ";", &end); + i = atoi(field); /* convert the context into an integer */ + + if( i == CONTEXT_ALL || ( i & context ) ) /* all contexts (0) or the current context */ + { + /* read the keypad button */ + field = strtok_r(NULL, ";", &end); + + if( keycode == atoi( field ) ) /* matches the key pressed */ + { + /* get the action code next */ + if((field = strtok_r(NULL, ";", &end))) + { + action = atoi(field); + + /* see if this action is actually valid by checking the language + return value against NULL */ + + if( 0 <= action && action < ACTION_MAXIMUM ) + { + /* we can assume that this is a valid entry */ + entries[ current ].context = context; + entries[ current ].keycode = keycode; + entries[ current ].menu[count].action = action; + + /* retrieve the description */ + if ((field = strtok_r(NULL, ";", &end))) + { + /* if the field is empty then use the standard LANG */ + strncpy(entries[ current ].menu[count].desc, strlen( field ) == 1 && isspace(field[0]) ? (char *)str(actions[ action ].lang) : field, sizeof entries[ current ].menu[count].desc); + + /* load the setting */ + memset(entries[ current ].menu[count].setting, 0, sizeof entries[ current ].menu[count].setting); + + if ((field = strtok_r(NULL, ";", &end))) + strncpy(entries[current].menu[count].setting, field, sizeof entries[current].menu[count].setting); + } + count++; + } + } + } + } + } + } + close(fhandle); + entries[ current ].count = count; + entry = current; + current++; + + if( current == MAX_ENTRIES ) + current = 0; + } + + if( entries[ entry ].count > 0 ) + { + /* + * this will blow your mind - if there was only _1_ entry then just + * run that option, otherwise load a menu to choose + */ + + if( entries[ entry ].count == 1 ) + cursor = 0; + else + { + cursor = -1; + + /* create the structure for menu_items */ + for( i=0 ; i= 0) + result = actions[entries[ entry ].menu[cursor].action].function(context, strlen(entries[ entry ].menu[cursor].setting)==0 ? NULL : entries[ entry ].menu[cursor].setting); + + } + + return result; +} + +/* + * action_volume either displays the volume setting, or directly sets the + * volume to the value of setting. If the first character of setting is + or - + * the volume is incremented / decremented by that value + */ + +static bool action_volume(const int context, char* setting) +{ + debugf("Setting = %d\n", context); + + if( setting==NULL ) + return volume(); + else + { + /* means an increment in volume is required */ + int vol; + char level[4]; + + if(setting[0]=='+' || setting[0]=='-') + { + vol = global_settings.volume + atoi(setting); + + if( vol < 0 ) + vol = 0; + + if( vol > 100 ) + vol = 100; + + snprintf(level, sizeof level, "%i", vol); + } + else + strncpy(level, setting, sizeof level); + + set_sound_option(level, SOUND_VOLUME, &global_settings.volume); + } + + return false; +} + +/* + * action_plugin either browses the plugins, or directly runs a plugin + * As parameters can be passed to plugins, the plugin is parsed for + * parameters which are passed if available + */ + +static bool action_plugin(int const context, char* plugin) +{ + debugf("Setting = %d\n", context); + + if( plugin == NULL ) + return plugin_browse(); + else + { + /* the plugin may also have the parameter value on the end */ + char* param; + param = strchr(plugin, ' '); + + if(param!=NULL) + { + param[0] = '\0'; + param++; + } + + plugin_load(plugin, param); + return false; + } +} + +static bool action_cfg(int const context, char* cfg) +{ + settings_load_config(cfg); + + return false; +} + +/* + * action_shuffle either displays the shuffle option, or directly sets the + * shuffle to the value of setting. + */ + +static bool action_shuffle(const int context, char* setting) +{ + if( setting==NULL ) + return shuffle(); + else + set_cfg_bool(&global_settings.playlist_shuffle, setting); + + return false; +} + --- rockbox/apps/action.h 2004-04-13 22:57:49.000000000 +0930 +++ current/apps/action.h 2004-04-15 07:10:45.000000000 +0930 @@ -20,21 +20,9 @@ #include "stdbool.h" -#define CONTEXT_WPS 0x0001 -#define CONTEXT_TREE 0x0002 -#define CONTEXT_RECORD 0x0004 -#define CONTEXT_MAINMENU 0x0008 -#define CONTEXT_ALL 0x0000 +#define CONTEXT_WPS 1 +#define CONTEXT_TREE 2 +#define CONTEXT_RECORD 3 +#define CONTEXT_MAINMENU 4 -#ifdef HAVE_RECORDER_KEYPAD -#include "menu.h" -bool context_keys(int context, int keycode); -#endif - -#define ACTION_VOLUME 0 -#define ACTION_PLUGINS 1 -#define ACTION_CFG 2 -#define ACTION_SHUFFLE 3 - -#define ACTION_MAXIMUM 4 #endif