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"
|
|
|
|
#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 "dir.h"
|
|
|
|
#include "file.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2007-03-29 06:16:00 +00:00
|
|
|
#include "buffer.h"
|
2007-06-17 21:16:34 +00:00
|
|
|
#include "icons.h"
|
2007-06-17 23:10:01 +00:00
|
|
|
#include "logf.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-08-12 09:53:41 +00:00
|
|
|
/* max filetypes (plugins & icons stored here) */
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
#define MAX_FILETYPES 128
|
|
|
|
#else
|
|
|
|
#define MAX_FILETYPES 48
|
|
|
|
#endif
|
|
|
|
|
2007-04-18 13:03:01 +00:00
|
|
|
/* a table for the know file types */
|
|
|
|
const struct filetype inbuilt_filetypes[] = {
|
|
|
|
{ "mp3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mp2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpa", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-08-12 09:53:41 +00:00
|
|
|
/* Temporary hack to allow playlist creation */
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "mp1", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "ogg", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "wma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-07-03 13:16:49 +00:00
|
|
|
{ "wmv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "asf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "wav", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "flac",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "ac3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "a52", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "wv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "m4a", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "m4b", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mp4", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2008-05-21 11:19:58 +00:00
|
|
|
{ "mod", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "shn", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "aif", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "aiff",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "spx" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "sid", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "adx", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "nsf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "nsfe",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "spc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-06-05 16:58:29 +00:00
|
|
|
{ "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
#endif
|
|
|
|
{ "m3u", FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
|
|
|
|
{ "m3u8",FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
|
|
|
|
{ "cfg", FILE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG },
|
|
|
|
{ "wps", FILE_ATTR_WPS, Icon_Wps, VOICE_EXT_WPS },
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
{ "rwps",FILE_ATTR_RWPS, Icon_Wps, VOICE_EXT_RWPS },
|
|
|
|
#endif
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
{ "bmp", FILE_ATTR_BMP, Icon_Wps, VOICE_EXT_WPS },
|
|
|
|
#endif
|
|
|
|
#if CONFIG_TUNER
|
|
|
|
{ "fmr", FILE_ATTR_FMR, Icon_Preset, LANG_FMR },
|
|
|
|
#endif
|
|
|
|
{ "lng", FILE_ATTR_LNG, Icon_Language, LANG_LANGUAGE },
|
|
|
|
{ "rock",FILE_ATTR_ROCK,Icon_Plugin, VOICE_EXT_ROCK },
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
{ "fnt", FILE_ATTR_FONT,Icon_Font, VOICE_EXT_FONT },
|
|
|
|
{ "kbd", FILE_ATTR_KBD, Icon_Keyboard, VOICE_EXT_KBD },
|
|
|
|
#endif
|
|
|
|
{ "bmark",FILE_ATTR_BMARK, Icon_Bookmark, VOICE_EXT_BMARK },
|
2007-08-05 19:19:39 +00:00
|
|
|
{ "cue", FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET },
|
2007-04-18 13:03:01 +00:00
|
|
|
#ifdef BOOTFILE_EXT
|
|
|
|
{ BOOTFILE_EXT, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ },
|
2007-08-12 09:53:41 +00:00
|
|
|
#endif /* #ifndef SIMULATOR */
|
2007-04-18 13:03:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tree_get_filetypes(const struct filetype** types, int* count)
|
|
|
|
{
|
|
|
|
*types = inbuilt_filetypes;
|
|
|
|
*count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes);
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
unsigned char attr; /* FILETYPES_MASK >> 8 */
|
|
|
|
char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
|
|
|
|
char* extension; /* NULL for none */
|
|
|
|
};
|
2007-08-12 09:53:41 +00:00
|
|
|
static struct file_type filetypes[MAX_FILETYPES];
|
|
|
|
static int custom_filetype_icons[MAX_FILETYPES];
|
2007-04-16 14:33:29 +00:00
|
|
|
static bool custom_icons_loaded = false;
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-08-12 09:53:41 +00:00
|
|
|
static int custom_colors[MAX_FILETYPES+1];
|
2007-06-17 21:16:34 +00:00
|
|
|
#endif
|
2007-08-12 09:53:41 +00:00
|
|
|
static int filetype_count = 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
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-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
/* Colors file format is similar to icons:
|
|
|
|
* ext:hex_color
|
|
|
|
* load a colors file from a theme with:
|
2007-06-19 04:21:06 +00:00
|
|
|
* filetype colours: filename.colours */
|
2007-06-17 21:16:34 +00:00
|
|
|
void read_color_theme_file(void) {
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
int fd;
|
|
|
|
char *ext, *color;
|
|
|
|
int i;
|
2007-08-12 09:53:41 +00:00
|
|
|
for (i = 0; i < MAX_FILETYPES+1; i++) {
|
2007-06-17 21:16:34 +00:00
|
|
|
custom_colors[i] = -1;
|
|
|
|
}
|
2007-06-19 04:21:06 +00:00
|
|
|
snprintf(buffer, MAX_PATH, "%s/%s.colours", THEME_DIR,
|
2007-06-17 21:16:34 +00:00
|
|
|
global_settings.colors_file);
|
|
|
|
fd = open(buffer, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
while (read_line(fd, buffer, MAX_PATH) > 0)
|
|
|
|
{
|
|
|
|
if (!settings_parseline(buffer, &ext, &color))
|
|
|
|
continue;
|
2007-06-17 23:10:01 +00:00
|
|
|
if (!strcasecmp(ext, "folder"))
|
|
|
|
{
|
2008-03-21 13:41:35 +00:00
|
|
|
hex_to_rgb(color, &custom_colors[0]);
|
2007-06-17 23:10:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-06-18 22:41:39 +00:00
|
|
|
if (!strcasecmp(ext, "???"))
|
|
|
|
{
|
2008-03-21 13:41:35 +00:00
|
|
|
hex_to_rgb(color, &custom_colors[MAX_FILETYPES]);
|
2007-06-18 22:41:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-06-17 23:10:01 +00:00
|
|
|
for (i=1; i<filetype_count; i++)
|
2007-06-17 21:16:34 +00:00
|
|
|
{
|
|
|
|
if (filetypes[i].extension &&
|
|
|
|
!strcasecmp(ext, filetypes[i].extension))
|
|
|
|
{
|
2008-03-21 13:41:35 +00:00
|
|
|
hex_to_rgb(color, &custom_colors[i]);
|
2007-06-17 21:16:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
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;
|
2007-04-26 05:30:46 +00:00
|
|
|
global_status.viewer_icon_count = 0;
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_icons_loaded = false;
|
2007-04-16 14:52:47 +00:00
|
|
|
custom_filetype_icons[0] = Icon_Folder;
|
|
|
|
for (i=1; i<filetype_count; i++)
|
2007-04-17 09:17:23 +00:00
|
|
|
{
|
2007-04-22 08:50:24 +00:00
|
|
|
custom_filetype_icons[i] = filetypes[i].icon;
|
2007-04-17 09:17:23 +00:00
|
|
|
}
|
2007-04-16 14:33:29 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
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++)
|
|
|
|
{
|
2007-06-17 21:16:34 +00:00
|
|
|
if (filetypes[i].extension &&
|
|
|
|
!strcasecmp(ext, filetypes[i].extension))
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
|
|
|
if (*icon == '*')
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_filetype_icons[i] = atoi(icon+1);
|
2007-04-16 09:14:36 +00:00
|
|
|
else if (*icon == '-')
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_filetype_icons[i] = Icon_NOICON;
|
2007-04-16 12:26:49 +00:00
|
|
|
else if (*icon >= '0' && *icon <= '9')
|
2007-04-26 05:30:46 +00:00
|
|
|
{
|
|
|
|
int number = atoi(icon);
|
|
|
|
if (number > global_status.viewer_icon_count)
|
|
|
|
global_status.viewer_icon_count++;
|
|
|
|
custom_filetype_icons[i] = Icon_Last_Themeable + number;
|
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_icons_loaded = true;
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
|
|
|
#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
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
read_color_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-04-18 13:03:01 +00:00
|
|
|
int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes), i;
|
2007-08-12 09:53:41 +00:00
|
|
|
for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
filetypes[filetype_count].extension = inbuilt_filetypes[i].extension;
|
2007-03-29 06:16:00 +00:00
|
|
|
filetypes[filetype_count].plugin = NULL;
|
2007-08-12 09:53:41 +00:00
|
|
|
filetypes[filetype_count].attr = inbuilt_filetypes[i].tree_attr>>8;
|
2007-03-29 06:16:00 +00:00
|
|
|
if (filetypes[filetype_count].attr > heighest_attr)
|
|
|
|
heighest_attr = filetypes[filetype_count].attr;
|
2007-08-12 09:53:41 +00:00
|
|
|
filetypes[filetype_count].icon = inbuilt_filetypes[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];
|
|
|
|
int fd = open(config_file, O_RDONLY);
|
|
|
|
if (fd < 0)
|
2004-05-21 20:08:24 +00:00
|
|
|
return;
|
2007-08-12 09:53:41 +00:00
|
|
|
/* config file is in the for
|
2007-03-29 06:16:00 +00:00
|
|
|
<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-08-12 09:53:41 +00:00
|
|
|
if (filetype_count >= MAX_FILETYPES)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(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';
|
2007-08-06 13:42:52 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
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].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 */
|
|
|
|
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
|
|
|
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++;
|
2007-08-12 09:53:41 +00:00
|
|
|
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))
|
2007-04-18 13:03:01 +00:00
|
|
|
return (filetypes[i].attr<<8)&FILE_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-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-06-17 23:10:01 +00:00
|
|
|
int filetype_get_color(const char * name, int attr)
|
2007-06-17 21:16:34 +00:00
|
|
|
{
|
2007-06-17 23:10:01 +00:00
|
|
|
char *extension;
|
|
|
|
int i;
|
|
|
|
if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY)
|
|
|
|
return custom_colors[0];
|
|
|
|
extension = strrchr(name, '.');
|
|
|
|
if (!extension)
|
2007-08-12 09:53:41 +00:00
|
|
|
return custom_colors[MAX_FILETYPES];
|
2007-06-17 23:10:01 +00:00
|
|
|
extension++;
|
2007-08-07 07:55:18 +00:00
|
|
|
|
2007-06-17 23:10:01 +00:00
|
|
|
for (i=1; i<filetype_count; i++)
|
|
|
|
{
|
|
|
|
if (filetypes[i].extension &&
|
|
|
|
!strcasecmp(extension, filetypes[i].extension))
|
|
|
|
return custom_colors[i];
|
|
|
|
}
|
2007-08-12 09:53:41 +00:00
|
|
|
return custom_colors[MAX_FILETYPES];
|
2007-06-17 21:16:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
2007-04-16 14:33:29 +00:00
|
|
|
if (custom_icons_loaded)
|
|
|
|
return custom_filetype_icons[index];
|
2007-04-16 09:14:36 +00:00
|
|
|
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",
|
2007-08-06 13:42:52 +00:00
|
|
|
PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION);
|
2007-03-29 06:16:00 +00:00
|
|
|
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-08-07 07:55:18 +00:00
|
|
|
/**** Open With Screen ****/
|
2007-10-21 00:11:47 +00:00
|
|
|
struct cb_data {
|
|
|
|
int *items;
|
|
|
|
char *current_file;
|
|
|
|
};
|
2008-04-09 15:25:17 +00:00
|
|
|
|
|
|
|
static enum themable_icons openwith_get_icon(int selected_item, void * data)
|
2007-08-07 07:55:18 +00:00
|
|
|
{
|
2007-10-21 00:11:47 +00:00
|
|
|
struct cb_data *info = (struct cb_data *)data;
|
|
|
|
int *items = info->items;
|
2007-08-07 07:55:18 +00:00
|
|
|
return filetypes[items[selected_item]].icon;
|
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
|
|
|
static char * openwith_get_name(int selected_item, void * data,
|
|
|
|
char * buffer, size_t buffer_len)
|
2007-08-07 07:55:18 +00:00
|
|
|
{
|
2008-04-09 15:25:17 +00:00
|
|
|
(void)buffer; (void)buffer_len;
|
2007-10-21 00:11:47 +00:00
|
|
|
struct cb_data *info = (struct cb_data *)data;
|
|
|
|
int *items = info->items;
|
2007-08-07 07:55:18 +00:00
|
|
|
char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
|
|
|
|
if (s)
|
|
|
|
return s+1;
|
|
|
|
else return filetypes[items[selected_item]].plugin;
|
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
|
|
|
static int openwith_action_callback(int action, struct gui_synclist *lists)
|
2007-10-21 00:11:47 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
struct cb_data *info = (struct cb_data *)lists->data;
|
2007-10-21 00:11:47 +00:00
|
|
|
int *items = info->items;
|
|
|
|
int i;
|
|
|
|
if (action == ACTION_STD_OK)
|
|
|
|
{
|
|
|
|
char plugin[MAX_PATH];
|
|
|
|
i = items[gui_synclist_get_sel_pos(lists)];
|
|
|
|
snprintf(plugin, MAX_PATH, "%s/%s.%s",
|
|
|
|
PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
|
|
|
|
plugin_load(plugin, info->current_file);
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_list_viewers(const char* current_file)
|
|
|
|
{
|
2007-10-21 00:11:47 +00:00
|
|
|
int i, count = 0;
|
2007-08-12 09:53:41 +00:00
|
|
|
int items[MAX_FILETYPES];
|
2007-10-21 00:11:47 +00:00
|
|
|
struct simplelist_info info;
|
|
|
|
struct cb_data data = { items, (char*)current_file };
|
2007-08-12 09:53:41 +00:00
|
|
|
for (i=0; i<filetype_count && count < MAX_FILETYPES; 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-08-08 10:02:00 +00:00
|
|
|
if (filetypes[i].plugin &&
|
|
|
|
!strcmp(filetypes[i].plugin,filetypes[items[j]].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 */
|
2007-08-07 07:55:18 +00:00
|
|
|
items[count++] = i;
|
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-10-21 06:42:52 +00:00
|
|
|
simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), count, &data);
|
2007-10-21 00:11:47 +00:00
|
|
|
info.action_callback = openwith_action_callback;
|
|
|
|
info.get_name = openwith_get_name;
|
|
|
|
info.get_icon = openwith_get_icon;
|
|
|
|
return simplelist_show_list(&info);
|
2007-03-29 06:16:00 +00:00
|
|
|
}
|
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-08-07 07:55:18 +00:00
|
|
|
int i;
|
2007-03-29 06:16:00 +00:00
|
|
|
char plugin_name[MAX_PATH];
|
2007-08-07 07:55:18 +00:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (i=0;i<filetype_count;i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-07 07:55:18 +00:00
|
|
|
if (filetypes[i].plugin)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-07 07:55:18 +00:00
|
|
|
s = strrchr(filetypes[i].plugin, '/');
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
if (!strcmp(s+1, plugin))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!strcmp(filetypes[i].plugin, plugin))
|
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-07 07:55:18 +00:00
|
|
|
if (i >= filetype_count)
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
|
|
|
|
PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
|
2008-05-12 17:52:50 +00:00
|
|
|
return plugin_load(plugin_name, file);
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|