]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/selector.cpp
Qt: PLSelector: add customized icons
[vlc] / modules / gui / qt4 / components / playlist / selector.cpp
index e2881de7de41e916bb91c9cb18283b85e0fa4bd9..8b4c0ccd16d7307c9506addaff4aaa2770d8622a 100644 (file)
 # include "config.h"
 #endif
 
-#include <assert.h>
-
-#include "components/playlist/selector.hpp"
-#include "playlist_model.hpp"
 #include "qt4.hpp"
-#include "../../dialogs_provider.hpp"
-#include "playlist.hpp"
-#include "util/customwidgets.hpp"
+#include "components/playlist/selector.hpp"
+#include "playlist_model.hpp"                /* plMimeData */
+#include "input_manager.hpp"                 /* MainInputManager, for podcast */
 
-#include <QVBoxLayout>
-#include <QHeaderView>
-#include <QMimeData>
+#include <QApplication>
 #include <QInputDialog>
 #include <QMessageBox>
+#include <QMimeData>
+#include <QDragMoveEvent>
+#include <QTreeWidgetItem>
+#include <QHBoxLayout>
+#include <QPainter>
+#include <QPalette>
+#include <QScrollBar>
+#include <QResource>
+#include <assert.h>
 
 #include <vlc_playlist.h>
 #include <vlc_services_discovery.h>
@@ -55,22 +58,19 @@ void SelectorActionButton::paintEvent( QPaintEvent *event )
     int frame = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this );
     p.drawLine( rect().topLeft() + QPoint( 0, frame ),
                 rect().bottomLeft() - QPoint( 0, frame ) );
-    QVLCFramelessButton::paintEvent( event );
+    QFramelessButton::paintEvent( event );
 }
 
 PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text )
     : qitem(i), lblAction( NULL)
 {
-    layout = new QHBoxLayout();
+    layout = new QHBoxLayout( this );
     layout->setContentsMargins(0,0,0,0);
     layout->addSpacing( 3 );
 
-    lbl = new QVLCElidingLabel( text );
-
+    lbl = new QElidingLabel( text );
     layout->addWidget(lbl, 1);
 
-    setLayout( layout );
-
     int height = qMax( 22, fontMetrics().height() + 8 );
     setMinimumHeight( height );
 }
@@ -87,6 +87,8 @@ void PLSelItem::addAction( ItemAction act, const QString& tooltip )
         icon = QIcon( ":/buttons/playlist/playlist_add" ); break;
     case RM_ACTION:
         icon = QIcon( ":/buttons/playlist/playlist_remove" ); break;
+    default:
+        return;
     }
 
     lblAction = new SelectorActionButton();
@@ -101,33 +103,38 @@ void PLSelItem::addAction( ItemAction act, const QString& tooltip )
     CONNECT( lblAction, clicked(), this, triggerAction() );
 }
 
