Commit 2d973ecf authored by Rémi Duraffort's avatar Rémi Duraffort

Add a function to get the Title and fallback to the name if the title is empty.

parent 673f8026
......@@ -138,6 +138,7 @@ VLC_EXPORT( void, input_item_SetMeta, ( input_item_t *, vlc_meta_type_t meta_typ
VLC_EXPORT( bool, input_item_MetaMatch, ( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz ) );
VLC_EXPORT( char *, input_item_GetMeta, ( input_item_t *p_i, vlc_meta_type_t meta_type ) );
VLC_EXPORT( char *, input_item_GetName, ( input_item_t * p_i ) );
VLC_EXPORT( char *, input_item_GetTitleFbName, ( input_item_t * p_i ) );
VLC_EXPORT( char *, input_item_GetURI, ( input_item_t * p_i ) );
VLC_EXPORT( void, input_item_SetURI, ( input_item_t * p_i, const char *psz_uri ));
VLC_EXPORT(mtime_t, input_item_GetDuration, ( input_item_t * p_i ) );
......
......@@ -265,20 +265,13 @@
if( [[o_tc identifier] isEqualToString:@"name"] )
{
/* sanity check to prevent the NSString class from crashing */
char *psz_title = input_item_GetTitle( p_item->p_input );
if( !EMPTY_STR( psz_title ) )
char *psz_title = input_item_GetTitleFbName( p_item->p_input );
if( psz_title )
{
o_value = [NSString stringWithUTF8String: psz_title];
}
else
{
char *psz_name = input_item_GetName( p_item->p_input );
if( psz_name )
o_value = [NSString stringWithUTF8String: psz_name];
free( psz_name );
}
free( psz_title );
}
}
else if( [[o_tc identifier] isEqualToString:@"artist"] )
{
char *psz_artist = input_item_GetArtist( p_item->p_input );
......
......@@ -2271,12 +2271,7 @@ static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
{
char *psz_display;
p_child = p_node->pp_children[k];
char *psz_name = input_item_GetTitle( p_child->p_input );
if( !psz_name || !*psz_name )
{
free( psz_name );
psz_name = input_item_GetName( p_child->p_input );
}
char *psz_name = input_item_GetTitleFbName( p_child->p_input );
if( c && *c )
{
......
......@@ -184,15 +184,14 @@ void MetaPanel::update( input_item_t *p_item )
free( psz_meta );
/* Name / Title */
psz_meta = input_item_GetTitle( p_item );
char *psz_name = input_item_GetName( p_item );
if( !EMPTY_STR( psz_meta ) )
psz_meta = input_item_GetTitleFbName( p_item );
if( psz_meta )
{
title_text->setText( qfu( psz_meta ) );
else if( !EMPTY_STR( psz_name ) )
title_text->setText( qfu( psz_name ) );
else title_text->setText( "" );
free( psz_meta );
free( psz_name );
}
else
title_text->setText( "" );
/* URL / URI */
psz_meta = input_item_GetURL( p_item );
......
......@@ -63,7 +63,6 @@ static const char * psz_column_title( uint32_t i_column )
* Returned value has to be freed */
static char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
{
char *psz;
int i_duration;
char psz_duration[MSTRTIME_MAX_SIZE];
switch( i_column )
......@@ -71,10 +70,7 @@ static char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
case COLUMN_NUMBER:
return NULL;
case COLUMN_TITLE:
psz = input_item_GetTitle( p_item );
if( !psz )
psz = input_item_GetName( p_item );
return psz;
return input_item_GetTitleFbName( p_item );
case COLUMN_DURATION:
i_duration = input_item_GetDuration( p_item ) / 1000000;
secstotimestr( psz_duration, i_duration );
......
......@@ -420,12 +420,7 @@ void InputManager::UpdateName()
QString text;
/* Try to get the Title, then the Name */
char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
if( EMPTY_STR( psz_name ) )
{
free( psz_name );
psz_name = input_item_GetName( input_GetItem( p_input ) );
}
char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
/* Try to get the nowplaying */
char *psz_nowplaying =
......
......@@ -571,8 +571,7 @@ static int WriteMeta( vlc_object_t *p_this )
// Saving all common fields
// If the title is empty, use the name
psz_meta = input_item_GetTitle( p_item );
if( !psz_meta ) psz_meta = input_item_GetName( p_item );
psz_meta = input_item_GetTitleFbName( p_item );
SET( Title, psz_meta );
free( psz_meta );
......
......@@ -180,18 +180,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
/* Playing something ... */
input_item_t *p_item = input_GetItem( p_input );
psz_title = input_item_GetTitle( p_item );
if( EMPTY_STR( psz_title ) )
{
free( psz_title );
psz_title = input_item_GetName( input_GetItem( p_input ) );
psz_title = input_item_GetTitleFbName( p_item );
if( EMPTY_STR( psz_title ) )
{
free( psz_title );
vlc_object_release( p_input );
return VLC_SUCCESS;
}
}
psz_artist = input_item_GetArtist( p_item );
if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
......
......@@ -142,18 +142,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
/* Playing something ... */
input_item_t *p_item = input_GetItem( p_input );
psz_title = input_item_GetTitle( p_item );
if( EMPTY_STR( psz_title ) )
{
free( psz_title );
psz_title = input_item_GetName( input_GetItem( p_input ) );
psz_title = input_item_GetTitleFbName( p_item );
if( EMPTY_STR( psz_title ) )
{
free( psz_title );
vlc_object_release( p_input );
return VLC_SUCCESS;
}
}
psz_artist = input_item_GetArtist( p_item );
if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
......
......@@ -158,11 +158,9 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
/* Playing something ... */
psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
psz_album = input_item_GetAlbum( input_GetItem( p_input ) );
psz_title = input_item_GetTitle( input_GetItem( p_input ) );
psz_title = input_item_GetTitleFbName( input_GetItem( p_input ) );
if( !psz_artist ) psz_artist = strdup( "" );
if( !psz_album ) psz_album = strdup( "" );
if( !psz_title )
psz_title = input_item_GetName( input_GetItem( p_input ) );
psz_buf = str_format_meta( p_this, p_intf->p_sys->psz_format );
......
......@@ -182,12 +182,8 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
input_item_t *p_input_item = input_GetItem( p_input );
psz_artist = input_item_GetArtist( p_input_item );
psz_album = input_item_GetAlbum( p_input_item );
psz_title = input_item_GetTitle( p_input_item );
if( EMPTY_STR( psz_title ) )
{
free( psz_title );
psz_title = input_item_GetName( p_input_item );
}
psz_title = input_item_GetTitleFbName( p_input_item );
if( EMPTY_STR( psz_title ) )
{ /* Not enough metadata ... */
free( psz_title );
......
......@@ -298,6 +298,28 @@ char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
return psz;
}
/* Get the title of a given item or fallback to the name if the title is empty */
char *input_item_GetTitleFbName( input_item_t *p_item )
{
char *psz_ret;
vlc_mutex_lock( &p_item->lock );
if( !p_item->p_meta )
{
vlc_mutex_unlock( &p_item->lock );
return NULL;
}
const char *psz_meta = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
if( !EMPTY_STR( psz_meta ) )
psz_ret = strdup( psz_meta );
else
psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
vlc_mutex_unlock( &p_item->lock );
return psz_ret;
}
char *input_item_GetName( input_item_t *p_item )
{
vlc_mutex_lock( &p_item->lock );
......
......@@ -181,6 +181,7 @@ input_item_GetDuration
input_item_GetInfo
input_item_GetMeta
input_item_GetName
input_item_GetTitleFbName
input_item_GetURI
input_item_HasErrorWhenReading
input_item_IsArtFetched
......
......@@ -119,10 +119,8 @@ static int playlist_cmp(const void *first, const void *second)
{
#define META_STRCASECMP_NAME( ) { \
char *psz_i = input_item_GetTitle( (*(playlist_item_t **)first)->p_input ); \
char *psz_ismall = input_item_GetTitle( (*(playlist_item_t **)second)->p_input ); \
if(EMPTY_STR(psz_i)) {free(psz_i); psz_i = input_item_GetName( (*(playlist_item_t **)first)->p_input ); }\
if(EMPTY_STR(psz_ismall)) {free(psz_ismall); psz_ismall = input_item_GetName( (*(playlist_item_t **)second)->p_input ); }\
char *psz_i = input_item_GetTitleFbName( (*(playlist_item_t **)first)->p_input ); \
char *psz_ismall = input_item_GetTitleFbName( (*(playlist_item_t **)second)->p_input ); \
if( psz_i != NULL && psz_ismall != NULL ) i_test = strcasecmp( psz_i, psz_ismall ); \
else if ( psz_i == NULL && psz_ismall != NULL ) i_test = 1; \
else if ( psz_ismall == NULL && psz_i != NULL ) i_test = -1; \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment