]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/selector.cpp
Qt: PLSelector: add customized icons
[vlc] / modules / gui / qt4 / components / playlist / selector.cpp
1 /*****************************************************************************
2  * selector.cpp : Playlist source selector
3  ****************************************************************************
4  * Copyright (C) 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "qt4.hpp"
30 #include "components/playlist/selector.hpp"
31 #include "playlist_model.hpp"                /* plMimeData */
32 #include "input_manager.hpp"                 /* MainInputManager, for podcast */
33
34 #include <QApplication>
35 #include <QInputDialog>
36 #include <QMessageBox>
37 #include <QMimeData>
38 #include <QDragMoveEvent>
39 #include <QTreeWidgetItem>
40 #include <QHBoxLayout>
41 #include <QPainter>
42 #include <QPalette>
43 #include <QScrollBar>
44 #include <QResource>
45 #include <assert.h>
46
47 #include <vlc_playlist.h>
48 #include <vlc_services_discovery.h>
49
50 void SelectorActionButton::paintEvent( QPaintEvent *event )
51 {
52     QPainter p( this );
53     QColor color = palette().color( QPalette::HighlightedText );
54     color.setAlpha( 80 );
55     if( underMouse() )
56         p.fillRect( rect(), color );
57     p.setPen( color );
58     int frame = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this );
59     p.drawLine( rect().topLeft() + QPoint( 0, frame ),
60                 rect().bottomLeft() - QPoint( 0, frame ) );
61     QFramelessButton::paintEvent( event );
62 }
63
64 PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text )
65     : qitem(i), lblAction( NULL)
66 {
67     layout = new QHBoxLayout( this );
68     layout->setContentsMargins(0,0,0,0);
69     layout->addSpacing( 3 );
70
71     lbl = new QElidingLabel( text );
72     layout->addWidget(lbl, 1);
73
74     int height = qMax( 22, fontMetrics().height() + 8 );
75     setMinimumHeight( height );
76 }
77
78 void PLSelItem::addAction( ItemAction act, const QString& tooltip )
79 {
80     if( lblAction ) return; //might change later
81
82     QIcon icon;
83
84     switch( act )
85     {
86     case ADD_ACTION:
87         icon = QIcon( ":/buttons/playlist/playlist_add" ); break;
88     case RM_ACTION:
89         icon = QIcon( ":/buttons/playlist/playlist_remove" ); break;
90     default:
91         return;
92     }
93
94     lblAction = new SelectorActionButton();
95     lblAction->setIcon( icon );
96     lblAction->setMinimumWidth( lblAction->sizeHint().width() + 6 );
97
98     if( !tooltip.isEmpty() ) lblAction->setToolTip( tooltip );
99
100     layout->addWidget( lblAction, 0 );
101     lblAction->hide();
102
103     CONNECT( lblAction, clicked(), this, triggerAction() );
104 }
105
106
107 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
108            : QTreeWidget( p ), p_intf(_p_intf)
109 {
110     /* Properties */
111     setFrameStyle( QFrame::NoFrame );
112     setAttribute( Qt::WA_MacShowFocusRect, false );
113     viewport()->setAutoFillBackground( false );
114     setIconSize( QSize( 24,24 ) );
115     setIndentation( 12 );
116     setHeaderHidden( true );
117     setRootIsDecorated( true );
118     setAlternatingRowColors( false );
119
120     /* drops */
121     viewport()->setAcceptDrops(true);
122     setDropIndicatorShown(true);
123     invisibleRootItem()->setFlags( invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled );
124
125 #ifdef Q_WS_MAC
126     setAutoFillBackground( true );
127     QPalette palette;
128     palette.setColor( QPalette::Window, QColor(209,215,226) );
129     setPalette( palette );
130 #endif
131     setMinimumHeight( 120 );
132
133     /* Podcasts */
134     podcastsParent = NULL;
135     podcastsParentId = -1;
136
137     /* Podcast connects */
138     CONNECT( THEMIM, playlistItemAppended( int, int ),
139              this, plItemAdded( int, int ) );
140     CONNECT( THEMIM, playlistItemRemoved( int ),
141              this, plItemRemoved( int ) );
142     DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
143               this, inputItemUpdate( input_item_t * ) );
144
145     createItems();
146
147     setRootIsDecorated( false );
148     setIndentation( 5 );
149     /* Expand at least to show level 2 */
150     for ( int i = 0; i < topLevelItemCount(); i++ )
151         expandItem( topLevelItem( i ) );
152
153     /***
154      * We need to react to both clicks and activation (enter-key) here.
155      * We use curItem to avoid rebuilding twice.
156      * See QStyle::SH_ItemView_ActivateItemOnSingleClick
157      ***/
158     curItem = NULL;
159     CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
160              this, setSource( QTreeWidgetItem *) );
161     CONNECT( this, itemClicked( QTreeWidgetItem *, int ),
162              this, setSource( QTreeWidgetItem *) );
163 }
164
165 PLSelector::~PLSelector()
166 {
167     if( podcastsParent )
168     {
169         int c = podcastsParent->childCount();
170         for( int i = 0; i < c; i++ )
171         {
172             QTreeWidgetItem *item = podcastsParent->child(i);
173             input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
174             vlc_gc_decref( p_input );
175         }
176     }
177 }
178
179 PLSelItem * putSDData( PLSelItem* item, const char* name, const char* longname )
180 {
181     item->treeItem()->setData( 0, NAME_ROLE, qfu( name ) );
182     item->treeItem()->setData( 0, LONGNAME_ROLE, qfu( longname ) );
183     return item;
184 }
185
186 PLSelItem * putPLData( PLSelItem* item, playlist_item_t* plItem )
187 {
188     item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( plItem ) );
189 /*    item->setData( 0, PL_ITEM_ID_ROLE, plItem->i_id );
190     item->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( (void*) plItem->p_input ) ); );*/
191     return item;
192 }
193
194 /*
195  * Reads and updates the playlist's duration as [xx:xx] after the label in the tree
196  * item - the treeview item to get the duration for
197  * prefix - the string to use before the time (should be the category name)
198  */
199 void PLSelector::updateTotalDuration( PLSelItem* item, const char* prefix )
200 {
201     /* Getting  the playlist */
202     QVariant playlistVariant = item->treeItem()->data( 0, PL_ITEM_ROLE );
203     playlist_item_t* node = playlistVariant.value<playlist_item_t*>();
204
205     /* Get the duration of the playlist item */
206     playlist_Lock( THEPL );
207     mtime_t mt_duration = playlist_GetNodeDuration( node );
208     playlist_Unlock( THEPL );
209
210     /* Formatting time */
211     QString qs_timeLabel( prefix );
212
213     int i_seconds = mt_duration / 1000000;
214     int i_minutes = i_seconds / 60;
215     i_seconds = i_seconds % 60;
216     if( i_minutes >= 60 )
217     {
218         int i_hours = i_minutes / 60;
219         i_minutes = i_minutes % 60;
220         qs_timeLabel += QString(" [%1:%2:%3]").arg( i_hours ).arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
221     }
222     else
223         qs_timeLabel += QString( " [%1:%2]").arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
224
225     item->setText( qs_timeLabel );
226 }
227
228 void PLSelector::createItems()
229 {
230     /* PL */
231     playlistItem = putPLData( addItem( PL_ITEM_TYPE, N_("Playlist"), true ),
232                               THEPL->p_playing );
233     playlistItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
234     playlistItem->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/playlist" ) );
235     setCurrentItem( playlistItem->treeItem() );
236
237     /* ML */
238     PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, N_("Media Library"), true ),
239                               THEPL->p_media_library );
240     ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
241     ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );
242
243 #ifdef MEDIA_LIBRARY
244     /* SQL ML */
245     ml = addItem( SQL_ML_TYPE, "SQL Media Library" )->treeItem();
246     ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );
247 #endif
248
249     /* SD nodes */
250     QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, N_("My Computer"), false, true )->treeItem();
251     QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, N_("Devices"), false, true )->treeItem();
252     QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, N_("Local Network"), false, true )->treeItem();
253     QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, N_("Internet"), false, true )->treeItem();
254
255 #define NOT_SELECTABLE(w) w->setFlags( w->flags() ^ Qt::ItemIsSelectable );
256     NOT_SELECTABLE( mycomp );
257     NOT_SELECTABLE( devices );
258     NOT_SELECTABLE( lan );
259     NOT_SELECTABLE( internet );
260 #undef NOT_SELECTABLE
261
262     /* SD subnodes */
263     char **ppsz_longnames;
264     int *p_categories;
265     char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
266     if( !ppsz_names )
267         return;
268
269     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
270     int *p_category = p_categories;
271     for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
272     {
273         //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
274
275         PLSelItem *selItem;
276         QIcon icon;
277         QString name( *ppsz_name );
278         switch( *p_category )
279         {
280         case SD_CAT_INTERNET:
281             {
282             selItem = addItem( SD_TYPE, *ppsz_longname, false, false, internet );
283             if( name.startsWith( "podcast" ) )
284             {
285                 selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
286                 selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
287                 CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
288                 podcastsParent = selItem->treeItem();
289                 icon = QIcon( ":/sidebar/podcast" );
290             }
291             else if ( name.startsWith( "lua{" ) )
292             {
293                 int i_head = name.indexOf( "sd='" ) + 4;
294                 int i_tail = name.indexOf( '\'', i_head );
295                 name.mid( i_head, i_tail - i_head );
296                 QString iconname = QString( ":/sidebar/sd/%1" ).arg( name.mid( i_head, i_tail - i_head ) );
297                 QResource resource( iconname );
298                 if ( !resource.isValid() )
299                     icon = QIcon( ":/sidebar/network" );
300                 else
301                     icon = QIcon( iconname );
302             }
303             }
304             break;
305         case SD_CAT_DEVICES:
306             name = name.mid( 0, name.indexOf( '{' ) );
307             selItem = addItem( SD_TYPE, *ppsz_longname, false, false, devices );
308             if ( name == "xcb_apps" )
309                 icon = QIcon( ":/sidebar/screen" );
310             else if ( name == "mtp" )
311                 icon = QIcon( ":/sidebar/mtp" );
312             else if ( name == "disc" )
313                 icon = QIcon( ":/sidebar/disc" );
314             else
315                 icon = QIcon( ":/sidebar/capture" );
316             break;
317         case SD_CAT_LAN:
318             selItem = addItem( SD_TYPE, *ppsz_longname, false, false, lan );
319             icon = QIcon( ":/sidebar/lan" );
320             break;
321         case SD_CAT_MYCOMPUTER:
322             name = name.mid( 0, name.indexOf( '{' ) );
323             selItem = addItem( SD_TYPE, *ppsz_longname, false, false, mycomp );
324             if ( name == "video_dir" )
325                 icon = QIcon( ":/sidebar/movie" );
326             else if ( name == "audio_dir" )
327                 icon = QIcon( ":/sidebar/music" );
328             else if ( name == "picture_dir" )
329                 icon = QIcon( ":/sidebar/pictures" );
330             else
331                 icon = QIcon( ":/sidebar/movie" );
332             break;
333         default:
334             selItem = addItem( SD_TYPE, *ppsz_longname );
335         }
336
337         putSDData( selItem, *ppsz_name, *ppsz_longname );
338         if ( ! icon.isNull() )
339             selItem->treeItem()->setData( 0, Qt::DecorationRole, icon );
340
341         free( *ppsz_name );
342         free( *ppsz_longname );
343     }
344     free( ppsz_names );
345     free( ppsz_longnames );
346     free( p_categories );
347
348     if( mycomp->childCount() == 0 ) delete mycomp;
349     if( devices->childCount() == 0 ) delete devices;
350     if( lan->childCount() == 0 ) delete lan;
351     if( internet->childCount() == 0 ) delete internet;
352 }
353
354 void PLSelector::setSource( QTreeWidgetItem *item )
355 {
356     if( !item || item == curItem )
357         return;
358
359     bool b_ok;
360     int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok );
361     if( !b_ok || i_type == CATEGORY_TYPE )
362         return;
363
364     bool sd_loaded;
365     if( i_type == SD_TYPE )
366     {
367         QString qs = item->data( 0, NAME_ROLE ).toString();
368         sd_loaded = playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) );
369         if( !sd_loaded )
370         {
371             if ( playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) ) != VLC_SUCCESS )
372                 return ;
373
374             services_discovery_descriptor_t *p_test = new services_discovery_descriptor_t;
375             int i_ret = playlist_ServicesDiscoveryControl( THEPL, qtu( qs ), SD_CMD_DESCRIPTOR, p_test );
376             if( i_ret == VLC_SUCCESS && p_test->i_capabilities & SD_CAP_SEARCH )
377                 item->setData( 0, CAP_SEARCH_ROLE, true );
378         }
379     }
380 #ifdef MEDIA_LIBRARY
381     else if( i_type == SQL_ML_TYPE )
382     {
383         emit categoryActivated( NULL, true );
384         curItem = item;
385         return;
386     }
387 #endif
388
389     curItem = item;
390
391     /* */
392     playlist_Lock( THEPL );
393     playlist_item_t *pl_item = NULL;
394
395     /* Special case for podcast */
396     // FIXME: simplify
397     if( i_type == SD_TYPE )
398     {
399         /* Find the right item for the SD */
400         pl_item = playlist_ChildSearchName( THEPL->p_root,
401                       qtu( item->data(0, LONGNAME_ROLE ).toString() ) );
402
403         /* Podcasts */
404         if( item->data( 0, SPECIAL_ROLE ).toInt() == IS_PODCAST )
405         {
406             if( pl_item && !sd_loaded )
407             {
408                 podcastsParentId = pl_item->i_id;
409                 for( int i=0; i < pl_item->i_children; i++ )
410                     addPodcastItem( pl_item->pp_children[i] );
411             }
412             pl_item = NULL; //to prevent activating it
413         }
414     }
415     else
416         pl_item = item->data( 0, PL_ITEM_ROLE ).value<playlist_item_t*>();
417
418     playlist_Unlock( THEPL );
419
420     /* */
421     if( pl_item )
422         emit categoryActivated( pl_item, false );
423 }
424
425 PLSelItem * PLSelector::addItem (
426     SelectorItemType type, const char* str, bool drop, bool bold,
427     QTreeWidgetItem* parentItem )
428 {
429   QTreeWidgetItem *item = parentItem ?
430       new QTreeWidgetItem( parentItem ) : new QTreeWidgetItem( this );
431
432   PLSelItem *selItem = new PLSelItem( item, qtr( str ) );
433   if ( bold ) selItem->setStyleSheet( "font-weight: bold;" );
434   setItemWidget( item, 0, selItem );
435   item->setData( 0, TYPE_ROLE, (int)type );
436   if( !drop ) item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
437
438   return selItem;
439 }
440
441 PLSelItem *PLSelector::addPodcastItem( playlist_item_t *p_item )
442 {
443     vlc_gc_incref( p_item->p_input );
444
445     char *psz_name = input_item_GetName( p_item->p_input );
446     PLSelItem *item = addItem( PL_ITEM_TYPE,  psz_name, false, false, podcastsParent );
447     free( psz_name );
448
449     item->addAction( RM_ACTION, qtr( "Remove this podcast subscription" ) );
450     item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( p_item ) );
451     item->treeItem()->setData( 0, PL_ITEM_ID_ROLE, QVariant(p_item->i_id) );
452     item->treeItem()->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( p_item->p_input ) );
453     CONNECT( item, action( PLSelItem* ), this, podcastRemove( PLSelItem* ) );
454     return item;
455 }
456
457 QStringList PLSelector::mimeTypes() const
458 {
459     QStringList types;
460     types << "vlc/qt-input-items";
461     return types;
462 }
463
464 bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int,
465     const QMimeData * data, Qt::DropAction )
466 {
467     if( !parent ) return false;
468
469     QVariant type = parent->data( 0, TYPE_ROLE );
470     if( type == QVariant() ) return false;
471
472     int i_truth = parent->data( 0, SPECIAL_ROLE ).toInt();
473     if( i_truth != IS_PL && i_truth != IS_ML ) return false;
474
475     bool to_pl = ( i_truth == IS_PL );
476
477     const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
478     if( !plMimeData ) return false;
479
480     QList<input_item_t*> inputItems = plMimeData->inputItems();
481
482     playlist_Lock( THEPL );
483
484     foreach( input_item_t *p_input, inputItems )
485     {
486         playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input );
487         if( !p_item ) continue;
488
489         playlist_NodeAddCopy( THEPL, p_item,
490                               to_pl ? THEPL->p_playing : THEPL->p_media_library,
491                               PLAYLIST_END );
492     }
493
494     playlist_Unlock( THEPL );
495
496     return true;
497 }
498
499 void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
500 {
501     event->setDropAction( Qt::CopyAction );
502     QAbstractItemView::dragMoveEvent( event );
503 }
504
505 void PLSelector::plItemAdded( int item, int parent )
506 {
507     updateTotalDuration(playlistItem, "Playlist");
508     if( parent != podcastsParentId || podcastsParent == NULL ) return;
509
510     playlist_Lock( THEPL );
511
512     playlist_item_t *p_item = playlist_ItemGetById( THEPL, item );
513     if( !p_item ) {
514         playlist_Unlock( THEPL );
515         return;
516     }
517
518     int c = podcastsParent->childCount();
519     for( int i = 0; i < c; i++ )
520     {
521         QTreeWidgetItem *podItem = podcastsParent->child(i);
522         if( podItem->data( 0, PL_ITEM_ID_ROLE ).toInt() == item )
523         {
524           //msg_Dbg( p_intf, "Podcast already in: (%d) %s", item, p_item->p_input->psz_uri);
525           playlist_Unlock( THEPL );
526           return;
527         }
528     }
529
530     //msg_Dbg( p_intf, "Adding podcast: (%d) %s", item, p_item->p_input->psz_uri );
531     addPodcastItem( p_item );
532
533     playlist_Unlock( THEPL );
534
535     podcastsParent->setExpanded( true );
536 }
537
538 void PLSelector::plItemRemoved( int id )
539 {
540     updateTotalDuration(playlistItem, "Playlist");
541     if( !podcastsParent ) return;
542
543     int c = podcastsParent->childCount();
544     for( int i = 0; i < c; i++ )
545     {
546         QTreeWidgetItem *item = podcastsParent->child(i);
547         if( item->data( 0, PL_ITEM_ID_ROLE ).toInt() == id )
548         {
549             input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
550             //msg_Dbg( p_intf, "Removing podcast: (%d) %s", id, p_input->psz_uri );
551             vlc_gc_decref( p_input );
552             delete item;
553             return;
554         }
555     }
556 }
557
558 void PLSelector::inputItemUpdate( input_item_t *arg )
559 {
560     updateTotalDuration(playlistItem, "Playlist");
561
562     if( podcastsParent == NULL )
563         return;
564
565     int c = podcastsParent->childCount();
566     for( int i = 0; i < c; i++ )
567     {
568         QTreeWidgetItem *item = podcastsParent->child(i);
569         input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
570         if( p_input == arg )
571         {
572             PLSelItem *si = itemWidget( item );
573             char *psz_name = input_item_GetName( p_input );
574             si->setText( qfu( psz_name ) );
575             free( psz_name );
576             return;
577         }
578     }
579 }
580
581 void PLSelector::podcastAdd( PLSelItem * )
582 {
583     assert( podcastsParent );
584
585     bool ok;
586     QString url = QInputDialog::getText( this, qtr( "Subscribe" ),
587                                          qtr( "Enter URL of the podcast to subscribe to:" ),
588                                          QLineEdit::Normal, QString(), &ok );
589     if( !ok || url.isEmpty() ) return;
590
591     setSource( podcastsParent ); //to load the SD in case it's not loaded
592
593     vlc_object_t *p_obj = (vlc_object_t*) vlc_object_find_name( p_intf->p_libvlc, "podcast" );
594     if( !p_obj ) return;
595
596     QString request("ADD:");
597     request += url.trimmed();
598     var_SetString( p_obj, "podcast-request", qtu( request ) );
599     vlc_object_release( p_obj );
600 }
601
602 void PLSelector::podcastRemove( PLSelItem* item )
603 {
604     QString question ( qtr( "Do you really want to unsubscribe from %1?" ) );
605     question = question.arg( item->text() );
606     QMessageBox::StandardButton res =
607         QMessageBox::question( this, qtr( "Unsubscribe" ), question,
608                                QMessageBox::Yes | QMessageBox::No,
609                                QMessageBox::No );
610     if( res == QMessageBox::No ) return;
611
612     input_item_t *input = item->treeItem()->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
613     if( !input ) return;
614
615     vlc_object_t *p_obj = (vlc_object_t*) vlc_object_find_name(
616         p_intf->p_libvlc, "podcast" );
617     if( !p_obj ) return;
618
619     QString request("RM:");
620     char *psz_uri = input_item_GetURI( input );
621     request += qfu( psz_uri );
622     var_SetString( p_obj, "podcast-request", qtu( request ) );
623     vlc_object_release( p_obj );
624     free( psz_uri );
625 }
626
627 PLSelItem * PLSelector::itemWidget( QTreeWidgetItem *item )
628 {
629     return ( static_cast<PLSelItem*>( QTreeWidget::itemWidget( item, 0 ) ) );
630 }
631
632 void PLSelector::drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) const
633 {
634     if( !model()->hasChildren( index ) ) return;
635     QStyleOption option;
636     option.initFrom( this );
637     option.rect = rect.adjusted( rect.width() - indentation(), 0, 0, 0 );
638     style()->drawPrimitive( isExpanded( index ) ?
639                             QStyle::PE_IndicatorArrowDown :
640                             QStyle::PE_IndicatorArrowRight, &option, painter );
641 }
642
643 void PLSelector::getCurrentItemInfos( int* type, bool* can_delay_search, QString *string)
644 {
645     *type = currentItem()->data( 0, TYPE_ROLE ).toInt();
646     *string = currentItem()->data( 0, NAME_ROLE ).toString();
647     *can_delay_search = currentItem()->data( 0, CAP_SEARCH_ROLE ).toBool();
648 }
649
650 int PLSelector::getCurrentItemCategory()
651 {
652     return currentItem()->data( 0, SPECIAL_ROLE ).toInt();
653 }
654
655 void PLSelector::wheelEvent( QWheelEvent *e )
656 {
657     if( verticalScrollBar()->isVisible() && (
658         (verticalScrollBar()->value() != verticalScrollBar()->minimum() && e->delta() >= 0 ) ||
659         (verticalScrollBar()->value() != verticalScrollBar()->maximum() && e->delta() < 0 )
660         ) )
661         QApplication::sendEvent(verticalScrollBar(), e);
662
663     // Accept this event in order to prevent unwanted volume up/down changes
664     e->accept();
665 }