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

Preliminary deletion support

parent 1fc13bde
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class QTreeView; class QTreeView;
class PLModel; class PLModel;
class QPushButton; class QPushButton;
class QKeyEvent;
/** /**
* \todo Share a single model between views using a filterproxy * \todo Share a single model between views using a filterproxy
*/ */
...@@ -60,6 +60,8 @@ public: ...@@ -60,6 +60,8 @@ public:
StandardPLPanel( QWidget *, intf_thread_t *, StandardPLPanel( QWidget *, intf_thread_t *,
playlist_t *,playlist_item_t * ); playlist_t *,playlist_item_t * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
protected:
virtual void keyPressEvent( QKeyEvent *e );
private: private:
PLModel *model; PLModel *model;
QTreeView *view; QTreeView *view;
...@@ -67,6 +69,7 @@ private: ...@@ -67,6 +69,7 @@ private:
public slots: public slots:
virtual void setRoot( int ); virtual void setRoot( int );
private slots: private slots:
void deleteSelection();
void handleExpansion( const QModelIndex& ); void handleExpansion( const QModelIndex& );
void toggleRandom(); void toggleRandom();
void toggleRepeat(); void toggleRepeat();
......
...@@ -28,8 +28,10 @@ ...@@ -28,8 +28,10 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QKeyEvent>
#include "qt4.hpp" #include "qt4.hpp"
#include <assert.h> #include <assert.h>
#include <QModelIndexList>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_t *p_playlist, playlist_t *p_playlist,
...@@ -122,5 +124,23 @@ void StandardPLPanel::setRoot( int i_root_id ) ...@@ -122,5 +124,23 @@ void StandardPLPanel::setRoot( int i_root_id )
model->Rebuild(); 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() StandardPLPanel::~StandardPLPanel()
{} {}
...@@ -134,7 +134,7 @@ void QVLCMenu::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf ) ...@@ -134,7 +134,7 @@ void QVLCMenu::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
manageMenu->addAction( "Quick &Add File...", THEDP, manageMenu->addAction( "Quick &Add File...", THEDP,
SLOT( simpleAppendDialog() ) ); SLOT( simpleAppendDialog() ) );
manageMenu->addSeparator(); manageMenu->addSeparator();
manageMenu->addMenu( SDMenu( p_intf ) ); // manageMenu->addMenu( SDMenu( p_intf ) );
bar->addMenu( manageMenu ); bar->addMenu( manageMenu );
} }
......
...@@ -555,6 +555,61 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item, ...@@ -555,6 +555,61 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
emit dataChanged( index( item, 0 ) , index( item, 1 ) ); 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 * Playlist callbacks
**********************************************************************/ **********************************************************************/
......
...@@ -119,6 +119,8 @@ public: ...@@ -119,6 +119,8 @@ public:
void Rebuild(); void Rebuild();
void rebuildRoot( playlist_item_t * ); void rebuildRoot( playlist_item_t * );
bool hasRandom(); bool hasLoop(); bool hasRepeat(); bool hasRandom(); bool hasLoop(); bool hasRepeat();
void doDelete( QModelIndexList selected );
private: private:
void addCallbacks(); void addCallbacks();
void delCallbacks(); void delCallbacks();
...@@ -139,6 +141,10 @@ private: ...@@ -139,6 +141,10 @@ private:
void UpdateNodeChildren( PLItem * ); void UpdateNodeChildren( PLItem * );
void UpdateNodeChildren( playlist_item_t *, PLItem * ); void UpdateNodeChildren( playlist_item_t *, PLItem * );
/* Actions */
void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
void doDeleteItem( PLItem *item, QModelIndexList *fullList );
/* Lookups */ /* Lookups */
PLItem *FindById( PLItem *, int ); PLItem *FindById( PLItem *, int );
PLItem *FindByInput( 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