comparison src/audacious/ui_jumptotrack.c @ 4160:472aaaca02c0

Make "jump to track" feature to normalize search and match strings (Bugzilla #20)
author Jussi Judin <jjudin+audacious@iki.fi>
date Thu, 10 Jan 2008 02:25:01 -0600
parents 5853d43e539a
children 6425fbe741f1
comparison
equal deleted inserted replaced
4157:e474286a4c23 4160:472aaaca02c0
314 selection = gtk_tree_view_get_selection(tree); 314 selection = gtk_tree_view_get_selection(tree);
315 gtk_tree_selection_select_iter(selection, &iter); 315 gtk_tree_selection_select_iter(selection, &iter);
316 serial = playlist->serial; // important. --yaz 316 serial = playlist->serial; // important. --yaz
317 } 317 }
318 318
319
320 /**
321 * Normalizes an UTF-8 string to be used in case-insensitive searches.
322 *
323 * Returned string should be freed.
324 */
325 static gchar *
326 normalize_search_string(const gchar * string)
327 {
328 gchar* normalized_string = g_utf8_normalize(string, -1, G_NORMALIZE_NFKD);
329 gchar* folded_string = g_utf8_casefold(normalized_string, -1);
330 g_free(normalized_string);
331 return folded_string;
332 }
333
319 static void 334 static void
320 ui_jump_to_track_edit_cb(GtkEntry * entry, gpointer user_data) 335 ui_jump_to_track_edit_cb(GtkEntry * entry, gpointer user_data)
321 { 336 {
322 GtkTreeView *treeview = GTK_TREE_VIEW(user_data); 337 GtkTreeView *treeview = GTK_TREE_VIEW(user_data);
323 GtkTreeSelection *selection; 338 GtkTreeSelection *selection;
334 349
335 GSList *regex_list = NULL, *regex_list_tmp = NULL; 350 GSList *regex_list = NULL, *regex_list_tmp = NULL;
336 gint i = -1; 351 gint i = -1;
337 352
338 /* Chop the key string into ' '-separated key regex-pattern strings */ 353 /* Chop the key string into ' '-separated key regex-pattern strings */
339 words = g_strsplit(gtk_entry_get_text(entry), " ", 0); 354 gchar *search_text = normalize_search_string(gtk_entry_get_text(entry));
355 words = g_strsplit(search_text, " ", 0);
356 g_free(search_text);
340 357
341 /* create a list of regex using the regex-pattern strings */ 358 /* create a list of regex using the regex-pattern strings */
342 while ( words[++i] != NULL ) 359 while ( words[++i] != NULL )
343 { 360 {
344 regex_t *regex = g_malloc(sizeof(regex_t)); 361 regex_t *regex = g_malloc(sizeof(regex_t));
345 #if defined(USE_REGEX_PCRE) 362 #if defined(USE_REGEX_PCRE)
346 if ( regcomp( regex , words[i] , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) 363 if ( regcomp( regex , words[i] , REG_NOSUB | REG_UTF8 ) == 0 )
347 #else 364 #else
348 if ( regcomp( regex , words[i] , REG_NOSUB | REG_ICASE ) == 0 ) 365 if ( regcomp( regex , words[i] , REG_NOSUB ) == 0 )
349 #endif 366 #endif
350 regex_list = g_slist_append( regex_list , regex ); 367 regex_list = g_slist_append( regex_list , regex );
351 } 368 }
352 369
353 /* FIXME: Remove the connected signals before clearing 370 /* FIXME: Remove the connected signals before clearing
367 playlist_glist = g_list_next(playlist_glist)) 384 playlist_glist = g_list_next(playlist_glist))
368 { 385 {
369 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data); 386 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data);
370 gchar *title = NULL; 387 gchar *title = NULL;
371 388
372 if (entry->title) 389 if (entry->title) {
373 title = g_strdup(entry->title); 390 title = normalize_search_string(entry->title);
374 else { 391 } else {
375 gchar *realfn = NULL; 392 gchar *realfn = NULL;
376 realfn = g_filename_from_uri(entry->filename, NULL, NULL); 393 realfn = g_filename_from_uri(entry->filename, NULL, NULL);
377 title = str_to_utf8(realfn ? realfn : entry->filename); 394 gchar *tmp_title = str_to_utf8(realfn ? realfn : entry->filename);
395 title = normalize_search_string(tmp_title);
396 g_free(tmp_title);
378 g_free(realfn); realfn = NULL; 397 g_free(realfn); realfn = NULL;
379 } 398 }
380 399
381 /*we are matching all the path not just the filename or title*/ 400 /*we are matching all the path not just the filename or title*/
382 401
395 //g_print ("it passed\n"); 414 //g_print ("it passed\n");
396 if (regex_list != NULL) 415 if (regex_list != NULL)
397 match = ui_jump_to_track_match(title, regex_list); 416 match = ui_jump_to_track_match(title, regex_list);
398 else 417 else
399 match = TRUE; 418 match = TRUE;
419
420 g_free(title); title = NULL;
400 421
401 if (match) { 422 if (match) {
402 if (entry->title) 423 if (entry->title)
403 title = g_strdup(entry->title); 424 title = g_strdup(entry->title);
404 else { 425 else {