]> git.sesse.net Git - vlc/commitdiff
* wx : simplify some code, remove some useless duplications
authorClément Stenac <zorglub@videolan.org>
Sun, 6 Feb 2005 12:05:43 +0000 (12:05 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 6 Feb 2005 12:05:43 +0000 (12:05 +0000)
       hopefully prevent deadlocks

* API : add the b_force parameter to playlist_NodeDelete. If TRUE, nodes that are marked as read-only will also be deleted. Use with care.

* SAP/DAAP : Ensure that the  node gets removed on quit
* HAL : Remove the node on quit and fix f**age of the Close function

include/vlc_playlist.h
modules/gui/macosx/playlist.m
modules/gui/wxwindows/playlist.cpp
modules/gui/wxwindows/wxwindows.h
modules/services_discovery/daap.c
modules/services_discovery/hal.c
modules/services_discovery/sap.c
src/playlist/view.c

index 96084b95fffd07e9985db29afaf26b72d3f73d52..ca864aa36cbd7ee5d2661485a42be1a34ce1b01c 100644 (file)
@@ -288,7 +288,7 @@ VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,int,playlist_item_t*,playlis
 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
-VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
+VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
 
 /* Tree walking */
index 6c2225b699524feeb6b4cbdfe32d3bafa95c45d6..d25fc93b56c08f7580e728b4b4e4b66677732373 100644 (file)
@@ -490,7 +490,7 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
                 // if current item is in selected node and is playing then stop playlist
                 playlist_Stop( p_playlist );
             }
-            playlist_NodeDelete( p_playlist, p_item, VLC_TRUE);
+            playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
         }
         else
         {
index 82ffded19187c473821edcfdad494d9b59617f56..daa6d4170cb7fb83307b0ae737cb7557ee82c379 100644 (file)
@@ -379,8 +379,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 
     p_saved_item = NULL;
 
-    /* Update the playlist */
-    Rebuild();
 
     /* We want to be noticed of playlist changes */
 
@@ -396,9 +394,10 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     var_AddCallback( p_playlist, "item-append", ItemAppended, this );
     var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
 
-    vlc_object_release( p_playlist );
-
+    /* Update the playlist */
+    Rebuild();
 
+    vlc_object_release( p_playlist );
 }
 
 Playlist::~Playlist()
@@ -484,9 +483,6 @@ void Playlist::UpdateNodeChildren( playlist_t *p_playlist,
                            new PlaylistItem( p_node->pp_children[i]) );
 
             UpdateTreeItem( p_playlist, item );
-
-            treectrl->SetItemImage( item,
-                                    p_node->pp_children[i]->input.i_type );
         }
         else
         {
@@ -496,19 +492,11 @@ void Playlist::UpdateNodeChildren( playlist_t *p_playlist,
     }
 }
 
-/* Set current item */
-void Playlist::SetCurrentItem( wxTreeItemId item )
-{
-    if( item.IsOk() )
-    {
-        treectrl->SetItemBold( item, true );
-        treectrl->EnsureVisible( item );
-    }
-}
-
 /* Update an item in the tree */
 void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
 {
+    if( ! item.IsOk() ) return;
+
     playlist_item_t *p_item  =
             ((PlaylistItem *)treectrl->GetItemData( item ))->p_item;
 
@@ -546,7 +534,8 @@ void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
 
     if( p_playlist->status.p_item == p_item )
     {
-        SetCurrentItem( item );
+        treectrl->SetItemBold( item, true );
+        treectrl->EnsureVisible( item );
     }
     else
     {
@@ -676,7 +665,7 @@ wxTreeItemId Playlist::FindItem( wxTreeItemId root, playlist_item_t *p_item )
 
     p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
 
-    if( !p_item )
+    if( !p_item || !p_wxcurrent )
     {
         wxTreeItemId dummy;
         return dummy;
@@ -833,6 +822,15 @@ void Playlist::Rebuild()
     {
         return;
     }
+
+    /* We can remove the callbacks before locking, anyway, we won't
+     * miss anything */
+    var_DelCallback( p_playlist, "item-change", ItemChanged, this );
+    var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
+    var_DelCallback( p_playlist, "item-append", ItemAppended, this );
+    var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
+
     /* ...and rebuild it */
     vlc_mutex_lock( &p_playlist->object_lock );
 
@@ -847,6 +845,7 @@ void Playlist::Rebuild()
     wxTreeItemId root = treectrl->GetRootItem();
     UpdateNode( p_playlist, p_view->p_root, root );
 
+/*
     wxTreeItemId item;
     if( p_playlist->status.p_item != NULL )
     {
@@ -865,7 +864,7 @@ void Playlist::Rebuild()
     {
         SetCurrentItem( item );
     }
-
+*/
     int i_count = CountItems( treectrl->GetRootItem() );
 
     if( i_count < p_playlist->i_size && !b_changed_view )
@@ -890,6 +889,13 @@ void Playlist::Rebuild()
                                   p_playlist->i_size ), 0 );
     }
 