-void PLSelItem::showAction() { if( lblAction ) lblAction->show(); }
-
-void PLSelItem::hideAction() { if( lblAction ) lblAction->hide(); }
-
-void PLSelItem::setText( const QString& text ) { lbl->setText( text ); }
-
-void PLSelItem::enterEvent( QEvent *ev ){ showAction(); }
-
-void PLSelItem::leaveEvent( QEvent *ev ){ hideAction(); }
 
 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
            : QTreeWidget( p ), p_intf(_p_intf)
 {
+    /* Properties */
     setFrameStyle( QFrame::NoFrame );
+    setAttribute( Qt::WA_MacShowFocusRect, false );
     viewport()->setAutoFillBackground( false );
     setIconSize( QSize( 24,24 ) );
     setIndentation( 12 );
-    header()->hide();
+    setHeaderHidden( true );
     setRootIsDecorated( true );
     setAlternatingRowColors( false );
-    podcastsParent = NULL;
-    podcastsParentId = -1;
 
+    /* drops */
     viewport()->setAcceptDrops(true);
     setDropIndicatorShown(true);
     invisibleRootItem()->setFlags( invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled );
 
+#ifdef Q_WS_MAC
+    setAutoFillBackground( true );
+    QPalette palette;
+    palette.setColor( QPalette::Window, QColor(209,215,226) );
+    setPalette( palette );
+#endif
+    setMinimumHeight( 120 );
+
+    /* Podcasts */
+    podcastsParent = NULL;
+    podcastsParentId = -1;
+
+    /* Podcast connects */
     CONNECT( THEMIM, playlistItemAppended( int, int ),
              this, plItemAdded( int, int ) );
     CONNECT( THEMIM, playlistItemRemoved( int ),
@@ -136,18 +143,23 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
               this, inputItemUpdate( input_item_t * ) );
 
     createItems();
+
+    setRootIsDecorated( false );
+    setIndentation( 5 );
+    /* Expand at least to show level 2 */
+    for ( int i = 0; i < topLevelItemCount(); i++ )
+        expandItem( topLevelItem( i ) );
+
+    /***
+     * We need to react to both clicks and activation (enter-key) here.
+     * We use curItem to avoid rebuilding twice.
+     * See QStyle::SH_ItemView_ActivateItemOnSingleClick
+     ***/
+    curItem = NULL;
     CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
              this, setSource( QTreeWidgetItem *) );
     CONNECT( this, itemClicked( QTreeWidgetItem *, int ),
              this, setSource( QTreeWidgetItem *) );
-
-    /* I believe this is unnecessary, seeing
-       QStyle::SH_ItemView_ActivateItemOnSingleClick
-        CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
-             this, setSource( QTreeWidgetItem *) ); */
-
-    /* select the first item */
-//  view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
 }
 
 PLSelector::~PLSelector()
@@ -164,9 +176,184 @@ PLSelector::~PLSelector()
     }
 }
 
