comparison src/audacious/playlist.c @ 3863:dd5c459c5f2d

fix search and select. (bugzilla #29)
author William Pitcock <nenolod@atheme.org>
date Sun, 28 Oct 2007 09:19:29 -0500
parents 2c92b8947057
children e48f2f4c116d
comparison
equal deleted inserted replaced
3862:39bbef13fa41 3863:dd5c459c5f2d
2975 { 2975 {
2976 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; 2976 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL;
2977 gboolean is_first_search = TRUE; 2977 gboolean is_first_search = TRUE;
2978 gint num_of_entries_found = 0; 2978 gint num_of_entries_found = 0;
2979 const gchar *regex_pattern; 2979 const gchar *regex_pattern;
2980 const gchar *track_name = tuple_get_string( tuple, FIELD_TITLE, NULL ); 2980 const gchar *track_name;
2981 const gchar *album_name = tuple_get_string( tuple, FIELD_ALBUM, NULL ); 2981 const gchar *album_name;
2982 const gchar *performer = tuple_get_string( tuple, FIELD_PERFORMER, NULL ); 2982 const gchar *performer;
2983 const gchar *file_name = tuple_get_string( tuple, FIELD_FILE_NAME, NULL ); 2983 const gchar *file_name;
2984 2984
2985 #if defined(USE_REGEX_ONIGURUMA) 2985 #if defined(USE_REGEX_ONIGURUMA)
2986 /* set encoding for Oniguruma regex to UTF-8 */ 2986 /* set encoding for Oniguruma regex to UTF-8 */
2987 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); 2987 reg_set_encoding( REG_POSIX_ENCODING_UTF8 );
2988 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); 2988 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC );
2989 #endif 2989 #endif
2990 2990
2991 PLAYLIST_LOCK(playlist); 2991 PLAYLIST_LOCK(playlist);
2992 2992
2993 if ( (regex_pattern = tuple_get_string(tuple, FIELD_TITLE, NULL)) != NULL ) 2993 if ( (regex_pattern = tuple_get_string(tuple, FIELD_TITLE, NULL)) != NULL &&
2994 (*regex_pattern != '\0') )
2994 { 2995 {
2995 /* match by track_name */ 2996 /* match by track_name */
2996 regex_t regex; 2997 regex_t regex;
2997 #if defined(USE_REGEX_PCRE) 2998 #if defined(USE_REGEX_PCRE)
2998 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) 2999 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 )
3004 if ( is_first_search == TRUE ) entry_list = playlist->entries; 3005 if ( is_first_search == TRUE ) entry_list = playlist->entries;
3005 else entry_list = found_list; /* use found_list */ 3006 else entry_list = found_list; /* use found_list */
3006 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) 3007 for ( ; entry_list ; entry_list = g_list_next(entry_list) )
3007 { 3008 {
3008 PlaylistEntry *entry = entry_list->data; 3009 PlaylistEntry *entry = entry_list->data;
3009 if ( ( entry->tuple != NULL ) && ( track_name != NULL ) && 3010 if ( entry->tuple != NULL )
3010 ( regexec( &regex , track_name , 0 , NULL , 0 ) == 0 ) )
3011 { 3011 {
3012 tfound_list = g_list_append( tfound_list , entry ); 3012 track_name = tuple_get_string( entry->tuple, FIELD_TITLE, NULL );
3013 if (( track_name != NULL ) &&
3014 ( regexec( &regex , track_name , 0 , NULL , 0 ) == 0 ) )
3015 {
3016 tfound_list = g_list_append( tfound_list , entry );
3017 }
3013 } 3018 }
3014 } 3019 }
3015 g_list_free( found_list ); /* wipe old found_list */ 3020 g_list_free( found_list ); /* wipe old found_list */
3016 found_list = tfound_list; /* move tfound_list in found_list */ 3021 found_list = tfound_list; /* move tfound_list in found_list */
3017 regfree( &regex ); 3022 regfree( &regex );
3018 } 3023 }
3019 is_first_search = FALSE; 3024 is_first_search = FALSE;
3020 } 3025 }
3021 3026
3022 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ALBUM, NULL)) != NULL ) 3027 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ALBUM, NULL)) != NULL &&
3028 (*regex_pattern != '\0') )
3023 { 3029 {
3024 /* match by album_name */ 3030 /* match by album_name */
3025 regex_t regex; 3031 regex_t regex;
3026 #if defined(USE_REGEX_PCRE) 3032 #if defined(USE_REGEX_PCRE)
3027 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) 3033 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 )
3033 if ( is_first_search == TRUE ) entry_list = playlist->entries; 3039 if ( is_first_search == TRUE ) entry_list = playlist->entries;
3034 else entry_list = found_list; /* use found_list */ 3040 else entry_list = found_list; /* use found_list */
3035 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) 3041 for ( ; entry_list ; entry_list = g_list_next(entry_list) )
3036 { 3042 {
3037 PlaylistEntry *entry = entry_list->data; 3043 PlaylistEntry *entry = entry_list->data;
3038 if ( ( entry->tuple != NULL ) && ( album_name != NULL ) && 3044 if ( entry->tuple != NULL )
3039 ( regexec( &regex , album_name , 0 , NULL , 0 ) == 0 ) )
3040 { 3045 {
3041 tfound_list = g_list_append( tfound_list , entry ); 3046 album_name = tuple_get_string( entry->tuple, FIELD_ALBUM, NULL );
3047 if ( ( album_name != NULL ) &&
3048 ( regexec( &regex , album_name , 0 , NULL , 0 ) == 0 ) )
3049 {
3050 tfound_list = g_list_append( tfound_list , entry );
3051 }
3042 } 3052 }
3043 } 3053 }
3044 g_list_free( found_list ); /* wipe old found_list */ 3054 g_list_free( found_list ); /* wipe old found_list */
3045 found_list = tfound_list; /* move tfound_list in found_list */ 3055 found_list = tfound_list; /* move tfound_list in found_list */
3046 regfree( &regex ); 3056 regfree( &regex );
3047 } 3057 }
3048 is_first_search = FALSE; 3058 is_first_search = FALSE;
3049 } 3059 }
3050 3060
3051 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ARTIST, NULL)) != NULL ) 3061 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ARTIST, NULL)) != NULL &&
3062 (*regex_pattern != '\0') )
3052 { 3063 {
3053 /* match by performer */ 3064 /* match by performer */
3054 regex_t regex; 3065 regex_t regex;
3055 #if defined(USE_REGEX_PCRE) 3066 #if defined(USE_REGEX_PCRE)
3056 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) 3067 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 )
3062 if ( is_first_search == TRUE ) entry_list = playlist->entries; 3073 if ( is_first_search == TRUE ) entry_list = playlist->entries;
3063 else entry_list = found_list; /* use found_list */ 3074 else entry_list = found_list; /* use found_list */
3064 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) 3075 for ( ; entry_list ; entry_list = g_list_next(entry_list) )
3065 { 3076 {
3066 PlaylistEntry *entry = entry_list->data; 3077 PlaylistEntry *entry = entry_list->data;
3067 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && 3078 if ( entry->tuple != NULL )
3068 ( regexec( &regex , performer , 0 , NULL , 0 ) == 0 ) )
3069 { 3079 {
3070 tfound_list = g_list_append( tfound_list , entry ); 3080 performer = tuple_get_string( entry->tuple, FIELD_ARTIST, NULL );
3081 if ( ( entry->tuple != NULL ) && ( performer != NULL ) &&
3082 ( regexec( &regex , performer , 0 , NULL , 0 ) == 0 ) )
3083 {
3084 tfound_list = g_list_append( tfound_list , entry );
3085 }
3071 } 3086 }
3072 } 3087 }
3073 g_list_free( found_list ); /* wipe old found_list */ 3088 g_list_free( found_list ); /* wipe old found_list */
3074 found_list = tfound_list; /* move tfound_list in found_list */ 3089 found_list = tfound_list; /* move tfound_list in found_list */
3075 regfree( &regex ); 3090 regfree( &regex );
3076 } 3091 }
3077 is_first_search = FALSE; 3092 is_first_search = FALSE;
3078 } 3093 }
3079 3094
3080 if ( (regex_pattern = tuple_get_string(tuple, FIELD_FILE_NAME, NULL)) != NULL ) 3095 if ( (regex_pattern = tuple_get_string(tuple, FIELD_FILE_NAME, NULL)) != NULL &&
3096 (*regex_pattern != '\0') )
3081 { 3097 {
3082 /* match by file_name */ 3098 /* match by file_name */
3083 regex_t regex; 3099 regex_t regex;
3084 #if defined(USE_REGEX_PCRE) 3100 #if defined(USE_REGEX_PCRE)
3085 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) 3101 if ( regcomp( &regex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 )
3091 if ( is_first_search == TRUE ) entry_list = playlist->entries; 3107 if ( is_first_search == TRUE ) entry_list = playlist->entries;
3092 else entry_list = found_list; /* use found_list */ 3108 else entry_list = found_list; /* use found_list */
3093 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) 3109 for ( ; entry_list ; entry_list = g_list_next(entry_list) )
3094 { 3110 {
3095 PlaylistEntry *entry = entry_list->data; 3111 PlaylistEntry *entry = entry_list->data;
3096 if ( ( entry->tuple != NULL ) && ( file_name != NULL ) && 3112 if ( entry->tuple != NULL )
3097 ( regexec( &regex , file_name , 0 , NULL , 0 ) == 0 ) )
3098 { 3113 {
3099 tfound_list = g_list_append( tfound_list , entry ); 3114 file_name = tuple_get_string( entry->tuple, FIELD_FILE_NAME, NULL );
3115 if ( ( file_name != NULL ) &&
3116 ( regexec( &regex , file_name , 0 , NULL , 0 ) == 0 ) )
3117 {
3118 tfound_list = g_list_append( tfound_list , entry );
3119 }
3100 } 3120 }
3101 } 3121 }
3102 g_list_free( found_list ); /* wipe old found_list */ 3122 g_list_free( found_list ); /* wipe old found_list */
3103 found_list = tfound_list; /* move tfound_list in found_list */ 3123 found_list = tfound_list; /* move tfound_list in found_list */
3104 regfree( &regex ); 3124 regfree( &regex );