]> git.sesse.net Git - vlc/commitdiff
Use VLC object for meta writer and factor code
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 23 Aug 2009 17:15:39 +0000 (20:15 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 23 Aug 2009 17:17:21 +0000 (20:17 +0300)
include/vlc_common.h
include/vlc_meta.h
modules/gui/macosx/playlistinfo.m
modules/gui/qt4/components/info_panels.cpp
modules/meta_engine/taglib.cpp
src/input/meta.c
src/libvlccore.sym

index 488057fdda5a68d92d637ff52d90a0012dbda19c..f7f45a86cd1b2e8d8b9b0793fbe5b2c354f3cf4c 100644 (file)
@@ -342,9 +342,8 @@ typedef struct osd_menu_state_t osd_menu_state_t;
 typedef struct vlm_t         vlm_t;
 typedef struct vlm_message_t vlm_message_t;
 
-/* divers */
+/* misc */
 typedef struct vlc_meta_t    vlc_meta_t;
-typedef struct meta_export_t meta_export_t;
 
 /* Stats */
 typedef struct counter_t     counter_t;
index e5b11b89d3dc285769769d641aa4416da1086b5a..11c03693d4d0e5087985b27824c08380b4038b2d 100644 (file)
@@ -195,10 +195,13 @@ enum {
     ALBUM_ART_ALL
 };
 
-struct meta_export_t
+typedef struct meta_export_t
 {
+    VLC_COMMON_MEMBERS
     input_item_t *p_item;
     const char *psz_file;
-};
+} meta_export_t;
+
+VLC_EXPORT( int, input_item_WriteMeta, (vlc_object_t *, input_item_t *) );
 
 #endif
