If http-use-IE-proxy is enable, use Internet Explorer entered HTTP proxy server confi...
[vlc.git] / src / playlist / search.c
blob8de86c67a3befa81197bc03847ee352b8108dfaf
1 /*****************************************************************************
2 * search.c : Search functions
3 *****************************************************************************
4 * Copyright (C) 1999-2009 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26 #include <assert.h>
28 #include <vlc_common.h>
29 #include "vlc_playlist.h"
30 #include "playlist_internal.h"
32 /***************************************************************************
33 * Item search functions
34 ***************************************************************************/
36 /**
37 * Search a playlist item by its playlist_item id.
38 * The playlist have to be locked
39 * @param p_playlist: the playlist
40 * @param i_id: the id to find
41 * @return the item or NULL on failure
43 playlist_item_t* playlist_ItemGetById( playlist_t * p_playlist , int i_id )
45 int i;
46 PL_ASSERT_LOCKED;
47 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
48 if( i != -1 )
49 return ARRAY_VAL( p_playlist->all_items, i );
50 else
51 return NULL;
54 /**
55 * Search an item by its input_item_t
56 * The playlist have to be locked
57 * @param p_playlist: the playlist
58 * @param p_item: the input_item_t to find
59 * @return the item, or NULL on failure
61 playlist_item_t* playlist_ItemGetByInput( playlist_t * p_playlist,
62 input_item_t *p_item )
64 int i;
65 PL_ASSERT_LOCKED;
66 if( get_current_status_item( p_playlist ) &&
67 get_current_status_item( p_playlist )->p_input == p_item )
69 return get_current_status_item( p_playlist );
71 /** \todo Check if this is always incremental and whether we can bsearch */
72 for( i = 0 ; i < p_playlist->all_items.i_size; i++ )
74 if( ARRAY_VAL(p_playlist->all_items, i)->p_input == p_item )
76 return ARRAY_VAL(p_playlist->all_items, i);
79 return NULL;
83 /***************************************************************************
84 * Live search handling
85 ***************************************************************************/
87 /**
88 * Enable all items in the playlist
89 * @param p_root: the current root item
91 static void playlist_LiveSearchClean( playlist_item_t *p_root )
93 for( int i = 0; i < p_root->i_children; i++ )
95 playlist_item_t *p_item = p_root->pp_children[i];
96 if( p_item->i_children >= 0 )
97 playlist_LiveSearchClean( p_item );
98 p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
104 * Enable/Disable items in the playlist according to the search argument
105 * @param p_root: the current root item
106 * @param psz_string: the string to search
107 * @return true if an item match
109 static bool playlist_LiveSearchUpdateInternal( playlist_item_t *p_root,
110 const char *psz_string )
112 int i;
113 bool b_match = false;
114 for( i = 0 ; i < p_root->i_children ; i ++ )
116 bool b_enable = false;
117 playlist_item_t *p_item = p_root->pp_children[i];
118 // Go recurssively if their is some children
119 if( p_item->i_children >= 0 &&
120 playlist_LiveSearchUpdateInternal( p_item, psz_string ) )
122 b_enable = true;
125 if( !b_enable )
127 vlc_mutex_lock( &p_item->p_input->lock );
128 // Do we have some meta ?
129 if( p_item->p_input->p_meta )
131 // Use Title or fall back to psz_name
132 const char *psz_title = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Title );
133 if( !psz_title )
134 psz_title = p_item->p_input->psz_name;
135 const char *psz_album = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Album );
136 const char *psz_artist = vlc_meta_Get( p_item->p_input->p_meta, vlc_meta_Artist );
137 b_enable = ( psz_title && strcasestr( psz_title, psz_string ) ) ||
138 ( psz_album && strcasestr( psz_album, psz_string ) ) ||
139 ( psz_artist && strcasestr( psz_artist, psz_string ) );
141 else
142 b_enable = p_item->p_input->psz_name && strcasestr( p_item->p_input->psz_name, psz_string );
143 vlc_mutex_unlock( &p_item->p_input->lock );
146 if( b_enable )
147 p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
148 else
149 p_item->i_flags |= PLAYLIST_DBL_FLAG;
151 b_match |= b_enable;
153 return b_match;
159 * Launch the recursive search in the playlist
160 * @param p_playlist: the playlist
161 * @param p_root: the current root item
162 * @param psz_string: the string to find
163 * @return VLC_SUCCESS
165 int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
166 const char *psz_string )
168 PL_ASSERT_LOCKED;
169 pl_priv(p_playlist)->b_reset_currently_playing = true;
170 if( *psz_string )
171 playlist_LiveSearchUpdateInternal( p_root, psz_string );
172 else
173 playlist_LiveSearchClean( p_root );
174 vlc_cond_signal( &pl_priv(p_playlist)->signal );
175 return VLC_SUCCESS;