playlist.cpp

来自「VLC媒体播放程序」· C++ 代码 · 共 1,339 行 · 第 1/3 页

CPP
1,339
字号
            if( listitem.m_text.Lower().Contains( search_string.Lower() ) )            {                i_item = i_current;                b_ok = true;                break;            }        }    }    if( i_item < 0 || i_item >= listview->GetItemCount() ) return;    for( long item = 0; item < listview->GetItemCount(); item++ )    {        listview->Select( item, FALSE );    }    wxListItem listitem;    listitem.SetId(i_item);    listitem.m_state = wxLIST_STATE_SELECTED;    listview->Select( i_item, TRUE );    listview->Focus( i_item );}/********************************************************************** * Selection functions **********************************************************************/void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) ){    for( long item = 0; item < listview->GetItemCount(); item++ )    {        listview->Select( item, ! listview->IsSelected( item ) );    }}void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) ){    /* Delete from the end to the beginning, to avoid a shift of indices */    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )    {        if( listview->IsSelected( item ) )        {            DeleteItem( item );        }    }    Rebuild();}void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )    {        if( listview->IsSelected( item ) )        {            /*XXX*/            playlist_Enable( p_playlist, item );            UpdateItem( item );        }    }    vlc_object_release( p_playlist);}void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )    {        if( listview->IsSelected( item ) )        {            /*XXX*/            playlist_Disable( p_playlist, item );            UpdateItem( item );        }    }    vlc_object_release( p_playlist);}void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) ){    for( long item = 0; item < listview->GetItemCount(); item++ )    {        listview->Select( item, TRUE );    }}/********************************************************************** * Playlist mode functions **********************************************************************/void Playlist::OnRandom( wxCommandEvent& event ){    vlc_value_t val;    val.b_bool = event.IsChecked();    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    var_Set( p_playlist , "random", val);    vlc_object_release( p_playlist );}void Playlist::OnLoop ( wxCommandEvent& event ){    vlc_value_t val;    val.b_bool = event.IsChecked();    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    var_Set( p_playlist , "loop", val);    vlc_object_release( p_playlist );}void Playlist::OnRepeat ( wxCommandEvent& event ){    vlc_value_t val;    val.b_bool = event.IsChecked();    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    var_Set( p_playlist , "repeat", val);    vlc_object_release( p_playlist );}void Playlist::OnActivateItem( wxListEvent& event ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    playlist_Goto( p_playlist, event.GetIndex() );    vlc_object_release( p_playlist );}void Playlist::OnKeyDown( wxListEvent& event ){    long keycode = event.GetKeyCode();    /* Delete selected items */    if( keycode == WXK_BACK || keycode == WXK_DELETE )    {        /* We send a dummy event */        OnDeleteSelection( event );    }}void Playlist::ShowInfos( int i_item ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }       if( i_item == -1 )    {        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 );        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;        }    }    vlc_object_release( p_playlist );}void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) ){    /* We use the first selected item, so find it */    long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,                                         wxLIST_STATE_SELECTED );    ShowInfos( i_item );}void Playlist::OnEnDis( wxCommandEvent& event ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,                                         wxLIST_STATE_SELECTED );    if( i_item >= 0 && i_item < p_playlist->i_size )    {       switch( event.GetId() )       {           case EnableGroup_Event:               /*XXX*/               playlist_EnableGroup( p_playlist ,                                  p_playlist->pp_items[i_item]->i_group );               break;           case DisableGroup_Event:               playlist_DisableGroup( p_playlist ,                                  p_playlist->pp_items[i_item]->i_group );               break;       }       Rebuild();    }    vlc_object_release( p_playlist );}/***************************************************************************** * Popup management functions *****************************************************************************/void Playlist::OnPopup( wxListEvent& event ){    i_popup_item = event.GetIndex();    Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );}void Playlist::OnPopupPlay( wxMenuEvent& event ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    if( i_popup_item != -1 )    {        playlist_Goto( p_playlist, i_popup_item );    }    vlc_object_release( p_playlist );}void Playlist::OnPopupDel( wxMenuEvent& event ){    DeleteItem( i_popup_item );}void Playlist::OnPopupEna( wxMenuEvent& event ){    playlist_t *p_playlist =        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    if( p_playlist->pp_items[i_popup_item]->b_enabled )        //playlist_IsEnabled( p_playlist, i_popup_item ) )    {        playlist_Disable( p_playlist, i_popup_item );    }    else    {        playlist_Enable( p_playlist, i_popup_item );    }    vlc_object_release( p_playlist);    UpdateItem( i_popup_item );}void Playlist::OnPopupInfo( wxMenuEvent& event ){    ShowInfos( i_popup_item );}/***************************************************************************** * Custom events management *****************************************************************************/void Playlist::OnPlaylistEvent( wxCommandEvent& event ){    switch( event.GetId() )    {    case UpdateItem_Event:        UpdateItem( event.GetInt() );        break;    }}/***************************************************************************** * PlaylistChanged: callback triggered by the intf-change playlist variable *  We don't rebuild the playlist directly here because we don't want the *  caller to block for a too long time. *****************************************************************************/int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,                     vlc_value_t old_val, vlc_value_t new_val, void *param ){    Playlist *p_playlist_dialog = (Playlist *)param;    p_playlist_dialog->b_need_update = VLC_TRUE;    return VLC_SUCCESS;}/***************************************************************************** * Next: callback triggered by the playlist-current playlist variable *****************************************************************************/int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,                 vlc_value_t old_val, vlc_value_t new_val, void *param ){    Playlist *p_playlist_dialog = (Playlist *)param;    wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );    event.SetInt( old_val.i_int );    p_playlist_dialog->AddPendingEvent( event );    event.SetInt( new_val.i_int );    p_playlist_dialog->AddPendingEvent( event );    return 0;}/***************************************************************************** * ItemChanged: callback triggered by the item-change playlist variable *****************************************************************************/int ItemChanged( vlc_object_t *p_this, const char *psz_variable,                 vlc_value_t old_val, vlc_value_t new_val, void *param ){    Playlist *p_playlist_dialog = (Playlist *)param;    wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );    event.SetInt( new_val.i_int );    p_playlist_dialog->AddPendingEvent( event );    return 0;}/*************************************************************************** * NewGroup Class ***************************************************************************/NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):    wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,             wxDefaultSize, wxDEFAULT_FRAME_STYLE ){    /* Initializations */    p_intf = _p_intf;    psz_name = NULL;    SetIcon( *p_intf->p_sys->p_icon );    /* Create a panel to put everything in*/    wxPanel *panel = new wxPanel( this, -1 );    panel->SetAutoLayout( TRUE );    wxStaticText *group_label =            new wxStaticText( panel , -1,                wxU(_("Enter a name for the new group:")));    groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,                               wxSize(100,27),wxTE_PROCESS_ENTER);    wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );    ok_button->SetDefault();    wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,                                            wxU(_("Cancel")) );    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );    button_sizer->Add( ok_button, 0, wxALL, 5 );    button_sizer->Add( cancel_button, 0, wxALL, 5 );    button_sizer->Layout();    wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );    panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );    panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );    panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );    panel_sizer->Layout();    panel->SetSizerAndFit( panel_sizer );    wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );    main_sizer->Add( panel, 1, wxEXPAND, 0 );    main_sizer->Layout();    SetSizerAndFit( main_sizer );}NewGroup::~NewGroup(){}void NewGroup::OnOk( wxCommandEvent& event ){    psz_name = strdup( groupname->GetLineText(0).mb_str() );    playlist_t * p_playlist =          (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist )    {        if( !playlist_CreateGroup( p_playlist, psz_name ) )        {            psz_name = NULL;        }        vlc_object_release( p_playlist );    }    EndModal( wxID_OK );}void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) ){    EndModal( wxID_CANCEL );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?