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"
|
|
|
|
#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-24 15:51:39 +00:00
|
|
|
#include "main_menu.h"
|
2002-05-29 16:38:19 +00:00
|
|
|
#include "sprintf.h"
|
2002-05-30 13:23:03 +00:00
|
|
|
#include "mpeg.h"
|
2002-06-07 14:23:32 +00:00
|
|
|
#include "playlist.h"
|
2002-06-14 10:39:11 +00:00
|
|
|
#include "menu.h"
|
2002-06-25 13:26:04 +00:00
|
|
|
#include "wps.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-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
|
|
|
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
#include "ajf.h"
|
|
|
|
#endif
|
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
#define NAME_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH * MAX_FILES_IN_DIR)
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
char name_buffer[NAME_BUFFER_SIZE];
|
|
|
|
int name_buffer_length;
|
2002-05-16 12:53:40 +00:00
|
|
|
struct entry {
|
2002-08-15 12:28:52 +00:00
|
|
|
short attr; /* FAT attributes */
|
|
|
|
char *name;
|
2002-05-16 12:53:40 +00:00
|
|
|
};
|
|
|
|
|
2002-05-30 14:01:36 +00:00
|
|
|
static struct entry dircache[MAX_FILES_IN_DIR];
|
2002-05-28 16:26:12 +00:00
|
|
|
static int filesindir;
|
2002-07-15 22:46:38 +00:00
|
|
|
static char lastdir[MAX_PATH] = {0};
|
2002-05-28 16:26:12 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
void browse_root(void)
|
|
|
|
{
|
2002-07-22 22:45:20 +00:00
|
|
|
dirbrowse("/");
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
#define TREE_MAX_ON_SCREEN ((LCD_HEIGHT-MARGIN_Y)/LINE_HEIGTH-LINE_Y)
|
2002-05-16 12:53:40 +00:00
|
|
|
#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */
|
|
|
|
|
2002-06-18 09:16:47 +00:00
|
|
|
#define MARGIN_Y 0 /* Y pixel margin */
|
2002-08-13 20:55:08 +00:00
|
|
|
#define MARGIN_X 10 /* X pixel margin */
|
2002-08-15 14:12:32 +00:00
|
|
|
#define LINE_Y (global_settings.statusbar ? 1 : 0) /* Y position the entry-list starts at */
|
2002-08-13 20:55:08 +00:00
|
|
|
#define LINE_X 0 /* X position the entry-list starts at */
|
2002-05-16 12:53:40 +00:00
|
|
|
#define LINE_HEIGTH 8 /* pixels for each text line */
|
2002-06-14 08:47:44 +00:00
|
|
|
|
2002-06-18 09:16:47 +00:00
|
|
|
#define CURSOR_Y 0 /* the cursor is not positioned in regard to
|
2002-06-14 08:47:44 +00:00
|
|
|
the margins, so this is the amount of lines
|
|
|
|
we add to the cursor Y position to position
|
|
|
|
it on a line */
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
extern unsigned char bitmap_icons_6x8[LastIcon][6];
|
|
|
|
|
|
|
|
#else /* HAVE_LCD_BITMAP */
|
|
|
|
|
|
|
|
#define TREE_MAX_ON_SCREEN 2
|
|
|
|
#define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */
|
|
|
|
#define LINE_Y 0 /* Y position the entry-list starts at */
|
|
|
|
#define LINE_X 1 /* X position the entry-list starts at */
|
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
#define CURSOR_Y 0 /* not really used for players */
|
2002-05-31 09:04:51 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2002-06-12 08:59:48 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
#define TREE_NEXT BUTTON_DOWN
|
|
|
|
#define TREE_PREV BUTTON_UP
|
|
|
|
#define TREE_EXIT BUTTON_LEFT
|
|
|
|
#define TREE_ENTER BUTTON_RIGHT
|
|
|
|
#define TREE_MENU BUTTON_F1
|
2002-08-16 14:41:47 +00:00
|
|
|
#define RELEASE_MASK (BUTTON_OFF)
|
2002-06-12 08:59:48 +00:00
|
|
|
#else
|
|
|
|
#define TREE_NEXT BUTTON_RIGHT
|
|
|
|
#define TREE_PREV BUTTON_LEFT
|
|
|
|
#define TREE_EXIT BUTTON_STOP
|
|
|
|
#define TREE_ENTER BUTTON_PLAY
|
|
|
|
#define TREE_MENU BUTTON_MENU
|
2002-08-16 14:41:47 +00:00
|
|
|
#define RELEASE_MASK (BUTTON_STOP)
|
2002-06-12 08:59:48 +00:00
|
|
|
#endif /* HAVE_RECORDER_KEYPAD */
|
|
|
|
|
2002-07-16 14:40:27 +00:00
|
|
|
#define TREE_ATTR_M3U 0x80 /* unused by FAT attributes */
|
2002-07-16 15:30:23 +00:00
|
|
|
#define TREE_ATTR_MP3 0x40 /* unused by FAT attributes */
|
2002-07-16 14:40:27 +00:00
|
|
|
|
2002-08-08 06:42:02 +00:00
|
|
|
static int build_playlist(int start_index)
|
2002-08-06 13:10:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
2002-08-08 19:03:14 +00:00
|
|
|
int start=start_index;
|
2002-08-06 13:10:51 +00:00
|
|
|
|
|
|
|
playlist_clear();
|
2002-08-07 06:04:24 +00:00
|
|
|
|
|
|
|
for(i = 0;i < filesindir;i++)
|
2002-08-06 13:10:51 +00:00
|
|
|
{
|
2002-08-15 12:28:52 +00:00
|
|
|
if(dircache[i].attr & TREE_ATTR_MP3)
|
2002-08-06 13:10:51 +00:00
|
|
|
{
|
2002-08-15 12:28:52 +00:00
|
|
|
DEBUGF("Adding %s\n", dircache[i].name);
|
|
|
|
playlist_add(dircache[i].name);
|
2002-08-06 13:10:51 +00:00
|
|
|
}
|
2002-08-08 06:42:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Adjust the start index when se skip non-MP3 entries */
|
2002-08-08 19:03:14 +00:00
|
|
|
if(i < start)
|
2002-08-08 06:42:02 +00:00
|
|
|
start_index--;
|
|
|
|
}
|
2002-08-06 13:10:51 +00:00
|
|
|
}
|
2002-08-08 06:42:02 +00:00
|
|
|
|
|
|
|
return start_index;
|
2002-08-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
2002-07-17 11:25:04 +00:00
|
|
|
static int compare(const void* p1, const void* p2)
|
2002-05-30 14:01:36 +00:00
|
|
|
{
|
2002-08-15 12:28:52 +00:00
|
|
|
struct entry* e1 = (struct entry*)p1;
|
|
|
|
struct entry* e2 = (struct entry*)p2;
|
2002-07-17 11:25:04 +00:00
|
|
|
|
|
|
|
if (( e1->attr & ATTR_DIRECTORY ) == ( e2->attr & ATTR_DIRECTORY ))
|
2002-07-22 16:39:17 +00:00
|
|
|
if (global_settings.sort_case)
|
2002-08-15 12:28:52 +00:00
|
|
|
return strncmp(e1->name, e2->name, MAX_PATH);
|
2002-07-22 16:39:17 +00:00
|
|
|
else
|
2002-08-15 12:28:52 +00:00
|
|
|
return strncasecmp(e1->name, e2->name, MAX_PATH);
|
2002-07-17 11:25:04 +00:00
|
|
|
else
|
|
|
|
return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY );
|
2002-05-30 14:01:36 +00:00
|
|
|
}
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
static int showdir(char *path, int start)
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int icon_type = 0;
|
2002-08-11 09:17:47 +00:00
|
|
|
int line_height = LINE_HEIGTH;
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif
|
|
|
|
int i;
|
2002-08-11 09:17:47 +00:00
|
|
|
int tree_max_on_screen;
|
2002-08-15 12:28:52 +00:00
|
|
|
bool dir_buffer_full;
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
int fh;
|
|
|
|
unsigned char *font = lcd_getcurrentldfont();
|
|
|
|
fh = ajf_get_fontheight(font);
|
|
|
|
tree_max_on_screen = ((LCD_HEIGHT-MARGIN_Y)/fh)-LINE_Y;
|
|
|
|
line_height = fh;
|
|
|
|
#else
|
|
|
|
tree_max_on_screen = TREE_MAX_ON_SCREEN;
|
|
|
|
#endif
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
/* new dir? cache it */
|
|
|
|
if (strncmp(path,lastdir,sizeof(lastdir))) {
|
|
|
|
DIR *dir = opendir(path);
|
|
|
|
if(!dir)
|
|
|
|
return -1; /* not a directory */
|
2002-07-16 15:30:23 +00:00
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
name_buffer_length = 0;
|
|
|
|
dir_buffer_full = false;
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
|
2002-06-27 09:12:29 +00:00
|
|
|
int len;
|
2002-05-28 16:26:12 +00:00
|
|
|
struct dirent *entry = readdir(dir);
|
2002-07-16 15:30:23 +00:00
|
|
|
struct entry* dptr = &dircache[i];
|
2002-05-28 16:26:12 +00:00
|
|
|
if (!entry)
|
|
|
|
break;
|
2002-07-16 14:40:27 +00:00
|
|
|
|
|
|
|
/* skip directories . and .. */
|
2002-07-16 15:30:23 +00:00
|
|
|
if ((entry->attribute & ATTR_DIRECTORY) &&
|
|
|
|
(!strncmp(entry->d_name, ".", 1) ||
|
|
|
|
!strncmp(entry->d_name, "..", 2))) {
|
2002-05-28 16:26:12 +00:00
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
2002-07-16 15:30:23 +00:00
|
|
|
dptr->attr = entry->attribute;
|
2002-06-27 09:12:29 +00:00
|
|
|
len = strlen(entry->d_name);
|
2002-07-16 14:40:27 +00:00
|
|
|
|
2002-07-16 15:30:23 +00:00
|
|
|
/* mark mp3 and m3u files as such */
|
|
|
|
if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) {
|
|
|
|
if (!strcasecmp(&entry->d_name[len-4], ".mp3"))
|
|
|
|
dptr->attr |= TREE_ATTR_MP3;
|
|
|
|
else
|
|
|
|
if (!strcasecmp(&entry->d_name[len-4], ".m3u"))
|
|
|
|
dptr->attr |= TREE_ATTR_M3U;
|
|
|
|
}
|
2002-07-16 14:40:27 +00:00
|
|
|
|
2002-07-16 15:30:23 +00:00
|
|
|
/* filter hidden files and directories and non-mp3 or m3u files */
|
|
|
|
if ( global_settings.mp3filter &&
|
|
|
|
((dptr->attr & ATTR_HIDDEN) ||
|
|
|
|
!(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) {
|
|
|
|
i--;
|
|
|
|
continue;
|
2002-06-27 09:12:29 +00:00
|
|
|
}
|
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
if(len > NAME_BUFFER_SIZE - name_buffer_length - 1) {
|
|
|
|
/* Tell the world that we ran out of buffer space */
|
|
|
|
dir_buffer_full = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dptr->name = &name_buffer[name_buffer_length];
|
|
|
|
strcpy(dptr->name,entry->d_name);
|
|
|
|
name_buffer_length += len + 1;
|
2002-05-28 16:26:12 +00:00
|
|
|
}
|
|
|
|
filesindir = i;
|
|
|
|
closedir(dir);
|
|
|
|
strncpy(lastdir,path,sizeof(lastdir));
|
|
|
|
lastdir[sizeof(lastdir)-1] = 0;
|
2002-08-15 12:28:52 +00:00
|
|
|
qsort(dircache,filesindir,sizeof(struct entry),compare);
|
2002-08-12 22:52:19 +00:00
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
if ( dir_buffer_full || filesindir == MAX_FILES_IN_DIR ) {
|
2002-08-12 22:52:19 +00:00
|
|
|
#ifdef HAVE_NEW_CHARCELL_LCD
|
|
|
|
lcd_double_height(false);
|
|
|
|
#endif
|
|
|
|
lcd_clear_display();
|
2002-08-15 12:28:52 +00:00
|
|
|
lcd_puts(0,0,"Dir buffer");
|
|
|
|
lcd_puts(0,1,"is full!");
|
2002-08-12 22:52:19 +00:00
|
|
|
lcd_update();
|
|
|
|
sleep(HZ*2);
|
|
|
|
lcd_clear_display();
|
|
|
|
}
|
2002-05-28 16:26:12 +00:00
|
|
|
}
|
2002-05-31 12:11:22 +00:00
|
|
|
|
2002-06-12 08:06:13 +00:00
|
|
|
lcd_stop_scroll();
|
2002-05-31 11:16:25 +00:00
|
|
|
#ifdef HAVE_NEW_CHARCELL_LCD
|
|
|
|
lcd_double_height(false);
|
|
|
|
#endif
|
2002-05-28 16:26:12 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-13 20:55:08 +00:00
|
|
|
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
|
2002-06-12 15:17:34 +00:00
|
|
|
lcd_setfont(0);
|
2002-05-28 16:26:12 +00:00
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-08-11 09:17:47 +00:00
|
|
|
for ( i=start; i < start+tree_max_on_screen; i++ ) {
|
2002-05-29 08:18:46 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if ( i >= filesindir )
|
|
|
|
break;
|
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
len = strlen(dircache[i].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-15 12:28:52 +00:00
|
|
|
if ( dircache[i].attr & ATTR_DIRECTORY )
|
2002-07-16 15:30:23 +00:00
|
|
|
icon_type = Folder;
|
|
|
|
else {
|
2002-08-15 12:28:52 +00:00
|
|
|
if ( dircache[i].attr & TREE_ATTR_M3U )
|
2002-06-12 07:45:42 +00:00
|
|
|
icon_type = Playlist;
|
|
|
|
else
|
2002-07-16 14:40:27 +00:00
|
|
|
icon_type = File;
|
2002-07-16 15:30:23 +00:00
|
|
|
}
|
2002-05-29 08:18:46 +00:00
|
|
|
lcd_bitmap(bitmap_icons_6x8[icon_type],
|
2002-08-13 20:55:08 +00:00
|
|
|
4, MARGIN_Y+(LINE_Y+i-start)*line_height, 6, 8, true);
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-08-11 09:17:47 +00:00
|
|
|
|
2002-07-16 15:30:23 +00:00
|
|
|
/* if MP3 filter is on, cut off the extension */
|
|
|
|
if (global_settings.mp3filter &&
|
2002-08-15 12:28:52 +00:00
|
|
|
(dircache[i].attr & (TREE_ATTR_M3U|TREE_ATTR_MP3)))
|
2002-07-16 15:30:23 +00:00
|
|
|
{
|
2002-08-15 12:28:52 +00:00
|
|
|
char temp = dircache[i].name[len-4];
|
|
|
|
dircache[i].name[len-4] = 0;
|
|
|
|
lcd_puts(LINE_X, LINE_Y+i-start, dircache[i].name);
|
|
|
|
dircache[i].name[len-4] = temp;
|
2002-07-16 15:30:23 +00:00
|
|
|
}
|
|
|
|
else
|
2002-08-15 12:28:52 +00:00
|
|
|
lcd_puts(LINE_X, LINE_Y+i-start, dircache[i].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-07-22 22:45:20 +00:00
|
|
|
status_draw();
|
2002-05-28 16:26:12 +00:00
|
|
|
return filesindir;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
bool ask_resume(void)
|
|
|
|
{
|
2002-08-16 15:06:50 +00:00
|
|
|
#ifdef HAVE_NEW_CHARCELL_LCD
|
|
|
|
lcd_double_height(false);
|
|
|
|
#endif
|
2002-08-16 14:41:47 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,"Resume?");
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
lcd_puts(0,1,"(Play/Stop)");
|
|
|
|
#else
|
|
|
|
lcd_puts(0,1,"Play = Yes");
|
|
|
|
lcd_puts(0,2,"Any other = No");
|
|
|
|
#endif
|
|
|
|
lcd_update();
|
|
|
|
if (button_get(true) == BUTTON_PLAY)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void start_resume(void)
|
|
|
|
{
|
|
|
|
if ( global_settings.resume &&
|
|
|
|
global_settings.resume_index != -1 ) {
|
|
|
|
int len = strlen(global_settings.resume_file);
|
|
|
|
|
|
|
|
DEBUGF("Resume file %s\n",global_settings.resume_file);
|
|
|
|
DEBUGF("Resume index %X offset %X\n",
|
|
|
|
global_settings.resume_index,
|
|
|
|
global_settings.resume_offset);
|
|
|
|
DEBUGF("Resume shuffle %s seed %X\n",
|
|
|
|
global_settings.playlist_shuffle?"on":"off",
|
|
|
|
global_settings.resume_seed);
|
|
|
|
|
|
|
|
/* playlist? */
|
|
|
|
if (!strcasecmp(&global_settings.resume_file[len-4], ".m3u")) {
|
|
|
|
char* slash;
|
|
|
|
|
|
|
|
/* check that the file exists */
|
|
|
|
int fd = open(global_settings.resume_file, O_RDONLY);
|
|
|
|
if(fd<0)
|
|
|
|
return;
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (!ask_resume())
|
|
|
|
return;
|
|
|
|
|
|
|
|
slash = strrchr(global_settings.resume_file,'/');
|
|
|
|
if (slash) {
|
|
|
|
*slash=0;
|
|
|
|
play_list(global_settings.resume_file,
|
|
|
|
slash+1,
|
|
|
|
global_settings.resume_index,
|
|
|
|
global_settings.resume_offset,
|
|
|
|
global_settings.resume_seed );
|
|
|
|
*slash='/';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* check that the dir exists */
|
|
|
|
DIR* dir = opendir(global_settings.resume_file);
|
|
|
|
if(!dir)
|
|
|
|
return;
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
if (!ask_resume())
|
|
|
|
return;
|
|
|
|
|
|
|
|
play_list("/",
|
|
|
|
global_settings.resume_file,
|
|
|
|
global_settings.resume_index,
|
|
|
|
global_settings.resume_offset,
|
|
|
|
global_settings.resume_seed );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!ask_resume())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (showdir(global_settings.resume_file, 0) < 0 )
|
|
|
|
return;
|
2002-08-16 15:23:57 +00:00
|
|
|
build_playlist(global_settings.resume_index);
|
2002-08-16 14:41:47 +00:00
|
|
|
play_list(global_settings.resume_file,
|
|
|
|
NULL,
|
2002-08-16 15:23:57 +00:00
|
|
|
global_settings.resume_index,
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_offset,
|
|
|
|
global_settings.resume_seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_set_playmode(STATUS_PLAY);
|
|
|
|
status_draw();
|
|
|
|
wps_show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
bool dirbrowse(char *root)
|
|
|
|
{
|
2002-08-08 12:06:38 +00:00
|
|
|
int numentries=0;
|
|
|
|
int dircursor=0;
|
|
|
|
int start=0;
|
|
|
|
int dirpos[MAX_DIR_LEVELS];
|
|
|
|
int cursorpos[MAX_DIR_LEVELS];
|
|
|
|
int dirlevel=0;
|
|
|
|
char currdir[MAX_PATH];
|
2002-07-15 22:46:38 +00:00
|
|
|
char buf[MAX_PATH];
|
2002-05-16 12:53:40 +00:00
|
|
|
int i;
|
2002-08-07 10:35:26 +00:00
|
|
|
int lasti=-1;
|
2002-07-01 11:06:23 +00:00
|
|
|
int rc;
|
2002-07-27 19:41:58 +00:00
|
|
|
int button;
|
2002-08-08 06:42:02 +00:00
|
|
|
int start_index;
|
2002-08-11 09:17:47 +00:00
|
|
|
int tree_max_on_screen;
|
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
int fh;
|
|
|
|
unsigned char *font = lcd_getcurrentldfont();
|
|
|
|
fh = ajf_get_fontheight(font);
|
|
|
|
tree_max_on_screen = ((LCD_HEIGHT-MARGIN_Y)/fh)-LINE_Y;
|
|
|
|
#else
|
|
|
|
tree_max_on_screen = TREE_MAX_ON_SCREEN;
|
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
start_resume();
|
|
|
|
button_set_release(RELEASE_MASK);
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
memcpy(currdir,root,sizeof(currdir));
|
2002-05-28 16:26:12 +00:00
|
|
|
numentries = showdir(root, start);
|
2002-05-16 12:53:40 +00:00
|
|
|
if (numentries == -1)
|
|
|
|
return -1; /* root is not a directory */
|
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
2002-06-25 13:26:04 +00:00
|
|
|
bool restore = false;
|
2002-06-18 11:22:48 +00:00
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
button = button_get_w_tmo(HZ/5);
|
2002-07-27 20:55:39 +00:00
|
|
|
switch ( button ) {
|
2002-06-12 08:59:48 +00:00
|
|
|
case TREE_EXIT:
|
2002-05-16 12:53:40 +00:00
|
|
|
i=strlen(currdir);
|
2002-05-21 14:30:54 +00:00
|
|
|
if (i>1) {
|
2002-05-16 12:53:40 +00:00
|
|
|
while (currdir[i-1]!='/')
|
|
|
|
i--;
|
|
|
|
strcpy(buf,&currdir[i]);
|
|
|
|
if (i==1)
|
|
|
|
currdir[i]=0;
|
|
|
|
else
|
|
|
|
currdir[i-1]=0;
|
|
|
|
|
|
|
|
dirlevel--;
|
2002-05-31 07:19:38 +00:00
|
|
|
if ( dirlevel < MAX_DIR_LEVELS ) {
|
2002-05-16 12:53:40 +00:00
|
|
|
start = dirpos[dirlevel];
|
2002-05-31 07:19:38 +00:00
|
|
|
dircursor = cursorpos[dirlevel];
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
else
|
2002-05-31 07:19:38 +00:00
|
|
|
start = dircursor = 0;
|
2002-06-25 13:26:04 +00:00
|
|
|
restore = true;
|
2002-05-27 14:55:40 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
break;
|
2002-08-16 14:41:47 +00:00
|
|
|
|
2002-08-06 09:25:45 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_OFF:
|
|
|
|
mpeg_stop();
|
|
|
|
status_set_playmode(STATUS_STOP);
|
2002-08-07 10:35:26 +00:00
|
|
|
status_draw();
|
|
|
|
restore = true;
|
2002-08-06 09:25:45 +00:00
|
|
|
break;
|
2002-08-16 14:41:47 +00:00
|
|
|
|
|
|
|
case BUTTON_OFF | BUTTON_REL:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP | BUTTON_REL:
|
2002-08-06 09:25:45 +00:00
|
|
|
#endif
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_index = -1;
|
|
|
|
settings_save();
|
|
|
|
break;
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-06-12 08:59:48 +00:00
|
|
|
case TREE_ENTER:
|
2002-06-25 11:10:24 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
#endif
|
2002-06-19 20:10:58 +00:00
|
|
|
if ( !numentries )
|
|
|
|
break;
|
2002-05-16 12:53:40 +00:00
|
|
|
if ((currdir[0]=='/') && (currdir[1]==0)) {
|
2002-05-30 14:01:36 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s%s",currdir,
|
2002-08-15 12:28:52 +00:00
|
|
|
dircache[dircursor+start].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
} else {
|
2002-05-30 14:01:36 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s/%s",currdir,
|
2002-08-15 12:28:52 +00:00
|
|
|
dircache[dircursor+start].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-08-15 12:28:52 +00:00
|
|
|
if (dircache[dircursor+start].attr & ATTR_DIRECTORY) {
|
2002-05-16 12:53:40 +00:00
|
|
|
memcpy(currdir,buf,sizeof(currdir));
|
2002-05-31 07:19:38 +00:00
|
|
|
if ( dirlevel < MAX_DIR_LEVELS ) {
|
2002-07-22 22:45:20 +00:00
|
|
|
dirpos[dirlevel] = start;
|
|
|
|
cursorpos[dirlevel] = dircursor;
|
2002-05-31 07:19:38 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
dirlevel++;
|
|
|
|
dircursor=0;
|
|
|
|
start=0;
|
|
|
|
} else {
|
2002-08-16 14:41:47 +00:00
|
|
|
int seed = current_tick;
|
2002-06-10 13:24:27 +00:00
|
|
|
lcd_stop_scroll();
|
2002-08-15 12:28:52 +00:00
|
|
|
if(dircache[dircursor+start].attr & TREE_ATTR_M3U )
|
2002-06-12 07:45:42 +00:00
|
|
|
{
|
2002-08-16 14:41:47 +00:00
|
|
|
if ( global_settings.resume )
|
|
|
|
snprintf(global_settings.resume_file,
|
|
|
|
MAX_PATH, "%s/%s",
|
|
|
|
currdir,
|
|
|
|
dircache[dircursor+start].name);
|
2002-08-07 06:04:24 +00:00
|
|
|
play_list(currdir,
|
2002-08-16 14:41:47 +00:00
|
|
|
dircache[dircursor+start].name,
|
|
|
|
0, 0, seed );
|
2002-06-04 21:44:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-08-16 14:41:47 +00:00
|
|
|
if ( global_settings.resume )
|
|
|
|
strncpy(global_settings.resume_file,
|
|
|
|
currdir, MAX_PATH);
|
2002-08-08 06:42:02 +00:00
|
|
|
start_index = build_playlist(dircursor+start);
|
2002-08-16 14:41:47 +00:00
|
|
|
play_list(currdir, NULL, start_index, 0, seed);
|
2002-06-04 21:44:29 +00:00
|
|
|
}
|
2002-08-16 14:41:47 +00:00
|
|
|
|
|
|
|
if ( global_settings.resume ) {
|
|
|
|
global_settings.resume_index = 0;
|
|
|
|
global_settings.resume_offset = 0;
|
|
|
|
global_settings.resume_seed = seed;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
|
2002-08-07 06:04:24 +00:00
|
|
|
status_set_playmode(STATUS_PLAY);
|
2002-07-22 22:45:20 +00:00
|
|
|
status_draw();
|
2002-06-27 01:25:36 +00:00
|
|
|
lcd_stop_scroll();
|
2002-07-01 11:06:23 +00:00
|
|
|
rc = wps_show();
|
|
|
|
if(rc == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
/* Force a re-read of the root directory */
|
|
|
|
strcpy(currdir, "/");
|
|
|
|
lastdir[0] = 0;
|
2002-07-25 11:33:32 +00:00
|
|
|
dirlevel = 0;
|
|
|
|
dircursor = 0;
|
|
|
|
start = 0;
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_index = -1;
|
2002-07-01 11:06:23 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2002-06-25 13:26:04 +00:00
|
|
|
restore = true;
|
2002-05-16 12:53:40 +00:00
|
|
|
break;
|
2002-08-06 18:11:00 +00:00
|
|
|
|
|
|
|
case TREE_PREV:
|
2002-08-07 20:51:37 +00:00
|
|
|
case TREE_PREV | BUTTON_REPEAT:
|
2002-08-12 18:28:51 +00:00
|
|
|
case BUTTON_VOL_UP:
|
2002-08-06 18:11:00 +00:00
|
|
|
if(filesindir) {
|
2002-07-22 22:45:20 +00:00
|
|
|
if(dircursor) {
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, false);
|
|
|
|
dircursor--;
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (start) {
|
|
|
|
start--;
|
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
else {
|
2002-08-11 09:17:47 +00:00
|
|
|
if (numentries < tree_max_on_screen) {
|
2002-07-22 22:45:20 +00:00
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor,
|
|
|
|
false);
|
|
|
|
dircursor = numentries - 1;
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
else {
|
2002-08-11 09:17:47 +00:00
|
|
|
start = numentries - tree_max_on_screen;
|
|
|
|
dircursor = tree_max_on_screen - 1;
|
2002-07-22 22:45:20 +00:00
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y +
|
2002-08-11 09:17:47 +00:00
|
|
|
tree_max_on_screen - 1, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lcd_update();
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
break;
|
2002-05-16 14:48:40 +00:00
|
|
|
|
2002-06-12 08:59:48 +00:00
|
|
|
case TREE_NEXT:
|
2002-08-07 20:51:37 +00:00
|
|
|
case TREE_NEXT | BUTTON_REPEAT:
|
2002-08-12 18:28:51 +00:00
|
|
|
case BUTTON_VOL_DOWN:
|
2002-07-22 22:45:20 +00:00
|
|
|
if(filesindir)
|
|
|
|
{
|
|
|
|
if (dircursor + start + 1 < numentries ) {
|
2002-08-11 09:17:47 +00:00
|
|
|
if(dircursor+1 < tree_max_on_screen) {
|
2002-07-22 22:45:20 +00:00
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor,
|
|
|
|
false);
|
|
|
|
dircursor++;
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start++;
|
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-08-11 09:17:47 +00:00
|
|
|
if(numentries < tree_max_on_screen) {
|
2002-07-22 22:45:20 +00:00
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor,
|
|
|
|
false);
|
|
|
|
start = dircursor = 0;
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start = dircursor = 0;
|
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lcd_update();
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
break;
|
2002-05-21 14:30:54 +00:00
|
|
|
|
2002-06-27 09:12:29 +00:00
|
|
|
case TREE_MENU: {
|
|
|
|
bool lastfilter = global_settings.mp3filter;
|
2002-07-22 16:44:06 +00:00
|
|
|
bool lastsortcase = global_settings.sort_case;
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
bool laststate=statusbar(false);
|
|
|
|
#endif
|
2002-06-10 13:24:27 +00:00
|
|
|
lcd_stop_scroll();
|
2002-05-21 14:30:54 +00:00
|
|
|
main_menu();
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
statusbar(laststate);
|
|
|
|
#endif
|
2002-06-27 09:12:29 +00:00
|
|
|
/* do we need to rescan dir? */
|
2002-07-22 16:44:06 +00:00
|
|
|
if ( lastfilter != global_settings.mp3filter ||
|
|
|
|
lastsortcase != global_settings.sort_case)
|
2002-06-27 09:12:29 +00:00
|
|
|
lastdir[0] = 0;
|
2002-06-25 13:26:04 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
2002-06-27 09:12:29 +00:00
|
|
|
}
|
2002-05-21 14:30:54 +00:00
|
|
|
|
2002-06-25 13:26:04 +00:00
|
|
|
case BUTTON_ON:
|
2002-08-07 06:04:24 +00:00
|
|
|
if (mpeg_is_playing())
|
|
|
|
{
|
2002-06-27 01:20:08 +00:00
|
|
|
lcd_stop_scroll();
|
2002-07-01 11:06:23 +00:00
|
|
|
rc = wps_show();
|
|
|
|
if(rc == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
/* Force a re-read of the root directory */
|
|
|
|
strcpy(currdir, "/");
|
|
|
|
lastdir[0] = 0;
|
2002-07-25 11:33:32 +00:00
|
|
|
dirlevel = 0;
|
|
|
|
dircursor = 0;
|
|
|
|
start = 0;
|
2002-07-01 11:06:23 +00:00
|
|
|
}
|
2002-06-27 01:20:08 +00:00
|
|
|
restore = true;
|
|
|
|
}
|
2002-05-21 14:30:54 +00:00
|
|
|
break;
|
2002-06-30 16:27:39 +00:00
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F3:
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-15 14:12:32 +00:00
|
|
|
global_settings.statusbar = !global_settings.statusbar;
|
|
|
|
settings_save();
|
|
|
|
restore = true;
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2002-06-30 16:27:39 +00:00
|
|
|
#ifndef SIMULATOR
|
2002-08-07 10:35:26 +00:00
|
|
|
case SYS_USB_CONNECTED: {
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
bool laststate=statusbar(false);
|
|
|
|
#endif
|
2002-07-01 11:06:23 +00:00
|
|
|
/* Tell the USB thread that we are safe */
|
|
|
|
DEBUGF("dirbrowse got SYS_USB_CONNECTED\n");
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
|
|
|
|
/* Wait until the USB cable is extracted again */
|
|
|
|
usb_wait_for_disconnect(&button_queue);
|
|
|
|
|
|
|
|
/* Force a re-read of the root directory */
|
|
|
|
restore = true;
|
|
|
|
strcpy(currdir, "/");
|
|
|
|
lastdir[0] = 0;
|
2002-07-25 11:33:32 +00:00
|
|
|
dirlevel = 0;
|
|
|
|
dircursor = 0;
|
|
|
|
start = 0;
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
statusbar(laststate);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
2002-06-30 16:27:39 +00:00
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2002-06-10 13:24:27 +00:00
|
|
|
|
2002-06-25 13:26:04 +00:00
|
|
|
if ( restore ) {
|
|
|
|
/* restore display */
|
2002-08-08 10:46:10 +00:00
|
|
|
/* We need to adjust if the number of lines on screen have
|
|
|
|
changed because of a status bar change */
|
2002-08-11 09:17:47 +00:00
|
|
|
if(CURSOR_Y+LINE_Y+dircursor>tree_max_on_screen) {
|
2002-08-08 10:46:10 +00:00
|
|
|
start++;
|
|
|
|
dircursor--;
|
|
|
|
}
|
2002-06-25 13:26:04 +00:00
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true);
|
|
|
|
}
|
2002-06-10 13:24:27 +00:00
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
if ( numentries ) {
|
|
|
|
i = start+dircursor;
|
|
|
|
|
|
|
|
/* if MP3 filter is on, cut off the extension */
|
|
|
|
if(lasti!=i || restore) {
|
|
|
|
lasti=i;
|
|
|
|
lcd_stop_scroll();
|
|
|
|
if (global_settings.mp3filter &&
|
2002-08-15 12:28:52 +00:00
|
|
|
(dircache[i].attr &
|
2002-08-07 10:35:26 +00:00
|
|
|
(TREE_ATTR_M3U|TREE_ATTR_MP3)))
|
|
|
|
{
|
2002-08-15 12:28:52 +00:00
|
|
|
int len = strlen(dircache[i].name);
|
|
|
|
char temp = dircache[i].name[len-4];
|
|
|
|
dircache[i].name[len-4] = 0;
|
2002-08-07 10:35:26 +00:00
|
|
|
lcd_puts_scroll(LINE_X, LINE_Y+dircursor,
|
2002-08-15 12:28:52 +00:00
|
|
|
dircache[i].name);
|
|
|
|
dircache[i].name[len-4] = temp;
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
lcd_puts_scroll(LINE_X, LINE_Y+dircursor,
|
2002-08-15 12:28:52 +00:00
|
|
|
dircache[i].name);
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
status_draw();
|
|
|
|
lcd_update();
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|