Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * |
| 8 | * $Id$ |
| 9 | * |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 10 | * Copyright (C) 2007 Jonathan Gordon |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <stdbool.h> |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 26 | #include "string.h" |
| 27 | #include <ctype.h> |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 28 | |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 29 | #include "settings.h" |
| 30 | #include "debug.h" |
| 31 | #include "lang.h" |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 32 | #include "kernel.h" |
| 33 | #include "plugin.h" |
| 34 | #include "filetypes.h" |
| 35 | #include "screens.h" |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 36 | #include "dir.h" |
| 37 | #include "file.h" |
Kevin Ferrare | e991bee | 2005-11-16 15:12:15 +0000 | [diff] [blame] | 38 | #include "splash.h" |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 39 | #include "core_alloc.h" |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 40 | #include "icons.h" |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 41 | #include "logf.h" |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 42 | |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 43 | /* max filetypes (plugins & icons stored here) */ |
| 44 | #if CONFIG_CODEC == SWCODEC |
Yoshihisa Uchida | f2df42e | 2010-05-12 12:41:31 +0000 | [diff] [blame] | 45 | #define MAX_FILETYPES 192 |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 46 | #else |
Yoshihisa Uchida | f2df42e | 2010-05-12 12:41:31 +0000 | [diff] [blame] | 47 | #define MAX_FILETYPES 128 |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 48 | #endif |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 49 | /* max viewer plugins */ |
| 50 | #ifdef HAVE_LCD_BITMAP |
| 51 | #define MAX_VIEWERS 56 |
| 52 | #else |
| 53 | #define MAX_VIEWERS 24 |
| 54 | #endif |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 55 | |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 56 | /* a table for the known file types */ |
Nils Wallménius | 11a667b | 2008-05-24 20:56:19 +0000 | [diff] [blame] | 57 | static const struct filetype inbuilt_filetypes[] = { |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 58 | { "mp3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 59 | { "mp2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 60 | { "mpa", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 61 | #if CONFIG_CODEC == SWCODEC |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 62 | /* Temporary hack to allow playlist creation */ |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 63 | { "mp1", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 64 | { "ogg", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Dave Chapman | 25d4f4b | 2008-10-30 01:17:26 +0000 | [diff] [blame] | 65 | { "oga", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 66 | { "wma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Dave Chapman | 48304ce | 2007-07-03 13:16:49 +0000 | [diff] [blame] | 67 | { "wmv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 68 | { "asf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 69 | { "wav", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 70 | { "flac",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 71 | { "ac3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 72 | { "a52", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 73 | { "mpc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 74 | { "wv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 75 | { "m4a", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 76 | { "m4b", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 77 | { "mp4", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Thom Johansen | c0f7eb9 | 2008-05-21 11:19:58 +0000 | [diff] [blame] | 78 | { "mod", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 79 | { "shn", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 80 | { "aif", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 81 | { "aiff",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 82 | { "spx" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Frederik M J Vestre | 1b8e380 | 2012-07-26 14:38:32 +0200 | [diff] [blame] | 83 | { "opus",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 84 | { "sid", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 85 | { "adx", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 86 | { "nsf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 87 | { "nsfe",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 88 | { "spc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Dave Chapman | 5202742 | 2007-06-05 16:58:29 +0000 | [diff] [blame] | 89 | { "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 90 | { "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Dominik Wenger | 25bb37b | 2008-07-26 15:16:10 +0000 | [diff] [blame] | 91 | { "sap" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Mohamed Tarek | e184ef1 | 2009-07-06 22:40:45 +0000 | [diff] [blame] | 92 | { "rm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 93 | { "ra", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Mohamed Tarek | 320bd1a | 2009-07-27 11:36:26 +0000 | [diff] [blame] | 94 | { "rmvb",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 95 | { "cmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 96 | { "cm3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 97 | { "cmr", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 98 | { "cms", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 99 | { "dmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 100 | { "dlt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 101 | { "mpt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 102 | { "mpd", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 103 | { "rmt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 104 | { "tmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 105 | { "tm8", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 106 | { "tm2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Mohamed Tarek | 23ac6ff | 2010-02-12 03:21:37 +0000 | [diff] [blame] | 107 | { "oma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 108 | { "aa3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Mohamed Tarek | 82f0589 | 2010-02-16 03:34:39 +0000 | [diff] [blame] | 109 | { "at3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Yoshihisa Uchida | 45e009a | 2010-02-24 11:46:29 +0000 | [diff] [blame] | 110 | { "mmf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Yoshihisa Uchida | 4e3c807 | 2010-02-28 07:22:20 +0000 | [diff] [blame] | 111 | { "au", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 112 | { "snd", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Yoshihisa Uchida | 8c5eaa3 | 2010-02-28 08:13:30 +0000 | [diff] [blame] | 113 | { "vox", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Yoshihisa Uchida | 561cb2c | 2010-02-28 08:48:07 +0000 | [diff] [blame] | 114 | { "w64", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Yoshihisa Uchida | 0f5c6d4 | 2010-05-13 12:40:09 +0000 | [diff] [blame] | 115 | { "tta", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Andree Buschmann | acb0917 | 2011-08-07 20:01:04 +0000 | [diff] [blame] | 116 | { "ay", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 117 | { "gbs", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 118 | { "hes", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 119 | { "sgc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 120 | { "vgm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 121 | { "vgz", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
| 122 | { "kss", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Solomon Peachy | 928557b | 2018-12-22 20:01:42 -0500 | [diff] [blame] | 123 | { "aac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 124 | #endif |
| 125 | { "m3u", FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, |
| 126 | { "m3u8",FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, |
| 127 | { "cfg", FILE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG }, |
| 128 | { "wps", FILE_ATTR_WPS, Icon_Wps, VOICE_EXT_WPS }, |
| 129 | #ifdef HAVE_REMOTE_LCD |
| 130 | { "rwps",FILE_ATTR_RWPS, Icon_Wps, VOICE_EXT_RWPS }, |
| 131 | #endif |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 132 | #if CONFIG_TUNER |
| 133 | { "fmr", FILE_ATTR_FMR, Icon_Preset, LANG_FMR }, |
Jonathan Gordon | 1bd072c | 2010-05-12 10:38:00 +0000 | [diff] [blame] | 134 | { "fms", FILE_ATTR_FMS, Icon_Wps, VOICE_EXT_FMS }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 135 | #endif |
| 136 | { "lng", FILE_ATTR_LNG, Icon_Language, LANG_LANGUAGE }, |
| 137 | { "rock",FILE_ATTR_ROCK,Icon_Plugin, VOICE_EXT_ROCK }, |
Maurus Cuelenaere | d789e41 | 2009-10-28 23:31:42 +0000 | [diff] [blame] | 138 | { "lua", FILE_ATTR_LUA, Icon_Plugin, VOICE_EXT_ROCK }, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 139 | #ifdef HAVE_LCD_BITMAP |
| 140 | { "fnt", FILE_ATTR_FONT,Icon_Font, VOICE_EXT_FONT }, |
| 141 | { "kbd", FILE_ATTR_KBD, Icon_Keyboard, VOICE_EXT_KBD }, |
| 142 | #endif |
| 143 | { "bmark",FILE_ATTR_BMARK, Icon_Bookmark, VOICE_EXT_BMARK }, |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 144 | { "cue", FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET }, |
Thomas Martitz | 1016ee4 | 2009-10-19 15:28:15 +0000 | [diff] [blame] | 145 | #ifdef HAVE_LCD_BITMAP |
| 146 | { "sbs", FILE_ATTR_SBS, Icon_Wps, VOICE_EXT_SBS }, |
| 147 | #endif |
| 148 | #ifdef HAVE_REMOTE_LCD |
| 149 | { "rsbs", FILE_ATTR_RSBS, Icon_Wps, VOICE_EXT_RSBS }, |
Jonathan Gordon | 1bd072c | 2010-05-12 10:38:00 +0000 | [diff] [blame] | 150 | #if CONFIG_TUNER |
| 151 | { "rfms", FILE_ATTR_RFMS, Icon_Wps, VOICE_EXT_RFMS }, |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 152 | #endif |
Thomas Martitz | 1016ee4 | 2009-10-19 15:28:15 +0000 | [diff] [blame] | 153 | #endif |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 154 | #ifdef BOOTFILE_EXT |
| 155 | { BOOTFILE_EXT, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ }, |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 156 | #endif |
Dave Chapman | 4fe2ee0 | 2009-10-10 11:46:23 +0000 | [diff] [blame] | 157 | #ifdef BOOTFILE_EXT2 |
| 158 | { BOOTFILE_EXT2, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ }, |
| 159 | #endif |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | void tree_get_filetypes(const struct filetype** types, int* count) |
| 163 | { |
| 164 | *types = inbuilt_filetypes; |
| 165 | *count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes); |
| 166 | } |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 167 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 168 | #define ROCK_EXTENSION "rock" |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 169 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 170 | struct file_type { |
Thomas Martitz | 7b374b4 | 2011-06-20 19:32:48 +0000 | [diff] [blame] | 171 | enum themable_icons icon; /* the icon which shall be used for it, NOICON if unknown */ |
Maurus Cuelenaere | db8d79d | 2009-10-28 23:31:45 +0000 | [diff] [blame] | 172 | unsigned char attr; /* FILE_ATTR_MASK >> 8 */ |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 173 | char* plugin; /* Which plugin to use, NULL if unknown, or builtin */ |
| 174 | char* extension; /* NULL for none */ |
| 175 | }; |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 176 | static struct file_type filetypes[MAX_FILETYPES]; |
| 177 | static int custom_filetype_icons[MAX_FILETYPES]; |
Jonathan Gordon | a9c1df4 | 2007-04-16 14:33:29 +0000 | [diff] [blame] | 178 | static bool custom_icons_loaded = false; |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 179 | #ifdef HAVE_LCD_COLOR |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 180 | static int custom_colors[MAX_FILETYPES]; |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 181 | #endif |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 182 | struct filetype_unknown { |
Jonathan Gordon | 3b6b513 | 2013-01-21 09:07:04 +1100 | [diff] [blame] | 183 | int icon; |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 184 | #ifdef HAVE_LCD_COLOR |
| 185 | int color; |
| 186 | #endif |
| 187 | }; |
| 188 | static struct filetype_unknown unknown_file = { |
| 189 | .icon = Icon_NOICON, |
| 190 | #ifdef HAVE_LCD_COLOR |
| 191 | .color = -1, |
| 192 | #endif |
| 193 | }; |
| 194 | |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 195 | /* index array to filetypes used in open with list. */ |
| 196 | static int viewers[MAX_VIEWERS]; |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 197 | static int filetype_count = 0; |
Nils Wallménius | 11a667b | 2008-05-24 20:56:19 +0000 | [diff] [blame] | 198 | static unsigned char highest_attr = 0; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 199 | static int viewer_count = 0; |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 200 | |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 201 | static int strdup_handle, strdup_bufsize, strdup_cur_idx; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 202 | static int move_callback(int handle, void* current, void* new) |
| 203 | { |
| 204 | /*could compare to strdup_handle, but ops is only used once */ |
| 205 | (void)handle; |
| 206 | size_t diff = new - current; |
| 207 | #define FIX_PTR(x) \ |
Jonathan Gordon | ccaf55a | 2011-09-21 13:32:37 +0000 | [diff] [blame] | 208 | { if ((void*)x >= current && (void*)x < (current+strdup_bufsize)) x+= diff; } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 209 | for(int i = 0; i < filetype_count; i++) |
| 210 | { |
| 211 | FIX_PTR(filetypes[i].extension); |
| 212 | FIX_PTR(filetypes[i].plugin); |
| 213 | } |
| 214 | return BUFLIB_CB_OK; |
| 215 | } |
| 216 | |
| 217 | static struct buflib_callbacks ops = { |
| 218 | .move_callback = move_callback, |
| 219 | .shrink_callback = NULL, |
| 220 | }; |
| 221 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 222 | static char *filetypes_strdup(char* string) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 223 | { |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 224 | char *buffer = core_get_data(strdup_handle) + strdup_cur_idx; |
| 225 | strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 226 | return buffer; |
| 227 | } |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 228 | |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 229 | static char *filetypes_store_plugin(char *plugin, int n) |
| 230 | { |
| 231 | int i; |
| 232 | /* if the plugin is in the list already, use it. */ |
| 233 | for (i=0; i<viewer_count; i++) |
| 234 | { |
| 235 | if (!strcmp(filetypes[viewers[i]].plugin, plugin)) |
| 236 | return filetypes[viewers[i]].plugin; |
| 237 | } |
| 238 | /* otherwise, allocate buffer */ |
| 239 | if (viewer_count < MAX_VIEWERS) |
| 240 | viewers[viewer_count++] = n; |
| 241 | return filetypes_strdup(plugin); |
| 242 | } |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 243 | |
| 244 | static int find_extension(const char* extension) |
| 245 | { |
| 246 | int i; |
| 247 | if (!extension) |
| 248 | return -1; |
| 249 | for (i=1; i<filetype_count; i++) |
| 250 | { |
| 251 | if (filetypes[i].extension && |
| 252 | !strcasecmp(extension, filetypes[i].extension)) |
| 253 | return i; |
| 254 | } |
| 255 | return -1; |
| 256 | } |
| 257 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 258 | static void read_builtin_types(void); |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 259 | static void read_config(int fd); |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 260 | #ifdef HAVE_LCD_COLOR |
| 261 | /* Colors file format is similar to icons: |
| 262 | * ext:hex_color |
| 263 | * load a colors file from a theme with: |
Paul Louden | f8b5913 | 2007-06-19 04:21:06 +0000 | [diff] [blame] | 264 | * filetype colours: filename.colours */ |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 265 | void read_color_theme_file(void) { |
Thomas Martitz | 2c24160 | 2010-12-06 22:26:31 +0000 | [diff] [blame] | 266 | char buffer[MAX_PATH]; |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 267 | int fd; |
| 268 | char *ext, *color; |
| 269 | int i; |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 270 | for (i = 0; i < MAX_FILETYPES; i++) { |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 271 | custom_colors[i] = -1; |
| 272 | } |
Thomas Martitz | 2c24160 | 2010-12-06 22:26:31 +0000 | [diff] [blame] | 273 | snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours", |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 274 | global_settings.colors_file); |
| 275 | fd = open(buffer, O_RDONLY); |
| 276 | if (fd < 0) |
| 277 | return; |
| 278 | while (read_line(fd, buffer, MAX_PATH) > 0) |
| 279 | { |
| 280 | if (!settings_parseline(buffer, &ext, &color)) |
| 281 | continue; |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 282 | if (!strcasecmp(ext, "folder")) |
| 283 | { |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 284 | hex_to_rgb(color, &custom_colors[0]); |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 285 | continue; |
| 286 | } |
Paul Louden | 5b25a6e | 2007-06-18 22:41:39 +0000 | [diff] [blame] | 287 | if (!strcasecmp(ext, "???")) |
| 288 | { |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 289 | hex_to_rgb(color, &unknown_file.color); |
Paul Louden | 5b25a6e | 2007-06-18 22:41:39 +0000 | [diff] [blame] | 290 | continue; |
| 291 | } |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 292 | i = find_extension(ext); |
| 293 | if (i >= 0) |
| 294 | hex_to_rgb(color, &custom_colors[i]); |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 295 | } |
| 296 | close(fd); |
| 297 | } |
| 298 | #endif |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 299 | #ifdef HAVE_LCD_BITMAP |
| 300 | void read_viewer_theme_file(void) |
| 301 | { |
| 302 | char buffer[MAX_PATH]; |
| 303 | int fd; |
| 304 | char *ext, *icon; |
| 305 | int i; |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 306 | int *icon_dest; |
Jonathan Gordon | 5b5d101 | 2007-04-26 05:30:46 +0000 | [diff] [blame] | 307 | global_status.viewer_icon_count = 0; |
Jonathan Gordon | a9c1df4 | 2007-04-16 14:33:29 +0000 | [diff] [blame] | 308 | custom_icons_loaded = false; |
Jonathan Gordon | fd951ab | 2007-04-16 14:52:47 +0000 | [diff] [blame] | 309 | custom_filetype_icons[0] = Icon_Folder; |
| 310 | for (i=1; i<filetype_count; i++) |
Jonathan Gordon | 27643c6 | 2007-04-17 09:17:23 +0000 | [diff] [blame] | 311 | { |
Jonathan Gordon | 9d3694c | 2007-04-22 08:50:24 +0000 | [diff] [blame] | 312 | custom_filetype_icons[i] = filetypes[i].icon; |
Jonathan Gordon | 27643c6 | 2007-04-17 09:17:23 +0000 | [diff] [blame] | 313 | } |
Jonathan Gordon | a9c1df4 | 2007-04-16 14:33:29 +0000 | [diff] [blame] | 314 | |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 315 | snprintf(buffer, MAX_PATH, "%s/%s.icons", ICON_DIR, |
| 316 | global_settings.viewers_icon_file); |
| 317 | fd = open(buffer, O_RDONLY); |
| 318 | if (fd < 0) |
| 319 | return; |
| 320 | while (read_line(fd, buffer, MAX_PATH) > 0) |
| 321 | { |
| 322 | if (!settings_parseline(buffer, &ext, &icon)) |
| 323 | continue; |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 324 | i = find_extension(ext); |
| 325 | if (i >= 0) |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 326 | icon_dest = &custom_filetype_icons[i]; |
| 327 | else if (!strcmp(ext, "???")) |
| 328 | icon_dest = &unknown_file.icon; |
| 329 | else |
| 330 | icon_dest = NULL; |
| 331 | |
| 332 | if (icon_dest) |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 333 | { |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 334 | if (*icon == '*') |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 335 | *icon_dest = atoi(icon+1); |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 336 | else if (*icon == '-') |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 337 | *icon_dest = Icon_NOICON; |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 338 | else if (*icon >= '0' && *icon <= '9') |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 339 | { |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 340 | int number = atoi(icon); |
| 341 | if (number > global_status.viewer_icon_count) |
| 342 | global_status.viewer_icon_count++; |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 343 | *icon_dest = Icon_Last_Themeable + number; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | close(fd); |
Jonathan Gordon | a9c1df4 | 2007-04-16 14:33:29 +0000 | [diff] [blame] | 348 | custom_icons_loaded = true; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 349 | } |
| 350 | #endif |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 351 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 352 | void filetype_init(void) |
| 353 | { |
| 354 | /* set the directory item first */ |
| 355 | filetypes[0].extension = NULL; |
| 356 | filetypes[0].plugin = NULL; |
| 357 | filetypes[0].attr = 0; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 358 | filetypes[0].icon = Icon_Folder; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 359 | |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 360 | /* estimate bufsize with the filesize, will not be larger */ |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 361 | viewer_count = 0; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 362 | filetype_count = 1; |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 363 | |
| 364 | int fd = open(VIEWERS_CONFIG, O_RDONLY); |
| 365 | if (fd < 0) |
| 366 | return; |
| 367 | |
| 368 | strdup_bufsize = filesize(fd); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 369 | strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); |
Bertrik Sikken | d023bf0 | 2012-06-10 17:15:47 +0200 | [diff] [blame] | 370 | if (strdup_handle <= 0) |
Thomas Jarosch | 96afbb3 | 2011-10-02 20:04:44 +0000 | [diff] [blame] | 371 | { |
| 372 | close(fd); |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 373 | return; |
Thomas Jarosch | 96afbb3 | 2011-10-02 20:04:44 +0000 | [diff] [blame] | 374 | } |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 375 | read_builtin_types(); |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 376 | read_config(fd); |
Thomas Jarosch | 96afbb3 | 2011-10-02 20:04:44 +0000 | [diff] [blame] | 377 | close(fd); |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 378 | #ifdef HAVE_LCD_BITMAP |
| 379 | read_viewer_theme_file(); |
| 380 | #endif |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 381 | #ifdef HAVE_LCD_COLOR |
| 382 | read_color_theme_file(); |
| 383 | #endif |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 384 | core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 387 | /* remove all white spaces from string */ |
| 388 | static void rm_whitespaces(char* str) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 389 | { |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 390 | char *s = str; |
| 391 | while (*str) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 392 | { |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 393 | if (!isspace(*str)) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 394 | { |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 395 | *s = *str; |
| 396 | s++; |
| 397 | } |
| 398 | str++; |
| 399 | } |
| 400 | *s = '\0'; |
| 401 | } |
| 402 | |
| 403 | static void read_builtin_types(void) |
| 404 | { |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 405 | int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes), i; |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 406 | for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 407 | { |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 408 | filetypes[filetype_count].extension = inbuilt_filetypes[i].extension; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 409 | filetypes[filetype_count].plugin = NULL; |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 410 | filetypes[filetype_count].attr = inbuilt_filetypes[i].tree_attr>>8; |
Nils Wallménius | 11a667b | 2008-05-24 20:56:19 +0000 | [diff] [blame] | 411 | if (filetypes[filetype_count].attr > highest_attr) |
| 412 | highest_attr = filetypes[filetype_count].attr; |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 413 | filetypes[filetype_count].icon = inbuilt_filetypes[i].icon; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 414 | filetype_count++; |
| 415 | } |
| 416 | } |
| 417 | |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 418 | static void read_config(int fd) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 419 | { |
| 420 | char line[64], *s, *e; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 421 | char *extension, *plugin; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 422 | /* config file is in the format |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 423 | <extension>,<plugin>,<icon code> |
| 424 | ignore line if either of the first two are missing */ |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 425 | while (read_line(fd, line, sizeof line) > 0) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 426 | { |
Jonathan Gordon | 07a7d47 | 2007-08-12 09:53:41 +0000 | [diff] [blame] | 427 | if (filetype_count >= MAX_FILETYPES) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 428 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 429 | splash(HZ, ID2P(LANG_FILETYPES_FULL)); |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | rm_whitespaces(line); |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 433 | /* get the extension */ |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 434 | s = line; |
| 435 | e = strchr(s, ','); |
| 436 | if (!e) |
| 437 | continue; |
| 438 | *e = '\0'; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 439 | extension = s; |
| 440 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 441 | /* get the plugin */ |
| 442 | s = e+1; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 443 | e = strchr(s, ','); |
| 444 | if (!e) |
| 445 | continue; |
| 446 | *e = '\0'; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 447 | plugin = s; |
| 448 | |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 449 | if (!strcmp("???", extension)) |
| 450 | { |
| 451 | /* get the icon */ |
| 452 | s = e+1; |
| 453 | if (*s == '*') |
| 454 | unknown_file.icon = atoi(s+1); |
| 455 | else if (*s == '-') |
| 456 | unknown_file.icon = Icon_NOICON; |
| 457 | else if (*s >= '0' && *s <= '9') |
| 458 | unknown_file.icon = Icon_Last_Themeable + atoi(s); |
| 459 | continue; |
| 460 | } |
| 461 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 462 | /* ok, store this plugin/extension, check icon after */ |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 463 | struct file_type *file_type = &filetypes[filetype_count]; |
| 464 | file_type->extension = filetypes_strdup(extension); |
| 465 | file_type->plugin = filetypes_store_plugin(plugin, filetype_count); |
| 466 | file_type->attr = highest_attr +1; |
| 467 | file_type->icon = Icon_Questionmark; |
Nils Wallménius | 11a667b | 2008-05-24 20:56:19 +0000 | [diff] [blame] | 468 | highest_attr++; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 469 | /* get the icon */ |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 470 | s = e+1; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 471 | if (*s == '*') |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 472 | file_type->icon = atoi(s+1); |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 473 | else if (*s == '-') |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 474 | file_type->icon = Icon_NOICON; |
Jonathan Gordon | 4a16739 | 2007-04-16 12:26:49 +0000 | [diff] [blame] | 475 | else if (*s >= '0' && *s <= '9') |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 476 | file_type->icon = Icon_Last_Themeable + atoi(s); |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 477 | filetype_count++; |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 478 | } |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 479 | } |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 480 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 481 | int filetype_get_attr(const char* file) |
| 482 | { |
| 483 | char *extension = strrchr(file, '.'); |
| 484 | int i; |
| 485 | if (!extension) |
| 486 | return 0; |
| 487 | extension++; |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 488 | |
| 489 | i = find_extension(extension); |
| 490 | if (i >= 0) |
| 491 | return (filetypes[i].attr<<8)&FILE_ATTR_MASK; |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 495 | static int find_attr(int attr) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 496 | { |
| 497 | int i; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 498 | /* skip the directory item */ |
| 499 | if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY) |
| 500 | return 0; |
| 501 | for (i=1; i<filetype_count; i++) |
| 502 | { |
| 503 | if ((attr>>8) == filetypes[i].attr) |
| 504 | return i; |
| 505 | } |
| 506 | return -1; |
| 507 | } |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 508 | |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 509 | #ifdef HAVE_LCD_COLOR |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 510 | int filetype_get_color(const char * name, int attr) |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 511 | { |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 512 | char *extension; |
| 513 | int i; |
| 514 | if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY) |
| 515 | return custom_colors[0]; |
| 516 | extension = strrchr(name, '.'); |
| 517 | if (!extension) |
Boris Gjenero | 15fa7f8 | 2013-06-05 18:35:09 -0400 | [diff] [blame] | 518 | return unknown_file.color; |
Brandon Low | f8682a0 | 2007-06-17 23:10:01 +0000 | [diff] [blame] | 519 | extension++; |
Teruaki Kawashima | 194bc86 | 2010-11-27 12:57:19 +0000 | [diff] [blame] | 520 | |
| 521 | i = find_extension(extension); |
| 522 | if (i >= 0) |
| 523 | return custom_colors[i]; |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 524 | return unknown_file.color; |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 525 | } |
| 526 | #endif |
| 527 | |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 528 | int filetype_get_icon(int attr) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 529 | { |
| 530 | int index = find_attr(attr); |
| 531 | if (index < 0) |
Jonathan Gordon | 70595a2 | 2013-01-20 22:29:43 +1100 | [diff] [blame] | 532 | return unknown_file.icon; |
Jonathan Gordon | a9c1df4 | 2007-04-16 14:33:29 +0000 | [diff] [blame] | 533 | if (custom_icons_loaded) |
| 534 | return custom_filetype_icons[index]; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 535 | return filetypes[index].icon; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | char* filetype_get_plugin(const struct entry* file) |
| 539 | { |
| 540 | static char plugin_name[MAX_PATH]; |
| 541 | int index = find_attr(file->attr); |
| 542 | if (index < 0) |
| 543 | return NULL; |
Jonathan Gordon | 3124134 | 2007-04-16 11:10:41 +0000 | [diff] [blame] | 544 | if (filetypes[index].plugin == NULL) |
Jonathan Gordon | ccaf24a | 2007-04-16 11:01:41 +0000 | [diff] [blame] | 545 | return NULL; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 546 | snprintf(plugin_name, MAX_PATH, "%s/%s.%s", |
Jonathan Gordon | fda7d72 | 2007-08-06 13:42:52 +0000 | [diff] [blame] | 547 | PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION); |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 548 | return plugin_name; |
| 549 | } |
| 550 | |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 551 | bool filetype_supported(int attr) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 552 | { |
| 553 | return find_attr(attr) >= 0; |
| 554 | } |
| 555 | |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 556 | /**** Open With Screen ****/ |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 557 | struct cb_data { |
Nils Wallménius | 11a667b | 2008-05-24 20:56:19 +0000 | [diff] [blame] | 558 | const char *current_file; |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 559 | }; |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 560 | |
| 561 | static enum themable_icons openwith_get_icon(int selected_item, void * data) |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 562 | { |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 563 | (void)data; |
| 564 | return filetypes[viewers[selected_item]].icon; |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 565 | } |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 566 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 567 | static const char* openwith_get_name(int selected_item, void * data, |
| 568 | char * buffer, size_t buffer_len) |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 569 | { |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 570 | (void)data; (void)buffer; (void)buffer_len; |
| 571 | const char *s = strrchr(filetypes[viewers[selected_item]].plugin, '/'); |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 572 | if (s) |
| 573 | return s+1; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 574 | else return filetypes[viewers[selected_item]].plugin; |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 575 | } |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 576 | |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 577 | static int openwith_get_talk(int selected_item, void * data) |
| 578 | { |
| 579 | (void)data; |
| 580 | char viewer_filename[MAX_FILENAME]; |
| 581 | snprintf(viewer_filename, MAX_FILENAME, "%s.%s", |
| 582 | filetypes[viewers[selected_item]].plugin, ROCK_EXTENSION); |
| 583 | talk_file_or_spell(PLUGIN_DIR, viewer_filename, |
| 584 | NULL, false); |
| 585 | return 0; |
| 586 | } |
| 587 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 588 | static int openwith_action_callback(int action, struct gui_synclist *lists) |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 589 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 590 | struct cb_data *info = (struct cb_data *)lists->data; |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 591 | int i; |
| 592 | if (action == ACTION_STD_OK) |
| 593 | { |
| 594 | char plugin[MAX_PATH]; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 595 | i = viewers[gui_synclist_get_sel_pos(lists)]; |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 596 | snprintf(plugin, MAX_PATH, "%s/%s.%s", |
| 597 | PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION); |
| 598 | plugin_load(plugin, info->current_file); |
| 599 | return ACTION_STD_CANCEL; |
| 600 | } |
| 601 | return action; |
| 602 | } |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 603 | |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 604 | int filetype_list_viewers(const char* current_file) |
| 605 | { |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 606 | struct simplelist_info info; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 607 | struct cb_data data = { current_file }; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 608 | #ifndef HAVE_LCD_BITMAP |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 609 | if (viewer_count == 0) |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 610 | { |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 611 | splash(HZ*2, ID2P(LANG_NO_VIEWERS)); |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 612 | return PLUGIN_OK; |
| 613 | } |
| 614 | #endif |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 615 | simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, &data); |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 616 | info.action_callback = openwith_action_callback; |
| 617 | info.get_name = openwith_get_name; |
Jonathan Gordon | e425371 | 2009-12-16 08:36:46 +0000 | [diff] [blame] | 618 | info.get_icon = global_settings.show_icons?openwith_get_icon:NULL; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 619 | info.get_talk = openwith_get_talk; |
Jonathan Gordon | 5ca8abf | 2007-10-21 00:11:47 +0000 | [diff] [blame] | 620 | return simplelist_show_list(&info); |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Nils Wallménius | a0377bd | 2011-12-05 19:23:46 +0000 | [diff] [blame] | 623 | int filetype_load_plugin(const char* plugin, const char* file) |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 624 | { |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 625 | int i; |
Jonathan Gordon | 21165a3 | 2007-03-29 06:16:00 +0000 | [diff] [blame] | 626 | char plugin_name[MAX_PATH]; |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 627 | char *s; |
Teruaki Kawashima | 7d3f8c0 | 2010-11-09 14:35:19 +0000 | [diff] [blame] | 628 | |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 629 | for (i=0;i<filetype_count;i++) |
Linus Nielsen Feltzing | 25efd33 | 2006-03-13 07:33:30 +0000 | [diff] [blame] | 630 | { |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 631 | if (filetypes[i].plugin) |
Linus Nielsen Feltzing | 25efd33 | 2006-03-13 07:33:30 +0000 | [diff] [blame] | 632 | { |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 633 | s = strrchr(filetypes[i].plugin, '/'); |
| 634 | if (s) |
| 635 | { |
| 636 | if (!strcmp(s+1, plugin)) |
| 637 | break; |
| 638 | } |
| 639 | else if (!strcmp(filetypes[i].plugin, plugin)) |
| 640 | break; |
Linus Nielsen Feltzing | 25efd33 | 2006-03-13 07:33:30 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
Jonathan Gordon | 7316032 | 2007-08-07 07:55:18 +0000 | [diff] [blame] | 643 | if (i >= filetype_count) |
| 644 | return PLUGIN_ERROR; |
| 645 | snprintf(plugin_name, MAX_PATH, "%s/%s.%s", |
| 646 | PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION); |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 647 | return plugin_load(plugin_name, file); |
Björn Stenberg | fb00c21 | 2004-05-21 20:08:24 +0000 | [diff] [blame] | 648 | } |