]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/playlist.cpp
Misc Fixes
[vlc] / modules / gui / wxwindows / playlist.cpp
index 67f824842df60b52dbbc0383b11f6aa42b2054da..7ecc413716807a0f9b88ef5bde6458e8fb8f68db 100644 (file)
 #include "bitmaps/repeat.xpm"
 #include "bitmaps/loop.xpm"
 
+
+#define HELP_SHUFFLE N_( "Shuffle" )
+#define HELP_LOOP N_( "Loop" )
+#define HELP_REPEAT N_( "Repeat" )
+
 /* Callback prototype */
 static int PlaylistChanged( vlc_object_t *, const char *,
                             vlc_value_t, vlc_value_t, void * );
@@ -176,12 +181,11 @@ END_EVENT_TABLE()
  *****************************************************************************/
 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
-             wxDefaultSize, wxDEFAULT_FRAME_STYLE )
+             wxSize(345,400), wxDEFAULT_FRAME_STYLE ), listview(NULL)
 {
     vlc_value_t val;
 
     /* Initializations */
-    iteminfo_dialog = NULL;
     p_intf = _p_intf;
     i_update_counter = 0;
     i_sort_mode = MODE_NONE;
@@ -258,59 +262,46 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 
     /* Create the toolbar */
     wxToolBar *toolbar =
-             CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
-#define HELP_SHUFFLE "Shuffle"
-#define HELP_LOOP "Loop"
-#define HELP_REPEAT "Repeat"
+        CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
 
     /* Create the random tool */
     toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
                        wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
                        wxU(_(HELP_SHUFFLE) ) );
     var_Get( p_intf, "random", &val );
-    vlc_bool_t b_random = val.b_bool;
-    toolbar->ToggleTool( Random_Event ,  b_random  );
+    toolbar->ToggleTool( Random_Event, val.b_bool );
 
     /* Create the Loop tool */
     toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
                       wxBitmap( loop_xpm), wxITEM_CHECK,
                       wxU(_(HELP_LOOP )  ) );
     var_Get( p_intf, "loop", &val );
-    int b_loop = val.b_bool ;
-    toolbar->ToggleTool( Loop_Event,  b_loop );
+    toolbar->ToggleTool( Loop_Event, val.b_bool );
 
     /* Create the Repeat one checkbox */
     toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
                       wxBitmap( repeat_xpm), wxITEM_CHECK,
                       wxU(_(HELP_REPEAT )  ) );
-
     var_Get( p_intf, "repeat", &val );
-    int b_repeat = val.b_bool ;
-    toolbar->ToggleTool( Repeat_Event, b_repeat) ;
+    toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
 
     /* Create the Search Textbox */
-    search_text =
-        new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
-                        wxDefaultPosition, wxSize(100, -1),
-                        wxTE_PROCESS_ENTER);
+    search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
+                                  wxDefaultPosition, wxSize(100, -1),
+                                  wxTE_PROCESS_ENTER);
 
     /* Create the search button */
-    search_button =
-        new wxButton( toolbar , Search_Event, wxU(_("Search")) );
+    search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
 
-    search_button->SetDefault();
-    wxControl *p_dummy_ctrl =
-            new wxControl( toolbar, -1, wxDefaultPosition,
-                           wxSize(64, 16 ), wxBORDER_NONE );
-
-    toolbar->AddSeparator();
-    toolbar->AddControl( p_dummy_ctrl );
+    toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
+                         wxSize(16, 16), wxBORDER_NONE ) );
     toolbar->AddControl( search_text );
+    toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
+                         wxSize(5, 5), wxBORDER_NONE ) );
     toolbar->AddControl( search_button );
-
+    search_button->SetDefault();
     toolbar->Realize();
 
-
     /* Create the listview */
     /* FIXME: the given size is arbitrary, and prevents us from resizing
      * the window to smaller dimensions. But the sizers don't seem to adjust
@@ -319,84 +310,39 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     listview = new wxListView( playlist_panel, ListView_Event,
                                wxDefaultPosition, wxDefaultSize,
                                wxLC_REPORT | wxSUNKEN_BORDER );
+
+    /* Reduce font size */
+    wxFont font= listview->GetFont();
+    font.SetPointSize(8);
+    listview->SetFont( font );
+
     listview->InsertColumn( 0, wxU(_("Name")) );
-#if 0
-    listview->InsertColumn( 1, wxU(_("Author")) );
-#endif
+    listview->SetColumnWidth( 0, 250 );
     listview->InsertColumn( 1, wxU(_("Duration")) );
-#if 0
-    listview->InsertColumn( 3, wxU(_("Group")) );
-#endif
-    listview->SetColumnWidth( 0, 240 );
-    listview->SetColumnWidth( 1, 55 );
-
-   DoSize();
+    listview->SetColumnWidth( 1, 75 );
+    listview->Layout();
 
     /* Create the Up-Down buttons */
     wxButton *up_button =
         new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
-
     wxButton *down_button =
         new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
 
