2006-11-30 22:29:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Peter D'Hoye
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-11-30 22:29:48 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
PLUGIN_HEADER
|
|
|
|
|
|
|
|
bool its_a_dir = false;
|
|
|
|
|
|
|
|
char str_filename[MAX_PATH];
|
|
|
|
char str_dirname[MAX_PATH];
|
|
|
|
char str_size[64];
|
|
|
|
char str_dircount[64];
|
|
|
|
char str_filecount[64];
|
|
|
|
char str_date[64];
|
|
|
|
char str_time[64];
|
2007-08-14 12:28:19 +00:00
|
|
|
|
2007-08-14 11:56:15 +00:00
|
|
|
char str_title[MAX_PATH];
|
|
|
|
char str_artist[MAX_PATH];
|
|
|
|
char str_album[MAX_PATH];
|
2009-02-21 22:22:05 +00:00
|
|
|
char str_duration[32];
|
2007-08-14 11:56:15 +00:00
|
|
|
|
|
|
|
int num_properties;
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
static char* filesize2string(long long size, char* pstr, int len)
|
|
|
|
{
|
|
|
|
/* margin set at 10K boundary: 10239 B +1 => 10 KB
|
|
|
|
routine below is 200 bytes smaller than cascaded if/else :)
|
|
|
|
not using build-in function because of huge values (long long) */
|
|
|
|
const char* kgb[4] = { "B", "KB", "MB", "GB" };
|
|
|
|
int i = 0;
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
if((size < 10240) || (i > 2))
|
|
|
|
{
|
|
|
|
/* depends on the order in the above array */
|
|
|
|
rb->snprintf(pstr, len, "%ld %s", (long)size, kgb[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size >>= 10; /* div by 1024 */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return pstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool file_properties(char* selected_file)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
char tstr[MAX_PATH];
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
2007-08-14 13:19:22 +00:00
|
|
|
struct mp3entry id3;
|
2007-07-20 17:06:55 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
char* ptr = rb->strrchr(selected_file, '/') + 1;
|
|
|
|
int dirlen = (ptr - selected_file);
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(tstr, selected_file, dirlen + 1);
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
dir = rb->opendir(tstr);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while(0 != (entry = rb->readdir(dir)))
|
|
|
|
{
|
|
|
|
if(!rb->strcmp(entry->d_name, selected_file+dirlen))
|
|
|
|
{
|
|
|
|
rb->snprintf(str_dirname, sizeof str_dirname, "Path: %s",
|
|
|
|
tstr);
|
|
|
|
rb->snprintf(str_filename, sizeof str_filename, "Name: %s",
|
|
|
|
selected_file+dirlen);
|
|
|
|
rb->snprintf(str_size, sizeof str_size, "Size: %s",
|
|
|
|
filesize2string(entry->size, tstr, sizeof tstr));
|
|
|
|
rb->snprintf(str_date, sizeof str_date, "Date: %04d/%02d/%02d",
|
|
|
|
((entry->wrtdate >> 9 ) & 0x7F) + 1980, /* year */
|
|
|
|
((entry->wrtdate >> 5 ) & 0x0F), /* month */
|
|
|
|
((entry->wrtdate ) & 0x1F)); /* day */
|
|
|
|
rb->snprintf(str_time, sizeof str_time, "Time: %02d:%02d",
|
|
|
|
((entry->wrttime >> 11) & 0x1F), /* hour */
|
|
|
|
((entry->wrttime >> 5 ) & 0x3F)); /* minutes */
|
2007-08-14 11:56:15 +00:00
|
|
|
|
|
|
|
num_properties = 5;
|
|
|
|
|
2007-08-14 12:28:19 +00:00
|
|
|
#if (CONFIG_CODEC == SWCODEC)
|
2007-08-14 12:44:50 +00:00
|
|
|
int fd = rb->open(selected_file, O_RDONLY);
|
2007-08-14 13:19:22 +00:00
|
|
|
if (fd >= 0 &&
|
2007-09-19 10:40:55 +00:00
|
|
|
rb->get_metadata(&id3, fd, selected_file))
|
2007-08-14 13:19:22 +00:00
|
|
|
#else
|
2007-09-19 10:40:55 +00:00
|
|
|
if (!rb->mp3info(&id3, selected_file))
|
2007-08-14 13:19:22 +00:00
|
|
|
#endif
|
2007-08-14 11:56:15 +00:00
|
|
|
{
|
2009-02-21 22:22:05 +00:00
|
|
|
long dur = id3.length / 1000; /* seconds */
|
2007-08-14 13:19:22 +00:00
|
|
|
rb->snprintf(str_artist, sizeof str_artist,
|
|
|
|
"Artist: %s", id3.artist ? id3.artist : "");
|
|
|
|
rb->snprintf(str_title, sizeof str_title,
|
|
|
|
"Title: %s", id3.title ? id3.title : "");
|
|
|
|
rb->snprintf(str_album, sizeof str_album,
|
|
|
|
"Album: %s", id3.album ? id3.album : "");
|
|
|
|
num_properties += 3;
|
2009-02-21 22:22:05 +00:00
|
|
|
|
|
|
|
if (dur > 0)
|
|
|
|
{
|
|
|
|
if (dur < 3600)
|
|
|
|
rb->snprintf(str_duration, sizeof str_duration,
|
|
|
|
"Duration: %d:%02d", (int)(dur / 60),
|
|
|
|
(int)(dur % 60));
|
|
|
|
else
|
|
|
|
rb->snprintf(str_duration, sizeof str_duration,
|
|
|
|
"Duration: %d:%02d:%02d",
|
|
|
|
(int)(dur / 3600),
|
|
|
|
(int)(dur % 3600 / 60),
|
|
|
|
(int)(dur % 60));
|
|
|
|
num_properties++;
|
|
|
|
}
|
2007-08-14 11:56:15 +00:00
|
|
|
}
|
2007-08-14 13:19:22 +00:00
|
|
|
#if (CONFIG_CODEC == SWCODEC)
|
|
|
|
rb->close(fd);
|
2007-08-14 12:28:19 +00:00
|
|
|
#endif
|
2006-11-30 22:29:48 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char dirname[MAX_PATH];
|
|
|
|
int len;
|
|
|
|
unsigned int dc;
|
|
|
|
unsigned int fc;
|
|
|
|
long long bc;
|
|
|
|
char tstr[64];
|
|
|
|
char tstr2[64];
|
|
|
|
} DPS;
|
|
|
|
|
|
|
|
static bool _dir_properties(DPS* dps)
|
|
|
|
{
|
|
|
|
/* recursively scan directories in search of files
|
|
|
|
and informs the user of the progress */
|
|
|
|
bool result;
|
|
|
|
int dirlen;
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
|
|
|
|
2006-12-13 19:52:08 +00:00
|
|
|
result = true;
|
2006-11-30 22:29:48 +00:00
|
|
|
dirlen = rb->strlen(dps->dirname);
|
|
|
|
dir = rb->opendir(dps->dirname);
|
|
|
|
if (!dir)
|
|
|
|
return false; /* open error */
|
|
|
|
|
|
|
|
/* walk through the directory content */
|
2006-12-13 19:52:08 +00:00
|
|
|
while(result && (0 != (entry = rb->readdir(dir))))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
/* append name to current directory */
|
|
|
|
rb->snprintf(dps->dirname+dirlen, dps->len-dirlen, "/%s",
|
|
|
|
entry->d_name);
|
|
|
|
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY)
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
2006-11-30 22:29:48 +00:00
|
|
|
if (!rb->strcmp((char *)entry->d_name, ".") ||
|
|
|
|
!rb->strcmp((char *)entry->d_name, ".."))
|
|
|
|
continue; /* skip these */
|
|
|
|
|
|
|
|
dps->dc++; /* new directory */
|
|
|
|
rb->lcd_clear_display();
|
2006-11-30 23:00:17 +00:00
|
|
|
rb->lcd_puts(0,0,"SCANNING...");
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->lcd_puts(0,1,dps->dirname);
|
|
|
|
rb->lcd_puts(0,2,entry->d_name);
|
|
|
|
rb->snprintf(dps->tstr, 64, "Directories: %d", dps->dc);
|
|
|
|
rb->lcd_puts(0,3,dps->tstr);
|
|
|
|
rb->snprintf(dps->tstr, 64, "Files: %d", dps->fc);
|
|
|
|
rb->lcd_puts(0,4,dps->tstr);
|
|
|
|
rb->snprintf(dps->tstr, 64, "Size: %s",
|
|
|
|
filesize2string(dps->bc, dps->tstr2, 64));
|
|
|
|
rb->lcd_puts(0,5,dps->tstr);
|
|
|
|
rb->lcd_update();
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
/* recursion */
|
|
|
|
result = _dir_properties(dps);
|
|
|
|
}
|
|
|
|
else
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
2006-11-30 22:29:48 +00:00
|
|
|
dps->fc++; /* new file */
|
|
|
|
dps->bc += entry->size;
|
|
|
|
}
|
2006-12-13 19:52:08 +00:00
|
|
|
if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
|
|
|
|
result = false;
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dir_properties(char* selected_file)
|
|
|
|
{
|
|
|
|
DPS dps;
|
|
|
|
char tstr[64];
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
|
2006-11-30 22:29:48 +00:00
|
|
|
dps.len = MAX_PATH;
|
|
|
|
dps.dc = 0;
|
|
|
|
dps.fc = 0;
|
|
|
|
dps.bc = 0;
|
2006-12-13 19:52:08 +00:00
|
|
|
if(false == _dir_properties(&dps))
|
|
|
|
return false;
|
2006-11-30 22:29:48 +00:00
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(str_dirname, selected_file, MAX_PATH);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc);
|
|
|
|
rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc);
|
|
|
|
rb->snprintf(str_size, sizeof str_size, "Size: %s",
|
|
|
|
filesize2string(dps.bc, tstr, sizeof tstr));
|
2007-08-14 11:56:15 +00:00
|
|
|
num_properties = 4;
|
2006-11-30 22:29:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char * get_props(int selected_item, void* data,
|
|
|
|
char *buffer, size_t buffer_len)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
switch(selected_item)
|
|
|
|
{
|
|
|
|
case 0:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, str_dirname, buffer_len);
|
2006-11-30 22:29:48 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? str_dircount : str_filename,
|
2008-04-09 15:25:17 +00:00
|
|
|
buffer_len);
|
2006-11-30 22:29:48 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? str_filecount : str_size, buffer_len);
|
2006-11-30 22:29:48 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? str_size : str_date, buffer_len);
|
2006-11-30 22:29:48 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? "" : str_time, buffer_len);
|
2006-11-30 22:29:48 +00:00
|
|
|
break;
|
2007-08-14 11:56:15 +00:00
|
|
|
case 5:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? "" : str_artist, buffer_len);
|
2007-08-14 11:56:15 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? "" : str_title, buffer_len);
|
2007-08-14 11:56:15 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? "" : str_album, buffer_len);
|
2007-08-14 11:56:15 +00:00
|
|
|
break;
|
2009-02-21 22:22:05 +00:00
|
|
|
case 8:
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
|
2009-02-21 22:22:05 +00:00
|
|
|
break;
|
2006-11-30 22:29:48 +00:00
|
|
|
default:
|
2009-08-20 16:47:44 +00:00
|
|
|
return "ERROR";
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
struct gui_synclist properties_lists;
|
2009-12-21 13:32:43 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int i;
|
|
|
|
#endif
|
2006-11-30 22:29:48 +00:00
|
|
|
int button;
|
2009-12-21 13:32:43 +00:00
|
|
|
bool quit = false, usb = false;
|
2008-05-13 09:57:56 +00:00
|
|
|
char file[MAX_PATH];
|
2009-07-29 13:56:23 +00:00
|
|
|
if(!parameter) return PLUGIN_ERROR;
|
2008-05-13 09:57:56 +00:00
|
|
|
rb->strcpy(file, (const char *) parameter);
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
/* determine if it's a file or a directory */
|
|
|
|
bool found = false;
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
2008-05-13 09:57:56 +00:00
|
|
|
char* ptr = rb->strrchr(file, '/') + 1;
|
|
|
|
int dirlen = (ptr - file);
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(str_dirname, file, dirlen + 1);
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
dir = rb->opendir(str_dirname);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while(0 != (entry = rb->readdir(dir)))
|
|
|
|
{
|
|
|
|
if(!rb->strcmp(entry->d_name, file+dirlen))
|
|
|
|
{
|
|
|
|
its_a_dir = entry->attribute & ATTR_DIRECTORY ? true : false;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
/* now we know if it's a file or a dir or maybe something failed */
|
2009-12-21 13:32:43 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
if(!found)
|
|
|
|
{
|
|
|
|
/* weird: we couldn't find the entry. This Should Never Happen (TM) */
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(0, "File/Dir not found: %s", file);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->action_userabort(TIMEOUT_BLOCK);
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-03 23:18:14 +00:00
|
|
|
/* get the info depending on its_a_dir */
|
2008-05-13 09:57:56 +00:00
|
|
|
if(!(its_a_dir ? dir_properties(file) : file_properties(file)))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2007-07-03 23:38:22 +00:00
|
|
|
/* something went wrong (to do: tell user what it was (nesting,...) */
|
2007-07-03 23:45:00 +00:00
|
|
|
rb->splash(0, "Failed to gather information");
|
2007-07-03 23:18:14 +00:00
|
|
|
rb->action_userabort(TIMEOUT_BLOCK);
|
|
|
|
return PLUGIN_OK;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 13:32:43 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
rb->viewportmanager_theme_enable(i, true, NULL);
|
|
|
|
#endif
|
|
|
|
|
2008-03-26 03:35:24 +00:00
|
|
|
rb->gui_synclist_init(&properties_lists, &get_props, file, false, 1, NULL);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->gui_synclist_set_title(&properties_lists, its_a_dir ?
|
|
|
|
"Directory properties" :
|
|
|
|
"File properties", NOICON);
|
|
|
|
rb->gui_synclist_set_icon_callback(&properties_lists, NULL);
|
2007-08-14 11:56:15 +00:00
|
|
|
rb->gui_synclist_set_nb_items(&properties_lists, num_properties);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->gui_synclist_limit_scroll(&properties_lists, true);
|
|
|
|
rb->gui_synclist_select_item(&properties_lists, 0);
|
|
|
|
rb->gui_synclist_draw(&properties_lists);
|
|
|
|
|
|
|
|
while(!quit)
|
|
|
|
{
|
2009-12-21 13:32:43 +00:00
|
|
|
button = rb->get_action(CONTEXT_LIST, HZ);
|
|
|
|
/* HZ so the status bar redraws corectly */
|
2007-09-17 10:08:50 +00:00
|
|
|
if (rb->gui_synclist_do_button(&properties_lists,&button,LIST_WRAP_ON))
|
2006-11-30 22:29:48 +00:00
|
|
|
continue;
|
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
case ACTION_STD_CANCEL:
|
|
|
|
quit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
|
|
|
quit = true;
|
|
|
|
usb = true;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-21 13:32:43 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
rb->viewportmanager_theme_undo(i, false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return usb? PLUGIN_USB_CONNECTED: PLUGIN_OK;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|