+PLSelItem * putSDData( PLSelItem* item, const char* name, const char* longname )
+{
+    item->treeItem()->setData( 0, NAME_ROLE, qfu( name ) );
+    item->treeItem()->setData( 0, LONGNAME_ROLE, qfu( longname ) );
+    return item;
+}
+
+PLSelItem * putPLData( PLSelItem* item, playlist_item_t* plItem )
+{
+    item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( plItem ) );
+/*    item->setData( 0, PL_ITEM_ID_ROLE, plItem->i_id );
+    item->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( (void*) plItem->p_input ) ); );*/
+    return item;
+}
+
+/*
+ * Reads and updates the playlist's duration as [xx:xx] after the label in the tree
+ * item - the treeview item to get the duration for
+ * prefix - the string to use before the time (should be the category name)
+ */
+void PLSelector::updateTotalDuration( PLSelItem* item, const char* prefix )
+{
+    /* Getting  the playlist */
+    QVariant playlistVariant = item->treeItem()->data( 0, PL_ITEM_ROLE );
+    playlist_item_t* node = playlistVariant.value<playlist_item_t*>();
+
+    /* Get the duration of the playlist item */
+    playlist_Lock( THEPL );
+    mtime_t mt_duration = playlist_GetNodeDuration( node );
+    playlist_Unlock( THEPL );
+
+    /* Formatting time */
+    QString qs_timeLabel( prefix );
+
+    int i_seconds = mt_duration / 1000000;
+    int i_minutes = i_seconds / 60;
+    i_seconds = i_seconds % 60;
+    if( i_minutes >= 60 )
+    {
+        int i_hours = i_minutes / 60;
+        i_minutes = i_minutes % 60;
+        qs_timeLabel += QString(" [%1:%2:%3]").arg( i_hours ).arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
+    }
+    else
+        qs_timeLabel += QString( " [%1:%2]").arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
+
+    item->setText( qs_timeLabel );
+}
+
+void PLSelector::createItems()
+{
+    /* PL */
+    playlistItem = putPLData( addItem( PL_ITEM_TYPE, N_("Playlist"), true ),
+                              THEPL->p_playing );
+    playlistItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
+    playlistItem->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/playlist" ) );
+    setCurrentItem( playlistItem->treeItem() );
+
+    /* ML */
+    PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, N_("Media Library"), true ),
+                              THEPL->p_media_library );
+    ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
+    ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );
+
+#ifdef MEDIA_LIBRARY
+    /* SQL ML */
+    ml = addItem( SQL_ML_TYPE, "SQL Media Library" )->treeItem();
+    ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );
+#endif
+
+    /* SD nodes */
+    QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, N_("My Computer"), false, true )->treeItem();
+    QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, N_("Devices"), false, true )->treeItem();
+    QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, N_("Local Network"), false, true )->treeItem();
+    QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, N_("Internet"), false, true )->treeItem();
+
+#define NOT_SELECTABLE(w) w->setFlags( w->flags() ^ Qt::ItemIsSelectable );
+    NOT_SELECTABLE( mycomp );
+    NOT_SELECTABLE( devices );
+    NOT_SELECTABLE( lan );
+    NOT_SELECTABLE( internet );
+#undef NOT_SELECTABLE
+
+    /* SD subnodes */
+    char **ppsz_longnames;
+    int *p_categories;
+    char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
+    if( !ppsz_names )
+        return;
+
+    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
+    int *p_category = p_categories;
+    for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
+    {
+        //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
+
+        PLSelItem *selItem;
+        QIcon icon;
+        QString name( *ppsz_name );
+        switch( *p_category )
+        {
+        case SD_CAT_INTERNET:
+            {
+            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, internet );
+            if( name.startsWith( "podcast" ) )
+            {
+                selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
+                selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
+                CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
+                podcastsParent = selItem->treeItem();
+                icon = QIcon( ":/sidebar/podcast" );
+            }
+            else if ( name.startsWith( "lua{" ) )
+            {
+                int i_head = name.indexOf( "sd='" ) + 4;
+                int i_tail = name.indexOf( '\'', i_head );
+                name.mid( i_head, i_tail - i_head );
+                QString iconname = QString( ":/sidebar/sd/%1" ).arg( name.mid( i_head, i_tail - i_head ) );
+                QResource resource( iconname );
+                if ( !resource.isValid() )
+                    icon = QIcon( ":/sidebar/network" );
+                else
+                    icon = QIcon( iconname );
+            }
+            }
+            break;
+        case SD_CAT_DEVICES:
+            name = name.mid( 0, name.indexOf( '{' ) );
+            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, devices );
+            if ( name == "xcb_apps" )
+                icon = QIcon( ":/sidebar/screen" );
+            else if ( name == "mtp" )
+                icon = QIcon( ":/sidebar/mtp" );
+            else if ( name == "disc" )
+                icon = QIcon( ":/sidebar/disc" );
+            else
+                icon = QIcon( ":/sidebar/capture" );
+            break;
+        case SD_CAT_LAN:
+            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, lan );
+            icon = QIcon( ":/sidebar/lan" );
+            break;
+        case SD_CAT_MYCOMPUTER:
+            name = name.mid( 0, name.indexOf( '{' ) );
+            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, mycomp );
+            if ( name == "video_dir" )
+                icon = QIcon( ":/sidebar/movie" );
+            else if ( name == "audio_dir" )
+                icon = QIcon( ":/sidebar/music" );
+            else if ( name == "picture_dir" )
+                icon = QIcon( ":/sidebar/pictures" );
+            else
+                icon = QIcon( ":/sidebar/movie" );
+            break;
+        default:
+            selItem = addItem( SD_TYPE, *ppsz_longname );
+        }
+
+        putSDData( selItem, *ppsz_name, *ppsz_longname );
+        if ( ! icon.isNull() )
+            selItem->treeItem()->setData( 0, Qt::DecorationRole, icon );
+
+        free( *ppsz_name );
+        free( *ppsz_longname );
+    }
+    free( ppsz_names );
+    free( ppsz_longnames );
+    free( p_categories );
+
+    if( mycomp->childCount() == 0 ) delete mycomp;
+    if( devices->childCount() == 0 ) delete devices;
+    if( lan->childCount() == 0 ) delete lan;
+    if( internet->childCount() == 0 ) delete internet;
+}
+
 void PLSelector::setSource( QTreeWidgetItem *item )
 {
-    if( !item )
+    if( !item || item == curItem )
         return;
 
     bool b_ok;
@@ -180,16 +367,40 @@ void PLSelector::setSource( QTreeWidgetItem *item )
         QString qs = item->data( 0, NAME_ROLE ).toString();
         sd_loaded = playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) );
         if( !sd_loaded )
