1 /*****************************************************************************
2 * selector.cpp : Playlist source selector
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@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 *****************************************************************************/
31 #include "components/playlist/selector.hpp"
34 #include <QVBoxLayout>
35 #include <QHeaderView>
36 #include <QTreeWidget>
38 #include <vlc_playlist.h>
39 #include <vlc_services_discovery.h>
41 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf)
43 // model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
44 view = new QTreeWidget;
45 view->setIconSize( QSize( 24,24 ) );
46 // view->setAlternatingRowColors( true );
47 view->setIndentation( 10 );
48 view->header()->hide();
49 view->setRootIsDecorated( false );
50 // view->setModel( model );
52 view->setAcceptDrops(true);
53 view->setDropIndicatorShown(true);
57 CONNECT( view, itemActivated( QTreeWidgetItem *, int ),
58 this, setSource( QTreeWidgetItem *) );
59 CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
60 this, setSource( QTreeWidgetItem *) );
62 QVBoxLayout *layout = new QVBoxLayout();
63 layout->setSpacing( 0 ); layout->setMargin( 0 );
64 layout->addWidget( view );
67 /* select the first item */
68 // view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
71 void PLSelector::setSource( QTreeWidgetItem *item )
76 int i_type = item->data( 0, Qt::UserRole ).toInt();
78 if( i_type == SD_TYPE )
80 QString qs = item->data( 0, Qt::UserRole + 1 ).toString();
81 if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) ) )
83 playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) );
84 //FIXME we should return the playlist_item_t;
88 else if( i_type == PL_TYPE || i_type == ML_TYPE )
90 playlist_item_t *pl_item =
91 item->data( 0, Qt::UserRole + 1 ).value<playlist_item_t *>();
93 emit activated( pl_item );
99 void PLSelector::createItems()
102 QTreeWidgetItem *pl = new QTreeWidgetItem( view );
103 pl->setText( 0, qtr( "Playlist" ) );
104 pl->setData( 0, Qt::UserRole, PL_TYPE );
105 pl->setData( 0, Qt::UserRole + 1, QVariant::fromValue( THEPL->p_local_category ) );
106 /* QTreeWidgetItem *empty = new QTreeWidgetItem( view );
107 empty->setFlags(Qt::NoItemFlags);
109 QTreeWidgetItem *lib = new QTreeWidgetItem( view );
110 lib->setText( 0, qtr( "Library" ) );
111 lib->setData( 0, Qt::UserRole, ML_TYPE );
112 lib->setData( 0, Qt::UserRole + 1, QVariant::fromValue( THEPL->p_ml_category ) );
114 QTreeWidgetItem *empty2 = new QTreeWidgetItem( view );
115 empty2->setFlags(Qt::NoItemFlags);*/
117 QTreeWidgetItem *sds = new QTreeWidgetItem( view );
118 sds->setExpanded( true );
119 sds->setText( 0, qtr( "Libraries" ) );
121 char **ppsz_longnames;
122 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
126 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
127 QTreeWidgetItem *sd_item;
128 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
130 sd_item = new QTreeWidgetItem( QStringList( *ppsz_longname ) );
131 sd_item->setData( 0, Qt::UserRole, SD_TYPE );
132 sd_item->setData( 0, Qt::UserRole + 1, qfu( *ppsz_name ) );
133 sds->addChild( sd_item );
137 PLSelector::~PLSelector()