📄 playlist_model.cpp
字号:
}/************************* Actions ******************************//** * Deletion, here we have to do a ugly slow hack as we retrieve the full * list of indexes to delete at once: when we delete a node and all of * its children, we need to update the list. * Todo: investigate whethere we can use ranges to be sure to delete all items? */void PLModel::doDelete( QModelIndexList selected ){ for( int i = selected.size() -1 ; i >= 0; i-- ) { QModelIndex index = selected[i]; if( index.column() != 0 ) continue; PLItem *item = static_cast<PLItem*>(index.internalPointer()); if( item ) { if( item->children.size() ) recurseDelete( item->children, &selected ); doDeleteItem( item, &selected ); } }}void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList ){ for( int i = children.size() - 1; i >= 0 ; i-- ) { PLItem *item = children[i]; if( item->children.size() ) recurseDelete( item->children, fullList ); doDeleteItem( item, fullList ); }}void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList ){ QModelIndex deleteIndex = index( item, 0 ); fullList->removeAll( deleteIndex ); PL_LOCK; playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id, pl_Locked ); if( !p_item ) { PL_UNLOCK; return; } if( p_item->i_children == -1 ) playlist_DeleteFromInput( p_playlist, item->i_input_id, pl_Locked ); else playlist_NodeDelete( p_playlist, p_item, true, false ); /* And finally, remove it from the tree */ item->remove( item ); PL_UNLOCK;}/******* Volume III: Sorting and searching ********/void PLModel::sort( int column, Qt::SortOrder order ){ int i_index = -1; int i_flag = 0; // FIXME: Disable sorting on startup by ignoring // first call of sorting caused by showing dialog // see: standardpanel.cpp:65 static bool b_first_time = true; if( b_first_time ) { b_first_time = false; return; }#define CHECK_COLUMN( meta ) \{ \ if( ( shownFlags() & meta ) ) \ i_index++; \ if( column == i_index ) \ { \ i_flag = meta; \ goto next; \ } \} CHECK_COLUMN( COLUMN_NUMBER ); CHECK_COLUMN( COLUMN_TITLE ); CHECK_COLUMN( COLUMN_DURATION ); CHECK_COLUMN( COLUMN_ARTIST ); CHECK_COLUMN( COLUMN_GENRE ); CHECK_COLUMN( COLUMN_ALBUM ); CHECK_COLUMN( COLUMN_TRACK_NUMBER ); CHECK_COLUMN( COLUMN_DESCRIPTION );#undef CHECK_COLUMNnext: PL_LOCK; { playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id, pl_Locked ); if( p_root ) { playlist_RecursiveNodeSort( p_playlist, p_root, i_column_sorting( i_flag ), order == Qt::AscendingOrder ? ORDER_NORMAL : ORDER_REVERSE ); p_playlist->b_reset_currently_playing = true; } } PL_UNLOCK; rebuild();}void PLModel::search( QString search_text ){ /** \todo Fire the search with a small delay ? */ PL_LOCK; { playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id, pl_Locked ); assert( p_root ); char *psz_name = search_text.toUtf8().data(); playlist_LiveSearchUpdate( p_playlist , p_root, psz_name ); } PL_UNLOCK; rebuild();}/*********** Popup *********/void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ){ assert( index.isValid() ); PL_LOCK; playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ), pl_Locked ); if( p_item ) { i_popup_item = p_item->i_id; i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1; PL_UNLOCK; current_selection = list; QMenu *menu = new QMenu; menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) ); menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) ); menu->addSeparator(); menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) ); menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) ); menu->addSeparator(); menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) ); if( p_item->i_children > -1 ) { menu->addSeparator(); menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) ); menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) ); } menu->addSeparator(); menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) ); menu->popup( point ); } else PL_UNLOCK;}void PLModel::viewchanged( int meta ){ assert( meta ); int _meta = meta; if( rootItem ) { int index=-1; while( _meta ) { index++; _meta >>= 1; } /* UNUSED emit layoutAboutToBeChanged(); */ index = __MIN( index, rootItem->item_col_strings.count() ); QModelIndex parent = createIndex( 0, 0, rootItem ); if( rootItem->i_showflags & meta ) /* Removing columns */ { beginRemoveColumns( parent, index, index+1 ); rootItem->i_showflags &= ~( meta ); rootItem->updateColumnHeaders(); endRemoveColumns(); } else { /* Adding columns */ beginInsertColumns( parent, index, index+1 ); rootItem->i_showflags |= meta; rootItem->updateColumnHeaders(); endInsertColumns(); } rebuild(); }}void PLModel::popupDel(){ doDelete( current_selection );}void PLModel::popupPlay(){ PL_LOCK; { playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item, pl_Locked ); activateItem( p_item ); } PL_UNLOCK;}void PLModel::popupInfo(){ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item, pl_Unlocked ); if( p_item ) { MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input ); mid->show(); }}void PLModel::popupStream(){ QStringList mrls = selectedURIs(); if( !mrls.isEmpty() ) THEDP->streamingDialog( NULL, mrls[0], false );}void PLModel::popupSave(){ QStringList mrls = selectedURIs(); if( !mrls.isEmpty() ) THEDP->streamingDialog( NULL, mrls[0], true );}#include <QUrl>#include <QFileInfo>#include <QDesktopServices>void PLModel::popupExplore(){ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item, pl_Unlocked ); if( p_item ) { input_item_t *p_input = p_item->p_input; char *psz_meta = input_item_GetURI( p_input ); if( psz_meta ) { const char *psz_access; const char *psz_demux; char *psz_path; input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta ); if( EMPTY_STR( psz_access ) || !strncasecmp( psz_access, "file", 4 ) || !strncasecmp( psz_access, "dire", 4 ) ) { QFileInfo info( qfu( psz_meta ) ); QDesktopServices::openUrl( QUrl::fromLocalFile( info.absolutePath() ) ); } free( psz_meta ); } }}/********************************************************************** * Playlist callbacks **********************************************************************/static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param ){ PLModel *p_model = (PLModel *) param; PLEvent *event = new PLEvent( PLUpdate_Type, 0 ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); return VLC_SUCCESS;}static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param ){ PLModel *p_model = (PLModel *) param; PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); event = new PLEvent( ItemUpdate_Type, nval.i_int ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); return VLC_SUCCESS;}static int ItemChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param ){ PLModel *p_model = (PLModel *) param; PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); return VLC_SUCCESS;}static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param ){ PLModel *p_model = (PLModel *) param; PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int ); QApplication::postEvent( p_model, static_cast<QEvent*>(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 ){ PLModel *p_model = (PLModel *) param; playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t)); memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) ); PLEvent *event = new PLEvent( p_add ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); return VLC_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -