⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlist_manager.cpp

📁 uclinux 下的vlc播放器源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    wxString msg;    wxString duration = wxU( "" );    char *psz_author =        vlc_input_item_GetInfo( &p_item->input,                                _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );    if( !psz_author )    {        UnlockPlaylist( p_intf->p_sys, p_playlist );        return;    }    char psz_duration[MSTRTIME_MAX_SIZE];    mtime_t dur = p_item->input.i_duration;    if( dur != -1 )    {        secstotimestr( psz_duration, dur/1000000 );        duration.Append( wxU( " ( " ) +  wxString( wxU( psz_duration ) ) +                         wxU( " )" ) );    }    if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )    {        msg = wxString( wxU( p_item->input.psz_name ) ) + duration;    }    else    {        msg = wxString(wxU( psz_author )) + wxT(" - ") +                    wxString(wxU(p_item->input.psz_name)) + duration;    }    free( psz_author );    treectrl->SetItemText( item , msg );    treectrl->SetItemImage( item, p_item->input.i_type );    if( p_playlist->status.p_item == p_item )    {        treectrl->SetItemBold( item, true );        while( treectrl->GetItemParent( item ).IsOk() )        {            item = treectrl->GetItemParent( item );            treectrl->Expand( item );        }    }    else    {        treectrl->SetItemBold( item, false );    }    UnlockPlaylist( p_intf->p_sys, p_playlist );}void PlaylistManager::AppendItem( wxCommandEvent& event ){    playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();    playlist_item_t *p_item = NULL;    wxTreeItemId item, node;    i_items_to_append--;    /* 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;    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );    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,                                 new PlaylistItem( p_item ) );    treectrl->SetItemImage( item, p_item->input.i_type );    if( item.IsOk() && p_item->i_children == -1 ) UpdateTreeItem( item );update:    return;}void PlaylistManager::UpdateItem( int i ){    if( i < 0 ) return; /* Sanity check */    wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );    if( item.IsOk() ) UpdateTreeItem( item );}void PlaylistManager::RemoveItem( int i ){    if( i <= 0 ) return; /* Sanity check */    wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );    if( item.IsOk() )    {        treectrl->Delete( item );        /* Invalidate cache */        i_cached_item_id = -1;    }}/* This function is called on a regular basis */void PlaylistManager::Update(){    i_update_counter++;    /* If the playlist isn't show there's no need to update it */    if( !IsShown() ) return;    if( this->b_need_update )    {        this->b_need_update = VLC_FALSE;        Rebuild( VLC_TRUE );    }    /* Updating the playing status every 0.5s is enough */    if( i_update_counter % 5 ) return;}/********************************************************************** * Rebuild the playlist **********************************************************************/void PlaylistManager::Rebuild( vlc_bool_t b_root ){    playlist_view_t *p_view;    i_items_to_append = 0;    i_cached_item_id = -1;    p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );    treectrl->DeleteAllItems();    treectrl->AddRoot( wxU(_("root" )), -1, -1,                       new PlaylistItem( p_view->p_root ) );    wxTreeItemId root = treectrl->GetRootItem();    UpdateNode( p_view->p_root, root );}/********************************************************************** * Search functions (internal) **********************************************************************//* Find a wxItem from a playlist id */wxTreeItemId PlaylistManager::FindItem( wxTreeItemId root, int i_id ){    wxTreeItemIdValue cookie;    PlaylistItem *p_wxcurrent;    wxTreeItemId dummy, search, item, child;    if( i_id < 0 ) return dummy;    if( i_cached_item_id == i_id ) return cached_item;    p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );    if( !p_wxcurrent ) return dummy;    if( p_wxcurrent->i_id == i_id )    {        i_cached_item_id = i_id;        cached_item = root;        return root;    }    item = treectrl->GetFirstChild( root, cookie );    while( item.IsOk() )    {        p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );        if( !p_wxcurrent )        {            item = treectrl->GetNextChild( root, cookie );            continue;        }        if( p_wxcurrent->i_id == i_id )        {            i_cached_item_id = i_id;            cached_item = item;            return item;        }        if( treectrl->ItemHasChildren( item ) )        {            wxTreeItemId search = FindItem( item, i_id );            if( search.IsOk() ) return search;        }        item = treectrl->GetNextChild( root, cookie );    }    return dummy;}/******************************************************************** * Events ********************************************************************/void PlaylistManager::OnActivateItem( wxTreeEvent& event ){    playlist_item_t *p_item, *p_node;    wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() );    PlaylistItem *p_wxitem = (PlaylistItem *)        treectrl->GetItemData( event.GetItem() );    if( !p_wxitem || !parent.IsOk() ) return;    PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );    if( !p_wxparent ) return;    LockPlaylist( p_intf->p_sys, p_playlist );    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );    p_node = playlist_ItemGetById( p_playlist, p_wxparent->i_id );    if( !p_item || p_item->i_children >= 0 )    {        p_node = p_item;        p_item = NULL;    }    playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VIEW_CATEGORY,                      p_node, p_item );    UnlockPlaylist( p_intf->p_sys, p_playlist );}void PlaylistManager::OnPlaylistEvent( wxCommandEvent& event ){    switch( event.GetId() )    {    case UpdateItem_Event:        UpdateItem( event.GetInt() );        break;    case AppendItem_Event:        AppendItem( event );        break;    case RemoveItem_Event:        RemoveItem( event.GetInt() );        break;    }}/***************************************************************************** * ItemChanged: callback triggered by the item-change playlist variable *****************************************************************************/static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,                        vlc_value_t old_val, vlc_value_t new_val, void *param ){    PlaylistManager *p_playlist = (PlaylistManager *)param;    wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );    event.SetInt( new_val.i_int );    p_playlist->AddPendingEvent( event );    return VLC_SUCCESS;}static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,                        vlc_value_t old_val, vlc_value_t new_val, void *param ){    PlaylistManager *p_playlist = (PlaylistManager *)param;    wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );    event.SetInt( new_val.i_int );    p_playlist->AddPendingEvent( event );    return VLC_SUCCESS;}static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,                         vlc_value_t oval, vlc_value_t nval, void *param ){    PlaylistManager *p_playlist = (PlaylistManager *)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->i_items_to_append >= 50 )    {        /* Too many items waiting to be added, it will be quicker to rebuild         * the whole playlist */        p_playlist->b_need_update = VLC_TRUE;        return VLC_SUCCESS;    }    wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );    event.SetClientData( (void *)p_add );    p_playlist->AddPendingEvent( event );    return VLC_SUCCESS;}}

⌨️ 快捷键说明

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