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

📄 listviews.cpp

📁 video linux conference
💻 CPP
📖 第 1 页 / 共 3 页
字号:
PlaylistView::SelectionChanged(){    BLooper* looper = Looper();    if ( fSelectionChangeMessage && looper )    {        BMessage message( *fSelectionChangeMessage );        looper->PostMessage( &message );    }}/***************************************************************************** * PlaylistView::MoveItems *****************************************************************************/voidPlaylistView::MoveItems( BList& items, int32 index ){#if 0    DeselectAll();    // we remove the items while we look at them, the insertion index is decreased    // when the items index is lower, so that we insert at the right spot after    // removal    if ( fVlcWrapper->PlaylistLock() )    {        BList removedItems;        BList removeItems;        int32 count = items.CountItems();        int32 indexOriginal = index;        // remember currently playing item        BListItem* playingItem = _PlayingItem();        // collect item pointers for removal by index        for ( int32 i = 0; i < count; i++ )        {            int32 removeIndex = IndexOf( (BListItem*)items.ItemAt( i ) );            void* item = fVlcWrapper->PlaylistItemAt( removeIndex );            if ( item && removeItems.AddItem( item ) )            {                if ( removeIndex < index )                    index--;            }            // else ??? -> blow up        }        // actually remove items using pointers        for ( int32 i = 0; i < count; i++ )        {            void* item = fVlcWrapper->PlaylistRemoveItem( removeItems.ItemAt( i ) );            if ( item && !removedItems.AddItem( item ) )                free( item );        }        // add items at index        for ( int32 i = 0; void* item = removedItems.ItemAt( i ); i++ )        {            if ( fVlcWrapper->PlaylistAddItem( item, index ) )                // next items will be inserted after this one                index++;            else                free( item );        }        // update GUI        DragSortableListView::MoveItems( items, indexOriginal );        // restore currently playing item        _SetPlayingIndex( playingItem );        // update interface (in case it isn't playing,        // there is a chance that it needs to update)        fMainWindow->PostMessage( MSG_UPDATE );        fVlcWrapper->PlaylistUnlock();    }#endif}/***************************************************************************** * PlaylistView::CopyItems *****************************************************************************/voidPlaylistView::CopyItems( BList& items, int32 toIndex ){#if 0    DeselectAll();    // we remove the items while we look at them, the insertion index is decreased    // when the items index is lower, so that we insert at the right spot after    // removal    if ( fVlcWrapper->PlaylistLock() )    {        BList clonedItems;        int32 count = items.CountItems();        // remember currently playing item        BListItem* playingItem = _PlayingItem();        // collect cloned item pointers        for ( int32 i = 0; i < count; i++ )        {            int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );            void* item = fVlcWrapper->PlaylistItemAt( index );            void* cloned = fVlcWrapper->PlaylistCloneItem( item );            if ( cloned && !clonedItems.AddItem( cloned ) )                free( cloned );                    }        // add cloned items at index        int32 index = toIndex;        for ( int32 i = 0; void* item = clonedItems.ItemAt( i ); i++ )        {            if ( fVlcWrapper->PlaylistAddItem( item, index ) )                // next items will be inserted after this one                index++;            else                free( item );        }        // update GUI        DragSortableListView::CopyItems( items, toIndex );        // restore currently playing item        _SetPlayingIndex( playingItem );        // update interface (in case it isn't playing,        // there is a chance that it needs to update)        fMainWindow->PostMessage( MSG_UPDATE );        fVlcWrapper->PlaylistUnlock();    }#endif}/***************************************************************************** * PlaylistView::RemoveItemList *****************************************************************************/voidPlaylistView::RemoveItemList( BList& items ){#if 0    if ( fVlcWrapper->PlaylistLock() )    {        // remember currently playing item        BListItem* playingItem = _PlayingItem();        // collect item pointers for removal        BList removeItems;        int32 count = items.CountItems();        for ( int32 i = 0; i < count; i++ )        {            int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );            void* item = fVlcWrapper->PlaylistItemAt( index );            if ( item && !removeItems.AddItem( item ) )                free( item );        }        // remove items from playlist        count = removeItems.CountItems();        for ( int32 i = 0; void* item = removeItems.ItemAt( i ); i++ )        {            fVlcWrapper->PlaylistRemoveItem( item );        }        // update GUI        DragSortableListView::RemoveItemList( items );        // restore currently playing item        _SetPlayingIndex( playingItem );        // update interface (in case it isn't playing,        // there is a chance that it needs to update)        fMainWindow->PostMessage( MSG_UPDATE );        fVlcWrapper->PlaylistUnlock();    }#endif}/***************************************************************************** * PlaylistView::CloneItem *****************************************************************************/BListItem*PlaylistView::CloneItem( int32 atIndex ) const{    BListItem* clone = NULL;    if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( atIndex ) ) )        clone = new PlaylistItem( item->Text() );    return clone;}/***************************************************************************** * PlaylistView::DrawListItem *****************************************************************************/voidPlaylistView::DrawListItem( BView* owner, int32 index, BRect frame ) const{    if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( index ) ) )        item->Draw( owner,  frame, index % 2,                    fDisplayMode, index == fCurrentIndex, fPlaying );}/***************************************************************************** * PlaylistView::MakeDragMessage *****************************************************************************/voidPlaylistView::MakeDragMessage( BMessage* message ) const{    if ( message )    {        message->AddPointer( "list", (void*)this );        int32 index;        for ( int32 i = 0; ( index = CurrentSelection( i ) ) >= 0; i++ )        {            message->AddInt32( "index", index );            // add refs to message (inter application communication)            if ( BStringItem* item = dynamic_cast<BStringItem*>( ItemAt( index ) ) )            {                entry_ref ref;                if ( get_ref_for_path( item->Text(), &ref ) == B_OK )                    message->AddRef( "refs", &ref );            }        }    }}/***************************************************************************** * PlaylistView::SetCurrent *****************************************************************************/voidPlaylistView::SetCurrent( int32 index ){    if ( fCurrentIndex != index )    {        InvalidateItem( fCurrentIndex );        fCurrentIndex = index;        InvalidateItem( fCurrentIndex );    }}/***************************************************************************** * PlaylistView::SetPlaying *****************************************************************************/voidPlaylistView::SetPlaying( bool playing ){    if ( fPlaying != playing )    {        fPlaying = playing;        InvalidateItem( fCurrentIndex );    }}/***************************************************************************** * PlaylistView::SetPlaying *****************************************************************************/voidPlaylistView::RebuildList(){    playlist_t * p_playlist;    p_playlist = (playlist_t *) vlc_object_find( p_intf,        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );    if( !p_playlist )    {        return;    }    // remove all items    BListItem * item;    int32 count = CountItems();    while( ( item = RemoveItem( --count ) ) )        delete item;        // rebuild listview from VLC's playlist    vlc_mutex_lock( &p_playlist->object_lock );    for( int i = 0; i < p_playlist->i_size; i++ )        AddItem( new PlaylistItem( p_playlist->pp_items[i]->input.psz_name ) );    vlc_mutex_unlock( &p_playlist->object_lock );    vlc_object_release( p_playlist );}/***************************************************************************** * PlaylistView::SortReverse *****************************************************************************/voidPlaylistView::SortReverse(){#if 0    if ( int32 count = CountSelectedItems() )    {        int32 last  = count - 1;        // remember currently playing item        BListItem* playingItem = _PlayingItem();        for ( int32 first = 0; first < count / 2; first++, last-- )        {            int32 index1 = CurrentSelection( first);            int32 index2 = CurrentSelection( last);            if ( SwapItems( index1, index2 ) )            {                // index2 > index1, so the list won't get messed up                // if we remove the items in that order                // TODO: Error checking + handling!                void* item2 = fVlcWrapper->PlaylistRemoveItem( index2 );                void* item1 = fVlcWrapper->PlaylistRemoveItem( index1 );                fVlcWrapper->PlaylistAddItem( item2, index1 );                fVlcWrapper->PlaylistAddItem( item1, index2 );            }        }        // restore currently playing item        _SetPlayingIndex( playingItem );    }#endif}/***************************************************************************** * PlaylistView::SortByPath *****************************************************************************/voidPlaylistView::SortByPath(){    }/***************************************************************************** * PlaylistView::SortByName *****************************************************************************/voidPlaylistView::SortByName(){}/***************************************************************************** * PlaylistView::SetDisplayMode *****************************************************************************/voidPlaylistView::SetDisplayMode( uint32 mode ){    if ( mode != fDisplayMode )    {        fDisplayMode = mode;        Invalidate();    }}/***************************************************************************** * PlaylistView::_PlayingItem *****************************************************************************/BListItem*PlaylistView::_PlayingItem() const{    playlist_t * p_playlist;    p_playlist = (playlist_t *) vlc_object_find( p_intf,        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );    if( !p_playlist )    {        return NULL;    }    BListItem * item = ItemAt( p_playlist->i_index );    vlc_object_release( p_playlist );    return item;}/***************************************************************************** * PlaylistView::_SetPlayingIndex *****************************************************************************/voidPlaylistView::_SetPlayingIndex( BListItem* playingItem ){    for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )    {        if ( item == playingItem )        {            playlist_t * p_playlist;            p_playlist = (playlist_t *) vlc_object_find( p_intf,                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );                    if( !p_playlist )            {                return;            }            playlist_Goto( p_playlist, i );            SetCurrent( i );            vlc_object_release( p_playlist );            break;        }    }}

⌨️ 快捷键说明

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