2004-05-21 20:08:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-03-29 06:16:00 +00:00
|
|
|
* Copyright (C) 2007 Jonathan Gordon
|
2004-05-21 20:08:24 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2007-03-29 06:16:00 +00:00
|
|
|
#include "string.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#include "atoi.h"
|
2007-03-29 06:16:00 +00:00
|
|
|
#include <ctype.h>
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "language.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "filetypes.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "icons.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2007-03-29 06:16:00 +00:00
|
|
|
#include "buffer.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* max filetypes (plugins & icons stored here) */
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-03-29 06:16:00 +00:00
|
|
|
#define MAX_FILETYPES 72
|
2005-06-11 12:37:36 +00:00
|
|
|
#else
|
2006-04-02 11:58:25 +00:00
|
|
|
#define MAX_FILETYPES 48
|
2005-06-11 12:37:36 +00:00
|
|
|
#endif
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* number of bytes for the binary icon */
|
|
|
|
#define ICON_LENGTH 6
|
|
|
|
|
|
|
|
/* mask for dynamic filetype info in attribute */
|
|
|
|
#define FILETYPES_MASK 0xFF00
|
2007-03-29 06:16:00 +00:00
|
|
|
#define ROCK_EXTENSION "rock"
|
|
|
|
|
|
|
|
struct file_type {
|
2007-04-16 09:14:36 +00:00
|
|
|
int icon; /* the icon which shall be used for it, NOICON if unknown */
|
2007-03-29 06:16:00 +00:00
|
|
|
bool viewer; /* true if the rock is in viewers, false if in rocks */
|
|
|
|
unsigned char attr; /* FILETYPES_MASK >> 8 */
|
|
|
|
char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
|
|
|
|
char* extension; /* NULL for none */
|
|
|
|
};
|
2004-05-21 20:08:24 +00:00
|
|
|
static struct file_type filetypes[MAX_FILETYPES];
|
2007-03-29 06:16:00 +00:00
|
|
|
static int filetype_count = 0;
|
|
|
|
static unsigned char heighest_attr = 0;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static char *filetypes_strdup(char* string)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char *buffer = (char*)buffer_alloc(strlen(string)+1);
|
|
|
|
strcpy(buffer, string);
|
|
|
|
return buffer;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
static void read_builtin_types(void);
|
|
|
|
static void read_config(char* config_file);
|
2007-04-16 09:14:36 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
void read_viewer_theme_file(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
int fd;
|
|
|
|
char *ext, *icon;
|
|
|
|
int i;
|
|
|
|
snprintf(buffer, MAX_PATH, "%s/%s.icons", ICON_DIR,
|
|
|
|
global_settings.viewers_icon_file);
|
|
|
|
fd = open(buffer, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
while (read_line(fd, buffer, MAX_PATH) > 0)
|
|
|
|
{
|
|
|
|
if (!settings_parseline(buffer, &ext, &icon))
|
|
|
|
continue;
|
|
|
|
for (i=0; i<filetype_count; i++)
|
|
|
|
{
|
|
|
|
if (filetypes[i].extension && !strcasecmp(ext, filetypes[i].extension))
|
|
|
|
{
|
|
|
|
if (*icon == '*')
|
|
|
|
filetypes[i].icon = atoi(icon+1);
|
|
|
|
else if (*icon == '-')
|
|
|
|
filetypes[i].icon = Icon_NOICON;
|
2007-04-16 12:26:49 +00:00
|
|
|
else if (*icon >= '0' && *icon <= '9')
|
|
|
|
filetypes[i].icon = Icon_Last_Themeable + atoi(icon);
|
2007-04-16 09:14:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
void filetype_init(void)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
/* set the directory item first */
|
|
|
|
filetypes[0].extension = NULL;
|
|
|
|
filetypes[0].plugin = NULL;
|
|
|
|
filetypes[0].attr = 0;
|
2007-04-16 09:14:36 +00:00
|
|
|
filetypes[0].icon = Icon_Folder;
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
filetype_count = 1;
|
|
|
|
read_builtin_types();
|
|
|
|
read_config(VIEWERS_CONFIG);
|
2007-04-16 09:14:36 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
read_viewer_theme_file();
|
|
|
|
#endif
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
/* remove all white spaces from string */
|
|
|
|
static void rm_whitespaces(char* str)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char *s = str;
|
|
|
|
while (*str)
|
2006-03-13 07:33:30 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (!isspace(*str))
|
2006-03-13 07:33:30 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
*s = *str;
|
|
|
|
s++;
|
2006-03-13 07:33:30 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
str++;
|
2006-03-13 07:33:30 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
*s = '\0';
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static void read_builtin_types(void)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
const struct filetype *types;
|
|
|
|
int count, i;
|
|
|
|
tree_get_filetypes(&types, &count);
|
|
|
|
for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
filetypes[filetype_count].extension = types[i].extension;
|
|
|
|
filetypes[filetype_count].plugin = NULL;
|
|
|
|
filetypes[filetype_count].attr = types[i].tree_attr>>8;
|
|
|
|
if (filetypes[filetype_count].attr > heighest_attr)
|
|
|
|
heighest_attr = filetypes[filetype_count].attr;
|
2007-04-16 09:14:36 +00:00
|
|
|
filetypes[filetype_count].icon = types[i].icon;
|
2007-03-29 06:16:00 +00:00
|
|
|
filetype_count++;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static void read_config(char* config_file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char line[64], *s, *e;
|
|
|
|
char extension[8], plugin[32];
|
|
|
|
bool viewer;
|
|
|
|
int fd = open(config_file, O_RDONLY);
|
|
|
|
if (fd < 0)
|
2004-05-21 20:08:24 +00:00
|
|
|
return;
|
2007-03-29 06:16:00 +00:00
|
|
|
/* config file is in the for
|
|
|
|
<extension>,<plugin>,<icon code>
|
|
|
|
ignore line if either of the first two are missing */
|
|
|
|
while (read_line(fd, line, 64) > 0)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (filetype_count >= MAX_FILETYPES)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(HZ, str(LANG_FILETYPES_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
rm_whitespaces(line);
|
|
|
|
/* get the extention */
|
|
|
|
s = line;
|
|
|
|
e = strchr(s, ',');
|
|
|
|
if (!e)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
2007-03-29 06:16:00 +00:00
|
|
|
*e = '\0';
|
|
|
|
strcpy(extension, s);
|
|
|
|
|
|
|
|
/* get the plugin */
|
|
|
|
s = e+1;
|
|
|
|
e = strchr(s, '/');
|
|
|
|
if (!e)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
2007-03-29 06:16:00 +00:00
|
|
|
*e = '\0';
|
|
|
|
if (!strcasecmp("viewers", s))
|
|
|
|
viewer = true;
|
|
|
|
else
|
|
|
|
viewer = false;
|
|
|
|
s = e+1;
|
|
|
|
e = strchr(s, ',');
|
|
|
|
if (!e)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
2007-03-29 06:16:00 +00:00
|
|
|
*e = '\0';
|
|
|
|
strcpy(plugin, s);
|
|
|
|
/* ok, store this plugin/extension, check icon after */
|
|
|
|
filetypes[filetype_count].extension = filetypes_strdup(extension);
|
|
|
|
filetypes[filetype_count].plugin = filetypes_strdup(plugin);
|
|
|
|
filetypes[filetype_count].viewer = viewer;
|
|
|
|
filetypes[filetype_count].attr = heighest_attr +1;
|
2007-04-16 09:14:36 +00:00
|
|
|
filetypes[filetype_count].icon = Icon_Questionmark;
|
2007-03-29 06:16:00 +00:00
|
|
|
heighest_attr++;
|
|
|
|
/* get the icon */
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
s = e+1;
|
2007-04-16 09:14:36 +00:00
|
|
|
if (*s == '*')
|
|
|
|
filetypes[filetype_count].icon = atoi(s+1);
|
|
|
|
else if (*s == '-')
|
|
|
|
filetypes[filetype_count].icon = Icon_NOICON;
|
2007-04-16 12:26:49 +00:00
|
|
|
else if (*s >= '0' && *s <= '9')
|
|
|
|
filetypes[filetype_count].icon = Icon_Last_Themeable + atoi(s);
|
2007-03-29 06:16:00 +00:00
|
|
|
#else
|
2007-04-16 09:14:36 +00:00
|
|
|
filetypes[filetype_count].icon = Icon_NOICON;
|
2007-03-29 06:16:00 +00:00
|
|
|
#endif
|
|
|
|
filetype_count++;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_get_attr(const char* file)
|
2005-03-07 20:40:36 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char *extension = strrchr(file, '.');
|
2005-03-07 20:40:36 +00:00
|
|
|
int i;
|
2007-03-29 06:16:00 +00:00
|
|
|
if (!extension)
|
2005-03-07 20:40:36 +00:00
|
|
|
return 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
extension++;
|
|
|
|
for (i=0; i<filetype_count; i++)
|
2005-03-07 20:40:36 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (filetypes[i].extension &&
|
|
|
|
!strcasecmp(extension, filetypes[i].extension))
|
|
|
|
return (filetypes[i].attr<<8)&TREE_ATTR_MASK;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-03-07 20:40:36 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static int find_attr(int attr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* skip the directory item */
|
|
|
|
if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY)
|
2005-03-07 20:40:36 +00:00
|
|
|
return 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
for (i=1; i<filetype_count; i++)
|
|
|
|
{
|
|
|
|
if ((attr>>8) == filetypes[i].attr)
|
|
|
|
return i;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
return -1;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
int filetype_get_icon(int attr)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
int index = find_attr(attr);
|
|
|
|
if (index < 0)
|
2007-04-16 09:14:36 +00:00
|
|
|
return Icon_NOICON;
|
|
|
|
return filetypes[index].icon;
|
2007-03-29 06:16:00 +00:00
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
char* filetype_get_plugin(const struct entry* file)
|
|
|
|
{
|
|
|
|
static char plugin_name[MAX_PATH];
|
|
|
|
int index = find_attr(file->attr);
|
|
|
|
if (index < 0)
|
|
|
|
return NULL;
|
2007-04-16 11:10:41 +00:00
|
|
|
if (filetypes[index].plugin == NULL)
|
2007-04-16 11:01:41 +00:00
|
|
|
return NULL;
|
2007-03-29 06:16:00 +00:00
|
|
|
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
|
|
|
|
filetypes[index].viewer? VIEWERS_DIR: PLUGIN_DIR,
|
|
|
|
filetypes[index].plugin, ROCK_EXTENSION);
|
|
|
|
return plugin_name;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
bool filetype_supported(int attr)
|
|
|
|
{
|
|
|
|
return find_attr(attr) >= 0;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_list_viewers(const char* current_file)
|
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
char *strings[MAX_FILETYPES/2];
|
|
|
|
struct menu_callback_with_desc cb_and_desc =
|
|
|
|
{ NULL, ID2P(LANG_ONPLAY_OPEN_WITH), Icon_Plugin };
|
|
|
|
struct menu_item_ex menu;
|
|
|
|
|
|
|
|
for (i=0; i<filetype_count && count < (MAX_FILETYPES/2); i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (filetypes[i].plugin)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
int j;
|
|
|
|
for (j=0;j<count;j++) /* check if the plugin is in the list yet */
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (!strcmp(strings[j], filetypes[i].plugin))
|
2005-03-07 20:40:36 +00:00
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
if (j<count)
|
|
|
|
continue; /* it is so grab the next plugin */
|
|
|
|
strings[count] = filetypes[i].plugin;
|
|
|
|
count++;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
#ifndef HAVE_LCD_BITMAP
|
|
|
|
if (count == 0)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
/* FIX: translation! */
|
|
|
|
gui_syncsplash(HZ*2, (unsigned char *)"No viewers found");
|
|
|
|
return PLUGIN_OK;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-03-29 06:16:00 +00:00
|
|
|
menu.flags = MT_RETURN_ID|MENU_HAS_DESC|MENU_ITEM_COUNT(count);
|
|
|
|
menu.strings = (const char**)strings;
|
|
|
|
menu.callback_and_desc = &cb_and_desc;
|
|
|
|
i = do_menu(&menu, NULL);
|
|
|
|
if (i >= 0)
|
|
|
|
return filetype_load_plugin(strings[i], (void*)current_file);
|
|
|
|
return i;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_load_plugin(const char* plugin, char* file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
int fd;
|
|
|
|
char plugin_name[MAX_PATH];
|
|
|
|
snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s",
|
|
|
|
VIEWERS_DIR, plugin, ROCK_EXTENSION);
|
|
|
|
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
close(fd);
|
|
|
|
return plugin_load(plugin_name,file);
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
else
|
2007-03-29 06:16:00 +00:00
|
|
|
{
|
|
|
|
snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s",
|
|
|
|
PLUGIN_DIR, plugin, ROCK_EXTENSION);
|
|
|
|
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
close(fd);
|
|
|
|
return plugin_load(plugin_name,file);
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
return PLUGIN_ERROR;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|