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-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-09-02 12:46:32 +00:00
|
|
|
#include "wps-display.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-30 19:05:03 +00:00
|
|
|
#include "viewer.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"
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-30 13:49:32 +00:00
|
|
|
#include "widgets.h"
|
2002-05-16 12:53:40 +00:00
|
|
|
#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-12-18 14:57:45 +00:00
|
|
|
static char name_buffer[NAME_BUFFER_SIZE];
|
|
|
|
static int name_buffer_length;
|
2002-05-16 12:53:40 +00:00
|
|
|
struct entry {
|
2002-09-03 09:44:08 +00:00
|
|
|
short attr; /* FAT attributes + file type flags */
|
2002-08-15 12:28:52 +00:00
|
|
|
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-09-09 14:25:39 +00:00
|
|
|
static int dircursor;
|
|
|
|
static int dirstart;
|
|
|
|
static int dirlevel;
|
2002-05-28 16:26:12 +00:00
|
|
|
static int filesindir;
|
2002-09-09 14:25:39 +00:00
|
|
|
static int dirpos[MAX_DIR_LEVELS];
|
|
|
|
static int cursorpos[MAX_DIR_LEVELS];
|
|
|
|
static char lastdir[MAX_PATH];
|
|
|
|
static char lastfile[MAX_PATH];
|
|
|
|
static char currdir[MAX_PATH];
|
2003-01-15 14:52:53 +00:00
|
|
|
static bool reload_dir = false;
|
2002-05-28 16:26:12 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
void browse_root(void)
|
|
|
|
{
|
2003-01-31 08:43:12 +00:00
|
|
|
#ifndef SIMULATOR
|
2002-07-22 22:45:20 +00:00
|
|
|
dirbrowse("/");
|
2003-01-31 08:43:12 +00:00
|
|
|
#else
|
|
|
|
if (!dirbrowse("/")) {
|
|
|
|
DEBUGF("No filesystem found. Have you forgotten to create it?\n");
|
|
|
|
}
|
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2002-09-24 19:41:23 +00:00
|
|
|
/* pixel margins */
|
|
|
|
#define MARGIN_X (global_settings.scrollbar && \
|
|
|
|
filesindir > tree_max_on_screen ? SCROLLBAR_WIDTH : 0) + \
|
|
|
|
CURSOR_WIDTH + ICON_WIDTH
|
|
|
|
#define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
|
|
|
|
|
|
|
|
/* position the entry-list starts at */
|
|
|
|
#define LINE_X 0
|
|
|
|
#define LINE_Y (global_settings.statusbar ? 1 : 0)
|
|
|
|
|
|
|
|
#define CURSOR_X (global_settings.scrollbar && \
|
|
|
|
filesindir > tree_max_on_screen ? 1 : 0)
|
|
|
|
#define CURSOR_Y 0 /* the cursor is not positioned in regard to
|
|
|
|
the margins, so this is the amount of lines
|
|
|
|
we add to the cursor Y position to position
|
|
|
|
it on a line */
|
2002-08-30 13:49:32 +00:00
|
|
|
#define CURSOR_WIDTH 4
|
|
|
|
|
|
|
|
#define ICON_WIDTH 6
|
|
|
|
|
|
|
|
#define SCROLLBAR_X 0
|
|
|
|
#define SCROLLBAR_Y lcd_getymargin()
|
|
|
|
#define SCROLLBAR_WIDTH 6
|
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 */
|
2002-09-03 07:53:51 +00:00
|
|
|
#define LINE_X 2 /* X position the entry-list starts at */
|
2002-08-30 13:49:32 +00:00
|
|
|
#define LINE_Y 0 /* Y position the entry-list starts at */
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-08-30 13:49:32 +00:00
|
|
|
#define CURSOR_X 0
|
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
|
|
|
|
#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
|
|
|
|
#endif /* HAVE_RECORDER_KEYPAD */
|
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
/* using attribute not used by FAT */
|
|
|
|
#define TREE_ATTR_MPA 0x40 /* mpeg audio file */
|
|
|
|
#define TREE_ATTR_M3U 0x80 /* playlist */
|
|
|
|
#define TREE_ATTR_WPS 0x100 /* wps config file */
|
|
|
|
#define TREE_ATTR_MOD 0x200 /* firmware file */
|
2002-10-08 09:40:05 +00:00
|
|
|
#define TREE_ATTR_CFG 0x400 /* config file */
|
2002-09-30 19:05:03 +00:00
|
|
|
#define TREE_ATTR_TXT 0x500 /* text file */
|
2002-09-20 08:07:51 +00:00
|
|
|
#define TREE_ATTR_FONT 0x800 /* font file */
|
2002-09-24 12:40:52 +00:00
|
|
|
#define TREE_ATTR_LNG 0x1000 /* binary lang file */
|
2002-09-03 09:44:08 +00:00
|
|
|
#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
|
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-28 13:58:19 +00:00
|
|
|
if(dircache[i].attr & TREE_ATTR_MPA)
|
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
|
|
|
}
|
|
|
|
|
2003-01-24 10:56:59 +00:00
|
|
|
static void showfileline(int line, int direntry, bool scroll)
|
|
|
|
{
|
|
|
|
/* if music filter is on, cut off the extension */
|
|
|
|
if (global_settings.dirfilter == SHOW_MUSIC &&
|
|
|
|
(dircache[direntry].attr & (TREE_ATTR_M3U|TREE_ATTR_MPA)))
|
|
|
|
{
|
|
|
|
int len = strlen(dircache[direntry].name);
|
|
|
|
char temp = dircache[direntry].name[len-4];
|
|
|
|
dircache[direntry].name[len-4] = 0;
|
|
|
|
if(scroll)
|
|
|
|
lcd_puts_scroll(LINE_X, line, dircache[direntry].name);
|
|
|
|
else
|
|
|
|
lcd_puts(LINE_X, line, dircache[direntry].name);
|
|
|
|
dircache[direntry].name[len-4] = temp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(scroll)
|
|
|
|
lcd_puts_scroll(LINE_X, line, dircache[direntry].name);
|
|
|
|
else
|
|
|
|
lcd_puts(LINE_X, line, dircache[direntry].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
static int showdir(char *path, int start)
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
|
|
|
int icon_type = 0;
|
|
|
|
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-09-12 13:33:59 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-24 19:41:23 +00:00
|
|
|
int line_height;
|
2002-09-12 13:33:59 +00:00
|
|
|
int fw, fh;
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_setfont(FONT_UI);
|
|
|
|
lcd_getstringsize("A", &fw, &fh);
|
2002-08-20 19:39:55 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
2002-08-11 09:17:47 +00:00
|
|
|
line_height = fh;
|
|
|
|
#else
|
|
|
|
tree_max_on_screen = TREE_MAX_ON_SCREEN;
|
|
|
|
#endif
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
/* new dir? cache it */
|
2003-01-15 14:52:53 +00:00
|
|
|
if (strncmp(path,lastdir,sizeof(lastdir)) || reload_dir) {
|
2002-05-28 16:26:12 +00:00
|
|
|
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
|
|
|
|
2002-08-22 15:47:30 +00:00
|
|
|
len = strlen(entry->d_name);
|
|
|
|
|
2002-07-16 14:40:27 +00:00
|
|
|
/* skip directories . and .. */
|
2002-07-16 15:30:23 +00:00
|
|
|
if ((entry->attribute & ATTR_DIRECTORY) &&
|
2002-08-22 15:47:30 +00:00
|
|
|
(((len == 1) &&
|
|
|
|
(!strncmp(entry->d_name, ".", 1))) ||
|
|
|
|
((len == 2) &&
|
|
|
|
(!strncmp(entry->d_name, "..", 2))))) {
|
2002-05-28 16:26:12 +00:00
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
2002-08-22 15:47:30 +00:00
|
|
|
|
2002-09-06 04:59:23 +00:00
|
|
|
/* Skip FAT volume ID */
|
|
|
|
if (entry->attribute & ATTR_VOLUME_ID) {
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-09-24 19:12:09 +00:00
|
|
|
/* filter out dotfiles and hidden files */
|
|
|
|
if (global_settings.dirfilter != SHOW_ALL &&
|
2002-08-22 15:47:30 +00:00
|
|
|
((entry->d_name[0]=='.') ||
|
|
|
|
(entry->attribute & ATTR_HIDDEN))) {
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-07-16 15:30:23 +00:00
|
|
|
dptr->attr = entry->attribute;
|
2002-07-16 14:40:27 +00:00
|
|
|
|
2002-08-28 13:58:19 +00:00
|
|
|
/* mark mp? and m3u files as such */
|
2002-07-16 15:30:23 +00:00
|
|
|
if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) {
|
2002-08-28 13:58:19 +00:00
|
|
|
if (!strcasecmp(&entry->d_name[len-4], ".mp3") ||
|
2002-12-02 04:46:19 +00:00
|
|
|
(!strcasecmp(&entry->d_name[len-4], ".mp2")) ||
|
|
|
|
(!strcasecmp(&entry->d_name[len-4], ".mpa")))
|
2002-08-28 13:58:19 +00:00
|
|
|
dptr->attr |= TREE_ATTR_MPA;
|
2002-09-03 09:44:08 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".m3u"))
|
|
|
|
dptr->attr |= TREE_ATTR_M3U;
|
2002-10-08 10:10:16 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".cfg"))
|
2002-10-08 09:40:05 +00:00
|
|
|
dptr->attr |= TREE_ATTR_CFG;
|
2002-09-03 09:44:08 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".wps"))
|
|
|
|
dptr->attr |= TREE_ATTR_WPS;
|
2002-09-30 19:05:03 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".txt"))
|
|
|
|
dptr->attr |= TREE_ATTR_TXT;
|
2002-09-24 12:40:52 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".lng"))
|
|
|
|
dptr->attr |= TREE_ATTR_LNG;
|
2002-09-03 09:44:08 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-09-20 08:07:51 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".fnt"))
|
|
|
|
dptr->attr |= TREE_ATTR_FONT;
|
2002-09-03 09:44:08 +00:00
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".ajz"))
|
|
|
|
#else
|
|
|
|
else if (!strcasecmp(&entry->d_name[len-4], ".mod"))
|
|
|
|
#endif
|
|
|
|
dptr->attr |= TREE_ATTR_MOD;
|
2002-07-16 15:30:23 +00:00
|
|
|
}
|
2002-07-16 14:40:27 +00:00
|
|
|
|
2002-11-30 09:42:13 +00:00
|
|
|
/* filter out all non-playlist files */
|
|
|
|
if ( global_settings.dirfilter == SHOW_PLAYLIST &&
|
|
|
|
(!(dptr->attr &
|
|
|
|
(ATTR_DIRECTORY|TREE_ATTR_M3U))) ) {
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-09-24 19:12:09 +00:00
|
|
|
/* filter out non-music files */
|
|
|
|
if ( global_settings.dirfilter == SHOW_MUSIC &&
|
2002-08-22 15:47:30 +00:00
|
|
|
(!(dptr->attr &
|
2002-08-28 13:58:19 +00:00
|
|
|
(ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ) {
|
2002-07-16 15:30:23 +00:00
|
|
|
i--;
|
|
|
|
continue;
|
2002-06-27 09:12:29 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 19:12:09 +00:00
|
|
|
/* filter out non-supported files */
|
|
|
|
if ( global_settings.dirfilter == SHOW_SUPPORTED &&
|
|
|
|
(!(dptr->attr & TREE_ATTR_MASK)) ) {
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > NAME_BUFFER_SIZE - name_buffer_length - 1) {
|
2002-08-15 12:28:52 +00:00
|
|
|
/* 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-10-15 12:25:57 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2002-08-12 22:52:19 +00:00
|
|
|
lcd_double_height(false);
|
|
|
|
#endif
|
|
|
|
lcd_clear_display();
|
2002-09-18 14:08:05 +00:00
|
|
|
lcd_puts(0,0,str(LANG_SHOWDIR_ERROR_BUFFER));
|
|
|
|
lcd_puts(0,1,str(LANG_SHOWDIR_ERROR_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-09-09 14:25:39 +00:00
|
|
|
if (start == -1)
|
|
|
|
{
|
2002-09-09 17:32:15 +00:00
|
|
|
int diff_files;
|
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
/* use lastfile to determine start (default=0) */
|
2002-09-09 17:32:15 +00:00
|
|
|
start = 0;
|
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
for (i=0; i<filesindir; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(dircache[i].name, lastfile))
|
|
|
|
{
|
2002-09-09 17:32:15 +00:00
|
|
|
start = i;
|
2002-09-09 14:25:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-09 17:32:15 +00:00
|
|
|
|
|
|
|
diff_files = filesindir - start;
|
|
|
|
if (diff_files < tree_max_on_screen)
|
|
|
|
{
|
|
|
|
int oldstart = start;
|
|
|
|
|
|
|
|
start -= (tree_max_on_screen - diff_files);
|
|
|
|
if (start < 0)
|
|
|
|
start = 0;
|
|
|
|
|
|
|
|
dircursor = oldstart - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirstart = start;
|
2002-09-09 14:25:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-15 12:25:57 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2003-01-24 10:56:59 +00:00
|
|
|
lcd_stop_scroll();
|
2002-05-31 11:16:25 +00:00
|
|
|
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-09-12 13:33:59 +00:00
|
|
|
lcd_setfont(FONT_UI);
|
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
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
switch ( dircache[i].attr & TREE_ATTR_MASK ) {
|
|
|
|
case ATTR_DIRECTORY:
|
|
|
|
icon_type = Folder;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_ATTR_M3U:
|
|
|
|
icon_type = Playlist;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_ATTR_MPA:
|
|
|
|
icon_type = File;
|
|
|
|
break;
|
2002-08-23 22:15:51 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
case TREE_ATTR_WPS:
|
|
|
|
icon_type = Wps;
|
|
|
|
break;
|
|
|
|
|
2002-10-08 09:40:05 +00:00
|
|
|
case TREE_ATTR_CFG:
|
2002-10-08 10:10:16 +00:00
|
|
|
icon_type = Config;
|
2002-09-05 01:20:10 +00:00
|
|
|
break;
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
case TREE_ATTR_TXT:
|
2002-10-08 10:10:16 +00:00
|
|
|
icon_type = Text;
|
2002-09-30 19:05:03 +00:00
|
|
|
break;
|
|
|
|
|
2002-09-24 12:40:52 +00:00
|
|
|
case TREE_ATTR_LNG:
|
2002-09-24 14:42:14 +00:00
|
|
|
icon_type = Language;
|
2002-09-24 12:40:52 +00:00
|
|
|
break;
|
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
case TREE_ATTR_MOD:
|
|
|
|
icon_type = Mod_Ajz;
|
|
|
|
break;
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
case TREE_ATTR_FONT:
|
|
|
|
icon_type = Font;
|
|
|
|
break;
|
|
|
|
#endif
|
2002-09-03 09:44:08 +00:00
|
|
|
default:
|
2003-01-10 09:55:50 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-03 09:44:08 +00:00
|
|
|
icon_type = 0;
|
2003-01-10 09:55:50 +00:00
|
|
|
#else
|
|
|
|
icon_type = Unknown;
|
|
|
|
#endif
|
2002-09-03 09:44:08 +00:00
|
|
|
}
|
2002-09-03 20:47:23 +00:00
|
|
|
|
|
|
|
if (icon_type) {
|
2002-09-03 07:53:51 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-20 08:07:51 +00:00
|
|
|
int offset=0;
|
|
|
|
if ( line_height > 8 )
|
|
|
|
offset = (line_height - 8) / 2;
|
2002-08-23 22:15:51 +00:00
|
|
|
lcd_bitmap(bitmap_icons_6x8[icon_type],
|
2002-09-02 12:46:32 +00:00
|
|
|
CURSOR_X * 6 + CURSOR_WIDTH,
|
2002-09-20 08:07:51 +00:00
|
|
|
MARGIN_Y+(i-start)*line_height + offset,
|
|
|
|
6, 8, true);
|
2002-09-03 07:53:51 +00:00
|
|
|
#else
|
2003-01-10 09:55:50 +00:00
|
|
|
lcd_putc(LINE_X-1, i-start, icon_type);
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif
|
2002-09-03 20:47:23 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2003-01-24 10:56:59 +00:00
|
|
|
showfileline(i-start, i, false); /* no scroll */
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-08-30 13:49:32 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-24 19:41:23 +00:00
|
|
|
if (global_settings.scrollbar && filesindir > tree_max_on_screen)
|
2002-08-30 13:49:32 +00:00
|
|
|
scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1,
|
|
|
|
LCD_HEIGHT - SCROLLBAR_Y, filesindir, start,
|
|
|
|
start + tree_max_on_screen, VERTICAL);
|
|
|
|
#endif
|
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-10-15 12:25:57 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2002-08-20 20:27:36 +00:00
|
|
|
lcd_double_height(false);
|
|
|
|
#endif
|
|
|
|
|
2002-08-19 10:57:55 +00:00
|
|
|
/* always resume? */
|
|
|
|
if ( global_settings.resume == RESUME_ON )
|
|
|
|
return true;
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
lcd_clear_display();
|
2002-09-18 14:08:05 +00:00
|
|
|
lcd_puts(0,0,str(LANG_RESUME_ASK));
|
2002-08-16 14:41:47 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2003-01-10 16:12:50 +00:00
|
|
|
status_draw();
|
2002-09-18 14:08:05 +00:00
|
|
|
lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));
|
2002-08-16 14:41:47 +00:00
|
|
|
#else
|
2002-09-18 14:08:05 +00:00
|
|
|
lcd_puts(0,1,str(LANG_RESUME_CONFIRM_RECORDER));
|
|
|
|
lcd_puts(0,2,str(LANG_RESUME_CANCEL_RECORDER));
|
2002-08-16 14:41:47 +00:00
|
|
|
#endif
|
|
|
|
lcd_update();
|
2002-10-16 07:25:33 +00:00
|
|
|
|
2003-01-28 16:08:10 +00:00
|
|
|
switch (button_get(true)) {
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
usb_screen();
|
|
|
|
break;
|
|
|
|
}
|
2003-01-15 22:46:49 +00:00
|
|
|
|
|
|
|
if ( global_settings.resume == RESUME_ASK_ONCE) {
|
|
|
|
global_settings.resume_index = -1;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
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,
|
2002-08-21 15:08:01 +00:00
|
|
|
true, /* the index is AFTER shuffle */
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_offset,
|
2002-10-06 05:50:41 +00:00
|
|
|
global_settings.resume_seed,
|
2003-01-09 00:55:00 +00:00
|
|
|
global_settings.resume_first_index,
|
|
|
|
global_settings.queue_resume,
|
|
|
|
global_settings.queue_resume_index);
|
2002-08-16 14:41:47 +00:00
|
|
|
*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,
|
2002-08-21 15:08:01 +00:00
|
|
|
true,
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_offset,
|
2002-10-06 05:50:41 +00:00
|
|
|
global_settings.resume_seed,
|
2003-01-09 00:55:00 +00:00
|
|
|
global_settings.resume_first_index,
|
|
|
|
global_settings.queue_resume,
|
|
|
|
global_settings.queue_resume_index);
|
2002-08-16 14:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!ask_resume())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (showdir(global_settings.resume_file, 0) < 0 )
|
|
|
|
return;
|
2002-09-09 17:32:15 +00:00
|
|
|
|
|
|
|
lastdir[0] = '\0';
|
|
|
|
|
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-21 15:08:01 +00:00
|
|
|
global_settings.resume_index,
|
|
|
|
true,
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_offset,
|
2002-10-06 05:50:41 +00:00
|
|
|
global_settings.resume_seed,
|
2003-01-09 00:55:00 +00:00
|
|
|
global_settings.resume_first_index,
|
|
|
|
global_settings.queue_resume,
|
|
|
|
global_settings.queue_resume_index);
|
2002-08-16 14:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_set_playmode(STATUS_PLAY);
|
|
|
|
status_draw();
|
|
|
|
wps_show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
void set_current_file(char *path)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* separate directory from filename */
|
2002-09-17 07:42:21 +00:00
|
|
|
name = strrchr(path+1,'/');
|
2002-09-09 14:25:39 +00:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
*name = 0;
|
|
|
|
strcpy(currdir, path);
|
|
|
|
*name = '/';
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(currdir, "/");
|
|
|
|
name = path+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(lastfile, name);
|
|
|
|
|
|
|
|
dircursor = 0;
|
|
|
|
dirstart = -1;
|
|
|
|
|
|
|
|
if (strncmp(currdir,lastdir,sizeof(lastdir)))
|
|
|
|
{
|
|
|
|
dirlevel = 0;
|
|
|
|
dirpos[dirlevel] = -1;
|
|
|
|
cursorpos[dirlevel] = 0;
|
|
|
|
|
|
|
|
/* use '/' to calculate dirlevel */
|
|
|
|
for (i=1; i<strlen(path)+1; i++)
|
|
|
|
{
|
|
|
|
if (path[i] == '/')
|
|
|
|
{
|
|
|
|
dirlevel++;
|
|
|
|
dirpos[dirlevel] = -1;
|
|
|
|
cursorpos[dirlevel] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-29 08:26:11 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2003-01-15 14:52:53 +00:00
|
|
|
static int onplay_screen(char* dir, char* file)
|
2002-09-29 22:24:00 +00:00
|
|
|
{
|
|
|
|
bool exit = false;
|
|
|
|
bool used = false;
|
2003-01-15 14:52:53 +00:00
|
|
|
bool playing = mpeg_status() & MPEG_STATUS_PLAY;
|
|
|
|
char buf[MAX_PATH];
|
2003-01-15 16:21:45 +00:00
|
|
|
struct entry* f = &dircache[dirstart + dircursor];
|
|
|
|
bool isdir = f->attr & ATTR_DIRECTORY;
|
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
if ((dir[0]=='/') && (dir[1]==0))
|
|
|
|
snprintf(buf, sizeof buf, "%s%s", dir, file);
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s", dir, file);
|
|
|
|
|
|
|
|
lcd_clear_display();
|
2003-01-29 09:40:04 +00:00
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
char* ptr;
|
|
|
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
if (playing) {
|
|
|
|
ptr = str(LANG_QUEUE);
|
|
|
|
lcd_getstringsize(ptr,&w,&h);
|
|
|
|
lcd_putsxy((LCD_WIDTH-w)/2, h*2, ptr);
|
|
|
|
lcd_bitmap(bitmap_icons_7x8[Icon_Play],
|
|
|
|
LCD_WIDTH/2 - 3, LCD_HEIGHT/2 - 4, 7, 8, true);
|
|
|
|
}
|
|
|
|
|
2003-01-15 16:21:45 +00:00
|
|
|
/* don't delete directories */
|
|
|
|
if (!isdir) {
|
|
|
|
ptr = str(LANG_DELETE);
|
|
|
|
lcd_getstringsize(ptr,&w,&h);
|
|
|
|
lcd_putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h/2, ptr);
|
|
|
|
lcd_bitmap(bitmap_icons_7x8[Icon_FastForward],
|
|
|
|
LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8, true);
|
|
|
|
}
|
2003-01-15 14:52:53 +00:00
|
|
|
|
|
|
|
lcd_putsxy(0, LCD_HEIGHT/2 - h/2, str(LANG_RENAME));
|
|
|
|
lcd_bitmap(bitmap_icons_7x8[Icon_FastBackward],
|
|
|
|
LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8, true);
|
|
|
|
}
|
|
|
|
lcd_update();
|
|
|
|
|
2002-09-29 22:24:00 +00:00
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
while (!exit) {
|
|
|
|
switch (button_get(true)) {
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
case BUTTON_ON | BUTTON_LEFT: {
|
|
|
|
char newname[MAX_PATH];
|
|
|
|
char* ptr = strrchr(buf, '/') + 1;
|
|
|
|
int pathlen = (ptr - buf);
|
|
|
|
strncpy(newname, buf, sizeof newname);
|
|
|
|
if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
|
|
|
|
if (rename(buf, newname) < 0) {
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_RENAME));
|
|
|
|
lcd_puts(0,1,str(LANG_FAILED));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ*2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reload_dir = true;
|
|
|
|
}
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
case BUTTON_ON | BUTTON_RIGHT:
|
2003-01-15 16:21:45 +00:00
|
|
|
/* don't delete directories */
|
|
|
|
if (isdir)
|
|
|
|
break;
|
2003-01-15 14:52:53 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_REALLY_DELETE));
|
|
|
|
lcd_puts(0,1,file);
|
|
|
|
lcd_puts(0,3,str(LANG_RESUME_CONFIRM_RECORDER));
|
|
|
|
lcd_puts(0,4,str(LANG_RESUME_CANCEL_RECORDER));
|
|
|
|
lcd_update();
|
|
|
|
while (!exit) {
|
|
|
|
int btn = button_get(true);
|
|
|
|
switch (btn) {
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
case BUTTON_PLAY | BUTTON_REL:
|
|
|
|
if (!remove(buf)) {
|
|
|
|
reload_dir = true;
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,file);
|
|
|
|
lcd_puts(0,1,str(LANG_DELETED));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
|
|
|
exit = true;
|
|
|
|
}
|
2003-01-29 09:40:04 +00:00
|
|
|
break;
|
2003-01-15 14:52:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* ignore button releases */
|
|
|
|
if (!(btn & BUTTON_REL))
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
case BUTTON_ON | BUTTON_PLAY: {
|
|
|
|
if (playing)
|
|
|
|
queue_add(buf);
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BUTTON_ON | BUTTON_REL:
|
|
|
|
used = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_ON:
|
|
|
|
if (used)
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_OFF:
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_setfont(FONT_UI);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-01-29 08:26:11 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static int onplay_screen(char* dir, char* file)
|
|
|
|
{
|
2003-01-29 09:40:04 +00:00
|
|
|
bool exit = false;
|
|
|
|
bool playing = mpeg_status() & MPEG_STATUS_PLAY;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
struct entry* f = &dircache[dirstart + dircursor];
|
|
|
|
bool isdir = f->attr & ATTR_DIRECTORY;
|
|
|
|
struct menu_items items[3];
|
|
|
|
int ids[3];
|
|
|
|
int lastitem=0;
|
|
|
|
int m_handle;
|
|
|
|
int selected;
|
|
|
|
|
|
|
|
if ((dir[0]=='/') && (dir[1]==0))
|
|
|
|
snprintf(buf, sizeof buf, "%s%s", dir, file);
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s", dir, file);
|
|
|
|
|
|
|
|
if (playing) {
|
|
|
|
items[lastitem].desc=str(LANG_QUEUE);
|
|
|
|
ids[lastitem]=1;
|
|
|
|
lastitem++;
|
|
|
|
}
|
2003-01-29 08:26:11 +00:00
|
|
|
|
2003-01-29 09:40:04 +00:00
|
|
|
items[lastitem].desc=str(LANG_RENAME);
|
|
|
|
ids[lastitem]=2;
|
|
|
|
lastitem++;
|
2003-01-29 08:26:11 +00:00
|
|
|
|
|
|
|
/* don't delete directories */
|
2003-01-29 09:40:04 +00:00
|
|
|
if (!isdir) {
|
|
|
|
items[lastitem].desc=str(LANG_DELETE);
|
|
|
|
ids[lastitem]=3;
|
|
|
|
lastitem++;
|
|
|
|
}
|
|
|
|
m_handle=menu_init(items, lastitem);
|
|
|
|
|
|
|
|
selected=menu_show(m_handle);
|
|
|
|
if (selected>=0) {
|
|
|
|
switch(ids[selected]) {
|
|
|
|
case 1:
|
|
|
|
if (playing)
|
|
|
|
queue_add(buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
char newname[MAX_PATH];
|
|
|
|
char* ptr = strrchr(buf, '/') + 1;
|
|
|
|
int pathlen = (ptr - buf);
|
|
|
|
strncpy(newname, buf, sizeof newname);
|
|
|
|
if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
|
|
|
|
if (rename(buf, newname) < 0) {
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_RENAME));
|
|
|
|
lcd_puts(0,1,str(LANG_FAILED));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ*2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reload_dir = true;
|
|
|
|
}
|
2003-01-29 08:26:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-01-29 09:40:04 +00:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,file);
|
|
|
|
lcd_puts(0,1,str(LANG_REALLY_DELETE));
|
|
|
|
lcd_update();
|
|
|
|
while (!exit) {
|
|
|
|
int btn = button_get(true);
|
|
|
|
switch (btn) {
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
if (!remove(buf)) {
|
|
|
|
reload_dir = true;
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,file);
|
|
|
|
lcd_puts(0,1,str(LANG_DELETED));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
|
|
|
exit = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* ignore button releases */
|
|
|
|
if (!(btn & BUTTON_REL))
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-01-29 08:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-29 09:40:04 +00:00
|
|
|
menu_exit(m_handle);
|
|
|
|
return false;
|
2003-01-29 08:26:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
|
|
|
|
{
|
|
|
|
bool exit = false;
|
|
|
|
bool used = false;
|
|
|
|
|
2002-09-29 22:24:00 +00:00
|
|
|
int dirstart = *ds;
|
|
|
|
int dircursor = *dc;
|
|
|
|
|
|
|
|
while (!exit) {
|
|
|
|
switch (button_get(true)) {
|
2003-01-15 14:52:53 +00:00
|
|
|
case TREE_PREV:
|
|
|
|
case BUTTON_ON | TREE_PREV:
|
|
|
|
case BUTTON_ON | TREE_PREV | BUTTON_REPEAT:
|
2002-09-29 22:24:00 +00:00
|
|
|
used = true;
|
|
|
|
if ( dirstart ) {
|
|
|
|
dirstart -= tree_max_on_screen;
|
|
|
|
if ( dirstart < 0 )
|
|
|
|
dirstart = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dircursor = 0;
|
|
|
|
break;
|
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
case TREE_NEXT:
|
|
|
|
case BUTTON_ON | TREE_NEXT:
|
|
|
|
case BUTTON_ON | TREE_NEXT | BUTTON_REPEAT:
|
2002-09-29 22:24:00 +00:00
|
|
|
used = true;
|
|
|
|
if ( dirstart < numentries - tree_max_on_screen ) {
|
|
|
|
dirstart += tree_max_on_screen;
|
|
|
|
if ( dirstart >
|
|
|
|
numentries - tree_max_on_screen )
|
|
|
|
dirstart = numentries - tree_max_on_screen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dircursor = numentries - dirstart - 1;
|
|
|
|
break;
|
2003-01-15 14:52:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
case BUTTON_ON | BUTTON_PLAY:
|
|
|
|
onplay_screen(currdir, dircache[dircursor+dirstart].name);
|
|
|
|
exit = true;
|
|
|
|
used = true;
|
|
|
|
break;
|
2002-09-29 22:24:00 +00:00
|
|
|
|
|
|
|
case BUTTON_ON | BUTTON_REL:
|
2003-01-15 14:52:53 +00:00
|
|
|
case BUTTON_ON | TREE_PREV | BUTTON_REL:
|
|
|
|
case BUTTON_ON | TREE_NEXT | BUTTON_REL:
|
2002-09-29 22:24:00 +00:00
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
2003-01-15 14:52:53 +00:00
|
|
|
if ( used && !exit ) {
|
2002-09-29 22:24:00 +00:00
|
|
|
showdir(currdir, dirstart);
|
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ds = dirstart;
|
|
|
|
*dc = dircursor;
|
|
|
|
|
|
|
|
return used;
|
|
|
|
}
|
|
|
|
|
2002-10-08 15:42:40 +00:00
|
|
|
static void storefile(char* filename, char* setting, int maxlen)
|
|
|
|
{
|
|
|
|
int len = strlen(filename);
|
|
|
|
int extlen = 0;
|
|
|
|
char* ptr = filename + len;
|
|
|
|
|
|
|
|
while (*ptr != '.') {
|
|
|
|
extlen++;
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
|
2002-10-08 15:45:50 +00:00
|
|
|
if (strcmp(ROCKBOX_DIR, currdir) || (len-extlen > maxlen))
|
2002-10-08 15:42:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
strncpy(setting, filename, len-extlen);
|
|
|
|
setting[len-extlen]=0;
|
|
|
|
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
bool dirbrowse(char *root)
|
|
|
|
{
|
2002-08-08 12:06:38 +00:00
|
|
|
int numentries=0;
|
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-27 19:41:58 +00:00
|
|
|
int button;
|
2002-08-11 09:17:47 +00:00
|
|
|
int tree_max_on_screen;
|
2002-09-03 20:47:23 +00:00
|
|
|
bool reload_root = false;
|
2002-09-24 19:12:09 +00:00
|
|
|
int lastfilter = global_settings.dirfilter;
|
2002-09-03 20:47:23 +00:00
|
|
|
bool lastsortcase = global_settings.sort_case;
|
2003-01-23 14:28:16 +00:00
|
|
|
int lastdircursor=-1;
|
2003-01-24 10:56:59 +00:00
|
|
|
bool need_update = true;
|
|
|
|
|
|
|
|
bool update_all = false; /* set this to true when the whole file list
|
|
|
|
has been refreshed on screen */
|
|
|
|
|
2002-09-12 13:33:59 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int fw, fh;
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_getstringsize("A", &fw, &fh);
|
2002-08-20 19:39:55 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
2002-08-11 09:17:47 +00:00
|
|
|
#else
|
|
|
|
tree_max_on_screen = TREE_MAX_ON_SCREEN;
|
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-09-09 14:25:39 +00:00
|
|
|
dircursor=0;
|
|
|
|
dirstart=0;
|
|
|
|
dirlevel=0;
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
memcpy(currdir,root,sizeof(currdir));
|
2002-09-09 17:32:15 +00:00
|
|
|
|
|
|
|
start_resume();
|
|
|
|
|
|
|
|
numentries = showdir(currdir, dirstart);
|
2002-05-16 12:53:40 +00:00
|
|
|
if (numentries == -1)
|
2003-01-31 08:43:12 +00:00
|
|
|
return false; /* currdir is not a directory */
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all = true;
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
2002-09-09 14:25:39 +00:00
|
|
|
struct entry* file = &dircache[dircursor+dirstart];
|
2002-09-02 12:46:32 +00:00
|
|
|
|
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-09-01 14:49:56 +00:00
|
|
|
case TREE_EXIT | BUTTON_REPEAT:
|
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-09-09 14:25:39 +00:00
|
|
|
dirstart = dirpos[dirlevel];
|
2002-05-31 07:19:38 +00:00
|
|
|
dircursor = cursorpos[dirlevel];
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
else
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart = dircursor = 0;
|
|
|
|
|
|
|
|
if (dirstart == -1)
|
|
|
|
strcpy(lastfile, buf);
|
|
|
|
|
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
|
|
|
settings_save();
|
|
|
|
break;
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
case TREE_ENTER:
|
2002-09-01 14:49:56 +00:00
|
|
|
case TREE_ENTER | BUTTON_REPEAT:
|
2002-06-25 11:10:24 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2003-01-15 14:52:53 +00:00
|
|
|
case BUTTON_PLAY:
|
2002-09-02 12:46:32 +00:00
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
2002-06-25 11:10:24 +00:00
|
|
|
#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-09-02 12:46:32 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s%s",currdir, file->name);
|
2002-05-16 12:53:40 +00:00
|
|
|
} else {
|
2002-09-02 12:46:32 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s/%s",currdir, file->name);
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 12:46:32 +00:00
|
|
|
if (file->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-09-09 14:25:39 +00:00
|
|
|
dirpos[dirlevel] = dirstart;
|
2002-07-22 22:45:20 +00:00
|
|
|
cursorpos[dirlevel] = dircursor;
|
2002-05-31 07:19:38 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
dirlevel++;
|
|
|
|
dircursor=0;
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart=0;
|
2003-01-24 10:56:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-08-16 14:41:47 +00:00
|
|
|
int seed = current_tick;
|
2002-09-03 09:44:08 +00:00
|
|
|
bool play = false;
|
|
|
|
int start_index=0;
|
2002-10-08 15:42:40 +00:00
|
|
|
|
2002-06-10 13:24:27 +00:00
|
|
|
lcd_stop_scroll();
|
2002-09-03 09:44:08 +00:00
|
|
|
switch ( file->attr & TREE_ATTR_MASK ) {
|
|
|
|
case TREE_ATTR_M3U:
|
|
|
|
if ( global_settings.resume )
|
|
|
|
snprintf(global_settings.resume_file,
|
|
|
|
MAX_PATH, "%s/%s",
|
|
|
|
currdir, file->name);
|
2002-10-06 05:50:41 +00:00
|
|
|
play_list(currdir, file->name, 0, false, 0,
|
2003-01-09 00:55:00 +00:00
|
|
|
seed, 0, 0, -1);
|
2002-09-03 09:44:08 +00:00
|
|
|
start_index = 0;
|
|
|
|
play = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_ATTR_MPA:
|
2003-01-15 14:52:53 +00:00
|
|
|
if ( global_settings.resume )
|
|
|
|
strncpy(global_settings.resume_file,
|
|
|
|
currdir, MAX_PATH);
|
|
|
|
start_index =
|
|
|
|
build_playlist(dircursor+dirstart);
|
|
|
|
|
2003-01-09 00:55:00 +00:00
|
|
|
/* it is important that we get back the index
|
|
|
|
in the (shuffled) list and store that */
|
2003-01-15 14:52:53 +00:00
|
|
|
start_index = play_list(currdir, NULL,
|
|
|
|
start_index, false,
|
|
|
|
0, seed, 0, 0, -1);
|
|
|
|
play = true;
|
2002-09-03 09:44:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* wps config file */
|
|
|
|
case TREE_ATTR_WPS:
|
2002-09-02 12:46:32 +00:00
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
2002-10-08 15:42:40 +00:00
|
|
|
wps_load(buf,true);
|
|
|
|
storefile(file->name, global_settings.wps_file,
|
|
|
|
MAX_FILENAME);
|
2002-09-02 12:46:32 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
2002-09-03 09:44:08 +00:00
|
|
|
|
2002-10-08 09:40:05 +00:00
|
|
|
case TREE_ATTR_CFG:
|
2002-09-05 01:20:10 +00:00
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
2002-10-08 09:40:05 +00:00
|
|
|
settings_load_config(buf);
|
2002-09-05 01:20:10 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
case TREE_ATTR_TXT:
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
|
|
|
viewer_run(buf);
|
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
2002-09-24 12:40:52 +00:00
|
|
|
case TREE_ATTR_LNG:
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
2002-09-24 13:37:38 +00:00
|
|
|
if(!lang_load(buf)) {
|
2002-10-08 15:42:40 +00:00
|
|
|
storefile(file->name,
|
|
|
|
global_settings.lang_file,
|
|
|
|
MAX_FILENAME);
|
|
|
|
|
2002-09-24 13:37:38 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
lcd_puts(0, 0, str(LANG_LANGUAGE_LOADED));
|
|
|
|
#else
|
|
|
|
lcd_getstringsize(str(LANG_LANGUAGE_LOADED),
|
2002-09-24 18:04:15 +00:00
|
|
|
&fw, &fh);
|
2002-09-24 13:37:38 +00:00
|
|
|
if(fw>LCD_WIDTH)
|
|
|
|
fw=0;
|
|
|
|
else
|
|
|
|
fw=LCD_WIDTH/2 - fw/2;
|
|
|
|
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy(fw, LCD_HEIGHT/2 - fh/2,
|
|
|
|
str(LANG_LANGUAGE_LOADED));
|
2002-09-24 13:37:38 +00:00
|
|
|
#endif
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
|
|
|
restore = true;
|
|
|
|
}
|
2002-09-24 12:40:52 +00:00
|
|
|
break;
|
|
|
|
|
2002-09-20 08:07:51 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
case TREE_ATTR_FONT:
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
|
|
|
font_load(buf);
|
2002-10-08 15:42:40 +00:00
|
|
|
storefile(file->name, global_settings.font_file,
|
|
|
|
MAX_FILENAME);
|
|
|
|
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_getstringsize("A", &fw, &fh);
|
2002-09-20 08:07:51 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
|
|
|
/* make sure cursor is on screen */
|
|
|
|
while ( dircursor > tree_max_on_screen ) {
|
|
|
|
dircursor--;
|
|
|
|
dirstart++;
|
|
|
|
}
|
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
#ifndef SIMULATOR
|
|
|
|
/* firmware file */
|
|
|
|
case TREE_ATTR_MOD:
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s",
|
|
|
|
currdir, file->name);
|
|
|
|
rolo_load(buf);
|
2002-09-02 12:46:32 +00:00
|
|
|
break;
|
2002-09-03 09:44:08 +00:00
|
|
|
#endif
|
2002-08-16 14:41:47 +00:00
|
|
|
}
|
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
if ( play ) {
|
|
|
|
if ( global_settings.resume ) {
|
|
|
|
/* the resume_index must always be the index in the
|
|
|
|
shuffled list in case shuffle is enabled */
|
|
|
|
global_settings.resume_index = start_index;
|
|
|
|
global_settings.resume_offset = 0;
|
2002-10-11 09:14:30 +00:00
|
|
|
global_settings.resume_first_index =
|
|
|
|
playlist_first_index();
|
2002-09-03 09:44:08 +00:00
|
|
|
global_settings.resume_seed = seed;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
|
|
|
|
status_set_playmode(STATUS_PLAY);
|
|
|
|
status_draw();
|
|
|
|
lcd_stop_scroll();
|
2002-09-03 20:47:23 +00:00
|
|
|
if ( wps_show() == SYS_USB_CONNECTED ) {
|
|
|
|
reload_root = true;
|
2002-09-03 09:44:08 +00:00
|
|
|
}
|
2002-09-12 13:33:59 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-03 09:44:08 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
2002-08-30 13:49:32 +00:00
|
|
|
#endif
|
2002-09-03 09:44:08 +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) {
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);
|
2002-07-22 22:45:20 +00:00
|
|
|
dircursor--;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-09-09 14:25:39 +00:00
|
|
|
if (dirstart) {
|
|
|
|
dirstart--;
|
|
|
|
numentries = showdir(currdir, dirstart);
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all=true;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-08-11 09:17:47 +00:00
|
|
|
if (numentries < tree_max_on_screen) {
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
|
2002-07-22 22:45:20 +00:00
|
|
|
false);
|
|
|
|
dircursor = numentries - 1;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
|
2002-07-22 22:45:20 +00:00
|
|
|
true);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart = numentries - tree_max_on_screen;
|
2002-08-11 09:17:47 +00:00
|
|
|
dircursor = tree_max_on_screen - 1;
|
2002-09-09 14:25:39 +00:00
|
|
|
numentries = showdir(currdir, dirstart);
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all = true;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y +
|
2002-08-11 09:17:47 +00:00
|
|
|
tree_max_on_screen - 1, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-28 09:11:42 +00:00
|
|
|
need_update = true;
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2002-09-09 14:25:39 +00:00
|
|
|
if (dircursor + dirstart + 1 < numentries ) {
|
2002-08-11 09:17:47 +00:00
|
|
|
if(dircursor+1 < tree_max_on_screen) {
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
|
2002-07-22 22:45:20 +00:00
|
|
|
false);
|
|
|
|
dircursor++;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart++;
|
|
|
|
numentries = showdir(currdir, dirstart);
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all = true;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-08-11 09:17:47 +00:00
|
|
|
if(numentries < tree_max_on_screen) {
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
|
2002-07-22 22:45:20 +00:00
|
|
|
false);
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart = dircursor = 0;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart = dircursor = 0;
|
|
|
|
numentries = showdir(currdir, dirstart);
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all=true;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-28 09:11:42 +00:00
|
|
|
need_update = true;
|
2002-07-22 22:45:20 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
break;
|
2002-05-21 14:30:54 +00:00
|
|
|
|
2002-09-03 20:47:23 +00:00
|
|
|
case TREE_MENU:
|
2002-06-10 13:24:27 +00:00
|
|
|
lcd_stop_scroll();
|
2002-09-24 17:22:12 +00:00
|
|
|
if (main_menu())
|
|
|
|
reload_root = true;
|
2002-06-25 13:26:04 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
2002-05-21 14:30:54 +00:00
|
|
|
|
2002-06-25 13:26:04 +00:00
|
|
|
case BUTTON_ON:
|
2003-01-15 14:52:53 +00:00
|
|
|
if (handle_on(&dirstart, &dircursor, numentries,
|
|
|
|
tree_max_on_screen))
|
2002-08-07 06:04:24 +00:00
|
|
|
{
|
2002-09-29 22:24:00 +00:00
|
|
|
/* start scroll */
|
|
|
|
restore = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mpeg_status() & MPEG_STATUS_PLAY)
|
|
|
|
{
|
|
|
|
lcd_stop_scroll();
|
|
|
|
if (wps_show() == SYS_USB_CONNECTED)
|
|
|
|
reload_root = true;
|
2002-09-12 13:33:59 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-29 22:24:00 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
2002-08-30 13:49:32 +00:00
|
|
|
#endif
|
2002-09-29 22:24:00 +00:00
|
|
|
restore = true;
|
|
|
|
}
|
2002-06-27 01:20:08 +00:00
|
|
|
}
|
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
|
2002-09-03 15:58:47 +00:00
|
|
|
case BUTTON_F2:
|
2002-09-03 20:47:23 +00:00
|
|
|
if (f2_screen())
|
|
|
|
reload_root = true;
|
2002-09-03 15:58:47 +00:00
|
|
|
restore = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_F3:
|
2002-09-03 20:47:23 +00:00
|
|
|
if (f3_screen())
|
|
|
|
reload_root = true;
|
2002-09-12 13:33:59 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-09-03 15:58:47 +00:00
|
|
|
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
2002-09-03 15:58:47 +00:00
|
|
|
restore = true;
|
2002-08-07 10:35:26 +00:00
|
|
|
break;
|
2002-08-20 19:39:55 +00:00
|
|
|
#endif
|
2002-08-07 10:35:26 +00:00
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
case SYS_USB_CONNECTED:
|
2002-10-11 08:56:23 +00:00
|
|
|
status_set_playmode(STATUS_STOP);
|
2002-09-24 17:22:12 +00:00
|
|
|
usb_screen();
|
2002-09-03 20:47:23 +00:00
|
|
|
reload_root = true;
|
2002-09-24 17:22:12 +00:00
|
|
|
break;
|
2002-10-28 09:11:42 +00:00
|
|
|
|
|
|
|
case BUTTON_NONE:
|
|
|
|
status_draw();
|
|
|
|
break;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2002-06-10 13:24:27 +00:00
|
|
|
|
2002-08-26 13:21:14 +00:00
|
|
|
if ( button )
|
|
|
|
ata_spin();
|
|
|
|
|
2002-09-03 20:47:23 +00:00
|
|
|
/* do we need to rescan dir? */
|
|
|
|
if (reload_root ||
|
2002-09-24 19:12:09 +00:00
|
|
|
lastfilter != global_settings.dirfilter ||
|
|
|
|
lastsortcase != global_settings.sort_case)
|
2002-09-03 20:47:23 +00:00
|
|
|
{
|
|
|
|
if ( reload_root ) {
|
|
|
|
strcpy(currdir, "/");
|
|
|
|
dirlevel = 0;
|
|
|
|
reload_root = false;
|
|
|
|
}
|
|
|
|
dircursor = 0;
|
2002-09-09 14:25:39 +00:00
|
|
|
dirstart = 0;
|
2002-09-03 20:47:23 +00:00
|
|
|
lastdir[0] = 0;
|
2002-09-24 19:12:09 +00:00
|
|
|
lastfilter = global_settings.dirfilter;
|
2002-09-03 20:47:23 +00:00
|
|
|
lastsortcase = global_settings.sort_case;
|
|
|
|
restore = true;
|
|
|
|
}
|
|
|
|
|
2003-01-15 14:52:53 +00:00
|
|
|
if (restore || reload_dir) {
|
2002-06-25 13:26:04 +00:00
|
|
|
/* 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-09-09 14:25:39 +00:00
|
|
|
dirstart++;
|
2002-08-08 10:46:10 +00:00
|
|
|
dircursor--;
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* the sub-screen might've ruined the margins */
|
|
|
|
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and
|
|
|
|
icon */
|
|
|
|
#endif
|
2002-09-09 14:25:39 +00:00
|
|
|
numentries = showdir(currdir, dirstart);
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all = true;
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
|
2002-10-28 09:11:42 +00:00
|
|
|
|
|
|
|
need_update = true;
|
2003-01-15 14:52:53 +00:00
|
|
|
reload_dir = false;
|
2002-06-25 13:26:04 +00:00
|
|
|
}
|
2002-06-10 13:24:27 +00:00
|
|
|
|
2003-01-24 10:56:59 +00:00
|
|
|
if ( numentries && need_update) {
|
2002-09-09 14:25:39 +00:00
|
|
|
i = dirstart+dircursor;
|
2002-08-07 10:35:26 +00:00
|
|
|
|
|
|
|
/* if MP3 filter is on, cut off the extension */
|
|
|
|
if(lasti!=i || restore) {
|
|
|
|
lcd_stop_scroll();
|
2003-01-24 10:56:59 +00:00
|
|
|
|
|
|
|
/* So if lastdircursor and dircursor differ, and then full
|
|
|
|
screen was not refreshed, restore the previous line */
|
|
|
|
if ((lastdircursor != dircursor) && !update_all ) {
|
|
|
|
showfileline(lastdircursor, lasti, false); /* no scroll */
|
|
|
|
}
|
2003-01-23 14:28:16 +00:00
|
|
|
lasti=i;
|
|
|
|
lastdircursor=dircursor;
|
2002-10-28 09:11:42 +00:00
|
|
|
|
2003-01-24 10:56:59 +00:00
|
|
|
showfileline(dircursor, i, true); /* scroll please */
|
2002-10-28 09:11:42 +00:00
|
|
|
need_update = true;
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-28 09:11:42 +00:00
|
|
|
|
|
|
|
if(need_update) {
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
need_update = false;
|
2003-01-24 10:56:59 +00:00
|
|
|
update_all = false;
|
2002-10-28 09:11:42 +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;
|
|
|
|
static bool add_dir(char* dirname, int fd)
|
|
|
|
{
|
|
|
|
bool abort = false;
|
|
|
|
char buf[MAX_PATH/2]; /* saving a little stack... */
|
2003-01-29 17:14:55 +00:00
|
|
|
DIR* dir;
|
|
|
|
|
2003-01-29 13:20:22 +00:00
|
|
|
/* check for user abort */
|
|
|
|
#ifdef HAVE_PLAYER_KEYPAD
|
|
|
|
if (button_get(false) == BUTTON_STOP)
|
|
|
|
#else
|
|
|
|
if (button_get(false) == BUTTON_OFF)
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
|
2003-01-29 17:14:55 +00:00
|
|
|
dir = opendir(dirname);
|
2003-01-29 13:20:22 +00:00
|
|
|
if(!dir)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
entry = readdir(dir);
|
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY) {
|
|
|
|
if (!strcmp(entry->d_name, ".") ||
|
|
|
|
!strcmp(entry->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
snprintf(buf, sizeof buf, "%s/%s", dirname, entry->d_name);
|
|
|
|
if (add_dir(buf,fd)) {
|
|
|
|
abort = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int x = strlen(entry->d_name);
|
|
|
|
if ((!strcasecmp(&entry->d_name[x-4], ".mp3")) ||
|
|
|
|
(!strcasecmp(&entry->d_name[x-4], ".mp2")) ||
|
|
|
|
(!strcasecmp(&entry->d_name[x-4], ".mpa")))
|
|
|
|
{
|
|
|
|
write(fd, dirname, strlen(dirname));
|
|
|
|
write(fd, "/", 1);
|
|
|
|
write(fd, entry->d_name, x);
|
|
|
|
write(fd, "\n", 1);
|
|
|
|
|
|
|
|
plsize++;
|
|
|
|
snprintf(buf, sizeof buf, "%d", plsize);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_puts(0,4,buf);
|
|
|
|
lcd_update();
|
|
|
|
#else
|
|
|
|
x = 10;
|
|
|
|
if (plsize > 999)
|
|
|
|
x=7;
|
|
|
|
else {
|
|
|
|
if (plsize > 99)
|
|
|
|
x=8;
|
|
|
|
else {
|
|
|
|
if (plsize > 9)
|
|
|
|
x=9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lcd_puts(x,0,buf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
return abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool create_playlist(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
|
|
|
|
snprintf(filename, sizeof filename, "%s.m3u",
|
|
|
|
currdir[1] ? currdir : "/root");
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_CREATING));
|
|
|
|
lcd_puts_scroll(0,1,filename);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
fd = creat(filename,0);
|
|
|
|
if (!fd)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
plsize = 0;
|
|
|
|
add_dir(currdir[1] ? currdir : "/", fd);
|
|
|
|
close(fd);
|
|
|
|
sleep(HZ);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|