index dc316dcb31fded7b85182607b7a7131494cbda90..fc902b5e2b34c0e79b17255d3076629af514864b 100644 (file)
@@ -368,29 +368,8 @@ static VLCInfo *_o_sharedInstance = nil;
 
 - (IBAction)saveMetaData:(id)sender
 {
-    playlist_t * p_playlist = pl_Hold( VLCIntf );
-
     if( !p_item ) goto error;
 
-    meta_export_t p_export;
-    p_export.p_item = p_item;
-
-    /* we can write meta data only in a file */
-    vlc_mutex_lock( &p_item->lock );
-    int i_type = p_item->i_type;
-    vlc_mutex_unlock( &p_item->lock );
-
-    if( i_type != ITEM_TYPE_FILE )
-        goto error;
-
-    char *psz_uri_orig = input_item_GetURI( p_item );
-    char *psz_uri = psz_uri_orig;
-    if( !strncmp( psz_uri, "file://", 7 ) )
-        psz_uri += 7; /* strlen("file://") = 7 */
-
-    p_export.psz_file = strndup( psz_uri, PATH_MAX );
-    free( psz_uri_orig );
-
     #define utf8( o_blub ) \
         [[o_blub stringValue] UTF8String]
 
@@ -406,13 +385,8 @@ static VLCInfo *_o_sharedInstance = nil;
     input_item_SetDescription( p_item, utf8( o_description_txt ) );
     input_item_SetLanguage( p_item, utf8( o_language_txt ) );
 
-    PL_LOCK;
-    p_playlist->p_private = &p_export;
-
-    module_t *p_mod = module_need( p_playlist, "meta writer", NULL, false );
-    if( p_mod )
-        module_unneed( p_playlist, p_mod );
-    PL_UNLOCK;
+    playlist_t * p_playlist = pl_Hold( VLCIntf );
+    input_item_WriteMeta( p_playlist, p_item );
 
     var_SetBool( p_playlist, "intf-change", true );
     [self updatePanelWithItem: p_item];
@@ -422,7 +396,6 @@ static VLCInfo *_o_sharedInstance = nil;
     return;
 
 error:
-    pl_Release( VLCIntf );
     NSRunAlertPanel(_NS("Error while saving meta"),
         _NS("VLC was unable to save the meta data."),
         _NS("OK"), nil, nil);
index 2ac9e5abb8cfc8f736d77af859a1f152a19e9fbe..7edf3b7c6b95e4274f8ba84da5368703b68843a4 100644 (file)
@@ -249,31 +249,9 @@ void MetaPanel::update( input_item_t *p_item )
  **/
 void MetaPanel::saveMeta()
 {
-    playlist_t *p_playlist;
-
-    meta_export_t p_export;
-    p_export.p_item = p_input;
-
     if( p_input == NULL )
         return;
 
-    /* we can write meta data only in a file */
-    vlc_mutex_lock( &p_input->lock );
-    int i_type = p_input->i_type;
-    vlc_mutex_unlock( &p_input->lock );
-    if( i_type == ITEM_TYPE_FILE )
-    {
-        char *psz_uri_orig = input_item_GetURI( p_input );
-        char *psz_uri = psz_uri_orig;
-        if( !strncmp( psz_uri, "file://", 7 ) )
-            psz_uri += 7; /* strlen("file://") = 7 */
-
-        p_export.psz_file = strndup( psz_uri, PATH_MAX );
-        free( psz_uri_orig );
-    }
-    else
-        return;
-
     /* now we read the modified meta data */
     input_item_SetTitle(  p_input, qtu( title_text->text() ) );
     input_item_SetArtist( p_input, qtu( artist_text->text() ) );
@@ -286,14 +264,8 @@ void MetaPanel::saveMeta()
     input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
     input_item_SetDescription( p_input, qtu( description_text->text() ) );
 
-    p_playlist = pl_Hold( p_intf );
-    PL_LOCK;
-    p_playlist->p_private = &p_export;
-
-    module_t *p_mod = module_need( p_playlist, "meta writer", NULL, false );
-    if( p_mod )
-        module_unneed( p_playlist, p_mod );
-    PL_UNLOCK;
+    playlist_t *p_playlist = pl_Hold( p_intf );
+    input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
     pl_Release( p_intf );
 
     /* Reset the status of the mode. No need to emit any signal because parent
index 724fcfc50df0672ac7baa709f7c6588a7c45d50e..c499b51b41488a840e32ada08e322d5e52b3468b 100644 (file)
@@ -514,8 +514,7 @@ static void WriteMetaToXiph( Ogg::XiphComment* tag, input_item_t* p_item )
 
 static int WriteMeta( vlc_object_t *p_this )
 {
-    playlist_t *p_playlist = (playlist_t *)p_this;
-    meta_export_t *p_export = (meta_export_t *)p_playlist->p_private;
+    meta_export_t *p_export = (meta_export_t *)p_this;
     input_item_t *p_item = p_export->p_item;
     FileRef f;
 
index ad97c296753d4eba7885cad125eba49b0c1cb568..77dfae3529447cadec492b4c0267eca5742462ea 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <vlc_common.h>
 #include <vlc_playlist.h>
+#include <vlc_url.h>
+
 #include "input_internal.h"
 #include "../playlist/art.h"
 
@@ -129,3 +131,44 @@ exit:
     free( psz_arturl );
 }
 
+int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item )
+{
+    meta_export_t *p_export =
+        vlc_custom_create( obj, sizeof( *p_export ), VLC_OBJECT_GENERIC,
+                           "meta writer" );
+    if( p_export == NULL )
+        return VLC_ENOMEM;
+    vlc_object_attach( p_export, obj );
+    p_export->p_item = p_item;
+
+    int type;
+    vlc_mutex_lock( &p_item->lock );
+    type = p_item->i_type;
+    vlc_mutex_unlock( &p_item->lock );
+    if( type != ITEM_TYPE_FILE )
+    {
+        char *psz_uri = input_item_GetURI( p_item );
+
+#warning FIXME: function for URI->path conversion!
+        decode_URI( psz_uri );
+        if( !strncmp( psz_uri, "file://", 7 ) )
+        {
+            p_export->psz_file = strdup( psz_uri + 7 );
+            free( psz_uri );
+        }
+        else
+#warning This should not happen!
+            p_export->psz_file = psz_uri;
+    }
+    else
+    {
+        vlc_object_release( p_export );
+        return VLC_EGENERIC;
+    }
+
+    module_t *p_mod = module_need( p_export, "meta writer", NULL, false );
+    if( p_mod )
+        module_unneed( p_export, p_mod );
+    vlc_object_release( p_export );
+    return VLC_SUCCESS;
+}
index b50040270826d7ed782ae094581419d45d8ef280..5d40e4af7ccc5b377857432661c0d6d6b35404a5 100644 (file)
@@ -205,6 +205,7 @@ input_item_SetDuration
 input_item_SetMeta
 input_item_SetName
 input_item_SetURI
+input_item_WriteMeta
 input_MetaTypeToLocalizedString
 __input_Read
 input_SplitMRL