Björn Stenberg | 8218285 | 2002-05-16 12:53:40 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 Daniel Stenberg |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Björn Stenberg | 8218285 | 2002-05-16 12:53:40 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #ifndef _TREE_H_ |
| 22 | #define _TREE_H_ |
| 23 | |
| 24 | #include <stdbool.h> |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 25 | #include <applimits.h> |
| 26 | #include <file.h> |
Boris Gjenero | fdc29d0 | 2011-12-19 20:12:52 +0000 | [diff] [blame] | 27 | #include "config.h" |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 28 | #include "icon.h" |
Björn Stenberg | 8218285 | 2002-05-16 12:53:40 +0000 | [diff] [blame] | 29 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 30 | /* keep this struct compatible (total size and name member) |
| 31 | * with struct tagtree_entry (tagtree.h) */ |
Hardeep Sidhu | 9e42620 | 2003-07-01 21:05:43 +0000 | [diff] [blame] | 32 | struct entry { |
Hardeep Sidhu | 9e42620 | 2003-07-01 21:05:43 +0000 | [diff] [blame] | 33 | char *name; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 34 | int attr; /* FAT attributes + file type flags */ |
| 35 | unsigned time_write; /* Last write time */ |
Hardeep Sidhu | 9e42620 | 2003-07-01 21:05:43 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Alexander Levin | 794bda7 | 2010-12-15 18:14:13 +0000 | [diff] [blame] | 38 | #define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */ |
| 39 | #define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */ |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 40 | #define BROWSE_RUNFILE 0x0004 /* do ft_open() on the file instead of browsing */ |
Alexander Levin | 794bda7 | 2010-12-15 18:14:13 +0000 | [diff] [blame] | 41 | #define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */ |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 42 | |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 43 | |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 44 | struct tree_context; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 45 | |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 46 | struct tree_cache { |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 47 | /* A big buffer with plenty of entry structs, contains all files and dirs |
| 48 | * in the current dir (with filters applied) |
| 49 | * Note that they're buflib-allocated and can therefore possibly move |
| 50 | * They need to be locked if used around yielding functions */ |
| 51 | int entries_handle; /* handle to the entry cache */ |
| 52 | int name_buffer_handle; /* handle to the name cache */ |
| 53 | int max_entries; /* Max entries in the cache */ |
| 54 | int name_buffer_size; /* in bytes */ |
| 55 | volatile int lock_count; /* non-0 if buffers may not move */ |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 56 | }; |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 57 | |
| 58 | struct browse_context { |
| 59 | int dirfilter; |
| 60 | unsigned flags; /* ored BROWSE_* */ |
| 61 | bool (*callback_show_item)(char *name, int attr, struct tree_context *tc); |
| 62 | /* callback function to determine to show/hide |
| 63 | the item for custom browser */ |
| 64 | char *title; /* title of the browser. if set to NULL, |
| 65 | directory name is used. */ |
| 66 | enum themable_icons icon; /* title icon */ |
| 67 | const char *root; /* full path of start directory */ |
| 68 | const char *selected; /* name of selected file in the root */ |
| 69 | char *buf; /* buffer to store selected file */ |
| 70 | size_t bufsize; /* size of the buffer */ |
| 71 | }; |
| 72 | |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 73 | /* browser context for file or db */ |
| 74 | struct tree_context { |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 75 | /* The directory we are browsing */ |
| 76 | char currdir[MAX_PATH]; |
| 77 | /* the number of directories we have crossed from / */ |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 78 | int dirlevel; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 79 | /* The currently selected file/id3dbitem index (old dircursor+dirfile) */ |
| 80 | int selected_item; |
| 81 | /* The selected item in each directory crossed |
| 82 | * (used when we want to return back to a previouws directory)*/ |
| 83 | int selected_item_history[MAX_DIR_LEVELS]; |
| 84 | |
Björn Stenberg | 84c7d880 | 2005-01-18 22:45:00 +0000 | [diff] [blame] | 85 | int firstpos; /* which dir entry is on first |
| 86 | position in dir buffer */ |
| 87 | int pos_history[MAX_DIR_LEVELS]; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 88 | |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 89 | int *dirfilter; /* file use */ |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 90 | int filesindir; /* The number of files in the dircache */ |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 91 | int dirsindir; /* file use */ |
Björn Stenberg | 84c7d880 | 2005-01-18 22:45:00 +0000 | [diff] [blame] | 92 | int dirlength; /* total number of entries in dir, incl. those not loaded */ |
Jonathan Gordon | 2f4521e | 2007-02-06 13:25:57 +0000 | [diff] [blame] | 93 | #ifdef HAVE_TAGCACHE |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 94 | int table_history[MAX_DIR_LEVELS]; /* db use */ |
| 95 | int extra_history[MAX_DIR_LEVELS]; /* db use */ |
| 96 | int currtable; /* db use */ |
| 97 | int currextra; /* db use */ |
Jonathan Gordon | 2f4521e | 2007-02-06 13:25:57 +0000 | [diff] [blame] | 98 | #endif |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 99 | struct tree_cache cache; |
Björn Stenberg | 84c7d880 | 2005-01-18 22:45:00 +0000 | [diff] [blame] | 100 | bool dirfull; |
Nils Wallménius | 48b52ae | 2008-10-08 16:32:01 +0000 | [diff] [blame] | 101 | int sort_dir; /* directory sort order */ |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 102 | struct browse_context *browse; |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 103 | }; |
Björn Stenberg | d7a55e1 | 2003-03-12 20:21:30 +0000 | [diff] [blame] | 104 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 105 | /* |
| 106 | * Call one of the two below after yields since the entrys may move inbetween */ |
| 107 | struct entry* tree_get_entries(struct tree_context *t); |
| 108 | struct entry* tree_get_entry_at(struct tree_context *t, int index); |
Thomas Martitz | f8edc32 | 2010-03-03 23:20:32 +0000 | [diff] [blame] | 109 | void tree_mem_init(void) INIT_ATTR; |
| 110 | void tree_gui_init(void) INIT_ATTR; |
Thomas Martitz | 79798ff | 2010-08-27 10:33:09 +0000 | [diff] [blame] | 111 | char* get_current_file(char* buffer, size_t buffer_len); |
Jonathan Gordon | ef81572 | 2007-08-05 12:14:07 +0000 | [diff] [blame] | 112 | void set_dirfilter(int l_dirfilter); |
Teruaki Kawashima | 368e89e | 2010-10-22 12:50:14 +0000 | [diff] [blame] | 113 | void set_current_file(const char *path); |
Teruaki Kawashima | 08af5d8 | 2010-12-14 13:37:58 +0000 | [diff] [blame] | 114 | void browse_context_init(struct browse_context *browse, |
| 115 | int dirfilter, unsigned flags, |
| 116 | char *title, enum themable_icons icon, |
| 117 | const char *root, const char *selected); |
| 118 | int rockbox_browse(struct browse_context *browse); |
Björn Stenberg | efb165f | 2003-01-29 13:20:22 +0000 | [diff] [blame] | 119 | bool create_playlist(void); |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 120 | void resume_directory(const char *dir); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 121 | static inline void tree_lock_cache(struct tree_context *t) |
| 122 | { |
| 123 | t->cache.lock_count++; |
| 124 | } |
| 125 | static inline void tree_unlock_cache(struct tree_context *t) |
| 126 | { |
| 127 | t->cache.lock_count--; |
| 128 | } |
Thomas Martitz | 2c2e261 | 2010-08-27 12:38:25 +0000 | [diff] [blame] | 129 | #ifdef WIN32 |
| 130 | /* it takes an int on windows */ |
| 131 | #define getcwd_size_t int |
| 132 | #else |
| 133 | #define getcwd_size_t size_t |
| 134 | #endif |
| 135 | char *getcwd(char *buf, getcwd_size_t size); |
Hardeep Sidhu | 9e42620 | 2003-07-01 21:05:43 +0000 | [diff] [blame] | 136 | void reload_directory(void); |
Henrik Backe | 66b45ee | 2004-09-10 20:51:12 +0000 | [diff] [blame] | 137 | bool check_rockboxdir(void); |
Björn Stenberg | 8a5de5f | 2005-01-17 11:39:46 +0000 | [diff] [blame] | 138 | struct tree_context* tree_get_context(void); |
Linus Nielsen Feltzing | 74353a7 | 2005-09-14 09:07:05 +0000 | [diff] [blame] | 139 | void tree_flush(void); |
| 140 | void tree_restore(void); |
Björn Stenberg | 8218285 | 2002-05-16 12:53:40 +0000 | [diff] [blame] | 141 | |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 142 | bool bookmark_play(char* resume_file, int index, unsigned long elapsed, |
| 143 | unsigned long offset, int seed, char *filename); |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 144 | |
| 145 | extern struct gui_synclist tree_lists; |
Björn Stenberg | 8218285 | 2002-05-16 12:53:40 +0000 | [diff] [blame] | 146 | #endif |