A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 148 lines 5.6 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2002 Daniel Stenberg 11 * 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. 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> 25#include <applimits.h> 26#include <file.h> 27#include "config.h" 28#include "icon.h" 29 30/* keep this struct compatible (total size and name member) 31 * with struct tagtree_entry (tagtree.h) */ 32struct entry { 33 char *name; 34 int attr; /* FAT attributes + file type flags */ 35 unsigned time_write; /* Last write time */ 36 #ifdef HAVE_TAGCACHE 37 int customaction; /* db use */ 38 char* album_name; /* db use */ 39 #endif 40}; 41 42#define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */ 43#define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */ 44#define BROWSE_RUNFILE 0x0004 /* do ft_open() on the file instead of browsing */ 45#define BROWSE_DIRFILTER 0x0080 /* override global_settings.dirfilter with browse_context.dirfilter */ 46#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */ 47 48 49struct tree_context; 50 51struct tree_cache { 52 /* A big buffer with plenty of entry structs, contains all files and dirs 53 * in the current dir (with filters applied) 54 * Note that they're buflib-allocated and can therefore possibly move 55 * They need to be locked if used around yielding functions */ 56 int entries_handle; /* handle to the entry cache */ 57 int name_buffer_handle; /* handle to the name cache */ 58 int max_entries; /* Max entries in the cache */ 59 int name_buffer_size; /* in bytes */ 60}; 61 62struct browse_context { 63 int dirfilter; 64 unsigned flags; /* ored BROWSE_* */ 65 bool (*callback_show_item)(char *name, int attr, struct tree_context *tc); 66 /* callback function to determine to show/hide 67 the item for custom browser */ 68 char *title; /* title of the browser. if set to NULL, 69 directory name is used. */ 70 enum themable_icons icon; /* title icon */ 71 const char *root; /* full path of start directory */ 72 const char *selected; /* name of selected file in the root */ 73 char *buf; /* buffer to store selected file */ 74 size_t bufsize; /* size of the buffer */ 75 bool disable_gui; /* disable gui for this browse */ 76}; 77 78/* browser context for file or db */ 79struct tree_context { 80 /* The directory we are browsing */ 81 char currdir[MAX_PATH]; 82 /* the number of directories we have crossed from / */ 83 int dirlevel; 84 /* The currently selected file/id3dbitem index (old dircursor+dirfile) */ 85 int selected_item; 86 /* The selected item in each directory crossed 87 * (used when we want to return back to a previouws directory)*/ 88 int selected_item_history[MAX_DIR_LEVELS]; 89 90 int *dirfilter; /* file use */ 91 int filesindir; /* The number of files in the dircache */ 92 int dirsindir; /* file use */ 93 int dirlength; /* total number of entries in dir, incl. those not loaded */ 94#ifdef HAVE_TAGCACHE 95 int currtable; /* db use */ 96 int currextra; /* db use */ 97 int special_entry_count; /* db use */ 98#endif 99 int sort_dir; /* directory sort order */ 100 int out_of_tree; /* shortcut from elsewhere */ 101 struct tree_cache cache; 102 bool dirfull; 103 bool is_browsing; /* valid browse context? */ 104 105 struct browse_context *browse; 106}; 107 108/* 109 * Call one of the two below after yields since the entrys may move inbetween */ 110struct entry* tree_get_entries(struct tree_context *t); 111/* returns NULL on invalid index */ 112struct entry* tree_get_entry_at(struct tree_context *t, int index); 113 114void tree_mem_init(void) INIT_ATTR; 115void tree_init(void) INIT_ATTR; 116char* get_current_file(char* buffer, size_t buffer_len); 117void set_dirfilter(int l_dirfilter); 118void set_current_file(const char *path); 119int rockbox_browse(struct browse_context *browse); 120int rockbox_browse_root(); 121int create_playlist(void); 122void resume_directory(const char *dir); 123 124void tree_lock_cache(struct tree_context *t); 125void tree_unlock_cache(struct tree_context *t); 126 127#ifdef WIN32 128/* it takes an int on windows */ 129#define getcwd_size_t int 130#else 131#define getcwd_size_t size_t 132#endif 133#ifdef CTRU 134/* devkitarm already defines getcwd */ 135char *__wrap_getcwd(char *buf, getcwd_size_t size); 136#else 137char *getcwd(char *buf, getcwd_size_t size); 138#endif 139void reload_directory(void); 140bool check_rockboxdir(void); 141struct tree_context* tree_get_context(void); 142void tree_flush(void); 143void tree_restore(void); 144 145bool bookmark_play(char* resume_file, int index, unsigned long elapsed, 146 unsigned long offset, int seed, char *filename); 147 148#endif