2002-04-30 13:16:08 +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-05 10:45:50 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-04-30 13:16:08 +00:00
|
|
|
#include <dir.h>
|
2002-05-05 10:45:50 +00:00
|
|
|
#include <file.h>
|
2002-04-30 13:16:08 +00:00
|
|
|
#include <types.h>
|
2002-04-30 13:37:28 +00:00
|
|
|
#include <lcd.h>
|
|
|
|
#include <button.h>
|
2002-04-30 21:15:44 +00:00
|
|
|
#include "kernel.h"
|
2002-05-04 10:02:50 +00:00
|
|
|
#include "tree.h"
|
2002-04-30 13:16:08 +00:00
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
#include "play.h"
|
|
|
|
|
|
|
|
#define TREE_MAX_FILENAMELEN 64
|
|
|
|
#define TREE_MAX_ON_SCREEN 7
|
|
|
|
#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
|
2002-04-30 13:37:28 +00:00
|
|
|
|
2002-05-04 10:02:50 +00:00
|
|
|
void browse_root(void) {
|
|
|
|
dirbrowse("/");
|
|
|
|
}
|
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
struct entry {
|
|
|
|
int file; /* TRUE if file, FALSE if dir */
|
|
|
|
char name[TREE_MAX_FILENAMELEN];
|
|
|
|
int namelen;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LINE_Y 8 /* Y position the entry-list starts at */
|
|
|
|
#define LINE_X 6 /* X position the entry-list starts at */
|
|
|
|
#define LINE_HEIGTH 8 /* pixels for each text line */
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2002-05-06 06:47:19 +00:00
|
|
|
bool is_dir(char* path)
|
|
|
|
{
|
2002-05-06 06:17:07 +00:00
|
|
|
DIR* dir = opendir(path);
|
2002-05-06 06:50:35 +00:00
|
|
|
if(dir) {
|
|
|
|
closedir(dir);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-05-06 06:17:07 +00:00
|
|
|
}
|
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
int static
|
|
|
|
showdir(char *path, struct entry *buffer, int start)
|
2002-04-30 13:16:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
2002-05-05 10:45:50 +00:00
|
|
|
DIR *dir = opendir(path);
|
2002-04-30 13:16:08 +00:00
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
if(!dir)
|
2002-05-06 06:17:07 +00:00
|
|
|
return -1; /* not a directory */
|
2002-04-30 13:16:08 +00:00
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
i=start;
|
|
|
|
while((entry = readdir(dir))) {
|
|
|
|
int len;
|
2002-04-30 13:37:28 +00:00
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
if(entry->d_name[0] == '.')
|
|
|
|
/* skip names starting with a dot */
|
|
|
|
continue;
|
2002-04-30 13:37:28 +00:00
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
len = strlen(entry->d_name);
|
|
|
|
if(len < TREE_MAX_FILENAMELEN)
|
|
|
|
/* strncpy() is evil, we memcpy() instead, +1 includes the
|
|
|
|
trailing zero */
|
|
|
|
memcpy(buffer[i].name, entry->d_name, len+1);
|
|
|
|
else
|
|
|
|
memcpy(buffer[i].name, "too long", 9);
|
|
|
|
|
|
|
|
buffer[i].file = TRUE; /* files only for now */
|
|
|
|
|
|
|
|
if(len < TREE_MAX_LEN_DISPLAY)
|
|
|
|
lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0);
|
|
|
|
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*LINE_HEIGTH, buffer[i].name, 0);
|
|
|
|
buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage;
|
|
|
|
}
|
2002-04-30 13:16:08 +00:00
|
|
|
|
2002-04-30 21:15:44 +00:00
|
|
|
if(++i >= TREE_MAX_ON_SCREEN)
|
2002-04-30 13:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool dirbrowse(char *root)
|
|
|
|
{
|
|
|
|
struct entry buffer[TREE_MAX_ON_SCREEN];
|
|
|
|
int numentries;
|
2002-05-06 06:17:07 +00:00
|
|
|
char buf[255];
|
|
|
|
char currdir[255];
|
|
|
|
int dircursor=0;
|
|
|
|
int i;
|
2002-05-05 10:45:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
lcd_puts(0,0, "[Browse]", 0);
|
2002-05-06 06:17:07 +00:00
|
|
|
memcpy(currdir,root,sizeof(currdir));
|
2002-05-05 10:45:50 +00:00
|
|
|
|
2002-05-06 06:17:07 +00:00
|
|
|
numentries = showdir(root, buffer, 0);
|
|
|
|
|
|
|
|
if (numentries == -1) return -1; /* root is not a directory */
|
2002-05-05 10:45:50 +00:00
|
|
|
|
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
2002-04-30 13:37:28 +00:00
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int key = button_get();
|
|
|
|
|
|
|
|
if(!key) {
|
|
|
|
sleep(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch(key) {
|
|
|
|
case BUTTON_OFF:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
2002-05-05 10:45:50 +00:00
|
|
|
|
2002-05-06 06:17:07 +00:00
|
|
|
case BUTTON_LEFT:
|
|
|
|
i=strlen(currdir);
|
|
|
|
if (i==1) {
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
while (currdir[i-1]!='/') i--;
|
|
|
|
strcpy(buf,&currdir[i]);
|
|
|
|
if (i==1) currdir[i]=0;
|
|
|
|
else currdir[i-1]=0;
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0, "[Browse]", 0);
|
|
|
|
numentries = showdir(currdir, buffer, 0);
|
|
|
|
dircursor=0;
|
|
|
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
|
|
|
(strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2002-05-05 10:45:50 +00:00
|
|
|
case BUTTON_RIGHT:
|
|
|
|
case BUTTON_PLAY:
|
2002-05-06 06:17:07 +00:00
|
|
|
if ((currdir[0]=='/') && (currdir[1]==0)) {
|
|
|
|
sprintf(buf,"%s%s",currdir,buffer[dircursor].name);
|
|
|
|
} else {
|
|
|
|
sprintf(buf,"%s/%s",currdir,buffer[dircursor].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_dir(buf)) {
|
|
|
|
memcpy(currdir,buf,sizeof(currdir));
|
|
|
|
dircursor=0;
|
|
|
|
} else {
|
|
|
|
playtune(currdir, buffer[dircursor].name);
|
|
|
|
}
|
2002-05-05 10:45:50 +00:00
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0, "[Browse]", 0);
|
2002-05-06 06:17:07 +00:00
|
|
|
numentries = showdir(currdir, buffer, 0);
|
2002-05-05 10:45:50 +00:00
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
|
|
|
lcd_update();
|
|
|
|
break;
|
2002-04-30 13:37:28 +00:00
|
|
|
|
|
|
|
case BUTTON_UP:
|
|
|
|
if(dircursor) {
|
2002-05-05 10:45:50 +00:00
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
|
|
|
|
dircursor--;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
2002-04-30 13:37:28 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
2002-05-06 06:17:07 +00:00
|
|
|
if(dircursor+1 < numentries) {
|
2002-05-05 10:45:50 +00:00
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
|
|
|
|
dircursor++;
|
|
|
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
2002-04-30 13:37:28 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-05-04 12:27:18 +00:00
|
|
|
#endif
|
2002-04-30 13:37:28 +00:00
|
|
|
|
2002-04-30 13:16:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|