blob: 66979ea3c1ca0af7e41d288074d185f3afbd95f6 [file] [log] [blame]
Björn Stenberg82182852002-05-16 12:53:40 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Daniel Stenberg
11 *
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 Stenberg82182852002-05-16 12:53:40 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Björn Stenberg244688e2002-05-16 14:48:40 +000021#include <stdio.h>
Björn Stenberg82182852002-05-16 12:53:40 +000022#include <string.h>
23#include <stdlib.h>
24#include <stdbool.h>
25
Linus Nielsen Feltzing5917e812002-08-15 12:28:52 +000026#include "applimits.h"
Björn Stenberg82182852002-05-16 12:53:40 +000027#include "dir.h"
28#include "file.h"
29#include "lcd.h"
Daniel Stenberg93b231c2002-09-12 13:33:59 +000030#include "font.h"
Justin Heinerb5025a82002-08-31 04:58:35 +000031#include "backlight.h"
Björn Stenberg82182852002-05-16 12:53:40 +000032#include "button.h"
33#include "kernel.h"
Linus Nielsen Feltzinge0b23fe2002-06-30 13:23:58 +000034#include "usb.h"
Björn Stenberg82182852002-05-16 12:53:40 +000035#include "tree.h"
Felix Arendsebbbe4b2002-05-29 16:38:19 +000036#include "sprintf.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000037#include "audio.h"
Daniel Stenberg7bd65ab2002-06-07 14:23:32 +000038#include "playlist.h"
Daniel Stenberg91f743f2002-06-14 10:39:11 +000039#include "menu.h"
Christi Scarborough4c0b83f2005-11-17 20:14:59 +000040#include "gwps.h"
Björn Stenberg24fdde02002-06-27 09:12:29 +000041#include "settings.h"
Linus Nielsen Feltzinge0b23fe2002-06-30 13:23:58 +000042#include "debug.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000043#include "storage.h"
Björn Stenbergc521ed12002-09-03 09:44:08 +000044#include "rolo.h"
Linus Nielsen Feltzing10452d22002-09-03 07:53:51 +000045#include "icons.h"
Björn Stenberg505eca72002-09-18 14:08:05 +000046#include "lang.h"
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000047#include "screens.h"
Björn Stenbergcaebdd42003-01-15 14:52:53 +000048#include "keyboard.h"
Björn Stenberga108ec22004-01-14 00:13:04 +000049#include "bookmark.h"
Björn Stenbergd7a55e12003-03-12 20:21:30 +000050#include "onplay.h"
Linus Nielsen Feltzing20d031f2003-05-09 16:01:21 +000051#include "buffer.h"
Björn Stenberg461d6e32003-12-04 00:08:25 +000052#include "power.h"
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +000053#include "action.h"
Jörg Hohensohn3aa99e12004-03-27 00:11:01 +000054#include "talk.h"
Björn Stenbergfb00c212004-05-21 20:08:24 +000055#include "filetypes.h"
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +000056#include "misc.h"
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000057#include "filetree.h"
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000058#include "tagtree.h"
Michael Sevakis0f5cb942006-11-06 18:07:30 +000059#ifdef HAVE_RECORDING
Christi Scarborough8a8bd912005-02-04 10:37:21 +000060#include "recorder/recording.h"
Michael Sevakis0f5cb942006-11-06 18:07:30 +000061#endif
Christi Scarborougheeed0572005-02-05 19:57:19 +000062#include "rtc.h"
Miika Pekkarinenab78b042005-10-07 17:38:05 +000063#include "dircache.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000064#ifdef HAVE_TAGCACHE
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000065#include "tagcache.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000066#endif
Kevin Ferrare8719f092005-11-18 02:07:02 +000067#include "yesno.h"
Peter D'Hoye5f3c0122006-07-01 23:48:30 +000068#include "gwps-common.h"
Miika Pekkarinen954b7322006-08-05 20:19:10 +000069#include "eeprom_settings.h"
Jonathan Gordon517aca82008-05-04 13:01:16 +000070#include "playlist_catalog.h"
Björn Stenberg82182852002-05-16 12:53:40 +000071
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000072/* gui api */
73#include "list.h"
74#include "statusbar.h"
75#include "splash.h"
76#include "buttonbar.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000077#include "action.h"
Jonathan Gordonea664e02008-05-03 12:30:40 +000078#include "quickscreen.h"
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000079
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000080#include "root_menu.h"
Peter D'Hoye93b899d2006-05-21 11:00:02 +000081
Jonathan Gordon36a2e302007-04-18 13:03:01 +000082static const struct filetype *filetypes;
83static int filetypes_count;
Jörg Hohensohn8b813d02003-12-07 16:57:43 +000084
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000085struct gui_synclist tree_lists;
86
87/* I put it here because other files doesn't use it yet,
88 * but should be elsewhere since it will be used mostly everywhere */
Peter D'Hoyef76122f2008-05-29 20:32:39 +000089#ifdef HAVE_BUTTONBAR
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000090struct gui_buttonbar tree_buttonbar;
91#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000092static struct tree_context tc;
Björn Stenberg82182852002-05-16 12:53:40 +000093
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000094bool boot_changed = false;
Björn Stenberg82182852002-05-16 12:53:40 +000095
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000096char lastfile[MAX_PATH];
Björn Stenberg84c7d8802005-01-18 22:45:00 +000097static char lastdir[MAX_PATH];
Jonathan Gordon2f4521e2007-02-06 13:25:57 +000098#ifdef HAVE_TAGCACHE
Björn Stenberg84c7d8802005-01-18 22:45:00 +000099static int lasttable, lastextra, lastfirstpos;
Jonathan Gordon2f4521e2007-02-06 13:25:57 +0000100#endif
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000101static int max_files = 0;
Linus Nielsen Feltzing20d031f2003-05-09 16:01:21 +0000102
Björn Stenbergcaebdd42003-01-15 14:52:53 +0000103static bool reload_dir = false;
Björn Stenberg361aaf62002-05-28 16:26:12 +0000104
Björn Stenberga108ec22004-01-14 00:13:04 +0000105static bool start_wps = false;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000106static int curr_context = false;/* id3db or tree*/
107
Nils Wallménius685f6bb2007-03-17 00:55:23 +0000108static int dirbrowse(void);
Nils Wallménius685f6bb2007-03-17 00:55:23 +0000109static int ft_play_dirname(char* name);
110static void ft_play_filename(char *dir, char *file);
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000111static void say_filetype(int attr);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000112
Nils Wallménius68489612008-04-09 15:25:17 +0000113static char * tree_get_filename(int selected_item, void *data,
114 char *buffer, size_t buffer_len)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000115{
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000116 struct tree_context * local_tc=(struct tree_context *)data;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000117 char *name;
118 int attr=0;
Peter D'Hoye043c9662007-08-13 23:11:30 +0000119 bool stripit = false;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000120#ifdef HAVE_TAGCACHE
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000121 bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
122
Miika Pekkarinen75b6abb2006-04-15 13:57:15 +0000123 if (id3db)
124 {
125 return tagtree_get_entry(&tc, selected_item)->name;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000126 }
Miika Pekkarinen75b6abb2006-04-15 13:57:15 +0000127 else
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000128#endif
Miika Pekkarinen75b6abb2006-04-15 13:57:15 +0000129 {
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000130 struct entry* dc = local_tc->dircache;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000131 struct entry* e = &dc[selected_item];
132 name = e->name;
133 attr = e->attr;
134 }
Peter D'Hoye043c9662007-08-13 23:11:30 +0000135
Peter D'Hoye360d9512007-08-14 21:02:44 +0000136 if(!(attr & ATTR_DIRECTORY))
Peter D'Hoye043c9662007-08-13 23:11:30 +0000137 {
Peter D'Hoye360d9512007-08-14 21:02:44 +0000138 switch(global_settings.show_filename_ext)
139 {
140 case 0:
141 /* show file extension: off */
142 stripit = true;
143 break;
144 case 1:
145 /* show file extension: on */
146 break;
147 case 2:
148 /* show file extension: only unknown types */
149 stripit = filetype_supported(attr);
150 break;
151 case 3:
152 default:
153 /* show file extension: only when viewing all */
154 stripit = (*(local_tc->dirfilter) != SHOW_ID3DB) &&
155 (*(local_tc->dirfilter) != SHOW_ALL);
156 break;
157 }
Peter D'Hoye043c9662007-08-13 23:11:30 +0000158 }
159
Peter D'Hoye043c9662007-08-13 23:11:30 +0000160 if(stripit)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000161 {
Nils Wallménius68489612008-04-09 15:25:17 +0000162 return(strip_extension(buffer, buffer_len, name));
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000163 }
164 return(name);
165}
166
Brandon Low74cbb0a2007-06-17 21:16:34 +0000167#ifdef HAVE_LCD_COLOR
168static int tree_get_filecolor(int selected_item, void * data)
169{
Paul Louden9727d152007-06-19 09:53:58 +0000170 if (*tc.dirfilter == SHOW_ID3DB)
171 return -1;
Brandon Low74cbb0a2007-06-17 21:16:34 +0000172 struct tree_context * local_tc=(struct tree_context *)data;
173 struct entry* dc = local_tc->dircache;
174 struct entry* e = &dc[selected_item];
Brandon Lowf8682a02007-06-17 23:10:01 +0000175 return filetype_get_color(e->name, e->attr);
Brandon Low74cbb0a2007-06-17 21:16:34 +0000176}
177#endif
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000178
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000179static int tree_get_fileicon(int selected_item, void * data)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000180{
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000181 struct tree_context * local_tc=(struct tree_context *)data;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000182#ifdef HAVE_TAGCACHE
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000183 bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000184 if (id3db) {
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000185 return tagtree_get_icon(&tc);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000186 }
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000187 else
188#endif
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000189 {
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000190 struct entry* dc = local_tc->dircache;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000191 struct entry* e = &dc[selected_item];
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000192 return filetype_get_icon(e->attr);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000193 }
194}
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000195
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000196static int tree_voice_cb(int selected_item, void * data)
197{
198 struct tree_context * local_tc=(struct tree_context *)data;
199 char *name;
200 int attr=0;
201#ifdef HAVE_TAGCACHE
202 bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
203
204 if (id3db)
205 {
206 attr = tagtree_get_attr(local_tc);
207 name = tagtree_get_entry(local_tc, selected_item)->name;
208 }
209 else
210#endif
211 {
212 struct entry* dc = local_tc->dircache;
213 struct entry* e = &dc[selected_item];
214 name = e->name;
215 attr = e->attr;
216 }
217 bool is_dir = (attr & ATTR_DIRECTORY);
218 bool did_clip = false;
219 /* First the .talk clip case */
220 if(is_dir)
221 {
222 if(global_settings.talk_dir_clip)
223 {
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000224 did_clip = true;
225 if(ft_play_dirname(name) <0)
226 /* failed, not existing */
227 did_clip = false;
228 }
229 } else { /* it's a file */
230 if (global_settings.talk_file_clip && (attr & FILE_ATTR_THUMBNAIL))
231 {
232 did_clip = true;
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000233 ft_play_filename(local_tc->currdir, name);
234 }
235 }
236 if(!did_clip)
237 {
238 /* say the number or spell if required or as a fallback */
239 switch (is_dir ? global_settings.talk_dir : global_settings.talk_file)
240 {
241 case 1: /* as numbers */
242 talk_id(is_dir ? VOICE_DIR : VOICE_FILE, false);
243 talk_number(selected_item+1 - (is_dir ? 0 : local_tc->dirsindir),
244 true);
Stéphane Doyona4f491c2007-11-07 03:25:33 +0000245 if(global_settings.talk_filetype
246 && !is_dir && *local_tc->dirfilter < NUM_FILTER_MODES)
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000247 say_filetype(attr);
248 break;
249 case 2: /* spelled */
Stéphane Doyon8024aad2007-11-07 01:45:43 +0000250 talk_shutup();
Stéphane Doyona4f491c2007-11-07 03:25:33 +0000251 if(global_settings.talk_filetype)
252 {
253 if(is_dir)
254 talk_id(VOICE_DIR, true);
255 else if(*local_tc->dirfilter < NUM_FILTER_MODES)
256 say_filetype(attr);
257 }
Stéphane Doyon8024aad2007-11-07 01:45:43 +0000258 talk_spell(name, true);
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000259 break;
260 }
261 }
262 return 0;
263}
264
Henrik Backe66b45ee2004-09-10 20:51:12 +0000265bool check_rockboxdir(void)
Björn Stenberg82182852002-05-16 12:53:40 +0000266{
Nils Wallméniusa0199642008-04-16 19:51:43 +0000267 if(!dir_exists(ROCKBOX_DIR))
Jens Arnold67de1d32006-04-01 13:36:33 +0000268 { /* No need to localise this message.
269 If .rockbox is missing, it wouldn't work anyway */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000270 int i;
Jens Arnoldedf5a702005-11-09 22:47:15 +0000271 FOR_NB_SCREENS(i)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000272 screens[i].clear_display();
Nils Wallménius01729e72008-08-15 08:27:39 +0000273 splash(HZ*2, "No .rockbox directory");
Jens Arnoldedf5a702005-11-09 22:47:15 +0000274 FOR_NB_SCREENS(i)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000275 screens[i].clear_display();
Nils Wallménius01729e72008-08-15 08:27:39 +0000276 splash(HZ*2, "Installation incomplete");
Henrik Backe66b45ee2004-09-10 20:51:12 +0000277 return false;
Henrik Backe717fae92004-09-05 16:50:07 +0000278 }
Henrik Backe66b45ee2004-09-10 20:51:12 +0000279 return true;
280}
281
Jonathan Gordon2cda9942007-06-10 10:41:27 +0000282/* do this really late in the init sequence */
283void tree_gui_init(void)
Henrik Backe66b45ee2004-09-10 20:51:12 +0000284{
Henrik Backe66b45ee2004-09-10 20:51:12 +0000285 check_rockboxdir();
286
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000287 strcpy(tc.currdir, "/");
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000288
Jens Arnold40eeeb32005-06-29 17:39:18 +0000289#ifdef HAVE_LCD_CHARCELLS
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000290 int i;
Jens Arnoldedf5a702005-11-09 22:47:15 +0000291 FOR_NB_SCREENS(i)
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000292 screens[i].double_height(false);
Jens Arnold40eeeb32005-06-29 17:39:18 +0000293#endif
Peter D'Hoyef76122f2008-05-29 20:32:39 +0000294#ifdef HAVE_BUTTONBAR
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000295 gui_buttonbar_init(&tree_buttonbar);
296 /* since archos only have one screen, no need to create more than that */
297 gui_buttonbar_set_display(&tree_buttonbar, &(screens[SCREEN_MAIN]) );
298#endif
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000299 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL);
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000300 gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb);
Steve Bavin361a60c2007-03-01 18:25:13 +0000301 gui_synclist_set_icon_callback(&tree_lists, &tree_get_fileicon);
Brandon Low74cbb0a2007-06-17 21:16:34 +0000302#ifdef HAVE_LCD_COLOR
Jonathan Gordon0e5cec22008-03-05 09:58:30 +0000303 gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor);
Brandon Low74cbb0a2007-06-17 21:16:34 +0000304#endif
Björn Stenberg82182852002-05-16 12:53:40 +0000305}
306
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000307
Björn Stenberg82182852002-05-16 12:53:40 +0000308
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000309struct tree_context* tree_get_context(void)
310{
311 return &tc;
312}
313
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000314/*
315 * Returns the position of a given file in the current directory
316 * returns -1 if not found
317 */
Jens Arnold2597a132006-12-25 14:01:47 +0000318static int tree_get_file_position(char * filename)
Linus Nielsen Feltzing4a4f17f2002-08-06 13:10:51 +0000319{
Björn Stenberg82182852002-05-16 12:53:40 +0000320 int i;
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +0000321
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000322 /* use lastfile to determine the selected item (default=0) */
323 for (i=0; i < tc.filesindir; i++)
324 {
325 struct entry* dc = tc.dircache;
326 struct entry* e = &dc[i];
327 if (!strcasecmp(e->name, filename))
328 return(i);
329 }
330 return(-1);/* no file can match, returns undefined */
331}
Björn Stenbergcd225732002-08-11 09:17:47 +0000332
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000333/*
334 * Called when a new dir is loaded (for example when returning from other apps ...)
335 * also completely redraws the tree
336 */
337static int update_dir(void)
338{
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000339 bool changed = false;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000340#ifdef HAVE_TAGCACHE
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000341 bool id3db = *tc.dirfilter == SHOW_ID3DB;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000342 /* Checks for changes */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000343 if (id3db) {
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000344 if (tc.currtable != lasttable ||
345 tc.currextra != lastextra ||
Hardeep Sidhu432a6982006-06-07 20:42:42 +0000346 tc.firstpos != lastfirstpos ||
347 reload_dir)
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000348 {
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +0000349 if (tagtree_load(&tc) < 0)
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000350 return -1;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000351
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000352 lasttable = tc.currtable;
353 lastextra = tc.currextra;
354 lastfirstpos = tc.firstpos;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000355 changed = true;
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000356 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000357 }
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000358 else
359#endif
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000360 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000361 /* if the tc.currdir has been changed, reload it ...*/
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000362 if (strncmp(tc.currdir, lastdir, sizeof(lastdir)) || reload_dir)
363 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000364 if (ft_load(&tc, NULL) < 0)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000365 return -1;
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000366 strcpy(lastdir, tc.currdir);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000367 changed = true;
Björn Stenberge33d66a2002-08-12 22:52:19 +0000368 }
Björn Stenberg361aaf62002-05-28 16:26:12 +0000369 }
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000370 /* if selected item is undefined */
371 if (tc.selected_item == -1)
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000372 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000373 /* use lastfile to determine the selected item */
374 tc.selected_item = tree_get_file_position(lastfile);
375
376 /* If the file doesn't exists, select the first one (default) */
377 if(tc.selected_item < 0)
378 tc.selected_item = 0;
379 changed = true;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000380 }
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000381 if (changed)
Eric Linenbergecca1232002-09-09 14:25:39 +0000382 {
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000383 if(
384#ifdef HAVE_TAGCACHE
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000385 !id3db &&
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000386#endif
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000387 (tc.dirfull || tc.filesindir == global_settings.max_files_in_dir) )
Eric Linenbergecca1232002-09-09 14:25:39 +0000388 {
Nils Wallménius01729e72008-08-15 08:27:39 +0000389 splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000390 }
Björn Stenberg82182852002-05-16 12:53:40 +0000391 }
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000392#ifdef HAVE_TAGCACHE
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000393 if (id3db)
394 {
Jonathan Gordon189f9e22008-01-13 09:29:45 +0000395#ifdef HAVE_LCD_BITMAP
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000396 if (global_settings.show_path_in_browser == SHOW_PATH_FULL
397 || global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
398 {
399 gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc),
Steve Bavin361a60c2007-03-01 18:25:13 +0000400 filetype_get_icon(ATTR_DIRECTORY));
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000401 }
402 else
403 {
404 /* Must clear the title as the list is reused */
405 gui_synclist_set_title(&tree_lists, NULL, NOICON);
406 }
Jonathan Gordon189f9e22008-01-13 09:29:45 +0000407#endif
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000408 }
409 else
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000410#endif
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000411 {
Jonathan Gordon189f9e22008-01-13 09:29:45 +0000412#ifdef HAVE_LCD_BITMAP
Jonathan Gordonda727b52007-08-16 13:55:37 +0000413 if (global_settings.show_path_in_browser &&
414 *(tc.dirfilter) == SHOW_PLUGINS)
415 {
416 char *title;
417 if (!strcmp(tc.currdir, PLUGIN_GAMES_DIR))
418 title = str(LANG_PLUGIN_GAMES);
419 else if (!strcmp(tc.currdir, PLUGIN_APPS_DIR))
420 title = str(LANG_PLUGIN_APPS);
421 else if (!strcmp(tc.currdir, PLUGIN_DEMOS_DIR))
422 title = str(LANG_PLUGIN_DEMOS);
423 else title = str(LANG_PLUGINS);
424 gui_synclist_set_title(&tree_lists, title, Icon_Plugin);
425 }
426 else if (global_settings.show_path_in_browser == SHOW_PATH_FULL)
Mark Arigo34301bb2006-08-23 20:02:06 +0000427 {
428 gui_synclist_set_title(&tree_lists, tc.currdir,
Steve Bavin361a60c2007-03-01 18:25:13 +0000429 filetype_get_icon(ATTR_DIRECTORY));
Dan Evertonc0f8b182006-08-15 12:23:55 +0000430 }
Mark Arigo34301bb2006-08-23 20:02:06 +0000431 else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
432 {
433 char *title = strrchr(tc.currdir, '/') + 1;
434 if (*title == '\0')
435 {
Steve Bavin4af33862007-03-01 17:34:49 +0000436 /* Display "Files" for the root dir */
437 gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER),
Steve Bavin361a60c2007-03-01 18:25:13 +0000438 filetype_get_icon(ATTR_DIRECTORY));
Mark Arigo34301bb2006-08-23 20:02:06 +0000439 }
440 else
441 gui_synclist_set_title(&tree_lists, title,
Steve Bavin361a60c2007-03-01 18:25:13 +0000442 filetype_get_icon(ATTR_DIRECTORY));
Mark Arigo34301bb2006-08-23 20:02:06 +0000443 }
444 else
445 {
446 /* Must clear the title as the list is reused */
447 gui_synclist_set_title(&tree_lists, NULL, NOICON);
448 }
Jonathan Gordon189f9e22008-01-13 09:29:45 +0000449#endif
Dan Evertoneb1dd382006-08-15 09:38:13 +0000450 }
Miika Pekkarinen1e6b2272006-09-19 12:36:21 +0000451
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000452 gui_synclist_set_nb_items(&tree_lists, tc.filesindir);
Steve Bavin361a60c2007-03-01 18:25:13 +0000453 gui_synclist_set_icon_callback(&tree_lists, tree_get_fileicon);
Kevin Ferraref7c97522005-11-09 01:17:57 +0000454 if( tc.selected_item >= tc.filesindir)
455 tc.selected_item=tc.filesindir-1;
456
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000457 gui_synclist_select_item(&tree_lists, tc.selected_item);
Peter D'Hoyef76122f2008-05-29 20:32:39 +0000458#ifdef HAVE_BUTTONBAR
Jens Arnold7067f182005-05-16 11:50:46 +0000459 if (global_settings.buttonbar) {
460 if (*tc.dirfilter < NUM_FILTER_MODES)
Shachar Libermanf17e5c02006-08-07 21:24:22 +0000461 gui_buttonbar_set(&tree_buttonbar, str(LANG_SYSFONT_DIRBROWSE_F1),
462 str(LANG_SYSFONT_DIRBROWSE_F2),
463 str(LANG_SYSFONT_DIRBROWSE_F3));
Jens Arnold7067f182005-05-16 11:50:46 +0000464 else
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000465 gui_buttonbar_set(&tree_buttonbar, "<<<", "", "");
466 gui_buttonbar_draw(&tree_buttonbar);
Linus Nielsen Feltzing77936e62004-03-16 13:44:56 +0000467 }
Markus Braun000c2db2002-08-30 13:49:32 +0000468#endif
Linus Nielsen Feltzing1d668262006-07-01 10:31:50 +0000469 gui_synclist_draw(&tree_lists);
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000470 gui_synclist_speak_item(&tree_lists);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000471 return tc.filesindir;
Björn Stenberg82182852002-05-16 12:53:40 +0000472}
473
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000474/* load tracks from specified directory to resume play */
Jens Arnold8fb33612004-08-18 01:09:31 +0000475void resume_directory(const char *dir)
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000476{
Jonathan Gordon7f77dd82009-02-25 05:41:31 +0000477 int dirfilter = *tc.dirfilter;
478 int ret;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000479#ifdef HAVE_TAGCACHE
Miika Pekkarinena99bc992006-04-03 18:52:58 +0000480 bool id3db = *tc.dirfilter == SHOW_ID3DB;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000481#endif
Jonathan Gordon7f77dd82009-02-25 05:41:31 +0000482 /* make sure the dirfilter is sane. The only time it should be possible
483 * thats its not is when resume playlist is called from a plugin
484 */
485#ifdef HAVE_TAGCACHE
486 if (!id3db)
487#endif
488 *tc.dirfilter = global_settings.dirfilter;
489 ret = ft_load(&tc, dir);
490 *tc.dirfilter = dirfilter;
491 if (ret < 0)
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000492 return;
493 lastdir[0] = 0;
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +0000494
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000495 ft_build_playlist(&tc, 0);
Miika Pekkarinena99bc992006-04-03 18:52:58 +0000496
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000497#ifdef HAVE_TAGCACHE
Miika Pekkarinena99bc992006-04-03 18:52:58 +0000498 if (id3db)
499 tagtree_load(&tc);
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000500#endif
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000501}
502
503/* Returns the current working directory and also writes cwd to buf if
504 non-NULL. In case of error, returns NULL. */
505char *getcwd(char *buf, int size)
506{
507 if (!buf)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000508 return tc.currdir;
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000509 else if (size > 0)
510 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000511 strncpy(buf, tc.currdir, size);
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000512 return buf;
513 }
514 else
515 return NULL;
516}
517
518/* Force a reload of the directory next time directory browser is called */
519void reload_directory(void)
520{
521 reload_dir = true;
522}
523
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000524void get_current_file(char* buffer, int buffer_len)
525{
526#ifdef HAVE_TAGCACHE
527 /* in ID3DB mode it is a bad idea to call this function */
528 /* (only happens with `follow playlist') */
529 if( *tc.dirfilter == SHOW_ID3DB )
530 return;
531#endif
532
533 struct entry* dc = tc.dircache;
534 struct entry* e = &dc[tc.selected_item];
535 snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0),
Jens Arnold8e6e25c2007-04-07 15:31:22 +0000536 tc.dirlength ? e->name : "");
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000537}
538
Jonathan Gordonef815722007-08-05 12:14:07 +0000539/* Allow apps to change our dirfilter directly (required for sub browsers)
540 if they're suddenly going to become a file browser for example */
541void set_dirfilter(int l_dirfilter)
542{
543 *tc.dirfilter = l_dirfilter;
544}
545
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000546/* Selects a file and update tree context properly */
Jonathan Gordonef815722007-08-05 12:14:07 +0000547void set_current_file(char *path)
Eric Linenbergecca1232002-09-09 14:25:39 +0000548{
549 char *name;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000550 int i;
Eric Linenbergecca1232002-09-09 14:25:39 +0000551
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000552#ifdef HAVE_TAGCACHE
Linus Nielsen Feltzingd3a72442005-03-11 08:18:28 +0000553 /* in ID3DB mode it is a bad idea to call this function */
554 /* (only happens with `follow playlist') */
555 if( *tc.dirfilter == SHOW_ID3DB )
Linus Nielsen Feltzingd3a72442005-03-11 08:18:28 +0000556 return;
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000557#endif
Linus Nielsen Feltzingd3a72442005-03-11 08:18:28 +0000558
Eric Linenbergecca1232002-09-09 14:25:39 +0000559 /* separate directory from filename */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000560 /* gets the directory's name and put it into tc.currdir */
Hardeep Sidhuc2c8d1c2002-09-17 07:42:21 +0000561 name = strrchr(path+1,'/');
Eric Linenbergecca1232002-09-09 14:25:39 +0000562 if (name)
563 {
564 *name = 0;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000565 strcpy(tc.currdir, path);
Eric Linenbergecca1232002-09-09 14:25:39 +0000566 *name = '/';
567 name++;
568 }
569 else
570 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000571 strcpy(tc.currdir, "/");
Eric Linenbergecca1232002-09-09 14:25:39 +0000572 name = path+1;
573 }
574
575 strcpy(lastfile, name);
Zakk Roberts2f943b02006-04-10 03:51:17 +0000576
Eric Linenbergecca1232002-09-09 14:25:39 +0000577
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000578 /* If we changed dir we must recalculate the dirlevel
579 and adjust the selected history properly */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000580 if (strncmp(tc.currdir,lastdir,sizeof(lastdir)))
Eric Linenbergecca1232002-09-09 14:25:39 +0000581 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000582 tc.dirlevel = 0;
583 tc.selected_item_history[tc.dirlevel] = -1;
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +0000584
Eric Linenbergecca1232002-09-09 14:25:39 +0000585 /* use '/' to calculate dirlevel */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000586 for (i = 1; path[i] != '\0'; i++)
Eric Linenbergecca1232002-09-09 14:25:39 +0000587 {
588 if (path[i] == '/')
589 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000590 tc.dirlevel++;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000591 tc.selected_item_history[tc.dirlevel] = -1;
Eric Linenbergecca1232002-09-09 14:25:39 +0000592 }
593 }
594 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000595 if (ft_load(&tc, NULL) >= 0)
596 {
597 tc.selected_item = tree_get_file_position(lastfile);
598 }
Eric Linenbergecca1232002-09-09 14:25:39 +0000599}
600
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000601
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000602/* main loop, handles key events */
Nils Wallménius685f6bb2007-03-17 00:55:23 +0000603static int dirbrowse()
Björn Stenberg82182852002-05-16 12:53:40 +0000604{
Björn Stenberg079b2d12002-08-08 12:06:38 +0000605 int numentries=0;
Linus Nielsen Feltzing8c57ad92002-07-15 22:46:38 +0000606 char buf[MAX_PATH];
Jonathan Gordone385ee12008-12-31 05:59:26 +0000607 int button, oldbutton;
Björn Stenberg0ad20102002-09-03 20:47:23 +0000608 bool reload_root = false;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000609 int lastfilter = *tc.dirfilter;
Björn Stenberg0ad20102002-09-03 20:47:23 +0000610 bool lastsortcase = global_settings.sort_case;
Björn Stenbergde5477c2003-09-29 21:26:53 +0000611 bool exit_func = false;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000612
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000613 char* currdir = tc.currdir; /* just a shortcut */
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000614#ifdef HAVE_TAGCACHE
Björn Stenbergf2758d12005-01-18 23:07:23 +0000615 bool id3db = *tc.dirfilter == SHOW_ID3DB;
Daniel Stenbergcc46b4a2003-01-24 10:56:59 +0000616
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000617 if (id3db)
618 curr_context=CONTEXT_ID3DB;
619 else
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000620#endif
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000621 curr_context=CONTEXT_TREE;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000622 if (tc.selected_item < 0)
623 tc.selected_item = 0;
Jonathan Gordon2f4521e2007-02-06 13:25:57 +0000624#ifdef HAVE_TAGCACHE
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000625 tc.firstpos = 0;
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000626 lasttable = -1;
627 lastextra = -1;
628 lastfirstpos = 0;
Jonathan Gordon2f4521e2007-02-06 13:25:57 +0000629#endif
Eric Linenbergecca1232002-09-09 14:25:39 +0000630
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000631 start_wps = false;
632 numentries = update_dir();
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000633 reload_dir = false;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000634 if (numentries == -1)
Jonathan Gordon1e199cd2007-10-19 06:11:13 +0000635 return GO_TO_PREVIOUS; /* currdir is not a directory */
Linus Nielsen Feltzingb3050e92005-09-02 07:59:42 +0000636
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000637 if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0)
638 {
Nils Wallménius01729e72008-08-15 08:27:39 +0000639 splash(HZ*2, ID2P(LANG_NO_FILES));
Jonathan Gordon1e199cd2007-10-19 06:11:13 +0000640 return GO_TO_PREVIOUS; /* No files found for rockbox_browser() */
Christi Scarborough8a8bd912005-02-04 10:37:21 +0000641 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000642
Jonathan Gordon45445312009-01-15 06:24:58 +0000643 gui_synclist_draw(&tree_lists);
Björn Stenberg82182852002-05-16 12:53:40 +0000644 while(1) {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000645 struct entry *dircache = tc.dircache;
Björn Stenbergbb9aaf52002-06-25 13:26:04 +0000646 bool restore = false;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000647 if (tc.dirlevel < 0)
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000648 tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
Linus Nielsen Feltzing88d5aab2005-03-31 10:50:15 +0000649#ifdef BOOTFILE
Björn Stenbergba5dfbd2003-06-29 22:39:35 +0000650 if (boot_changed) {
Nils Wallménius33c44462008-04-26 09:30:24 +0000651 static const char *lines[]={ID2P(LANG_BOOT_CHANGED), ID2P(LANG_REBOOT_NOW)};
652 static const struct text_message message={lines, 2};
Kevin Ferrare8719f092005-11-18 02:07:02 +0000653 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
654 rolo_load("/" BOOTFILE);
Björn Stenbergba5dfbd2003-06-29 22:39:35 +0000655 restore = true;
656 boot_changed = false;
657 }
658#endif
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000659 button = get_action(CONTEXT_TREE,
660 list_do_action_timeout(&tree_lists, HZ/2));
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000661 oldbutton = button;
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000662 gui_synclist_do_button(&tree_lists, &button,LIST_WRAP_UNLESS_HELD);
Jonathan Gordonfd30be52007-03-10 12:51:08 +0000663 tc.selected_item = gui_synclist_get_sel_pos(&tree_lists);
Linus Nielsen Feltzingf140b202002-07-27 20:55:39 +0000664 switch ( button ) {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000665 case ACTION_STD_OK:
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000666 /* nothing to do if no files to display */
667 if ( numentries == 0 )
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000668 break;
669
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000670#ifdef HAVE_TAGCACHE
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +0000671 switch (id3db?tagtree_enter(&tc):ft_enter(&tc))
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000672#else
673 switch (ft_enter(&tc))
674#endif
Björn Stenberg30d8f612005-01-20 16:24:26 +0000675 {
676 case 1: reload_dir = true; break;
Jens Arnold32be5902005-05-17 18:28:32 +0000677 case 2: start_wps = true; break;
678 case 3: exit_func = true; break;
Björn Stenberg30d8f612005-01-20 16:24:26 +0000679 default: break;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000680 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000681 restore = true;
682 break;
683
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000684 case ACTION_STD_CANCEL:
Björn Stenbergea1188c2005-01-18 22:59:29 +0000685 if (*tc.dirfilter > NUM_FILTER_MODES && tc.dirlevel < 1) {
686 exit_func = true;
687 break;
688 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000689 if ((*tc.dirfilter == SHOW_ID3DB && tc.dirlevel == 0) ||
690 ((*tc.dirfilter != SHOW_ID3DB && !strcmp(currdir,"/"))))
691 {
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000692#ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
693 if (oldbutton == ACTION_TREE_PGLEFT)
Jonathan Gordon277c39c2007-03-01 23:41:45 +0000694 break;
Jonathan Gordon277c39c2007-03-01 23:41:45 +0000695 else
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000696#endif
Jonathan Gordon277c39c2007-03-01 23:41:45 +0000697 return GO_TO_ROOT;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000698 }
699
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000700#ifdef HAVE_TAGCACHE
Linus Nielsen Feltzing1adc87a2006-08-15 21:27:04 +0000701 if (id3db)
702 tagtree_exit(&tc);
703 else
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000704#endif
Linus Nielsen Feltzing1adc87a2006-08-15 21:27:04 +0000705 if (ft_exit(&tc) == 3)
706 exit_func = true;
707
708 restore = true;
709 break;
Björn Stenberg82182852002-05-16 12:53:40 +0000710
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000711 case ACTION_TREE_STOP:
Jens Arnold178c5652007-04-09 13:39:37 +0000712 if (list_stop_handler())
713 restore = true;
714 break;
715
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000716 case ACTION_STD_MENU:
Linus Nielsen Feltzing421b67e2007-03-01 13:01:14 +0000717 return GO_TO_ROOT;
Björn Stenberge493efd2002-05-21 14:30:54 +0000718 break;
Björn Stenbergbb9aaf52002-06-25 13:26:04 +0000719
Jonathan Gordon73336e92007-08-02 12:13:20 +0000720#ifdef HAVE_RECORDING
721 case ACTION_STD_REC:
722 return GO_TO_RECSCREEN;
723#endif
724
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000725 case ACTION_TREE_WPS:
Linus Nielsen Feltzing421b67e2007-03-01 13:01:14 +0000726 return GO_TO_PREVIOUS_MUSIC;
Björn Stenbergbb9aaf52002-06-25 13:26:04 +0000727 break;
Zakk Roberts2f943b02006-04-10 03:51:17 +0000728#ifdef HAVE_QUICKSCREEN
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000729 case ACTION_STD_QUICKSCREEN:
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000730 /* don't enter f2 from plugin browser */
731 if (*tc.dirfilter < NUM_FILTER_MODES)
Linus Nielsen Feltzingf97756e2003-11-04 16:47:05 +0000732 {
Kevin Ferraref57d0222005-11-22 21:55:05 +0000733 if (quick_screen_quick(button))
Jens Arnold8f664222005-05-16 12:07:25 +0000734 reload_dir = true;
Linus Nielsen Feltzingf97756e2003-11-04 16:47:05 +0000735 restore = true;
Linus Nielsen Feltzingf97756e2003-11-04 16:47:05 +0000736 }
Jens Arnold376611e2006-04-03 06:08:24 +0000737 break;
Christi Scarborough37c3d8b2005-06-26 20:16:26 +0000738#endif
Christi Scarborough37c3d8b2005-06-26 20:16:26 +0000739#ifdef BUTTON_F3
Jonathan Gordoncbcc9db2006-08-22 08:23:24 +0000740 case ACTION_F3:
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000741 /* don't enter f3 from plugin browser */
742 if (*tc.dirfilter < NUM_FILTER_MODES)
Linus Nielsen Feltzingf97756e2003-11-04 16:47:05 +0000743 {
Linus Nielsen Feltzing0ab1a3b2008-04-03 13:38:24 +0000744 if (quick_screen_f3(ACTION_F3))
Jens Arnold8f664222005-05-16 12:07:25 +0000745 reload_dir = true;
Linus Nielsen Feltzingf97756e2003-11-04 16:47:05 +0000746 restore = true;
747 }
Björn Stenbergfb00c212004-05-21 20:08:24 +0000748 break;
Björn Stenberg2b816de2004-10-05 00:08:04 +0000749#endif
750
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000751 case ACTION_STD_CONTEXT:
Björn Stenberg2b816de2004-10-05 00:08:04 +0000752 {
753 int onplay_result;
Björn Stenberg30d8f612005-01-20 16:24:26 +0000754 int attr = 0;
Björn Stenberg2b816de2004-10-05 00:08:04 +0000755
756 if(!numentries)
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000757 onplay_result = onplay(NULL, 0, curr_context);
Björn Stenberg2b816de2004-10-05 00:08:04 +0000758 else {
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000759#ifdef HAVE_TAGCACHE
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000760 if (id3db)
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000761 {
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000762 if (tagtree_get_attr(&tc) == FILE_ATTR_AUDIO)
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000763 {
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000764 attr = FILE_ATTR_AUDIO;
Hardeep Sidhua85b23f2006-05-05 07:01:43 +0000765 tagtree_get_filename(&tc, buf, sizeof(buf));
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000766 }
Miika Pekkarinen4e6c79b2006-07-25 07:41:00 +0000767 else
768 attr = ATTR_DIRECTORY;
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000769 }
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000770 else
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000771#endif
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000772 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000773 attr = dircache[tc.selected_item].attr;
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000774
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000775 if (currdir[1]) /* Not in / */
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000776 snprintf(buf, sizeof buf, "%s/%s",
777 currdir,
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000778 dircache[tc.selected_item].name);
779 else /* In / */
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000780 snprintf(buf, sizeof buf, "/%s",
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000781 dircache[tc.selected_item].name);
Linus Nielsen Feltzing196376c2005-08-30 07:52:36 +0000782 }
Linus Nielsen Feltzing6e0436f2005-06-23 01:31:26 +0000783 onplay_result = onplay(buf, attr, curr_context);
Björn Stenberg2b816de2004-10-05 00:08:04 +0000784 }
Björn Stenberg2b816de2004-10-05 00:08:04 +0000785 switch (onplay_result)
786 {
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000787 case ONPLAY_MAINMENU:
788 return GO_TO_ROOT;
789
Björn Stenberg2b816de2004-10-05 00:08:04 +0000790 case ONPLAY_OK:
791 restore = true;
792 break;
793
794 case ONPLAY_RELOAD_DIR:
795 reload_dir = true;
796 break;
797
798 case ONPLAY_START_PLAY:
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000799 return GO_TO_WPS;
Björn Stenberg2b816de2004-10-05 00:08:04 +0000800 break;
801 }
802 break;
803 }
Markus Braunde8fbf02002-08-07 10:35:26 +0000804
Jörg Hohensohn70bf5162005-01-28 23:02:05 +0000805#ifdef HAVE_HOTSWAP
806 case SYS_FS_CHANGED:
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000807#ifdef HAVE_TAGCACHE
Jens Arnoldeb8cead2005-05-14 23:48:18 +0000808 if (!id3db)
Jonathan Gordon710ccb72006-10-25 10:17:57 +0000809#endif
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000810 reload_dir = true;
Jens Arnoldeb8cead2005-05-14 23:48:18 +0000811 /* The 'dir no longer valid' situation will be caught later
812 * by checking the showdir() result. */
Jörg Hohensohn70bf5162005-01-28 23:02:05 +0000813 break;
814#endif
815
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000816 default:
Linus Nielsen Feltzing74353a72005-09-14 09:07:05 +0000817 if (default_event_handler(button) == SYS_USB_CONNECTED)
Jens Arnoldd203d4b2004-10-24 23:19:13 +0000818 {
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000819 if(*tc.dirfilter > NUM_FILTER_MODES)
Jens Arnoldd203d4b2004-10-24 23:19:13 +0000820 /* leave sub-browsers after usb, doing otherwise
821 might be confusing to the user */
822 exit_func = true;
823 else
Jens Arnold7067f182005-05-16 11:50:46 +0000824 reload_dir = true;
Jens Arnoldd203d4b2004-10-24 23:19:13 +0000825 }
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000826 break;
Björn Stenberg82182852002-05-16 12:53:40 +0000827 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000828 if (start_wps)
829 return GO_TO_WPS;
Jonathan Gordon36531c72009-01-01 13:12:37 +0000830 if (button && !IS_SYSEVENT(button))
Björn Stenberg2b816de2004-10-05 00:08:04 +0000831 {
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000832 storage_spin();
Björn Stenberg2b816de2004-10-05 00:08:04 +0000833 }
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +0000834
Björn Stenberga108ec22004-01-14 00:13:04 +0000835
Jens Arnoldeb8cead2005-05-14 23:48:18 +0000836 check_rescan:
Björn Stenberg0ad20102002-09-03 20:47:23 +0000837 /* do we need to rescan dir? */
Daniel Stenbergd3d29052003-03-07 08:10:10 +0000838 if (reload_dir || reload_root ||
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000839 lastfilter != *tc.dirfilter ||
Björn Stenberga7dcf912002-09-24 19:12:09 +0000840 lastsortcase != global_settings.sort_case)
Björn Stenberg0ad20102002-09-03 20:47:23 +0000841 {
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000842 if (reload_root) {
Björn Stenberg0ad20102002-09-03 20:47:23 +0000843 strcpy(currdir, "/");
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000844 tc.dirlevel = 0;
Jonathan Gordon2f4521e2007-02-06 13:25:57 +0000845#ifdef HAVE_TAGCACHE
Jens Arnold04ed4082005-04-26 19:23:47 +0000846 tc.currtable = 0;
847 tc.currextra = 0;
848 lasttable = -1;
849 lastextra = -1;
Jonathan Gordon2f4521e2007-02-06 13:25:57 +0000850#endif
Björn Stenberg0ad20102002-09-03 20:47:23 +0000851 reload_root = false;
852 }
Zakk Roberts2f943b02006-04-10 03:51:17 +0000853
Nils Wallméniusade8ae92007-11-20 13:53:29 +0000854 if (!reload_dir)
Daniel Stenbergd3d29052003-03-07 08:10:10 +0000855 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000856 gui_synclist_select_item(&tree_lists, 0);
857 gui_synclist_draw(&tree_lists);
858 tc.selected_item = 0;
Daniel Stenbergd3d29052003-03-07 08:10:10 +0000859 lastdir[0] = 0;
860 }
Björn Stenbergde5477c2003-09-29 21:26:53 +0000861
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000862 lastfilter = *tc.dirfilter;
Björn Stenberg0ad20102002-09-03 20:47:23 +0000863 lastsortcase = global_settings.sort_case;
Björn Stenberg0ad20102002-09-03 20:47:23 +0000864 restore = true;
865 }
866
Björn Stenbergde5477c2003-09-29 21:26:53 +0000867 if (exit_func)
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000868 return GO_TO_PREVIOUS;
Björn Stenbergde5477c2003-09-29 21:26:53 +0000869
Björn Stenbergcaebdd42003-01-15 14:52:53 +0000870 if (restore || reload_dir) {
Björn Stenbergbb9aaf52002-06-25 13:26:04 +0000871 /* restore display */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000872 numentries = update_dir();
Stéphane Doyon8e82a902007-10-21 00:20:51 +0000873 reload_dir = false;
Jens Arnold7067f182005-05-16 11:50:46 +0000874 if (currdir[1] && (numentries < 0))
Jens Arnoldeb8cead2005-05-14 23:48:18 +0000875 { /* not in root and reload failed */
876 reload_root = true; /* try root */
Jens Arnoldeb8cead2005-05-14 23:48:18 +0000877 goto check_rescan;
878 }
Markus Braunde8fbf02002-08-07 10:35:26 +0000879 }
Björn Stenberg82182852002-05-16 12:53:40 +0000880 }
Mats Lidell816bc8c2003-01-31 08:43:12 +0000881 return true;
Björn Stenberg82182852002-05-16 12:53:40 +0000882}
Björn Stenbergefb165f2003-01-29 13:20:22 +0000883
Björn Stenbergefb165f2003-01-29 13:20:22 +0000884bool create_playlist(void)
885{
Björn Stenbergefb165f2003-01-29 13:20:22 +0000886 char filename[MAX_PATH];
887
Marcoen Hirschbergd3591932006-12-21 09:07:23 +0000888 snprintf(filename, sizeof filename, "%s.m3u8",
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000889 tc.currdir[1] ? tc.currdir : "/root");
Nils Wallménius01729e72008-08-15 08:27:39 +0000890 splashf(0, "%s %s", str(LANG_CREATING), filename);
Björn Stenbergefb165f2003-01-29 13:20:22 +0000891
Brandon Low8a828922006-11-11 05:33:24 +0000892 trigger_cpu_boost();
Jonathan Gordon517aca82008-05-04 13:01:16 +0000893 catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
Michael Sevakisfadbf0a2007-11-20 03:44:25 +0000894 cancel_cpu_boost();
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +0000895
Linus Nielsen Feltzing887e2172003-03-21 03:07:31 +0000896 return true;
Björn Stenbergefb165f2003-01-29 13:20:22 +0000897}
Linus Nielsen Feltzing20d031f2003-05-09 16:01:21 +0000898
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000899int rockbox_browse(const char *root, int dirfilter)
Björn Stenbergde5477c2003-09-29 21:26:53 +0000900{
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000901 int ret_val = 0;
902 int *last_filter = tc.dirfilter;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000903 tc.dirfilter = &dirfilter;
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000904 tc.sort_dir = global_settings.sort_dir;
Miika Pekkarinen7e84db72006-08-14 18:19:56 +0000905
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000906 reload_dir = true;
907 if (dirfilter >= NUM_FILTER_MODES)
908 {
909 static struct tree_context backup;
910 int last_context;
911
912 backup = tc;
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000913 tc.selected_item = 0;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000914 tc.dirlevel = 0;
915 memcpy(tc.currdir, root, sizeof(tc.currdir));
916 start_wps = false;
917 last_context = curr_context;
918
919 ret_val = dirbrowse();
920 tc = backup;
921 curr_context = last_context;
922 }
923 else
924 {
925 static char buf[MAX_PATH];
926 if (dirfilter != SHOW_ID3DB)
927 tc.dirfilter = &global_settings.dirfilter;
928 strcpy(buf,root);
929 set_current_file(buf);
930 ret_val = dirbrowse();
931 }
932 tc.dirfilter = last_filter;
933 return ret_val;
Björn Stenbergde5477c2003-09-29 21:26:53 +0000934}
935
Jonathan Gordon2cda9942007-06-10 10:41:27 +0000936void tree_mem_init(void)
Linus Nielsen Feltzing20d031f2003-05-09 16:01:21 +0000937{
Björn Stenberga50cc0b2005-01-17 12:56:00 +0000938 /* We copy the settings value in case it is changed by the user. We can't
939 use it until the next reboot. */
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000940 max_files = global_settings.max_files_in_dir;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000941
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000942 /* initialize tree context struct */
943 memset(&tc, 0, sizeof(tc));
944 tc.dirfilter = &global_settings.dirfilter;
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000945 tc.sort_dir = global_settings.sort_dir;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000946
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000947 tc.name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files;
948 tc.name_buffer = buffer_alloc(tc.name_buffer_size);
949
950 tc.dircache_size = max_files * sizeof(struct entry);
951 tc.dircache = buffer_alloc(tc.dircache_size);
Jonathan Gordon36a2e302007-04-18 13:03:01 +0000952 tree_get_filetypes(&filetypes, &filetypes_count);
Linus Nielsen Feltzing20d031f2003-05-09 16:01:21 +0000953}
Björn Stenberga108ec22004-01-14 00:13:04 +0000954
Magnus Holmgren04dc8282008-02-10 12:16:27 +0000955bool bookmark_play(char *resume_file, int index, int offset, int seed,
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +0000956 char *filename)
Björn Stenberga108ec22004-01-14 00:13:04 +0000957{
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +0000958 int i;
Magnus Holmgrenf19d17b2006-09-21 18:57:54 +0000959 char* suffix = strrchr(resume_file, '.');
Magnus Holmgren04dc8282008-02-10 12:16:27 +0000960 bool started = false;
Björn Stenberga108ec22004-01-14 00:13:04 +0000961
Magnus Holmgrenf19d17b2006-09-21 18:57:54 +0000962 if (suffix != NULL &&
963 (!strcasecmp(suffix, ".m3u") || !strcasecmp(suffix, ".m3u8")))
Björn Stenberga108ec22004-01-14 00:13:04 +0000964 {
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +0000965 /* Playlist playback */
Björn Stenberga108ec22004-01-14 00:13:04 +0000966 char* slash;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000967 /* check that the file exists */
Nils Wallméniusa0199642008-04-16 19:51:43 +0000968 if(!file_exists(resume_file))
Magnus Holmgren04dc8282008-02-10 12:16:27 +0000969 return false;
Björn Stenberga108ec22004-01-14 00:13:04 +0000970
971 slash = strrchr(resume_file,'/');
972 if (slash)
973 {
974 char* cp;
975 *slash=0;
976
977 cp=resume_file;
978 if (!cp[0])
979 cp="/";
980
981 if (playlist_create(cp, slash+1) != -1)
982 {
983 if (global_settings.playlist_shuffle)
984 playlist_shuffle(seed, -1);
985 playlist_start(index,offset);
Magnus Holmgren04dc8282008-02-10 12:16:27 +0000986 started = true;
Björn Stenberga108ec22004-01-14 00:13:04 +0000987 }
988 *slash='/';
989 }
990 }
991 else
992 {
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +0000993 /* Directory playback */
Björn Stenberga108ec22004-01-14 00:13:04 +0000994 lastdir[0]='\0';
995 if (playlist_create(resume_file, NULL) != -1)
996 {
Magnus Holmgrenec88dff2007-04-12 19:11:39 +0000997 char* peek_filename;
Björn Stenberga108ec22004-01-14 00:13:04 +0000998 resume_directory(resume_file);
999 if (global_settings.playlist_shuffle)
1000 playlist_shuffle(seed, -1);
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +00001001
1002 /* Check if the file is at the same spot in the directory,
1003 else search for it */
Magnus Holmgrenec88dff2007-04-12 19:11:39 +00001004 peek_filename = playlist_peek(index);
1005
1006 if (peek_filename == NULL)
Magnus Holmgren04dc8282008-02-10 12:16:27 +00001007 return false;
Magnus Holmgrenec88dff2007-04-12 19:11:39 +00001008
1009 if (strcmp(strrchr(peek_filename, '/') + 1, filename))
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +00001010 {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +00001011 for ( i=0; i < playlist_amount(); i++ )
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +00001012 {
Magnus Holmgrenec88dff2007-04-12 19:11:39 +00001013 peek_filename = playlist_peek(i);
1014
1015 if (peek_filename == NULL)
Magnus Holmgren04dc8282008-02-10 12:16:27 +00001016 return false;
Magnus Holmgrenec88dff2007-04-12 19:11:39 +00001017
1018 if (!strcmp(strrchr(peek_filename, '/') + 1, filename))
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +00001019 break;
1020 }
1021 if (i < playlist_amount())
1022 index = i;
1023 else
Magnus Holmgren04dc8282008-02-10 12:16:27 +00001024 return false;
Linus Nielsen Feltzing8f032ae2004-12-07 14:20:37 +00001025 }
Björn Stenberga108ec22004-01-14 00:13:04 +00001026 playlist_start(index,offset);
Magnus Holmgren04dc8282008-02-10 12:16:27 +00001027 started = true;
Björn Stenberga108ec22004-01-14 00:13:04 +00001028 }
1029 }
1030
Magnus Holmgren04dc8282008-02-10 12:16:27 +00001031 if (started)
1032 start_wps = true;
1033 return started;
Björn Stenberga108ec22004-01-14 00:13:04 +00001034}
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001035
Stéphane Doyon8e82a902007-10-21 00:20:51 +00001036static void say_filetype(int attr)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001037{
1038 /* try to find a voice ID for the extension, if known */
Jonathan Gordon36a2e302007-04-18 13:03:01 +00001039 int j;
Stéphane Doyon8e82a902007-10-21 00:20:51 +00001040 attr &= FILE_ATTR_MASK; /* file type */
Jonathan Gordon36a2e302007-04-18 13:03:01 +00001041 for (j=0; j<filetypes_count; j++)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001042 if (attr == filetypes[j].tree_attr)
1043 {
Stéphane Doyon8e82a902007-10-21 00:20:51 +00001044 talk_id(filetypes[j].voiceclip, true);
1045 return;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001046 }
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001047}
1048
Nils Wallménius685f6bb2007-03-17 00:55:23 +00001049static int ft_play_dirname(char* name)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001050{
Linus Nielsen Feltzing30c618c2006-08-01 22:02:47 +00001051#if CONFIG_CODEC != SWCODEC
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +00001052 if (audio_status() & AUDIO_STATUS_PLAY)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001053 return 0;
Linus Nielsen Feltzing30c618c2006-08-01 22:02:47 +00001054#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001055
Stéphane Doyon3eb76d02008-07-15 14:55:31 +00001056 if(talk_file(tc.currdir, name, dir_thumbnail_name, NULL,
1057 NULL, false))
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001058 {
Stéphane Doyon3eb76d02008-07-15 14:55:31 +00001059 if(global_settings.talk_filetype)
1060 talk_id(VOICE_DIR, true);
1061 return 1;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001062 }
Stéphane Doyon3eb76d02008-07-15 14:55:31 +00001063 else
1064 return -1;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001065}
1066
Nils Wallménius685f6bb2007-03-17 00:55:23 +00001067static void ft_play_filename(char *dir, char *file)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001068{
Linus Nielsen Feltzing30c618c2006-08-01 22:02:47 +00001069#if CONFIG_CODEC != SWCODEC
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +00001070 if (audio_status() & AUDIO_STATUS_PLAY)
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001071 return;
Linus Nielsen Feltzing30c618c2006-08-01 22:02:47 +00001072#endif
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001073
Steve Bavin8a813fd2008-09-02 08:15:44 +00001074 if (strlen(file) >= strlen(file_thumbnail_ext)
Stéphane Doyon3eb76d02008-07-15 14:55:31 +00001075 && strcasecmp(&file[strlen(file) - strlen(file_thumbnail_ext)],
1076 file_thumbnail_ext))
1077 /* file has no .talk extension */
1078 talk_file(dir, NULL, file, file_thumbnail_ext,
1079 NULL, false);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001080 else
Stéphane Doyon3eb76d02008-07-15 14:55:31 +00001081 /* it already is a .talk file, play this directly, but prefix it. */
1082 talk_file(dir, NULL, file, NULL,
1083 TALK_IDARRAY(LANG_VOICE_DIR_HOVER), false);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +00001084}
1085
Linus Nielsen Feltzing74353a72005-09-14 09:07:05 +00001086/* These two functions are called by the USB and shutdown handlers */
1087void tree_flush(void)
1088{
Jonathan Gordon710ccb72006-10-25 10:17:57 +00001089#ifdef HAVE_TAGCACHE
Miika Pekkarinen6ee82e72006-09-23 10:29:14 +00001090 tagcache_shutdown();
Jonathan Gordon710ccb72006-10-25 10:17:57 +00001091#endif
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +00001092
Miika Pekkarinenc2eb67b2006-08-09 07:41:28 +00001093#ifdef HAVE_TC_RAMCACHE
1094 tagcache_unload_ramcache();
1095#endif
Miika Pekkarinen3b52bb92006-08-11 10:13:16 +00001096
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001097#ifdef HAVE_DIRCACHE
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001098 {
Jonathan Gordon228d62d2007-01-24 02:19:22 +00001099 int old_val = global_status.dircache_size;
Jonathan Gordon65811462006-12-12 10:45:34 +00001100 if (global_settings.dircache)
1101 {
Magnus Holmgren7d345652007-10-07 12:05:48 +00001102 if (!dircache_is_initializing())
1103 global_status.dircache_size = dircache_get_cache_size();
Peter D'Hoyec4a59a22006-08-15 22:54:06 +00001104# ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinen7b1e8272007-04-07 17:48:51 +00001105 if (firmware_settings.initialized)
1106 dircache_save();
Miika Pekkarinen954b7322006-08-05 20:19:10 +00001107# endif
Jonathan Gordon65811462006-12-12 10:45:34 +00001108 dircache_disable();
1109 }
1110 else
1111 {
Jonathan Gordon228d62d2007-01-24 02:19:22 +00001112 global_status.dircache_size = 0;
Jonathan Gordon65811462006-12-12 10:45:34 +00001113 }
Jonathan Gordon228d62d2007-01-24 02:19:22 +00001114 if (old_val != global_status.dircache_size)
1115 status_save();
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001116 }
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001117#endif
Linus Nielsen Feltzing74353a72005-09-14 09:07:05 +00001118}
1119
1120void tree_restore(void)
1121{
Peter D'Hoyec4a59a22006-08-15 22:54:06 +00001122#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinenc2eb67b2006-08-09 07:41:28 +00001123 firmware_settings.disk_clean = false;
1124#endif
1125
Miika Pekkarinen3b52bb92006-08-11 10:13:16 +00001126#ifdef HAVE_TC_RAMCACHE
1127 remove(TAGCACHE_STATEFILE);
1128#endif
1129
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001130#ifdef HAVE_DIRCACHE
Miika Pekkarinen954b7322006-08-05 20:19:10 +00001131 remove(DIRCACHE_FILE);
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001132 if (global_settings.dircache)
Miika Pekkarinen57b25ca2005-10-19 11:34:32 +00001133 {
1134 /* Print "Scanning disk..." to the display. */
Nils Wallménius01729e72008-08-15 08:27:39 +00001135 splash(0, str(LANG_SCANNING_DISK));
Dave Chapman74443712005-11-02 12:05:33 +00001136
Jonathan Gordon228d62d2007-01-24 02:19:22 +00001137 dircache_build(global_status.dircache_size);
Miika Pekkarinen57b25ca2005-10-19 11:34:32 +00001138 }
Miika Pekkarinenab78b042005-10-07 17:38:05 +00001139#endif
Jonathan Gordon710ccb72006-10-25 10:17:57 +00001140#ifdef HAVE_TAGCACHE
Miika Pekkarinenebd3d082006-07-12 16:07:27 +00001141 tagcache_start_scan();
Jonathan Gordon710ccb72006-10-25 10:17:57 +00001142#endif
Linus Nielsen Feltzing74353a72005-09-14 09:07:05 +00001143}