-#if 0
-    /* Create the iteminfo button */
-    wxButton *iteminfo_button =
-        new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
-
-    /* Place everything in sizers */
-    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
-    button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT, 5);
-    button_sizer->Layout();
-#endif
-
     wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
-    updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
-    updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
     updown_sizer->Layout();
 
-    wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
-#if 0
-    //checkbox_sizer->Add( random_checkbox, 0,
-      //                   wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
-    //checkbox_sizer->Add( loop_checkbox, 0,
-                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
-    checkbox_sizer->Add( repeat_checkbox, 0,
-                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
-    checkbox_sizer->Layout();
-
-    wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
-//    search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
-//    search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
-    search_sizer->Layout();
-#endif
-
     /* The top and bottom sizers */
-#if 0
-    wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
-   top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
-    top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
-    top_sizer->Layout();
-#endif
     wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
-    bottom_sizer->Add( updown_sizer, 0,
-                       wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4 );
-//    bottom_sizer->Add( button_sizer, 0,
-//                     wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
+    bottom_sizer->Add( up_button, 0, wxALIGN_LEFT | wxRIGHT, 3);
+    bottom_sizer->Add( down_button, 0, wxALIGN_LEFT | wxLEFT, 3);
     bottom_sizer->Layout();
 
-    wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
-
     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
- //   panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
     panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
-    panel_sizer->Add( bottom_sizer, 0, wxEXPAND | wxALL, 5);
+    panel_sizer->Add( bottom_sizer, 0, wxALL, 5);
     panel_sizer->Layout();
 
     playlist_panel->SetSizerAndFit( panel_sizer );
-    main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
-    main_sizer->Layout();
-    SetSizerAndFit( main_sizer );
 
 #if wxUSE_DRAG_AND_DROP
     /* Associate drop targets with the playlist */
@@ -422,7 +368,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     /* One item has been updated */
     var_AddCallback( p_playlist, "item-change", ItemChanged, this );
 
-
     vlc_object_release( p_playlist );
 
     /* Update the playlist */
@@ -430,18 +375,14 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 }
 
 void Playlist::OnSize( wxSizeEvent& event)
-{
-    DoSize();
-    event.Skip();
-}
-
-void Playlist::DoSize()
 {
     wxSize size = GetClientSize();
-    listview->SetSize( 0,0,size.x,size.y);
+    if( listview )
+        listview->SetColumnWidth( 0, size.x - listview->GetColumnWidth(1)
+                                 - 15 /* margins */ );
+    event.Skip();
 }
 
-
 Playlist::~Playlist()
 {
     playlist_t *p_playlist =
@@ -452,8 +393,6 @@ Playlist::~Playlist()
         return;
     }
 
-    delete iteminfo_dialog;
-
     var_DelCallback( p_playlist, "item-change", ItemChanged, this );
     var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
@@ -562,6 +501,7 @@ void Playlist::Rebuild()
     {
         wxString filename = wxL2U(p_playlist->pp_items[i]->input.psz_name);
         listview->InsertItem( i, filename );
+        /* FIXME: Very slow, need to find the playlist many times */
         UpdateItem( i );
     }
     vlc_mutex_unlock( &p_playlist->object_lock );
@@ -1002,12 +942,37 @@ void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
 
 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
 {
+    long *pd_del = NULL;
+    int i_del = 0;
+    int i;
+
     /* Delete from the end to the beginning, to avoid a shift of indices */
     for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
     {
+        /* TODO : use vector */
         if( listview->IsSelected( item ) )
         {
-            DeleteItem( item );
+            if( i_del> 0 )
+            {
+                pd_del = (long *)realloc( pd_del, sizeof( void **) *
+                                                         (i_del + 1 ) );
+            }
+            else
+            {
+                pd_del = (long *)malloc( sizeof( void ** ) );
+            }
+            pd_del[i_del] = item;
+            i_del ++;
+        }
+    }
+    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
+    {
+        for( i = 0 ; i < i_del; i++ )
+        {
+            if( item == pd_del[i] )
+            {
+                DeleteItem( item );
+            }
         }
     }
 
@@ -1157,21 +1122,17 @@ void Playlist::ShowInfos( int i_item )
         return;
     }
 
-    if( iteminfo_dialog == NULL )
-    {
-        vlc_mutex_lock( &p_playlist->object_lock);
-        playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
-        vlc_mutex_unlock( &p_playlist->object_lock );
+    vlc_mutex_lock( &p_playlist->object_lock);
+    playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
+    vlc_mutex_unlock( &p_playlist->object_lock );
 
-        if( p_item )
-        {
-            iteminfo_dialog = new ItemInfoDialog( p_intf, p_item, this );
-            if( iteminfo_dialog->ShowModal() == wxID_OK )
-                UpdateItem( i_item );
-            delete iteminfo_dialog;
-            iteminfo_dialog = NULL;
-        }
+    if( p_item )
+    {
+        iteminfo_dialog = new ItemInfoDialog( p_intf, p_item, this );
+        if( iteminfo_dialog->ShowModal() == wxID_OK ) UpdateItem( i_item );
+        delete iteminfo_dialog;
     }
+
     vlc_object_release( p_playlist );
 }