1 /*****************************************************************************
2 * playlist.cpp : Custom widgets for the playlist
3 ****************************************************************************
4 * Copyright © 2007-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include "components/playlist/panels.hpp"
30 #include "components/playlist/selector.hpp"
31 #include "components/playlist/playlist.hpp"
33 #include "input_manager.hpp" /* art signal */
34 #include "main_interface.hpp" /* DropEvent TODO remove this*/
39 /**********************************************************************
40 * Playlist Widget. The embedded playlist
41 **********************************************************************/
43 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
45 setContentsMargins( 3, 3, 3, 3 );
47 /* Left Part and design */
48 QSplitter *leftW = new QSplitter( Qt::Vertical, this );
51 selector = new PLSelector( this, p_intf );
52 QVBoxLayout *selBox = new QVBoxLayout();
53 selBox->setContentsMargins(0,5,0,0);
54 selBox->addWidget( selector );
55 QGroupBox *selGroup = new QGroupBox( qtr( "Media Browser") );
56 selGroup->setLayout( selBox );
57 leftW->addWidget( selGroup );
59 /* Create a Container for the Art Label
60 in order to have a beautiful resizing for the selector above it */
61 QWidget *artContainer = new QWidget;
62 QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
63 artContLay->setMargin( 0 );
64 artContLay->setSpacing( 0 );
65 artContainer->setMaximumHeight( 128 );
68 art = new ArtLabel( artContainer, p_intf );
69 art->setToolTip( qtr( "Double click to get media information" ) );
71 CONNECT( THEMIM->getIM(), artChanged( QString ),
72 art, showArtUpdate( const QString& ) );
74 artContLay->addWidget( art, 1 );
76 leftW->addWidget( artContainer );
78 /* Initialisation of the playlist */
79 playlist_t * p_playlist = THEPL;
81 playlist_item_t *p_root =
82 playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
85 rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
87 /* Connect the activation of the selector to a redefining of the PL */
88 CONNECT( selector, activated( playlist_item_t * ),
89 rightPanel, setRoot( playlist_item_t * ) );
91 rightPanel->setRoot( p_root );
93 /* Add the two sides of the QSplitter */
95 addWidget( rightPanel );
98 sizeList << 180 << 420 ;
100 //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
101 setStretchFactor( 0, 0 );
102 setStretchFactor( 1, 3 );
103 leftW->setMaximumWidth( 250 );
104 setCollapsible( 1, false );
106 /* In case we want to keep the splitter informations */
107 // components shall never write there setting to a fixed location, may infer
108 // with other uses of the same component...
109 // getSettings()->beginGroup( "playlist" );
110 getSettings()->beginGroup("Playlist");
111 restoreState( getSettings()->value("splitterSizes").toByteArray());
112 getSettings()->endGroup();
114 setAcceptDrops( true );
115 setWindowTitle( qtr( "Playlist" ) );
116 setWindowRole( "vlc-playlist" );
117 setWindowIcon( QApplication::windowIcon() );
120 PlaylistWidget::~PlaylistWidget()
122 getSettings()->beginGroup("Playlist");
123 getSettings()->setValue( "splitterSizes", saveState() );
124 getSettings()->endGroup();
125 msg_Dbg( p_intf, "Playlist Destroyed" );
128 void PlaylistWidget::dropEvent( QDropEvent *event )
130 if( p_intf->p_sys->p_mi )
131 p_intf->p_sys->p_mi->dropEventPlay( event, false );
133 void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
135 event->acceptProposedAction();
138 void PlaylistWidget::closeEvent( QCloseEvent *event )
140 if( THEDP->isDying() )
142 /* FIXME is it needed ? */
152 PlaylistEventManager::PlaylistEventManager( playlist_t *_pl )
155 var_AddCallback( pl, "playlist-item-append", itemAddedCb, this );
156 var_AddCallback( pl, "playlist-item-deleted", itemRemovedCb, this );
159 PlaylistEventManager::~PlaylistEventManager()
161 var_DelCallback( pl, "playlist-item-append", itemAddedCb, this );
162 var_DelCallback( pl, "playlist-item-deleted", itemRemovedCb, this );
165 int PlaylistEventManager::itemAddedCb
166 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
168 PlaylistEventManager *p_this = static_cast<PlaylistEventManager*>(data);
169 p_this->trigger( cur, ItemAddedEv );
173 int PlaylistEventManager::itemRemovedCb
174 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
176 PlaylistEventManager *p_this = static_cast<PlaylistEventManager*>(data);
177 p_this->trigger( cur, ItemRemovedEv );
181 void PlaylistEventManager::trigger( vlc_value_t val, int type )
183 if( type == ItemAddedEv )
185 playlist_add_t *p_add = static_cast<playlist_add_t*>( val.p_address );
186 QApplication::postEvent( this, new PLEMEvent( type, p_add->i_item, p_add->i_node ) );
190 QApplication::postEvent( this, new PLEMEvent( type, val.i_int, 0 ) );
194 void PlaylistEventManager::customEvent( QEvent *e )
196 PLEMEvent *ev = static_cast<PLEMEvent*>(e);
197 if( (int) ev->type() == ItemAddedEv )
198 emit itemAdded( ev->item, ev->parent );
200 emit itemRemoved( ev->item );