blob: 2570b46460bf024937d0ca0c71185d7f7cf6af91 [file] [log] [blame]
Jonathan Gordonf331d192011-11-28 12:41:15 +00001/***************************************************************************
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00002 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000010 * Copyright (C) 2005 by Björn Stenberg
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000011 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Stenberg8a5de5f2005-01-17 11:39:46 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdlib.h>
22#include <file.h>
23#include <dir.h>
24#include <string.h>
25#include <kernel.h>
26#include <lcd.h>
27#include <debug.h>
28#include <font.h>
Jean-Philippe Bernardy00cf0da2005-02-15 15:30:19 +000029#include <limits.h>
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000030#include "bookmark.h"
31#include "tree.h"
Thomas Martitzbaa070c2011-08-30 14:01:45 +000032#include "core_alloc.h"
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000033#include "settings.h"
34#include "filetypes.h"
35#include "talk.h"
36#include "playlist.h"
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000037#include "lang.h"
38#include "language.h"
39#include "screens.h"
40#include "plugin.h"
41#include "rolo.h"
Kevin Ferraree991bee2005-11-16 15:12:15 +000042#include "splash.h"
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +000043#include "cuesheet.h"
Bertrik Sikkena5d30292008-04-28 10:22:05 +000044#include "filetree.h"
Nils Wallméniusdabcb812008-05-01 10:13:12 +000045#include "misc.h"
Thomas Martitzd13f1a42009-03-01 17:55:59 +000046#include "strnatcmp.h"
Frank Dischner75c3d0b2006-03-29 16:21:42 +000047#ifdef HAVE_LCD_BITMAP
48#include "keyboard.h"
49#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000050
Jonathan Gordon8ff3a652007-02-18 02:04:47 +000051#if CONFIG_TUNER
Hristo Kovachev009853f2006-04-02 12:23:08 +000052#include "radio.h"
53#endif
Thomas Martitz3b75c862009-08-03 15:06:30 +000054#include "wps.h"
Peter D'Hoye93b899d2006-05-21 11:00:02 +000055
Nils Wallménius48b52ae2008-10-08 16:32:01 +000056static int compare_sort_dir; /* qsort key for sorting directories */
57
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000058int ft_build_playlist(struct tree_context* c, int start_index)
59{
60 int i;
61 int start=start_index;
62
Thomas Martitzbaa070c2011-08-30 14:01:45 +000063 tree_lock_cache(c);
64 struct entry *entries = tree_get_entries(c);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000065
66 for(i = 0;i < c->filesindir;i++)
67 {
Thomas Martitz98096972011-08-03 09:49:25 +000068 if((entries[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000069 {
Thomas Martitz98096972011-08-03 09:49:25 +000070 if (playlist_add(entries[i].name) < 0)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000071 break;
72 }
73 else
74 {
75 /* Adjust the start index when se skip non-MP3 entries */
76 if(i < start)
77 start_index--;
78 }
79 }
80
Thomas Martitzbaa070c2011-08-30 14:01:45 +000081 tree_unlock_cache(c);
82
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000083 return start_index;
84}
85
Magnus Holmgrenfabdd382007-10-30 17:38:21 +000086/* Start playback of a playlist, checking for bookmark autoload, modified
87 * playlists, etc., as required. Returns false if playback wasn't started,
88 * or started via bookmark autoload, true otherwise.
89 *
90 * Pointers to both the full pathname and the separated parts needed to
91 * avoid allocating yet another path buffer on the stack (and save some
92 * code; the caller typically needs to create the full pathname anyway)...
93 */
94bool ft_play_playlist(char* pathname, char* dirname, char* filename)
95{
Jonathan Gordonddc21762008-08-19 11:55:30 +000096 if (global_settings.party_mode && audio_status())
Magnus Holmgrenfabdd382007-10-30 17:38:21 +000097 {
Nils Wallménius01729e72008-08-15 08:27:39 +000098 splash(HZ, ID2P(LANG_PARTY_MODE));
Magnus Holmgrenfabdd382007-10-30 17:38:21 +000099 return false;
100 }
101
102 if (bookmark_autoload(pathname))
103 {
104 return false;
105 }
106
Nils Wallménius01729e72008-08-15 08:27:39 +0000107 splash(0, ID2P(LANG_WAIT));
Magnus Holmgrenfabdd382007-10-30 17:38:21 +0000108
109 /* about to create a new current playlist...
110 allow user to cancel the operation */
Nils Wallméniusdabcb812008-05-01 10:13:12 +0000111 if (!warn_on_pl_erase())
112 return false;
Magnus Holmgrenfabdd382007-10-30 17:38:21 +0000113
114 if (playlist_create(dirname, filename) != -1)
115 {
116 if (global_settings.playlist_shuffle)
117 {
118 playlist_shuffle(current_tick, -1);
119 }
120
Michael Sevakis31b71222013-07-14 07:59:39 -0400121 playlist_start(0, 0, 0);
Magnus Holmgrenfabdd382007-10-30 17:38:21 +0000122 return true;
123 }
124
125 return false;
126}
127
Thomas Martitz98096972011-08-03 09:49:25 +0000128/* walk a directory and check all entries if a .talk file exists */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000129static void check_file_thumbnails(struct tree_context* c)
130{
131 int i;
Kevin Ferrare011a3252007-07-20 17:06:55 +0000132 struct dirent *entry;
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000133 struct entry* entries;
Kevin Ferrare011a3252007-07-20 17:06:55 +0000134 DIR *dir;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000135
Kevin Ferrare011a3252007-07-20 17:06:55 +0000136 dir = opendir(c->currdir);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000137 if(!dir)
138 return;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000139 /* mark all files as non talking, except the .talk ones */
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000140 tree_lock_cache(c);
William Wilgus3f110da2018-12-13 10:39:49 -0600141 entries = tree_get_entries(c);
142
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000143 for (i=0; i < c->filesindir; i++)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000144 {
Thomas Martitz98096972011-08-03 09:49:25 +0000145 if (entries[i].attr & ATTR_DIRECTORY)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000146 continue; /* we're not touching directories */
147
148 if (strcasecmp(file_thumbnail_ext,
Thomas Martitz98096972011-08-03 09:49:25 +0000149 &entries[i].name[strlen(entries[i].name)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000150 - strlen(file_thumbnail_ext)]))
151 { /* no .talk file */
Thomas Martitz98096972011-08-03 09:49:25 +0000152 entries[i].attr &= ~FILE_ATTR_THUMBNAIL; /* clear */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000153 }
154 else
155 { /* .talk file, we later let them speak themselves */
Thomas Martitz98096972011-08-03 09:49:25 +0000156 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000157 }
158 }
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000159
Kevin Ferrare011a3252007-07-20 17:06:55 +0000160 while((entry = readdir(dir)) != 0) /* walk directory */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000161 {
162 int ext_pos;
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000163 struct dirinfo info = dir_get_info(dir, entry);
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000164 ext_pos = strlen((char *)entry->d_name) - strlen(file_thumbnail_ext);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000165 if (ext_pos <= 0 /* too short to carry ".talk" */
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000166 || (info.attribute & ATTR_DIRECTORY) /* no file */
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000167 || strcasecmp((char *)&entry->d_name[ext_pos], file_thumbnail_ext))
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000168 { /* or doesn't end with ".talk", no candidate */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000169 continue;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000170 }
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000171
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000172 /* terminate the (disposable) name in dir buffer,
173 this truncates off the ".talk" without needing an extra buffer */
174 entry->d_name[ext_pos] = '\0';
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000175
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000176 /* search corresponding file in dir cache */
177 for (i=0; i < c->filesindir; i++)
178 {
Thomas Martitz98096972011-08-03 09:49:25 +0000179 if (!strcasecmp(entries[i].name, (char *)entry->d_name))
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000180 { /* match */
Thomas Martitz98096972011-08-03 09:49:25 +0000181 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set the flag */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000182 break; /* exit search loop, because we found it */
183 }
184 }
185 }
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000186 tree_unlock_cache(c);
Kevin Ferrare011a3252007-07-20 17:06:55 +0000187 closedir(dir);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000188}
189
190/* support function for qsort() */
191static int compare(const void* p1, const void* p2)
192{
193 struct entry* e1 = (struct entry*)p1;
194 struct entry* e2 = (struct entry*)p2;
195 int criteria;
196
197 if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY)
198 { /* two directories */
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000199 criteria = compare_sort_dir;
Björn Stenbergb2d84b12005-01-17 12:29:27 +0000200
Nils Wallménius685f6bb2007-03-17 00:55:23 +0000201#ifdef HAVE_MULTIVOLUME
Björn Stenbergb2d84b12005-01-17 12:29:27 +0000202 if (e1->attr & ATTR_VOLUME || e2->attr & ATTR_VOLUME)
203 { /* a volume identifier is involved */
204 if (e1->attr & ATTR_VOLUME && e2->attr & ATTR_VOLUME)
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000205 criteria = SORT_ALPHA; /* two volumes: sort alphabetically */
Björn Stenbergb2d84b12005-01-17 12:29:27 +0000206 else /* only one is a volume: volume first */
207 return (e2->attr & ATTR_VOLUME) - (e1->attr & ATTR_VOLUME);
208 }
Nils Wallménius685f6bb2007-03-17 00:55:23 +0000209#endif
210
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000211 }
212 else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY))
213 { /* two files */
214 criteria = global_settings.sort_file;
215 }
216 else /* dir and file, dir goes first */
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000217 return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000218
219 switch(criteria)
220 {
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000221 case SORT_TYPE:
222 case SORT_TYPE_REVERSED:
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000223 {
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000224 int t1 = e1->attr & FILE_ATTR_MASK;
225 int t2 = e2->attr & FILE_ATTR_MASK;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000226
227 if (!t1) /* unknown type */
Jean-Philippe Bernardy87587132005-02-12 12:29:41 +0000228 t1 = INT_MAX; /* gets a high number, to sort after known */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000229 if (!t2) /* unknown type */
Jean-Philippe Bernardy87587132005-02-12 12:29:41 +0000230 t2 = INT_MAX; /* gets a high number, to sort after known */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000231
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000232 if (t1 != t2) /* if different */
233 return (t1 - t2) * (criteria == SORT_TYPE_REVERSED ? -1 : 1);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000234 /* else fall through to alphabetical sorting */
235 }
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000236
237 case SORT_DATE:
238 case SORT_DATE_REVERSED:
239 /* Ignore SORT_TYPE */
240 if (criteria == SORT_DATE || criteria == SORT_DATE_REVERSED)
241 {
242 if (e1->time_write != e2->time_write)
243 return (e1->time_write - e2->time_write)
244 * (criteria == SORT_DATE_REVERSED ? -1 : 1);
245 /* else fall through to alphabetical sorting */
246 }
247
248 case SORT_ALPHA:
249 case SORT_ALPHA_REVERSED:
Thomas Martitzd13f1a42009-03-01 17:55:59 +0000250 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000251 if (global_settings.sort_case)
Thomas Martitzd13f1a42009-03-01 17:55:59 +0000252 {
253 if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER)
254 return strnatcmp(e1->name, e2->name)
255 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
256 else
257 return strncmp(e1->name, e2->name, MAX_PATH)
258 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
259 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000260 else
Thomas Martitzd13f1a42009-03-01 17:55:59 +0000261 {
262 if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER)
263 return strnatcasecmp(e1->name, e2->name)
264 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
265 else
266 return strncasecmp(e1->name, e2->name, MAX_PATH)
267 * (criteria == SORT_ALPHA_REVERSED ? -1 : 1);
268 }
269 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000270
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000271 }
272 return 0; /* never reached */
273}
274
Thomas Martitz98096972011-08-03 09:49:25 +0000275/* load and sort directory into the tree's cache. returns NULL on failure. */
Björn Stenbergcdd79a32005-01-18 22:50:47 +0000276int ft_load(struct tree_context* c, const char* tempdir)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000277{
Magnus Holmgrenc2ff6462011-05-04 18:33:12 +0000278 int files_in_dir = 0;
Björn Stenberga50cc0b2005-01-17 12:56:00 +0000279 int name_buffer_used = 0;
Magnus Holmgrenc2ff6462011-05-04 18:33:12 +0000280 struct dirent *entry;
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000281 bool (*callback_show_item)(char *, int, struct tree_context *) = NULL;
Kevin Ferrare011a3252007-07-20 17:06:55 +0000282 DIR *dir;
Björn Stenbergcdd79a32005-01-18 22:50:47 +0000283
284 if (tempdir)
Kevin Ferrare011a3252007-07-20 17:06:55 +0000285 dir = opendir(tempdir);
Björn Stenbergcdd79a32005-01-18 22:50:47 +0000286 else
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000287 {
Kevin Ferrare011a3252007-07-20 17:06:55 +0000288 dir = opendir(c->currdir);
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000289 callback_show_item = c->browse? c->browse->callback_show_item: NULL;
290 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000291 if(!dir)
292 return -1; /* not a directory */
293
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000294 c->dirsindir = 0;
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000295 c->dirfull = false;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000296
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000297 tree_lock_cache(c);
Magnus Holmgrenc2ff6462011-05-04 18:33:12 +0000298 while ((entry = readdir(dir))) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000299 int len;
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000300 struct dirinfo info;
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000301 struct entry* dptr = tree_get_entry_at(c, files_in_dir);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000302 if (!entry)
303 break;
304
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000305 info = dir_get_info(dir, entry);
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000306 len = strlen((char *)entry->d_name);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000307
308 /* skip directories . and .. */
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000309 if ((info.attribute & ATTR_DIRECTORY) &&
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000310 (((len == 1) && (!strncmp((char *)entry->d_name, ".", 1))) ||
311 ((len == 2) && (!strncmp((char *)entry->d_name, "..", 2))))) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000312 continue;
313 }
314
315 /* Skip FAT volume ID */
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000316 if (info.attribute & ATTR_VOLUME_ID) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000317 continue;
318 }
319
320 /* filter out dotfiles and hidden files */
321 if (*c->dirfilter != SHOW_ALL &&
322 ((entry->d_name[0]=='.') ||
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000323 (info.attribute & ATTR_HIDDEN))) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000324 continue;
325 }
326
Thomas Martitz6eaab4d2010-09-01 21:29:34 +0000327 dptr->attr = info.attribute;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000328
329 /* check for known file types */
Henrik Backeb2473d52005-09-02 15:05:35 +0000330 if ( !(dptr->attr & ATTR_DIRECTORY) )
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000331 dptr->attr |= filetype_get_attr((char *)entry->d_name);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000332
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000333 /* filter out non-visible files */
Jonas Häggqvist280d9cc2005-08-17 17:53:54 +0000334 if ((!(dptr->attr & ATTR_DIRECTORY) && (
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000335 (*c->dirfilter == SHOW_PLAYLIST &&
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000336 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000337 ((*c->dirfilter == SHOW_MUSIC &&
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000338 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) &&
339 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
Jonas Häggqvist280d9cc2005-08-17 17:53:54 +0000340 (*c->dirfilter == SHOW_SUPPORTED && !filetype_supported(dptr->attr)))) ||
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000341 (*c->dirfilter == SHOW_WPS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_WPS) ||
Thomas Martitzde7f2412009-10-19 16:08:43 +0000342#ifdef HAVE_LCD_BITMAP
343 (*c->dirfilter == SHOW_FONT && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FONT) ||
344 (*c->dirfilter == SHOW_SBS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_SBS) ||
Jonathan Gordon1bd072c2010-05-12 10:38:00 +0000345#if CONFIG_TUNER
346 (*c->dirfilter == SHOW_FMS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FMS) ||
347#endif
Thomas Martitzde7f2412009-10-19 16:08:43 +0000348#endif
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000349#ifdef HAVE_REMOTE_LCD
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000350 (*c->dirfilter == SHOW_RWPS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RWPS) ||
Thomas Martitzde7f2412009-10-19 16:08:43 +0000351 (*c->dirfilter == SHOW_RSBS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RSBS) ||
Jonathan Gordon1bd072c2010-05-12 10:38:00 +0000352#if CONFIG_TUNER
353 (*c->dirfilter == SHOW_RFMS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_RFMS) ||
354#endif
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000355#endif
Jonathan Gordon8ff3a652007-02-18 02:04:47 +0000356#if CONFIG_TUNER
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000357 (*c->dirfilter == SHOW_FMR && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_FMR) ||
Hristo Kovachev009853f2006-04-02 12:23:08 +0000358#endif
Teruaki Kawashimae6b4d8f2010-12-15 12:47:30 +0000359 (*c->dirfilter == SHOW_M3U && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) ||
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000360 (*c->dirfilter == SHOW_CFG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_CFG) ||
361 (*c->dirfilter == SHOW_LNG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LNG) ||
362 (*c->dirfilter == SHOW_MOD && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_MOD) ||
Maurus Cuelenaered789e412009-10-28 23:31:42 +0000363 (*c->dirfilter == SHOW_PLUGINS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_ROCK &&
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000364 (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA) ||
365 (callback_show_item && !callback_show_item(entry->d_name, dptr->attr, c)))
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000366 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000367 continue;
368 }
369
Thomas Martitz98096972011-08-03 09:49:25 +0000370 if ((len > c->cache.name_buffer_size - name_buffer_used - 1) ||
371 (files_in_dir >= c->cache.max_entries)) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000372 /* Tell the world that we ran out of buffer space */
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000373 c->dirfull = true;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000374 break;
375 }
Magnus Holmgrenc2ff6462011-05-04 18:33:12 +0000376
377 ++files_in_dir;
378
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000379 dptr->name = core_get_data(c->cache.name_buffer_handle)+name_buffer_used;
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400380 dptr->time_write = info.mtime;
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000381 strcpy(dptr->name, (char *)entry->d_name);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000382 name_buffer_used += len + 1;
383
384 if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000385 c->dirsindir++;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000386 }
Magnus Holmgrenc2ff6462011-05-04 18:33:12 +0000387 c->filesindir = files_in_dir;
388 c->dirlength = files_in_dir;
Kevin Ferrare011a3252007-07-20 17:06:55 +0000389 closedir(dir);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000390
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000391 compare_sort_dir = c->sort_dir;
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000392 qsort(tree_get_entries(c), files_in_dir, sizeof(struct entry), compare);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000393
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000394 /* If thumbnail talking is enabled, make an extra run to mark files with
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000395 associated thumbnails, so we don't do unsuccessful spinups later. */
Steve Bavina1f0a832007-06-07 11:29:45 +0000396 if (global_settings.talk_file_clip)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000397 check_file_thumbnails(c); /* map .talk to ours */
398
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000399 tree_unlock_cache(c);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000400 return 0;
401}
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000402#ifdef HAVE_LCD_BITMAP
403static void ft_load_font(char *file)
404{
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000405 int current_font_id;
406 enum screen_type screen = SCREEN_MAIN;
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000407#if NB_SCREENS > 1
408 MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL,
409 ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN))
410 switch (do_menu(&menu, NULL, NULL, false))
411 {
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000412 case 0: /* main lcd */
413 screen = SCREEN_MAIN;
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000414 set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
415 break;
416 case 1: /* remote */
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000417 screen = SCREEN_REMOTE;
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000418 set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME);
419 break;
420 }
421#else
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000422 set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
423#endif
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000424 splash(0, ID2P(LANG_WAIT));
Jonathan Gordonf19f3ef2011-11-08 10:09:33 +0000425 current_font_id = screens[screen].getuifont();
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000426 if (current_font_id >= 0)
427 font_unload(current_font_id);
Fred Bauerbccee892011-11-20 18:03:39 +0000428 screens[screen].setuifont(
429 font_load_ex(file,0,global_settings.glyphs_to_cache));
Jonathan Gordonaa0f4a42011-09-24 13:19:34 +0000430 viewportmanager_theme_changed(THEME_UI_VIEWPORT);
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000431}
432#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000433
434int ft_enter(struct tree_context* c)
435{
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000436 int rc = GO_TO_PREVIOUS;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000437 char buf[MAX_PATH];
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000438 struct entry* file = tree_get_entry_at(c, c->selected_item);
439 int file_attr = file->attr;
William Wilgus5e5ddce2018-07-25 19:28:25 +0200440 int len;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000441
442 if (c->currdir[1])
William Wilgus5e5ddce2018-07-25 19:28:25 +0200443 {
444 len = snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name);
445 if ((unsigned) len > sizeof(buf))
446 splash(HZ, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
447 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000448 else
449 snprintf(buf,sizeof(buf),"/%s",file->name);
450
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000451 if (file_attr & ATTR_DIRECTORY) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000452 memcpy(c->currdir, buf, sizeof(c->currdir));
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000453 if ( c->dirlevel < MAX_DIR_LEVELS )
454 c->selected_item_history[c->dirlevel] = c->selected_item;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000455 c->dirlevel++;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000456 c->selected_item=0;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000457 }
458 else {
459 int seed = current_tick;
460 bool play = false;
461 int start_index=0;
462
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000463 switch ( file_attr & FILE_ATTR_MASK ) {
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000464 case FILE_ATTR_M3U:
Jonathan Gordonf331d192011-11-28 12:41:15 +0000465 play = ft_play_playlist(buf, c->currdir, file->name);
466
467 if (play)
468 {
469 start_index = 0;
470 }
471
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000472 break;
473
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000474 case FILE_ATTR_AUDIO:
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000475 if (bookmark_autoload(c->currdir))
476 break;
477
Nils Wallménius01729e72008-08-15 08:27:39 +0000478 splash(0, ID2P(LANG_WAIT));
Zakk Robertsddb36b22006-04-15 06:23:34 +0000479
Hardeep Sidhu941de852006-02-05 19:35:03 +0000480 /* about to create a new current playlist...
481 allow user to cancel the operation */
Nils Wallméniusdabcb812008-05-01 10:13:12 +0000482 if (!warn_on_pl_erase())
483 break;
Hardeep Sidhu941de852006-02-05 19:35:03 +0000484
Jonathan Gordonddc21762008-08-19 11:55:30 +0000485 if (global_settings.party_mode && audio_status())
Miika Pekkarinen887cfeb2006-08-10 09:50:45 +0000486 {
Björn Stenbergfc390af2006-03-19 08:40:31 +0000487 playlist_insert_track(NULL, buf,
Miika Pekkarinen887cfeb2006-08-10 09:50:45 +0000488 PLAYLIST_INSERT_LAST, true, true);
Nils Wallménius01729e72008-08-15 08:27:39 +0000489 splash(HZ, ID2P(LANG_QUEUE_LAST));
Björn Stenbergfc390af2006-03-19 08:40:31 +0000490 }
491 else if (playlist_create(c->currdir, NULL) != -1)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000492 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000493 start_index = ft_build_playlist(c, c->selected_item);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000494 if (global_settings.playlist_shuffle)
495 {
496 start_index = playlist_shuffle(seed, start_index);
497
498 /* when shuffling dir.: play all files
499 even if the file selected by user is
500 not the first one */
501 if (!global_settings.play_selected)
502 start_index = 0;
503 }
504
Michael Sevakis31b71222013-07-14 07:59:39 -0400505 playlist_start(start_index, 0, 0);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000506 play = true;
507 }
508 break;
509
Jonathan Gordon8ff3a652007-02-18 02:04:47 +0000510#if CONFIG_TUNER
Hristo Kovachev009853f2006-04-02 12:23:08 +0000511 /* fmr preset file */
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000512 case FILE_ATTR_FMR:
Nils Wallménius01729e72008-08-15 08:27:39 +0000513 splash(0, ID2P(LANG_WAIT));
Zakk Robertsddb36b22006-04-15 06:23:34 +0000514
Hristo Kovachev009853f2006-04-02 12:23:08 +0000515 /* Preset inside the default folder. */
516 if(!strncasecmp(FMPRESET_PATH, buf, strlen(FMPRESET_PATH)))
517 {
518 set_file(buf, global_settings.fmr_file, MAX_FILENAME);
519 radio_load_presets(global_settings.fmr_file);
Hristo Kovachev009853f2006-04-02 12:23:08 +0000520 }
Zakk Robertsddb36b22006-04-15 06:23:34 +0000521 /*
Hristo Kovachev009853f2006-04-02 12:23:08 +0000522 * Preset outside default folder, we can choose such only
Zakk Robertsddb36b22006-04-15 06:23:34 +0000523 * if we are out of the radio screen, so the check for the
524 * radio status isn't neccessary
Hristo Kovachev009853f2006-04-02 12:23:08 +0000525 */
526 else
527 {
528 radio_load_presets(buf);
Hristo Kovachev009853f2006-04-02 12:23:08 +0000529 }
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000530 rc = GO_TO_FM;
Zakk Robertsddb36b22006-04-15 06:23:34 +0000531
Hristo Kovachev009853f2006-04-02 12:23:08 +0000532 break;
Jonathan Gordon1bd072c2010-05-12 10:38:00 +0000533 case FILE_ATTR_FMS:
534 splash(0, ID2P(LANG_WAIT));
535 set_file(buf, (char *)global_settings.fms_file, MAX_FILENAME);
536 settings_apply_skins();
537 break;
538#ifdef HAVE_REMOTE_LCD
539 case FILE_ATTR_RFMS:
540 splash(0, ID2P(LANG_WAIT));
541 set_file(buf, (char *)global_settings.rfms_file, MAX_FILENAME);
542 settings_apply_skins();
543 break;
544#endif
Hristo Kovachev009853f2006-04-02 12:23:08 +0000545#endif
546
Thomas Martitz1016ee42009-10-19 15:28:15 +0000547#ifdef HAVE_LCD_BITMAP
548 case FILE_ATTR_SBS:
549 splash(0, ID2P(LANG_WAIT));
Jonathan Gordona9b5f4d2010-03-06 00:29:46 +0000550 set_file(buf, (char *)global_settings.sbs_file, MAX_FILENAME);
Thomas Martitz1016ee42009-10-19 15:28:15 +0000551 settings_apply_skins();
Thomas Martitz1016ee42009-10-19 15:28:15 +0000552 break;
553#endif
554#ifdef HAVE_REMOTE_LCD
555 case FILE_ATTR_RSBS:
556 splash(0, ID2P(LANG_WAIT));
Jonathan Gordona9b5f4d2010-03-06 00:29:46 +0000557 set_file(buf, (char *)global_settings.rsbs_file, MAX_FILENAME);
Thomas Martitz1016ee42009-10-19 15:28:15 +0000558 settings_apply_skins();
Thomas Martitz1016ee42009-10-19 15:28:15 +0000559 break;
560#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000561 /* wps config file */
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000562 case FILE_ATTR_WPS:
Nils Wallménius01729e72008-08-15 08:27:39 +0000563 splash(0, ID2P(LANG_WAIT));
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000564 set_file(buf, (char *)global_settings.wps_file,
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000565 MAX_FILENAME);
Thomas Martitzc4266282009-08-16 20:12:17 +0000566 settings_apply_skins();
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000567 break;
568
Magnus Holmgrenf9fa33f2005-12-04 12:11:08 +0000569#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000570 /* remote-wps config file */
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000571 case FILE_ATTR_RWPS:
Nils Wallménius01729e72008-08-15 08:27:39 +0000572 splash(0, ID2P(LANG_WAIT));
Daniel Stenbergf981ea92005-12-05 22:44:42 +0000573 set_file(buf, (char *)global_settings.rwps_file,
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000574 MAX_FILENAME);
Thomas Martitzc4266282009-08-16 20:12:17 +0000575 settings_apply_skins();
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000576 break;
577#endif
578
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000579 case FILE_ATTR_CFG:
Nils Wallménius01729e72008-08-15 08:27:39 +0000580 splash(0, ID2P(LANG_WAIT));
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000581 if (!settings_load_config(buf,true))
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000582 break;
Nils Wallménius01729e72008-08-15 08:27:39 +0000583 splash(HZ, ID2P(LANG_SETTINGS_LOADED));
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000584 break;
585
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000586 case FILE_ATTR_BMARK:
Nils Wallménius01729e72008-08-15 08:27:39 +0000587 splash(0, ID2P(LANG_WAIT));
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000588 bookmark_load(buf, false);
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000589 rc = GO_TO_FILEBROWSER;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000590 break;
591
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000592 case FILE_ATTR_LNG:
Nils Wallménius01729e72008-08-15 08:27:39 +0000593 splash(0, ID2P(LANG_WAIT));
Tomer Shalevbb5078c2009-10-19 15:50:06 +0000594 if (lang_core_load(buf))
595 {
Tomer Shalev9351d412009-10-19 16:01:05 +0000596 splash(HZ, ID2P(LANG_FAILED));
Tomer Shalevbb5078c2009-10-19 15:50:06 +0000597 break;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000598 }
Tomer Shalevbb5078c2009-10-19 15:50:06 +0000599 set_file(buf, (char *)global_settings.lang_file,
600 MAX_FILENAME);
601 talk_init(); /* use voice of same language */
602 viewportmanager_theme_changed(THEME_LANGUAGE);
Jonathan Gordon91e6b062010-01-07 07:34:15 +0000603 settings_apply_skins();
Tomer Shalevbb5078c2009-10-19 15:50:06 +0000604 splash(HZ, ID2P(LANG_LANGUAGE_LOADED));
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000605 break;
606
607#ifdef HAVE_LCD_BITMAP
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000608 case FILE_ATTR_FONT:
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000609 ft_load_font(buf);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000610 break;
Frank Dischner75c3d0b2006-03-29 16:21:42 +0000611
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000612 case FILE_ATTR_KBD:
Nils Wallménius01729e72008-08-15 08:27:39 +0000613 splash(0, ID2P(LANG_WAIT));
Frank Dischner75c3d0b2006-03-29 16:21:42 +0000614 if (!load_kbd(buf))
Nils Wallménius01729e72008-08-15 08:27:39 +0000615 splash(HZ, ID2P(LANG_KEYBOARD_LOADED));
Frank Dischner75c3d0b2006-03-29 16:21:42 +0000616 set_file(buf, (char *)global_settings.kbd_file, MAX_FILENAME);
617 break;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000618#endif
619
Thomas Martitz35e8b142010-06-21 16:53:00 +0000620#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000621 /* firmware file */
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000622 case FILE_ATTR_MOD:
Nils Wallménius01729e72008-08-15 08:27:39 +0000623 splash(0, ID2P(LANG_WAIT));
Thomas Martitzd1322b72011-08-14 15:13:00 +0000624 audio_hard_stop();
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000625 rolo_load(buf);
626 break;
627#endif
628
629 /* plugin file */
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000630 case FILE_ATTR_ROCK:
Maurus Cuelenaered789e412009-10-28 23:31:42 +0000631 case FILE_ATTR_LUA:
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000632 {
Thomas Martitz9c0b2472010-08-01 16:15:27 +0000633 char *plugin = buf, *argument = NULL, lua_path[MAX_PATH];
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000634 int ret;
Maurus Cuelenaered789e412009-10-28 23:31:42 +0000635
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000636 if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) {
Thomas Martitz9c0b2472010-08-01 16:15:27 +0000637 snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */
638 plugin = lua_path;
Maurus Cuelenaered789e412009-10-28 23:31:42 +0000639 argument = buf;
640 }
641
Jonathan Gordonddc21762008-08-19 11:55:30 +0000642 if (global_settings.party_mode && audio_status()) {
Nils Wallménius01729e72008-08-15 08:27:39 +0000643 splash(HZ, ID2P(LANG_PARTY_MODE));
Björn Stenbergfc390af2006-03-19 08:40:31 +0000644 break;
645 }
Maurus Cuelenaered789e412009-10-28 23:31:42 +0000646 ret = plugin_load(plugin, argument);
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000647 switch (ret)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000648 {
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000649 case PLUGIN_GOTO_WPS:
650 play = true;
651 break;
652 case PLUGIN_USB_CONNECTED:
653 if(*c->dirfilter > NUM_FILTER_MODES)
654 /* leave sub-browsers after usb, doing
655 otherwise might be confusing to the user */
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000656 rc = GO_TO_ROOT;
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000657 else
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000658 rc = GO_TO_FILEBROWSER;
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000659 break;
660 /*
661 case PLUGIN_ERROR:
662 case PLUGIN_OK:
663 */
664 default:
665 break;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000666 }
667 break;
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000668 }
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000669 case FILE_ATTR_CUE:
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +0000670 display_cuesheet_content(buf);
671 break;
672
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000673 default:
674 {
Steve Bavinad95df22008-05-12 17:52:50 +0000675 const char* plugin;
Björn Stenbergfc390af2006-03-19 08:40:31 +0000676
Jonathan Gordonddc21762008-08-19 11:55:30 +0000677 if (global_settings.party_mode && audio_status()) {
Nils Wallménius01729e72008-08-15 08:27:39 +0000678 splash(HZ, ID2P(LANG_PARTY_MODE));
Björn Stenbergfc390af2006-03-19 08:40:31 +0000679 break;
680 }
Zakk Robertsddb36b22006-04-15 06:23:34 +0000681
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000682 struct entry* file = tree_get_entry_at(c, c->selected_item);
Björn Stenbergfc390af2006-03-19 08:40:31 +0000683 plugin = filetype_get_plugin(file);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000684 if (plugin)
685 {
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000686 switch (plugin_load(plugin,buf))
687 {
688 case PLUGIN_USB_CONNECTED:
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000689 rc = GO_TO_FILEBROWSER;
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000690 break;
691 case PLUGIN_GOTO_WPS:
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000692 rc = GO_TO_WPS;
Thomas Martitzdf6f9552009-07-05 22:12:42 +0000693 break;
694 /*
695 case PLUGIN_OK:
696 case PLUGIN_ERROR:
697 */
698 default:
699 break;
700 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000701 }
702 break;
703 }
704 }
705
706 if ( play ) {
Christi Scarborough9e8918b2005-06-29 12:23:09 +0000707 /* the resume_index must always be the index in the
708 shuffled list in case shuffle is enabled */
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000709 global_status.resume_index = start_index;
Richard Quirk212e7802012-12-09 21:04:17 +0100710 global_status.resume_crc32 =
711 playlist_get_filename_crc32(NULL, start_index);
Michael Sevakis31b71222013-07-14 07:59:39 -0400712 global_status.resume_elapsed = 0;
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000713 global_status.resume_offset = 0;
714 status_save();
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000715 rc = GO_TO_WPS;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000716 }
717 else {
718 if (*c->dirfilter > NUM_FILTER_MODES &&
Thomas Martitzdeb6b812009-05-11 22:50:48 +0000719 *c->dirfilter != SHOW_CFG &&
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000720 *c->dirfilter != SHOW_FONT &&
721 *c->dirfilter != SHOW_PLUGINS)
722 {
Jonathan Gordon43c85a42010-08-16 13:16:29 +0000723 rc = GO_TO_ROOT;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000724 }
725 }
726 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000727 return rc;
728}
729
730int ft_exit(struct tree_context* c)
731{
732 extern char lastfile[]; /* from tree.c */
733 char buf[MAX_PATH];
734 int rc = 0;
735 bool exit_func = false;
736
737 int i = strlen(c->currdir);
738 if (i>1) {
739 while (c->currdir[i-1]!='/')
740 i--;
741 strcpy(buf,&c->currdir[i]);
742 if (i==1)
743 c->currdir[i]=0;
744 else
745 c->currdir[i-1]=0;
746
747 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
748 exit_func = true;
749
750 c->dirlevel--;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000751 if ( c->dirlevel < MAX_DIR_LEVELS )
752 c->selected_item=c->selected_item_history[c->dirlevel];
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000753 else
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000754 c->selected_item=0;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000755
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000756 /* if undefined position */
757 if (c->selected_item == -1)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000758 strcpy(lastfile, buf);
759 }
760 else
761 {
762 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
763 exit_func = true;
764 }
765
766 if (exit_func)
Jens Arnold32be5902005-05-17 18:28:32 +0000767 rc = 3;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000768
769 return rc;
770}