summaryrefslogtreecommitdiffstats
path: root/apps/tree.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-07-25 16:27:41 +0000
committerThomas Martitz <kugel@rockbox.org>2010-07-25 16:27:41 +0000
commitd4b5922d3a8b9d694270c6ff06076568feb1d1fe (patch)
tree1ee9d2f33e2fcdd74890bbd158b04e4d9eb35c6a /apps/tree.c
parent5215773c9fbd3293f996561893fe5f144f3ffac2 (diff)
downloadrockbox-d4b5922d3a8b9d694270c6ff06076568feb1d1fe.tar.gz
rockbox-d4b5922d3a8b9d694270c6ff06076568feb1d1fe.tar.bz2
rockbox-d4b5922d3a8b9d694270c6ff06076568feb1d1fe.zip
Rewrite r21464 in a more compact/readable way. Reduces code duplication as well.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27554 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c98
1 files changed, 50 insertions, 48 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 97ddfbb44d..8889b160e8 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -923,6 +923,7 @@ int rockbox_browse(const char *root, int dirfilter)
static struct tree_context backup;
char current[MAX_PATH];
int last_context;
+ const char *dir, *ext, *setting;
backup = tc;
tc.selected_item = 0;
@@ -930,61 +931,62 @@ int rockbox_browse(const char *root, int dirfilter)
memcpy(tc.currdir, root, sizeof(tc.currdir));
start_wps = false;
last_context = curr_context;
-
- /* Center on the currently loaded language when browsing languages. */
- if (dirfilter == SHOW_LNG)
- {
- if (global_settings.lang_file[0])
- {
- snprintf(current, sizeof(current), LANG_DIR "/%s.lng",
- global_settings.lang_file);
- }
- else
- {
- strlcpy(current, LANG_DIR "/english.lng", sizeof(current));
- }
- }
- /* Center on currently loaded WPS */
- else if (dirfilter == SHOW_WPS)
+
+ /* if we are in a special settings folder, center the current setting */
+ switch(dirfilter)
{
- snprintf(current, sizeof(current), WPS_DIR "/%s.wps",
- global_settings.wps_file);
- }
+ case SHOW_LNG:
+ dir = LANG_DIR;
+ ext = "lng";
+ if (global_settings.lang_file[0])
+ setting = global_settings.lang_file;
+ else
+ setting = "english";
+ break;
+ case SHOW_WPS:
+ dir = WPS_DIR;
+ ext = "wps";
+ setting = global_settings.wps_file;
+ break;
#ifdef HAVE_REMOTE_LCD
- /* Center on currently loaded RWPS */
- else if (dirfilter == SHOW_RWPS)
- {
- snprintf(current, sizeof(current), WPS_DIR "/%s.rwps",
- global_settings.rwps_file);
- }
- else if (dirfilter == SHOW_RSBS)
- {
- snprintf(current, sizeof(current), SBS_DIR "/%s.rsbs",
- global_settings.rsbs_file);
- }
+ case SHOW_RWPS:
+ dir = WPS_DIR;
+ ext = "rwps";
+ setting = global_settings.rwps_file;
+ break;
+ case SHOW_RSBS:
+ dir = WPS_DIR;
+ ext = "rsbs";
+ setting = global_settings.rsbs_file;
+ break;
#endif
#ifdef HAVE_LCD_BITMAP
- /* Center on the currently loaded font when browsing fonts */
- else if (dirfilter == SHOW_FONT)
- {
- snprintf(current, sizeof(current), FONT_DIR "/%s.fnt",
- global_settings.font_file);
- }
- else if (dirfilter == SHOW_SBS)
- {
- snprintf(current, sizeof(current), SBS_DIR "/%s.sbs",
- global_settings.sbs_file);
- }
+ case SHOW_FONT:
+ dir = FONT_DIR;
+ ext = "fnt";
+ setting = global_settings.font_file;
+ break;
+ case SHOW_SBS:
+ dir = WPS_DIR;
+ ext = "sbs";
+ setting = global_settings.sbs_file;
+ break;
#endif
#if CONFIG_TUNER
- /* Center on the currently loaded FM preset when browsing those */
- else if (dirfilter == SHOW_FMR)
- {
- snprintf(current, sizeof(current), FMPRESET_PATH "/%s.fmr",
- global_settings.fmr_file);
- }
+ case SHOW_FMR:
+ dir = FMPRESET_PATH;
+ ext = "fmr";
+ setting = global_settings.fmr_file;
+ break;
#endif
- else /* reset current[] */
+ default:
+ dir = ext = setting = NULL;
+ break;
+ }
+
+ if (setting)
+ snprintf(current, sizeof(current), "%s/%s.%s", dir, setting, ext);
+ else /* reset current, the next call might use the old value */
current[0] = '\0';
/* If we've found a file to center on, do it */