[vlc-devel] [PATCH 6/6] qt: playlist: add Browse and Shrink actions

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Tue Jul 25 18:00:43 CEST 2017


When right-clicking onto a folder, the user can now browse it, or shrink it if
he's using the tree view.
---
 .../gui/qt/components/playlist/playlist_item.hpp   |  3 +++
 .../gui/qt/components/playlist/playlist_model.cpp  |  9 ++++++-
 .../gui/qt/components/playlist/playlist_model.hpp  |  2 +-
 .../gui/qt/components/playlist/standardpanel.cpp   | 30 ++++++++++++++++++++--
 .../gui/qt/components/playlist/standardpanel.hpp   |  1 +
 modules/gui/qt/components/playlist/vlc_model.hpp   |  5 +++-
 6 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/components/playlist/playlist_item.hpp b/modules/gui/qt/components/playlist/playlist_item.hpp
index b88314b1ff..ec310d8837 100644
--- a/modules/gui/qt/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt/components/playlist/playlist_item.hpp
@@ -50,7 +50,9 @@ protected:
     int indexOf( AbstractPLItem *item ) const { return children.indexOf( item ); };
     int lastIndexOf( AbstractPLItem *item ) const { return children.lastIndexOf( item ); };
     AbstractPLItem *parent() { return parentItem; }
+    AbstractPLItem const*parent() const { return parentItem; }
     virtual input_item_t *inputItem() = 0;
+    virtual input_item_t const*inputItem() const = 0;
     void insertChild( AbstractPLItem *item, int pos = -1 ) { children.insert( pos, item ); }
     void appendChild( AbstractPLItem *item ) { insertChild( item, children.count() ); } ;
     virtual AbstractPLItem *child( int id ) const = 0;
@@ -77,6 +79,7 @@ private:
     /* AbstractPLItem */
     int id() const Q_DECL_OVERRIDE;
     input_item_t *inputItem() Q_DECL_OVERRIDE { return p_input; }
+    input_item_t const*inputItem() const Q_DECL_OVERRIDE { return p_input; }
     AbstractPLItem *child( int id ) const Q_DECL_OVERRIDE { return children.value( id ); };
     virtual QString getURI() const Q_DECL_OVERRIDE;
     virtual QString getTitle() const Q_DECL_OVERRIDE;
diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
index eeda0e2dc7..dcab7533a0 100644
--- a/modules/gui/qt/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt/components/playlist/playlist_model.cpp
@@ -1020,7 +1020,7 @@ bool PLModel::action( QAction *action, const QModelIndexList &indexes )
     return false;
 }
 
-bool PLModel::isSupportedAction( actions action, const QModelIndex &index ) const
+bool PLModel::isSupportedAction( actions action, const QModelIndex &index, const StandardPLPanel &panel ) const
 {
     AbstractPLItem const* item = VLCModel::getItem( index );
 
@@ -1056,6 +1056,13 @@ bool PLModel::isSupportedAction( actions action, const QModelIndex &index ) cons
 
         return playlist_Status( THEPL ) == PLAYLIST_RUNNING;
     }
+    case ACTION_BROWSE:
+        return item
+            && ( !index.data( VLCModelSubInterface::LEAF_NODE_ROLE ).toBool() ||
+                 item->inputItem()->i_type == ITEM_TYPE_DIRECTORY )
+            && ( !isTree() || !panel.isTreeItemExpanded( index ) );
+    case ACTION_SHRINK:
+        return item && panel.isTreeItemExpanded( index );
     case ACTION_STREAM:
     case ACTION_SAVE:
     case ACTION_INFO:
diff --git a/modules/gui/qt/components/playlist/playlist_model.hpp b/modules/gui/qt/components/playlist/playlist_model.hpp
index a82ec5c2c6..c4f680f463 100644
--- a/modules/gui/qt/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt/components/playlist/playlist_model.hpp
@@ -105,7 +105,7 @@ public:
     virtual bool isTree() const Q_DECL_OVERRIDE;
     virtual bool canEdit() const Q_DECL_OVERRIDE;
     virtual bool action( QAction *action, const QModelIndexList &indexes ) Q_DECL_OVERRIDE;
-    virtual bool isSupportedAction( actions action, const QModelIndex & ) const Q_DECL_OVERRIDE;
+    virtual bool isSupportedAction( actions action, const QModelIndex &, const StandardPLPanel & ) const Q_DECL_OVERRIDE;
 
 protected:
     /* VLCModel subclassing */
diff --git a/modules/gui/qt/components/playlist/standardpanel.cpp b/modules/gui/qt/components/playlist/standardpanel.cpp
index f27537a42f..b3c0afa075 100644
--- a/modules/gui/qt/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt/components/playlist/standardpanel.cpp
@@ -172,7 +172,7 @@ bool StandardPLPanel::popup( const QPoint &point )
     VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
 
 #define ADD_MENU_ENTRY( icon, title, act ) \