+    /* Put callbacks back online */
+    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
+    var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    var_AddCallback( p_playlist, "item-change", ItemChanged, this );
+    var_AddCallback( p_playlist, "item-append", ItemAppended, this );
+    var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
+
     vlc_mutex_unlock( &p_playlist->object_lock );
 
     vlc_object_release( p_playlist );
@@ -959,7 +965,7 @@ void Playlist::DeleteNode( playlist_item_t *p_item )
         return;
     }
 
-    playlist_NodeDelete( p_playlist, p_item, VLC_TRUE );
+    playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
 
     vlc_object_release( p_playlist );
 }
@@ -1334,8 +1340,10 @@ void Playlist::OnMenuEvent( wxCommandEvent& event )
         }
         else
         {
+            wxMutexGuiLeave();
             playlist_ServicesDiscoveryRemove( p_playlist,
                             pp_sds[event.GetId() - FirstSD_Event] );
+            wxMutexGuiEnter();
         }
     }
     vlc_object_release( p_playlist );
index 1bdbe37cb8bc8d09b30934e421ee6da0f7fbec0c..9412928556d8ebf0b05708db3da4c2cae8f7f1e4 100644 (file)
@@ -874,7 +874,6 @@ private:
     void UpdateNodeChildren( playlist_t *, playlist_item_t*, wxTreeItemId );
     void CreateNode( playlist_t *, playlist_item_t*, wxTreeItemId );
     void UpdateTreeItem( playlist_t *, wxTreeItemId );
-    void SetCurrentItem( wxTreeItemId );
 
     /* Search (internal) */
     int CountItems( wxTreeItemId);
index 02b00e31a2b72e596b8f2d78726b5d7462077b63..c5e98a3726752786f84ab8437e66c2f79b690b97 100644 (file)
@@ -321,7 +321,7 @@ static void Close( vlc_object_t *p_this )
 
     if( p_playlist )
     {
-        playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE );
+        playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
         vlc_object_release( p_playlist );
     }
 
index 3f595b0e2892ab20756165577c185f175592c6f9..d613e796b516ce64bd1e546fe103f5064a302e9c 100644 (file)
@@ -99,6 +99,7 @@ static int Open( vlc_object_t *p_this )
     services_discovery_sys_t *p_sys  = malloc(
                                     sizeof( services_discovery_sys_t ) );
 
+    vlc_value_t         val;
     playlist_t          *p_playlist;
     playlist_view_t     *p_view;
 
@@ -124,6 +125,11 @@ static int Open( vlc_object_t *p_this )
     p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
     p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
                                          _("Devices"), p_view->p_root );
+
+    p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
+    val.b_bool = VLC_TRUE;
+    var_Set( p_playlist, "intf-change", val );
+
     vlc_object_release( p_playlist );
 
     return VLC_SUCCESS;
