]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/standardpanel.cpp
various modules: adjust to new playlist design
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
index f9bb59fa999e4a0f02a8ccf7da16dd814708de44..2cade837cce6fb395e90cecaf3a17bbd8fdd96a2 100644 (file)
@@ -60,14 +60,12 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     layout->setSpacing( 0 ); layout->setMargin( 0 );
     setMinimumWidth( 300 );
 
-    model = new PLModel( p_playlist, p_intf, p_root, this );
-    CONNECT( model, currentChanged( const QModelIndex& ),
-             this, handleExpansion( const QModelIndex& ) );
-
     iconView = NULL;
     treeView = NULL;
 
+    model = new PLModel( p_playlist, p_intf, p_root, this );
     currentRootId = -1;
+    last_activated_id = -1;
 
     /* Title label */
     /*title = new QLabel;
@@ -97,31 +95,46 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     BUTTONACT( addButton, popupAdd() );
     layout->addWidget( addButton, 0, 3 );
 
-    QPushButton *viewButton = new QPushButton( this );
-    viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
+    /* Button to switch views */
+    QToolButton *viewButton = new QToolButton( this );
+    viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogContentsView ) );
     layout->addWidget( viewButton, 0, 2 );
-    BUTTONACT( viewButton, toggleView() );
+
+    /* View selection menu */
+    viewSelectionMapper = new QSignalMapper( this );
+    CONNECT( viewSelectionMapper, mapped( int ), this, showView( int ) );
+
+    QActionGroup *actionGroup = new QActionGroup( this );
+
+    treeViewAction = actionGroup->addAction( "Detailed view" );
+    treeViewAction->setCheckable( true );
+    viewSelectionMapper->setMapping( treeViewAction, TREE_VIEW );
+    CONNECT( treeViewAction, triggered(), viewSelectionMapper, map() );
+
+    iconViewAction = actionGroup->addAction( "Icon view" );
+    iconViewAction->setCheckable( true );
+    viewSelectionMapper->setMapping( iconViewAction, ICON_VIEW );
+    CONNECT( iconViewAction, triggered(), viewSelectionMapper, map() );
+
+    BUTTONACT( viewButton, cycleViews() );
+    QMenu *viewMenu = new QMenu( this );
+    viewMenu->addActions( actionGroup->actions() );
+
+    viewButton->setMenu( viewMenu );
 
     /* Saved Settings */
     getSettings()->beginGroup("Playlist");
 
     int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt();
-    if( i_viewMode == ICON_VIEW )
-    {
-        createIconView();
-        currentView = iconView;
-    }
-    else
-    {
-        createTreeView();
-        currentView = treeView;
-    }
+    showView( i_viewMode );
 
     getSettings()->endGroup();
 
-    last_activated_id = -1;
-    CONNECT( THEMIM, inputChanged( input_thread_t * ),
-             this, handleInputChange( input_thread_t * ) );
+    CONNECT( THEMIM, leafBecameParent( input_item_t *),
+             this, browseInto( input_item_t * ) );
+
+    CONNECT( model, currentChanged( const QModelIndex& ),
+             this, handleExpansion( const QModelIndex& ) );
 }
 
 StandardPLPanel::~StandardPLPanel()
@@ -217,9 +230,6 @@ void StandardPLPanel::setRoot( playlist_item_t *p_item )
     QPL_LOCK;
     assert( p_item );
 
-    playlist_item_t *p_pref_item = playlist_GetPreferredNode( THEPL, p_item );
-    if( p_pref_item ) p_item = p_pref_item;
-
     /* needed for popupAdd() */
     currentRootId = p_item->i_id;
 
