[vlc-devel] [PATCH 1/6] Added a new button for playlist shuffle. So far the button invokes a dummy procedure.

Martin Zeman dileptor at gmail.com
Sat Mar 9 00:17:19 CET 2013


---
 modules/gui/qt4/components/playlist/playlist.cpp   |    8 +++
 .../gui/qt4/components/playlist/standardpanel.cpp  |   66 ++++++++++++++++++++
 .../gui/qt4/components/playlist/standardpanel.hpp  |    1 +
 3 files changed, 75 insertions(+)

diff --git a/modules/gui/qt4/components/playlist/playlist.cpp b/modules/gui/qt4/components/playlist/playlist.cpp
index 3598743..59d0b8c 100644
--- a/modules/gui/qt4/components/playlist/playlist.cpp
+++ b/modules/gui/qt4/components/playlist/playlist.cpp
@@ -123,6 +123,14 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     viewButton->setMenu( StandardPLPanel::viewSelectionMenu( mainView ));
     CONNECT( viewButton, clicked(), mainView, cycleViews() );
 
+    /* Button to shuffle playlist */
+    QToolButton *shuffleButton = new QToolButton( this );
+    shuffleButton->setIcon(QIcon( ":/buttons/playlist/shuffle_on"));
+    shuffleButton->setToolTip( qtr("Shuffle the playlist") );
+    topbarLayout->addWidget( shuffleButton );
+
+    CONNECT( shuffleButton, clicked(), mainView, shufflePlaylist() ); /* cycleViews will be replaced by the shuffle method*/
+
     /* Search */
     searchEdit = new SearchLineEdit( this );
     searchEdit->setMaximumWidth( 250 );
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 35e6117..54e62b1 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -710,6 +710,72 @@ void StandardPLPanel::cycleViews()
         assert( 0 );
 }
 
+void StandardPLPanel::shufflePlaylist(const QModelIndex &index )
+{
+ /*My code to shuffle and fill the Playrlist*/
+    /*playlist_Lock( THEPL );
+
+    playlist_item_t *p_temp;
+    playlist_item_array_t pp_items = THEPL->all_items;
+    p_temp = pp_items[0];
+	pp_items[0] = pp_items[1];
+	pp_items[1] = p_temp;
+	playlist_Unlock( THEPL );*/
+
+	FOREACH_ARRAY( playlist_item_t *p_del, THEPL->all_items )
+	        free( p_del->pp_children );
+	        vlc_gc_decref( p_del->p_input );
+	        free( p_del );
+	    FOREACH_END();
+
+	    vlc_object_release( THEPL );
+
+	//if( currentView->model() == model )
+	   // {
+	        /* If we are not a leaf node */
+	      //  if( !index.data( PLModel::IsLeafNodeRole ).toBool() )
+	        //{
+	         //   if( currentView != treeView )
+	         //       browseInto( index );
+	        //}
+	        //else
+	        //{
+	            /*playlist_Lock( THEPL );
+	            playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index ) );
+	            playlist_item_t *p_item_two = playlist_ItemGetById( THEPL, model->itemId( 2 ) );
+	            p_item->i_flags |= PLAYLIST_SUBITEM_STOP_FLAG;
+	            lastActivatedId = p_item->i_id;
+	            playlist_Unlock( THEPL );
+	            model->activateItem( index );*/
+	        //}
+	   // }
+
+	//FOR INSPECTION
+			/*static inline
+		void playlist_ItemArraySort( unsigned i_items, playlist_item_t **pp_items,
+									 sortfn_t p_sortfn )
+		{
+			if( p_sortfn )
+			{
+				qsort( pp_items, i_items, sizeof( pp_items[0] ), p_sortfn );
+			}
+			else
+			{
+				unsigned i_position;
+				unsigned i_new;
+				playlist_item_t *p_temp;
+
+				for( i_position = i_items - 1; i_position > 0; i_position-- )
+				{
+					i_new = ((unsigned)vlc_mrand48()) % (i_position+1);
+					p_temp = pp_items[i_position];
+					pp_items[i_position] = pp_items[i_new];
+					pp_items[i_new] = p_temp;
+				}
+			}
+		} */
+}
+
 void StandardPLPanel::activate( const QModelIndex &index )
 {
     if( currentView->model() == model )
diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp
index 725d79e..e8e3757 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.hpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.hpp
@@ -140,6 +140,7 @@ private slots:
     void toggleColumnShown( int );
 
     void cycleViews();
+    void shufflePlaylist(const QModelIndex & );
 
 signals:
     void viewChanged( const QModelIndex& );
-- 
1.7.9.5




More information about the vlc-devel mailing list