-            playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) );
+        {
+            if ( playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) ) != VLC_SUCCESS )
+                return ;
+
+            services_discovery_descriptor_t *p_test = new services_discovery_descriptor_t;
+            int i_ret = playlist_ServicesDiscoveryControl( THEPL, qtu( qs ), SD_CMD_DESCRIPTOR, p_test );
+            if( i_ret == VLC_SUCCESS && p_test->i_capabilities & SD_CAP_SEARCH )
+                item->setData( 0, CAP_SEARCH_ROLE, true );
+        }
+    }
+#ifdef MEDIA_LIBRARY
+    else if( i_type == SQL_ML_TYPE )
+    {
+        emit categoryActivated( NULL, true );
+        curItem = item;
+        return;
     }
+#endif
 
-    playlist_Lock( THEPL );
+    curItem = item;
 
+    /* */
+    playlist_Lock( THEPL );
     playlist_item_t *pl_item = NULL;
 
+    /* Special case for podcast */
+    // FIXME: simplify
     if( i_type == SD_TYPE )
     {
-        pl_item = playlist_ChildSearchName( THEPL->p_root, qtu( item->data(0, LONGNAME_ROLE ).toString() ) );
+        /* Find the right item for the SD */
+        pl_item = playlist_ChildSearchName( THEPL->p_root,
+                      qtu( item->data(0, LONGNAME_ROLE ).toString() ) );
+
+        /* Podcasts */
         if( item->data( 0, SPECIAL_ROLE ).toInt() == IS_PODCAST )
         {
             if( pl_item && !sd_loaded )
@@ -206,17 +417,20 @@ void PLSelector::setSource( QTreeWidgetItem *item )
 
     playlist_Unlock( THEPL );
 
+    /* */
     if( pl_item )
-       emit activated( pl_item );
+        emit categoryActivated( pl_item, false );
 }
 
 PLSelItem * PLSelector::addItem (
-  SelectorItemType type, const QString& str, bool drop,
-  QTreeWidgetItem* parentItem )
+    SelectorItemType type, const char* str, bool drop, bool bold,
+    QTreeWidgetItem* parentItem )
 {
   QTreeWidgetItem *item = parentItem ?
       new QTreeWidgetItem( parentItem ) : new QTreeWidgetItem( this );
-  PLSelItem *selItem = new PLSelItem( item, str );
+
+  PLSelItem *selItem = new PLSelItem( item, qtr( str ) );
+  if ( bold ) selItem->setStyleSheet( "font-weight: bold;" );
   setItemWidget( item, 0, selItem );
   item->setData( 0, TYPE_ROLE, (int)type );
   if( !drop ) item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
@@ -224,113 +438,22 @@ PLSelItem * PLSelector::addItem (
   return selItem;
 }
 
-PLSelItem * putSDData( PLSelItem* item, const char* name, const char* longname )
-{
-    item->treeItem()->setData( 0, NAME_ROLE, qtr( name ) );
-    item->treeItem()->setData( 0, LONGNAME_ROLE, qtr( longname ) );
-    return item;
-}
-
-PLSelItem * putPLData( PLSelItem* item, playlist_item_t* plItem )
-{
-    item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( plItem ) );
-/*    item->setData( 0, PL_ITEM_ID_ROLE, plItem->i_id );
-    item->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( (void*) plItem->p_input ) ); );*/
-    return item;
-}
-
 PLSelItem *PLSelector::addPodcastItem( playlist_item_t *p_item )
 {
     vlc_gc_incref( p_item->p_input );
+
     char *psz_name = input_item_GetName( p_item->p_input );
-    PLSelItem *item = addItem(
-            PL_ITEM_TYPE, qfu( psz_name ), false, podcastsParent );
+    PLSelItem *item = addItem( PL_ITEM_TYPE,  psz_name, false, false, podcastsParent );
+    free( psz_name );
+
     item->addAction( RM_ACTION, qtr( "Remove this podcast subscription" ) );
     item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( p_item ) );
     item->treeItem()->setData( 0, PL_ITEM_ID_ROLE, QVariant(p_item->i_id) );
     item->treeItem()->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( p_item->p_input ) );
     CONNECT( item, action( PLSelItem* ), this, podcastRemove( PLSelItem* ) );
