Commit 9846f39f authored by Clément Stenac's avatar Clément Stenac

Preliminary deletion support

parent 1fc13bde
......@@ -32,7 +32,7 @@
class QTreeView;
class PLModel;
class QPushButton;
class QKeyEvent;
/**
* \todo Share a single model between views using a filterproxy
*/
......@@ -60,6 +60,8 @@ public:
StandardPLPanel( QWidget *, intf_thread_t *,
playlist_t *,playlist_item_t * );
virtual ~StandardPLPanel();
protected:
virtual void keyPressEvent( QKeyEvent *e );
private:
PLModel *model;
QTreeView *view;
......@@ -67,6 +69,7 @@ private:
public slots:
virtual void setRoot( int );
private slots:
void deleteSelection();
void handleExpansion( const QModelIndex& );
void toggleRandom();
void toggleRepeat();
......
......@@ -28,8 +28,10 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QKeyEvent>
#include "qt4.hpp"
#include <assert.h>
#include <QModelIndexList>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_t *p_playlist,
......@@ -122,5 +124,23 @@ void StandardPLPanel::setRoot( int i_root_id )
model->Rebuild();
}
void StandardPLPanel::keyPressEvent( QKeyEvent *e )
{
switch( e->key() )
{
case Qt::Key_Back:
case Qt::Key_Delete:
deleteSelection();
break;
}
}
void StandardPLPanel::deleteSelection()
{
QItemSelectionModel *selection = view->selectionModel();
QModelIndexList list = selection->selectedIndexes();
model->doDelete( list );
}
StandardPLPanel::~StandardPLPanel()
{}
......@@ -134,7 +134,7 @@ void QVLCMenu::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
manageMenu->addAction( "Quick &Add File...", THEDP,
SLOT( simpleAppendDialog() ) );
manageMenu->addSeparator();
manageMenu->addMenu( SDMenu( p_intf ) );
// manageMenu->addMenu( SDMenu( p_intf ) );
bar->addMenu( manageMenu );
}
......
......@@ -555,6 +555,61 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
emit dataChanged( index( item, 0 ) , index( item, 1 ) );
}
/************************* 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 );
if( !p_item )
{
PL_UNLOCK; return;
}
if( p_item->i_children == -1 )
playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
else
playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
/* And finally, remove it from the tree */
item->remove( item );
PL_UNLOCK;
}
/**********************************************************************
* Playlist callbacks
**********************************************************************/
......
......@@ -119,6 +119,8 @@ public:
void Rebuild();
void rebuildRoot( playlist_item_t * );
bool hasRandom(); bool hasLoop(); bool hasRepeat();
void doDelete( QModelIndexList selected );
private:
void addCallbacks();
void delCallbacks();
......@@ -139,6 +141,10 @@ private:
void UpdateNodeChildren( PLItem * );
void UpdateNodeChildren( playlist_item_t *, PLItem * );
/* Actions */
void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
void doDeleteItem( PLItem *item, QModelIndexList *fullList );
/* Lookups */
PLItem *FindById( PLItem *, int );
PLItem *FindByInput( PLItem *, int );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment