]> git.sesse.net Git - vlc/commitdiff
* modules/gui/wxwidgets/playlist.cpp: if too many items are queued to be added to...
authorGildas Bazin <gbazin@videolan.org>
Wed, 2 Nov 2005 10:25:41 +0000 (10:25 +0000)
committerGildas Bazin <gbazin@videolan.org>
Wed, 2 Nov 2005 10:25:41 +0000 (10:25 +0000)
modules/gui/wxwidgets/playlist.cpp
modules/gui/wxwidgets/wxwidgets.h

index 11fd8f4c7b0bf3710de2ec5a658cf56a0c74d285..6100c458ecff11a5494b5c0252890483f0ed4c4e 100644 (file)
@@ -204,6 +204,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     i_update_counter = 0;
     i_sort_mode = MODE_NONE;
     b_need_update = VLC_FALSE;
+    i_items_to_append = 0;
     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                 FIND_ANYWHERE );
     if( p_playlist == NULL ) return;
@@ -540,23 +541,23 @@ void Playlist::AppendItem( wxCommandEvent& event )
 {
     playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
     playlist_item_t *p_item = NULL;
+    wxTreeItemId item, node;
 
-    wxTreeItemId item,node;
+    i_items_to_append--;
 
-    if( p_add->i_view != i_current_view )
-    {
-        goto update;
-    }
+    /* No need to do anything if the playlist is going to be rebuilt */
+    if( b_need_update ) return;
+
+    if( p_add->i_view != i_current_view ) goto update;
 
     node = FindItem( treectrl->GetRootItem(), p_add->i_node );
-    if( !node.IsOk() )
-    {
-        goto update;
-    }
+    if( !node.IsOk() ) goto update;
 
     p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
-    if( !p_item )
-        goto update;
+    if( !p_item ) goto update;
+
+    item = FindItem( treectrl->GetRootItem(), p_add->i_item );
+    if( item.IsOk() ) goto update;
 
     item = treectrl->AppendItem( node,
                                  wxL2U( p_item->input.psz_name ), -1,-1,
@@ -755,6 +756,8 @@ void Playlist::Rebuild( vlc_bool_t b_root )
 {
     playlist_view_t *p_view;
 
+    i_items_to_append = 0;
+
     /* We can remove the callbacks before locking, anyway, we won't
      * miss anything */
     if( b_root )
@@ -1509,9 +1512,16 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
     Playlist *p_playlist_dialog = (Playlist *)param;
 
     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
-
     memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
 
+    if( p_playlist_dialog->i_items_to_append++ > 50 )
+    {
+        /* Too many items waiting to be added, it will be quicker to rebuild
+         * the whole playlist */
+        p_playlist_dialog->b_need_update = VLC_TRUE;
+        return VLC_SUCCESS;
+    }
+
     wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
     event.SetClientData( (void *)p_add );
     p_playlist_dialog->AddPendingEvent( event );
index 5177d2576315778127affe79921f13ada6fd118e..e97463f85da3fcef4d111cd37356f031fd550094 100644 (file)
@@ -878,6 +878,7 @@ public:
     void AppendItem( wxCommandEvent& );
 
     bool b_need_update;
+    int  i_items_to_append;
 
 private:
     void RemoveItem( int );