]> git.sesse.net Git - vlc/commitdiff
Preliminary deletion support
authorClément Stenac <zorglub@videolan.org>
Thu, 24 Aug 2006 18:00:28 +0000 (18:00 +0000)
committerClément Stenac <zorglub@videolan.org>
Thu, 24 Aug 2006 18:00:28 +0000 (18:00 +0000)
modules/gui/qt4/components/playlist/panels.hpp
modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/playlist_model.cpp
modules/gui/qt4/playlist_model.hpp

index 9bb2c53ad406f42a2fe237cfceaf8412d5f8dd04..c3fb88a53b514fcd41856c14987aaa8d6a922620 100644 (file)
@@ -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();
index 27cc33a8f00101a867831e2d6b975ea26d80951a..3a770a71fdec7e3109aafbc17d679c003f199eef 100644 (file)
 #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()
 {}
index 4d374fdd7d7158c3e12e054d26cdc9555a7b55ec..c0f8d2d9849a67697d62acbe495d07f03be6386d 100644 (file)
@@ -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 );
 }
index d2b886a626493a7b339a9cb94327d3f95f5b146e..d7fad4e6c9b88aa5139f1e189c36a11e0b3ac9b8 100644 (file)
@@ -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
  **********************************************************************/
index 9b0cbc1d2b00cc23040be9acc66058038ba61ab6..615934cd94862eb6dc0a89aa7d1f763b1a7a03b7 100644 (file)
@@ -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 );