2006-03-26 11:33:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Miika Pekkarinen
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-03-26 11:33:42 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
/**
|
2006-03-26 11:33:42 +00:00
|
|
|
* Basic structure on this file was copied from dbtree.c and modified to
|
|
|
|
* support the tag cache interface.
|
|
|
|
*/
|
2009-06-20 16:17:54 +00:00
|
|
|
|
2009-11-03 16:25:03 +00:00
|
|
|
/*#define LOGF_ENABLE*/
|
2009-06-20 16:17:54 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include "string-extra.h"
|
2007-04-18 13:03:01 +00:00
|
|
|
#include "config.h"
|
2006-03-26 11:33:42 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "splash.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "tree.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2006-03-26 11:33:42 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "tagcache.h"
|
|
|
|
#include "tagtree.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "logf.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "gui/list.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
2006-08-09 07:28:48 +00:00
|
|
|
#include "yesno.h"
|
2006-10-21 20:37:33 +00:00
|
|
|
#include "misc.h"
|
2007-04-18 13:03:01 +00:00
|
|
|
#include "filetypes.h"
|
2007-10-29 12:15:47 +00:00
|
|
|
#include "audio.h"
|
2008-10-16 10:38:03 +00:00
|
|
|
#include "appevents.h"
|
2008-11-01 16:14:28 +00:00
|
|
|
#include "storage.h"
|
2010-09-01 21:29:34 +00:00
|
|
|
#include "dir.h"
|
2011-02-23 14:31:13 +00:00
|
|
|
#include "playback.h"
|
2014-01-15 22:18:35 +00:00
|
|
|
#include "strnatcmp.h"
|
2011-08-30 14:01:45 +00:00
|
|
|
#include "panic.h"
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
#define str_or_empty(x) (x ? x : "(NULL)")
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
#define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config"
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
static int tagtree_play_folder(struct tree_context* c);
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* this needs to be same size as struct entry (tree.h) and name needs to be
|
|
|
|
* the first; so that they're compatible enough to walk arrays of both
|
|
|
|
* derefencing the name member*/
|
|
|
|
struct tagentry {
|
|
|
|
char* name;
|
|
|
|
int newtable;
|
|
|
|
int extraseek;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tagentry* tagtree_get_entry(struct tree_context *c, int id);
|
|
|
|
|
2007-10-30 10:02:57 +00:00
|
|
|
#define SEARCHSTR_SIZE 256
|
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
enum table {
|
|
|
|
ROOT = 1,
|
|
|
|
NAVIBROWSE,
|
|
|
|
ALLSUBENTRIES,
|
|
|
|
PLAYTRACK,
|
|
|
|
};
|
|
|
|
|
2007-10-29 14:10:24 +00:00
|
|
|
static const struct id3_to_search_mapping {
|
|
|
|
char *string;
|
|
|
|
size_t id3_offset;
|
|
|
|
} id3_to_search_mapping[] = {
|
2007-10-30 10:02:57 +00:00
|
|
|
{ "", 0 }, /* offset n/a */
|
|
|
|
{ "#directory#", 0 }, /* offset n/a */
|
2007-10-29 14:10:24 +00:00
|
|
|
{ "#title#", offsetof(struct mp3entry, title) },
|
|
|
|
{ "#artist#", offsetof(struct mp3entry, artist) },
|
|
|
|
{ "#album#", offsetof(struct mp3entry, album) },
|
|
|
|
{ "#genre#", offsetof(struct mp3entry, genre_string) },
|
|
|
|
{ "#composer#", offsetof(struct mp3entry, composer) },
|
|
|
|
{ "#albumartist#", offsetof(struct mp3entry, albumartist) },
|
|
|
|
};
|
2006-08-26 22:00:22 +00:00
|
|
|
enum variables {
|
|
|
|
var_sorttype = 100,
|
2006-09-19 11:54:33 +00:00
|
|
|
var_limit,
|
2006-09-26 18:59:16 +00:00
|
|
|
var_strip,
|
2006-09-19 11:54:33 +00:00
|
|
|
var_menu_start,
|
|
|
|
var_include,
|
|
|
|
var_rootmenu,
|
2006-10-15 11:01:18 +00:00
|
|
|
var_format,
|
2006-09-19 11:54:33 +00:00
|
|
|
menu_next,
|
|
|
|
menu_load,
|
2019-07-30 01:49:41 +00:00
|
|
|
menu_reload,
|
2006-08-26 22:00:22 +00:00
|
|
|
};
|
|
|
|
|
2006-08-25 13:22:46 +00:00
|
|
|
/* Capacity 10 000 entries (for example 10k different artists) */
|
|
|
|
#define UNIQBUF_SIZE (64*1024)
|
2011-08-30 14:01:45 +00:00
|
|
|
static long uniqbuf[UNIQBUF_SIZE / sizeof(long)];
|
2006-08-25 13:22:46 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
#define MAX_TAGS 5
|
2007-06-22 12:48:06 +00:00
|
|
|
#define MAX_MENU_ID_SIZE 32
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2019-07-30 01:49:41 +00:00
|
|
|
#define RELOAD_TAGTREE (-1024)
|
2006-08-26 22:00:22 +00:00
|
|
|
static bool sort_inverse;
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
/*
|
2006-08-26 22:00:22 +00:00
|
|
|
* "%3d. %s" autoscore title %sort = "inverse" %limit = "100"
|
2013-07-12 16:03:20 +00:00
|
|
|
*
|
2006-07-15 17:36:25 +00:00
|
|
|
* valid = true
|
|
|
|
* formatstr = "%-3d. %s"
|
|
|
|
* tags[0] = tag_autoscore
|
|
|
|
* tags[1] = tag_title
|
|
|
|
* tag_count = 2
|
2013-07-12 16:03:20 +00:00
|
|
|
*
|
2006-08-26 22:00:22 +00:00
|
|
|
* limit = 100
|
|
|
|
* sort_inverse = true
|
2006-07-15 17:36:25 +00:00
|
|
|
*/
|
|
|
|
struct display_format {
|
2006-10-15 11:01:18 +00:00
|
|
|
char name[32];
|
|
|
|
struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
|
|
|
|
int clause_count;
|
|
|
|
char *formatstr;
|
|
|
|
int group_id;
|
2006-07-15 17:36:25 +00:00
|
|
|
int tags[MAX_TAGS];
|
|
|
|
int tag_count;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
int limit;
|
2006-09-26 18:59:16 +00:00
|
|
|
int strip;
|
2006-08-26 22:00:22 +00:00
|
|
|
bool sort_inverse;
|
2006-07-15 17:36:25 +00:00
|
|
|
};
|
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
static struct display_format *formats[TAGMENU_MAX_FMTS];
|
|
|
|
static int format_count;
|
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
struct menu_entry {
|
|
|
|
char name[64];
|
|
|
|
int type;
|
2011-06-20 19:32:52 +00:00
|
|
|
struct search_instruction {
|
|
|
|
char name[64];
|
|
|
|
int tagorder[MAX_TAGS];
|
|
|
|
int tagorder_count;
|
|
|
|
struct tagcache_search_clause *clause[MAX_TAGS][TAGCACHE_MAX_CLAUSES];
|
|
|
|
int format_id[MAX_TAGS];
|
|
|
|
int clause_count[MAX_TAGS];
|
|
|
|
int result_seek[MAX_TAGS];
|
|
|
|
} si;
|
2006-09-19 11:54:33 +00:00
|
|
|
int link;
|
|
|
|
};
|
|
|
|
|
2009-05-30 16:35:28 +00:00
|
|
|
struct menu_root {
|
2006-09-19 11:54:33 +00:00
|
|
|
char title[64];
|
2007-06-22 12:48:06 +00:00
|
|
|
char id[MAX_MENU_ID_SIZE];
|
2006-09-19 11:54:33 +00:00
|
|
|
int itemcount;
|
|
|
|
struct menu_entry *items[TAGMENU_MAX_ITEMS];
|
|
|
|
};
|
|
|
|
|
2011-05-31 19:44:21 +00:00
|
|
|
struct match
|
|
|
|
{
|
|
|
|
const char* str;
|
|
|
|
int symbol;
|
|
|
|
};
|
|
|
|
|
2006-09-25 19:52:38 +00:00
|
|
|
/* Statusbar text of the current view. */
|
|
|
|
static char current_title[MAX_TAGS][128];
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
static struct menu_root * menus[TAGMENU_MAX_MENUS];
|
|
|
|
static struct menu_root * menu;
|
2006-09-19 11:54:33 +00:00
|
|
|
static struct search_instruction *csi;
|
2006-04-04 19:28:13 +00:00
|
|
|
static const char *strp;
|
2006-09-19 11:54:33 +00:00
|
|
|
static int menu_count;
|
2009-05-30 16:35:28 +00:00
|
|
|
static int rootmenu;
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
static int current_offset;
|
|
|
|
static int current_entry_count;
|
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
static struct tree_context *tc;
|
|
|
|
|
2011-06-20 19:32:56 +00:00
|
|
|
/* a few memory alloc helper */
|
2011-08-30 14:01:45 +00:00
|
|
|
static int tagtree_handle, lock_count;
|
2011-08-30 14:01:33 +00:00
|
|
|
static size_t tagtree_bufsize, tagtree_buf_used;
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
#define UPDATE(x, y) { x = (typeof(x))((char*)(x) + (y)); }
|
|
|
|
static int move_callback(int handle, void* current, void* new)
|
|
|
|
{
|
|
|
|
(void)handle; (void)current; (void)new;
|
|
|
|
ptrdiff_t diff = new - current;
|
|
|
|
|
|
|
|
if (lock_count > 0)
|
|
|
|
return BUFLIB_CB_CANNOT_MOVE;
|
|
|
|
|
2017-02-11 01:10:14 +00:00
|
|
|
if (menu)
|
|
|
|
UPDATE(menu, diff);
|
|
|
|
|
|
|
|
if (csi)
|
|
|
|
UPDATE(csi, diff);
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* loop over menus */
|
|
|
|
for(int i = 0; i < menu_count; i++)
|
|
|
|
{
|
|
|
|
struct menu_root* menu = menus[i];
|
|
|
|
/* then over the menu_entries of a menu */
|
|
|
|
for(int j = 0; j < menu->itemcount; j++)
|
|
|
|
{
|
|
|
|
struct menu_entry* mentry = menu->items[j];
|
|
|
|
/* then over the search_instructions of each menu_entry */
|
|
|
|
for(int k = 0; k < mentry->si.tagorder_count; k++)
|
|
|
|
{
|
|
|
|
for(int l = 0; l < mentry->si.clause_count[k]; l++)
|
|
|
|
{
|
|
|
|
UPDATE(mentry->si.clause[k][l]->str, diff);
|
|
|
|
UPDATE(mentry->si.clause[k][l], diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UPDATE(menu->items[j], diff);
|
|
|
|
}
|
|
|
|
UPDATE(menus[i], diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now the same game for formats */
|
|
|
|
for(int i = 0; i < format_count; i++)
|
|
|
|
{
|
|
|
|
for(int j = 0; j < formats[i]->clause_count; j++)
|
|
|
|
{
|
|
|
|
UPDATE(formats[i]->clause[j]->str, diff);
|
|
|
|
UPDATE(formats[i]->clause[j], diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (formats[i]->formatstr)
|
|
|
|
UPDATE(formats[i]->formatstr, diff);
|
|
|
|
|
|
|
|
UPDATE(formats[i], diff);
|
|
|
|
}
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
#undef UPDATE
|
|
|
|
|
|
|
|
static inline void tagtree_lock(void)
|
|
|
|
{
|
|
|
|
lock_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tagtree_unlock(void)
|
|
|
|
{
|
|
|
|
lock_count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buflib_callbacks ops = {
|
|
|
|
.move_callback = move_callback,
|
|
|
|
.shrink_callback = NULL,
|
|
|
|
};
|
|
|
|
|
2011-06-20 19:32:56 +00:00
|
|
|
static void* tagtree_alloc(size_t size)
|
|
|
|
{
|
2011-08-30 14:01:33 +00:00
|
|
|
size = ALIGN_UP(size, sizeof(void*));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (size > (tagtree_bufsize - tagtree_buf_used))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char* buf = core_get_data(tagtree_handle) + tagtree_buf_used;
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
tagtree_buf_used += size;
|
|
|
|
return buf;
|
2011-06-20 19:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void* tagtree_alloc0(size_t size)
|
|
|
|
{
|
|
|
|
void* ret = tagtree_alloc(size);
|
2019-07-30 01:49:41 +00:00
|
|
|
if (ret)
|
|
|
|
memset(ret, 0, size);
|
2011-06-20 19:32:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* tagtree_strdup(const char* buf)
|
|
|
|
{
|
|
|
|
size_t len = strlen(buf) + 1;
|
|
|
|
char* dest = tagtree_alloc(len);
|
2019-07-30 01:49:41 +00:00
|
|
|
if (dest)
|
|
|
|
strcpy(dest, buf);
|
2011-06-20 19:32:56 +00:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* save to call without locking */
|
2006-04-04 19:28:13 +00:00
|
|
|
static int get_token_str(char *buf, int size)
|
|
|
|
{
|
|
|
|
/* Find the start. */
|
|
|
|
while (*strp != '"' && *strp != '\0')
|
|
|
|
strp++;
|
|
|
|
|
|
|
|
if (*strp == '\0' || *(++strp) == '\0')
|
|
|
|
return -1;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
/* Read the data. */
|
|
|
|
while (*strp != '"' && *strp != '\0' && --size > 0)
|
|
|
|
*(buf++) = *(strp++);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
*buf = '\0';
|
|
|
|
if (*strp != '"')
|
|
|
|
return -2;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
strp++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_tag(int *tag)
|
|
|
|
{
|
2011-05-31 19:44:21 +00:00
|
|
|
static const struct match get_tag_match[] =
|
2011-07-18 18:57:50 +00:00
|
|
|
{
|
|
|
|
{"album", tag_album},
|
|
|
|
{"artist", tag_artist},
|
|
|
|
{"bitrate", tag_bitrate},
|
|
|
|
{"composer", tag_composer},
|
|
|
|
{"comment", tag_comment},
|
|
|
|
{"albumartist", tag_albumartist},
|
|
|
|
{"ensemble", tag_albumartist},
|
|
|
|
{"grouping", tag_grouping},
|
|
|
|
{"genre", tag_genre},
|
|
|
|
{"length", tag_length},
|
|
|
|
{"Lm", tag_virt_length_min},
|
|
|
|
{"Ls", tag_virt_length_sec},
|
|
|
|
{"Pm", tag_virt_playtime_min},
|
|
|
|
{"Ps", tag_virt_playtime_sec},
|
|
|
|
{"title", tag_title},
|
|
|
|
{"filename", tag_filename},
|
2011-07-31 16:26:35 +00:00
|
|
|
{"basename", tag_virt_basename},
|
2011-07-18 18:57:50 +00:00
|
|
|
{"tracknum", tag_tracknumber},
|
|
|
|
{"discnum", tag_discnumber},
|
|
|
|
{"year", tag_year},
|
|
|
|
{"playcount", tag_playcount},
|
|
|
|
{"rating", tag_rating},
|
|
|
|
{"lastplayed", tag_lastplayed},
|
2013-07-14 11:59:39 +00:00
|
|
|
{"lastelapsed", tag_lastelapsed},
|
2011-07-18 18:57:50 +00:00
|
|
|
{"lastoffset", tag_lastoffset},
|
|
|
|
{"commitid", tag_commitid},
|
|
|
|
{"entryage", tag_virt_entryage},
|
|
|
|
{"autoscore", tag_virt_autoscore},
|
|
|
|
{"%sort", var_sorttype},
|
|
|
|
{"%limit", var_limit},
|
|
|
|
{"%strip", var_strip},
|
|
|
|
{"%menu_start", var_menu_start},
|
|
|
|
{"%include", var_include},
|
|
|
|
{"%root_menu", var_rootmenu},
|
|
|
|
{"%format", var_format},
|
|
|
|
{"->", menu_next},
|
2019-07-30 01:49:41 +00:00
|
|
|
{"==>", menu_load},
|
|
|
|
{"%reload", menu_reload}
|
2011-05-31 19:44:21 +00:00
|
|
|
};
|
2006-10-10 10:29:42 +00:00
|
|
|
char buf[128];
|
2011-05-31 19:44:21 +00:00
|
|
|
unsigned int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
/* Find the start. */
|
2006-09-19 11:54:33 +00:00
|
|
|
while ((*strp == ' ' || *strp == '>') && *strp != '\0')
|
2006-04-04 19:28:13 +00:00
|
|
|
strp++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
if (*strp == '\0' || *strp == '?')
|
2006-04-04 19:28:13 +00:00
|
|
|
return 0;
|
2011-05-31 19:44:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(buf)-1; i++)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
if (*strp == '\0' || *strp == ' ')
|
|
|
|
break ;
|
|
|
|
buf[i] = *strp;
|
|
|
|
strp++;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
2011-05-31 19:44:21 +00:00
|
|
|
|
2011-07-18 18:57:50 +00:00
|
|
|
for (i = 0; i < ARRAYLEN(get_tag_match); i++)
|
2011-05-31 19:44:21 +00:00
|
|
|
{
|
2011-07-18 18:57:50 +00:00
|
|
|
if (!strcasecmp(buf, get_tag_match[i].str))
|
|
|
|
{
|
|
|
|
*tag = get_tag_match[i].symbol;
|
|
|
|
return 1;
|
|
|
|
}
|
2011-05-31 19:44:21 +00:00
|
|
|
}
|
2011-07-18 18:57:50 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
logf("NO MATCH: %s\n", buf);
|
|
|
|
if (buf[0] == '?')
|
|
|
|
return 0;
|
2011-05-31 19:44:21 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_clause(int *condition)
|
|
|
|
{
|
2011-05-31 19:44:21 +00:00
|
|
|
static const struct match get_clause_match[] =
|
2011-07-18 18:57:50 +00:00
|
|
|
{
|
|
|
|
{"=", clause_is},
|
|
|
|
{"==", clause_is},
|
|
|
|
{"!=", clause_is_not},
|
|
|
|
{">", clause_gt},
|
|
|
|
{">=", clause_gteq},
|
|
|
|
{"<", clause_lt},
|
|
|
|
{"<=", clause_lteq},
|
|
|
|
{"~", clause_contains},
|
|
|
|
{"!~", clause_not_contains},
|
|
|
|
{"^", clause_begins_with},
|
|
|
|
{"!^", clause_not_begins_with},
|
|
|
|
{"$", clause_ends_with},
|
|
|
|
{"!$", clause_not_ends_with},
|
|
|
|
{"@", clause_oneof}
|
2011-05-31 19:44:21 +00:00
|
|
|
};
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
char buf[4];
|
2011-05-31 19:44:21 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
/* Find the start. */
|
|
|
|
while (*strp == ' ' && *strp != '\0')
|
|
|
|
strp++;
|
2011-05-31 19:44:21 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
if (*strp == '\0')
|
|
|
|
return 0;
|
2011-05-31 19:44:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(buf)-1; i++)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
if (*strp == '\0' || *strp == ' ')
|
|
|
|
break ;
|
|
|
|
buf[i] = *strp;
|
|
|
|
strp++;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
2011-05-31 19:44:21 +00:00
|
|
|
|
2011-07-18 18:57:50 +00:00
|
|
|
for (i = 0; i < ARRAYLEN(get_clause_match); i++)
|
2011-05-31 19:44:21 +00:00
|
|
|
{
|
2011-07-18 18:57:50 +00:00
|
|
|
if (!strcasecmp(buf, get_clause_match[i].str))
|
|
|
|
{
|
|
|
|
*condition = get_clause_match[i].symbol;
|
|
|
|
return 1;
|
|
|
|
}
|
2011-05-31 19:44:21 +00:00
|
|
|
}
|
2011-07-18 18:57:50 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
static bool read_clause(struct tagcache_search_clause *clause)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
2007-10-30 10:02:57 +00:00
|
|
|
char buf[SEARCHSTR_SIZE];
|
|
|
|
unsigned int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_tag(&clause->tag) <= 0)
|
2006-04-04 19:28:13 +00:00
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_clause(&clause->type) <= 0)
|
2006-04-04 19:28:13 +00:00
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_token_str(buf, sizeof buf) < 0)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-10-30 10:02:57 +00:00
|
|
|
for (i=0; i<ARRAYLEN(id3_to_search_mapping); i++)
|
2007-10-29 14:10:24 +00:00
|
|
|
{
|
2007-10-30 10:02:57 +00:00
|
|
|
if (!strcasecmp(buf, id3_to_search_mapping[i].string))
|
|
|
|
break;
|
2007-10-29 14:10:24 +00:00
|
|
|
}
|
2007-10-30 10:02:57 +00:00
|
|
|
|
|
|
|
if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */
|
|
|
|
{
|
|
|
|
clause->source = source_runtime+i;
|
2011-06-20 19:32:56 +00:00
|
|
|
clause->str = tagtree_alloc(SEARCHSTR_SIZE);
|
2013-07-12 16:03:20 +00:00
|
|
|
}
|
|
|
|
else
|
2007-10-30 10:02:57 +00:00
|
|
|
{
|
|
|
|
clause->source = source_constant;
|
2011-06-20 19:32:56 +00:00
|
|
|
clause->str = tagtree_strdup(buf);
|
2013-07-12 16:03:20 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!clause->str)
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "clause string");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (TAGCACHE_IS_NUMERIC(clause->tag))
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
clause->numeric = true;
|
2006-10-15 11:01:18 +00:00
|
|
|
clause->numeric_data = atoi(clause->str);
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
clause->numeric = false;
|
2007-10-30 10:02:57 +00:00
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str);
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
static bool read_variable(char *buf, int size)
|
|
|
|
{
|
|
|
|
int condition;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (!get_clause(&condition))
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (condition != clause_is)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (get_token_str(buf, size) < 0)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "%3d. %s" autoscore title %sort = "inverse" %limit = "100" */
|
2006-07-15 17:36:25 +00:00
|
|
|
static int get_format_str(struct display_format *fmt)
|
|
|
|
{
|
|
|
|
int ret;
|
2006-10-11 04:32:33 +00:00
|
|
|
char buf[128];
|
2006-10-15 11:01:18 +00:00
|
|
|
int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
memset(fmt, 0, sizeof(struct display_format));
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_token_str(fmt->name, sizeof fmt->name) < 0)
|
|
|
|
return -10;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
/* Determine the group id */
|
|
|
|
fmt->group_id = 0;
|
|
|
|
for (i = 0; i < format_count; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(formats[i]->name, fmt->name))
|
|
|
|
{
|
|
|
|
fmt->group_id = formats[i]->group_id;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (formats[i]->group_id > fmt->group_id)
|
|
|
|
fmt->group_id = formats[i]->group_id;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (i == format_count)
|
|
|
|
fmt->group_id++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
logf("format: (%d) %s", fmt->group_id, fmt->name);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_token_str(buf, sizeof buf) < 0)
|
2006-07-15 17:36:25 +00:00
|
|
|
return -10;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-06-20 19:32:56 +00:00
|
|
|
fmt->formatstr = tagtree_strdup(buf);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
while (fmt->tag_count < MAX_TAGS)
|
|
|
|
{
|
|
|
|
ret = get_tag(&fmt->tags[fmt->tag_count]);
|
|
|
|
if (ret < 0)
|
|
|
|
return -11;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
if (ret == 0)
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
switch (fmt->tags[fmt->tag_count]) {
|
|
|
|
case var_sorttype:
|
|
|
|
if (!read_variable(buf, sizeof buf))
|
|
|
|
return -12;
|
|
|
|
if (!strcasecmp("inverse", buf))
|
|
|
|
fmt->sort_inverse = true;
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
case var_limit:
|
|
|
|
if (!read_variable(buf, sizeof buf))
|
|
|
|
return -13;
|
|
|
|
fmt->limit = atoi(buf);
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-26 18:59:16 +00:00
|
|
|
case var_strip:
|
|
|
|
if (!read_variable(buf, sizeof buf))
|
|
|
|
return -14;
|
|
|
|
fmt->strip = atoi(buf);
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
default:
|
|
|
|
fmt->tag_count++;
|
|
|
|
}
|
2006-07-15 17:36:25 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_format(const char *buf)
|
|
|
|
{
|
2011-06-14 20:54:26 +00:00
|
|
|
if (format_count >= TAGMENU_MAX_FMTS)
|
|
|
|
{
|
|
|
|
logf("too many formats");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
strp = buf;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (formats[format_count] == NULL)
|
2011-06-20 19:32:56 +00:00
|
|
|
formats[format_count] = tagtree_alloc0(sizeof(struct display_format));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!formats[format_count])
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "format string");
|
|
|
|
return -2;
|
|
|
|
}
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_format_str(formats[format_count]) < 0)
|
|
|
|
{
|
|
|
|
logf("get_format_str() parser failed!");
|
2019-07-30 01:49:41 +00:00
|
|
|
if (formats[format_count])
|
|
|
|
memset(formats[format_count], 0, sizeof(struct display_format));
|
2006-10-15 11:01:18 +00:00
|
|
|
return -4;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
while (*strp != '\0' && *strp != '?')
|
|
|
|
strp++;
|
|
|
|
|
|
|
|
if (*strp == '?')
|
|
|
|
{
|
|
|
|
int clause_count = 0;
|
|
|
|
strp++;
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
tagtree_lock();
|
2006-10-15 11:01:18 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2019-07-30 01:49:41 +00:00
|
|
|
struct tagcache_search_clause *new_clause;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-25 15:14:15 +00:00
|
|
|
if (clause_count >= TAGCACHE_MAX_CLAUSES)
|
|
|
|
{
|
|
|
|
logf("too many clauses");
|
|
|
|
break;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2019-07-30 01:49:41 +00:00
|
|
|
new_clause = tagtree_alloc(sizeof(struct tagcache_search_clause));
|
|
|
|
if (!new_clause)
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "search clause");
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
formats[format_count]->clause[clause_count] = new_clause;
|
|
|
|
if (!read_clause(new_clause))
|
2006-10-15 11:01:18 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
clause_count++;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_unlock();
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
formats[format_count]->clause_count = clause_count;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
format_count++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
static int get_condition(struct search_instruction *inst)
|
|
|
|
{
|
2011-05-10 10:25:41 +00:00
|
|
|
struct tagcache_search_clause *new_clause;
|
2006-10-15 11:01:18 +00:00
|
|
|
int clause_count;
|
2006-10-11 04:32:33 +00:00
|
|
|
char buf[128];
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
switch (*strp)
|
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
case '=':
|
2006-10-15 11:01:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (get_token_str(buf, sizeof buf) < 0)
|
|
|
|
return -1;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
for (i = 0; i < format_count; i++)
|
2006-07-15 17:36:25 +00:00
|
|
|
{
|
2006-10-15 11:01:18 +00:00
|
|
|
if (!strcasecmp(formats[i]->name, buf))
|
|
|
|
break;
|
2006-07-15 17:36:25 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (i == format_count)
|
|
|
|
{
|
|
|
|
logf("format not found: %s", buf);
|
|
|
|
return -2;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
inst->format_id[inst->tagorder_count] = formats[i]->group_id;
|
2006-08-26 22:00:22 +00:00
|
|
|
return 1;
|
2006-10-15 11:01:18 +00:00
|
|
|
}
|
2006-04-04 19:28:13 +00:00
|
|
|
case '?':
|
|
|
|
case ' ':
|
|
|
|
case '&':
|
|
|
|
strp++;
|
|
|
|
return 1;
|
2006-09-19 11:54:33 +00:00
|
|
|
case '-':
|
2006-04-04 19:28:13 +00:00
|
|
|
case '\0':
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
clause_count = inst->clause_count[inst->tagorder_count];
|
|
|
|
if (clause_count >= TAGCACHE_MAX_CLAUSES)
|
|
|
|
{
|
|
|
|
logf("Too many clauses");
|
2019-07-30 01:49:41 +00:00
|
|
|
return -2;
|
2006-10-15 11:01:18 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-06-20 19:32:56 +00:00
|
|
|
new_clause = tagtree_alloc(sizeof(struct tagcache_search_clause));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!new_clause)
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "search clause");
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
2011-05-10 10:25:41 +00:00
|
|
|
inst->clause[inst->tagorder_count][clause_count] = new_clause;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-05-10 10:25:41 +00:00
|
|
|
if (*strp == '|')
|
|
|
|
{
|
|
|
|
strp++;
|
|
|
|
new_clause->type = clause_logical_or;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
tagtree_lock();
|
|
|
|
bool ret = read_clause(new_clause);
|
|
|
|
tagtree_unlock();
|
|
|
|
if (!ret)
|
|
|
|
return -1;
|
|
|
|
}
|
2006-10-15 11:01:18 +00:00
|
|
|
inst->clause_count[inst->tagorder_count]++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* example search:
|
|
|
|
* "Best" artist ? year >= "2000" & title !^ "crap" & genre = "good genre" \
|
|
|
|
* : album ? year >= "2000" : songs
|
|
|
|
* ^ begins with
|
|
|
|
* * contains
|
|
|
|
* $ ends with
|
|
|
|
*/
|
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
static bool parse_search(struct menu_entry *entry, const char *str)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2006-09-19 11:54:33 +00:00
|
|
|
int type;
|
2011-06-20 19:32:52 +00:00
|
|
|
struct search_instruction *inst = &entry->si;
|
2006-09-19 11:54:33 +00:00
|
|
|
char buf[MAX_PATH];
|
|
|
|
int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
strp = str;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
/* Parse entry name */
|
|
|
|
if (get_token_str(entry->name, sizeof entry->name) < 0)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
logf("No name found.");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
/* Parse entry type */
|
|
|
|
if (get_tag(&entry->type) <= 0)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
if (entry->type == menu_load)
|
|
|
|
{
|
|
|
|
if (get_token_str(buf, sizeof buf) < 0)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
/* Find the matching root menu or "create" it */
|
|
|
|
for (i = 0; i < menu_count; i++)
|
|
|
|
{
|
2006-09-26 06:40:14 +00:00
|
|
|
if (!strcasecmp(menus[i]->id, buf))
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
|
|
|
entry->link = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-06-22 12:48:06 +00:00
|
|
|
if (menu_count >= TAGMENU_MAX_MENUS)
|
|
|
|
{
|
|
|
|
logf("max menucount reached");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-06-22 12:48:06 +00:00
|
|
|
/* Allocate a new menu unless link is found. */
|
2011-06-20 19:32:56 +00:00
|
|
|
menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!menus[menu_count])
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "menu");
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
strlcpy(menus[menu_count]->id, buf, MAX_MENU_ID_SIZE);
|
2007-06-22 12:48:06 +00:00
|
|
|
entry->link = menu_count;
|
|
|
|
++menu_count;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-06-22 12:48:06 +00:00
|
|
|
return true;
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
if (entry->type != menu_next)
|
|
|
|
return false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
while (inst->tagorder_count < MAX_TAGS)
|
|
|
|
{
|
|
|
|
ret = get_tag(&inst->tagorder[inst->tagorder_count]);
|
2013-07-12 16:03:20 +00:00
|
|
|
if (ret < 0)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
logf("Parse error #1");
|
2006-09-19 11:54:33 +00:00
|
|
|
logf("%s", strp);
|
2006-04-04 19:28:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
if (ret == 0)
|
|
|
|
break ;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
logf("tag: %d", inst->tagorder[inst->tagorder_count]);
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
tagtree_lock();
|
2006-10-15 11:01:18 +00:00
|
|
|
while ( (ret = get_condition(inst)) > 0 ) ;
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_unlock();
|
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return false;
|
2006-04-04 19:28:13 +00:00
|
|
|
|
|
|
|
inst->tagorder_count++;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
if (get_tag(&type) <= 0 || type != menu_next)
|
|
|
|
break;
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-30 12:07:32 +00:00
|
|
|
static int compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
struct tagentry *e1 = (struct tagentry *)p1;
|
|
|
|
struct tagentry *e2 = (struct tagentry *)p2;
|
2011-08-30 14:01:45 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (sort_inverse)
|
|
|
|
return strncasecmp(e2->name, e1->name, MAX_PATH);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-30 12:07:32 +00:00
|
|
|
return strncasecmp(e1->name, e2->name, MAX_PATH);
|
|
|
|
}
|
|
|
|
|
2014-01-15 22:18:35 +00:00
|
|
|
static int nat_compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
struct tagentry *e1 = (struct tagentry *)p1;
|
|
|
|
struct tagentry *e2 = (struct tagentry *)p2;
|
|
|
|
|
|
|
|
if (sort_inverse)
|
|
|
|
return strnatcasecmp(e2->name, e1->name);
|
|
|
|
|
|
|
|
return strnatcasecmp(e1->name, e2->name);
|
|
|
|
}
|
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
static void tagtree_buffer_event(unsigned short id, void *ev_data)
|
2006-07-15 17:36:25 +00:00
|
|
|
{
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_search tcs;
|
2014-03-14 22:15:16 +00:00
|
|
|
struct mp3entry *id3 = ((struct track_event *)ev_data)->id3;
|
2013-07-12 16:06:38 +00:00
|
|
|
|
|
|
|
bool runtimedb = global_settings.runtimedb;
|
|
|
|
bool autoresume = global_settings.autoresume_enable;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 16:06:54 +00:00
|
|
|
/* Do not gather data unless proper setting has been enabled. */
|
2013-07-12 16:06:38 +00:00
|
|
|
if (!runtimedb && !autoresume)
|
2006-08-26 16:06:54 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-23 17:58:03 +00:00
|
|
|
logf("be:%s", id3->path);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-01-17 22:28:36 +00:00
|
|
|
while (! tagcache_is_fully_initialized())
|
2010-11-16 13:17:37 +00:00
|
|
|
yield();
|
|
|
|
|
2006-08-26 16:06:54 +00:00
|
|
|
if (!tagcache_find_index(&tcs, id3->path))
|
|
|
|
{
|
|
|
|
logf("tc stat: not found: %s", id3->path);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
if (runtimedb)
|
2011-01-02 02:49:13 +00:00
|
|
|
{
|
|
|
|
id3->playcount = tagcache_get_numeric(&tcs, tag_playcount);
|
|
|
|
if (!id3->rating)
|
|
|
|
id3->rating = tagcache_get_numeric(&tcs, tag_rating);
|
|
|
|
id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
|
|
|
|
id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10;
|
|
|
|
id3->playtime = tagcache_get_numeric(&tcs, tag_playtime);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
logf("-> %ld/%ld", id3->playcount, id3->playtime);
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
if (autoresume)
|
2011-01-02 02:49:13 +00:00
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
/* Load current file resume info if not already defined (by
|
2011-01-02 02:49:13 +00:00
|
|
|
another resume mechanism) */
|
2013-07-14 11:59:39 +00:00
|
|
|
if (id3->elapsed == 0)
|
|
|
|
{
|
|
|
|
id3->elapsed = tagcache_get_numeric(&tcs, tag_lastelapsed);
|
|
|
|
|
|
|
|
logf("tagtree_buffer_event: Set elapsed for %s to %lX\n",
|
|
|
|
str_or_empty(id3->title), id3->elapsed);
|
|
|
|
}
|
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
if (id3->offset == 0)
|
|
|
|
{
|
|
|
|
id3->offset = tagcache_get_numeric(&tcs, tag_lastoffset);
|
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
logf("tagtree_buffer_event: Set offset for %s to %lX\n",
|
2011-01-02 02:49:13 +00:00
|
|
|
str_or_empty(id3->title), id3->offset);
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-07-21 17:35:19 +00:00
|
|
|
/* Store our tagcache index pointer. */
|
2008-02-12 18:51:10 +00:00
|
|
|
id3->tagcache_idx = tcs.idx_id+1;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 16:06:54 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2006-07-15 17:36:25 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
static void tagtree_track_finish_event(unsigned short id, void *ev_data)
|
2006-07-15 17:36:25 +00:00
|
|
|
{
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
|
|
|
struct track_event *te = (struct track_event *)ev_data;
|
2013-07-12 16:06:38 +00:00
|
|
|
struct mp3entry *id3 = te->id3;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
long tagcache_idx = id3->tagcache_idx;
|
2008-02-12 18:51:10 +00:00
|
|
|
if (!tagcache_idx)
|
2006-08-02 17:39:34 +00:00
|
|
|
{
|
2007-07-21 17:35:19 +00:00
|
|
|
logf("No tagcache index pointer found");
|
2006-07-15 17:36:25 +00:00
|
|
|
return;
|
2006-08-02 17:39:34 +00:00
|
|
|
}
|
2008-02-12 18:51:10 +00:00
|
|
|
tagcache_idx--;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
bool auto_skip = te->flags & TEF_AUTO_SKIP;
|
|
|
|
bool runtimedb = global_settings.runtimedb;
|
|
|
|
bool autoresume = global_settings.autoresume_enable;
|
|
|
|
|
|
|
|
/* Don't process unplayed tracks, or tracks interrupted within the
|
|
|
|
first 15 seconds but always process autoresume point */
|
|
|
|
if (runtimedb && (id3->elapsed == 0
|
|
|
|
|| (id3->elapsed < 15 * 1000 && !auto_skip)
|
|
|
|
))
|
|
|
|
{
|
|
|
|
logf("not db logging unplayed or skipped track");
|
|
|
|
runtimedb = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3s because that is the threshold the WPS uses to rewind instead
|
|
|
|
of skip backwards */
|
|
|
|
if (autoresume && (id3->elapsed == 0
|
|
|
|
|| (id3->elapsed < 3 * 1000 && !auto_skip)))
|
|
|
|
{
|
|
|
|
logf("not logging autoresume");
|
|
|
|
autoresume = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not gather data unless proper setting has been enabled and at least
|
|
|
|
one is still slated to be recorded */
|
|
|
|
if (!(runtimedb || autoresume))
|
2006-07-15 17:36:25 +00:00
|
|
|
{
|
2013-07-12 16:06:38 +00:00
|
|
|
logf("runtimedb gathering and autoresume not enabled/ignored");
|
2006-07-15 17:36:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
long lastplayed = tagcache_increase_serial();
|
2006-07-20 12:19:31 +00:00
|
|
|
if (lastplayed < 0)
|
2006-08-02 17:39:34 +00:00
|
|
|
{
|
2007-03-18 09:50:53 +00:00
|
|
|
logf("incorrect tc serial:%ld", lastplayed);
|
2006-07-20 12:19:31 +00:00
|
|
|
return;
|
2006-08-02 17:39:34 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
if (runtimedb)
|
2011-01-02 02:49:13 +00:00
|
|
|
{
|
|
|
|
long playcount;
|
|
|
|
long playtime;
|
|
|
|
|
|
|
|
playcount = id3->playcount + 1;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
/* Ignore the last 15s (crossfade etc.) */
|
|
|
|
playtime = id3->playtime + MIN(id3->length, id3->elapsed + 15 * 1000);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
logf("ube:%s", id3->path);
|
|
|
|
logf("-> %ld/%ld", playcount, playtime);
|
|
|
|
logf("-> %ld/%ld/%ld", id3->elapsed, id3->length,
|
|
|
|
MIN(id3->length, id3->elapsed + 15 * 1000));
|
|
|
|
|
|
|
|
/* Queue the updates to the tagcache system. */
|
|
|
|
tagcache_update_numeric(tagcache_idx, tag_playcount, playcount);
|
|
|
|
tagcache_update_numeric(tagcache_idx, tag_playtime, playtime);
|
|
|
|
tagcache_update_numeric(tagcache_idx, tag_lastplayed, lastplayed);
|
|
|
|
}
|
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
if (autoresume)
|
2011-01-02 02:49:13 +00:00
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
unsigned long elapsed = auto_skip ? 0 : id3->elapsed;
|
2013-07-12 16:06:38 +00:00
|
|
|
unsigned long offset = auto_skip ? 0 : id3->offset;
|
2013-07-14 11:59:39 +00:00
|
|
|
tagcache_update_numeric(tagcache_idx, tag_lastelapsed, elapsed);
|
2011-01-02 02:49:13 +00:00
|
|
|
tagcache_update_numeric(tagcache_idx, tag_lastoffset, offset);
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
logf("tagtree_track_finish_event: Save resume for %s: %lX %lX",
|
|
|
|
str_or_empty(id3->title), elapsed, offset);
|
2011-01-02 02:49:13 +00:00
|
|
|
}
|
2006-07-15 17:36:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 03:04:04 +00:00
|
|
|
int tagtree_export(void)
|
2006-07-16 15:04:46 +00:00
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_search tcs;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, str(LANG_CREATING));
|
2006-07-16 15:04:46 +00:00
|
|
|
if (!tagcache_create_changelog(&tcs))
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_FAILED));
|
2006-07-16 15:04:46 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2018-10-16 03:04:04 +00:00
|
|
|
return 0;
|
2006-07-16 15:04:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 03:04:04 +00:00
|
|
|
int tagtree_import(void)
|
2006-07-20 12:19:31 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_WAIT));
|
2006-07-20 12:19:31 +00:00
|
|
|
if (!tagcache_import_changelog())
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_FAILED));
|
2006-07-20 12:19:31 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2018-10-16 03:04:04 +00:00
|
|
|
return 0;
|
2006-07-20 12:19:31 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
static bool parse_menu(const char *filename);
|
|
|
|
|
2011-06-23 20:22:00 +00:00
|
|
|
static int parse_line(int n, char *buf, void *parameters)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
2006-09-19 11:54:33 +00:00
|
|
|
char data[256];
|
|
|
|
int variable;
|
2006-10-21 20:37:33 +00:00
|
|
|
static bool read_menu;
|
2006-09-19 11:54:33 +00:00
|
|
|
int i;
|
2011-06-23 20:22:00 +00:00
|
|
|
char *p;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
(void)parameters;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-06-23 20:22:00 +00:00
|
|
|
/* Strip possible <CR> at end of line. */
|
|
|
|
p = strchr(buf, '\r');
|
|
|
|
if (p != NULL)
|
|
|
|
*p = '\0';
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-25 15:14:15 +00:00
|
|
|
logf("parse:%d/%s", n, buf);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
/* First line, do initialisation. */
|
|
|
|
if (n == 0)
|
2006-08-23 08:41:18 +00:00
|
|
|
{
|
2006-10-21 20:37:33 +00:00
|
|
|
if (strcasecmp(TAGNAVI_VERSION, buf))
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
2006-10-21 20:37:33 +00:00
|
|
|
logf("Version mismatch");
|
|
|
|
return -1;
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
read_menu = false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (buf[0] == '#')
|
|
|
|
return 0;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (buf[0] == '\0')
|
|
|
|
{
|
|
|
|
if (read_menu)
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
2006-10-21 20:37:33 +00:00
|
|
|
/* End the menu */
|
|
|
|
read_menu = false;
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
2006-10-21 20:37:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (!read_menu)
|
|
|
|
{
|
|
|
|
strp = buf;
|
|
|
|
if (get_tag(&variable) <= 0)
|
|
|
|
return 0;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
switch (variable)
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
2006-10-21 20:37:33 +00:00
|
|
|
case var_format:
|
|
|
|
if (add_format(strp) < 0)
|
|
|
|
{
|
|
|
|
logf("Format add fail: %s", data);
|
|
|
|
}
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
case var_include:
|
|
|
|
if (get_token_str(data, sizeof(data)) < 0)
|
|
|
|
{
|
2007-03-18 09:50:53 +00:00
|
|
|
logf("%%include empty");
|
2006-10-25 15:14:15 +00:00
|
|
|
return 0;
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (!parse_menu(data))
|
|
|
|
{
|
|
|
|
logf("Load menu fail: %s", data);
|
|
|
|
}
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
case var_menu_start:
|
|
|
|
if (menu_count >= TAGMENU_MAX_MENUS)
|
|
|
|
{
|
|
|
|
logf("max menucount reached");
|
2006-10-25 15:14:15 +00:00
|
|
|
return 0;
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-06-22 12:48:06 +00:00
|
|
|
if (get_token_str(data, sizeof data) < 0)
|
2006-10-21 20:37:33 +00:00
|
|
|
{
|
2007-03-18 09:50:53 +00:00
|
|
|
logf("%%menu_start id empty");
|
2006-10-25 15:14:15 +00:00
|
|
|
return 0;
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-06-22 12:48:06 +00:00
|
|
|
menu = NULL;
|
|
|
|
for (i = 0; i < menu_count; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(menus[i]->id, data))
|
|
|
|
{
|
|
|
|
menu = menus[i];
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
|
|
|
if (menu == NULL)
|
2007-06-22 12:48:06 +00:00
|
|
|
{
|
2011-06-20 19:32:56 +00:00
|
|
|
menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!menus[menu_count])
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "menu");
|
|
|
|
return -2;
|
|
|
|
}
|
2007-06-22 12:48:06 +00:00
|
|
|
menu = menus[menu_count];
|
|
|
|
++menu_count;
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(menu->id, data, MAX_MENU_ID_SIZE);
|
2007-06-22 12:48:06 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (get_token_str(menu->title, sizeof(menu->title)) < 0)
|
|
|
|
{
|
2007-03-18 09:50:53 +00:00
|
|
|
logf("%%menu_start title empty");
|
2006-10-25 15:14:15 +00:00
|
|
|
return 0;
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
2006-10-25 15:14:15 +00:00
|
|
|
logf("menu: %s", menu->title);
|
2006-10-21 20:37:33 +00:00
|
|
|
read_menu = true;
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
case var_rootmenu:
|
|
|
|
/* Only set root menu once. */
|
2009-05-30 16:35:28 +00:00
|
|
|
if (rootmenu >= 0)
|
2006-09-19 11:54:33 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (get_token_str(data, sizeof(data)) < 0)
|
|
|
|
{
|
2009-05-30 16:35:28 +00:00
|
|
|
logf("%%rootmenu empty");
|
2006-10-25 15:14:15 +00:00
|
|
|
return 0;
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
for (i = 0; i < menu_count; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(menus[i]->id, data))
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
2009-05-30 16:35:28 +00:00
|
|
|
rootmenu = i;
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
2006-10-21 20:37:33 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
if (menu->itemcount >= TAGMENU_MAX_ITEMS)
|
|
|
|
{
|
|
|
|
logf("max itemcount reached");
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
/* Allocate */
|
|
|
|
if (menu->items[menu->itemcount] == NULL)
|
2011-06-20 19:32:56 +00:00
|
|
|
menu->items[menu->itemcount] = tagtree_alloc0(sizeof(struct menu_entry));
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!menu->items[menu->itemcount])
|
|
|
|
{
|
|
|
|
logf("tagtree failed to allocate %s", "menu items");
|
|
|
|
return -2;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_lock();
|
|
|
|
if (parse_search(menu->items[menu->itemcount], buf))
|
|
|
|
menu->itemcount++;
|
|
|
|
tagtree_unlock();
|
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool parse_menu(const char *filename)
|
|
|
|
{
|
|
|
|
int fd;
|
2006-10-25 15:14:15 +00:00
|
|
|
char buf[1024];
|
2019-07-30 01:49:41 +00:00
|
|
|
int rc;
|
2006-10-21 20:37:33 +00:00
|
|
|
|
|
|
|
if (menu_count >= TAGMENU_MAX_MENUS)
|
|
|
|
{
|
|
|
|
logf("max menucount reached");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
logf("Search instruction file not found.");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-21 20:37:33 +00:00
|
|
|
/* Now read file for real, parsing into si */
|
2019-07-30 01:49:41 +00:00
|
|
|
rc = fast_readline(fd, buf, sizeof buf, NULL, parse_line);
|
2006-04-04 19:28:13 +00:00
|
|
|
close(fd);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2019-07-30 01:49:41 +00:00
|
|
|
return (rc >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tagtree_unload(struct tree_context *c)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tagtree_lock();
|
|
|
|
|
|
|
|
remove_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event);
|
|
|
|
remove_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event);
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
tree_lock_cache(c);
|
|
|
|
struct tagentry *dptr = core_get_data(c->cache.entries_handle);
|
|
|
|
menu = menus[c->currextra];
|
|
|
|
if (!menu)
|
|
|
|
{
|
|
|
|
logf("tagtree menu doesn't exist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < menu->itemcount; i++)
|
|
|
|
{
|
|
|
|
dptr->name = NULL;
|
|
|
|
dptr->newtable = 0;
|
|
|
|
dptr->extraseek = 0;
|
|
|
|
dptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < menu_count; i++)
|
|
|
|
menus[i] = NULL;
|
|
|
|
menu_count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < format_count; i++)
|
|
|
|
formats[i] = NULL;
|
|
|
|
format_count = 0;
|
|
|
|
|
|
|
|
core_free(tagtree_handle);
|
|
|
|
tagtree_handle = 0;
|
|
|
|
tagtree_buf_used = 0;
|
|
|
|
tagtree_bufsize = 0;
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
|
|
|
if (lock_count > 0)
|
|
|
|
tagtree_unlock();/* second unlock to enable re-init */
|
2006-09-19 11:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tagtree_init(void)
|
|
|
|
{
|
2006-10-15 11:01:18 +00:00
|
|
|
format_count = 0;
|
2006-09-19 11:54:33 +00:00
|
|
|
menu_count = 0;
|
2006-09-26 06:40:14 +00:00
|
|
|
menu = NULL;
|
2009-05-30 16:35:28 +00:00
|
|
|
rootmenu = -1;
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_handle = core_alloc_maximum("tagtree", &tagtree_bufsize, &ops);
|
2019-07-30 01:49:41 +00:00
|
|
|
if (!parse_menu(FILE_SEARCH_INSTRUCTIONS))
|
|
|
|
{
|
|
|
|
tagtree_unload(NULL);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
/* safety check since tree.c needs to cast tagentry to entry */
|
|
|
|
if (sizeof(struct tagentry) != sizeof(struct entry))
|
|
|
|
panicf("tagentry(%zu) and entry mismatch(%zu)",
|
|
|
|
sizeof(struct tagentry), sizeof(struct entry));
|
|
|
|
if (lock_count > 0)
|
|
|
|
panicf("tagtree locked after parsing");
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-04-12 18:33:40 +00:00
|
|
|
/* If no root menu is set, assume it's the first single menu
|
|
|
|
* we have. That shouldn't normally happen. */
|
2009-05-30 16:35:28 +00:00
|
|
|
if (rootmenu < 0)
|
|
|
|
rootmenu = 0;
|
2008-03-16 13:55:16 +00:00
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
add_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event);
|
|
|
|
add_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event);
|
2011-08-30 14:01:33 +00:00
|
|
|
|
|
|
|
core_shrink(tagtree_handle, core_get_data(tagtree_handle), tagtree_buf_used);
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static bool show_search_progress(bool init, int count)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
static int last_tick = 0;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2008-02-27 17:42:51 +00:00
|
|
|
/* Don't show splashes for 1/2 second after starting search */
|
2006-04-15 13:57:15 +00:00
|
|
|
if (init)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2008-02-27 17:42:51 +00:00
|
|
|
last_tick = current_tick + HZ/2;
|
2006-04-15 13:57:15 +00:00
|
|
|
return true;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2008-02-27 17:42:51 +00:00
|
|
|
/* Update progress every 1/10 of a second */
|
2009-08-20 19:31:09 +00:00
|
|
|
if (TIME_AFTER(current_tick, last_tick + HZ/10))
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), count, str(LANG_OFF_ABORT));
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2006-04-15 13:57:15 +00:00
|
|
|
return false;
|
|
|
|
last_tick = current_tick;
|
2006-08-12 11:00:39 +00:00
|
|
|
yield();
|
2006-04-15 13:57:15 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static int format_str(struct tagcache_search *tcs, struct display_format *fmt,
|
|
|
|
char *buf, int buf_size)
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
2011-07-31 16:26:31 +00:00
|
|
|
char fmtbuf[20];
|
2006-10-24 16:20:48 +00:00
|
|
|
bool read_format = false;
|
2011-07-31 16:26:31 +00:00
|
|
|
unsigned fmtbuf_pos = 0;
|
2006-10-24 16:20:48 +00:00
|
|
|
int parpos = 0;
|
|
|
|
int buf_pos = 0;
|
|
|
|
int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
memset(buf, 0, buf_size);
|
|
|
|
for (i = 0; fmt->formatstr[i] != '\0'; i++)
|
|
|
|
{
|
|
|
|
if (fmt->formatstr[i] == '%')
|
|
|
|
{
|
|
|
|
read_format = true;
|
|
|
|
fmtbuf_pos = 0;
|
|
|
|
if (parpos >= fmt->tag_count)
|
|
|
|
{
|
|
|
|
logf("too many format tags");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-08-04 10:23:18 +00:00
|
|
|
char formatchar = fmt->formatstr[i];
|
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
if (read_format)
|
|
|
|
{
|
2011-07-31 16:26:31 +00:00
|
|
|
fmtbuf[fmtbuf_pos++] = formatchar;
|
|
|
|
if (fmtbuf_pos >= sizeof fmtbuf)
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
|
|
|
logf("format parse error");
|
|
|
|
return -2;
|
|
|
|
}
|
2011-07-31 16:26:31 +00:00
|
|
|
|
|
|
|
if (formatchar == 's' || formatchar == 'd')
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
2011-07-31 16:26:31 +00:00
|
|
|
unsigned space_left = buf_size - buf_pos;
|
2011-08-04 10:23:18 +00:00
|
|
|
char tmpbuf[MAX_PATH];
|
2011-07-31 16:26:31 +00:00
|
|
|
char *result;
|
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
fmtbuf[fmtbuf_pos] = '\0';
|
|
|
|
read_format = false;
|
2011-07-31 16:26:31 +00:00
|
|
|
|
|
|
|
switch (formatchar)
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
2011-07-31 16:26:31 +00:00
|
|
|
case 's':
|
|
|
|
if (fmt->tags[parpos] == tcs->type)
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
2011-07-31 16:26:31 +00:00
|
|
|
result = tcs->result;
|
2006-10-24 16:20:48 +00:00
|
|
|
}
|
2011-07-31 16:26:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Need to fetch the tag data. */
|
|
|
|
int tag = fmt->tags[parpos];
|
|
|
|
|
|
|
|
if (!tagcache_retrieve(tcs, tcs->idx_id,
|
|
|
|
(tag == tag_virt_basename ?
|
|
|
|
tag_filename : tag),
|
2011-08-04 10:23:18 +00:00
|
|
|
tmpbuf, sizeof tmpbuf))
|
2011-07-31 16:26:31 +00:00
|
|
|
{
|
|
|
|
logf("retrieve failed");
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag == tag_virt_basename
|
|
|
|
&& (result = strrchr(tmpbuf, '/')) != NULL)
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = tmpbuf;
|
|
|
|
}
|
2011-08-04 10:23:18 +00:00
|
|
|
buf_pos +=
|
|
|
|
snprintf(&buf[buf_pos], space_left, fmtbuf, result);
|
2011-07-31 16:26:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
2011-08-04 10:23:18 +00:00
|
|
|
buf_pos +=
|
|
|
|
snprintf(&buf[buf_pos], space_left, fmtbuf,
|
|
|
|
tagcache_get_numeric(tcs, fmt->tags[parpos]));
|
2006-10-24 16:20:48 +00:00
|
|
|
}
|
2011-07-31 16:26:31 +00:00
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
parpos++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-31 16:26:31 +00:00
|
|
|
else
|
2011-08-04 10:23:18 +00:00
|
|
|
buf[buf_pos++] = formatchar;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-08-04 10:23:18 +00:00
|
|
|
if (buf_pos >= buf_size - 1) /* need at least one more byte for \0 */
|
2006-10-24 16:20:48 +00:00
|
|
|
{
|
|
|
|
logf("buffer overflow");
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
buf[buf_pos++] = '\0';
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-24 16:20:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
static struct tagentry* get_entries(struct tree_context *tc)
|
|
|
|
{
|
|
|
|
return core_get_data(tc->cache.entries_handle);
|
|
|
|
}
|
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
static int retrieve_entries(struct tree_context *c, int offset, bool init)
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_search tcs;
|
2006-08-26 22:00:22 +00:00
|
|
|
struct display_format *fmt;
|
2006-04-15 13:57:15 +00:00
|
|
|
int i;
|
|
|
|
int namebufused = 0;
|
|
|
|
int total_count = 0;
|
2006-04-19 18:56:59 +00:00
|
|
|
int special_entry_count = 0;
|
2006-08-25 21:13:49 +00:00
|
|
|
int level = c->currextra;
|
2006-04-19 11:03:37 +00:00
|
|
|
int tag;
|
2006-04-15 13:57:15 +00:00
|
|
|
bool sort = false;
|
2006-09-26 18:59:16 +00:00
|
|
|
int sort_limit;
|
|
|
|
int strip;
|
2009-08-20 19:31:09 +00:00
|
|
|
|
|
|
|
/* Show search progress straight away if the disk needs to spin up,
|
|
|
|
otherwise show it after the normal 1/2 second delay */
|
|
|
|
show_search_progress(
|
2008-10-07 19:37:33 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
2009-08-20 19:31:09 +00:00
|
|
|
storage_disk_is_active()
|
2008-02-27 17:42:51 +00:00
|
|
|
#else
|
2009-08-20 19:31:09 +00:00
|
|
|
true
|
2008-02-26 19:25:07 +00:00
|
|
|
#endif
|
2009-08-20 19:31:09 +00:00
|
|
|
, 0);
|
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
if (c->currtable == ALLSUBENTRIES)
|
2006-04-19 11:03:37 +00:00
|
|
|
{
|
|
|
|
tag = tag_title;
|
2006-08-25 21:13:49 +00:00
|
|
|
level--;
|
2006-04-19 11:03:37 +00:00
|
|
|
}
|
|
|
|
else
|
2006-08-25 21:13:49 +00:00
|
|
|
tag = csi->tagorder[level];
|
2006-04-19 11:03:37 +00:00
|
|
|
|
2019-07-30 01:49:41 +00:00
|
|
|
if (tag == menu_reload)
|
|
|
|
return RELOAD_TAGTREE;
|
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
if (!tagcache_search(&tcs, tag))
|
2006-04-16 17:32:54 +00:00
|
|
|
return -1;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-25 13:22:46 +00:00
|
|
|
/* Prevent duplicate entries in the search list. */
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-03 08:19:32 +00:00
|
|
|
if (level || csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag))
|
2006-08-25 13:22:46 +00:00
|
|
|
sort = true;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-25 21:13:49 +00:00
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
{
|
2009-06-03 08:19:32 +00:00
|
|
|
if (TAGCACHE_IS_NUMERIC(csi->tagorder[i]))
|
2006-08-25 21:13:49 +00:00
|
|
|
{
|
|
|
|
static struct tagcache_search_clause cc;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-25 21:13:49 +00:00
|
|
|
memset(&cc, 0, sizeof(struct tagcache_search_clause));
|
|
|
|
cc.tag = csi->tagorder[i];
|
|
|
|
cc.type = clause_is;
|
|
|
|
cc.numeric = true;
|
|
|
|
cc.numeric_data = csi->result_seek[i];
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_add_clause(&tcs, &cc);
|
2006-08-25 21:13:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-12 16:03:20 +00:00
|
|
|
tagcache_search_add_filter(&tcs, csi->tagorder[i],
|
2006-08-25 21:13:49 +00:00
|
|
|
csi->result_seek[i]);
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
/* because tagcache saves the clauses, we need to lock the buffer
|
|
|
|
* for the entire duration of the search */
|
|
|
|
tagtree_lock();
|
2006-08-25 21:13:49 +00:00
|
|
|
for (i = 0; i <= level; i++)
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2006-08-25 13:22:46 +00:00
|
|
|
int j;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-25 13:22:46 +00:00
|
|
|
for (j = 0; j < csi->clause_count[i]; j++)
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_add_clause(&tcs, csi->clause[i][j]);
|
2006-04-15 13:57:15 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
current_offset = offset;
|
|
|
|
current_entry_count = 0;
|
2006-03-26 11:33:42 +00:00
|
|
|
c->dirfull = false;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
fmt = NULL;
|
|
|
|
for (i = 0; i < format_count; i++)
|
|
|
|
{
|
|
|
|
if (formats[i]->group_id == csi->format_id[level])
|
|
|
|
fmt = formats[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt)
|
2006-08-26 22:00:22 +00:00
|
|
|
{
|
|
|
|
sort_inverse = fmt->sort_inverse;
|
|
|
|
sort_limit = fmt->limit;
|
2006-09-26 18:59:16 +00:00
|
|
|
strip = fmt->strip;
|
2008-07-01 20:55:19 +00:00
|
|
|
sort = true;
|
2006-08-26 22:00:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sort_inverse = false;
|
|
|
|
sort_limit = 0;
|
2006-09-26 18:59:16 +00:00
|
|
|
strip = 0;
|
2006-08-26 22:00:22 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* lock buflib out due to possible yields */
|
|
|
|
tree_lock_cache(c);
|
|
|
|
struct tagentry *dptr = core_get_data(c->cache.entries_handle);
|
|
|
|
|
2006-07-16 15:04:46 +00:00
|
|
|
if (tag != tag_title && tag != tag_filename)
|
2006-04-19 11:03:37 +00:00
|
|
|
{
|
|
|
|
if (offset == 0)
|
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = ALLSUBENTRIES;
|
2006-04-19 11:03:37 +00:00
|
|
|
dptr->name = str(LANG_TAGNAVI_ALL_TRACKS);
|
|
|
|
dptr++;
|
|
|
|
current_entry_count++;
|
2011-08-04 10:21:52 +00:00
|
|
|
special_entry_count++;
|
2006-04-19 11:03:37 +00:00
|
|
|
}
|
2007-12-21 13:31:50 +00:00
|
|
|
if (offset <= 1)
|
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = NAVIBROWSE;
|
2007-12-21 13:31:50 +00:00
|
|
|
dptr->name = str(LANG_TAGNAVI_RANDOM);
|
|
|
|
dptr->extraseek = -1;
|
|
|
|
dptr++;
|
|
|
|
current_entry_count++;
|
2011-08-04 10:21:52 +00:00
|
|
|
special_entry_count++;
|
2007-12-21 13:31:50 +00:00
|
|
|
}
|
2011-08-04 10:21:52 +00:00
|
|
|
|
|
|
|
total_count += 2;
|
2006-04-19 11:03:37 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
while (tagcache_get_next(&tcs))
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
if (total_count++ < offset)
|
|
|
|
continue;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = NAVIBROWSE;
|
2006-07-16 15:04:46 +00:00
|
|
|
if (tag == tag_title || tag == tag_filename)
|
2006-08-30 18:18:37 +00:00
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = PLAYTRACK;
|
2009-06-20 16:17:54 +00:00
|
|
|
dptr->extraseek = tcs.idx_id;
|
2006-08-30 18:18:37 +00:00
|
|
|
}
|
|
|
|
else
|
2009-06-20 16:17:54 +00:00
|
|
|
dptr->extraseek = tcs.result_seek;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
fmt = NULL;
|
|
|
|
/* Check the format */
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_lock();
|
2006-10-15 11:01:18 +00:00
|
|
|
for (i = 0; i < format_count; i++)
|
|
|
|
{
|
|
|
|
if (formats[i]->group_id != csi->format_id[level])
|
|
|
|
continue;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
if (tagcache_check_clauses(&tcs, formats[i]->clause,
|
2006-10-15 11:01:18 +00:00
|
|
|
formats[i]->clause_count))
|
|
|
|
{
|
|
|
|
fmt = formats[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
tagtree_unlock();
|
2006-10-15 11:01:18 +00:00
|
|
|
|
2011-06-01 08:00:37 +00:00
|
|
|
if (strcmp(tcs.result, UNTAGGED) == 0)
|
|
|
|
{
|
|
|
|
tcs.result = str(LANG_TAGNAVI_UNTAGGED);
|
|
|
|
tcs.result_len = strlen(tcs.result);
|
|
|
|
tcs.ramresult = true;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
if (!tcs.ramresult || fmt)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
dptr->name = core_get_data(c->cache.name_buffer_handle)+namebufused;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-15 11:01:18 +00:00
|
|
|
if (fmt)
|
2006-04-19 11:03:37 +00:00
|
|
|
{
|
2011-08-04 10:23:18 +00:00
|
|
|
int ret = format_str(&tcs, fmt, dptr->name,
|
|
|
|
c->cache.name_buffer_size - namebufused);
|
|
|
|
if (ret == -4) /* buffer full */
|
|
|
|
{
|
|
|
|
logf("chunk mode #2: %d", current_entry_count);
|
|
|
|
c->dirfull = true;
|
|
|
|
sort = false;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
else if (ret < 0)
|
2006-03-30 12:07:32 +00:00
|
|
|
{
|
2006-10-24 16:20:48 +00:00
|
|
|
logf("format_str() failed");
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
2006-10-24 16:20:48 +00:00
|
|
|
return 0;
|
2006-03-30 12:07:32 +00:00
|
|
|
}
|
2011-08-04 10:23:18 +00:00
|
|
|
else
|
|
|
|
namebufused += strlen(dptr->name)+1;
|
2006-03-30 12:07:32 +00:00
|
|
|
}
|
|
|
|
else
|
2006-07-15 17:36:25 +00:00
|
|
|
{
|
2011-08-04 10:23:18 +00:00
|
|
|
namebufused += tcs.result_len;
|
|
|
|
if (namebufused < c->cache.name_buffer_size)
|
|
|
|
strcpy(dptr->name, tcs.result);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logf("chunk mode #2a: %d", current_entry_count);
|
|
|
|
c->dirfull = true;
|
|
|
|
sort = false;
|
|
|
|
break ;
|
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-06-20 16:17:54 +00:00
|
|
|
dptr->name = tcs.result;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
dptr++;
|
2006-04-15 13:57:15 +00:00
|
|
|
current_entry_count++;
|
|
|
|
|
2011-08-03 09:49:25 +00:00
|
|
|
if (current_entry_count >= c->cache.max_entries)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
logf("chunk mode #3: %d", current_entry_count);
|
2006-03-26 11:33:42 +00:00
|
|
|
c->dirfull = true;
|
2006-04-15 13:57:15 +00:00
|
|
|
sort = false;
|
2006-03-26 11:33:42 +00:00
|
|
|
break ;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
if (init && !tcs.ramsearch)
|
2006-04-08 08:59:47 +00:00
|
|
|
{
|
2008-02-27 17:42:51 +00:00
|
|
|
if (!show_search_progress(false, total_count))
|
2009-08-20 19:31:09 +00:00
|
|
|
{ /* user aborted */
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
2006-04-15 13:57:15 +00:00
|
|
|
return current_entry_count;
|
|
|
|
}
|
2006-04-08 08:59:47 +00:00
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-30 12:07:32 +00:00
|
|
|
if (sort)
|
2011-08-03 09:49:25 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
struct tagentry *entries = get_entries(c);
|
|
|
|
qsort(&entries[special_entry_count],
|
2006-04-19 18:56:59 +00:00
|
|
|
current_entry_count - special_entry_count,
|
2014-01-15 22:18:35 +00:00
|
|
|
sizeof(struct tagentry),
|
|
|
|
global_settings.interpret_numbers ? nat_compare : compare);
|
2011-08-03 09:49:25 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (!init)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
2006-04-15 13:57:15 +00:00
|
|
|
return current_entry_count;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
while (tagcache_get_next(&tcs))
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
if (!tcs.ramsearch)
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
|
|
|
if (!show_search_progress(false, total_count))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
total_count++;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-06-20 16:17:54 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (!sort && (sort_inverse || sort_limit))
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(HZ*4, ID2P(LANG_SHOWDIR_BUFFER_FULL), total_count);
|
2006-08-26 22:00:22 +00:00
|
|
|
logf("Too small dir buffer");
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-26 22:00:22 +00:00
|
|
|
if (sort_limit)
|
|
|
|
total_count = MIN(total_count, sort_limit);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-26 18:59:16 +00:00
|
|
|
if (strip)
|
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
dptr = get_entries(c);
|
2011-08-04 10:21:52 +00:00
|
|
|
for (i = special_entry_count; i < current_entry_count; i++, dptr++)
|
2006-09-26 18:59:16 +00:00
|
|
|
{
|
|
|
|
int len = strlen(dptr->name);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-26 18:59:16 +00:00
|
|
|
if (len < strip)
|
|
|
|
continue;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-26 18:59:16 +00:00
|
|
|
dptr->name = &dptr->name[strip];
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
return total_count;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
}
|
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
static int load_root(struct tree_context *c)
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
struct tagentry *dptr = core_get_data(c->cache.entries_handle);
|
2006-04-16 17:32:54 +00:00
|
|
|
int i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
tc = c;
|
2009-05-30 16:10:34 +00:00
|
|
|
c->currtable = ROOT;
|
2006-09-19 11:54:33 +00:00
|
|
|
if (c->dirlevel == 0)
|
2009-05-30 16:35:28 +00:00
|
|
|
c->currextra = rootmenu;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-26 06:40:14 +00:00
|
|
|
menu = menus[c->currextra];
|
|
|
|
if (menu == NULL)
|
|
|
|
return 0;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2018-12-22 18:45:02 +00:00
|
|
|
if (menu->itemcount > c->cache.max_entries)
|
|
|
|
panicf("%s tree_cache too small", __func__);
|
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
for (i = 0; i < menu->itemcount; i++)
|
2006-04-16 17:32:54 +00:00
|
|
|
{
|
2006-09-19 11:54:33 +00:00
|
|
|
dptr->name = menu->items[i]->name;
|
|
|
|
switch (menu->items[i]->type)
|
|
|
|
{
|
|
|
|
case menu_next:
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = NAVIBROWSE;
|
2006-09-19 11:54:33 +00:00
|
|
|
dptr->extraseek = i;
|
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 11:54:33 +00:00
|
|
|
case menu_load:
|
2009-05-30 16:10:34 +00:00
|
|
|
dptr->newtable = ROOT;
|
2006-09-19 11:54:33 +00:00
|
|
|
dptr->extraseek = menu->items[i]->link;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
dptr++;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
current_offset = 0;
|
|
|
|
current_entry_count = i;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tagtree_load(struct tree_context* c)
|
|
|
|
{
|
|
|
|
int count;
|
2006-04-15 13:57:15 +00:00
|
|
|
int table = c->currtable;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-10-20 06:49:31 +00:00
|
|
|
c->dirsindir = 0;
|
2006-04-15 13:57:15 +00:00
|
|
|
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
c->dirfull = false;
|
2009-05-30 16:10:34 +00:00
|
|
|
table = ROOT;
|
2006-04-15 13:57:15 +00:00
|
|
|
c->currtable = table;
|
2009-05-30 16:35:28 +00:00
|
|
|
c->currextra = rootmenu;
|
2006-04-15 13:57:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
switch (table)
|
2006-04-16 17:32:54 +00:00
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
case ROOT:
|
2006-04-16 17:32:54 +00:00
|
|
|
count = load_root(c);
|
|
|
|
break;
|
2006-04-15 13:57:15 +00:00
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
case ALLSUBENTRIES:
|
|
|
|
case NAVIBROWSE:
|
2006-04-15 13:57:15 +00:00
|
|
|
logf("navibrowse...");
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2009-06-20 16:17:54 +00:00
|
|
|
count = retrieve_entries(c, 0, true);
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-04-15 13:57:15 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
default:
|
|
|
|
logf("Unsupported table %d\n", table);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
if (count < 0)
|
|
|
|
{
|
2019-07-30 01:49:41 +00:00
|
|
|
if (count != RELOAD_TAGTREE)
|
|
|
|
splash(HZ, str(LANG_TAGCACHE_BUSY));
|
|
|
|
else /* unload and re-init tagtree */
|
|
|
|
{
|
|
|
|
splash(HZ, str(LANG_WAIT));
|
|
|
|
tagtree_unload(c);
|
|
|
|
tagtree_init();
|
|
|
|
}
|
2006-04-16 17:32:54 +00:00
|
|
|
c->dirlevel = 0;
|
|
|
|
count = load_root(c);
|
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
|
|
|
|
/* The _total_ numer of entries available. */
|
2006-04-16 17:32:54 +00:00
|
|
|
c->dirlength = c->filesindir = count;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
return count;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int tagtree_enter(struct tree_context* c)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
2006-04-15 13:57:15 +00:00
|
|
|
struct tagentry *dptr;
|
2007-10-29 12:02:55 +00:00
|
|
|
struct mp3entry *id3;
|
2006-03-26 11:33:42 +00:00
|
|
|
int newextra;
|
2006-04-19 11:03:37 +00:00
|
|
|
int seek;
|
2007-10-29 12:02:55 +00:00
|
|
|
int source;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
dptr = tagtree_get_entry(c, c->selected_item);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
c->dirfull = false;
|
2013-07-12 16:03:20 +00:00
|
|
|
seek = dptr->extraseek;
|
|
|
|
if (seek == -1)
|
2007-12-21 13:31:50 +00:00
|
|
|
{
|
2008-01-03 07:29:19 +00:00
|
|
|
if(c->filesindir<=2)
|
|
|
|
return 0;
|
2007-12-21 13:31:50 +00:00
|
|
|
srand(current_tick);
|
|
|
|
dptr = (tagtree_get_entry(c, 2+(rand() % (c->filesindir-2))));
|
|
|
|
seek = dptr->extraseek;
|
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
newextra = dptr->newtable;
|
|
|
|
|
|
|
|
if (c->dirlevel >= MAX_DIR_LEVELS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
c->selected_item_history[c->dirlevel]=c->selected_item;
|
|
|
|
c->table_history[c->dirlevel] = c->currtable;
|
|
|
|
c->extra_history[c->dirlevel] = c->currextra;
|
|
|
|
c->pos_history[c->dirlevel] = c->firstpos;
|
|
|
|
c->dirlevel++;
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* lock buflib for possible I/O to protect dptr */
|
|
|
|
tree_lock_cache(c);
|
|
|
|
tagtree_lock();
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
switch (c->currtable) {
|
2009-05-30 16:10:34 +00:00
|
|
|
case ROOT:
|
2006-03-26 11:33:42 +00:00
|
|
|
c->currextra = newextra;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
if (newextra == ROOT)
|
2006-09-19 11:54:33 +00:00
|
|
|
{
|
2006-09-26 06:40:14 +00:00
|
|
|
menu = menus[seek];
|
2006-09-19 11:54:33 +00:00
|
|
|
c->currextra = seek;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
else if (newextra == NAVIBROWSE)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-06-20 19:32:52 +00:00
|
|
|
csi = &menu->items[seek]->si;
|
2006-04-04 19:28:13 +00:00
|
|
|
c->currextra = 0;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
|
|
|
strlcpy(current_title[c->currextra], dptr->name,
|
2009-07-14 13:57:45 +00:00
|
|
|
sizeof(current_title[0]));
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
/* Read input as necessary. */
|
|
|
|
for (i = 0; i < csi->tagorder_count; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < csi->clause_count[i]; j++)
|
|
|
|
{
|
2007-10-30 10:02:57 +00:00
|
|
|
char* searchstring;
|
2011-05-10 10:25:41 +00:00
|
|
|
|
|
|
|
if (csi->clause[i][j]->type == clause_logical_or)
|
|
|
|
continue;
|
|
|
|
|
2007-10-29 12:02:55 +00:00
|
|
|
source = csi->clause[i][j]->source;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-10-29 12:02:55 +00:00
|
|
|
if (source == source_constant)
|
2006-04-04 19:28:13 +00:00
|
|
|
continue;
|
2007-10-30 10:02:57 +00:00
|
|
|
|
|
|
|
searchstring=csi->clause[i][j]->str;
|
2013-07-12 16:03:20 +00:00
|
|
|
*searchstring = '\0';
|
|
|
|
|
2007-10-29 12:02:55 +00:00
|
|
|
id3 = audio_current_track();
|
2007-10-30 10:02:57 +00:00
|
|
|
|
2007-10-29 14:10:24 +00:00
|
|
|
if (source == source_current_path && id3)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
2007-10-29 14:10:24 +00:00
|
|
|
char *e;
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(searchstring, id3->path, SEARCHSTR_SIZE);
|
2007-10-29 14:10:24 +00:00
|
|
|
e = strrchr(searchstring, '/');
|
|
|
|
if (e)
|
|
|
|
*e = '\0';
|
|
|
|
}
|
2007-10-30 10:02:57 +00:00
|
|
|
else if (source > source_runtime && id3)
|
2007-10-29 12:02:55 +00:00
|
|
|
{
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2007-10-30 10:02:57 +00:00
|
|
|
int k = source-source_runtime;
|
|
|
|
int offset = id3_to_search_mapping[k].id3_offset;
|
2007-10-29 14:10:24 +00:00
|
|
|
char **src = (char**)((char*)id3 + offset);
|
|
|
|
if (*src)
|
|
|
|
{
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(searchstring, *src, SEARCHSTR_SIZE);
|
2007-10-29 14:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-30 10:02:57 +00:00
|
|
|
else
|
2007-10-29 12:02:55 +00:00
|
|
|
{
|
2020-07-21 06:33:53 +00:00
|
|
|
rc = kbd_input(searchstring, SEARCHSTR_SIZE, NULL);
|
2009-08-12 14:38:25 +00:00
|
|
|
if (rc < 0 || !searchstring[0])
|
2007-10-29 12:02:55 +00:00
|
|
|
{
|
|
|
|
tagtree_exit(c);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
2007-10-29 12:02:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-10-30 10:02:57 +00:00
|
|
|
if (csi->clause[i][j]->numeric)
|
|
|
|
csi->clause[i][j]->numeric_data = atoi(searchstring);
|
2013-07-12 16:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-05 18:46:38 +00:00
|
|
|
c->currtable = newextra;
|
2007-10-30 10:02:57 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
break;
|
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
case NAVIBROWSE:
|
|
|
|
case ALLSUBENTRIES:
|
|
|
|
if (newextra == PLAYTRACK)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
2008-08-19 12:05:01 +00:00
|
|
|
if (global_settings.party_mode && audio_status()) {
|
|
|
|
splash(HZ, ID2P(LANG_PARTY_MODE));
|
|
|
|
break;
|
|
|
|
}
|
2006-04-19 11:03:37 +00:00
|
|
|
c->dirlevel--;
|
2006-08-09 07:28:48 +00:00
|
|
|
/* about to create a new current playlist...
|
|
|
|
allow user to cancel the operation */
|
2008-05-01 10:13:12 +00:00
|
|
|
if (!warn_on_pl_erase())
|
|
|
|
break;
|
2006-04-04 19:28:13 +00:00
|
|
|
if (tagtree_play_folder(c) >= 0)
|
|
|
|
rc = 2;
|
2006-04-19 11:03:37 +00:00
|
|
|
break;
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
2006-04-19 11:03:37 +00:00
|
|
|
|
|
|
|
c->currtable = newextra;
|
|
|
|
csi->result_seek[c->currextra] = seek;
|
|
|
|
if (c->currextra < csi->tagorder_count-1)
|
|
|
|
c->currextra++;
|
|
|
|
else
|
|
|
|
c->dirlevel--;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-25 19:52:38 +00:00
|
|
|
/* Update the statusbar title */
|
2013-07-12 16:03:20 +00:00
|
|
|
strlcpy(current_title[c->currextra], dptr->name,
|
2009-07-14 13:57:45 +00:00
|
|
|
sizeof(current_title[0]));
|
2006-03-26 11:33:42 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
default:
|
|
|
|
c->dirlevel--;
|
|
|
|
break;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
c->selected_item=0;
|
|
|
|
gui_synclist_select_item(&tree_lists, c->selected_item);
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(c);
|
|
|
|
tagtree_unlock();
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tagtree_exit(struct tree_context* c)
|
|
|
|
{
|
|
|
|
c->dirfull = false;
|
2006-09-19 11:54:33 +00:00
|
|
|
if (c->dirlevel > 0)
|
|
|
|
c->dirlevel--;
|
2006-03-26 11:33:42 +00:00
|
|
|
c->selected_item=c->selected_item_history[c->dirlevel];
|
|
|
|
gui_synclist_select_item(&tree_lists, c->selected_item);
|
|
|
|
c->currtable = c->table_history[c->dirlevel];
|
|
|
|
c->currextra = c->extra_history[c->dirlevel];
|
|
|
|
c->firstpos = c->pos_history[c->dirlevel];
|
|
|
|
}
|
|
|
|
|
|
|
|
int tagtree_get_filename(struct tree_context* c, char *buf, int buflen)
|
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_search tcs;
|
2011-08-30 14:01:45 +00:00
|
|
|
int extraseek = tagtree_get_entry(c, c->selected_item)->extraseek;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
if (!tagcache_search(&tcs, tag_filename))
|
|
|
|
return -1;
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
if (!tagcache_retrieve(&tcs, extraseek, tcs.type, buf, buflen))
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
|
|
|
tagcache_search_finish(&tcs);
|
2006-04-16 17:32:54 +00:00
|
|
|
return -2;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tagcache_search_finish(&tcs);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-07-25 07:41:00 +00:00
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static bool insert_all_playlist(struct tree_context *c, int position, bool queue)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2009-06-20 16:17:54 +00:00
|
|
|
struct tagcache_search tcs;
|
2006-03-26 11:33:42 +00:00
|
|
|
int i;
|
2006-04-10 10:26:24 +00:00
|
|
|
char buf[MAX_PATH];
|
2006-08-12 09:06:50 +00:00
|
|
|
int from, to, direction;
|
2006-10-15 11:01:18 +00:00
|
|
|
int files_left = c->filesindir;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2006-04-16 17:32:54 +00:00
|
|
|
if (!tagcache_search(&tcs, tag_filename))
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ, ID2P(LANG_TAGCACHE_BUSY));
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-07-25 07:41:00 +00:00
|
|
|
return false;
|
2006-04-16 17:32:54 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-12-26 13:31:04 +00:00
|
|
|
if (position == PLAYLIST_REPLACE)
|
|
|
|
{
|
2008-04-20 11:19:50 +00:00
|
|
|
if (playlist_remove_all_tracks(NULL) == 0)
|
2006-12-26 13:31:04 +00:00
|
|
|
position = PLAYLIST_INSERT_LAST;
|
2008-06-29 07:29:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cpu_boost(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-12-26 13:31:04 +00:00
|
|
|
|
2006-08-12 09:06:50 +00:00
|
|
|
if (position == PLAYLIST_INSERT_FIRST)
|
|
|
|
{
|
|
|
|
from = c->filesindir - 1;
|
|
|
|
to = -1;
|
|
|
|
direction = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
from = 0;
|
|
|
|
to = c->filesindir;
|
|
|
|
direction = 1;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-08-12 09:06:50 +00:00
|
|
|
for (i = from; i != to; i += direction)
|
2006-04-10 10:26:24 +00:00
|
|
|
{
|
2006-10-15 11:01:18 +00:00
|
|
|
/* Count back to zero */
|
|
|
|
if (!show_search_progress(false, files_left--))
|
2006-04-15 13:57:15 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
|
|
|
if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek,
|
2006-10-24 16:20:48 +00:00
|
|
|
tcs.type, buf, sizeof buf))
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-10 10:26:24 +00:00
|
|
|
continue;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 09:50:45 +00:00
|
|
|
if (playlist_insert_track(NULL, buf, position, queue, false) < 0)
|
2006-08-14 19:03:37 +00:00
|
|
|
{
|
|
|
|
logf("playlist_insert_track failed");
|
2006-08-10 09:50:45 +00:00
|
|
|
break;
|
2006-08-14 19:03:37 +00:00
|
|
|
}
|
2006-08-12 11:00:39 +00:00
|
|
|
yield();
|
2006-04-10 10:26:24 +00:00
|
|
|
}
|
2006-08-10 09:50:45 +00:00
|
|
|
playlist_sync(NULL);
|
2006-04-10 10:26:24 +00:00
|
|
|
tagcache_search_finish(&tcs);
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tagtree_insert_selection_playlist(int position, bool queue)
|
|
|
|
{
|
2006-07-26 06:44:39 +00:00
|
|
|
char buf[MAX_PATH];
|
2006-07-25 07:41:00 +00:00
|
|
|
int dirlevel = tc->dirlevel;
|
2011-08-30 14:01:45 +00:00
|
|
|
int newtable;
|
2006-07-25 07:41:00 +00:00
|
|
|
|
2009-08-20 19:31:09 +00:00
|
|
|
show_search_progress(
|
|
|
|
#ifdef HAVE_DISK_STORAGE
|
|
|
|
storage_disk_is_active()
|
|
|
|
#else
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
, 0);
|
|
|
|
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-08-20 19:31:09 +00:00
|
|
|
/* We need to set the table to allsubentries. */
|
2011-08-30 14:01:45 +00:00
|
|
|
newtable = tagtree_get_entry(tc, tc->selected_item)->newtable;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-26 06:44:39 +00:00
|
|
|
/* Insert a single track? */
|
2011-08-30 14:01:45 +00:00
|
|
|
if (newtable == PLAYTRACK)
|
2006-07-26 06:44:39 +00:00
|
|
|
{
|
|
|
|
if (tagtree_get_filename(tc, buf, sizeof buf) < 0)
|
|
|
|
{
|
|
|
|
logf("tagtree_get_filename failed");
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-10 09:50:45 +00:00
|
|
|
playlist_insert_track(NULL, buf, position, queue, true);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-26 06:44:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
if (newtable == NAVIBROWSE)
|
2006-07-25 07:41:00 +00:00
|
|
|
{
|
|
|
|
tagtree_enter(tc);
|
|
|
|
tagtree_load(tc);
|
2011-08-30 14:01:45 +00:00
|
|
|
newtable = tagtree_get_entry(tc, tc->selected_item)->newtable;
|
2006-07-25 07:41:00 +00:00
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
else if (newtable != ALLSUBENTRIES)
|
2006-07-25 07:41:00 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
logf("unsupported table: %d", newtable);
|
2006-07-25 07:41:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
/* Now the current table should be allsubentries. */
|
2011-08-30 14:01:45 +00:00
|
|
|
if (newtable != PLAYTRACK)
|
2006-07-25 07:41:00 +00:00
|
|
|
{
|
|
|
|
tagtree_enter(tc);
|
|
|
|
tagtree_load(tc);
|
2011-08-30 14:01:45 +00:00
|
|
|
newtable = tagtree_get_entry(tc, tc->selected_item)->newtable;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
/* And now the newtable should be playtrack. */
|
2011-08-30 14:01:45 +00:00
|
|
|
if (newtable != PLAYTRACK)
|
2006-07-25 07:41:00 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
logf("newtable: %d !!", newtable);
|
2006-07-25 07:41:00 +00:00
|
|
|
tc->dirlevel = dirlevel;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tc->filesindir <= 0)
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ, ID2P(LANG_END_PLAYLIST));
|
2006-07-25 07:41:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
logf("insert_all_playlist");
|
2006-08-14 19:03:37 +00:00
|
|
|
if (!insert_all_playlist(tc, position, queue))
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_FAILED));
|
2006-07-25 07:41:00 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
/* Finally return the dirlevel to its original value. */
|
|
|
|
while (tc->dirlevel > dirlevel)
|
|
|
|
tagtree_exit(tc);
|
|
|
|
tagtree_load(tc);
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tagtree_play_folder(struct tree_context* c)
|
|
|
|
{
|
|
|
|
if (playlist_create(NULL, NULL) < 0)
|
|
|
|
{
|
|
|
|
logf("Failed creating playlist\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-09-18 04:41:50 +00:00
|
|
|
if (!insert_all_playlist(c, PLAYLIST_INSERT_LAST, false))
|
2006-07-25 07:41:00 +00:00
|
|
|
return -2;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
c->selected_item = playlist_shuffle(current_tick, c->selected_item);
|
|
|
|
if (!global_settings.play_selected)
|
|
|
|
c->selected_item = 0;
|
|
|
|
gui_synclist_select_item(&tree_lists, c->selected_item);
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
playlist_start(c->selected_item, 0, 0);
|
2009-12-21 05:44:00 +00:00
|
|
|
playlist_get_current()->num_inserted_tracks = 0; /* make warn on playlist erase work */
|
2006-03-26 11:33:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
static struct tagentry* tagtree_get_entry(struct tree_context *c, int id)
|
2006-04-10 10:26:24 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
struct tagentry *entry;
|
2006-04-15 13:57:15 +00:00
|
|
|
int realid = id - current_offset;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
/* Load the next chunk if necessary. */
|
|
|
|
if (realid >= current_entry_count || realid < 0)
|
|
|
|
{
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2009-06-20 16:17:54 +00:00
|
|
|
if (retrieve_entries(c, MAX(0, id - (current_entry_count / 2)),
|
2006-04-16 17:32:54 +00:00
|
|
|
false) < 0)
|
|
|
|
{
|
2006-04-19 18:56:59 +00:00
|
|
|
logf("retrieve failed");
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-04-16 17:32:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
realid = id - current_offset;
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-04-15 13:57:15 +00:00
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
entry = get_entries(c);
|
2006-04-15 13:57:15 +00:00
|
|
|
return &entry[realid];
|
2006-04-10 10:26:24 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
char* tagtree_get_entry_name(struct tree_context *c, int id,
|
|
|
|
char* buf, size_t bufsize)
|
|
|
|
{
|
|
|
|
struct tagentry *entry = tagtree_get_entry(c, id);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
|
|
|
strlcpy(buf, entry->name, bufsize);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-19 12:36:21 +00:00
|
|
|
char *tagtree_get_title(struct tree_context* c)
|
|
|
|
{
|
|
|
|
switch (c->currtable)
|
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
case ROOT:
|
2006-09-19 12:36:21 +00:00
|
|
|
return menu->title;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
case NAVIBROWSE:
|
|
|
|
case ALLSUBENTRIES:
|
2006-09-25 19:52:38 +00:00
|
|
|
return current_title[c->currextra];
|
2006-09-19 12:36:21 +00:00
|
|
|
}
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-09-19 12:36:21 +00:00
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
|
2006-05-05 07:01:43 +00:00
|
|
|
int tagtree_get_attr(struct tree_context* c)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-05-05 07:01:43 +00:00
|
|
|
int attr = -1;
|
2006-03-26 11:33:42 +00:00
|
|
|
switch (c->currtable)
|
|
|
|
{
|
2009-05-30 16:10:34 +00:00
|
|
|
case NAVIBROWSE:
|
2006-04-04 19:28:13 +00:00
|
|
|
if (csi->tagorder[c->currextra] == tag_title)
|
2007-04-18 13:03:01 +00:00
|
|
|
attr = FILE_ATTR_AUDIO;
|
2006-04-04 19:28:13 +00:00
|
|
|
else
|
2006-05-05 07:01:43 +00:00
|
|
|
attr = ATTR_DIRECTORY;
|
2006-03-26 11:33:42 +00:00
|
|
|
break;
|
|
|
|
|
2009-05-30 16:10:34 +00:00
|
|
|
case ALLSUBENTRIES:
|
2007-04-18 13:03:01 +00:00
|
|
|
attr = FILE_ATTR_AUDIO;
|
2006-04-19 11:03:37 +00:00
|
|
|
break;
|
2013-07-12 16:03:20 +00:00
|
|
|
|
2006-05-05 07:01:43 +00:00
|
|
|
default:
|
|
|
|
attr = ATTR_DIRECTORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
int tagtree_get_icon(struct tree_context* c)
|
2006-05-05 07:01:43 +00:00
|
|
|
{
|
2006-05-05 07:54:19 +00:00
|
|
|
int icon = Icon_Folder;
|
2006-05-05 07:01:43 +00:00
|
|
|
|
2007-04-18 13:03:01 +00:00
|
|
|
if (tagtree_get_attr(c) == FILE_ATTR_AUDIO)
|
2006-05-05 07:54:19 +00:00
|
|
|
icon = Icon_Audio;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|