1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include <applimits.h>
30 /* keep this struct compatible (total size and name member)
31 * with struct tagtree_entry (tagtree.h) */
34 int attr
; /* FAT attributes + file type flags */
35 unsigned time_write
; /* Last write time */
38 #define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */
39 #define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */
40 #define BROWSE_RUNFILE 0x0004 /* do ft_open() on the file instead of browsing */
41 #define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */
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 */
58 struct browse_context
{
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 */
73 /* browser context for file or db */
75 /* The directory we are browsing */
76 char currdir
[MAX_PATH
];
77 /* the number of directories we have crossed from / */
79 /* The currently selected file/id3dbitem index (old dircursor+dirfile) */
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
];
85 int firstpos
; /* which dir entry is on first
86 position in dir buffer */
87 int pos_history
[MAX_DIR_LEVELS
];
89 int *dirfilter
; /* file use */
90 int filesindir
; /* The number of files in the dircache */
91 int dirsindir
; /* file use */
92 int dirlength
; /* total number of entries in dir, incl. those not loaded */
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 */
99 struct tree_cache cache
;
101 int sort_dir
; /* directory sort order */
102 struct browse_context
*browse
;
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
);
109 void tree_mem_init(void) INIT_ATTR
;
110 void tree_gui_init(void) INIT_ATTR
;
111 char* get_current_file(char* buffer
, size_t buffer_len
);
112 void set_dirfilter(int l_dirfilter
);
113 void set_current_file(const char *path
);
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
);
119 bool create_playlist(void);
120 void resume_directory(const char *dir
);
121 static inline void tree_lock_cache(struct tree_context
*t
)
123 t
->cache
.lock_count
++;
125 static inline void tree_unlock_cache(struct tree_context
*t
)
127 t
->cache
.lock_count
--;
130 /* it takes an int on windows */
131 #define getcwd_size_t int
133 #define getcwd_size_t size_t
135 char *getcwd(char *buf
, getcwd_size_t size
);
136 void reload_directory(void);
137 bool check_rockboxdir(void);
138 struct tree_context
* tree_get_context(void);
139 void tree_flush(void);
140 void tree_restore(void);
142 bool bookmark_play(char* resume_file
, int index
, int offset
, int seed
,
145 extern struct gui_synclist tree_lists
;