From: RĂ©mi Duraffort Date: Sat, 25 Apr 2009 20:01:48 +0000 (+0200) Subject: Add a function to get the Title and fallback to the name if the title is empty. X-Git-Tag: 1.0.0-rc1~216 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=2d973ecfa0fae25f2b25fb824941b5ffba608c21;p=vlc Add a function to get the Title and fallback to the name if the title is empty. --- diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h index 4ef4e7c256..4d6a83cd3f 100644 --- a/include/vlc_input_item.h +++ b/include/vlc_input_item.h @@ -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 ) ); diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m index d01375d9ad..d777d4ae86 100644 --- a/modules/gui/macosx/playlist.m +++ b/modules/gui/macosx/playlist.m @@ -265,19 +265,12 @@ 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]; + free( 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"] ) { diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c index 5c0d2a48c7..709171597c 100644 --- a/modules/gui/ncurses.c +++ b/modules/gui/ncurses.c @@ -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 ) { diff --git a/modules/gui/qt4/components/info_panels.cpp b/modules/gui/qt4/components/info_panels.cpp index 6287060a67..696a85227b 100644 --- a/modules/gui/qt4/components/info_panels.cpp +++ b/modules/gui/qt4/components/info_panels.cpp @@ -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 ); + free( psz_meta ); + } + else + title_text->setText( "" ); /* URL / URI */ psz_meta = input_item_GetURL( p_item ); diff --git a/modules/gui/qt4/components/playlist/sorting.h b/modules/gui/qt4/components/playlist/sorting.h index bcbdf8c933..21e3f28bf9 100644 --- a/modules/gui/qt4/components/playlist/sorting.h +++ b/modules/gui/qt4/components/playlist/sorting.h @@ -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 ); diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp index 52503540ca..5ca2c006ca 100644 --- a/modules/gui/qt4/input_manager.cpp +++ b/modules/gui/qt4/input_manager.cpp @@ -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 = diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp index c5740aa068..43ac697460 100644 --- a/modules/meta_engine/taglib.cpp +++ b/modules/meta_engine/taglib.cpp @@ -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 ); diff --git a/modules/misc/notify/growl.m b/modules/misc/notify/growl.m index c1b07eb270..19c890088a 100644 --- a/modules/misc/notify/growl.m +++ b/modules/misc/notify/growl.m @@ -180,17 +180,12 @@ 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 ); + psz_title = input_item_GetTitleFbName( p_item ); if( EMPTY_STR( psz_title ) ) { free( psz_title ); - psz_title = input_item_GetName( input_GetItem( p_input ) ); - if( EMPTY_STR( psz_title ) ) - { - free( psz_title ); - vlc_object_release( p_input ); - return VLC_SUCCESS; - } + vlc_object_release( p_input ); + return VLC_SUCCESS; } psz_artist = input_item_GetArtist( p_item ); diff --git a/modules/misc/notify/growl_udp.c b/modules/misc/notify/growl_udp.c index 4f0387b694..3ef0e9e76a 100644 --- a/modules/misc/notify/growl_udp.c +++ b/modules/misc/notify/growl_udp.c @@ -142,17 +142,12 @@ 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 ); + psz_title = input_item_GetTitleFbName( p_item ); if( EMPTY_STR( psz_title ) ) { free( psz_title ); - psz_title = input_item_GetName( input_GetItem( p_input ) ); - if( EMPTY_STR( psz_title ) ) - { - free( psz_title ); - vlc_object_release( p_input ); - return VLC_SUCCESS; - } + vlc_object_release( p_input ); + return VLC_SUCCESS; } psz_artist = input_item_GetArtist( p_item ); diff --git a/modules/misc/notify/msn.c b/modules/misc/notify/msn.c index 67951bc692..f177f1d0fd 100644 --- a/modules/misc/notify/msn.c +++ b/modules/misc/notify/msn.c @@ -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 ); diff --git a/modules/misc/notify/notify.c b/modules/misc/notify/notify.c index 1c1246acf1..6b3be7cb41 100644 --- a/modules/misc/notify/notify.c +++ b/modules/misc/notify/notify.c @@ -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 ); diff --git a/src/input/item.c b/src/input/item.c index 8d6e12b4b5..864e84ae57 100644 --- a/src/input/item.c +++ b/src/input/item.c @@ -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 ); diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 77a494c4d6..f714221b34 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -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 diff --git a/src/playlist/sort.c b/src/playlist/sort.c index e9d1e43482..7b79606685 100644 --- a/src/playlist/sort.c +++ b/src/playlist/sort.c @@ -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; \