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>
|
|
|
|
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "tree.h"
|
2002-05-16 14:48:40 +00:00
|
|
|
#include "play.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-16 12:53:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
#define MAX_FILES_IN_DIR 200
|
2002-05-16 12:53:40 +00:00
|
|
|
#define TREE_MAX_FILENAMELEN 128
|
|
|
|
#define MAX_DIR_LEVELS 10
|
|
|
|
|
|
|
|
struct entry {
|
|
|
|
bool file; /* true if file, false if dir */
|
|
|
|
char name[TREE_MAX_FILENAMELEN];
|
|
|
|
};
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
static struct entry buffer[MAX_FILES_IN_DIR];
|
|
|
|
static int filesindir;
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
void browse_root(void)
|
|
|
|
{
|
|
|
|
dirbrowse("/");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
|
|
|
#define TREE_MAX_ON_SCREEN 7
|
|
|
|
#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */
|
|
|
|
|
|
|
|
#define MARGIN_Y 8 /* Y pixel margin */
|
|
|
|
#define MARGIN_X 12 /* X pixel margin */
|
|
|
|
#define LINE_Y 0 /* Y position the entry-list starts at */
|
|
|
|
#define LINE_X 2 /* X position the entry-list starts at */
|
|
|
|
#define LINE_HEIGTH 8 /* pixels for each text line */
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
static int showdir(char *path, int start)
|
2002-05-16 12:53:40 +00:00
|
|
|
{
|
2002-05-28 16:26:12 +00:00
|
|
|
static char lastdir[256] = {0};
|
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int icon_type = 0;
|
|
|
|
#endif
|
|
|
|
int i;
|
|
|
|
|
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 */
|
|
|
|
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
|
|
|
|
struct dirent *entry = readdir(dir);
|
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
if(entry->d_name[0] == '.') {
|
|
|
|
/* skip names starting with a dot */
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buffer[i].file = !(entry->attribute & ATTR_DIRECTORY);
|
|
|
|
strncpy(buffer[i].name,entry->d_name,TREE_MAX_FILENAMELEN);
|
|
|
|
buffer[i].name[TREE_MAX_FILENAMELEN-1]=0;
|
|
|
|
}
|
|
|
|
filesindir = i;
|
|
|
|
closedir(dir);
|
|
|
|
strncpy(lastdir,path,sizeof(lastdir));
|
|
|
|
lastdir[sizeof(lastdir)-1] = 0;
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_putsxy(0,0, "[Browse]",0);
|
|
|
|
lcd_update();
|
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
|
2002-05-28 16:26:12 +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;
|
|
|
|
|
|
|
|
len = strlen(buffer[i].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-05-28 16:32:43 +00:00
|
|
|
if ( buffer[i].file )
|
|
|
|
icon_type=File;
|
|
|
|
else
|
|
|
|
icon_type=Folder;
|
2002-05-29 08:18:46 +00:00
|
|
|
lcd_bitmap(bitmap_icons_6x8[icon_type],
|
|
|
|
6, MARGIN_Y+(i-start)*LINE_HEIGTH, 6, 8, true);
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-28 16:32:43 +00:00
|
|
|
if(len < TREE_MAX_LEN_DISPLAY)
|
|
|
|
lcd_puts(LINE_X, LINE_Y+i-start, buffer[i].name);
|
|
|
|
else {
|
|
|
|
char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY];
|
|
|
|
buffer[i].name[TREE_MAX_LEN_DISPLAY]=0;
|
|
|
|
lcd_puts(LINE_X, LINE_Y+i-start, buffer[i].name);
|
|
|
|
buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
return filesindir;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool dirbrowse(char *root)
|
|
|
|
{
|
|
|
|
int numentries;
|
|
|
|
char buf[255];
|
|
|
|
char currdir[255];
|
|
|
|
int dircursor=0;
|
|
|
|
int i;
|
|
|
|
int start=0;
|
|
|
|
int dirpos[MAX_DIR_LEVELS];
|
|
|
|
int dirlevel=0;
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_putsxy(0,0, "[Browse]",0);
|
|
|
|
lcd_setmargins(0,MARGIN_Y);
|
|
|
|
lcd_setfont(0);
|
|
|
|
#endif
|
|
|
|
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 */
|
|
|
|
|
|
|
|
lcd_puts(0, dircursor, "-");
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_update();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while(1) {
|
2002-05-28 16:32:43 +00:00
|
|
|
switch(button_get(true)) {
|
2002-05-21 20:23:35 +00:00
|
|
|
#if defined(SIMULATOR) && defined(HAVE_RECODER_KEYPAD)
|
2002-05-21 18:02:47 +00:00
|
|
|
case BUTTON_OFF:
|
|
|
|
return false;
|
2002-05-21 18:05:31 +00:00
|
|
|
#endif
|
2002-05-21 18:02:47 +00:00
|
|
|
|
2002-05-16 12:53:40 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
2002-05-16 14:48:40 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
#endif
|
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--;
|
|
|
|
if ( dirlevel < MAX_DIR_LEVELS )
|
|
|
|
start = dirpos[dirlevel];
|
|
|
|
else
|
|
|
|
start = 0;
|
2002-05-28 16:26:12 +00:00
|
|
|
numentries = showdir(currdir, start);
|
2002-05-16 12:53:40 +00:00
|
|
|
dircursor=0;
|
|
|
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
2002-05-28 16:26:12 +00:00
|
|
|
(strcmp(buffer[dircursor+start].name,buf)!=0))
|
2002-05-16 12:53:40 +00:00
|
|
|
dircursor++;
|
|
|
|
if (dircursor==TREE_MAX_ON_SCREEN)
|
|
|
|
dircursor=0;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
2002-05-27 14:55:40 +00:00
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-05-16 14:48:40 +00:00
|
|
|
case BUTTON_RIGHT:
|
2002-05-16 12:53:40 +00:00
|
|
|
#endif
|
2002-05-16 14:48:40 +00:00
|
|
|
case BUTTON_PLAY:
|
2002-05-16 12:53:40 +00:00
|
|
|
if ((currdir[0]=='/') && (currdir[1]==0)) {
|
2002-05-28 16:26:12 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s%s",currdir,buffer[dircursor+start].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
} else {
|
2002-05-28 16:26:12 +00:00
|
|
|
snprintf(buf,sizeof(buf),"%s/%s",currdir,buffer[dircursor+start].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
if (!buffer[dircursor+start].file) {
|
2002-05-16 12:53:40 +00:00
|
|
|
memcpy(currdir,buf,sizeof(currdir));
|
|
|
|
if ( dirlevel < MAX_DIR_LEVELS )
|
|
|
|
dirpos[dirlevel] = start+dircursor;
|
|
|
|
dirlevel++;
|
|
|
|
dircursor=0;
|
|
|
|
start=0;
|
|
|
|
} else {
|
2002-05-28 16:26:12 +00:00
|
|
|
playtune(currdir, buffer[dircursor+start].name);
|
2002-05-16 12:53:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_setmargins(0, MARGIN_Y);
|
|
|
|
lcd_setfont(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-05-28 16:26:12 +00:00
|
|
|
numentries = showdir(currdir, start);
|
2002-05-16 12:53:40 +00:00
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
break;
|
2002-05-16 14:48:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-05-16 12:53:40 +00:00
|
|
|
case BUTTON_UP:
|
2002-05-16 14:48:40 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#endif
|
2002-05-16 12:53:40 +00:00
|
|
|
if(dircursor) {
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, " ");
|
|
|
|
dircursor--;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
else {
|
2002-05-28 16:26:12 +00:00
|
|
|
if (start) {
|
2002-05-16 12:53:40 +00:00
|
|
|
start--;
|
2002-05-28 16:26:12 +00:00
|
|
|
numentries = showdir(currdir, start);
|
2002-05-16 12:53:40 +00:00
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-05-16 14:48:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-05-16 12:53:40 +00:00
|
|
|
case BUTTON_DOWN:
|
2002-05-16 14:48:40 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
#endif
|
2002-05-29 09:00:13 +00:00
|
|
|
if (dircursor + start + 1 < numentries ) {
|
|
|
|
if(dircursor+1 < TREE_MAX_ON_SCREEN) {
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, " ");
|
|
|
|
dircursor++;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start++;
|
|
|
|
numentries = showdir(currdir, start);
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
}
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-05-21 14:30:54 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F1:
|
|
|
|
case BUTTON_F2:
|
|
|
|
case BUTTON_F3:
|
|
|
|
#else
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
|
|
|
main_menu();
|
|
|
|
|
|
|
|
/* restore display */
|
|
|
|
/* TODO: this is just a copy from BUTTON_STOP, fix it */
|
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_putsxy(0,0, "[Browse]",0);
|
|
|
|
lcd_setmargins(0,MARGIN_Y);
|
|
|
|
lcd_setfont(0);
|
|
|
|
#endif
|
2002-05-28 16:26:12 +00:00
|
|
|
numentries = showdir(currdir, start);
|
2002-05-21 14:30:54 +00:00
|
|
|
dircursor=0;
|
|
|
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
2002-05-28 16:26:12 +00:00
|
|
|
(strcmp(buffer[dircursor+start].name,buf)!=0))
|
2002-05-21 14:30:54 +00:00
|
|
|
dircursor++;
|
|
|
|
if (dircursor==TREE_MAX_ON_SCREEN)
|
|
|
|
dircursor=0;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor, "-");
|
|
|
|
|
|
|
|
break;
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
2002-05-28 16:26:12 +00:00
|
|
|
lcd_update();
|
2002-05-16 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|