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>
29 /* keep this struct compatible (total size and name member)
30 * with struct tagtree_entry (tagtree.h) */
33 int attr
; /* FAT attributes + file type flags */
34 unsigned time_write
; /* Last write time */
37 #define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */
38 #define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */
39 #define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */
44 /* A big buffer with plenty of entry structs, contains all files and dirs
45 * in the current dir (with filters applied)
46 * Note that they're buflib-allocated and can therefore possibly move
47 * They need to be locked if used around yielding functions */
48 int entries_handle
; /* handle to the entry cache */
49 int name_buffer_handle
; /* handle to the name cache */
50 int max_entries
; /* Max entries in the cache */
51 int name_buffer_size
; /* in bytes */
52 volatile int lock_count
; /* non-0 if buffers may not move */
55 struct browse_context
{
57 unsigned flags
; /* ored BROWSE_* */
58 bool (*callback_show_item
)(char *name
, int attr
, struct tree_context
*tc
);
59 /* callback function to determine to show/hide
60 the item for custom browser */
61 char *title
; /* title of the browser. if set to NULL,
62 directory name is used. */
63 enum themable_icons icon
; /* title icon */
64 const char *root
; /* full path of start directory */
65 const char *selected
; /* name of selected file in the root */
66 char *buf
; /* buffer to store selected file */
67 size_t bufsize
; /* size of the buffer */
70 /* browser context for file or db */
72 /* The directory we are browsing */
73 char currdir
[MAX_PATH
];
74 /* the number of directories we have crossed from / */
76 /* The currently selected file/id3dbitem index (old dircursor+dirfile) */
78 /* The selected item in each directory crossed
79 * (used when we want to return back to a previouws directory)*/
80 int selected_item_history
[MAX_DIR_LEVELS
];
82 int firstpos
; /* which dir entry is on first
83 position in dir buffer */
84 int pos_history
[MAX_DIR_LEVELS
];
86 int *dirfilter
; /* file use */
87 int filesindir
; /* The number of files in the dircache */
88 int dirsindir
; /* file use */
89 int dirlength
; /* total number of entries in dir, incl. those not loaded */
91 int table_history
[MAX_DIR_LEVELS
]; /* db use */
92 int extra_history
[MAX_DIR_LEVELS
]; /* db use */
93 int currtable
; /* db use */
94 int currextra
; /* db use */
96 struct tree_cache cache
;
98 int sort_dir
; /* directory sort order */
99 struct browse_context
*browse
;
103 * Call one of the two below after yields since the entrys may move inbetween */
104 struct entry
* tree_get_entries(struct tree_context
*t
);
105 struct entry
* tree_get_entry_at(struct tree_context
*t
, int index
);
106 void tree_drawlists(void);
107 void tree_mem_init(void) INIT_ATTR
;
108 void tree_gui_init(void) INIT_ATTR
;
109 char* get_current_file(char* buffer
, size_t buffer_len
);
110 void set_dirfilter(int l_dirfilter
);
111 void set_current_file(const char *path
);
112 void browse_context_init(struct browse_context
*browse
,
113 int dirfilter
, unsigned flags
,
114 char *title
, enum themable_icons icon
,
115 const char *root
, const char *selected
);
116 int rockbox_browse(struct browse_context
*browse
);
117 bool create_playlist(void);
118 void resume_directory(const char *dir
);
119 static inline void tree_lock_cache(struct tree_context
*t
)
121 t
->cache
.lock_count
++;
123 static inline void tree_unlock_cache(struct tree_context
*t
)
125 t
->cache
.lock_count
--;
128 /* it takes an int on windows */
129 #define getcwd_size_t int
131 #define getcwd_size_t size_t
133 char *getcwd(char *buf
, getcwd_size_t size
);
134 void reload_directory(void);
135 bool check_rockboxdir(void);
136 struct tree_context
* tree_get_context(void);
137 void tree_flush(void);
138 void tree_restore(void);
140 bool bookmark_play(char* resume_file
, int index
, int offset
, int seed
,
143 extern struct gui_synclist tree_lists
;