annotate src/audacious/ui_jumptotrack_cache.c @ 4546:d4c5719d30d1

- rename dock.c to ui_dock.c - remove an UI reference in playlist.c
author mf0102 <0102@gmx.at>
date Wed, 14 May 2008 00:35:09 +0200
parents ca077e01ed3a
children 23a9ded30c70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4291
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
1 /* Audacious - Cross-platform multimedia player
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
2 * Copyright (C) 2008 Audacious development team.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
3 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
6 * the Free Software Foundation; under version 3 of the License.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
7 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
11 * GNU General Public License for more details.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
12 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
14 * along with this program. If not, see <http://www.gnu.org/licenses>.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
15 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
16 * The Audacious team does not consider modular code linking to
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
17 * Audacious or using our public API to be a derived work.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
18 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
19
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
20 #include <glib.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
21 #include <string.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
22 #include <assert.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
23
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
24 #if defined(USE_REGEX_ONIGURUMA)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
25 #include <onigposix.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
26 #elif defined(USE_REGEX_PCRE)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
27 #include <pcreposix.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
28 #else
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
29 #include <regex.h>
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
30 #endif
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
31
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
32 #include "playlist.h"
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
33 #include "strings.h"
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
34
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
35 #include "ui_jumptotrack_cache.h"
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
36
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
37 // Struct to keep information about matches from searches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
38 typedef struct
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
39 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
40 GArray* track_entries; // JumpToTrackEntry*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
41 GArray* normalized_titles; // gchar*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
42 } KeywordMatches;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
43
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
44 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
45 * Creates an regular expression list usable in searches from search keyword.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
46 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
47 * In searches, every regular expression on this list is matched against
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
48 * the search title and if they all match, the title is declared as
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
49 * matching one.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
50 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
51 * Regular expressions in list are formed by splitting the 'keyword' to words
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
52 * by splitting the keyword string with space character.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
53 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
54 static GSList*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
55 ui_jump_to_track_cache_regex_list_create(const GString* keyword)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
56 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
57 GSList *regex_list = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
58 gchar **words = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
59 int i = -1;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
60 /* Chop the key string into ' '-separated key regex-pattern strings */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
61 words = g_strsplit(keyword->str, " ", 0);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
62
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
63 /* create a list of regex using the regex-pattern strings */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
64 while ( words[++i] != NULL )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
65 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
66 // Ignore empty words.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
67 if (words[i][0] == 0) {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
68 continue;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
69 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
70 regex_t *regex = g_malloc(sizeof(regex_t));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
71 #if defined(USE_REGEX_PCRE)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
72 if ( regcomp( regex , words[i] , REG_NOSUB | REG_UTF8 ) == 0 )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
73 #else
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
74 if ( regcomp( regex , words[i] , REG_NOSUB ) == 0 )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
75 #endif
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
76 regex_list = g_slist_append( regex_list , regex );
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
77 else
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
78 g_free( regex );
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
79 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
80
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
81 g_strfreev(words);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
82
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
83 return regex_list;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
84 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
85
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
86 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
87 * Frees the regular expression list used in searches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
88 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
89 static void
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
90 ui_jump_to_track_cache_regex_list_free(GSList* regex_list)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
91 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
92 if ( regex_list != NULL )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
93 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
94 GSList* regex_list_tmp = regex_list;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
95 while ( regex_list != NULL )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
96 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
97 regex_t *regex = regex_list->data;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
98 regfree( regex );
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
99 g_free( regex );
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
100 regex_list = g_slist_next(regex_list);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
101 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
102 g_slist_free( regex_list_tmp );
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
103 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
104 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
105
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
106 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
107 * Checks if 'song' matches all regular expressions in 'regex_list'.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
108 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
109 static gboolean
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
110 ui_jump_to_track_match(const gchar * song, GSList *regex_list)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
111 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
112 if ( song == NULL )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
113 return FALSE;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
114
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
115 for ( ; regex_list ; regex_list = g_slist_next(regex_list) )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
116 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
117 regex_t *regex = regex_list->data;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
118 if ( regexec( regex , song , 0 , NULL , 0 ) != 0 )
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
119 return FALSE;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
120 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
121
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
122 return TRUE;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
123 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
124
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
125 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
126 * Returns all songs that match 'keyword'.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
127 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
128 * Searches are conducted against entries in 'search_space' variable
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
129 * and after the search, search result is added to 'cache'.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
130 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
131 * @param cache The result of this search is added to cache.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
132 * @param search_space Entries inside which the search is conducted.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
133 * @param keyword Normalized string for searches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
134 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
135 static GArray*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
136 ui_jump_to_track_cache_match_keyword(JumpToTrackCache* cache,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
137 const KeywordMatches* search_space,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
138 const GString* keyword)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
139 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
140 GSList* regex_list = ui_jump_to_track_cache_regex_list_create(keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
141 GArray* track_entries = g_array_new(FALSE, FALSE, sizeof(JumpToTrackEntry*));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
142 GArray* normalized_titles = g_array_new(FALSE, FALSE, sizeof(gchar*));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
143 gboolean match = FALSE;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
144 int i = 0;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
145
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
146 for (i = 0; i < search_space->normalized_titles->len; i++)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
147 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
148 gchar* title = g_array_index(search_space->normalized_titles, gchar*, i);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
149
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
150 if (regex_list != NULL)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
151 match = ui_jump_to_track_match(title, regex_list);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
152 else
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
153 match = TRUE;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
154
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
155 if (match) {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
156 JumpToTrackEntry* entry = g_array_index(search_space->track_entries,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
157 JumpToTrackEntry*, i);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
158 g_array_append_val(track_entries, entry);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
159 g_array_append_val(normalized_titles, title);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
160 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
161 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
162
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
163 KeywordMatches* keyword_matches = g_new(KeywordMatches, 1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
164 keyword_matches->track_entries = track_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
165 keyword_matches->normalized_titles = normalized_titles;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
166
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
167 g_hash_table_insert(cache->keywords,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
168 GINT_TO_POINTER(g_string_hash(keyword)),
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
169 keyword_matches);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
170
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
171 ui_jump_to_track_cache_regex_list_free(regex_list);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
172 return track_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
173 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
174
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
175 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
176 * Normalizes the search string to be more suitable for searches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
177 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
178 * Basically this does Unicode NFKD normalization to for example match
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
179 * half-width and full-width characters and case folding mainly to match
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
180 * upper- and lowercase letters.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
181 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
182 * String returned by this function should be freed manually.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
183 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
184 static gchar *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
185 normalize_search_string(const gchar* string)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
186 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
187 gchar* normalized_string = g_utf8_normalize(string, -1, G_NORMALIZE_NFKD);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
188 gchar* folded_string = g_utf8_casefold(normalized_string, -1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
189 g_free(normalized_string);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
190 return folded_string;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
191 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
192
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
193 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
194 * Frees the possibly allocated data in KeywordMatches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
195 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
196 static void
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
197 ui_jump_to_track_cache_free_keywordmatch_data(KeywordMatches* match_entry)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
198 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
199 int i = 0;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
200 assert(match_entry->normalized_titles->len == match_entry->track_entries->len);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
201 for (i = 0; i < match_entry->normalized_titles->len; i++)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
202 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
203 g_free(g_array_index(match_entry->normalized_titles, gchar*, i));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
204 g_free(g_array_index(match_entry->track_entries, PlaylistEntry*, i));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
205 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
206 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
207
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
208 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
209 * Frees the memory reserved for an search result.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
210 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
211 static void
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
212 ui_jump_to_track_cache_free_cache_entry(gpointer entry)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
213 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
214 KeywordMatches* match_entry = (KeywordMatches*)entry;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
215 g_array_free(match_entry->track_entries, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
216 g_array_free(match_entry->normalized_titles, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
217 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
218
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
219 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
220 * Creates a new song search cache.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
221 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
222 * Returned value should be freed with ui_jump_to_track_cache_free() function.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
223 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
224 JumpToTrackCache*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
225 ui_jump_to_track_cache_new()
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
226 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
227 JumpToTrackCache* cache = g_new(JumpToTrackCache, 1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
228 cache->playlist_serial = -1;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
229 cache->keywords = g_hash_table_new_full(NULL, NULL, NULL,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
230 ui_jump_to_track_cache_free_cache_entry);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
231 return cache;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
232 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
233
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
234 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
235 * Clears the search cache.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
236 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
237 static void
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
238 ui_jump_to_track_cache_clear(JumpToTrackCache* cache)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
239 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
240 GString* empty_keyword = g_string_new("");
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
241 gpointer found_keyword = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
242
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
243 cache->playlist_serial = -1;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
244
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
245 // All normalized titles reside in an empty key "" so we'll free them
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
246 // first.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
247 found_keyword = g_hash_table_lookup(cache->keywords,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
248 GINT_TO_POINTER(g_string_hash(empty_keyword)));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
249 g_string_free(empty_keyword,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
250 TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
251 if (found_keyword != NULL)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
252 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
253 KeywordMatches* all_titles = (KeywordMatches*)found_keyword;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
254 ui_jump_to_track_cache_free_keywordmatch_data(all_titles);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
255 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
256 // Now when all normalized strings are freed, no need to worry about
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
257 // double frees or memory leaks.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
258 g_hash_table_remove_all(cache->keywords);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
259 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
260
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
261 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
262 * Initializes the search cache if cache is empty or has wrong playlist.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
263 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
264 static void
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
265 ui_jump_to_track_cache_init(JumpToTrackCache* cache,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
266 const Playlist* playlist)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
267 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
268 if (cache->playlist_serial != playlist->serial)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
269 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
270 GList* playlist_entries = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
271 GArray* track_entries = g_array_new(FALSE, FALSE, sizeof(JumpToTrackEntry*));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
272 GArray* normalized_titles = g_array_new(FALSE, FALSE, sizeof(gchar*));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
273 GString* empty_keyword = g_string_new("");
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
274 gulong song_index = 0;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
275
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
276 // Reset cache state
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
277 ui_jump_to_track_cache_clear(cache);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
278
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
279 cache->playlist_serial = playlist->serial;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
280
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
281 // Initialize cache with playlist data
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
282 for (playlist_entries = playlist->entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
283 playlist_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
284 playlist_entries = g_list_next(playlist_entries))
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
285 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
286 PlaylistEntry* playlist_entry = PLAYLIST_ENTRY(playlist_entries->data);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
287
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
288 gchar *title = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
289 /*we are matching all the path not just the filename or title*/
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
290
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
291 /*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
292 * FIXME: The search string should be adapted to the
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
293 * current display setting, e.g. if the user has set it to
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
294 * "%p - %t" then build the match string like that too, or
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
295 * even better, search for each of the tags seperatly.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
296 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
297 * In any case the string to match should _never_ contain
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
298 * something the user can't actually see in the playlist.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
299 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
300 if (playlist_entry->title) {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
301 title = normalize_search_string(playlist_entry->title);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
302 } else {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
303 gchar *realfn = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
304 realfn = g_filename_from_uri(playlist_entry->filename, NULL, NULL);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
305 gchar *tmp_title = str_to_utf8(realfn ? realfn : playlist_entry->filename);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
306 title = normalize_search_string(tmp_title);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
307 g_free(tmp_title);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
308 g_free(realfn); realfn = NULL;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
309 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
310
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
311 JumpToTrackEntry* search_entry = g_new(JumpToTrackEntry, 1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
312 search_entry->entry = playlist_entry;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
313 search_entry->playlist_position = song_index;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
314 g_array_append_val(track_entries, search_entry);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
315 g_array_append_val(normalized_titles, title);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
316 // We need to manually keep track of the current playlist index.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
317 song_index++;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
318 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
319 // Finally insert all titles into cache into an empty key "" so that
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
320 // the matchable data has specified place to be.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
321 KeywordMatches* keyword_data = g_new(KeywordMatches, 1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
322 keyword_data->track_entries = track_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
323 keyword_data->normalized_titles = normalized_titles;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
324 g_hash_table_insert(cache->keywords,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
325 GINT_TO_POINTER(g_string_hash(empty_keyword)),
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
326 keyword_data);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
327 g_string_free(empty_keyword,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
328 TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
329 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
330 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
331
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
332 /**
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
333 * Searches 'keyword' inside 'playlist' by using 'cache' to speed up searching.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
334 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
335 * Searches are basically conducted as follows:
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
336 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
337 * Cache is checked if it has the information about right playlist and
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
338 * initialized with playlist data if needed.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
339 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
340 * Keyword is normalized for searching (Unicode NFKD, case folding)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
341 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
342 * Cache is checked if it has keyword and if it has, we can immediately get
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
343 * the search results and return. If not, searching goes as follows:
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
344 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
345 * Search for the longest word that is in cache that matches the beginning
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
346 * of keyword and use the cached matches as base for the current search.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
347 * The shortest word that can be matched against is the empty string "", so
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
348 * there should always be matches in cache.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
349 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
350 * After that conduct the search by splitting keyword into words separated
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
351 * by space and using regular expressions.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
352 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
353 * When the keyword is searched, search result is added to cache to
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
354 * corresponding keyword that can be used as base for new searches.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
355 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
356 * The motivation for caching is that to search word 'some cool song' one
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
357 * has to type following strings that are all searched individually:
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
358 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
359 * s
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
360 * so
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
361 * som
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
362 * some
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
363 * some
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
364 * some c
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
365 * some co
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
366 * some coo
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
367 * some cool
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
368 * some cool
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
369 * some cool s
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
370 * some cool so
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
371 * some cool son
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
372 * some cool song
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
373 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
374 * If the search results are cached in every phase and the result of
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
375 * the maximum length matching string is used as base for concurrent
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
376 * searches, we can probably get the matches reduced to some hundreds
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
377 * after a few letters typed on playlists with thousands of songs and
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
378 * reduce useless iteration quite a lot.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
379 *
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
380 * Return: GArray of JumpToTrackEntry*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
381 */
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
382 const GArray*
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
383 ui_jump_to_track_cache_search(JumpToTrackCache* cache,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
384 const Playlist* playlist,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
385 const gchar* keyword)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
386 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
387 gchar* normalized_keyword = normalize_search_string(keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
388 GString* keyword_string = g_string_new(normalized_keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
389 GString* match_string = g_string_new(normalized_keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
390 gsize match_string_length = keyword_string->len;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
391
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
392 ui_jump_to_track_cache_init(cache, playlist);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
393
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
394 while (match_string_length >= 0)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
395 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
396 gpointer string_ptr = GINT_TO_POINTER(g_string_hash(match_string));
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
397 gpointer result_entries = g_hash_table_lookup(cache->keywords,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
398 string_ptr);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
399 if (result_entries != NULL)
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
400 {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
401 KeywordMatches* matched_entries = (KeywordMatches*)result_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
402 // if keyword matches something we have, we'll just return the list
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
403 // of matches that the keyword has.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
404 if (match_string_length == keyword_string->len) {
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
405 g_string_free(keyword_string, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
406 g_string_free(match_string, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
407 g_free(normalized_keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
408 return matched_entries->track_entries;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
409 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
410
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
411 // Do normal search by using the result of previous search
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
412 // as search space.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
413 GArray* result = ui_jump_to_track_cache_match_keyword(cache,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
414 matched_entries,
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
415 keyword_string);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
416 g_string_free(keyword_string, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
417 g_string_free(match_string, TRUE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
418 g_free(normalized_keyword);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
419 return result;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
420 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
421 match_string_length--;
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
422 g_string_set_size(match_string, match_string_length);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
423 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
424 // This should never, ever get to this point because there is _always_
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
425 // the empty string to match against.
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
426 AUDDBG("One should never get to this point. Something is really wrong with \
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
427 cache->keywords hash table.");
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
428 assert(FALSE);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
429 g_return_val_if_fail(FALSE, (GArray*)-1);
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
430 }
ca077e01ed3a Add caching to Jump to Track feature to speed up searches. (Bugzilla #180)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
diff changeset
431