]> git.sesse.net Git - vlc/commitdiff
Add a function to get the Title and fallback to the name if the title is empty.
authorRémi Duraffort <ivoire@videolan.org>
Sat, 25 Apr 2009 20:01:48 +0000 (22:01 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Sun, 26 Apr 2009 16:15:37 +0000 (18:15 +0200)
14 files changed:
include/vlc_input_item.h
modules/gui/macosx/playlist.m
modules/gui/ncurses.c
modules/gui/qt4/components/info_panels.cpp
modules/gui/qt4/components/playlist/sorting.h
modules/gui/qt4/input_manager.cpp
modules/meta_engine/taglib.cpp
modules/misc/notify/growl.m
modules/misc/notify/growl_udp.c
modules/misc/notify/msn.c
modules/misc/notify/notify.c
src/input/item.c
src/libvlccore.sym
src/playlist/sort.c

index 4ef4e7c256a002c7350dfa8347d7550537542598..4d6a83cd3f79ab921853db712cb0b9bed4af3a19 100644 (file)
@@ -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 ) );
index d01375d9adb4a5b5a3dc9650959a1cadf6b06b03..d777d4ae864edec3715a16ff20e41e0e32b23f9d 100644 (file)
     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"] )
     {
index 5c0d2a48c74647fd22fec14e7790e1cbe8f06c8a..709171597c9cf4da596c970070d40a9e0eacfc05 100644 (file)
@@ -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 )
         {
index 6287060a6738a79196f7dd68dc4e32b99349cb30..696a85227b17dbb63c301c23a9d6c4bec28fd3cf 100644 (file)
@@ -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 );
index bcbdf8c933603c3438707c8ff8118fa67b5d80e3..21e3f28bf9510e7eb4a4393e6b96fa7890418559 100644 (file)
@@ -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 );
index 52503540cae5d59ab0b08a54f278a9b4aef7e3a6..5ca2c006cabb9c0e2cde604e173c0c379297d02b 100644 (file)
@@ -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 =
index c5740aa068f066e6ade7b2e980c810f2384f4ef3..43ac6974601bcc17d14532159eae7902e7411f9c 100644 (file)
@@ -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 );
 
index c1b07eb27092e1ce877f272504a40e44b7de2394..19c890088ab9f8a15db3fe18b35c0d4f9e2efd41 100644 (file)
@@ -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 );
index 4f0387b694854074a5fad1b83f759c6d014d354e..3ef0e9e76addcca3951638e179b6ad6235e1df96 100644 (file)
@@ -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 );
index 67951bc692b8abe2f7cfc9731bca921a6ed43516..f177f1d0fd8e97e65aa9052db8744c3f381b5ebf 100644 (file)
@@ -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 );
 
index 1c1246acf1c13bd83c46a6923a9fd39ebda51142..6b3be7cb4197e1b9a9099dc111e22fb3fef87670 100644 (file)
@@ -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 );
index 8d6e12b4b503922123e105c374b44788b482cd02..864e84ae577bb555aa96e7836f21b746983494cf 100644 (file)
@@ -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 );
index 77a494c4d62e15f398f0116c641a9d2e8e3de5a0..f714221b346d0a20779ea9b40a82c784e786bb77 100644 (file)
@@ -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
index e9d1e43482f2b8ca16e8a047aad2b45718e6fb39..7b79606685442e68a80dd8d9ae8b401b38aec748 100644 (file)
@@ -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; \