Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Miika Pekkarinen |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | /** |
| 23 | * Basic structure on this file was copied from dbtree.c and modified to |
| 24 | * support the tag cache interface. |
| 25 | */ |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | #include <stdlib.h> |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 29 | #include "config.h" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 30 | #include "system.h" |
| 31 | #include "kernel.h" |
| 32 | #include "splash.h" |
| 33 | #include "icons.h" |
| 34 | #include "tree.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 35 | #include "action.h" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 36 | #include "settings.h" |
| 37 | #include "tagcache.h" |
| 38 | #include "tagtree.h" |
| 39 | #include "lang.h" |
| 40 | #include "logf.h" |
| 41 | #include "playlist.h" |
| 42 | #include "keyboard.h" |
| 43 | #include "gui/list.h" |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 44 | #include "buffer.h" |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 45 | #include "playback.h" |
Miika Pekkarinen | 29b9146 | 2006-08-09 07:28:48 +0000 | [diff] [blame] | 46 | #include "yesno.h" |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 47 | #include "misc.h" |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 48 | #include "filetypes.h" |
Jonathan Gordon | 1f415e2 | 2007-10-29 12:15:47 +0000 | [diff] [blame] | 49 | #include "audio.h" |
Bertrik Sikken | 4341480 | 2008-04-27 19:56:16 +0000 | [diff] [blame] | 50 | #include "events.h" |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 51 | |
| 52 | #define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 53 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 54 | static int tagtree_play_folder(struct tree_context* c); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 55 | |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 56 | #define SEARCHSTR_SIZE 256 |
| 57 | |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 58 | static const struct id3_to_search_mapping { |
| 59 | char *string; |
| 60 | size_t id3_offset; |
| 61 | } id3_to_search_mapping[] = { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 62 | { "", 0 }, /* offset n/a */ |
| 63 | { "#directory#", 0 }, /* offset n/a */ |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 64 | { "#title#", offsetof(struct mp3entry, title) }, |
| 65 | { "#artist#", offsetof(struct mp3entry, artist) }, |
| 66 | { "#album#", offsetof(struct mp3entry, album) }, |
| 67 | { "#genre#", offsetof(struct mp3entry, genre_string) }, |
| 68 | { "#composer#", offsetof(struct mp3entry, composer) }, |
| 69 | { "#albumartist#", offsetof(struct mp3entry, albumartist) }, |
| 70 | }; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 71 | enum variables { |
| 72 | var_sorttype = 100, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 73 | var_limit, |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 74 | var_strip, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 75 | var_menu_start, |
| 76 | var_include, |
| 77 | var_rootmenu, |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 78 | var_format, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 79 | menu_next, |
| 80 | menu_load, |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 83 | /* Capacity 10 000 entries (for example 10k different artists) */ |
| 84 | #define UNIQBUF_SIZE (64*1024) |
| 85 | static long *uniqbuf; |
| 86 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 87 | #define MAX_TAGS 5 |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 88 | #define MAX_MENU_ID_SIZE 32 |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 89 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 90 | static struct tagcache_search tcs, tcs2; |
| 91 | static bool sort_inverse; |
| 92 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 93 | /* |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 94 | * "%3d. %s" autoscore title %sort = "inverse" %limit = "100" |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 95 | * |
| 96 | * valid = true |
| 97 | * formatstr = "%-3d. %s" |
| 98 | * tags[0] = tag_autoscore |
| 99 | * tags[1] = tag_title |
| 100 | * tag_count = 2 |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 101 | * |
| 102 | * limit = 100 |
| 103 | * sort_inverse = true |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 104 | */ |
| 105 | struct display_format { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 106 | char name[32]; |
| 107 | struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES]; |
| 108 | int clause_count; |
| 109 | char *formatstr; |
| 110 | int group_id; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 111 | int tags[MAX_TAGS]; |
| 112 | int tag_count; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 113 | |
| 114 | int limit; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 115 | int strip; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 116 | bool sort_inverse; |
Miika Pekkarinen | ab643e7 | 2006-11-11 17:39:37 +0000 | [diff] [blame] | 117 | bool sort; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 120 | static struct display_format *formats[TAGMENU_MAX_FMTS]; |
| 121 | static int format_count; |
| 122 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 123 | struct search_instruction { |
| 124 | char name[64]; |
| 125 | int tagorder[MAX_TAGS]; |
| 126 | int tagorder_count; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 127 | struct tagcache_search_clause *clause[MAX_TAGS][TAGCACHE_MAX_CLAUSES]; |
| 128 | int format_id[MAX_TAGS]; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 129 | int clause_count[MAX_TAGS]; |
| 130 | int result_seek[MAX_TAGS]; |
| 131 | }; |
| 132 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 133 | struct menu_entry { |
| 134 | char name[64]; |
| 135 | int type; |
| 136 | struct search_instruction *si; |
| 137 | int link; |
| 138 | }; |
| 139 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 140 | struct root_menu { |
| 141 | char title[64]; |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 142 | char id[MAX_MENU_ID_SIZE]; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 143 | int itemcount; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 144 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; |
| 145 | }; |
| 146 | |
Miika Pekkarinen | 6e8ab3d | 2006-09-25 19:52:38 +0000 | [diff] [blame] | 147 | /* Statusbar text of the current view. */ |
| 148 | static char current_title[MAX_TAGS][128]; |
| 149 | |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 150 | static struct root_menu *menus[TAGMENU_MAX_MENUS]; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 151 | static struct root_menu *menu; |
| 152 | static struct search_instruction *csi; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 153 | static const char *strp; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 154 | static int menu_count; |
| 155 | static int root_menu; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 156 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 157 | static int current_offset; |
| 158 | static int current_entry_count; |
| 159 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 160 | static int format_count; |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 161 | static struct tree_context *tc; |
| 162 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 163 | static int get_token_str(char *buf, int size) |
| 164 | { |
| 165 | /* Find the start. */ |
| 166 | while (*strp != '"' && *strp != '\0') |
| 167 | strp++; |
| 168 | |
| 169 | if (*strp == '\0' || *(++strp) == '\0') |
| 170 | return -1; |
| 171 | |
| 172 | /* Read the data. */ |
| 173 | while (*strp != '"' && *strp != '\0' && --size > 0) |
| 174 | *(buf++) = *(strp++); |
| 175 | |
| 176 | *buf = '\0'; |
| 177 | if (*strp != '"') |
| 178 | return -2; |
| 179 | |
| 180 | strp++; |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | #define MATCH(tag,str1,str2,settag) \ |
| 186 | if (!strcasecmp(str1, str2)) { \ |
| 187 | *tag = settag; \ |
| 188 | return 1; \ |
| 189 | } |
| 190 | |
| 191 | static int get_tag(int *tag) |
| 192 | { |
Miika Pekkarinen | 3b7111e | 2006-10-10 10:29:42 +0000 | [diff] [blame] | 193 | char buf[128]; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 194 | int i; |
| 195 | |
| 196 | /* Find the start. */ |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 197 | while ((*strp == ' ' || *strp == '>') && *strp != '\0') |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 198 | strp++; |
| 199 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 200 | if (*strp == '\0' || *strp == '?') |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 201 | return 0; |
| 202 | |
| 203 | for (i = 0; i < (int)sizeof(buf)-1; i++) |
| 204 | { |
| 205 | if (*strp == '\0' || *strp == ' ') |
| 206 | break ; |
| 207 | buf[i] = *strp; |
| 208 | strp++; |
| 209 | } |
| 210 | buf[i] = '\0'; |
| 211 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 212 | MATCH(tag, buf, "album", tag_album); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 213 | MATCH(tag, buf, "artist", tag_artist); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 214 | MATCH(tag, buf, "bitrate", tag_bitrate); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 215 | MATCH(tag, buf, "composer", tag_composer); |
Miika Pekkarinen | 4e97664 | 2007-02-10 12:09:28 +0000 | [diff] [blame] | 216 | MATCH(tag, buf, "comment", tag_comment); |
| 217 | MATCH(tag, buf, "albumartist", tag_albumartist); |
| 218 | MATCH(tag, buf, "ensemble", tag_albumartist); |
Dan Everton | eecfe9f | 2007-08-08 10:19:56 +0000 | [diff] [blame] | 219 | MATCH(tag, buf, "grouping", tag_grouping); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 220 | MATCH(tag, buf, "genre", tag_genre); |
| 221 | MATCH(tag, buf, "length", tag_length); |
Miika Pekkarinen | 9d9937a | 2007-04-12 20:14:05 +0000 | [diff] [blame] | 222 | MATCH(tag, buf, "Lm", tag_virt_length_min); |
| 223 | MATCH(tag, buf, "Ls", tag_virt_length_sec); |
Miika Pekkarinen | 5e47daa | 2007-04-12 20:21:56 +0000 | [diff] [blame] | 224 | MATCH(tag, buf, "Pm", tag_virt_playtime_min); |
| 225 | MATCH(tag, buf, "Ps", tag_virt_playtime_sec); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 226 | MATCH(tag, buf, "title", tag_title); |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 227 | MATCH(tag, buf, "filename", tag_filename); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 228 | MATCH(tag, buf, "tracknum", tag_tracknumber); |
Dan Everton | f4a61f0 | 2007-08-03 10:00:42 +0000 | [diff] [blame] | 229 | MATCH(tag, buf, "discnum", tag_discnumber); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 230 | MATCH(tag, buf, "year", tag_year); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 231 | MATCH(tag, buf, "playcount", tag_playcount); |
Robert Kukla | 226cb7b | 2007-03-26 15:08:59 +0000 | [diff] [blame] | 232 | MATCH(tag, buf, "rating", tag_rating); |
Miika Pekkarinen | 7d1dcd1 | 2006-09-26 18:24:48 +0000 | [diff] [blame] | 233 | MATCH(tag, buf, "lastplayed", tag_lastplayed); |
Miika Pekkarinen | f5184f3 | 2007-02-25 20:41:51 +0000 | [diff] [blame] | 234 | MATCH(tag, buf, "commitid", tag_commitid); |
| 235 | MATCH(tag, buf, "entryage", tag_virt_entryage); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 236 | MATCH(tag, buf, "autoscore", tag_virt_autoscore); |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 237 | MATCH(tag, buf, "%sort", var_sorttype); |
| 238 | MATCH(tag, buf, "%limit", var_limit); |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 239 | MATCH(tag, buf, "%strip", var_strip); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 240 | MATCH(tag, buf, "%menu_start", var_menu_start); |
| 241 | MATCH(tag, buf, "%include", var_include); |
| 242 | MATCH(tag, buf, "%root_menu", var_rootmenu); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 243 | MATCH(tag, buf, "%format", var_format); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 244 | MATCH(tag, buf, "->", menu_next); |
| 245 | MATCH(tag, buf, "==>", menu_load); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 246 | |
| 247 | logf("NO MATCH: %s\n", buf); |
| 248 | if (buf[0] == '?') |
| 249 | return 0; |
| 250 | |
| 251 | return -1; |
| 252 | } |
| 253 | |
| 254 | static int get_clause(int *condition) |
| 255 | { |
| 256 | char buf[4]; |
| 257 | int i; |
| 258 | |
| 259 | /* Find the start. */ |
| 260 | while (*strp == ' ' && *strp != '\0') |
| 261 | strp++; |
| 262 | |
| 263 | if (*strp == '\0') |
| 264 | return 0; |
| 265 | |
| 266 | for (i = 0; i < (int)sizeof(buf)-1; i++) |
| 267 | { |
| 268 | if (*strp == '\0' || *strp == ' ') |
| 269 | break ; |
| 270 | buf[i] = *strp; |
| 271 | strp++; |
| 272 | } |
| 273 | buf[i] = '\0'; |
| 274 | |
| 275 | MATCH(condition, buf, "=", clause_is); |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 276 | MATCH(condition, buf, "==", clause_is); |
Miika Pekkarinen | 33d9104 | 2006-08-13 12:33:34 +0000 | [diff] [blame] | 277 | MATCH(condition, buf, "!=", clause_is_not); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 278 | MATCH(condition, buf, ">", clause_gt); |
| 279 | MATCH(condition, buf, ">=", clause_gteq); |
| 280 | MATCH(condition, buf, "<", clause_lt); |
| 281 | MATCH(condition, buf, "<=", clause_lteq); |
| 282 | MATCH(condition, buf, "~", clause_contains); |
Miika Pekkarinen | 33d9104 | 2006-08-13 12:33:34 +0000 | [diff] [blame] | 283 | MATCH(condition, buf, "!~", clause_not_contains); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 284 | MATCH(condition, buf, "^", clause_begins_with); |
Miika Pekkarinen | 33d9104 | 2006-08-13 12:33:34 +0000 | [diff] [blame] | 285 | MATCH(condition, buf, "!^", clause_not_begins_with); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 286 | MATCH(condition, buf, "$", clause_ends_with); |
Miika Pekkarinen | 33d9104 | 2006-08-13 12:33:34 +0000 | [diff] [blame] | 287 | MATCH(condition, buf, "!$", clause_not_ends_with); |
Miika Pekkarinen | be2eb02 | 2006-10-09 10:23:35 +0000 | [diff] [blame] | 288 | MATCH(condition, buf, "@", clause_oneof); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 293 | static bool read_clause(struct tagcache_search_clause *clause) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 294 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 295 | char buf[SEARCHSTR_SIZE]; |
| 296 | unsigned int i; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 297 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 298 | if (get_tag(&clause->tag) <= 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 299 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 300 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 301 | if (get_clause(&clause->type) <= 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 302 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 303 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 304 | if (get_token_str(buf, sizeof buf) < 0) |
| 305 | return false; |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 306 | |
| 307 | for (i=0; i<ARRAYLEN(id3_to_search_mapping); i++) |
| 308 | { |
| 309 | if (!strcasecmp(buf, id3_to_search_mapping[i].string)) |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */ |
| 314 | { |
| 315 | clause->source = source_runtime+i; |
| 316 | clause->str = buffer_alloc(SEARCHSTR_SIZE); |
| 317 | } |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 318 | else |
| 319 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 320 | clause->source = source_constant; |
| 321 | clause->str = buffer_alloc(strlen(buf)+1); |
| 322 | strcpy(clause->str, buf); |
| 323 | } |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 324 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 325 | if (tagcache_is_numeric_tag(clause->tag)) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 326 | { |
| 327 | clause->numeric = true; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 328 | clause->numeric_data = atoi(clause->str); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 329 | } |
| 330 | else |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 331 | clause->numeric = false; |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 332 | |
| 333 | logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 338 | static bool read_variable(char *buf, int size) |
| 339 | { |
| 340 | int condition; |
| 341 | |
| 342 | if (!get_clause(&condition)) |
| 343 | return false; |
| 344 | |
| 345 | if (condition != clause_is) |
| 346 | return false; |
| 347 | |
| 348 | if (get_token_str(buf, size) < 0) |
| 349 | return false; |
| 350 | |
| 351 | return true; |
| 352 | } |
| 353 | |
| 354 | /* "%3d. %s" autoscore title %sort = "inverse" %limit = "100" */ |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 355 | static int get_format_str(struct display_format *fmt) |
| 356 | { |
| 357 | int ret; |
Miika Pekkarinen | bba9de2 | 2006-10-11 04:32:33 +0000 | [diff] [blame] | 358 | char buf[128]; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 359 | int i; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 360 | |
| 361 | memset(fmt, 0, sizeof(struct display_format)); |
| 362 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 363 | if (get_token_str(fmt->name, sizeof fmt->name) < 0) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 364 | return -10; |
| 365 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 366 | /* Determine the group id */ |
| 367 | fmt->group_id = 0; |
| 368 | for (i = 0; i < format_count; i++) |
| 369 | { |
| 370 | if (!strcasecmp(formats[i]->name, fmt->name)) |
| 371 | { |
| 372 | fmt->group_id = formats[i]->group_id; |
| 373 | break; |
| 374 | } |
| 375 | |
| 376 | if (formats[i]->group_id > fmt->group_id) |
| 377 | fmt->group_id = formats[i]->group_id; |
| 378 | } |
| 379 | |
| 380 | if (i == format_count) |
| 381 | fmt->group_id++; |
| 382 | |
| 383 | logf("format: (%d) %s", fmt->group_id, fmt->name); |
| 384 | |
| 385 | if (get_token_str(buf, sizeof buf) < 0) |
| 386 | return -10; |
| 387 | |
| 388 | fmt->formatstr = buffer_alloc(strlen(buf) + 1); |
| 389 | strcpy(fmt->formatstr, buf); |
| 390 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 391 | while (fmt->tag_count < MAX_TAGS) |
| 392 | { |
| 393 | ret = get_tag(&fmt->tags[fmt->tag_count]); |
| 394 | if (ret < 0) |
| 395 | return -11; |
| 396 | |
| 397 | if (ret == 0) |
| 398 | break; |
| 399 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 400 | switch (fmt->tags[fmt->tag_count]) { |
| 401 | case var_sorttype: |
| 402 | if (!read_variable(buf, sizeof buf)) |
| 403 | return -12; |
| 404 | if (!strcasecmp("inverse", buf)) |
| 405 | fmt->sort_inverse = true; |
Miika Pekkarinen | ab643e7 | 2006-11-11 17:39:37 +0000 | [diff] [blame] | 406 | |
| 407 | fmt->sort = true; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 408 | break; |
| 409 | |
| 410 | case var_limit: |
| 411 | if (!read_variable(buf, sizeof buf)) |
| 412 | return -13; |
| 413 | fmt->limit = atoi(buf); |
| 414 | break; |
| 415 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 416 | case var_strip: |
| 417 | if (!read_variable(buf, sizeof buf)) |
| 418 | return -14; |
| 419 | fmt->strip = atoi(buf); |
| 420 | break; |
| 421 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 422 | default: |
| 423 | fmt->tag_count++; |
| 424 | } |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 427 | return 1; |
| 428 | } |
| 429 | |
| 430 | static int add_format(const char *buf) |
| 431 | { |
| 432 | strp = buf; |
| 433 | |
| 434 | if (formats[format_count] == NULL) |
| 435 | formats[format_count] = buffer_alloc(sizeof(struct display_format)); |
| 436 | |
| 437 | memset(formats[format_count], 0, sizeof(struct display_format)); |
| 438 | if (get_format_str(formats[format_count]) < 0) |
| 439 | { |
| 440 | logf("get_format_str() parser failed!"); |
| 441 | return -4; |
| 442 | } |
| 443 | |
| 444 | while (*strp != '\0' && *strp != '?') |
| 445 | strp++; |
| 446 | |
| 447 | if (*strp == '?') |
| 448 | { |
| 449 | int clause_count = 0; |
| 450 | strp++; |
| 451 | |
| 452 | while (1) |
| 453 | { |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 454 | if (clause_count >= TAGCACHE_MAX_CLAUSES) |
| 455 | { |
| 456 | logf("too many clauses"); |
| 457 | break; |
| 458 | } |
| 459 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 460 | formats[format_count]->clause[clause_count] = |
| 461 | buffer_alloc(sizeof(struct tagcache_search_clause)); |
| 462 | |
| 463 | if (!read_clause(formats[format_count]->clause[clause_count])) |
| 464 | break; |
| 465 | |
| 466 | clause_count++; |
| 467 | } |
| 468 | |
| 469 | formats[format_count]->clause_count = clause_count; |
| 470 | } |
| 471 | |
| 472 | format_count++; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 473 | |
| 474 | return 1; |
| 475 | } |
| 476 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 477 | static int get_condition(struct search_instruction *inst) |
| 478 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 479 | int clause_count; |
Miika Pekkarinen | bba9de2 | 2006-10-11 04:32:33 +0000 | [diff] [blame] | 480 | char buf[128]; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 481 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 482 | switch (*strp) |
| 483 | { |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 484 | case '=': |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 485 | { |
| 486 | int i; |
| 487 | |
| 488 | if (get_token_str(buf, sizeof buf) < 0) |
| 489 | return -1; |
| 490 | |
| 491 | for (i = 0; i < format_count; i++) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 492 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 493 | if (!strcasecmp(formats[i]->name, buf)) |
| 494 | break; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 495 | } |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 496 | |
| 497 | if (i == format_count) |
| 498 | { |
| 499 | logf("format not found: %s", buf); |
| 500 | return -2; |
| 501 | } |
| 502 | |
| 503 | inst->format_id[inst->tagorder_count] = formats[i]->group_id; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 504 | return 1; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 505 | } |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 506 | case '?': |
| 507 | case ' ': |
| 508 | case '&': |
| 509 | strp++; |
| 510 | return 1; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 511 | case '-': |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 512 | case '\0': |
| 513 | return 0; |
| 514 | } |
| 515 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 516 | clause_count = inst->clause_count[inst->tagorder_count]; |
| 517 | if (clause_count >= TAGCACHE_MAX_CLAUSES) |
| 518 | { |
| 519 | logf("Too many clauses"); |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | inst->clause[inst->tagorder_count][clause_count] = |
| 524 | buffer_alloc(sizeof(struct tagcache_search_clause)); |
| 525 | |
| 526 | if (!read_clause(inst->clause[inst->tagorder_count][clause_count])) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 527 | return -1; |
| 528 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 529 | inst->clause_count[inst->tagorder_count]++; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 530 | |
| 531 | return 1; |
| 532 | } |
| 533 | |
| 534 | /* example search: |
| 535 | * "Best" artist ? year >= "2000" & title !^ "crap" & genre = "good genre" \ |
| 536 | * : album ? year >= "2000" : songs |
| 537 | * ^ begins with |
| 538 | * * contains |
| 539 | * $ ends with |
| 540 | */ |
| 541 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 542 | static bool parse_search(struct menu_entry *entry, const char *str) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 543 | { |
| 544 | int ret; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 545 | int type; |
| 546 | struct search_instruction *inst = entry->si; |
| 547 | char buf[MAX_PATH]; |
| 548 | int i; |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 549 | struct root_menu *new_menu; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 550 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 551 | strp = str; |
| 552 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 553 | /* Parse entry name */ |
| 554 | if (get_token_str(entry->name, sizeof entry->name) < 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 555 | { |
| 556 | logf("No name found."); |
| 557 | return false; |
| 558 | } |
| 559 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 560 | /* Parse entry type */ |
| 561 | if (get_tag(&entry->type) <= 0) |
| 562 | return false; |
| 563 | |
| 564 | if (entry->type == menu_load) |
| 565 | { |
| 566 | if (get_token_str(buf, sizeof buf) < 0) |
| 567 | return false; |
| 568 | |
| 569 | /* Find the matching root menu or "create" it */ |
| 570 | for (i = 0; i < menu_count; i++) |
| 571 | { |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 572 | if (!strcasecmp(menus[i]->id, buf)) |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 573 | { |
| 574 | entry->link = i; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 575 | return true; |
| 576 | } |
| 577 | } |
| 578 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 579 | if (menu_count >= TAGMENU_MAX_MENUS) |
| 580 | { |
| 581 | logf("max menucount reached"); |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | /* Allocate a new menu unless link is found. */ |
| 586 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); |
| 587 | new_menu = menus[menu_count]; |
| 588 | memset(new_menu, 0, sizeof(struct root_menu)); |
| 589 | strncpy(new_menu->id, buf, MAX_MENU_ID_SIZE-1); |
| 590 | entry->link = menu_count; |
| 591 | ++menu_count; |
| 592 | |
| 593 | return true; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | if (entry->type != menu_next) |
| 597 | return false; |
| 598 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 599 | while (inst->tagorder_count < MAX_TAGS) |
| 600 | { |
| 601 | ret = get_tag(&inst->tagorder[inst->tagorder_count]); |
| 602 | if (ret < 0) |
| 603 | { |
| 604 | logf("Parse error #1"); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 605 | logf("%s", strp); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 606 | return false; |
| 607 | } |
| 608 | |
| 609 | if (ret == 0) |
| 610 | break ; |
| 611 | |
| 612 | logf("tag: %d", inst->tagorder[inst->tagorder_count]); |
| 613 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 614 | while ( (ret = get_condition(inst)) > 0 ) ; |
| 615 | if (ret < 0) |
| 616 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 617 | |
| 618 | inst->tagorder_count++; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 619 | |
| 620 | if (get_tag(&type) <= 0 || type != menu_next) |
| 621 | break; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | return true; |
| 625 | } |
| 626 | |
Miika Pekkarinen | 44b76bc | 2006-03-30 12:07:32 +0000 | [diff] [blame] | 627 | static int compare(const void *p1, const void *p2) |
| 628 | { |
| 629 | struct tagentry *e1 = (struct tagentry *)p1; |
| 630 | struct tagentry *e2 = (struct tagentry *)p2; |
| 631 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 632 | if (sort_inverse) |
| 633 | return strncasecmp(e2->name, e1->name, MAX_PATH); |
| 634 | |
Miika Pekkarinen | 44b76bc | 2006-03-30 12:07:32 +0000 | [diff] [blame] | 635 | return strncasecmp(e1->name, e2->name, MAX_PATH); |
| 636 | } |
| 637 | |
Robert Kukla | a334bd2 | 2007-11-23 23:36:42 +0000 | [diff] [blame] | 638 | static void tagtree_buffer_event(struct mp3entry *id3) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 639 | { |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 640 | /* Do not gather data unless proper setting has been enabled. */ |
| 641 | if (!global_settings.runtimedb) |
| 642 | return; |
| 643 | |
Miika Pekkarinen | f98a0a9 | 2007-11-23 17:58:03 +0000 | [diff] [blame] | 644 | logf("be:%s", id3->path); |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 645 | |
| 646 | if (!tagcache_find_index(&tcs, id3->path)) |
| 647 | { |
| 648 | logf("tc stat: not found: %s", id3->path); |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | id3->playcount = tagcache_get_numeric(&tcs, tag_playcount); |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 653 | if (!id3->rating) |
| 654 | id3->rating = tagcache_get_numeric(&tcs, tag_rating); |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 655 | id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); |
Robert Kukla | 226cb7b | 2007-03-26 15:08:59 +0000 | [diff] [blame] | 656 | id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 657 | id3->playtime = tagcache_get_numeric(&tcs, tag_playtime); |
| 658 | |
| 659 | /* Store our tagcache index pointer. */ |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 660 | id3->tagcache_idx = tcs.idx_id+1; |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 661 | |
| 662 | tagcache_search_finish(&tcs); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Miika Pekkarinen | 2ccdc48 | 2008-03-07 22:56:51 +0000 | [diff] [blame] | 665 | static void tagtree_track_finish_event(struct mp3entry *id3) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 666 | { |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 667 | long playcount; |
| 668 | long playtime; |
| 669 | long lastplayed; |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 670 | long tagcache_idx; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 671 | |
| 672 | /* Do not gather data unless proper setting has been enabled. */ |
| 673 | if (!global_settings.runtimedb) |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 674 | { |
| 675 | logf("runtimedb gathering not enabled"); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 676 | return; |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 677 | } |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 678 | |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 679 | tagcache_idx=id3->tagcache_idx; |
| 680 | if (!tagcache_idx) |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 681 | { |
| 682 | logf("No tagcache index pointer found"); |
| 683 | return; |
| 684 | } |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 685 | tagcache_idx--; |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 686 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 687 | /* Don't process unplayed tracks. */ |
| 688 | if (id3->elapsed == 0) |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 689 | { |
| 690 | logf("not logging unplayed track"); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 691 | return; |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 692 | } |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 693 | |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 694 | playcount = id3->playcount + 1; |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 695 | lastplayed = tagcache_increase_serial(); |
| 696 | if (lastplayed < 0) |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 697 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 698 | logf("incorrect tc serial:%ld", lastplayed); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 699 | return; |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 700 | } |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 701 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 702 | /* Ignore the last 15s (crossfade etc.) */ |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 703 | playtime = id3->playtime + MIN(id3->length, id3->elapsed + 15 * 1000); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 704 | |
| 705 | logf("ube:%s", id3->path); |
Miika Pekkarinen | f98a0a9 | 2007-11-23 17:58:03 +0000 | [diff] [blame] | 706 | logf("-> %ld/%ld", playcount, playtime); |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 707 | logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000)); |
Robert Kukla | a334bd2 | 2007-11-23 23:36:42 +0000 | [diff] [blame] | 708 | |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 709 | /* Queue the updates to the tagcache system. */ |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 710 | tagcache_update_numeric(tagcache_idx, tag_playcount, playcount); |
| 711 | tagcache_update_numeric(tagcache_idx, tag_playtime, playtime); |
| 712 | tagcache_update_numeric(tagcache_idx, tag_lastplayed, lastplayed); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 715 | bool tagtree_export(void) |
| 716 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 717 | gui_syncsplash(0, str(LANG_CREATING)); |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 718 | if (!tagcache_create_changelog(&tcs)) |
| 719 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 720 | gui_syncsplash(HZ*2, ID2P(LANG_FAILED)); |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | return false; |
| 724 | } |
| 725 | |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 726 | bool tagtree_import(void) |
| 727 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 728 | gui_syncsplash(0, ID2P(LANG_WAIT)); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 729 | if (!tagcache_import_changelog()) |
| 730 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 731 | gui_syncsplash(HZ*2, ID2P(LANG_FAILED)); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | return false; |
| 735 | } |
| 736 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 737 | static bool parse_menu(const char *filename); |
| 738 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 739 | static int parse_line(int n, const char *buf, void *parameters) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 740 | { |
| 741 | char data[256]; |
| 742 | int variable; |
| 743 | static bool read_menu; |
| 744 | int i; |
| 745 | |
| 746 | (void)parameters; |
| 747 | |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 748 | logf("parse:%d/%s", n, buf); |
| 749 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 750 | /* First line, do initialisation. */ |
| 751 | if (n == 0) |
| 752 | { |
| 753 | if (strcasecmp(TAGNAVI_VERSION, buf)) |
| 754 | { |
| 755 | logf("Version mismatch"); |
| 756 | return -1; |
| 757 | } |
| 758 | |
| 759 | read_menu = false; |
| 760 | } |
| 761 | |
| 762 | if (buf[0] == '#') |
| 763 | return 0; |
| 764 | |
| 765 | if (buf[0] == '\0') |
| 766 | { |
| 767 | if (read_menu) |
| 768 | { |
| 769 | /* End the menu */ |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 770 | read_menu = false; |
| 771 | } |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | if (!read_menu) |
| 776 | { |
| 777 | strp = buf; |
| 778 | if (get_tag(&variable) <= 0) |
| 779 | return 0; |
| 780 | |
| 781 | switch (variable) |
| 782 | { |
| 783 | case var_format: |
| 784 | if (add_format(strp) < 0) |
| 785 | { |
| 786 | logf("Format add fail: %s", data); |
| 787 | } |
| 788 | break; |
| 789 | |
| 790 | case var_include: |
| 791 | if (get_token_str(data, sizeof(data)) < 0) |
| 792 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 793 | logf("%%include empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 794 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | if (!parse_menu(data)) |
| 798 | { |
| 799 | logf("Load menu fail: %s", data); |
| 800 | } |
| 801 | break; |
| 802 | |
| 803 | case var_menu_start: |
| 804 | if (menu_count >= TAGMENU_MAX_MENUS) |
| 805 | { |
| 806 | logf("max menucount reached"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 807 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 810 | if (get_token_str(data, sizeof data) < 0) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 811 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 812 | logf("%%menu_start id empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 813 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 814 | } |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 815 | |
| 816 | menu = NULL; |
| 817 | for (i = 0; i < menu_count; i++) |
| 818 | { |
| 819 | if (!strcasecmp(menus[i]->id, data)) |
| 820 | { |
| 821 | menu = menus[i]; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | if (menu == NULL) |
| 826 | { |
| 827 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); |
| 828 | menu = menus[menu_count]; |
| 829 | ++menu_count; |
| 830 | memset(menu, 0, sizeof(struct root_menu)); |
| 831 | strncpy(menu->id, data, MAX_MENU_ID_SIZE-1); |
| 832 | } |
| 833 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 834 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) |
| 835 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 836 | logf("%%menu_start title empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 837 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 838 | } |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 839 | logf("menu: %s", menu->title); |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 840 | read_menu = true; |
| 841 | break; |
| 842 | |
| 843 | case var_rootmenu: |
| 844 | /* Only set root menu once. */ |
Miika Pekkarinen | e6de6e5 | 2007-04-12 18:33:40 +0000 | [diff] [blame] | 845 | if (root_menu >= 0) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | if (get_token_str(data, sizeof(data)) < 0) |
| 849 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 850 | logf("%%root_menu empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 851 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | for (i = 0; i < menu_count; i++) |
| 855 | { |
| 856 | if (!strcasecmp(menus[i]->id, data)) |
| 857 | { |
| 858 | root_menu = i; |
| 859 | } |
| 860 | } |
| 861 | break; |
| 862 | } |
| 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | if (menu->itemcount >= TAGMENU_MAX_ITEMS) |
| 868 | { |
| 869 | logf("max itemcount reached"); |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | /* Allocate */ |
| 874 | if (menu->items[menu->itemcount] == NULL) |
| 875 | { |
| 876 | menu->items[menu->itemcount] = buffer_alloc(sizeof(struct menu_entry)); |
| 877 | memset(menu->items[menu->itemcount], 0, sizeof(struct menu_entry)); |
| 878 | menu->items[menu->itemcount]->si = buffer_alloc(sizeof(struct search_instruction)); |
| 879 | } |
| 880 | |
| 881 | memset(menu->items[menu->itemcount]->si, 0, sizeof(struct search_instruction)); |
| 882 | if (!parse_search(menu->items[menu->itemcount], buf)) |
| 883 | return 0; |
| 884 | |
| 885 | menu->itemcount++; |
| 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 890 | static bool parse_menu(const char *filename) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 891 | { |
| 892 | int fd; |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 893 | char buf[1024]; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 894 | |
| 895 | if (menu_count >= TAGMENU_MAX_MENUS) |
Miika Pekkarinen | 1dc3577 | 2006-09-21 17:16:35 +0000 | [diff] [blame] | 896 | { |
| 897 | logf("max menucount reached"); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 898 | return false; |
Miika Pekkarinen | 1dc3577 | 2006-09-21 17:16:35 +0000 | [diff] [blame] | 899 | } |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 900 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 901 | fd = open(filename, O_RDONLY); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 902 | if (fd < 0) |
| 903 | { |
| 904 | logf("Search instruction file not found."); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 905 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Linus Nielsen Feltzing | eed923e | 2006-08-23 08:41:18 +0000 | [diff] [blame] | 908 | /* Now read file for real, parsing into si */ |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 909 | fast_readline(fd, buf, sizeof buf, NULL, parse_line); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 910 | close(fd); |
| 911 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 912 | return true; |
| 913 | } |
| 914 | |
| 915 | void tagtree_init(void) |
| 916 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 917 | format_count = 0; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 918 | menu_count = 0; |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 919 | menu = NULL; |
Miika Pekkarinen | e6de6e5 | 2007-04-12 18:33:40 +0000 | [diff] [blame] | 920 | root_menu = -1; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 921 | parse_menu(FILE_SEARCH_INSTRUCTIONS); |
| 922 | |
Miika Pekkarinen | e6de6e5 | 2007-04-12 18:33:40 +0000 | [diff] [blame] | 923 | /* If no root menu is set, assume it's the first single menu |
| 924 | * we have. That shouldn't normally happen. */ |
| 925 | if (root_menu < 0) |
| 926 | root_menu = 0; |
| 927 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 928 | uniqbuf = buffer_alloc(UNIQBUF_SIZE); |
Miika Pekkarinen | 19c6e66 | 2008-03-16 13:55:16 +0000 | [diff] [blame] | 929 | |
Jonathan Gordon | a67e5d8 | 2008-03-17 05:22:53 +0000 | [diff] [blame] | 930 | add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); |
| 931 | add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 934 | static bool show_search_progress(bool init, int count) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 935 | { |
| 936 | static int last_tick = 0; |
| 937 | |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 938 | /* Don't show splashes for 1/2 second after starting search */ |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 939 | if (init) |
| 940 | { |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 941 | last_tick = current_tick + HZ/2; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 942 | return true; |
| 943 | } |
| 944 | |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 945 | /* Update progress every 1/10 of a second */ |
| 946 | if (current_tick - last_tick > HZ/10) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 947 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 948 | gui_syncsplash(0, str(LANG_PLAYLIST_SEARCH_MSG), count, |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 949 | str(LANG_OFF_ABORT)); |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 950 | if (action_userabort(TIMEOUT_NOBLOCK)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 951 | return false; |
| 952 | last_tick = current_tick; |
Miika Pekkarinen | 54ec1f5 | 2006-08-12 11:00:39 +0000 | [diff] [blame] | 953 | yield(); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | return true; |
| 957 | } |
| 958 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 959 | static int format_str(struct tagcache_search *tcs, struct display_format *fmt, |
| 960 | char *buf, int buf_size) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 961 | { |
| 962 | char fmtbuf[8]; |
| 963 | bool read_format = false; |
| 964 | int fmtbuf_pos = 0; |
| 965 | int parpos = 0; |
| 966 | int buf_pos = 0; |
| 967 | int i; |
| 968 | |
| 969 | memset(buf, 0, buf_size); |
| 970 | for (i = 0; fmt->formatstr[i] != '\0'; i++) |
| 971 | { |
| 972 | if (fmt->formatstr[i] == '%') |
| 973 | { |
| 974 | read_format = true; |
| 975 | fmtbuf_pos = 0; |
| 976 | if (parpos >= fmt->tag_count) |
| 977 | { |
| 978 | logf("too many format tags"); |
| 979 | return -1; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | if (read_format) |
| 984 | { |
| 985 | fmtbuf[fmtbuf_pos++] = fmt->formatstr[i]; |
| 986 | if (fmtbuf_pos >= buf_size) |
| 987 | { |
| 988 | logf("format parse error"); |
| 989 | return -2; |
| 990 | } |
| 991 | |
| 992 | if (fmt->formatstr[i] == 's') |
| 993 | { |
| 994 | fmtbuf[fmtbuf_pos] = '\0'; |
| 995 | read_format = false; |
| 996 | if (fmt->tags[parpos] == tcs->type) |
| 997 | { |
| 998 | snprintf(&buf[buf_pos], buf_size - buf_pos, fmtbuf, tcs->result); |
| 999 | } |
| 1000 | else |
| 1001 | { |
| 1002 | /* Need to fetch the tag data. */ |
| 1003 | if (!tagcache_retrieve(tcs, tcs->idx_id, fmt->tags[parpos], |
| 1004 | &buf[buf_pos], buf_size - buf_pos)) |
| 1005 | { |
| 1006 | logf("retrieve failed"); |
| 1007 | return -3; |
| 1008 | } |
| 1009 | } |
| 1010 | buf_pos += strlen(&buf[buf_pos]); |
| 1011 | parpos++; |
| 1012 | } |
| 1013 | else if (fmt->formatstr[i] == 'd') |
| 1014 | { |
| 1015 | fmtbuf[fmtbuf_pos] = '\0'; |
| 1016 | read_format = false; |
| 1017 | snprintf(&buf[buf_pos], buf_size - buf_pos, fmtbuf, |
| 1018 | tagcache_get_numeric(tcs, fmt->tags[parpos])); |
| 1019 | buf_pos += strlen(&buf[buf_pos]); |
| 1020 | parpos++; |
| 1021 | } |
| 1022 | continue; |
| 1023 | } |
| 1024 | |
| 1025 | buf[buf_pos++] = fmt->formatstr[i]; |
| 1026 | |
| 1027 | if (buf_pos - 1 >= buf_size) |
| 1028 | { |
| 1029 | logf("buffer overflow"); |
| 1030 | return -4; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | buf[buf_pos++] = '\0'; |
| 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1039 | static int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs, |
| 1040 | int offset, bool init) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1041 | { |
| 1042 | struct tagentry *dptr = (struct tagentry *)c->dircache; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1043 | struct display_format *fmt; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1044 | int i; |
| 1045 | int namebufused = 0; |
| 1046 | int total_count = 0; |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1047 | int special_entry_count = 0; |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1048 | int level = c->currextra; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1049 | int tag; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1050 | bool sort = false; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1051 | int sort_limit; |
| 1052 | int strip; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1053 | |
| 1054 | if (init |
| 1055 | #ifdef HAVE_TC_RAMCACHE |
| 1056 | && !tagcache_is_ramcache() |
| 1057 | #endif |
| 1058 | ) |
| 1059 | { |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1060 | /* Show search progress straight away if the disk needs to spin up, |
| 1061 | otherwise show it after the normal 1/2 second delay */ |
| 1062 | show_search_progress( |
Barry Wardell | aef38f6 | 2008-02-27 17:54:57 +0000 | [diff] [blame] | 1063 | #if !defined(HAVE_FLASH_STORAGE) && !defined(SIMULATOR) |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1064 | ata_disk_is_active() |
| 1065 | #else |
| 1066 | true |
Barry Wardell | 3e4d79e | 2008-02-26 19:25:07 +0000 | [diff] [blame] | 1067 | #endif |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1068 | , 0); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1071 | if (c->currtable == allsubentries) |
| 1072 | { |
| 1073 | tag = tag_title; |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1074 | level--; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1075 | } |
| 1076 | else |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1077 | tag = csi->tagorder[level]; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1078 | |
| 1079 | if (!tagcache_search(tcs, tag)) |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1080 | return -1; |
| 1081 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1082 | /* Prevent duplicate entries in the search list. */ |
| 1083 | tagcache_search_set_uniqbuf(tcs, uniqbuf, UNIQBUF_SIZE); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1084 | |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1085 | if (level || csi->clause_count[0] || tagcache_is_numeric_tag(tag)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1086 | sort = true; |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1087 | |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1088 | for (i = 0; i < level; i++) |
| 1089 | { |
| 1090 | if (tagcache_is_numeric_tag(csi->tagorder[i])) |
| 1091 | { |
| 1092 | static struct tagcache_search_clause cc; |
| 1093 | |
| 1094 | memset(&cc, 0, sizeof(struct tagcache_search_clause)); |
| 1095 | cc.tag = csi->tagorder[i]; |
| 1096 | cc.type = clause_is; |
| 1097 | cc.numeric = true; |
| 1098 | cc.numeric_data = csi->result_seek[i]; |
| 1099 | tagcache_search_add_clause(tcs, &cc); |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | tagcache_search_add_filter(tcs, csi->tagorder[i], |
| 1104 | csi->result_seek[i]); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | for (i = 0; i <= level; i++) |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1109 | { |
| 1110 | int j; |
| 1111 | |
| 1112 | for (j = 0; j < csi->clause_count[i]; j++) |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1113 | tagcache_search_add_clause(tcs, csi->clause[i][j]); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | current_offset = offset; |
| 1117 | current_entry_count = 0; |
| 1118 | c->dirfull = false; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1119 | |
| 1120 | fmt = NULL; |
| 1121 | for (i = 0; i < format_count; i++) |
| 1122 | { |
| 1123 | if (formats[i]->group_id == csi->format_id[level]) |
| 1124 | fmt = formats[i]; |
| 1125 | } |
| 1126 | |
| 1127 | if (fmt) |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1128 | { |
| 1129 | sort_inverse = fmt->sort_inverse; |
| 1130 | sort_limit = fmt->limit; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1131 | strip = fmt->strip; |
Miika Pekkarinen | ab643e7 | 2006-11-11 17:39:37 +0000 | [diff] [blame] | 1132 | |
| 1133 | /* Check if sorting is forced. */ |
| 1134 | if (fmt->sort) |
| 1135 | sort = true; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1136 | } |
| 1137 | else |
| 1138 | { |
| 1139 | sort_inverse = false; |
| 1140 | sort_limit = 0; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1141 | strip = 0; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1142 | } |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1143 | |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1144 | if (tag != tag_title && tag != tag_filename) |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1145 | { |
| 1146 | if (offset == 0) |
| 1147 | { |
| 1148 | dptr->newtable = allsubentries; |
| 1149 | dptr->name = str(LANG_TAGNAVI_ALL_TRACKS); |
| 1150 | dptr++; |
| 1151 | current_entry_count++; |
| 1152 | } |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1153 | if (offset <= 1) |
| 1154 | { |
| 1155 | dptr->newtable = navibrowse; |
| 1156 | dptr->name = str(LANG_TAGNAVI_RANDOM); |
| 1157 | dptr->extraseek = -1; |
| 1158 | dptr++; |
| 1159 | current_entry_count++; |
| 1160 | } |
| 1161 | special_entry_count+=2; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1164 | total_count += special_entry_count; |
| 1165 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1166 | while (tagcache_get_next(tcs)) |
| 1167 | { |
| 1168 | if (total_count++ < offset) |
| 1169 | continue; |
| 1170 | |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1171 | dptr->newtable = navibrowse; |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1172 | if (tag == tag_title || tag == tag_filename) |
Miika Pekkarinen | 4294615 | 2006-08-30 18:18:37 +0000 | [diff] [blame] | 1173 | { |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1174 | dptr->newtable = playtrack; |
Miika Pekkarinen | 4294615 | 2006-08-30 18:18:37 +0000 | [diff] [blame] | 1175 | dptr->extraseek = tcs->idx_id; |
| 1176 | } |
| 1177 | else |
| 1178 | dptr->extraseek = tcs->result_seek; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1179 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1180 | fmt = NULL; |
| 1181 | /* Check the format */ |
| 1182 | for (i = 0; i < format_count; i++) |
| 1183 | { |
| 1184 | if (formats[i]->group_id != csi->format_id[level]) |
| 1185 | continue; |
| 1186 | |
| 1187 | if (tagcache_check_clauses(tcs, formats[i]->clause, |
| 1188 | formats[i]->clause_count)) |
| 1189 | { |
| 1190 | fmt = formats[i]; |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | if (!tcs->ramresult || fmt) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1196 | { |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1197 | char buf[MAX_PATH]; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1198 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1199 | if (fmt) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1200 | { |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1201 | if (format_str(tcs, fmt, buf, sizeof buf) < 0) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1202 | { |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1203 | logf("format_str() failed"); |
| 1204 | return 0; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1205 | } |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1206 | } |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1207 | |
| 1208 | dptr->name = &c->name_buffer[namebufused]; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1209 | if (fmt) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1210 | namebufused += strlen(buf)+1; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1211 | else |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1212 | namebufused += tcs->result_len; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1213 | |
| 1214 | if (namebufused >= c->name_buffer_size) |
| 1215 | { |
| 1216 | logf("chunk mode #2: %d", current_entry_count); |
| 1217 | c->dirfull = true; |
| 1218 | sort = false; |
| 1219 | break ; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1220 | } |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1221 | if (fmt) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1222 | strcpy(dptr->name, buf); |
| 1223 | else |
| 1224 | strcpy(dptr->name, tcs->result); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1225 | } |
| 1226 | else |
| 1227 | dptr->name = tcs->result; |
| 1228 | |
| 1229 | dptr++; |
| 1230 | current_entry_count++; |
| 1231 | |
| 1232 | if (current_entry_count >= global_settings.max_files_in_dir) |
| 1233 | { |
| 1234 | logf("chunk mode #3: %d", current_entry_count); |
| 1235 | c->dirfull = true; |
| 1236 | sort = false; |
| 1237 | break ; |
| 1238 | } |
| 1239 | |
| 1240 | if (init && !tcs->ramsearch) |
| 1241 | { |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1242 | if (!show_search_progress(false, total_count)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1243 | { |
| 1244 | tagcache_search_finish(tcs); |
| 1245 | return current_entry_count; |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | if (sort) |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1251 | qsort(c->dircache + special_entry_count * c->dentry_size, |
| 1252 | current_entry_count - special_entry_count, |
| 1253 | c->dentry_size, compare); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1254 | |
| 1255 | if (!init) |
| 1256 | { |
| 1257 | tagcache_search_finish(tcs); |
| 1258 | return current_entry_count; |
| 1259 | } |
| 1260 | |
| 1261 | while (tagcache_get_next(tcs)) |
| 1262 | { |
| 1263 | if (!tcs->ramsearch) |
| 1264 | { |
| 1265 | if (!show_search_progress(false, total_count)) |
| 1266 | break; |
| 1267 | } |
| 1268 | total_count++; |
| 1269 | } |
| 1270 | |
| 1271 | tagcache_search_finish(tcs); |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1272 | |
| 1273 | if (!sort && (sort_inverse || sort_limit)) |
| 1274 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1275 | gui_syncsplash(HZ*4, ID2P(LANG_SHOWDIR_BUFFER_FULL), total_count); |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1276 | logf("Too small dir buffer"); |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | if (sort_limit) |
| 1281 | total_count = MIN(total_count, sort_limit); |
| 1282 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1283 | if (strip) |
| 1284 | { |
| 1285 | dptr = c->dircache; |
| 1286 | for (i = 0; i < total_count; i++, dptr++) |
| 1287 | { |
| 1288 | int len = strlen(dptr->name); |
| 1289 | |
| 1290 | if (len < strip) |
| 1291 | continue; |
| 1292 | |
| 1293 | dptr->name = &dptr->name[strip]; |
| 1294 | } |
| 1295 | } |
| 1296 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1297 | return total_count; |
| 1298 | } |
| 1299 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1300 | static int load_root(struct tree_context *c) |
| 1301 | { |
| 1302 | struct tagentry *dptr = (struct tagentry *)c->dircache; |
| 1303 | int i; |
| 1304 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1305 | tc = c; |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1306 | c->currtable = root; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1307 | if (c->dirlevel == 0) |
| 1308 | c->currextra = root_menu; |
| 1309 | |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 1310 | menu = menus[c->currextra]; |
| 1311 | if (menu == NULL) |
| 1312 | return 0; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1313 | |
| 1314 | for (i = 0; i < menu->itemcount; i++) |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1315 | { |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1316 | dptr->name = menu->items[i]->name; |
| 1317 | switch (menu->items[i]->type) |
| 1318 | { |
| 1319 | case menu_next: |
| 1320 | dptr->newtable = navibrowse; |
| 1321 | dptr->extraseek = i; |
| 1322 | break; |
| 1323 | |
| 1324 | case menu_load: |
| 1325 | dptr->newtable = root; |
| 1326 | dptr->extraseek = menu->items[i]->link; |
| 1327 | break; |
| 1328 | } |
| 1329 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1330 | dptr++; |
| 1331 | } |
| 1332 | |
| 1333 | current_offset = 0; |
| 1334 | current_entry_count = i; |
| 1335 | |
| 1336 | return i; |
| 1337 | } |
| 1338 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1339 | int tagtree_load(struct tree_context* c) |
| 1340 | { |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1341 | int count; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1342 | int table = c->currtable; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1343 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1344 | c->dentry_size = sizeof(struct tagentry); |
Steve Bavin | e994774 | 2006-10-20 06:49:31 +0000 | [diff] [blame] | 1345 | c->dirsindir = 0; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1346 | |
| 1347 | if (!table) |
| 1348 | { |
| 1349 | c->dirfull = false; |
| 1350 | table = root; |
| 1351 | c->currtable = table; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1352 | c->currextra = root_menu; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1355 | switch (table) |
| 1356 | { |
| 1357 | case root: |
| 1358 | count = load_root(c); |
| 1359 | break; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1360 | |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1361 | case allsubentries: |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1362 | case navibrowse: |
| 1363 | logf("navibrowse..."); |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1364 | cpu_boost(true); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1365 | count = retrieve_entries(c, &tcs, 0, true); |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1366 | cpu_boost(false); |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1367 | break; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1368 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1369 | default: |
| 1370 | logf("Unsupported table %d\n", table); |
| 1371 | return -1; |
| 1372 | } |
| 1373 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1374 | if (count < 0) |
| 1375 | { |
| 1376 | c->dirlevel = 0; |
| 1377 | count = load_root(c); |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 1378 | gui_syncsplash(HZ, str(LANG_TAGCACHE_BUSY)); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1379 | } |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1380 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1381 | /* The _total_ numer of entries available. */ |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1382 | c->dirlength = c->filesindir = count; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1383 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1384 | return count; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1387 | int tagtree_enter(struct tree_context* c) |
| 1388 | { |
| 1389 | int rc = 0; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1390 | struct tagentry *dptr; |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1391 | struct mp3entry *id3; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1392 | int newextra; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1393 | int seek; |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1394 | int source; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1395 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1396 | dptr = tagtree_get_entry(c, c->selected_item); |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1397 | |
| 1398 | c->dirfull = false; |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1399 | seek = dptr->extraseek; |
| 1400 | if (seek == -1) |
| 1401 | { |
Steve Bavin | c7a046d | 2008-01-03 07:29:19 +0000 | [diff] [blame] | 1402 | if(c->filesindir<=2) |
| 1403 | return 0; |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1404 | srand(current_tick); |
| 1405 | dptr = (tagtree_get_entry(c, 2+(rand() % (c->filesindir-2)))); |
| 1406 | seek = dptr->extraseek; |
| 1407 | } |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1408 | newextra = dptr->newtable; |
| 1409 | |
| 1410 | if (c->dirlevel >= MAX_DIR_LEVELS) |
| 1411 | return 0; |
| 1412 | |
| 1413 | c->selected_item_history[c->dirlevel]=c->selected_item; |
| 1414 | c->table_history[c->dirlevel] = c->currtable; |
| 1415 | c->extra_history[c->dirlevel] = c->currextra; |
| 1416 | c->pos_history[c->dirlevel] = c->firstpos; |
| 1417 | c->dirlevel++; |
| 1418 | |
| 1419 | switch (c->currtable) { |
| 1420 | case root: |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1421 | c->currextra = newextra; |
Miika Pekkarinen | 35d213a | 2006-04-05 18:46:38 +0000 | [diff] [blame] | 1422 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1423 | if (newextra == root) |
| 1424 | { |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 1425 | menu = menus[seek]; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1426 | c->currextra = seek; |
| 1427 | } |
| 1428 | |
| 1429 | else if (newextra == navibrowse) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1430 | { |
| 1431 | int i, j; |
| 1432 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1433 | csi = menu->items[seek]->si; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1434 | c->currextra = 0; |
| 1435 | |
Miika Pekkarinen | 6e8ab3d | 2006-09-25 19:52:38 +0000 | [diff] [blame] | 1436 | strncpy(current_title[c->currextra], dptr->name, |
| 1437 | sizeof(current_title[0]) - 1); |
| 1438 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1439 | /* Read input as necessary. */ |
| 1440 | for (i = 0; i < csi->tagorder_count; i++) |
| 1441 | { |
| 1442 | for (j = 0; j < csi->clause_count[i]; j++) |
| 1443 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1444 | char* searchstring; |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1445 | source = csi->clause[i][j]->source; |
| 1446 | |
| 1447 | if (source == source_constant) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1448 | continue; |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1449 | |
| 1450 | searchstring=csi->clause[i][j]->str; |
| 1451 | *searchstring = '\0'; |
| 1452 | |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1453 | id3 = audio_current_track(); |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1454 | |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 1455 | if (source == source_current_path && id3) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1456 | { |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 1457 | char *e; |
| 1458 | strncpy(searchstring, id3->path, SEARCHSTR_SIZE); |
| 1459 | e = strrchr(searchstring, '/'); |
| 1460 | if (e) |
| 1461 | *e = '\0'; |
| 1462 | } |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1463 | else if (source > source_runtime && id3) |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1464 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1465 | |
| 1466 | int k = source-source_runtime; |
| 1467 | int offset = id3_to_search_mapping[k].id3_offset; |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 1468 | char **src = (char**)((char*)id3 + offset); |
| 1469 | if (*src) |
| 1470 | { |
| 1471 | strncpy(searchstring, *src, SEARCHSTR_SIZE); |
| 1472 | searchstring[SEARCHSTR_SIZE-1] = '\0'; |
| 1473 | } |
| 1474 | } |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1475 | else |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1476 | { |
| 1477 | rc = kbd_input(searchstring, SEARCHSTR_SIZE); |
| 1478 | if (rc == -1 || !searchstring[0]) |
| 1479 | { |
| 1480 | tagtree_exit(c); |
| 1481 | return 0; |
| 1482 | } |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1483 | if (csi->clause[i][j]->numeric) |
| 1484 | csi->clause[i][j]->numeric_data = atoi(searchstring); |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Jonathan Gordon | 4d18aa3 | 2007-10-29 12:02:55 +0000 | [diff] [blame] | 1487 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1488 | } |
| 1489 | } |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1490 | } |
Miika Pekkarinen | 35d213a | 2006-04-05 18:46:38 +0000 | [diff] [blame] | 1491 | c->currtable = newextra; |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 1492 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1495 | case navibrowse: |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1496 | case allsubentries: |
| 1497 | if (newextra == playtrack) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1498 | { |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1499 | c->dirlevel--; |
Miika Pekkarinen | 29b9146 | 2006-08-09 07:28:48 +0000 | [diff] [blame] | 1500 | /* about to create a new current playlist... |
| 1501 | allow user to cancel the operation */ |
Nils Wallménius | dabcb81 | 2008-05-01 10:13:12 +0000 | [diff] [blame] | 1502 | if (!warn_on_pl_erase()) |
| 1503 | break; |
Miika Pekkarinen | 29b9146 | 2006-08-09 07:28:48 +0000 | [diff] [blame] | 1504 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1505 | if (tagtree_play_folder(c) >= 0) |
| 1506 | rc = 2; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1507 | break; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1508 | } |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1509 | |
| 1510 | c->currtable = newextra; |
| 1511 | csi->result_seek[c->currextra] = seek; |
| 1512 | if (c->currextra < csi->tagorder_count-1) |
| 1513 | c->currextra++; |
| 1514 | else |
| 1515 | c->dirlevel--; |
Miika Pekkarinen | 6e8ab3d | 2006-09-25 19:52:38 +0000 | [diff] [blame] | 1516 | |
| 1517 | /* Update the statusbar title */ |
| 1518 | strncpy(current_title[c->currextra], dptr->name, |
| 1519 | sizeof(current_title[0]) - 1); |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1522 | default: |
| 1523 | c->dirlevel--; |
| 1524 | break; |
| 1525 | } |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1526 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1527 | c->selected_item=0; |
| 1528 | gui_synclist_select_item(&tree_lists, c->selected_item); |
| 1529 | |
| 1530 | return rc; |
| 1531 | } |
| 1532 | |
| 1533 | void tagtree_exit(struct tree_context* c) |
| 1534 | { |
| 1535 | c->dirfull = false; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1536 | if (c->dirlevel > 0) |
| 1537 | c->dirlevel--; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1538 | c->selected_item=c->selected_item_history[c->dirlevel]; |
| 1539 | gui_synclist_select_item(&tree_lists, c->selected_item); |
| 1540 | c->currtable = c->table_history[c->dirlevel]; |
| 1541 | c->currextra = c->extra_history[c->dirlevel]; |
| 1542 | c->firstpos = c->pos_history[c->dirlevel]; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | int tagtree_get_filename(struct tree_context* c, char *buf, int buflen) |
| 1546 | { |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1547 | struct tagentry *entry; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1548 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1549 | entry = tagtree_get_entry(c, c->selected_item); |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1550 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1551 | if (!tagcache_search(&tcs, tag_filename)) |
| 1552 | return -1; |
| 1553 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1554 | if (!tagcache_retrieve(&tcs, entry->extraseek, tcs.type, buf, buflen)) |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1555 | { |
| 1556 | tagcache_search_finish(&tcs); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1557 | return -2; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1560 | tagcache_search_finish(&tcs); |
| 1561 | |
| 1562 | return 0; |
| 1563 | } |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1564 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1565 | static bool insert_all_playlist(struct tree_context *c, int position, bool queue) |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1566 | { |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1567 | int i; |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1568 | char buf[MAX_PATH]; |
Miika Pekkarinen | c0b99f2 | 2006-08-12 09:06:50 +0000 | [diff] [blame] | 1569 | int from, to, direction; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1570 | int files_left = c->filesindir; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1571 | |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1572 | cpu_boost(true); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1573 | if (!tagcache_search(&tcs, tag_filename)) |
| 1574 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1575 | gui_syncsplash(HZ, ID2P(LANG_TAGCACHE_BUSY)); |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1576 | cpu_boost(false); |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1577 | return false; |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Jonathan Gordon | be3f29c | 2006-12-26 13:31:04 +0000 | [diff] [blame] | 1580 | if (position == PLAYLIST_REPLACE) |
| 1581 | { |
Bertrik Sikken | 3e98eb2 | 2008-04-20 11:19:50 +0000 | [diff] [blame] | 1582 | if (playlist_remove_all_tracks(NULL) == 0) |
Jonathan Gordon | be3f29c | 2006-12-26 13:31:04 +0000 | [diff] [blame] | 1583 | position = PLAYLIST_INSERT_LAST; |
| 1584 | else return -1; } |
| 1585 | |
Miika Pekkarinen | c0b99f2 | 2006-08-12 09:06:50 +0000 | [diff] [blame] | 1586 | if (position == PLAYLIST_INSERT_FIRST) |
| 1587 | { |
| 1588 | from = c->filesindir - 1; |
| 1589 | to = -1; |
| 1590 | direction = -1; |
| 1591 | } |
| 1592 | else |
| 1593 | { |
| 1594 | from = 0; |
| 1595 | to = c->filesindir; |
| 1596 | direction = 1; |
| 1597 | } |
| 1598 | |
| 1599 | for (i = from; i != to; i += direction) |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1600 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1601 | /* Count back to zero */ |
| 1602 | if (!show_search_progress(false, files_left--)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1603 | break; |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1604 | |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1605 | if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek, |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1606 | tcs.type, buf, sizeof buf)) |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1607 | { |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
Miika Pekkarinen | 887cfeb | 2006-08-10 09:50:45 +0000 | [diff] [blame] | 1611 | if (playlist_insert_track(NULL, buf, position, queue, false) < 0) |
Miika Pekkarinen | 5019b32 | 2006-08-14 19:03:37 +0000 | [diff] [blame] | 1612 | { |
| 1613 | logf("playlist_insert_track failed"); |
Miika Pekkarinen | 887cfeb | 2006-08-10 09:50:45 +0000 | [diff] [blame] | 1614 | break; |
Miika Pekkarinen | 5019b32 | 2006-08-14 19:03:37 +0000 | [diff] [blame] | 1615 | } |
Miika Pekkarinen | 54ec1f5 | 2006-08-12 11:00:39 +0000 | [diff] [blame] | 1616 | yield(); |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1617 | } |
Miika Pekkarinen | 887cfeb | 2006-08-10 09:50:45 +0000 | [diff] [blame] | 1618 | playlist_sync(NULL); |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1619 | tagcache_search_finish(&tcs); |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1620 | cpu_boost(false); |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1621 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1622 | return true; |
| 1623 | } |
| 1624 | |
| 1625 | bool tagtree_insert_selection_playlist(int position, bool queue) |
| 1626 | { |
| 1627 | struct tagentry *dptr; |
Miika Pekkarinen | 7374ca7 | 2006-07-26 06:44:39 +0000 | [diff] [blame] | 1628 | char buf[MAX_PATH]; |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1629 | int dirlevel = tc->dirlevel; |
| 1630 | |
Miika Pekkarinen | 54ec1f5 | 2006-08-12 11:00:39 +0000 | [diff] [blame] | 1631 | /* We need to set the table to allsubentries. */ |
| 1632 | show_search_progress(true, 0); |
| 1633 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1634 | dptr = tagtree_get_entry(tc, tc->selected_item); |
| 1635 | |
Miika Pekkarinen | 7374ca7 | 2006-07-26 06:44:39 +0000 | [diff] [blame] | 1636 | /* Insert a single track? */ |
| 1637 | if (dptr->newtable == playtrack) |
| 1638 | { |
| 1639 | if (tagtree_get_filename(tc, buf, sizeof buf) < 0) |
| 1640 | { |
| 1641 | logf("tagtree_get_filename failed"); |
| 1642 | return false; |
| 1643 | } |
Miika Pekkarinen | 887cfeb | 2006-08-10 09:50:45 +0000 | [diff] [blame] | 1644 | playlist_insert_track(NULL, buf, position, queue, true); |
Miika Pekkarinen | 7374ca7 | 2006-07-26 06:44:39 +0000 | [diff] [blame] | 1645 | |
| 1646 | return true; |
| 1647 | } |
| 1648 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1649 | if (dptr->newtable == navibrowse) |
| 1650 | { |
| 1651 | tagtree_enter(tc); |
| 1652 | tagtree_load(tc); |
| 1653 | dptr = tagtree_get_entry(tc, tc->selected_item); |
| 1654 | } |
| 1655 | else if (dptr->newtable != allsubentries) |
| 1656 | { |
| 1657 | logf("unsupported table: %d", dptr->newtable); |
| 1658 | return false; |
| 1659 | } |
| 1660 | |
| 1661 | /* Now the current table should be allsubentries. */ |
| 1662 | if (dptr->newtable != playtrack) |
| 1663 | { |
| 1664 | tagtree_enter(tc); |
| 1665 | tagtree_load(tc); |
| 1666 | dptr = tagtree_get_entry(tc, tc->selected_item); |
| 1667 | |
| 1668 | /* And now the newtable should be playtrack. */ |
| 1669 | if (dptr->newtable != playtrack) |
| 1670 | { |
| 1671 | logf("newtable: %d !!", dptr->newtable); |
| 1672 | tc->dirlevel = dirlevel; |
| 1673 | return false; |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | if (tc->filesindir <= 0) |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1678 | gui_syncsplash(HZ, ID2P(LANG_END_PLAYLIST)); |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1679 | else |
| 1680 | { |
| 1681 | logf("insert_all_playlist"); |
Miika Pekkarinen | 5019b32 | 2006-08-14 19:03:37 +0000 | [diff] [blame] | 1682 | if (!insert_all_playlist(tc, position, queue)) |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1683 | gui_syncsplash(HZ*2, ID2P(LANG_FAILED)); |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | /* Finally return the dirlevel to its original value. */ |
| 1687 | while (tc->dirlevel > dirlevel) |
| 1688 | tagtree_exit(tc); |
| 1689 | tagtree_load(tc); |
| 1690 | |
| 1691 | return true; |
| 1692 | } |
| 1693 | |
| 1694 | static int tagtree_play_folder(struct tree_context* c) |
| 1695 | { |
| 1696 | if (playlist_create(NULL, NULL) < 0) |
| 1697 | { |
| 1698 | logf("Failed creating playlist\n"); |
| 1699 | return -1; |
| 1700 | } |
| 1701 | |
Hardeep Sidhu | 77d47b5 | 2006-09-18 04:41:50 +0000 | [diff] [blame] | 1702 | if (!insert_all_playlist(c, PLAYLIST_INSERT_LAST, false)) |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1703 | return -2; |
| 1704 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1705 | if (global_settings.playlist_shuffle) |
| 1706 | c->selected_item = playlist_shuffle(current_tick, c->selected_item); |
| 1707 | if (!global_settings.play_selected) |
| 1708 | c->selected_item = 0; |
| 1709 | gui_synclist_select_item(&tree_lists, c->selected_item); |
| 1710 | |
| 1711 | playlist_start(c->selected_item,0); |
| 1712 | |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1716 | struct tagentry* tagtree_get_entry(struct tree_context *c, int id) |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1717 | { |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1718 | struct tagentry *entry = (struct tagentry *)c->dircache; |
| 1719 | int realid = id - current_offset; |
| 1720 | |
| 1721 | /* Load the next chunk if necessary. */ |
| 1722 | if (realid >= current_entry_count || realid < 0) |
| 1723 | { |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1724 | cpu_boost(true); |
Hardeep Sidhu | 000397d | 2006-05-05 07:54:19 +0000 | [diff] [blame] | 1725 | if (retrieve_entries(c, &tcs2, MAX(0, id - (current_entry_count / 2)), |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1726 | false) < 0) |
| 1727 | { |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1728 | logf("retrieve failed"); |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1729 | cpu_boost(false); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1730 | return NULL; |
| 1731 | } |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1732 | realid = id - current_offset; |
Miika Pekkarinen | c5d57f0 | 2006-12-05 20:01:48 +0000 | [diff] [blame] | 1733 | cpu_boost(false); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | return &entry[realid]; |
Miika Pekkarinen | 58fe4de | 2006-04-10 10:26:24 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
Miika Pekkarinen | 1e6b227 | 2006-09-19 12:36:21 +0000 | [diff] [blame] | 1739 | char *tagtree_get_title(struct tree_context* c) |
| 1740 | { |
| 1741 | switch (c->currtable) |
| 1742 | { |
| 1743 | case root: |
| 1744 | return menu->title; |
| 1745 | |
| 1746 | case navibrowse: |
Miika Pekkarinen | 1e6b227 | 2006-09-19 12:36:21 +0000 | [diff] [blame] | 1747 | case allsubentries: |
Miika Pekkarinen | 6e8ab3d | 2006-09-25 19:52:38 +0000 | [diff] [blame] | 1748 | return current_title[c->currextra]; |
Miika Pekkarinen | 1e6b227 | 2006-09-19 12:36:21 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | return "?"; |
| 1752 | } |
| 1753 | |
Hardeep Sidhu | a85b23f | 2006-05-05 07:01:43 +0000 | [diff] [blame] | 1754 | int tagtree_get_attr(struct tree_context* c) |
| 1755 | { |
| 1756 | int attr = -1; |
| 1757 | switch (c->currtable) |
| 1758 | { |
| 1759 | case navibrowse: |
| 1760 | if (csi->tagorder[c->currextra] == tag_title) |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 1761 | attr = FILE_ATTR_AUDIO; |
Hardeep Sidhu | a85b23f | 2006-05-05 07:01:43 +0000 | [diff] [blame] | 1762 | else |
| 1763 | attr = ATTR_DIRECTORY; |
| 1764 | break; |
| 1765 | |
| 1766 | case allsubentries: |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 1767 | attr = FILE_ATTR_AUDIO; |
Hardeep Sidhu | a85b23f | 2006-05-05 07:01:43 +0000 | [diff] [blame] | 1768 | break; |
| 1769 | |
| 1770 | default: |
| 1771 | attr = ATTR_DIRECTORY; |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | return attr; |
| 1776 | } |
| 1777 | |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 1778 | int tagtree_get_icon(struct tree_context* c) |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1779 | { |
Hardeep Sidhu | 000397d | 2006-05-05 07:54:19 +0000 | [diff] [blame] | 1780 | int icon = Icon_Folder; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1781 | |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 1782 | if (tagtree_get_attr(c) == FILE_ATTR_AUDIO) |
Hardeep Sidhu | 000397d | 2006-05-05 07:54:19 +0000 | [diff] [blame] | 1783 | icon = Icon_Audio; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1784 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1785 | return icon; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1786 | } |