-    free( psz_name );
     return item;
 }
 
-void PLSelector::createItems()
-{
-    PLSelItem *pl = putPLData( addItem( PL_ITEM_TYPE, qtr( "Playlist" ), true ),
-                              THEPL->p_playing );
-    pl->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
-
-    PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, qtr( "Media Library" ), true ),
-                              THEPL->p_media_library );
-    ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
-
-    QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, qtr( "My Computer" ),
-                                        false )->treeItem();
-    QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, qtr( "Devices" ),
-                                        false )->treeItem();
-    QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, qtr( "Local Network" ),
-                                    false )->treeItem();
-    QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, qtr( "Internet" ),
-                                          false )->treeItem();;
-
-    char **ppsz_longnames;
-    int *p_categories;
-    char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
-    if( !ppsz_names )
-        return;
-
-    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
-    int *p_category = p_categories;
-    for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
-    {
-        //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
-
-        if( *p_category == SD_CAT_INTERNET )
-        {
-            PLSelItem *selItem = addItem( SD_TYPE, *ppsz_longname, false, internet );
-            putSDData( selItem, *ppsz_name, *ppsz_longname );
-            if( !strncmp( *ppsz_name, "podcast", 7 ) )
-            {
-                selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
-                selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
-                CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
-                podcastsParent = selItem->treeItem();
-            }
-        }
-        else if( *p_category == SD_CAT_DEVICES )
-        {
-            putSDData( addItem( SD_TYPE, *ppsz_longname, false, devices ),
-                       *ppsz_name, *ppsz_longname );
-        }
-        else if( *p_category == SD_CAT_LAN )
-        {
-            putSDData( addItem( SD_TYPE, *ppsz_longname, false, lan ),
-                       *ppsz_name, *ppsz_longname );
-        }
-        else if( *p_category == SD_CAT_MYCOMPUTER )
-        {
-            putSDData( addItem( SD_TYPE, *ppsz_longname, false, mycomp ),
-                       *ppsz_name, *ppsz_longname );
-        }
-        else
-        {
-            putSDData( addItem( SD_TYPE, qtr( *ppsz_longname ), false ),
-                       *ppsz_name, *ppsz_longname );
-        }
-
-        free( *ppsz_name );
-        free( *ppsz_longname );
-    }
-    free( ppsz_names );
-    free( ppsz_longnames );
-    free( p_categories );
-
-    if( mycomp->childCount() == 0 ) delete mycomp;
-    if( devices->childCount() == 0 ) delete devices;
-    if( lan->childCount() == 0 ) delete lan;
-    if( internet->childCount() == 0 ) delete internet;
-}
-
 QStringList PLSelector::mimeTypes() const
 {
     QStringList types;
@@ -338,16 +461,17 @@ QStringList PLSelector::mimeTypes() const
     return types;
 }
 
-bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
-  const QMimeData * data, Qt::DropAction action )
+bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int,
+    const QMimeData * data, Qt::DropAction )
 {
     if( !parent ) return false;
 
     QVariant type = parent->data( 0, TYPE_ROLE );
     if( type == QVariant() ) return false;
-    int i_truth = parent->data( 0, SPECIAL_ROLE ).toInt();
 
+    int i_truth = parent->data( 0, SPECIAL_ROLE ).toInt();
     if( i_truth != IS_PL && i_truth != IS_ML ) return false;
+
     bool to_pl = ( i_truth == IS_PL );
 
     const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
@@ -380,7 +504,8 @@ void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
 
 void PLSelector::plItemAdded( int item, int parent )
 {
-    if( parent != podcastsParentId ) return;
+    updateTotalDuration(playlistItem, "Playlist");
+    if( parent != podcastsParentId || podcastsParent == NULL ) return;
 
     playlist_Lock( THEPL );
 
@@ -412,6 +537,9 @@ void PLSelector::plItemAdded( int item, int parent )
 
 void PLSelector::plItemRemoved( int id )
 {
+    updateTotalDuration(playlistItem, "Playlist");
+    if( !podcastsParent ) return;
+
     int c = podcastsParent->childCount();
     for( int i = 0; i < c; i++ )
     {
@@ -429,6 +557,11 @@ void PLSelector::plItemRemoved( int id )
 
 void PLSelector::inputItemUpdate( input_item_t *arg )
 {
+    updateTotalDuration(playlistItem, "Playlist");
+
+    if( podcastsParent == NULL )
+        return;
+
     int c = podcastsParent->childCount();
     for( int i = 0; i < c; i++ )
     {
@@ -445,8 +578,10 @@ void PLSelector::inputItemUpdate( input_item_t *arg )
     }
 }
 
-void PLSelector::podcastAdd( PLSelItem* item )
+void PLSelector::podcastAdd( PLSelItem * )
 {
+    assert( podcastsParent );
+
     bool ok;
     QString url = QInputDialog::getText( this, qtr( "Subscribe" ),
                                          qtr( "Enter URL of the podcast to subscribe to:" ),
@@ -455,8 +590,7 @@ void PLSelector::podcastAdd( PLSelItem* item )
 
     setSource( podcastsParent ); //to load the SD in case it's not loaded
 
-    vlc_object_t *p_obj = (vlc_object_t*) vlc_object_find_name(
-        p_intf->p_libvlc, "podcast", FIND_CHILD );
+    vlc_object_t *p_obj = (vlc_object_t*) vlc_object_find_name( p_intf->p_libvlc, "podcast" );
     if( !p_obj ) return;
 
     QString request("ADD:");
@@ -471,15 +605,15 @@ void PLSelector::podcastRemove( PLSelItem* item )
     question = question.arg( item->text() );
     QMessageBox::StandardButton res =
         QMessageBox::question( this, qtr( "Unsubscribe" ), question,
-                               QMessageBox::Ok | QMessageBox::Cancel,
-                               QMessageBox::Cancel );
-    if( res == QMessageBox::Cancel ) return;
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No );
+    if( res == QMessageBox::No ) return;
 
     input_item_t *input = item->treeItem()->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
     if( !input ) return;
 
     vlc_object_t *p_obj = (vlc_object_t*) vlc_object_find_name(
-        p_intf->p_libvlc, "podcast", FIND_CHILD );
+        p_intf->p_libvlc, "podcast" );
     if( !p_obj ) return;
 
     QString request("RM:");
@@ -505,3 +639,27 @@ void PLSelector::drawBranches ( QPainter * painter, const QRect & rect, const QM
                             QStyle::PE_IndicatorArrowDown :
                             QStyle::PE_IndicatorArrowRight, &option, painter );
 }
+
+void PLSelector::getCurrentItemInfos( int* type, bool* can_delay_search, QString *string)
+{
+    *type = currentItem()->data( 0, TYPE_ROLE ).toInt();
+    *string = currentItem()->data( 0, NAME_ROLE ).toString();
+    *can_delay_search = currentItem()->data( 0, CAP_SEARCH_ROLE ).toBool();
+}
+
+int PLSelector::getCurrentItemCategory()
+{
+    return currentItem()->data( 0, SPECIAL_ROLE ).toInt();
+}
+
+void PLSelector::wheelEvent( QWheelEvent *e )
+{
+    if( verticalScrollBar()->isVisible() && (
+        (verticalScrollBar()->value() != verticalScrollBar()->minimum() && e->delta() >= 0 ) ||
+        (verticalScrollBar()->value() != verticalScrollBar()->maximum() && e->delta() < 0 )
+        ) )
+        QApplication::sendEvent(verticalScrollBar(), e);
+
+    // Accept this event in order to prevent unwanted volume up/down changes
+    e->accept();
+}