Index: ../apps/misc.c =================================================================== --- ../apps/misc.c (revision 14623) +++ ../apps/misc.c (working copy) @@ -63,6 +63,7 @@ #include "gui/gwps-common.h" #include "bookmark.h" +#include "onplay.h" #include "misc.h" #include "playback.h" @@ -773,33 +774,97 @@ static void car_adapter_mode_processing(bool inserted) { + char buf[MAX_PATH]; + if (global_settings.car_adapter_mode) { + char old_mode = global_status.player_mode; + if(inserted) { /* * Just got plugged in, delay & resume if we were playing */ if (audio_status() & AUDIO_STATUS_PAUSE) { /* delay resume a bit while the engine is cranking */ play_resume_tick = current_tick + HZ*5; waiting_to_resume_play = true; } + + // update the global status player mode + global_status.player_mode = PLAYER_MODE_CARADAPTER; + gui_syncsplash(HZ*2, "car adapter detected"); + + /* + * if there is a car mode config, then apply it + */ + if (global_settings.carmode_config[0] != '\0') + { + // if the previous mode was unplugged mode, and there is a unplugged + // config, then flush the settings + // this will handle writing the settings to CONFIGFILE and + // carmode config + if (old_mode == PLAYER_MODE_UNPLUGGED && + global_settings.unplugged_config[0] != '\0') + { + gui_syncsplash(HZ*2, "saving unplugged mode config"); + // restore global status mode temporarily + global_status.player_mode = old_mode; + settings_save(); + global_status.player_mode = PLAYER_MODE_CARADAPTER; + } + + // load and apply the new settings + if (!get_file(global_settings.carmode_config, buf, sizeof(buf)) || + !settings_load_config(buf, true)) + { + gui_syncsplash(HZ*3, "unable to load carmode cfg: %s", CONFIGFILE); + } + } } else { /* * Just got unplugged, pause if playing */ if ((audio_status() & AUDIO_STATUS_PLAY) && !(audio_status() & AUDIO_STATUS_PAUSE)) { if (global_settings.fade_on_stop) fade(0); else audio_pause(); } + + // update the global status player mode + global_status.player_mode = PLAYER_MODE_UNPLUGGED; + + /* + * if there is a unplugged config, then apply it + */ + if (global_settings.unplugged_config[0] != '\0') + { + // if the previous mode was car mode, and there is a carmode + // config, then flush the settings + // this will handle writing the settings to CONFIGFILE and + // carmode config + if (old_mode == PLAYER_MODE_CARADAPTER && + global_settings.carmode_config[0] != '\0') + { + gui_syncsplash(HZ*2, "saving car mode config"); + global_status.player_mode = old_mode; + settings_save(); + global_status.player_mode = PLAYER_MODE_UNPLUGGED; + } + + // load and apply the new settings + if (!get_file(global_settings.unplugged_config, buf, sizeof(buf)) || + !settings_load_config(buf, true)) + { + gui_syncsplash(HZ*3, "unable to load unplugged cfg: %s", CONFIGFILE); + } + } } } } Index: ../apps/settings.c =================================================================== --- ../apps/settings.c (revision 14623) +++ ../apps/settings.c (working copy) @@ -419,9 +419,43 @@ int i; int fd; char value[MAX_PATH]; + + /* if the current mode is not PLAYER_MODE_UNKNOWN, and + * there is a corresponding mode config file set and we're + * writing to the default CONFIGFILE, then + * save this config file to the mode config file as well + * NOTE: options are OR'd with SETTINGS_PLUS_CONFIGDUP + * to prevent loop if either config are set to CONFIGFILE + */ + if (global_status.player_mode != PLAYER_MODE_UNKNOWN && + (options & SETTINGS_PLUS_CONFIGDUP) == 0 && + strcmp(filename, CONFIGFILE) == 0) + { + if (global_status.player_mode == PLAYER_MODE_CARADAPTER && + global_settings.carmode_config[0] != '\0' && + get_file(global_settings.carmode_config, value, sizeof(value))) + { + settings_write_config(value, options | SETTINGS_PLUS_CONFIGDUP); + } + else if (global_status.player_mode == PLAYER_MODE_UNPLUGGED && + global_settings.unplugged_config[0] != '\0' && + get_file(global_settings.unplugged_config, value, sizeof(value))) + { + settings_write_config(value, options | SETTINGS_PLUS_CONFIGDUP); + } + } + + // turn off SETTINGS_PLUS_CONFIGDUP + if ((options & SETTINGS_PLUS_CONFIGDUP) == SETTINGS_PLUS_CONFIGDUP) + options ^= SETTINGS_PLUS_CONFIGDUP; + fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); if (fd < 0) + { + gui_syncsplash(HZ*3, "Error (%d) opening %s", fd, filename); return false; + } + fdprintf(fd, "# .cfg file created by rockbox %s - " "http://www.rockbox.org\r\n\r\n", appsversion); for(i=0; iflags&F_T_MASK) != F_T_UCHARPTR) + { + gui_syncsplash(HZ*2, "get_file setting not a filename"); + filename[0] = '\0'; + return false; + } + + snprintf(filename, maxlen, + "%s%s%s", + setting->filename_setting->prefix, + (const char *)variable, + setting->filename_setting->suffix); + + return true; +} + Index: ../apps/settings.h =================================================================== --- ../apps/settings.h (revision 14623) +++ ../apps/settings.h (working copy) @@ -158,6 +158,16 @@ NUM_REPEAT_MODES }; +/* player mode options */ +enum +{ + PLAYER_MODE_UNKNOWN = 0, +#if CONFIG_CHARGING + PLAYER_MODE_CARADAPTER, + PLAYER_MODE_UNPLUGGED, +#endif +}; + /* dir filter options */ /* Note: Any new filter modes need to be added before NUM_FILTER_MODES. * Any new rockbox browse filter modes (accessible through the menu) @@ -238,12 +248,13 @@ int settings_save(void); /* defines for the options paramater */ enum { - SETTINGS_SAVE_CHANGED = 0, + SETTINGS_SAVE_CHANGED = 0x0000, SETTINGS_SAVE_ALL, SETTINGS_SAVE_THEME, #ifdef HAVE_RECORDING SETTINGS_SAVE_RECPRESETS, #endif + SETTINGS_PLUS_CONFIGDUP = 0x1000, // meant to be OR'd into the options }; bool settings_save_config(int options); @@ -287,8 +298,8 @@ bool set_time_screen(const char* string, struct tm *tm); int read_line(int fd, char* buffer, int buffer_size); void set_file(char* filename, char* setting, int maxlen); +bool get_file(void* variable, char* filename, int maxlen); - /** global_settings and global_status struct definitions **/ struct system_status @@ -309,6 +320,7 @@ #endif char last_screen; int viewer_icon_count; + char player_mode; /* current mode of player -- PLAYER_MODE_* */ }; struct user_settings @@ -748,6 +760,11 @@ int list_accel_start_delay; /* ms before we start increaseing step size */ int list_accel_wait; /* ms between increases */ #endif + + /* mode theme filenames */ + unsigned char carmode_config[MAX_FILENAME+1]; + unsigned char unplugged_config[MAX_FILENAME+1]; + #ifdef HAVE_USBSTACK int usb_stack_mode; /* device or host */ unsigned char usb_stack_device_driver[32]; /* usb device driver to load */ Index: ../apps/settings_list.c =================================================================== --- ../apps/settings_list.c (revision 14623) +++ ../apps/settings_list.c (working copy) @@ -1263,6 +1263,14 @@ 3, "list_accel_wait", UNIT_SEC, 1, 10, 1, scanaccel_formatter, scanaccel_getlang, NULL), #endif /* HAVE_SCROLLWHEEL */ + + /* mode config settings */ + FILENAME_SETTING(0, carmode_config, "carmode config", + "", ROCKBOX_DIR "/", ".cfg", MAX_FILENAME+1), + FILENAME_SETTING(0, unplugged_config, "unplugged config", + "", ROCKBOX_DIR "/", ".cfg", MAX_FILENAME+1), + SYSTEM_SETTING(NVRAM(1),player_mode,0), + #ifdef HAVE_USBSTACK CHOICE_SETTING(0, usb_stack_mode, LANG_USBSTACK_MODE, 0, "usb mode", "device,host", Index: ../apps/onplay.c =================================================================== --- ../apps/onplay.c (revision 14623) +++ ../apps/onplay.c (working copy) @@ -683,8 +683,10 @@ #define draw_slider() #endif -/* Paste a file to a new directory. Will overwrite always. */ -static bool clipboard_pastefile(const char *src, const char *target, bool copy) +/* Paste a file to a new directory. Will overwrite always. + * -- removed static keyword, so that this function can be + * used outside of onplay */ +bool clipboard_pastefile(const char *src, const char *target, bool copy) { int src_fd, target_fd; size_t buffersize; @@ -1070,6 +1072,66 @@ MENUITEM_FUNCTION(set_backdrop_item, 0, ID2P(LANG_SET_AS_BACKDROP), set_backdrop, NULL, clipboard_callback, Icon_NOICON); #endif + +/* CONTEXT BROWSE_CONFIG ITEMS AND FUNCTIONS */ +static bool set_carmode_config(void) +{ + set_file(selected_file, + (char *)global_settings.carmode_config, + MAX_FILENAME); + return false; +} + +static bool set_unplugged_config(void) +{ + set_file(selected_file, + (char *)global_settings.unplugged_config, + MAX_FILENAME); + return false; +} + +static int browse_config_callback(int action,const struct menu_item_ex *this_item); +MENUITEM_FUNCTION(set_carmode_config_item, 0, ID2P(LANG_SET_CARMODE_CONFIG), + set_carmode_config, NULL, browse_config_callback, Icon_NOICON); +MENUITEM_FUNCTION(set_unplugged_config_item, 0, ID2P(LANG_SET_UNPLUGGED_CONFIG), + set_unplugged_config, NULL, browse_config_callback, Icon_NOICON); + +static int browse_config_callback(int action,const struct menu_item_ex *this_item) +{ + /* TODO change icon depending on if theme is selected for car or unplugged + * mode, or unselected + */ + + switch (action) + { + case ACTION_REQUEST_MENUITEM: + if ((selected_file_attr & ATTR_DIRECTORY) +#ifdef HAVE_MULTIVOLUME + || (selected_file_attr & ATTR_VOLUME) +#endif + ) + { + /* cannot set themes to directories or volumes*/ + return ACTION_EXIT_MENUITEM; + } + else if (this_item == &set_carmode_config_item || + this_item == &set_unplugged_config_item) + { + // cannot set carmode or unplugged config to + // default config file + if (strcmp(selected_file, CONFIGFILE) == 0) + { + return ACTION_EXIT_MENUITEM; + } + } + break; + case ACTION_EXIT_MENUITEM: + settings_save(); + break; + } + return action; +} + #ifdef HAVE_RECORDING static bool set_recdir(void) { @@ -1176,6 +1238,17 @@ &eq_menu_graphical_item, &eq_browse_presets_item, #endif ); + +/* used when onplay() is called white browsing config files */ +MAKE_ONPLAYMENU( tree_browseconfig_menu, ID2P(LANG_ONPLAY_MENU_TITLE), + onplaymenu_callback, Icon_file_view_menu, + &set_carmode_config_item, &set_unplugged_config_item, + &rename_file_item, &clipboard_cut_item, &clipboard_copy_item, + &clipboard_paste_item, &delete_file_item, &delete_dir_item, + &list_viewers_item, &create_dir_item, &properties_item, + &add_to_faves_item, + ); + /* used when onplay() is not called in the CONTEXT_WPS context */ MAKE_ONPLAYMENU( tree_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE), onplaymenu_callback, Icon_file_view_menu, @@ -1211,7 +1284,19 @@ #endif } else - menu_result = do_menu(&tree_onplay_menu, NULL); + { + /* if this is a config file in the rockbox dir then + * browse config menu + */ + if (strncmp(ROCKBOX_DIR, file, strlen(ROCKBOX_DIR)) == 0 && + strrchr(file, '/') - file == ROCKBOX_DIR_LEN && + (selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_CFG) + { + menu_result = do_menu(&tree_browseconfig_menu, NULL); + } + else + menu_result = do_menu(&tree_onplay_menu, NULL); + } switch (menu_result) { case GO_TO_WPS: Index: ../apps/lang/english.lang =================================================================== --- ../apps/lang/english.lang (revision 14623) +++ ../apps/lang/english.lang (working copy) @@ -11027,6 +11027,34 @@ + id: LANG_SET_CARMODE_CONFIG + desc: set car mode config while browsing config files + user: + + *: "Set Car-Adapter mode Config" + + + *: "Set Car-Adapter mode Config" + + + *: "Set Car-Adapter mode Config" + + + + id: LANG_SET_UNPLUGGED_CONFIG + desc: set unplugged mode config while browsing config files + user: + + *: "Set Unplugged mode Config" + + + *: "Set Unplugged mode Config" + + + *: "Set Unplugged mode Config" + + id: LANG_EXT_ONLY_VIEW_ALL desc: in settings_menu user: