2006-03-26 11:33:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Miika Pekkarinen
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic structure on this file was copied from dbtree.c and modified to
|
|
|
|
* support the tag cache interface.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "splash.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#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"
|
2006-04-04 19:28:13 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "atoi.h"
|
2006-07-15 17:36:25 +00:00
|
|
|
#include "playback.h"
|
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
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
static char searchstring[32];
|
2006-04-04 19:28:13 +00:00
|
|
|
#define MAX_TAGS 5
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
/*
|
|
|
|
* "%3d. %s" autoscore title
|
|
|
|
*
|
|
|
|
* valid = true
|
|
|
|
* formatstr = "%-3d. %s"
|
|
|
|
* tags[0] = tag_autoscore
|
|
|
|
* tags[1] = tag_title
|
|
|
|
* tag_count = 2
|
|
|
|
*/
|
|
|
|
struct display_format {
|
|
|
|
bool valid;
|
|
|
|
char formatstr[64];
|
|
|
|
int tags[MAX_TAGS];
|
|
|
|
int tag_count;
|
|
|
|
};
|
|
|
|
|
2006-04-04 19:28:13 +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];
|
2006-07-15 17:36:25 +00:00
|
|
|
struct display_format format[MAX_TAGS];
|
2006-04-04 19:28:13 +00:00
|
|
|
int clause_count[MAX_TAGS];
|
|
|
|
int result_seek[MAX_TAGS];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct search_instruction *si, *csi;
|
|
|
|
static int si_count = 0;
|
|
|
|
static const char *strp;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Read the data. */
|
|
|
|
while (*strp != '"' && *strp != '\0' && --size > 0)
|
|
|
|
*(buf++) = *(strp++);
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
if (*strp != '"')
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
strp++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MATCH(tag,str1,str2,settag) \
|
|
|
|
if (!strcasecmp(str1, str2)) { \
|
|
|
|
*tag = settag; \
|
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_tag(int *tag)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Find the start. */
|
|
|
|
while (*strp == ' ' && *strp != '\0')
|
|
|
|
strp++;
|
|
|
|
|
|
|
|
if (*strp == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < (int)sizeof(buf)-1; i++)
|
|
|
|
{
|
|
|
|
if (*strp == '\0' || *strp == ' ')
|
|
|
|
break ;
|
|
|
|
buf[i] = *strp;
|
|
|
|
strp++;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
|
|
MATCH(tag, buf, "album", tag_album);
|
2006-04-19 11:03:37 +00:00
|
|
|
MATCH(tag, buf, "artist", tag_artist);
|
|
|
|
MATCH(tag, buf, "bitrate", tag_bitrate);
|
2006-04-04 19:28:13 +00:00
|
|
|
MATCH(tag, buf, "composer", tag_composer);
|
2006-04-19 11:03:37 +00:00
|
|
|
MATCH(tag, buf, "genre", tag_genre);
|
2006-04-04 19:28:13 +00:00
|
|
|
MATCH(tag, buf, "length", tag_length);
|
2006-04-19 11:03:37 +00:00
|
|
|
MATCH(tag, buf, "title", tag_title);
|
2006-07-16 15:04:46 +00:00
|
|
|
MATCH(tag, buf, "filename", tag_filename);
|
2006-04-04 19:28:13 +00:00
|
|
|
MATCH(tag, buf, "tracknum", tag_tracknumber);
|
2006-04-19 11:03:37 +00:00
|
|
|
MATCH(tag, buf, "year", tag_year);
|
2006-07-15 17:36:25 +00:00
|
|
|
MATCH(tag, buf, "playcount", tag_playcount);
|
|
|
|
MATCH(tag, buf, "autoscore", tag_virt_autoscore);
|
2006-04-04 19:28:13 +00:00
|
|
|
|
|
|
|
logf("NO MATCH: %s\n", buf);
|
|
|
|
if (buf[0] == '?')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_clause(int *condition)
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Find the start. */
|
|
|
|
while (*strp == ' ' && *strp != '\0')
|
|
|
|
strp++;
|
|
|
|
|
|
|
|
if (*strp == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < (int)sizeof(buf)-1; i++)
|
|
|
|
{
|
|
|
|
if (*strp == '\0' || *strp == ' ')
|
|
|
|
break ;
|
|
|
|
buf[i] = *strp;
|
|
|
|
strp++;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
|
|
MATCH(condition, buf, "=", clause_is);
|
2006-04-19 11:03:37 +00:00
|
|
|
MATCH(condition, buf, "==", clause_is);
|
2006-04-04 19:28:13 +00:00
|
|
|
MATCH(condition, buf, ">", clause_gt);
|
|
|
|
MATCH(condition, buf, ">=", clause_gteq);
|
|
|
|
MATCH(condition, buf, "<", clause_lt);
|
|
|
|
MATCH(condition, buf, "<=", clause_lteq);
|
|
|
|
MATCH(condition, buf, "~", clause_contains);
|
|
|
|
MATCH(condition, buf, "^", clause_begins_with);
|
|
|
|
MATCH(condition, buf, "$", clause_ends_with);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
static bool add_clause(struct search_instruction *inst,
|
2006-04-04 19:28:13 +00:00
|
|
|
int tag, int type, const char *str)
|
|
|
|
{
|
|
|
|
int len = strlen(str);
|
|
|
|
struct tagcache_search_clause *clause;
|
|
|
|
|
|
|
|
if (inst->clause_count[inst->tagorder_count] >= TAGCACHE_MAX_CLAUSES)
|
|
|
|
{
|
|
|
|
logf("Too many clauses");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clause = &inst->clause[inst->tagorder_count]
|
|
|
|
[inst->clause_count[inst->tagorder_count]];
|
|
|
|
if (len >= (int)sizeof(clause->str) - 1)
|
|
|
|
{
|
|
|
|
logf("Too long str in condition");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clause->tag = tag;
|
|
|
|
clause->type = type;
|
|
|
|
if (len == 0)
|
|
|
|
clause->input = true;
|
|
|
|
else
|
|
|
|
clause->input = false;
|
|
|
|
|
|
|
|
if (tagcache_is_numeric_tag(tag))
|
|
|
|
{
|
|
|
|
clause->numeric = true;
|
|
|
|
clause->numeric_data = atoi(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clause->numeric = false;
|
|
|
|
strcpy(clause->str, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
inst->clause_count[inst->tagorder_count]++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
static int get_format_str(struct display_format *fmt)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(fmt, 0, sizeof(struct display_format));
|
|
|
|
|
|
|
|
if (get_token_str(fmt->formatstr, sizeof fmt->formatstr) < 0)
|
|
|
|
return -10;
|
|
|
|
|
|
|
|
while (fmt->tag_count < MAX_TAGS)
|
|
|
|
{
|
|
|
|
ret = get_tag(&fmt->tags[fmt->tag_count]);
|
|
|
|
if (ret < 0)
|
|
|
|
return -11;
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
fmt->tag_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt->valid = true;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
static int get_condition(struct search_instruction *inst)
|
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
struct display_format format;
|
|
|
|
struct display_format *fmt = NULL;
|
2006-04-04 19:28:13 +00:00
|
|
|
int tag;
|
|
|
|
int condition;
|
|
|
|
char buf[32];
|
2006-07-15 17:36:25 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
switch (*strp)
|
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
case '=':
|
|
|
|
if (get_format_str(&format) < 0)
|
|
|
|
{
|
|
|
|
logf("get_format_str() parser failed!");
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
fmt = &format;
|
|
|
|
break;
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
case '?':
|
|
|
|
case ' ':
|
|
|
|
case '&':
|
|
|
|
strp++;
|
|
|
|
return 1;
|
|
|
|
case ':':
|
|
|
|
strp++;
|
|
|
|
case '\0':
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
if (fmt)
|
|
|
|
{
|
|
|
|
memcpy(&inst->format[inst->tagorder_count], fmt,
|
|
|
|
sizeof(struct display_format));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
inst->format[inst->tagorder_count].valid = false;
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
if (get_tag(&tag) <= 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (get_clause(&condition) <= 0)
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
if (get_token_str(buf, sizeof buf) < 0)
|
|
|
|
return -3;
|
|
|
|
|
|
|
|
logf("got clause: %d/%d [%s]", tag, condition, buf);
|
|
|
|
add_clause(inst, tag, condition, buf);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* example search:
|
|
|
|
* "Best" artist ? year >= "2000" & title !^ "crap" & genre = "good genre" \
|
|
|
|
* : album ? year >= "2000" : songs
|
|
|
|
* ^ begins with
|
|
|
|
* * contains
|
|
|
|
* $ ends with
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool parse_search(struct search_instruction *inst, const char *str)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(inst, 0, sizeof(struct search_instruction));
|
|
|
|
strp = str;
|
|
|
|
|
|
|
|
if (get_token_str(inst->name, sizeof inst->name) < 0)
|
|
|
|
{
|
|
|
|
logf("No name found.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (inst->tagorder_count < MAX_TAGS)
|
|
|
|
{
|
|
|
|
ret = get_tag(&inst->tagorder[inst->tagorder_count]);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
logf("Parse error #1");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
break ;
|
|
|
|
|
|
|
|
logf("tag: %d", inst->tagorder[inst->tagorder_count]);
|
|
|
|
|
|
|
|
while (get_condition(inst) > 0) ;
|
|
|
|
|
|
|
|
inst->tagorder_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-19 18:56:59 +00:00
|
|
|
static struct tagcache_search tcs, tcs2;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
return strncasecmp(e1->name, e2->name, MAX_PATH);
|
|
|
|
}
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
|
|
|
|
{
|
|
|
|
(void)id3;
|
|
|
|
(void)last_track;
|
|
|
|
|
|
|
|
logf("be:%d%s", last_track, id3->path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
|
|
|
|
{
|
|
|
|
(void)last_track;
|
|
|
|
long playcount;
|
|
|
|
long playtime;
|
|
|
|
long lastplayed;
|
|
|
|
|
|
|
|
/* Do not gather data unless proper setting has been enabled. */
|
|
|
|
if (!global_settings.runtimedb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Don't process unplayed tracks. */
|
|
|
|
if (id3->elapsed == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tagcache_find_index(&tcs, id3->path))
|
|
|
|
{
|
|
|
|
logf("tc stat: not found: %s", id3->path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
playcount = tagcache_get_numeric(&tcs, tag_playcount);
|
|
|
|
playtime = tagcache_get_numeric(&tcs, tag_playtime);
|
|
|
|
lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
|
|
|
|
|
|
|
|
playcount++;
|
|
|
|
|
2006-07-20 12:19:31 +00:00
|
|
|
lastplayed = tagcache_increase_serial();
|
|
|
|
if (lastplayed < 0)
|
|
|
|
return;
|
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
/* Ignore the last 15s (crossfade etc.) */
|
|
|
|
playtime += MIN(id3->length, id3->elapsed + 15 * 1000);
|
|
|
|
|
|
|
|
logf("ube:%s", id3->path);
|
|
|
|
logf("-> %d/%d/%d", last_track, playcount, playtime);
|
|
|
|
logf("-> %d/%d/%d", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000));
|
|
|
|
|
|
|
|
/* lastplayed not yet supported. */
|
|
|
|
|
|
|
|
if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount)
|
|
|
|
|| !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime)
|
|
|
|
|| !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, tag_lastplayed))
|
|
|
|
{
|
|
|
|
logf("tc stat: modify failed!");
|
|
|
|
tagcache_search_finish(&tcs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tagcache_search_finish(&tcs);
|
|
|
|
}
|
|
|
|
|
2006-07-16 15:04:46 +00:00
|
|
|
bool tagtree_export(void)
|
|
|
|
{
|
|
|
|
gui_syncsplash(0, true, str(LANG_WAIT));
|
|
|
|
if (!tagcache_create_changelog(&tcs))
|
|
|
|
{
|
|
|
|
gui_syncsplash(HZ*2, true, str(LANG_FAILED));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-20 12:19:31 +00:00
|
|
|
bool tagtree_import(void)
|
|
|
|
{
|
|
|
|
gui_syncsplash(0, true, str(LANG_WAIT));
|
|
|
|
if (!tagcache_import_changelog())
|
|
|
|
{
|
|
|
|
gui_syncsplash(HZ*2, true, str(LANG_FAILED));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
void tagtree_init(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char buf[256];
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
si_count = 0;
|
|
|
|
|
|
|
|
fd = open(FILE_SEARCH_INSTRUCTIONS, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
logf("Search instruction file not found.");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
si = (struct search_instruction *)(((long)audiobuf & ~0x03) + 0x04);
|
|
|
|
|
|
|
|
while ( 1 )
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
char *next = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = read(fd, &buf[pos], sizeof(buf)-pos-1);
|
|
|
|
if (rc >= 0)
|
|
|
|
buf[pos+rc] = '\0';
|
|
|
|
|
|
|
|
if ( (p = strchr(buf, '\r')) != NULL)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
next = ++p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
if ( (p = strchr(p, '\n')) != NULL)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
next = ++p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_search(si + si_count, buf))
|
|
|
|
break;
|
|
|
|
si_count++;
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
pos = sizeof(buf) - ((long)next - (long)buf) - 1;
|
|
|
|
memmove(buf, next, pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
audiobuf += sizeof(struct search_instruction) * si_count + 4;
|
2006-07-15 17:36:25 +00:00
|
|
|
|
|
|
|
audio_set_track_buffer_event(tagtree_buffer_event);
|
|
|
|
audio_set_track_unbuffer_event(tagtree_unbuffer_event);
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
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;
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (init)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
last_tick = current_tick;
|
|
|
|
return true;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
|
|
|
|
if (current_tick - last_tick > HZ/2)
|
|
|
|
{
|
|
|
|
gui_syncsplash(0, true, str(LANG_PLAYLIST_SEARCH_MSG), count,
|
|
|
|
#if CONFIG_KEYPAD == PLAYER_PAD
|
|
|
|
str(LANG_STOP_ABORT)
|
|
|
|
#else
|
|
|
|
str(LANG_OFF_ABORT)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (SETTINGS_CANCEL == button_get(false))
|
|
|
|
return false;
|
|
|
|
last_tick = current_tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
|
|
|
|
int offset, bool init)
|
|
|
|
{
|
|
|
|
struct tagentry *dptr = (struct tagentry *)c->dircache;
|
|
|
|
int i;
|
|
|
|
int namebufused = 0;
|
|
|
|
int total_count = 0;
|
2006-04-19 18:56:59 +00:00
|
|
|
int special_entry_count = 0;
|
2006-04-15 13:57:15 +00:00
|
|
|
int extra = c->currextra;
|
2006-04-19 11:03:37 +00:00
|
|
|
int tag;
|
2006-04-15 13:57:15 +00:00
|
|
|
bool sort = false;
|
|
|
|
|
|
|
|
if (init
|
2006-04-08 08:59:47 +00:00
|
|
|
#ifdef HAVE_TC_RAMCACHE
|
2006-04-15 13:57:15 +00:00
|
|
|
&& !tagcache_is_ramcache()
|
2006-04-08 08:59:47 +00:00
|
|
|
#endif
|
2006-04-15 13:57:15 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
show_search_progress(true, 0);
|
|
|
|
gui_syncsplash(0, true, str(LANG_PLAYLIST_SEARCH_MSG),
|
|
|
|
0, csi->name);
|
|
|
|
}
|
2006-04-08 08:59:47 +00:00
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
if (c->currtable == allsubentries)
|
|
|
|
{
|
|
|
|
tag = tag_title;
|
|
|
|
extra--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tag = csi->tagorder[extra];
|
|
|
|
|
|
|
|
if (!tagcache_search(tcs, tag))
|
2006-04-16 17:32:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
for (i = 0; i < extra; i++)
|
|
|
|
{
|
|
|
|
tagcache_search_add_filter(tcs, csi->tagorder[i], csi->result_seek[i]);
|
|
|
|
sort = true;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
for (i = 0; i < csi->clause_count[extra]; i++)
|
|
|
|
{
|
|
|
|
tagcache_search_add_clause(tcs, &csi->clause[extra][i]);
|
|
|
|
sort = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_offset = offset;
|
|
|
|
current_entry_count = 0;
|
2006-03-26 11:33:42 +00:00
|
|
|
c->dirfull = false;
|
2006-04-19 11:03:37 +00:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
dptr->newtable = allsubentries;
|
|
|
|
dptr->name = str(LANG_TAGNAVI_ALL_TRACKS);
|
|
|
|
dptr++;
|
|
|
|
current_entry_count++;
|
|
|
|
}
|
2006-04-19 18:56:59 +00:00
|
|
|
special_entry_count++;
|
2006-04-19 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
2006-04-19 18:56:59 +00:00
|
|
|
total_count += special_entry_count;
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
while (tagcache_get_next(tcs))
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
struct display_format *fmt = &csi->format[extra];
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (total_count++ < offset)
|
|
|
|
continue;
|
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
dptr->newtable = navibrowse;
|
|
|
|
dptr->extraseek = tcs->result_seek;
|
2006-07-16 15:04:46 +00:00
|
|
|
if (tag == tag_title || tag == tag_filename)
|
2006-07-15 17:36:25 +00:00
|
|
|
dptr->newtable = playtrack;
|
|
|
|
|
|
|
|
if (!tcs->ramsearch || fmt->valid)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
char buf[MAX_PATH];
|
|
|
|
int buf_pos = 0;
|
2006-04-05 18:46:38 +00:00
|
|
|
|
2006-07-15 17:36:25 +00:00
|
|
|
if (fmt->valid)
|
2006-04-19 11:03:37 +00:00
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
char fmtbuf[8];
|
|
|
|
bool read_format = false;
|
|
|
|
int fmtbuf_pos = 0;
|
|
|
|
int parpos = 0;
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof buf);
|
|
|
|
for (i = 0; fmt->formatstr[i] != '\0'; i++)
|
2006-03-30 12:07:32 +00:00
|
|
|
{
|
2006-07-15 17:36:25 +00:00
|
|
|
if (fmt->formatstr[i] == '%')
|
|
|
|
{
|
|
|
|
read_format = true;
|
|
|
|
fmtbuf_pos = 0;
|
|
|
|
if (parpos >= fmt->tag_count)
|
|
|
|
{
|
|
|
|
logf("too many format tags");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_format)
|
|
|
|
{
|
|
|
|
fmtbuf[fmtbuf_pos++] = fmt->formatstr[i];
|
|
|
|
if (fmtbuf_pos >= (long)sizeof(fmtbuf))
|
|
|
|
{
|
|
|
|
logf("format parse error");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt->formatstr[i] == 's')
|
|
|
|
{
|
|
|
|
fmtbuf[fmtbuf_pos] = '\0';
|
|
|
|
read_format = false;
|
|
|
|
snprintf(&buf[buf_pos], MAX_PATH - buf_pos, fmtbuf, tcs->result);
|
|
|
|
buf_pos += strlen(&buf[buf_pos]);
|
|
|
|
parpos++;
|
|
|
|
}
|
|
|
|
else if (fmt->formatstr[i] == 'd')
|
|
|
|
{
|
|
|
|
fmtbuf[fmtbuf_pos] = '\0';
|
|
|
|
read_format = false;
|
|
|
|
snprintf(&buf[buf_pos], MAX_PATH - buf_pos, fmtbuf,
|
|
|
|
tagcache_get_numeric(tcs, fmt->tags[parpos]));
|
|
|
|
buf_pos += strlen(&buf[buf_pos]);
|
|
|
|
parpos++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[buf_pos++] = fmt->formatstr[i];
|
|
|
|
|
|
|
|
if (buf_pos - 1 >= (long)sizeof(buf))
|
|
|
|
{
|
|
|
|
logf("buffer overflow");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-30 12:07:32 +00:00
|
|
|
}
|
2006-07-15 17:36:25 +00:00
|
|
|
|
|
|
|
buf[buf_pos++] = '\0';
|
2006-03-30 12:07:32 +00:00
|
|
|
}
|
2006-07-15 17:36:25 +00:00
|
|
|
|
|
|
|
dptr->name = &c->name_buffer[namebufused];
|
|
|
|
if (fmt->valid)
|
|
|
|
namebufused += buf_pos;
|
2006-03-30 12:07:32 +00:00
|
|
|
else
|
2006-04-15 13:57:15 +00:00
|
|
|
namebufused += tcs->result_len;
|
2006-07-15 17:36:25 +00:00
|
|
|
|
|
|
|
if (namebufused >= c->name_buffer_size)
|
|
|
|
{
|
|
|
|
logf("chunk mode #2: %d", current_entry_count);
|
|
|
|
c->dirfull = true;
|
|
|
|
sort = false;
|
|
|
|
break ;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2006-07-15 17:36:25 +00:00
|
|
|
if (fmt->valid)
|
|
|
|
strcpy(dptr->name, buf);
|
|
|
|
else
|
|
|
|
strcpy(dptr->name, tcs->result);
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
else
|
2006-04-15 13:57:15 +00:00
|
|
|
dptr->name = tcs->result;
|
2006-03-30 12:07:32 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
dptr++;
|
2006-04-15 13:57:15 +00:00
|
|
|
current_entry_count++;
|
|
|
|
|
|
|
|
if (current_entry_count >= global_settings.max_files_in_dir)
|
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 ;
|
|
|
|
}
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (init && !tcs->ramsearch)
|
2006-04-08 08:59:47 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
if (!show_search_progress(false, i))
|
|
|
|
{
|
|
|
|
tagcache_search_finish(tcs);
|
|
|
|
return current_entry_count;
|
|
|
|
}
|
2006-04-08 08:59:47 +00:00
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
|
2006-03-30 12:07:32 +00:00
|
|
|
if (sort)
|
2006-04-19 18:56:59 +00:00
|
|
|
qsort(c->dircache + special_entry_count * c->dentry_size,
|
|
|
|
current_entry_count - special_entry_count,
|
|
|
|
c->dentry_size, compare);
|
2006-03-30 12:07:32 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
if (!init)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
tagcache_search_finish(tcs);
|
|
|
|
return current_entry_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (tagcache_get_next(tcs))
|
|
|
|
{
|
|
|
|
if (!tcs->ramsearch)
|
|
|
|
{
|
|
|
|
if (!show_search_progress(false, total_count))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
total_count++;
|
2006-03-26 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
tagcache_search_finish(tcs);
|
|
|
|
return total_count;
|
|
|
|
}
|
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
static int load_root(struct tree_context *c)
|
2006-04-15 13:57:15 +00:00
|
|
|
{
|
|
|
|
struct tagentry *dptr = (struct tagentry *)c->dircache;
|
2006-04-16 17:32:54 +00:00
|
|
|
int i;
|
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
tc = c;
|
2006-04-16 17:32:54 +00:00
|
|
|
c->currtable = root;
|
|
|
|
for (i = 0; i < si_count; i++)
|
|
|
|
{
|
|
|
|
dptr->name = (si+i)->name;
|
|
|
|
dptr->newtable = navibrowse;
|
|
|
|
dptr->extraseek = i;
|
|
|
|
dptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_offset = 0;
|
|
|
|
current_entry_count = i;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tagtree_load(struct tree_context* c)
|
|
|
|
{
|
|
|
|
int count;
|
2006-04-15 13:57:15 +00:00
|
|
|
int table = c->currtable;
|
|
|
|
|
|
|
|
c->dentry_size = sizeof(struct tagentry);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
c->dirfull = false;
|
|
|
|
table = root;
|
|
|
|
c->currtable = table;
|
|
|
|
}
|
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
switch (table)
|
|
|
|
{
|
|
|
|
case root:
|
|
|
|
count = load_root(c);
|
2006-07-10 16:22:03 +00:00
|
|
|
c->dirlevel = 0;
|
2006-04-16 17:32:54 +00:00
|
|
|
break;
|
2006-04-15 13:57:15 +00:00
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
case allsubentries:
|
2006-04-15 13:57:15 +00:00
|
|
|
case navibrowse:
|
|
|
|
logf("navibrowse...");
|
2006-04-16 17:32:54 +00:00
|
|
|
count = retrieve_entries(c, &tcs, 0, true);
|
2006-04-15 13:57:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
logf("Unsupported table %d\n", table);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
c->dirlevel = 0;
|
|
|
|
count = load_root(c);
|
|
|
|
gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY));
|
|
|
|
}
|
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;
|
2006-03-26 11:33:42 +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;
|
2006-03-26 11:33:42 +00:00
|
|
|
int newextra;
|
2006-04-19 11:03:37 +00:00
|
|
|
int seek;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
dptr = tagtree_get_entry(c, c->selected_item);
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
c->dirfull = false;
|
|
|
|
newextra = dptr->newtable;
|
2006-04-19 11:03:37 +00:00
|
|
|
seek = dptr->extraseek;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
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++;
|
|
|
|
|
|
|
|
switch (c->currtable) {
|
|
|
|
case root:
|
|
|
|
c->currextra = newextra;
|
2006-04-05 18:46:38 +00:00
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
if (newextra == navibrowse)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
csi = si+seek;
|
2006-04-04 19:28:13 +00:00
|
|
|
c->currextra = 0;
|
|
|
|
|
|
|
|
/* Read input as necessary. */
|
|
|
|
for (i = 0; i < csi->tagorder_count; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < csi->clause_count[i]; j++)
|
|
|
|
{
|
|
|
|
if (!csi->clause[i][j].input)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = kbd_input(searchstring, sizeof(searchstring));
|
|
|
|
if (rc == -1 || !searchstring[0])
|
|
|
|
{
|
|
|
|
c->dirlevel--;
|
2006-04-05 18:46:38 +00:00
|
|
|
return 0;
|
2006-04-04 19:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (csi->clause[i][j].numeric)
|
|
|
|
csi->clause[i][j].numeric_data = atoi(searchstring);
|
|
|
|
else
|
|
|
|
strncpy(csi->clause[i][j].str, searchstring,
|
|
|
|
sizeof(csi->clause[i][j].str)-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-05 18:46:38 +00:00
|
|
|
c->currtable = newextra;
|
2006-04-19 11:03:37 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-04 19:28:13 +00:00
|
|
|
case navibrowse:
|
2006-04-19 11:03:37 +00:00
|
|
|
case allsubentries:
|
|
|
|
if (newextra == playtrack)
|
2006-04-04 19:28:13 +00:00
|
|
|
{
|
2006-04-19 11:03:37 +00:00
|
|
|
c->dirlevel--;
|
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--;
|
2006-03-26 11:33:42 +00:00
|
|
|
break;
|
2006-04-04 19:28:13 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
default:
|
|
|
|
c->dirlevel--;
|
|
|
|
break;
|
|
|
|
}
|
2006-04-19 11:03:37 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
c->selected_item=0;
|
|
|
|
gui_synclist_select_item(&tree_lists, c->selected_item);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tagtree_exit(struct tree_context* c)
|
|
|
|
{
|
|
|
|
c->dirfull = false;
|
|
|
|
c->dirlevel--;
|
|
|
|
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)
|
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
struct tagentry *entry;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
entry = tagtree_get_entry(c, c->selected_item);
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2006-04-16 17:32:54 +00:00
|
|
|
if (!tagcache_search(&tcs, tag_filename))
|
|
|
|
return -1;
|
|
|
|
|
2006-05-05 07:01:43 +00:00
|
|
|
if (!tagcache_retrieve(&tcs, entry->extraseek, 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);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-07-25 07:41:00 +00:00
|
|
|
|
|
|
|
bool insert_all_playlist(struct tree_context *c, int position, bool queue)
|
2006-03-26 11:33:42 +00:00
|
|
|
{
|
|
|
|
int i;
|
2006-04-10 10:26:24 +00:00
|
|
|
char buf[MAX_PATH];
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
cpu_boost(true);
|
2006-04-16 17:32:54 +00:00
|
|
|
if (!tagcache_search(&tcs, tag_filename))
|
|
|
|
{
|
|
|
|
gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY));
|
2006-07-25 07:41:00 +00:00
|
|
|
return false;
|
2006-04-16 17:32:54 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 10:26:24 +00:00
|
|
|
for (i=0; i < c->filesindir; i++)
|
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
if (!show_search_progress(false, i))
|
|
|
|
break;
|
2006-04-10 10:26:24 +00:00
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek,
|
2006-04-10 10:26:24 +00:00
|
|
|
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-07-25 07:41:00 +00:00
|
|
|
playlist_insert_track(NULL, buf, position, queue);
|
2006-04-10 10:26:24 +00:00
|
|
|
}
|
|
|
|
tagcache_search_finish(&tcs);
|
2006-03-26 11:33:42 +00:00
|
|
|
cpu_boost(false);
|
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tagtree_insert_selection_playlist(int position, bool queue)
|
|
|
|
{
|
|
|
|
struct tagentry *dptr;
|
|
|
|
int dirlevel = tc->dirlevel;
|
|
|
|
|
|
|
|
dptr = tagtree_get_entry(tc, tc->selected_item);
|
|
|
|
|
|
|
|
/* We need to set the table to allsubentries. */
|
|
|
|
if (dptr->newtable == navibrowse)
|
|
|
|
{
|
|
|
|
tagtree_enter(tc);
|
|
|
|
tagtree_load(tc);
|
|
|
|
dptr = tagtree_get_entry(tc, tc->selected_item);
|
|
|
|
}
|
|
|
|
else if (dptr->newtable != allsubentries)
|
|
|
|
{
|
|
|
|
logf("unsupported table: %d", dptr->newtable);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the current table should be allsubentries. */
|
|
|
|
if (dptr->newtable != playtrack)
|
|
|
|
{
|
|
|
|
tagtree_enter(tc);
|
|
|
|
tagtree_load(tc);
|
|
|
|
dptr = tagtree_get_entry(tc, tc->selected_item);
|
|
|
|
|
|
|
|
/* And now the newtable should be playtrack. */
|
|
|
|
if (dptr->newtable != playtrack)
|
|
|
|
{
|
|
|
|
logf("newtable: %d !!", dptr->newtable);
|
|
|
|
tc->dirlevel = dirlevel;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tc->filesindir <= 0)
|
|
|
|
gui_syncsplash(HZ, true, str(LANG_END_PLAYLIST_PLAYER));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logf("insert_all_playlist");
|
|
|
|
insert_all_playlist(tc, position, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally return the dirlevel to its original value. */
|
|
|
|
while (tc->dirlevel > dirlevel)
|
|
|
|
tagtree_exit(tc);
|
|
|
|
tagtree_load(tc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tagtree_play_folder(struct tree_context* c)
|
|
|
|
{
|
|
|
|
if (playlist_create(NULL, NULL) < 0)
|
|
|
|
{
|
|
|
|
logf("Failed creating playlist\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!insert_all_playlist(c, PLAYLIST_INSERT, false))
|
|
|
|
return -2;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
playlist_start(c->selected_item,0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-15 13:57:15 +00:00
|
|
|
struct tagentry* tagtree_get_entry(struct tree_context *c, int id)
|
2006-04-10 10:26:24 +00:00
|
|
|
{
|
2006-04-15 13:57:15 +00:00
|
|
|
struct tagentry *entry = (struct tagentry *)c->dircache;
|
|
|
|
int realid = id - current_offset;
|
|
|
|
|
|
|
|
/* Load the next chunk if necessary. */
|
|
|
|
if (realid >= current_entry_count || realid < 0)
|
|
|
|
{
|
2006-05-05 07:54:19 +00:00
|
|
|
if (retrieve_entries(c, &tcs2, 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-04-16 17:32:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-15 13:57:15 +00:00
|
|
|
realid = id - current_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &entry[realid];
|
2006-04-10 10:26:24 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2006-04-04 19:28:13 +00:00
|
|
|
case navibrowse:
|
|
|
|
if (csi->tagorder[c->currextra] == tag_title)
|
2006-05-05 07:01:43 +00:00
|
|
|
attr = TREE_ATTR_MPA;
|
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;
|
|
|
|
|
2006-04-19 11:03:37 +00:00
|
|
|
case allsubentries:
|
2006-05-05 07:01:43 +00:00
|
|
|
attr = TREE_ATTR_MPA;
|
2006-04-19 11:03:37 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-05 07:01:43 +00:00
|
|
|
default:
|
|
|
|
attr = ATTR_DIRECTORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
const unsigned char* tagtree_get_icon(struct tree_context* c)
|
|
|
|
#else
|
|
|
|
int tagtree_get_icon(struct tree_context* c)
|
|
|
|
#endif
|
|
|
|
{
|
2006-05-05 07:54:19 +00:00
|
|
|
int icon = Icon_Folder;
|
2006-05-05 07:01:43 +00:00
|
|
|
|
2006-05-05 07:54:19 +00:00
|
|
|
if (tagtree_get_attr(c) == TREE_ATTR_MPA)
|
|
|
|
icon = Icon_Audio;
|
2006-03-26 11:33:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-05 07:01:43 +00:00
|
|
|
return bitmap_icons_6x8[icon];
|
2006-03-26 11:33:42 +00:00
|
|
|
#else
|
|
|
|
return icon;
|
|
|
|
#endif
|
|
|
|
}
|