blob: 1601447b5878cb7e557d1ba0526845b2ff88dffd [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 ****************************************************************************/
21#ifndef _TREE_H_
22#define _TREE_H_
23
24#include <stdbool.h>
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000025#include <applimits.h>
26#include <file.h>
Boris Gjenerofdc29d02011-12-19 20:12:52 +000027#include "config.h"
Teruaki Kawashima08af5d82010-12-14 13:37:58 +000028#include "icon.h"
Björn Stenberg82182852002-05-16 12:53:40 +000029
Thomas Martitzbaa070c2011-08-30 14:01:45 +000030/* keep this struct compatible (total size and name member)
31 * with struct tagtree_entry (tagtree.h) */
Hardeep Sidhu9e426202003-07-01 21:05:43 +000032struct entry {
Hardeep Sidhu9e426202003-07-01 21:05:43 +000033 char *name;
Thomas Martitzbaa070c2011-08-30 14:01:45 +000034 int attr; /* FAT attributes + file type flags */
35 unsigned time_write; /* Last write time */
Hardeep Sidhu9e426202003-07-01 21:05:43 +000036};
37
Alexander Levin794bda72010-12-15 18:14:13 +000038#define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */
39#define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */
Jonathan Gordon101693f2011-11-15 13:22:02 +000040#define BROWSE_RUNFILE 0x0004 /* do ft_open() on the file instead of browsing */
Alexander Levin794bda72010-12-15 18:14:13 +000041#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */
Teruaki Kawashima08af5d82010-12-14 13:37:58 +000042
Jonathan Gordon101693f2011-11-15 13:22:02 +000043
Teruaki Kawashima08af5d82010-12-14 13:37:58 +000044struct tree_context;
Thomas Martitzbaa070c2011-08-30 14:01:45 +000045
Thomas Martitz98096972011-08-03 09:49:25 +000046struct tree_cache {
Thomas Martitzbaa070c2011-08-30 14:01:45 +000047 /* 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 Martitz98096972011-08-03 09:49:25 +000056};
Teruaki Kawashima08af5d82010-12-14 13:37:58 +000057
58struct 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 Stenberg8a5de5f2005-01-17 11:39:46 +000073/* browser context for file or db */
74struct tree_context {
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000075 /* The directory we are browsing */
76 char currdir[MAX_PATH];
77 /* the number of directories we have crossed from / */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000078 int dirlevel;
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000079 /* 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 Stenberg84c7d8802005-01-18 22:45:00 +000085 int firstpos; /* which dir entry is on first
86 position in dir buffer */
87 int pos_history[MAX_DIR_LEVELS];
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000088
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000089 int *dirfilter; /* file use */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000090 int filesindir; /* The number of files in the dircache */
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000091 int dirsindir; /* file use */
Björn Stenberg84c7d8802005-01-18 22:45:00 +000092 int dirlength; /* total number of entries in dir, incl. those not loaded */
Jonathan Gordon2f4521e2007-02-06 13:25:57 +000093#ifdef HAVE_TAGCACHE
Björn Stenberg8a5de5f2005-01-17 11:39:46 +000094 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 Gordon2f4521e2007-02-06 13:25:57 +000098#endif
Thomas Martitz98096972011-08-03 09:49:25 +000099 struct tree_cache cache;
Björn Stenberg84c7d8802005-01-18 22:45:00 +0000100 bool dirfull;
Nils Wallménius48b52ae2008-10-08 16:32:01 +0000101 int sort_dir; /* directory sort order */
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000102 struct browse_context *browse;
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000103};
Björn Stenbergd7a55e12003-03-12 20:21:30 +0000104
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000105/*
106 * Call one of the two below after yields since the entrys may move inbetween */
107struct entry* tree_get_entries(struct tree_context *t);
108struct entry* tree_get_entry_at(struct tree_context *t, int index);
Thomas Martitzf8edc322010-03-03 23:20:32 +0000109void tree_mem_init(void) INIT_ATTR;
110void tree_gui_init(void) INIT_ATTR;
Thomas Martitz79798ff2010-08-27 10:33:09 +0000111char* get_current_file(char* buffer, size_t buffer_len);
Jonathan Gordonef815722007-08-05 12:14:07 +0000112void set_dirfilter(int l_dirfilter);
Teruaki Kawashima368e89e2010-10-22 12:50:14 +0000113void set_current_file(const char *path);
Teruaki Kawashima08af5d82010-12-14 13:37:58 +0000114void 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);
118int rockbox_browse(struct browse_context *browse);
Björn Stenbergefb165f2003-01-29 13:20:22 +0000119bool create_playlist(void);
Jens Arnold8fb33612004-08-18 01:09:31 +0000120void resume_directory(const char *dir);
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000121static inline void tree_lock_cache(struct tree_context *t)
122{
123 t->cache.lock_count++;
124}
125static inline void tree_unlock_cache(struct tree_context *t)
126{
127 t->cache.lock_count--;
128}
Thomas Martitz2c2e2612010-08-27 12:38:25 +0000129#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
135char *getcwd(char *buf, getcwd_size_t size);
Hardeep Sidhu9e426202003-07-01 21:05:43 +0000136void reload_directory(void);
Henrik Backe66b45ee2004-09-10 20:51:12 +0000137bool check_rockboxdir(void);
Björn Stenberg8a5de5f2005-01-17 11:39:46 +0000138struct tree_context* tree_get_context(void);
Linus Nielsen Feltzing74353a72005-09-14 09:07:05 +0000139void tree_flush(void);
140void tree_restore(void);
Björn Stenberg82182852002-05-16 12:53:40 +0000141
Michael Sevakis31b71222013-07-14 07:59:39 -0400142bool bookmark_play(char* resume_file, int index, unsigned long elapsed,
143 unsigned long offset, int seed, char *filename);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000144
145extern struct gui_synclist tree_lists;
Björn Stenberg82182852002-05-16 12:53:40 +0000146#endif