@@ -134,9 +140,15 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-    services_discovery_t *p_sd = ( services_discovery_t* )p_sd;
-    services_discovery_sys_t *p_sys  = malloc(
-                                         sizeof( services_discovery_sys_t ) );
+    services_discovery_t *p_sd = ( services_discovery_t* )p_this;
+    services_discovery_sys_t *p_sys  = p_sd->p_sys;
+    playlist_t *p_playlist =  (playlist_t *) vlc_object_find( p_sd,
+                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    if( p_playlist )
+    {
+        playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
+        vlc_object_release( p_playlist );
+    }
     free( p_sys );
 }
 
index ee8fcbe398a5b7d4dfdaeeb1f3fae52cc28dca20..8da1179e8b15ca29f3f944b2416a84a46140cf26 100644 (file)
@@ -481,7 +481,7 @@ static void Close( vlc_object_t *p_this )
 
     if( p_playlist )
     {
-        playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE );
+        playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE , VLC_TRUE );
         vlc_object_release( p_playlist );
     }
 
index 71554547bfbc1ebab7476b216854743ad24a0011..49bb08199d00cb69f887be241e8fe8df02149f0a 100644 (file)
@@ -54,11 +54,6 @@ playlist_item_t *playlist_RecursiveFindPrev( playlist_t *p_playlist,
 void playlist_NodeDump( playlist_t *p_playlist, playlist_item_t *p_item,
                         int i_level );
 
-int playlist_NodeDeleteInternal( playlist_t *p_playlist,
-                                 playlist_item_t *p_root,
-                                 vlc_bool_t b_delete_items, vlc_bool_t b_force );
-
-
 /**********************************************************************
  * Exported View management functions
  **********************************************************************/
@@ -127,8 +122,7 @@ int playlist_ViewInsert( playlist_t *p_playlist, int i_id, char *psz_name )
  */
 int playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view )
 {
-    playlist_NodeDeleteInternal( p_playlist, p_view->p_root, VLC_TRUE,
-                                 VLC_TRUE );
+    playlist_NodeDelete( p_playlist, p_view->p_root, VLC_TRUE, VLC_TRUE );
     REMOVE_ELEM( p_playlist->pp_views, p_playlist->i_views, 0 );
     return VLC_SUCCESS;
 }
@@ -338,7 +332,7 @@ int playlist_NodeEmpty( playlist_t *p_playlist, playlist_item_t *p_root,
         if( p_root->pp_children[i]->i_children > -1 )
         {
             playlist_NodeDelete( p_playlist, p_root->pp_children[i],
-                                 b_delete_items );
+                                 b_delete_items , VLC_FALSE );
         }
         else if( b_delete_items )
         {
@@ -358,15 +352,7 @@ int playlist_NodeEmpty( playlist_t *p_playlist, playlist_item_t *p_root,
  * \return VLC_SUCCESS or an error
  */
 int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root,
-                         vlc_bool_t b_delete_items )
-{
-    return playlist_NodeDeleteInternal( p_playlist, p_root,
-                                        b_delete_items, VLC_FALSE );
-}
-
-int playlist_NodeDeleteInternal( playlist_t *p_playlist,
-                                 playlist_item_t *p_root,
-                                 vlc_bool_t b_delete_items, vlc_bool_t b_force )
+                         vlc_bool_t b_delete_items, vlc_bool_t b_force )
 {
     int i;
     if( p_root->i_children == -1 )
@@ -380,7 +366,7 @@ int playlist_NodeDeleteInternal( playlist_t *p_playlist,
         if( p_root->pp_children[i]->i_children > -1 )
         {
             playlist_NodeDelete( p_playlist, p_root->pp_children[i],
-                                b_delete_items );
+                                b_delete_items , b_force );
         }
         else if( b_delete_items )
         {
@@ -406,7 +392,6 @@ int playlist_NodeDeleteInternal( playlist_t *p_playlist,
 }
 
 
-
 /**
  * Adds an item to the childs of a node
  *