-    if ( model->isSupportedAction( act, index ) )\
+    if ( model->isSupportedAction( act, index, *this ) )      \
     {\
     action = menu.addAction( icon, title ); \
     container.action = act; \
@@ -195,6 +195,12 @@ bool StandardPLPanel::popup( const QPoint &point )
     ADD_MENU_ENTRY( QIcon( ":/menu/pause" ), qtr("Pause"),
                     VLCModelSubInterface::ACTION_PAUSE )
 
+    ADD_MENU_ENTRY( QIcon ( ":/type/folder-grey" ), qtr("Browse"),
+                    VLCModelSubInterface::ACTION_BROWSE )
+
+    ADD_MENU_ENTRY( QIcon ( ":/type/folder-grey" ), qtr("Shrink"),
+                    VLCModelSubInterface::ACTION_SHRINK );
+
     ADD_MENU_ENTRY( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM),
                     VLCModelSubInterface::ACTION_STREAM )
 
@@ -248,7 +254,7 @@ bool StandardPLPanel::popup( const QPoint &point )
     menu.addSeparator();
 
     /* Playlist sorting */
-    if ( model->isSupportedAction( VLCModelSubInterface::ACTION_SORT, index ) )
+    if ( model->isSupportedAction( VLCModelSubInterface::ACTION_SORT, index, *this ) )
     {
         QMenu *sortingMenu = new QMenu( qtr( "Sort by" ), &menu );
         /* Choose what columns to show in sorting menu, not sure if this should be configurable*/
@@ -304,6 +310,21 @@ void StandardPLPanel::popupAction( QAction *action )
     /* first try to complete actions requiring missing parameters thru UI dialogs */
     switch( a.action )
     {
+    case VLCModelSubInterface::ACTION_BROWSE:
+        if ( index.isValid() )
+        {
+            if ( index.data( VLCModelSubInterface::LEAF_NODE_ROLE ).toBool() )
+                activate( index );
+            else if ( currentView != treeView )
+                browseInto( index );
+            else
+                treeView->setExpanded( index, true );
+        }
+        break;
+    case VLCModelSubInterface::ACTION_SHRINK:
+        if ( index.isValid() )
+            treeView->setExpanded( index, false );
+        break;
     case VLCModelSubInterface::ACTION_INFO:
         /* locally handled only */
         if( index.isValid() )
@@ -663,6 +684,11 @@ void StandardPLPanel::createTreeView()
     viewStack->addWidget( treeView );
 }
 
+bool StandardPLPanel::isTreeItemExpanded( const QModelIndex & index ) const
+{
+    return currentView == treeView && treeView->isExpanded( index );
+}
+
 void StandardPLPanel::updateZoom( int i )
 {
     QVariant fontdata = model->data( QModelIndex(), Qt::FontRole );
diff --git a/modules/gui/qt/components/playlist/standardpanel.hpp b/modules/gui/qt/components/playlist/standardpanel.hpp
index f6f54b63c3..4e5526328f 100644
--- a/modules/gui/qt/components/playlist/standardpanel.hpp
+++ b/modules/gui/qt/components/playlist/standardpanel.hpp
@@ -68,6 +68,7 @@ public:
            VIEW_COUNT };
 
     int currentViewIndex() const;
+    bool isTreeItemExpanded( const QModelIndex & index ) const;
 
     static QMenu *viewSelectionMenu(StandardPLPanel *obj);
 
diff --git a/modules/gui/qt/components/playlist/vlc_model.hpp b/modules/gui/qt/components/playlist/vlc_model.hpp
index ea727eaca6..ae0c441ea5 100644
--- a/modules/gui/qt/components/playlist/vlc_model.hpp
+++ b/modules/gui/qt/components/playlist/vlc_model.hpp
@@ -32,6 +32,7 @@
 #include "sorting.h"
 
 #include "playlist_item.hpp"
+#include "standardpanel.hpp"
 
 #include <vlc_input.h>
 
@@ -83,6 +84,8 @@ public:
         ACTION_PLAYANDADDTOPLAYLIST = 1,
         ACTION_PLAY,
         ACTION_PAUSE,
+        ACTION_BROWSE,
+        ACTION_SHRINK,
         ACTION_STREAM,
         ACTION_SAVE,
         ACTION_INFO,
@@ -106,7 +109,7 @@ public:
         QString options;
     };
     virtual bool action( QAction *, const QModelIndexList & ) = 0;
-    virtual bool isSupportedAction( actions action, const QModelIndex & ) const = 0;
+    virtual bool isSupportedAction( actions action, const QModelIndex &, const StandardPLPanel & ) const = 0;
     static int columnFromMeta( int meta_col );
 
     virtual void activateItem( const QModelIndex &index ) = 0;
-- 
2.13.1



More information about the vlc-devel mailing list