2002-05-16 12:53:40 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Daniel Stenberg
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-05-16 14:48:40 +00:00
|
|
|
#include <stdio.h>
|
2002-05-16 12:53:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
#include "applimits.h"
|
2002-05-16 12:53:40 +00:00
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "lcd.h"
|
2002-09-12 13:33:59 +00:00
|
|
|
#include "font.h"
|
2002-08-31 04:58:35 +00:00
|
|
|
#include "backlight.h"
|
2002-05-16 12:53:40 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
2002-06-30 13:23:58 +00:00
|
|
|
#include "usb.h"
|
2002-05-16 12:53:40 +00:00
|
|
|
#include "tree.h"
|
2002-05-29 16:38:19 +00:00
|
|
|
#include "sprintf.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
#include "audio.h"
|
2002-06-07 14:23:32 +00:00
|
|
|
#include "playlist.h"
|
2002-06-14 10:39:11 +00:00
|
|
|
#include "menu.h"
|
2005-11-17 20:14:59 +00:00
|
|
|
#include "gwps.h"
|
2002-06-27 09:12:29 +00:00
|
|
|
#include "settings.h"
|
2002-07-22 22:45:20 +00:00
|
|
|
#include "status.h"
|
2002-06-30 13:23:58 +00:00
|
|
|
#include "debug.h"
|
2002-08-26 13:21:14 +00:00
|
|
|
#include "ata.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "rolo.h"
|
2002-09-03 07:53:51 +00:00
|
|
|
#include "icons.h"
|
2002-09-18 14:08:05 +00:00
|
|
|
#include "lang.h"
|
2002-09-24 12:40:52 +00:00
|
|
|
#include "language.h"
|
2002-09-24 17:22:12 +00:00
|
|
|
#include "screens.h"
|
2003-01-15 14:52:53 +00:00
|
|
|
#include "keyboard.h"
|
2004-01-14 00:13:04 +00:00
|
|
|
#include "bookmark.h"
|
2003-03-12 20:21:30 +00:00
|
|
|
#include "onplay.h"
|
2003-05-09 16:01:21 +00:00
|
|
|
#include "buffer.h"
|
2003-06-29 16:33:04 +00:00
|
|
|
#include "plugin.h"
|
2003-12-04 00:08:25 +00:00
|
|
|
#include "power.h"
|
2004-03-12 10:20:33 +00:00
|
|
|
#include "action.h"
|
2004-03-27 00:11:01 +00:00
|
|
|
#include "talk.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
#include "filetypes.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
#include "misc.h"
|
2005-01-17 11:39:46 +00:00
|
|
|
#include "filetree.h"
|
2006-03-26 11:33:42 +00:00
|
|
|
#include "tagtree.h"
|
2006-11-06 18:07:30 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2005-02-04 10:37:21 +00:00
|
|
|
#include "recorder/recording.h"
|
2006-11-06 18:07:30 +00:00
|
|
|
#endif
|
2005-02-05 19:57:19 +00:00
|
|
|
#include "rtc.h"
|
2005-10-07 17:38:05 +00:00
|
|
|
#include "dircache.h"
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-03-26 11:33:42 +00:00
|
|
|
#include "tagcache.h"
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2005-11-18 02:07:02 +00:00
|
|
|
#include "yesno.h"
|
2006-07-01 23:48:30 +00:00
|
|
|
#include "gwps-common.h"
|
2006-08-05 20:19:10 +00:00
|
|
|
#include "eeprom_settings.h"
|
2006-10-19 09:42:58 +00:00
|
|
|
#include "scrobbler.h"
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* gui api */
|
|
|
|
#include "list.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "splash.h"
|
|
|
|
#include "buttonbar.h"
|
2005-11-02 00:55:46 +00:00
|
|
|
#include "textarea.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
#include "root_menu.h"
|
2006-05-21 11:00:02 +00:00
|
|
|
#include "backdrop.h"
|
|
|
|
|
2007-04-18 13:03:01 +00:00
|
|
|
static const struct filetype *filetypes;
|
|
|
|
static int filetypes_count;
|
2003-12-07 16:57:43 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
struct gui_synclist tree_lists;
|
|
|
|
|
|
|
|
/* I put it here because other files doesn't use it yet,
|
|
|
|
* but should be elsewhere since it will be used mostly everywhere */
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
struct gui_buttonbar tree_buttonbar;
|
|
|
|
#endif
|
2005-01-17 11:39:46 +00:00
|
|
|
static struct tree_context tc;
|
|
|
|
|
|
|
|
bool boot_changed = false;
|
|
|
|
|
|
|
|
char lastfile[MAX_PATH];
|
2005-01-18 22:45:00 +00:00
|
|
|
static char lastdir[MAX_PATH];
|
2007-02-06 13:25:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-01-18 22:45:00 +00:00
|
|
|
static int lasttable, lastextra, lastfirstpos;
|
2007-02-06 13:25:57 +00:00
|
|
|
#endif
|
2005-01-18 22:45:00 +00:00
|
|
|
static int max_files = 0;
|
2005-01-17 11:39:46 +00:00
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
static bool reload_dir = false;
|
2002-05-28 16:26:12 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
static bool start_wps = false;
|
2005-10-28 00:00:00 +00:00
|
|
|
static int curr_context = false;/* id3db or tree*/
|
|
|
|
|
2007-03-17 00:55:23 +00:00
|
|
|
static int dirbrowse(void);
|
|
|
|
static int ft_play_dirname(char* name);
|
|
|
|
static void ft_play_filename(char *dir, char *file);
|
2007-10-21 00:20:51 +00:00
|
|
|
static void say_filetype(int attr);
|
2007-03-01 11:14:46 +00:00
|
|
|
|
2008-04-09 15:25:17 +00:00
|
|
|
static char * tree_get_filename(int selected_item, void *data,
|
|
|
|
char *buffer, size_t buffer_len)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
struct tree_context * local_tc=(struct tree_context *)data;
|
2005-10-28 00:00:00 +00:00
|
|
|
char *name;
|
|
|
|
int attr=0;
|
2007-08-13 23:11:30 +00:00
|
|
|
bool stripit = false;
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-10-29 02:33:19 +00:00
|
|
|
bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (id3db)
|
|
|
|
{
|
|
|
|
return tagtree_get_entry(&tc, selected_item)->name;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
struct entry* dc = local_tc->dircache;
|
2005-10-28 00:00:00 +00:00
|
|
|
struct entry* e = &dc[selected_item];
|
|
|
|
name = e->name;
|
|
|
|
attr = e->attr;
|
|
|
|
}
|
2007-08-13 23:11:30 +00:00
|
|
|
|
2007-08-14 21:02:44 +00:00
|
|
|
if(!(attr & ATTR_DIRECTORY))
|
2007-08-13 23:11:30 +00:00
|
|
|
{
|
2007-08-14 21:02:44 +00:00
|
|
|
switch(global_settings.show_filename_ext)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* show file extension: off */
|
|
|
|
stripit = true;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* show file extension: on */
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* show file extension: only unknown types */
|
|
|
|
stripit = filetype_supported(attr);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
/* show file extension: only when viewing all */
|
|
|
|
stripit = (*(local_tc->dirfilter) != SHOW_ID3DB) &&
|
|
|
|
(*(local_tc->dirfilter) != SHOW_ALL);
|
|
|
|
break;
|
|
|
|
}
|
2007-08-13 23:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(stripit)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2008-04-09 15:25:17 +00:00
|
|
|
return(strip_extension(buffer, buffer_len, name));
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
return(name);
|
|
|
|
}
|
|
|
|
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
static int tree_get_filecolor(int selected_item, void * data)
|
|
|
|
{
|
2007-06-19 09:53:58 +00:00
|
|
|
if (*tc.dirfilter == SHOW_ID3DB)
|
|
|
|
return -1;
|
2007-06-17 21:16:34 +00:00
|
|
|
struct tree_context * local_tc=(struct tree_context *)data;
|
|
|
|
struct entry* dc = local_tc->dircache;
|
|
|
|
struct entry* e = &dc[selected_item];
|
2007-06-17 23:10:01 +00:00
|
|
|
return filetype_get_color(e->name, e->attr);
|
2007-06-17 21:16:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
static int tree_get_fileicon(int selected_item, void * data)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
struct tree_context * local_tc=(struct tree_context *)data;
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-10-29 02:33:19 +00:00
|
|
|
bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
|
2005-10-28 00:00:00 +00:00
|
|
|
if (id3db) {
|
2007-04-16 09:14:36 +00:00
|
|
|
return tagtree_get_icon(&tc);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2006-10-25 10:17:57 +00:00
|
|
|
else
|
|
|
|
#endif
|
2007-02-27 11:09:09 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
struct entry* dc = local_tc->dircache;
|
2005-10-28 00:00:00 +00:00
|
|
|
struct entry* e = &dc[selected_item];
|
2007-04-16 09:14:36 +00:00
|
|
|
return filetype_get_icon(e->attr);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2007-10-21 00:20:51 +00:00
|
|
|
static int tree_voice_cb(int selected_item, void * data)
|
|
|
|
{
|
|
|
|
struct tree_context * local_tc=(struct tree_context *)data;
|
|
|
|
char *name;
|
|
|
|
int attr=0;
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
|
|
|
|
|
|
|
|
if (id3db)
|
|
|
|
{
|
|
|
|
attr = tagtree_get_attr(local_tc);
|
|
|
|
name = tagtree_get_entry(local_tc, selected_item)->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct entry* dc = local_tc->dircache;
|
|
|
|
struct entry* e = &dc[selected_item];
|
|
|
|
name = e->name;
|
|
|
|
attr = e->attr;
|
|
|
|
}
|
|
|
|
bool is_dir = (attr & ATTR_DIRECTORY);
|
|
|
|
bool did_clip = false;
|
|
|
|
/* First the .talk clip case */
|
|
|
|
if(is_dir)
|
|
|
|
{
|
|
|
|
if(global_settings.talk_dir_clip)
|
|
|
|
{
|
|
|
|
DEBUGF("Playing directory thumbnail: %s", local_tc->currdir);
|
|
|
|
did_clip = true;
|
|
|
|
if(ft_play_dirname(name) <0)
|
|
|
|
/* failed, not existing */
|
|
|
|
did_clip = false;
|
|
|
|
}
|
|
|
|
} else { /* it's a file */
|
|
|
|
if (global_settings.talk_file_clip && (attr & FILE_ATTR_THUMBNAIL))
|
|
|
|
{
|
|
|
|
did_clip = true;
|
|
|
|
DEBUGF("Playing file thumbnail: %s/%s%s\n",
|
|
|
|
local_tc->currdir, name, file_thumbnail_ext);
|
|
|
|
ft_play_filename(local_tc->currdir, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!did_clip)
|
|
|
|
{
|
|
|
|
/* say the number or spell if required or as a fallback */
|
|
|
|
switch (is_dir ? global_settings.talk_dir : global_settings.talk_file)
|
|
|
|
{
|
|
|
|
case 1: /* as numbers */
|
|
|
|
talk_id(is_dir ? VOICE_DIR : VOICE_FILE, false);
|
|
|
|
talk_number(selected_item+1 - (is_dir ? 0 : local_tc->dirsindir),
|
|
|
|
true);
|
2007-11-07 03:25:33 +00:00
|
|
|
if(global_settings.talk_filetype
|
|
|
|
&& !is_dir && *local_tc->dirfilter < NUM_FILTER_MODES)
|
2007-10-21 00:20:51 +00:00
|
|
|
say_filetype(attr);
|
|
|
|
break;
|
|
|
|
case 2: /* spelled */
|
2007-11-07 01:45:43 +00:00
|
|
|
talk_shutup();
|
2007-11-07 03:25:33 +00:00
|
|
|
if(global_settings.talk_filetype)
|
|
|
|
{
|
|
|
|
if(is_dir)
|
|
|
|
talk_id(VOICE_DIR, true);
|
|
|
|
else if(*local_tc->dirfilter < NUM_FILTER_MODES)
|
|
|
|
say_filetype(attr);
|
|
|
|
}
|
2007-11-07 01:45:43 +00:00
|
|
|
talk_spell(name, true);
|
2007-10-21 00:20:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-10 20:51:12 +00:00
|
|
|
bool check_rockboxdir(void)
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
2008-04-16 19:51:43 +00:00
|
|
|
if(!dir_exists(ROCKBOX_DIR))
|
2006-04-01 13:36:33 +00:00
|
|
|
{ /* No need to localise this message.
|
|
|
|
If .rockbox is missing, it wouldn't work anyway */
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
screens[i].clear_display();
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(HZ*2, "No .rockbox directory");
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
screens[i].clear_display();
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(HZ*2, "Installation incomplete");
|
2004-09-10 20:51:12 +00:00
|
|
|
return false;
|
2004-09-05 16:50:07 +00:00
|
|
|
}
|
2004-09-10 20:51:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-10 10:41:27 +00:00
|
|
|
/* do this really late in the init sequence */
|
|
|
|
void tree_gui_init(void)
|
2004-09-10 20:51:12 +00:00
|
|
|
{
|
2005-11-17 20:14:59 +00:00
|
|
|
gui_sync_wps_screen_init();
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2004-09-10 20:51:12 +00:00
|
|
|
check_rockboxdir();
|
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
strcpy(tc.currdir, "/");
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-06-29 17:39:18 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
screens[i].double_height(false);
|
2005-06-29 17:39:18 +00:00
|
|
|
#endif
|
2005-10-28 00:00:00 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_init(&tree_buttonbar);
|
|
|
|
/* since archos only have one screen, no need to create more than that */
|
|
|
|
gui_buttonbar_set_display(&tree_buttonbar, &(screens[SCREEN_MAIN]) );
|
|
|
|
#endif
|
2008-03-26 03:35:24 +00:00
|
|
|
gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL);
|
2007-10-21 00:20:51 +00:00
|
|
|
gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb);
|
2007-03-01 18:25:13 +00:00
|
|
|
gui_synclist_set_icon_callback(&tree_lists, &tree_get_fileicon);
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2008-03-05 09:58:30 +00:00
|
|
|
gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor);
|
2007-06-17 21:16:34 +00:00
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 13:03:01 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
struct tree_context* tree_get_context(void)
|
|
|
|
{
|
|
|
|
return &tc;
|
|
|
|
}
|
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/*
|
|
|
|
* Returns the position of a given file in the current directory
|
|
|
|
* returns -1 if not found
|
|
|
|
*/
|
2006-12-25 14:01:47 +00:00
|
|
|
static int tree_get_file_position(char * filename)
|
2004-03-27 00:11:01 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* use lastfile to determine the selected item (default=0) */
|
|
|
|
for (i=0; i < tc.filesindir; i++)
|
2003-01-24 10:56:59 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
struct entry* dc = tc.dircache;
|
|
|
|
struct entry* e = &dc[i];
|
|
|
|
if (!strcasecmp(e->name, filename))
|
|
|
|
return(i);
|
2003-01-24 10:56:59 +00:00
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
return(-1);/* no file can match, returns undefined */
|
2004-03-16 13:44:56 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/*
|
|
|
|
* Called when a new dir is loaded (for example when returning from other apps ...)
|
|
|
|
* also completely redraws the tree
|
|
|
|
*/
|
|
|
|
static int update_dir(void)
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
2007-11-20 13:53:29 +00:00
|
|
|
bool changed = false;
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-01-18 23:07:23 +00:00
|
|
|
bool id3db = *tc.dirfilter == SHOW_ID3DB;
|
2005-10-28 00:00:00 +00:00
|
|
|
/* Checks for changes */
|
2005-01-17 11:39:46 +00:00
|
|
|
if (id3db) {
|
2005-01-18 22:45:00 +00:00
|
|
|
if (tc.currtable != lasttable ||
|
|
|
|
tc.currextra != lastextra ||
|
2006-06-07 20:42:42 +00:00
|
|
|
tc.firstpos != lastfirstpos ||
|
|
|
|
reload_dir)
|
2005-01-18 22:45:00 +00:00
|
|
|
{
|
2006-03-26 11:33:42 +00:00
|
|
|
if (tagtree_load(&tc) < 0)
|
2005-01-18 22:45:00 +00:00
|
|
|
return -1;
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-01-18 22:45:00 +00:00
|
|
|
lasttable = tc.currtable;
|
|
|
|
lastextra = tc.currextra;
|
|
|
|
lastfirstpos = tc.firstpos;
|
2005-10-28 00:00:00 +00:00
|
|
|
changed = true;
|
2005-01-18 22:45:00 +00:00
|
|
|
}
|
2005-01-17 11:39:46 +00:00
|
|
|
}
|
2006-10-25 10:17:57 +00:00
|
|
|
else
|
|
|
|
#endif
|
2007-11-20 13:53:29 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
/* if the tc.currdir has been changed, reload it ...*/
|
2007-11-20 13:53:29 +00:00
|
|
|
if (strncmp(tc.currdir, lastdir, sizeof(lastdir)) || reload_dir)
|
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
if (ft_load(&tc, NULL) < 0)
|
2005-01-17 11:39:46 +00:00
|
|
|
return -1;
|
2005-01-18 22:45:00 +00:00
|
|
|
strcpy(lastdir, tc.currdir);
|
2005-10-28 00:00:00 +00:00
|
|
|
changed = true;
|
2005-01-17 11:39:46 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
/* if selected item is undefined */
|
|
|
|
if (tc.selected_item == -1)
|
2005-01-18 22:45:00 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
/* use lastfile to determine the selected item */
|
|
|
|
tc.selected_item = tree_get_file_position(lastfile);
|
2002-09-09 17:32:15 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* If the file doesn't exists, select the first one (default) */
|
|
|
|
if(tc.selected_item < 0)
|
|
|
|
tc.selected_item = 0;
|
|
|
|
changed = true;
|
2002-09-09 14:25:39 +00:00
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
if (changed)
|
2003-04-14 07:53:58 +00:00
|
|
|
{
|
2006-10-25 10:17:57 +00:00
|
|
|
if(
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-02-27 11:09:09 +00:00
|
|
|
!id3db &&
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2007-11-20 13:53:29 +00:00
|
|
|
(tc.dirfull || tc.filesindir == global_settings.max_files_in_dir) )
|
2003-04-14 07:53:58 +00:00
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
|
2002-09-03 20:47:23 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-09-19 12:36:21 +00:00
|
|
|
if (id3db)
|
|
|
|
{
|
2008-01-13 09:29:45 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-09-19 12:36:21 +00:00
|
|
|
if (global_settings.show_path_in_browser == SHOW_PATH_FULL
|
|
|
|
|| global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
|
|
|
|
{
|
|
|
|
gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc),
|
2007-03-01 18:25:13 +00:00
|
|
|
filetype_get_icon(ATTR_DIRECTORY));
|
2006-09-19 12:36:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Must clear the title as the list is reused */
|
|
|
|
gui_synclist_set_title(&tree_lists, NULL, NOICON);
|
|
|
|
}
|
2008-01-13 09:29:45 +00:00
|
|
|
#endif
|
2006-09-19 12:36:21 +00:00
|
|
|
}
|
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-09-19 12:36:21 +00:00
|
|
|
{
|
2008-01-13 09:29:45 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-08-16 13:55:37 +00:00
|
|
|
if (global_settings.show_path_in_browser &&
|
|
|
|
*(tc.dirfilter) == SHOW_PLUGINS)
|
|
|
|
{
|
|
|
|
char *title;
|
|
|
|
if (!strcmp(tc.currdir, PLUGIN_GAMES_DIR))
|
|
|
|
title = str(LANG_PLUGIN_GAMES);
|
|
|
|
else if (!strcmp(tc.currdir, PLUGIN_APPS_DIR))
|
|
|
|
title = str(LANG_PLUGIN_APPS);
|
|
|
|
else if (!strcmp(tc.currdir, PLUGIN_DEMOS_DIR))
|
|
|
|
title = str(LANG_PLUGIN_DEMOS);
|
|
|
|
else title = str(LANG_PLUGINS);
|
|
|
|
gui_synclist_set_title(&tree_lists, title, Icon_Plugin);
|
|
|
|
}
|
|
|
|
else if (global_settings.show_path_in_browser == SHOW_PATH_FULL)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
|
|
|
gui_synclist_set_title(&tree_lists, tc.currdir,
|
2007-03-01 18:25:13 +00:00
|
|
|
filetype_get_icon(ATTR_DIRECTORY));
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
|
|
|
|
{
|
|
|
|
char *title = strrchr(tc.currdir, '/') + 1;
|
|
|
|
if (*title == '\0')
|
|
|
|
{
|
2007-03-01 17:34:49 +00:00
|
|
|
/* Display "Files" for the root dir */
|
|
|
|
gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER),
|
2007-03-01 18:25:13 +00:00
|
|
|
filetype_get_icon(ATTR_DIRECTORY));
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
gui_synclist_set_title(&tree_lists, title,
|
2007-03-01 18:25:13 +00:00
|
|
|
filetype_get_icon(ATTR_DIRECTORY));
|
2006-08-15 12:23:55 +00:00
|
|
|
}
|
2006-08-23 20:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Must clear the title as the list is reused */
|
|
|
|
gui_synclist_set_title(&tree_lists, NULL, NOICON);
|
|
|
|
}
|
2008-01-13 09:29:45 +00:00
|
|
|
#endif
|
2006-08-15 09:38:13 +00:00
|
|
|
}
|
2006-09-19 12:36:21 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_set_nb_items(&tree_lists, tc.filesindir);
|
2007-03-01 18:25:13 +00:00
|
|
|
gui_synclist_set_icon_callback(&tree_lists, tree_get_fileicon);
|
2005-11-09 01:17:57 +00:00
|
|
|
if( tc.selected_item >= tc.filesindir)
|
|
|
|
tc.selected_item=tc.filesindir-1;
|
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_select_item(&tree_lists, tc.selected_item);
|
|
|
|
#ifdef HAS_BUTTONBAR
|
2005-05-16 11:50:46 +00:00
|
|
|
if (global_settings.buttonbar) {
|
|
|
|
if (*tc.dirfilter < NUM_FILTER_MODES)
|
2006-08-07 21:24:22 +00:00
|
|
|
gui_buttonbar_set(&tree_buttonbar, str(LANG_SYSFONT_DIRBROWSE_F1),
|
|
|
|
str(LANG_SYSFONT_DIRBROWSE_F2),
|
|
|
|
str(LANG_SYSFONT_DIRBROWSE_F3));
|
2005-05-16 11:50:46 +00:00
|
|
|
else
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_buttonbar_set(&tree_buttonbar, "<<<", "", "");
|
|
|
|
gui_buttonbar_draw(&tree_buttonbar);
|
2004-03-16 13:44:56 +00:00
|
|
|
}
|
2004-10-09 20:54:15 +00:00
|
|
|
#endif
|
2006-07-01 10:31:50 +00:00
|
|
|
gui_synclist_draw(&tree_lists);
|
2007-10-21 00:20:51 +00:00
|
|
|
gui_synclist_speak_item(&tree_lists);
|
2006-07-01 10:31:50 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2005-01-17 11:39:46 +00:00
|
|
|
return tc.filesindir;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* load tracks from specified directory to resume play */
|
2004-08-18 01:09:31 +00:00
|
|
|
void resume_directory(const char *dir)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-04-03 18:52:58 +00:00
|
|
|
bool id3db = *tc.dirfilter == SHOW_ID3DB;
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-04-10 03:51:17 +00:00
|
|
|
|
2005-01-25 08:55:21 +00:00
|
|
|
if (ft_load(&tc, dir) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return;
|
|
|
|
lastdir[0] = 0;
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
ft_build_playlist(&tc, 0);
|
2006-04-03 18:52:58 +00:00
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-04-03 18:52:58 +00:00
|
|
|
if (id3db)
|
|
|
|
tagtree_load(&tc);
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the current working directory and also writes cwd to buf if
|
|
|
|
non-NULL. In case of error, returns NULL. */
|
|
|
|
char *getcwd(char *buf, int size)
|
|
|
|
{
|
|
|
|
if (!buf)
|
2005-01-17 11:39:46 +00:00
|
|
|
return tc.currdir;
|
2003-07-01 21:05:43 +00:00
|
|
|
else if (size > 0)
|
|
|
|
{
|
2005-01-17 11:39:46 +00:00
|
|
|
strncpy(buf, tc.currdir, size);
|
2003-07-01 21:05:43 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force a reload of the directory next time directory browser is called */
|
|
|
|
void reload_directory(void)
|
|
|
|
{
|
|
|
|
reload_dir = true;
|
|
|
|
}
|
|
|
|
|
2007-03-06 08:21:18 +00:00
|
|
|
void get_current_file(char* buffer, int buffer_len)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
/* in ID3DB mode it is a bad idea to call this function */
|
|
|
|
/* (only happens with `follow playlist') */
|
|
|
|
if( *tc.dirfilter == SHOW_ID3DB )
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct entry* dc = tc.dircache;
|
|
|
|
struct entry* e = &dc[tc.selected_item];
|
|
|
|
snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0),
|
2007-04-07 15:31:22 +00:00
|
|
|
tc.dirlength ? e->name : "");
|
2007-03-06 08:21:18 +00:00
|
|
|
}
|
|
|
|
|
2007-08-05 12:14:07 +00:00
|
|
|
/* Allow apps to change our dirfilter directly (required for sub browsers)
|
|
|
|
if they're suddenly going to become a file browser for example */
|
|
|
|
void set_dirfilter(int l_dirfilter)
|
|
|
|
{
|
|
|
|
*tc.dirfilter = l_dirfilter;
|
|
|
|
}
|
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* Selects a file and update tree context properly */
|
2007-08-05 12:14:07 +00:00
|
|
|
void set_current_file(char *path)
|
2002-09-09 14:25:39 +00:00
|
|
|
{
|
|
|
|
char *name;
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2002-09-09 14:25:39 +00:00
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-03-11 08:18:28 +00:00
|
|
|
/* in ID3DB mode it is a bad idea to call this function */
|
|
|
|
/* (only happens with `follow playlist') */
|
|
|
|
if( *tc.dirfilter == SHOW_ID3DB )
|
|
|
|
return;
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2005-03-11 08:18:28 +00:00
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
/* separate directory from filename */
|
2005-10-28 00:00:00 +00:00
|
|
|
/* gets the directory's name and put it into tc.currdir */
|
2002-09-17 07:42:21 +00:00
|
|
|
name = strrchr(path+1,'/');
|
2002-09-09 14:25:39 +00:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
*name = 0;
|
2005-01-17 11:39:46 +00:00
|
|
|
strcpy(tc.currdir, path);
|
2002-09-09 14:25:39 +00:00
|
|
|
*name = '/';
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-01-17 11:39:46 +00:00
|
|
|
strcpy(tc.currdir, "/");
|
2002-09-09 14:25:39 +00:00
|
|
|
name = path+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(lastfile, name);
|
2006-04-10 03:51:17 +00:00
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* If we changed dir we must recalculate the dirlevel
|
|
|
|
and adjust the selected history properly */
|
2005-01-17 11:39:46 +00:00
|
|
|
if (strncmp(tc.currdir,lastdir,sizeof(lastdir)))
|
2002-09-09 14:25:39 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
tc.dirlevel = 0;
|
|
|
|
tc.selected_item_history[tc.dirlevel] = -1;
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
/* use '/' to calculate dirlevel */
|
2007-03-01 11:14:46 +00:00
|
|
|
for (i = 1; path[i] != '\0'; i++)
|
2002-09-09 14:25:39 +00:00
|
|
|
{
|
|
|
|
if (path[i] == '/')
|
|
|
|
{
|
2005-01-17 11:39:46 +00:00
|
|
|
tc.dirlevel++;
|
2005-10-28 00:00:00 +00:00
|
|
|
tc.selected_item_history[tc.dirlevel] = -1;
|
2002-09-09 14:25:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
if (ft_load(&tc, NULL) >= 0)
|
|
|
|
{
|
|
|
|
tc.selected_item = tree_get_file_position(lastfile);
|
|
|
|
}
|
2002-09-09 14:25:39 +00:00
|
|
|
}
|
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
/* main loop, handles key events */
|
2007-03-17 00:55:23 +00:00
|
|
|
static int dirbrowse()
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
2002-08-08 12:06:38 +00:00
|
|
|
int numentries=0;
|
2002-07-15 22:46:38 +00:00
|
|
|
char buf[MAX_PATH];
|
2007-09-17 10:08:50 +00:00
|
|
|
unsigned button, oldbutton;
|
2002-09-03 20:47:23 +00:00
|
|
|
bool reload_root = false;
|
2005-01-17 11:39:46 +00:00
|
|
|
int lastfilter = *tc.dirfilter;
|
2002-09-03 20:47:23 +00:00
|
|
|
bool lastsortcase = global_settings.sort_case;
|
2003-09-29 21:26:53 +00:00
|
|
|
bool exit_func = false;
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
char* currdir = tc.currdir; /* just a shortcut */
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-01-18 23:07:23 +00:00
|
|
|
bool id3db = *tc.dirfilter == SHOW_ID3DB;
|
2003-01-24 10:56:59 +00:00
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
if (id3db)
|
|
|
|
curr_context=CONTEXT_ID3DB;
|
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2005-06-23 01:31:26 +00:00
|
|
|
curr_context=CONTEXT_TREE;
|
2007-03-01 11:14:46 +00:00
|
|
|
if (tc.selected_item < 0)
|
|
|
|
tc.selected_item = 0;
|
2007-02-06 13:25:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-11-20 13:53:29 +00:00
|
|
|
tc.firstpos = 0;
|
2005-01-18 22:45:00 +00:00
|
|
|
lasttable = -1;
|
|
|
|
lastextra = -1;
|
|
|
|
lastfirstpos = 0;
|
2007-02-06 13:25:57 +00:00
|
|
|
#endif
|
2002-09-09 14:25:39 +00:00
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
start_wps = false;
|
|
|
|
numentries = update_dir();
|
2007-10-21 00:20:51 +00:00
|
|
|
reload_dir = false;
|
2007-03-01 11:14:46 +00:00
|
|
|
if (numentries == -1)
|
2007-10-19 06:11:13 +00:00
|
|
|
return GO_TO_PREVIOUS; /* currdir is not a directory */
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ*2, ID2P(LANG_NO_FILES));
|
2007-10-19 06:11:13 +00:00
|
|
|
return GO_TO_PREVIOUS; /* No files found for rockbox_browser() */
|
2005-01-21 15:42:47 +00:00
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
while(1) {
|
2005-01-17 11:39:46 +00:00
|
|
|
struct entry *dircache = tc.dircache;
|
2002-06-25 13:26:04 +00:00
|
|
|
bool restore = false;
|
2007-03-01 11:14:46 +00:00
|
|
|
if (tc.dirlevel < 0)
|
2007-11-20 13:53:29 +00:00
|
|
|
tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
|
2005-03-31 10:50:15 +00:00
|
|
|
#ifdef BOOTFILE
|
2003-06-29 22:39:35 +00:00
|
|
|
if (boot_changed) {
|
2008-04-26 09:30:24 +00:00
|
|
|
static const char *lines[]={ID2P(LANG_BOOT_CHANGED), ID2P(LANG_REBOOT_NOW)};
|
|
|
|
static const struct text_message message={lines, 2};
|
2005-11-18 02:07:02 +00:00
|
|
|
if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
|
|
|
|
rolo_load("/" BOOTFILE);
|
2003-06-29 22:39:35 +00:00
|
|
|
restore = true;
|
|
|
|
boot_changed = false;
|
|
|
|
}
|
|
|
|
#endif
|
2007-10-21 00:20:51 +00:00
|
|
|
button = get_action(CONTEXT_TREE,
|
|
|
|
list_do_action_timeout(&tree_lists, HZ/2));
|
2007-09-17 10:08:50 +00:00
|
|
|
oldbutton = button;
|
2007-10-21 00:20:51 +00:00
|
|
|
gui_synclist_do_button(&tree_lists, &button,LIST_WRAP_UNLESS_HELD);
|
2007-03-10 12:51:08 +00:00
|
|
|
tc.selected_item = gui_synclist_get_sel_pos(&tree_lists);
|
2002-07-27 20:55:39 +00:00
|
|
|
switch ( button ) {
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_OK:
|
2005-10-28 00:00:00 +00:00
|
|
|
/* nothing to do if no files to display */
|
|
|
|
if ( numentries == 0 )
|
2005-01-17 11:39:46 +00:00
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-03-26 11:33:42 +00:00
|
|
|
switch (id3db?tagtree_enter(&tc):ft_enter(&tc))
|
2006-10-25 10:17:57 +00:00
|
|
|
#else
|
|
|
|
switch (ft_enter(&tc))
|
|
|
|
#endif
|
2005-01-20 16:24:26 +00:00
|
|
|
{
|
|
|
|
case 1: reload_dir = true; break;
|
2005-05-17 18:28:32 +00:00
|
|
|
case 2: start_wps = true; break;
|
|
|
|
case 3: exit_func = true; break;
|
2005-01-20 16:24:26 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2005-01-17 11:39:46 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_CANCEL:
|
2005-01-18 22:59:29 +00:00
|
|
|
if (*tc.dirfilter > NUM_FILTER_MODES && tc.dirlevel < 1) {
|
|
|
|
exit_func = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
if ((*tc.dirfilter == SHOW_ID3DB && tc.dirlevel == 0) ||
|
|
|
|
((*tc.dirfilter != SHOW_ID3DB && !strcmp(currdir,"/"))))
|
|
|
|
{
|
2007-09-17 10:08:50 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
|
|
|
|
if (oldbutton == ACTION_TREE_PGLEFT)
|
2007-03-01 23:41:45 +00:00
|
|
|
break;
|
|
|
|
else
|
2007-09-17 10:08:50 +00:00
|
|
|
#endif
|
2007-03-01 23:41:45 +00:00
|
|
|
return GO_TO_ROOT;
|
2007-03-01 11:14:46 +00:00
|
|
|
}
|
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-08-15 21:27:04 +00:00
|
|
|
if (id3db)
|
|
|
|
tagtree_exit(&tc);
|
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-08-15 21:27:04 +00:00
|
|
|
if (ft_exit(&tc) == 3)
|
|
|
|
exit_func = true;
|
|
|
|
|
|
|
|
restore = true;
|
|
|
|
break;
|
2005-01-17 11:39:46 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_TREE_STOP:
|
2007-04-09 13:39:37 +00:00
|
|
|
if (list_stop_handler())
|
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_MENU:
|
2007-03-01 13:01:14 +00:00
|
|
|
return GO_TO_ROOT;
|
2002-06-25 13:26:04 +00:00
|
|
|
break;
|
2002-05-21 14:30:54 +00:00
|
|
|
|
2007-08-02 12:13:20 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
case ACTION_STD_REC:
|
|
|
|
return GO_TO_RECSCREEN;
|
|
|
|
#endif
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_TREE_WPS:
|
2007-03-01 13:01:14 +00:00
|
|
|
return GO_TO_PREVIOUS_MUSIC;
|
2002-05-21 14:30:54 +00:00
|
|
|
break;
|
2006-04-10 03:51:17 +00:00
|
|
|
#ifdef HAVE_QUICKSCREEN
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_QUICKSCREEN:
|
2005-01-17 11:39:46 +00:00
|
|
|
/* don't enter f2 from plugin browser */
|
|
|
|
if (*tc.dirfilter < NUM_FILTER_MODES)
|
2003-11-04 16:47:05 +00:00
|
|
|
{
|
2005-11-22 21:55:05 +00:00
|
|
|
if (quick_screen_quick(button))
|
2005-05-16 12:07:25 +00:00
|
|
|
reload_dir = true;
|
2003-11-04 16:47:05 +00:00
|
|
|
restore = true;
|
|
|
|
}
|
2006-04-03 06:08:24 +00:00
|
|
|
break;
|
2005-06-26 20:16:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef BUTTON_F3
|
2006-08-22 08:23:24 +00:00
|
|
|
case ACTION_F3:
|
2005-01-17 11:39:46 +00:00
|
|
|
/* don't enter f3 from plugin browser */
|
|
|
|
if (*tc.dirfilter < NUM_FILTER_MODES)
|
2003-11-04 16:47:05 +00:00
|
|
|
{
|
2008-04-03 13:38:24 +00:00
|
|
|
if (quick_screen_f3(ACTION_F3))
|
2005-05-16 12:07:25 +00:00
|
|
|
reload_dir = true;
|
2003-11-04 16:47:05 +00:00
|
|
|
restore = true;
|
|
|
|
}
|
2004-10-05 00:08:04 +00:00
|
|
|
break;
|
2002-08-20 19:39:55 +00:00
|
|
|
#endif
|
2004-10-05 00:08:04 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_CONTEXT:
|
2004-10-05 00:08:04 +00:00
|
|
|
{
|
|
|
|
int onplay_result;
|
2005-01-20 16:24:26 +00:00
|
|
|
int attr = 0;
|
2004-10-05 00:08:04 +00:00
|
|
|
|
|
|
|
if(!numentries)
|
2005-06-23 01:31:26 +00:00
|
|
|
onplay_result = onplay(NULL, 0, curr_context);
|
2004-10-05 00:08:04 +00:00
|
|
|
else {
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-06-23 01:31:26 +00:00
|
|
|
if (id3db)
|
2005-08-30 07:52:36 +00:00
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
if (tagtree_get_attr(&tc) == FILE_ATTR_AUDIO)
|
2005-06-23 01:31:26 +00:00
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
attr = FILE_ATTR_AUDIO;
|
2006-05-05 07:01:43 +00:00
|
|
|
tagtree_get_filename(&tc, buf, sizeof(buf));
|
2005-06-23 01:31:26 +00:00
|
|
|
}
|
2006-07-25 07:41:00 +00:00
|
|
|
else
|
|
|
|
attr = ATTR_DIRECTORY;
|
2005-08-30 07:52:36 +00:00
|
|
|
}
|
2005-06-23 01:31:26 +00:00
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2005-08-30 07:52:36 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
attr = dircache[tc.selected_item].attr;
|
2005-08-30 07:52:36 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
if (currdir[1]) /* Not in / */
|
2005-08-30 07:52:36 +00:00
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir,
|
2005-10-28 00:00:00 +00:00
|
|
|
dircache[tc.selected_item].name);
|
|
|
|
else /* In / */
|
2005-08-30 07:52:36 +00:00
|
|
|
snprintf(buf, sizeof buf, "/%s",
|
2005-10-28 00:00:00 +00:00
|
|
|
dircache[tc.selected_item].name);
|
2005-08-30 07:52:36 +00:00
|
|
|
}
|
2005-06-23 01:31:26 +00:00
|
|
|
onplay_result = onplay(buf, attr, curr_context);
|
2004-10-05 00:08:04 +00:00
|
|
|
}
|
|
|
|
switch (onplay_result)
|
|
|
|
{
|
2007-03-01 11:14:46 +00:00
|
|
|
case ONPLAY_MAINMENU:
|
|
|
|
return GO_TO_ROOT;
|
|
|
|
|
2004-10-05 00:08:04 +00:00
|
|
|
case ONPLAY_OK:
|
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ONPLAY_RELOAD_DIR:
|
|
|
|
reload_dir = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ONPLAY_START_PLAY:
|
2007-03-01 11:14:46 +00:00
|
|
|
return GO_TO_WPS;
|
2004-10-05 00:08:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
2004-10-05 00:08:04 +00:00
|
|
|
}
|
2002-08-07 10:35:26 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_NONE:
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2002-10-28 09:11:42 +00:00
|
|
|
break;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
2005-01-28 23:02:05 +00:00
|
|
|
#ifdef HAVE_HOTSWAP
|
|
|
|
case SYS_FS_CHANGED:
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-05-14 23:48:18 +00:00
|
|
|
if (!id3db)
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2005-10-28 00:00:00 +00:00
|
|
|
reload_dir = true;
|
2005-05-14 23:48:18 +00:00
|
|
|
/* The 'dir no longer valid' situation will be caught later
|
|
|
|
* by checking the showdir() result. */
|
2005-01-28 23:02:05 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-07-26 16:06:59 +00:00
|
|
|
default:
|
2005-09-14 09:07:05 +00:00
|
|
|
if (default_event_handler(button) == SYS_USB_CONNECTED)
|
2004-10-24 23:19:13 +00:00
|
|
|
{
|
2005-01-17 11:39:46 +00:00
|
|
|
if(*tc.dirfilter > NUM_FILTER_MODES)
|
2004-10-24 23:19:13 +00:00
|
|
|
/* leave sub-browsers after usb, doing otherwise
|
|
|
|
might be confusing to the user */
|
|
|
|
exit_func = true;
|
|
|
|
else
|
2005-05-16 11:50:46 +00:00
|
|
|
reload_dir = true;
|
2004-10-24 23:19:13 +00:00
|
|
|
}
|
2004-07-26 16:06:59 +00:00
|
|
|
break;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
if (start_wps)
|
|
|
|
return GO_TO_WPS;
|
2007-11-20 13:53:29 +00:00
|
|
|
if (button)
|
2004-10-05 00:08:04 +00:00
|
|
|
{
|
2002-08-26 13:21:14 +00:00
|
|
|
ata_spin();
|
2004-10-05 00:08:04 +00:00
|
|
|
}
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2005-05-14 23:48:18 +00:00
|
|
|
check_rescan:
|
2002-09-03 20:47:23 +00:00
|
|
|
/* do we need to rescan dir? */
|
2003-03-07 08:10:10 +00:00
|
|
|
if (reload_dir || reload_root ||
|
2005-01-17 11:39:46 +00:00
|
|
|
lastfilter != *tc.dirfilter ||
|
2002-09-24 19:12:09 +00:00
|
|
|
lastsortcase != global_settings.sort_case)
|
2002-09-03 20:47:23 +00:00
|
|
|
{
|
2007-11-20 13:53:29 +00:00
|
|
|
if (reload_root) {
|
2002-09-03 20:47:23 +00:00
|
|
|
strcpy(currdir, "/");
|
2005-01-17 11:39:46 +00:00
|
|
|
tc.dirlevel = 0;
|
2007-02-06 13:25:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2005-04-26 19:23:47 +00:00
|
|
|
tc.currtable = 0;
|
|
|
|
tc.currextra = 0;
|
|
|
|
lasttable = -1;
|
|
|
|
lastextra = -1;
|
2007-02-06 13:25:57 +00:00
|
|
|
#endif
|
2002-09-03 20:47:23 +00:00
|
|
|
reload_root = false;
|
|
|
|
}
|
2006-04-10 03:51:17 +00:00
|
|
|
|
2007-11-20 13:53:29 +00:00
|
|
|
if (!reload_dir)
|
2003-03-07 08:10:10 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_select_item(&tree_lists, 0);
|
|
|
|
gui_synclist_draw(&tree_lists);
|
|
|
|
tc.selected_item = 0;
|
2003-03-07 08:10:10 +00:00
|
|
|
lastdir[0] = 0;
|
|
|
|
}
|
2003-09-29 21:26:53 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
lastfilter = *tc.dirfilter;
|
2002-09-03 20:47:23 +00:00
|
|
|
lastsortcase = global_settings.sort_case;
|
|
|
|
restore = true;
|
|
|
|
}
|
|
|
|
|
2003-09-29 21:26:53 +00:00
|
|
|
if (exit_func)
|
2007-03-01 11:14:46 +00:00
|
|
|
return GO_TO_PREVIOUS;
|
2003-09-29 21:26:53 +00:00
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
if (restore || reload_dir) {
|
2002-06-25 13:26:04 +00:00
|
|
|
/* restore display */
|
2005-10-28 00:00:00 +00:00
|
|
|
numentries = update_dir();
|
2007-10-21 00:20:51 +00:00
|
|
|
reload_dir = false;
|
2005-05-16 11:50:46 +00:00
|
|
|
if (currdir[1] && (numentries < 0))
|
2005-05-14 23:48:18 +00:00
|
|
|
{ /* not in root and reload failed */
|
|
|
|
reload_root = true; /* try root */
|
|
|
|
goto check_rescan;
|
|
|
|
}
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2003-01-31 08:43:12 +00:00
|
|
|
return true;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2003-01-29 13:20:22 +00:00
|
|
|
|
|
|
|
static int plsize = 0;
|
2006-03-04 22:32:25 +00:00
|
|
|
static long pltick;
|
2004-03-21 22:27:56 +00:00
|
|
|
static bool add_dir(char* dirname, int len, int fd)
|
2003-01-29 13:20:22 +00:00
|
|
|
{
|
|
|
|
bool abort = false;
|
2007-07-20 17:06:55 +00:00
|
|
|
DIR* dir;
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2003-01-29 13:20:22 +00:00
|
|
|
/* check for user abort */
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2003-01-29 13:20:22 +00:00
|
|
|
return true;
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2007-07-20 17:06:55 +00:00
|
|
|
dir = opendir(dirname);
|
2003-01-29 13:20:22 +00:00
|
|
|
if(!dir)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while (true) {
|
2007-07-20 17:06:55 +00:00
|
|
|
struct dirent *entry;
|
2003-01-29 13:20:22 +00:00
|
|
|
|
2007-07-20 17:06:55 +00:00
|
|
|
entry = readdir(dir);
|
2003-01-29 13:20:22 +00:00
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY) {
|
2004-03-21 22:27:56 +00:00
|
|
|
int dirlen = strlen(dirname);
|
|
|
|
bool result;
|
|
|
|
|
2005-12-05 22:44:42 +00:00
|
|
|
if (!strcmp((char *)entry->d_name, ".") ||
|
|
|
|
!strcmp((char *)entry->d_name, ".."))
|
2003-01-29 13:20:22 +00:00
|
|
|
continue;
|
2004-03-21 22:27:56 +00:00
|
|
|
|
2003-03-11 09:57:46 +00:00
|
|
|
if (dirname[1])
|
2004-03-21 22:27:56 +00:00
|
|
|
snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
|
2003-03-11 09:57:46 +00:00
|
|
|
else
|
2004-03-21 22:27:56 +00:00
|
|
|
snprintf(dirname, len, "/%s", entry->d_name);
|
|
|
|
|
|
|
|
result = add_dir(dirname, len, fd);
|
|
|
|
dirname[dirlen] = '\0';
|
|
|
|
if (result) {
|
2003-01-29 13:20:22 +00:00
|
|
|
abort = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2005-12-05 22:44:42 +00:00
|
|
|
int x = strlen((char *)entry->d_name);
|
2007-04-18 13:03:01 +00:00
|
|
|
int i;
|
2005-12-05 22:44:42 +00:00
|
|
|
char *cp = strrchr((char *)entry->d_name,'.');
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-09-02 16:50:51 +00:00
|
|
|
if (cp) {
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
/* add all supported audio files to playlists */
|
2007-04-18 13:03:01 +00:00
|
|
|
for (i=0; i < filetypes_count; i++) {
|
|
|
|
if (filetypes[i].tree_attr == FILE_ATTR_AUDIO) {
|
2006-03-04 22:32:25 +00:00
|
|
|
if (!strcasecmp(cp, filetypes[i].extension)) {
|
2005-09-02 16:50:51 +00:00
|
|
|
char buf[8];
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2005-09-02 16:50:51 +00:00
|
|
|
write(fd, dirname, strlen(dirname));
|
|
|
|
write(fd, "/", 1);
|
|
|
|
write(fd, entry->d_name, x);
|
|
|
|
write(fd, "\n", 1);
|
|
|
|
|
|
|
|
plsize++;
|
2006-03-04 22:32:25 +00:00
|
|
|
if(TIME_AFTER(current_tick, pltick+HZ/4)) {
|
|
|
|
pltick = current_tick;
|
2006-04-10 03:51:17 +00:00
|
|
|
|
2006-03-04 22:32:25 +00:00
|
|
|
snprintf(buf, sizeof buf, "%d", plsize);
|
2003-01-29 13:20:22 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-03-04 22:32:25 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].puts(0, 4, (unsigned char *)buf);
|
|
|
|
gui_textarea_update(&screens[i]);
|
|
|
|
}
|
2003-01-29 13:20:22 +00:00
|
|
|
#else
|
2006-03-04 22:32:25 +00:00
|
|
|
if (plsize > 999)
|
|
|
|
x=7;
|
2007-11-20 13:53:29 +00:00
|
|
|
else if (plsize > 99)
|
|
|
|
x=8;
|
|
|
|
else if (plsize > 9)
|
|
|
|
x=9;
|
|
|
|
else
|
|
|
|
x = 10;
|
|
|
|
|
2006-03-04 22:32:25 +00:00
|
|
|
FOR_NB_SCREENS(i) {
|
|
|
|
screens[i].puts(x,0,buf);
|
2005-09-02 16:50:51 +00:00
|
|
|
}
|
2005-06-20 09:00:53 +00:00
|
|
|
#endif
|
2006-03-04 22:32:25 +00:00
|
|
|
}
|
2005-09-02 16:50:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-01-29 13:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-20 17:06:55 +00:00
|
|
|
closedir(dir);
|
2003-01-29 13:20:22 +00:00
|
|
|
|
|
|
|
return abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool create_playlist(void)
|
|
|
|
{
|
|
|
|
int fd;
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2003-01-29 13:20:22 +00:00
|
|
|
char filename[MAX_PATH];
|
|
|
|
|
2006-03-04 22:32:25 +00:00
|
|
|
pltick = current_tick;
|
2006-04-10 03:51:17 +00:00
|
|
|
|
2006-12-21 09:07:23 +00:00
|
|
|
snprintf(filename, sizeof filename, "%s.m3u8",
|
2005-01-17 11:39:46 +00:00
|
|
|
tc.currdir[1] ? tc.currdir : "/root");
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-11-02 00:55:46 +00:00
|
|
|
gui_textarea_clear(&screens[i]);
|
2005-12-05 22:44:42 +00:00
|
|
|
screens[i].puts(0, 0, str(LANG_CREATING));
|
|
|
|
screens[i].puts_scroll(0, 1, (unsigned char *)filename);
|
2005-10-28 00:00:00 +00:00
|
|
|
#if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
|
2005-11-02 00:55:46 +00:00
|
|
|
gui_textarea_update(&screens[i]);
|
2005-10-28 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
2007-02-01 23:08:15 +00:00
|
|
|
fd = creat(filename);
|
2003-03-21 03:07:31 +00:00
|
|
|
if (fd < 0)
|
2003-01-29 13:20:22 +00:00
|
|
|
return false;
|
|
|
|
|
2006-11-11 05:33:24 +00:00
|
|
|
trigger_cpu_boost();
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s",
|
|
|
|
tc.currdir[1] ? tc.currdir : "/");
|
2003-01-29 13:20:22 +00:00
|
|
|
plsize = 0;
|
2004-03-21 22:27:56 +00:00
|
|
|
add_dir(filename, sizeof(filename), fd);
|
2003-01-29 13:20:22 +00:00
|
|
|
close(fd);
|
2005-06-20 09:00:53 +00:00
|
|
|
|
2007-11-20 03:44:25 +00:00
|
|
|
cancel_cpu_boost();
|
2003-01-29 13:20:22 +00:00
|
|
|
sleep(HZ);
|
2003-12-12 13:34:27 +00:00
|
|
|
|
2003-03-21 03:07:31 +00:00
|
|
|
return true;
|
2003-01-29 13:20:22 +00:00
|
|
|
}
|
2003-05-09 16:01:21 +00:00
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
int rockbox_browse(const char *root, int dirfilter)
|
2003-09-29 21:26:53 +00:00
|
|
|
{
|
2007-03-01 11:14:46 +00:00
|
|
|
int ret_val = 0;
|
|
|
|
int *last_filter = tc.dirfilter;
|
2005-01-17 11:39:46 +00:00
|
|
|
tc.dirfilter = &dirfilter;
|
2006-08-14 18:19:56 +00:00
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
reload_dir = true;
|
|
|
|
if (dirfilter >= NUM_FILTER_MODES)
|
|
|
|
{
|
|
|
|
static struct tree_context backup;
|
|
|
|
int last_context;
|
|
|
|
|
|
|
|
backup = tc;
|
2007-03-06 08:21:18 +00:00
|
|
|
tc.selected_item = 0;
|
2007-03-01 11:14:46 +00:00
|
|
|
tc.dirlevel = 0;
|
|
|
|
memcpy(tc.currdir, root, sizeof(tc.currdir));
|
|
|
|
start_wps = false;
|
|
|
|
last_context = curr_context;
|
|
|
|
|
|
|
|
ret_val = dirbrowse();
|
|
|
|
tc = backup;
|
|
|
|
curr_context = last_context;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static char buf[MAX_PATH];
|
|
|
|
if (dirfilter != SHOW_ID3DB)
|
|
|
|
tc.dirfilter = &global_settings.dirfilter;
|
|
|
|
strcpy(buf,root);
|
|
|
|
set_current_file(buf);
|
|
|
|
ret_val = dirbrowse();
|
|
|
|
}
|
|
|
|
tc.dirfilter = last_filter;
|
|
|
|
return ret_val;
|
2003-09-29 21:26:53 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 10:41:27 +00:00
|
|
|
void tree_mem_init(void)
|
2003-05-09 16:01:21 +00:00
|
|
|
{
|
2005-01-17 12:56:00 +00:00
|
|
|
/* We copy the settings value in case it is changed by the user. We can't
|
|
|
|
use it until the next reboot. */
|
2005-01-18 22:45:00 +00:00
|
|
|
max_files = global_settings.max_files_in_dir;
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2005-01-17 11:39:46 +00:00
|
|
|
/* initialize tree context struct */
|
|
|
|
memset(&tc, 0, sizeof(tc));
|
|
|
|
tc.dirfilter = &global_settings.dirfilter;
|
|
|
|
|
|
|
|
tc.name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files;
|
|
|
|
tc.name_buffer = buffer_alloc(tc.name_buffer_size);
|
|
|
|
|
|
|
|
tc.dircache_size = max_files * sizeof(struct entry);
|
|
|
|
tc.dircache = buffer_alloc(tc.dircache_size);
|
2007-04-18 13:03:01 +00:00
|
|
|
tree_get_filetypes(&filetypes, &filetypes_count);
|
2003-05-09 16:01:21 +00:00
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2008-02-10 12:16:27 +00:00
|
|
|
bool bookmark_play(char *resume_file, int index, int offset, int seed,
|
2004-12-07 14:20:37 +00:00
|
|
|
char *filename)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-12-07 14:20:37 +00:00
|
|
|
int i;
|
2006-09-21 18:57:54 +00:00
|
|
|
char* suffix = strrchr(resume_file, '.');
|
2008-02-10 12:16:27 +00:00
|
|
|
bool started = false;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2006-09-21 18:57:54 +00:00
|
|
|
if (suffix != NULL &&
|
|
|
|
(!strcasecmp(suffix, ".m3u") || !strcasecmp(suffix, ".m3u8")))
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-12-07 14:20:37 +00:00
|
|
|
/* Playlist playback */
|
2004-01-14 00:13:04 +00:00
|
|
|
char* slash;
|
2005-10-28 00:00:00 +00:00
|
|
|
/* check that the file exists */
|
2008-04-16 19:51:43 +00:00
|
|
|
if(!file_exists(resume_file))
|
2008-02-10 12:16:27 +00:00
|
|
|
return false;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
|
|
|
slash = strrchr(resume_file,'/');
|
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
char* cp;
|
|
|
|
*slash=0;
|
|
|
|
|
|
|
|
cp=resume_file;
|
|
|
|
if (!cp[0])
|
|
|
|
cp="/";
|
|
|
|
|
|
|
|
if (playlist_create(cp, slash+1) != -1)
|
|
|
|
{
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
playlist_shuffle(seed, -1);
|
|
|
|
playlist_start(index,offset);
|
2008-02-10 12:16:27 +00:00
|
|
|
started = true;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
*slash='/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-07 14:20:37 +00:00
|
|
|
/* Directory playback */
|
2004-01-14 00:13:04 +00:00
|
|
|
lastdir[0]='\0';
|
|
|
|
if (playlist_create(resume_file, NULL) != -1)
|
|
|
|
{
|
2007-04-12 19:11:39 +00:00
|
|
|
char* peek_filename;
|
2004-01-14 00:13:04 +00:00
|
|
|
resume_directory(resume_file);
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
playlist_shuffle(seed, -1);
|
2004-12-07 14:20:37 +00:00
|
|
|
|
|
|
|
/* Check if the file is at the same spot in the directory,
|
|
|
|
else search for it */
|
2007-04-12 19:11:39 +00:00
|
|
|
peek_filename = playlist_peek(index);
|
|
|
|
|
|
|
|
if (peek_filename == NULL)
|
2008-02-10 12:16:27 +00:00
|
|
|
return false;
|
2007-04-12 19:11:39 +00:00
|
|
|
|
|
|
|
if (strcmp(strrchr(peek_filename, '/') + 1, filename))
|
2004-12-07 14:20:37 +00:00
|
|
|
{
|
2005-10-28 00:00:00 +00:00
|
|
|
for ( i=0; i < playlist_amount(); i++ )
|
2004-12-07 14:20:37 +00:00
|
|
|
{
|
2007-04-12 19:11:39 +00:00
|
|
|
peek_filename = playlist_peek(i);
|
|
|
|
|
|
|
|
if (peek_filename == NULL)
|
2008-02-10 12:16:27 +00:00
|
|
|
return false;
|
2007-04-12 19:11:39 +00:00
|
|
|
|
|
|
|
if (!strcmp(strrchr(peek_filename, '/') + 1, filename))
|
2004-12-07 14:20:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < playlist_amount())
|
|
|
|
index = i;
|
|
|
|
else
|
2008-02-10 12:16:27 +00:00
|
|
|
return false;
|
2004-12-07 14:20:37 +00:00
|
|
|
}
|
2004-01-14 00:13:04 +00:00
|
|
|
playlist_start(index,offset);
|
2008-02-10 12:16:27 +00:00
|
|
|
started = true;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-10 12:16:27 +00:00
|
|
|
if (started)
|
|
|
|
start_wps = true;
|
|
|
|
return started;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
2005-01-17 11:39:46 +00:00
|
|
|
|
2007-10-21 00:20:51 +00:00
|
|
|
static void say_filetype(int attr)
|
2005-01-17 11:39:46 +00:00
|
|
|
{
|
|
|
|
/* try to find a voice ID for the extension, if known */
|
2007-04-18 13:03:01 +00:00
|
|
|
int j;
|
2007-10-21 00:20:51 +00:00
|
|
|
attr &= FILE_ATTR_MASK; /* file type */
|
2007-04-18 13:03:01 +00:00
|
|
|
for (j=0; j<filetypes_count; j++)
|
2005-01-17 11:39:46 +00:00
|
|
|
if (attr == filetypes[j].tree_attr)
|
|
|
|
{
|
2007-10-21 00:20:51 +00:00
|
|
|
talk_id(filetypes[j].voiceclip, true);
|
|
|
|
return;
|
2005-01-17 11:39:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-17 00:55:23 +00:00
|
|
|
static int ft_play_dirname(char* name)
|
2005-01-17 11:39:46 +00:00
|
|
|
{
|
|
|
|
char dirname_mp3_filename[MAX_PATH+1];
|
|
|
|
|
2006-08-01 22:02:47 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
if (audio_status() & AUDIO_STATUS_PLAY)
|
2005-01-17 11:39:46 +00:00
|
|
|
return 0;
|
2006-08-01 22:02:47 +00:00
|
|
|
#endif
|
2005-01-17 11:39:46 +00:00
|
|
|
|
|
|
|
snprintf(dirname_mp3_filename, sizeof(dirname_mp3_filename), "%s/%s/%s",
|
2006-07-05 23:33:20 +00:00
|
|
|
tc.currdir[1] ? tc.currdir : "" , name,
|
2005-05-02 22:22:21 +00:00
|
|
|
dir_thumbnail_name);
|
2005-01-17 11:39:46 +00:00
|
|
|
|
|
|
|
DEBUGF("Checking for %s\n", dirname_mp3_filename);
|
|
|
|
|
2008-04-16 19:51:43 +00:00
|
|
|
if (!file_exists(dirname_mp3_filename))
|
2005-01-17 11:39:46 +00:00
|
|
|
{
|
|
|
|
DEBUGF("Failed to find: %s\n", dirname_mp3_filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGF("Found: %s\n", dirname_mp3_filename);
|
|
|
|
|
|
|
|
talk_file(dirname_mp3_filename, false);
|
2007-11-07 03:25:33 +00:00
|
|
|
if(global_settings.talk_filetype)
|
|
|
|
talk_id(VOICE_DIR, true);
|
2005-01-17 11:39:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-17 00:55:23 +00:00
|
|
|
static void ft_play_filename(char *dir, char *file)
|
2005-01-17 11:39:46 +00:00
|
|
|
{
|
|
|
|
char name_mp3_filename[MAX_PATH+1];
|
|
|
|
|
2006-08-01 22:02:47 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
if (audio_status() & AUDIO_STATUS_PLAY)
|
2005-01-17 11:39:46 +00:00
|
|
|
return;
|
2006-08-01 22:02:47 +00:00
|
|
|
#endif
|
2005-01-17 11:39:46 +00:00
|
|
|
|
|
|
|
if (strcasecmp(&file[strlen(file) - strlen(file_thumbnail_ext)],
|
|
|
|
file_thumbnail_ext))
|
|
|
|
{ /* file has no .talk extension */
|
|
|
|
snprintf(name_mp3_filename, sizeof(name_mp3_filename),
|
|
|
|
"%s/%s%s", dir, file, file_thumbnail_ext);
|
|
|
|
|
|
|
|
talk_file(name_mp3_filename, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* it already is a .talk file, play this directly */
|
|
|
|
snprintf(name_mp3_filename, sizeof(name_mp3_filename),
|
|
|
|
"%s/%s", dir, file);
|
|
|
|
talk_id(LANG_VOICE_DIR_HOVER, false); /* prefix it */
|
|
|
|
talk_file(name_mp3_filename, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-14 09:07:05 +00:00
|
|
|
/* These two functions are called by the USB and shutdown handlers */
|
|
|
|
void tree_flush(void)
|
|
|
|
{
|
2006-10-19 09:42:58 +00:00
|
|
|
scrobbler_shutdown();
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-09-23 10:29:14 +00:00
|
|
|
tagcache_shutdown();
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-02-05 18:17:41 +00:00
|
|
|
playlist_shutdown();
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-08-09 07:41:28 +00:00
|
|
|
#ifdef HAVE_TC_RAMCACHE
|
|
|
|
tagcache_unload_ramcache();
|
|
|
|
#endif
|
2006-08-11 10:13:16 +00:00
|
|
|
|
2005-10-07 17:38:05 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
{
|
2007-01-24 02:19:22 +00:00
|
|
|
int old_val = global_status.dircache_size;
|
2006-12-12 10:45:34 +00:00
|
|
|
if (global_settings.dircache)
|
|
|
|
{
|
2007-10-07 12:05:48 +00:00
|
|
|
if (!dircache_is_initializing())
|
|
|
|
global_status.dircache_size = dircache_get_cache_size();
|
2006-08-15 22:54:06 +00:00
|
|
|
# ifdef HAVE_EEPROM_SETTINGS
|
2007-04-07 17:48:51 +00:00
|
|
|
if (firmware_settings.initialized)
|
|
|
|
dircache_save();
|
2006-08-05 20:19:10 +00:00
|
|
|
# endif
|
2006-12-12 10:45:34 +00:00
|
|
|
dircache_disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-24 02:19:22 +00:00
|
|
|
global_status.dircache_size = 0;
|
2006-12-12 10:45:34 +00:00
|
|
|
}
|
2007-01-24 02:19:22 +00:00
|
|
|
if (old_val != global_status.dircache_size)
|
|
|
|
status_save();
|
2005-10-07 17:38:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-09-14 09:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tree_restore(void)
|
|
|
|
{
|
2006-08-15 22:54:06 +00:00
|
|
|
#ifdef HAVE_EEPROM_SETTINGS
|
2006-08-09 07:41:28 +00:00
|
|
|
firmware_settings.disk_clean = false;
|
|
|
|
#endif
|
|
|
|
|
2006-08-11 10:13:16 +00:00
|
|
|
#ifdef HAVE_TC_RAMCACHE
|
|
|
|
remove(TAGCACHE_STATEFILE);
|
|
|
|
#endif
|
|
|
|
|
2005-10-07 17:38:05 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2006-08-05 20:19:10 +00:00
|
|
|
remove(DIRCACHE_FILE);
|
2005-10-07 17:38:05 +00:00
|
|
|
if (global_settings.dircache)
|
2005-10-19 11:34:32 +00:00
|
|
|
{
|
|
|
|
/* Print "Scanning disk..." to the display. */
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
|
|
|
screens[i].putsxy((LCD_WIDTH/2) -
|
2007-08-05 19:19:39 +00:00
|
|
|
((strlen(str(LANG_SCANNING_DISK)) *
|
2005-10-28 00:00:00 +00:00
|
|
|
screens[i].char_width)/2),
|
|
|
|
LCD_HEIGHT-screens[i].char_height*3,
|
2007-08-05 19:19:39 +00:00
|
|
|
str(LANG_SCANNING_DISK));
|
2005-11-02 00:55:46 +00:00
|
|
|
gui_textarea_update(&screens[i]);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-08-06 13:08:36 +00:00
|
|
|
cond_talk_ids_fq(LANG_SCANNING_DISK);
|
2005-11-02 12:05:33 +00:00
|
|
|
|
2007-01-24 02:19:22 +00:00
|
|
|
dircache_build(global_status.dircache_size);
|
2005-11-02 12:05:33 +00:00
|
|
|
|
2005-10-19 11:34:32 +00:00
|
|
|
/* Clean the text when we are done. */
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-11-02 12:05:33 +00:00
|
|
|
{
|
|
|
|
gui_textarea_clear(&screens[i]);
|
|
|
|
}
|
2005-10-19 11:34:32 +00:00
|
|
|
}
|
2005-10-07 17:38:05 +00:00
|
|
|
#endif
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-07-12 16:07:27 +00:00
|
|
|
tagcache_start_scan();
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2006-10-19 09:42:58 +00:00
|
|
|
scrobbler_init();
|
2005-09-14 09:07:05 +00:00
|
|
|
}
|