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

📄 playlist.cpp

📁 video linux conference
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    /* We went to the next item */    var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );    /* One item has been updated */    var_AddCallback( p_playlist, "item-change", ItemChanged, this );    var_AddCallback( p_playlist, "item-append", ItemAppended, this );    var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );    /* Update the playlist */    Rebuild( VLC_TRUE );}Playlist::~Playlist(){    if( pp_sds != NULL )        free( pp_sds );    if( p_playlist == NULL )    {        return;    }    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 );    vlc_object_release( p_playlist );}/********************************************************************** * Update functions **********************************************************************//* Update a node */void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node ){    wxTreeItemIdValue cookie;    wxTreeItemId child;    for( int i = 0; i< p_node->i_children ; i++ )    {        if( i == 0 )        {            child = treectrl->GetFirstChild( node, cookie);        }        else        {            child = treectrl->GetNextChild( node, cookie );        }        if( !child.IsOk() )        {            /* Not enough children */            CreateNode( p_node->pp_children[i], node );            /* Keep the tree pointer up to date */            child = treectrl->GetNextChild( node, cookie );        }    }    treectrl->SetItemImage( node, p_node->input.i_type );}/* Creates the node p_node as last child of parent */void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent ){    wxTreeItemId node =        treectrl->AppendItem( parent, wxL2U( p_node->input.psz_name ),                              -1,-1, new PlaylistItem( p_node ) );    treectrl->SetItemImage( node, p_node->input.i_type );    UpdateNodeChildren( p_node, node );}/* Update all children (recursively) of this node */void Playlist::UpdateNodeChildren( playlist_item_t *p_node,                                   wxTreeItemId node ){    for( int i = 0; i< p_node->i_children ; i++ )    {        /* Append the item */        if( p_node->pp_children[i]->i_children == -1 )        {            wxTreeItemId item =                treectrl->AppendItem( node,                    wxL2U( p_node->pp_children[i]->input.psz_name ), -1,-1,                           new PlaylistItem( p_node->pp_children[i]) );            UpdateTreeItem( item );        }        else        {            CreateNode( p_node->pp_children[i], node );        }    }}/* Update an item in the tree */void Playlist::UpdateTreeItem( wxTreeItemId item ){    if( ! item.IsOk() ) return;    wxTreeItemData *p_data = treectrl->GetItemData( item );    if( !p_data ) return;        LockPlaylist( p_intf->p_sys, p_playlist );    playlist_item_t *p_item = playlist_ItemGetById( p_playlist,                                          ((PlaylistItem *)p_data)->i_id );    if( !p_item ) return;    wxString msg;    wxString duration = wxU( "" );    char *psz_author = vlc_input_item_GetInfo( &p_item->input,                                                     _("Meta-information"),                                                     _("Artist"));    if( psz_author == NULL )        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.Printf( wxString( wxU( p_item->input.psz_name ) ) + duration );    }    else    {        msg.Printf( 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 );        treectrl->EnsureVisible( item );    }    else    {        treectrl->SetItemBold( item, false );    }    UnlockPlaylist( p_intf->p_sys, p_playlist );}/* Process a AppendIt em request */void Playlist::AppendItem( wxCommandEvent& event ){    playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();    playlist_item_t *p_item = NULL;    wxTreeItemId item,node;    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 = 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:    int i_count = CountItems( treectrl->GetRootItem());    if( i_count != p_playlist->i_size )    {        statusbar->SetStatusText( wxString::Format( wxU(_(                                  "%i items in playlist (%i not shown)")),                                  p_playlist->i_size,                                  p_playlist->i_size - i_count ) );        if( !b_changed_view )        {            i_current_view = VIEW_CATEGORY;            b_changed_view = VLC_TRUE;            b_need_update = VLC_TRUE;        }    }    else    {        statusbar->SetStatusText( wxString::Format( wxU(_(                                  "%i items in playlist")),                                  p_playlist->i_size ), 0 );    }    return;}/* Process a updateitem request */void Playlist::UpdateItem( int i ){    if( i < 0 ) return; /* Sanity check */        wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );    if( item.IsOk() )    {        UpdateTreeItem( item );    }}void Playlist::RemoveItem( int i ){    if( i <= 0 ) return; /* Sanity check */    if( i == i_saved_id ) i_saved_id = -1;    wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );    if( item.IsOk() )    {        treectrl->Delete( item );    }}/********************************************************************** * Search functions (internal) **********************************************************************//* Find a wxItem from a playlist id */wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id ){    wxTreeItemIdValue cookie;    PlaylistItem *p_wxcurrent;    wxTreeItemId search;    wxTreeItemId item = treectrl->GetFirstChild( root, cookie );    wxTreeItemId child;    p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );    if( i_id < 0 )    {        wxTreeItemId dummy;        return dummy;    }    if( i_saved_id == i_id )    {        return saved_tree_item;    }    if( !p_wxcurrent )    {        wxTreeItemId dummy;        return dummy;    }            if( p_wxcurrent->i_id == i_id )    {        i_saved_id = i_id;        saved_tree_item = root;        return root;    }    while( item.IsOk() )    {        p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );        if( p_wxcurrent->i_id == i_id )        {            i_saved_id = i_id;            saved_tree_item = item;            return item;        }        if( treectrl->ItemHasChildren( item ) )        {            wxTreeItemId search = FindItem( item, i_id );            if( search.IsOk() )            {                i_saved_id = i_id;                saved_tree_item = search;                return search;            }        }        item = treectrl->GetNextChild( root, cookie );    }    /* Not found */    wxTreeItemId dummy;    return dummy;}int Playlist::CountItems( wxTreeItemId root ){    wxTreeItemIdValue cookie;    int count = 0;    wxTreeItemId item = treectrl->GetFirstChild( root, cookie );        while( item.IsOk() )    {        if( treectrl->ItemHasChildren( item ) )        {            count += CountItems( item );        }        else        {            playlist_item_t *p_item;            LockPlaylist( p_intf->p_sys, p_playlist );            p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );            if( p_item && p_item->i_children == -1 )                count++;            UnlockPlaylist( p_intf->p_sys, p_playlist );        }        item = treectrl->GetNextChild( root, cookie );    }    return count;}/* Find a wxItem from a name (from current) */wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found ){    wxTreeItemIdValue cookie;    wxTreeItemId search;    wxTreeItemId item = treectrl->GetFirstChild( root, cookie );    wxTreeItemId child;    while( item.IsOk() )    {        if( treectrl->GetItemText( item).Lower().Contains(                                                 search_string.Lower() ) )        {            if( !current.IsOk() || *pb_current_found == VLC_TRUE )            {                return item;            }            else if( current.IsOk() && item == current )            {                *pb_current_found = VLC_TRUE;            }        }        if( treectrl->ItemHasChildren( item ) )        {            wxTreeItemId search = FindItemByName( item, search_string, current,                                                  pb_current_found );            if( search.IsOk() )            {                return search;            }        }        item = treectrl->GetNextChild( root, cookie);    }    /* Not found */    wxTreeItemId dummy;    return dummy;}/********************************************************************** * Rebuild the playlist **********************************************************************/void Playlist::Rebuild( vlc_bool_t b_root ){    playlist_view_t *p_view;    /* We can remove the callbacks before locking, anyway, we won't     * miss anything */    if( b_root )    {        var_DelCallback( p_playlist, "item-change", ItemChanged, this );

⌨️ 快捷键说明

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