@@ -295,7 +305,6 @@ void StandardPLPanel::createTreeView()
 {
     /* Create and configure the QTreeView */
     treeView = new QTreeView;
-    treeView->setModel( model );
 
     treeView->setIconSize( QSize( 20, 20 ) );
     treeView->setAlternatingRowColors( true );
@@ -314,6 +323,9 @@ void StandardPLPanel::createTreeView()
     treeView->setDropIndicatorShown( true );
     treeView->setContextMenuPolicy( Qt::CustomContextMenu );
 
+    /* setModel after setSortingEnabled(true), or the model will sort immediately! */
+    treeView->setModel( model );
+
     if( getSettings()->contains( "headerStateV2" ) )
     {
         treeView->header()->restoreState(
@@ -346,28 +358,47 @@ void StandardPLPanel::createTreeView()
     layout->addWidget( treeView, 1, 0, 1, -1 );
 }
 
-void StandardPLPanel::toggleView()
+void StandardPLPanel::showView( int i_view )
 {
-    if( treeView && treeView->isVisible() )
+    switch( i_view )
+    {
+    case TREE_VIEW:
+    {
+        if( treeView == NULL )
+            createTreeView();
+        locationBar->setIndex( treeView->rootIndex() );
+        if( iconView ) iconView->hide();
+        treeView->show();
+        currentView = treeView;
+        treeViewAction->setChecked( true );
+        break;
+    }
+    case ICON_VIEW:
     {
         if( iconView == NULL )
             createIconView();
 
-        treeView->hide();
+        locationBar->setIndex( iconView->rootIndex() );
+        if( treeView ) treeView->hide();
         iconView->show();
         currentView = iconView;
+        iconViewAction->setChecked( true );
+        break;
     }
-    else
-    {
-        if( treeView == NULL )
-            createTreeView();
-
-        iconView->hide();
-        treeView->show();
-        currentView = treeView;
+    default:;
     }
 }
 
+void StandardPLPanel::cycleViews()
+{
+    if( currentView == iconView )
+        showView( TREE_VIEW );
+    else if( currentView == treeView )
+        showView( ICON_VIEW );
+    else
+        assert( 0 );
+}
+
 void StandardPLPanel::wheelEvent( QWheelEvent *e )
 {
     // Accept this event in order to prevent unwanted volume up/down changes
@@ -376,7 +407,6 @@ void StandardPLPanel::wheelEvent( QWheelEvent *e )
 
 void StandardPLPanel::activate( const QModelIndex &index )
 {
-    last_activated_id = model->itemId( index );
     if( model->hasChildren( index ) )
     {
         if( currentView == iconView ) {
@@ -387,66 +417,86 @@ void StandardPLPanel::activate( const QModelIndex &index )
     }
     else
     {
+        playlist_Lock( THEPL );
+        playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index ) );
+        p_item->i_flags |= PLAYLIST_SUBITEM_STOP_FLAG;
+        last_activated_id = p_item->p_input->i_id;//model->getItem( index )->inputItem()->i_id;
+        playlist_Unlock( THEPL );
         model->activateItem( index );
     }
 }
 
-void StandardPLPanel::handleInputChange( input_thread_t *p_input_thread )
+void StandardPLPanel::browseInto( input_item_t *p_input )
 {
-    input_item_t *p_input_item = input_GetItem( p_input_thread );
-    if( !p_input_item ) return;
 
-    playlist_Lock( THEPL );
+    if( p_input->i_id != last_activated_id ) return;
 
-    playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input_item );
+    playlist_Lock( THEPL );
 
-    if( p_item  && p_item->p_parent &&
-        p_item->p_parent->i_id == last_activated_id )
+    playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input );
+    if( !p_item )
     {
-        QModelIndex index = model->index( p_item->p_parent->i_id, 0 );
+        playlist_Unlock( THEPL );
+        return;
+    }
+
+    QModelIndex index = model->index( p_item->i_id, 0 );
+
+    playlist_Unlock( THEPL );
+
+    if( currentView == iconView ) {
         iconView->setRootIndex( index );
-        //title->setText( index.data().toString() );
         locationBar->setIndex( index );
-        last_activated_id = p_item->i_id;
     }
+    else
+        treeView->setExpanded( index, true );
+
+    last_activated_id = -1;
+
 
-    playlist_Unlock( THEPL );
 }
 
 LocationBar::LocationBar( PLModel *m )
 {
-  model = m;
-  mapper = new QSignalMapper;
-  CONNECT( mapper, mapped( int ), this, invoke( int ) );
+    model = m;
+    mapper = new QSignalMapper( this );
+    CONNECT( mapper, mapped( int ), this, invoke( int ) );
 }
 
 void LocationBar::setIndex( const QModelIndex &index )
 {
-  clear();
-  QAction *prev = NULL;
-  QModelIndex i = index;
-  QFont font;
-  QFontMetrics metrics( font );
-  while( true )
-  {
-      QToolButton *btn = new QToolButton;
-      PLItem *item = model->getItem( i );
-      QString text = input_item_GetTitleFbName( item->inputItem() );
-      text = QString("/ ") + metrics.elidedText( text, Qt::ElideRight, 150 );
-      btn->setText( text );
-      btn->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
-      prev = insertWidget( prev, btn );
-
-      mapper->setMapping( btn, item->id() );
-      CONNECT( btn, clicked( ), mapper, map( ) );
-
-      if( i.isValid() ) i = i.parent();
-      else break;
-  }
+    clear();
+    QAction *prev = NULL;
+    QModelIndex i = index;
+    QFont font;
+    QFontMetrics metrics( font );
+    font.setBold( true );
+    while( true )
+    {
+        PLItem *item = model->getItem( i );
+
+        QToolButton *btn = new QToolButton;
+        char *fb_name = input_item_GetTitleFbName( item->inputItem() );
+        QString text = qfu(fb_name);
+        free(fb_name);
+        text = QString("/ ") + metrics.elidedText( text, Qt::ElideRight, 150 );
+        btn->setText( text );
+        btn->setFont( font );
+        prev = insertWidget( prev, btn );
+
+        mapper->setMapping( btn, item->id() );
+        CONNECT( btn, clicked( ), mapper, map( ) );
+
+        font = QFont();
+
+        if( i.isValid() ) i = i.parent();
+        else break;
+    }
 }
 
 void LocationBar::invoke( int i_id )
 {
-  QModelIndex index = model->index( i_id, 0 );
-  emit invoked ( index );
+    QModelIndex index = model->index( i_id, 0 );
+    setIndex( index );
+    emit invoked ( index );
 }