1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 #if defined(HAVE_ICONV)
31 #include "playlist.hpp"
32 #include "../utils/ustring.hpp"
36 Playlist::Playlist( intf_thread_t *pIntf ): VarList( pIntf )
38 // Get the playlist VLC object
39 m_pPlaylist = pIntf->p_sys->p_playlist;
42 // Try to guess the current charset
43 char *pCharset = (char*)malloc( 100 );
44 vlc_current_charset( &pCharset );
45 iconvHandle = iconv_open( "UTF-8", pCharset );
46 msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
49 if( iconvHandle == (iconv_t)-1 )
51 msg_Warn( pIntf, "Unable to do requested conversion" );
54 msg_Dbg( pIntf, "No iconv support available" );
64 if( iconvHandle != (iconv_t)-1 )
66 iconv_close( iconvHandle );
72 void Playlist::delSelected()
74 // Remove the items from the VLC playlist
77 for( it = begin(); it != end(); it++ )
79 if( (*it).m_selected )
81 playlist_Delete( m_pPlaylist, index );
93 void Playlist::action( Elem_t *pItem )
95 // Find the index of the item
98 for( it = begin(); it != end(); it++ )
100 if( &*it == pItem ) break;
106 playlist_Goto( m_pPlaylist, index );
111 void Playlist::onChange()
118 void Playlist::buildList()
122 vlc_mutex_lock( &m_pPlaylist->object_lock );
123 for( int i = 0; i < m_pPlaylist->i_size; i++ )
125 // Get the name of the playlist item
126 UString *pName = convertName( m_pPlaylist->pp_items[i]->input.psz_name );
127 // Is it the played stream ?
128 bool playing = (i == m_pPlaylist->i_index );
129 // Add the item in the list
130 m_list.push_back( Elem_t( UStringPtr( pName ), false, playing ) );
132 vlc_mutex_unlock( &m_pPlaylist->object_lock );
136 UString *Playlist::convertName( const char *pName )
139 if( iconvHandle == (iconv_t)-1 )
141 return new UString( getIntf(), pName );
144 char *pNewName, *pBufferOut;
145 const char *pBufferIn;
146 size_t ret, inbytesLeft, outbytesLeft;
148 // Try to convert the playlist item into UTF8
149 pNewName = (char*)malloc( 6 * strlen( pName ) );
150 pBufferOut = pNewName;
152 inbytesLeft = strlen( pName );
153 outbytesLeft = 6 * inbytesLeft;
154 // ICONV_CONST is defined in config.h
155 ret = iconv( iconvHandle, (ICONV_CONST char **)&pBufferIn, &inbytesLeft,
156 &pBufferOut, &outbytesLeft );
161 msg_Warn( getIntf(), "Failed to convert the playlist item into UTF8" );
163 return new UString( getIntf(), pName );
167 UString *pString = new UString( getIntf(), pNewName );
172 return new UString( getIntf(), pName );