]> git.sesse.net Git - vlc/commitdiff
Qt: using correctly setSource with playlist_items
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 Sep 2009 23:13:58 +0000 (01:13 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 6 Sep 2009 22:04:43 +0000 (00:04 +0200)
And correct decoration.

modules/gui/qt4/components/playlist/selector.cpp
modules/gui/qt4/components/playlist/selector.hpp

index 40632214dd3c15762dfe8f1275e804096fd5c609..2a35181d35689c29d218c841d2c85f55327715dc 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * selector.cpp : Playlist source selector
  ****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
+ * Copyright (C) 2006-2009 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
+ *          Jean-Baptiste Kempf
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -35,6 +36,7 @@
 #include <QTreeWidget>
 
 #include <vlc_playlist.h>
+#include <vlc_services_discovery.h>
 
 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf)
 {
@@ -42,8 +44,9 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i
     view = new QTreeWidget;
     view->setIconSize( QSize( 24,24 ) );
 //    view->setAlternatingRowColors( true );
-    view->setIndentation( 0 );
+    view->setIndentation( 10 );
     view->header()->hide();
+    view->setRootIsDecorated( false );
 //    view->setModel( model );
 
     view->setAcceptDrops(true);
@@ -67,12 +70,30 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i
 
 void PLSelector::setSource( QTreeWidgetItem *item )
 {
-    if( item )
+    if( !item )
+        return;
+
+    int i_type = item->data( 0, Qt::UserRole ).toInt();
+
+    if( i_type == SD_TYPE )
+    {
+        QString qs = item->data( 0, Qt::UserRole + 1 ).toString();
+        if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) ) )
+        {
+            playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) );
+            //FIXME we should return the playlist_item_t;
+            emit NULL;
+        }
+    }
+    else if( i_type == PL_TYPE || i_type == ML_TYPE )
     {
         playlist_item_t *pl_item =
-                item->data( 0, Qt::UserRole ).value<playlist_item_t *>();
-        emit activated( pl_item );
+                item->data( 0, Qt::UserRole + 1 ).value<playlist_item_t *>();
+        if( pl_item )
+            emit activated( pl_item );
     }
+    else
+        assert( 0 );
 }
 
 void PLSelector::createItems()
@@ -80,18 +101,37 @@ void PLSelector::createItems()
     assert( view );
     QTreeWidgetItem *pl = new QTreeWidgetItem( view );
     pl->setText( 0, qtr( "Playlist" ) );
-    pl->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_local_category ) );
+    pl->setData( 0, Qt::UserRole, PL_TYPE );
+    pl->setData( 0, Qt::UserRole + 1, QVariant::fromValue( THEPL->p_local_category ) );
 /*    QTreeWidgetItem *empty = new QTreeWidgetItem( view );
     empty->setFlags(Qt::NoItemFlags);
 */
     QTreeWidgetItem *lib = new QTreeWidgetItem( view );
     lib->setText( 0, qtr( "Library" ) );
-    lib->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_ml_category ) );
+    lib->setData( 0, Qt::UserRole, ML_TYPE );
+    lib->setData( 0, Qt::UserRole + 1, QVariant::fromValue( THEPL->p_ml_category ) );
 /*
     QTreeWidgetItem *empty2 = new QTreeWidgetItem( view );
     empty2->setFlags(Qt::NoItemFlags);*/
 
+    QTreeWidgetItem *sds = new QTreeWidgetItem( view );
+    sds->setExpanded( true );
+    sds->setText( 0, qtr( "Libraries" ) );
 
+    char **ppsz_longnames;
+    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
+    if( !ppsz_names )
+        return;
+
+    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
+    QTreeWidgetItem *sd_item;
+    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
+    {
+        sd_item = new QTreeWidgetItem( QStringList( *ppsz_longname ) );
+        sd_item->setData( 0, Qt::UserRole, SD_TYPE );
+        sd_item->setData( 0, Qt::UserRole + 1, qfu( *ppsz_name ) );
+        sds->addChild( sd_item );
+    }
 
 }
 PLSelector::~PLSelector()
index e395e8393c1fdfbfb412fd67250179998b6dd8a0..f2c367eed3596f450a4c6f3d0f8f2a53972ed43a 100644 (file)
 class QTreeWidget;
 class PlaylistWidget;
 
+enum {
+    PL_TYPE,
+    ML_TYPE,
+    SD_TYPE,
+};
+
 Q_DECLARE_METATYPE( playlist_item_t *);
 class PLSelector: public QWidget
 {