Commit 4ed4e121 authored by Jakob Leben's avatar Jakob Leben

Qt4: more media browser (PL Selector) beautification

parent bc157d87
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include "input_manager.hpp" /* art signal */ #include "input_manager.hpp" /* art signal */
#include "main_interface.hpp" /* DropEvent TODO remove this*/ #include "main_interface.hpp" /* DropEvent TODO remove this*/
#include <QGroupBox>
#include <iostream>
/********************************************************************** /**********************************************************************
* Playlist Widget. The embedded playlist * Playlist Widget. The embedded playlist
**********************************************************************/ **********************************************************************/
...@@ -46,7 +49,12 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i ) ...@@ -46,7 +49,12 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
/* Source Selector */ /* Source Selector */
selector = new PLSelector( this, p_intf ); selector = new PLSelector( this, p_intf );
leftW->addWidget( selector ); QVBoxLayout *selBox = new QVBoxLayout();
selBox->setContentsMargins(0,5,0,0);
selBox->addWidget( selector );
QGroupBox *selGroup = new QGroupBox( qtr( "Media Browser") );
selGroup->setLayout( selBox );
leftW->addWidget( selGroup );
/* Create a Container for the Art Label /* Create a Container for the Art Label
in order to have a beautiful resizing for the selector above it */ in order to have a beautiful resizing for the selector above it */
...@@ -140,3 +148,54 @@ void PlaylistWidget::closeEvent( QCloseEvent *event ) ...@@ -140,3 +148,54 @@ void PlaylistWidget::closeEvent( QCloseEvent *event )
event->ignore(); event->ignore();
} }
} }
PlaylistEventManager::PlaylistEventManager( playlist_t *_pl )
: pl( _pl )
{
var_AddCallback( pl, "playlist-item-append", itemAddedCb, this );
var_AddCallback( pl, "playlist-item-deleted", itemRemovedCb, this );
}
PlaylistEventManager::~PlaylistEventManager()
{
var_DelCallback( pl, "playlist-item-append", itemAddedCb, this );
var_DelCallback( pl, "playlist-item-deleted", itemRemovedCb, this );
}
int PlaylistEventManager::itemAddedCb
( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
{
PlaylistEventManager *p_this = static_cast<PlaylistEventManager*>(data);
p_this->trigger( cur, ItemAddedEv );
return VLC_SUCCESS;
}
int PlaylistEventManager::itemRemovedCb
( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
{
PlaylistEventManager *p_this = static_cast<PlaylistEventManager*>(data);
p_this->trigger( cur, ItemRemovedEv );
return VLC_SUCCESS;
}
void PlaylistEventManager::trigger( vlc_value_t val, int type )
{
if( type == ItemAddedEv )
{
playlist_add_t *p_add = static_cast<playlist_add_t*>( val.p_address );
QApplication::postEvent( this, new PLEMEvent( type, p_add->i_item, p_add->i_node ) );
}
else
{
QApplication::postEvent( this, new PLEMEvent( type, val.i_int, 0 ) );
}
}
void PlaylistEventManager::customEvent( QEvent *e )
{
PLEMEvent *ev = static_cast<PLEMEvent*>(e);
if( (int) ev->type() == ItemAddedEv )
emit itemAdded( ev->item, ev->parent );
else
emit itemRemoved( ev->item );
}
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "dialogs_provider.hpp" /* Media Info from ArtLabel */ #include "dialogs_provider.hpp" /* Media Info from ArtLabel */
#include "components/interface_widgets.hpp" #include "components/interface_widgets.hpp"
//#include <vlc_playlist.h>
#include <QSplitter> #include <QSplitter>
#include <QLabel> #include <QLabel>
...@@ -75,5 +76,39 @@ public: ...@@ -75,5 +76,39 @@ public:
} }
}; };
enum PLEventType {
ItemAddedEv = QEvent::User,
ItemRemovedEv
};
class PLEMEvent : public QEvent
{
public:
PLEMEvent( int t, int i, int p )
: QEvent( (QEvent::Type)t ), item(i), parent(p) {}
int item;
int parent;
};
class PlaylistEventManager : public QObject
{
Q_OBJECT;
public:
PlaylistEventManager( playlist_t* );
~PlaylistEventManager();
signals:
void itemAdded( int, int );
void itemRemoved( int );
private:
static int itemAddedCb ( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int itemRemovedCb ( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
void trigger( vlc_value_t, int );
void customEvent( QEvent* );
playlist_t *pl;
};
#endif #endif
...@@ -32,31 +32,93 @@ ...@@ -32,31 +32,93 @@
#include "playlist_item.hpp" #include "playlist_item.hpp"
#include "qt4.hpp" #include "qt4.hpp"
#include "../../dialogs_provider.hpp" #include "../../dialogs_provider.hpp"
#include "playlist.hpp"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QMimeData> #include <QMimeData>
#include <QPushButton> #include <QInputDialog>
#include <QLabel> #include <QMessageBox>
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include <vlc_services_discovery.h> #include <vlc_services_discovery.h>
#include <iostream>
PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text )
: qitem(i), btnAction( NULL )
{
layout = new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);
lbl = new QLabel( text );
lbl->setMargin(3);
layout->addWidget(lbl);
setLayout( layout );
}
void PLSelItem::addAction( ItemAction act, const QString& tooltip )
{
if( btnAction ) return;
switch( act )
{
case ADD_ACTION:
btnAction = new QPushButton("+"); break;
case RM_ACTION:
btnAction = new QPushButton("-"); break;
}
if( !tooltip.isEmpty() ) btnAction->setToolTip( tooltip );
btnAction->setMaximumWidth(23);
layout->addWidget( btnAction );
btnAction->hide();
CONNECT( btnAction, clicked(), this, triggerAction() );
}
void PLSelItem::showAction() { if( btnAction ) btnAction->show(); }
void PLSelItem::hideAction() { if( btnAction ) btnAction->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 ) PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
: QTreeWidget( p ), p_intf(_p_intf) : QTreeWidget( p ), p_intf(_p_intf)
{ {
setItemDelegate( new PLSelectorDelegate() ); /* custom QItemDelegate just to assure the minimum row height,
setFrameStyle( QFrame::StyledPanel | QFrame::Plain ); which otherwise fails when new child item is inserted */
setFrameStyle( QFrame::NoFrame );
viewport()->setAutoFillBackground( false );
setIconSize( QSize( 24,24 ) ); setIconSize( QSize( 24,24 ) );
setIndentation( 15 ); setIndentation( 10 );
header()->hide(); header()->hide();
//setHeaderLabel( qtr( "Medias" ) );
//header()->setMovable( false );
setRootIsDecorated( false ); setRootIsDecorated( false );
setAlternatingRowColors( true ); setAlternatingRowColors( false );
setItemDelegate( new PLSelectorDelegate() );
podcastsParent = NULL;
podcastsParentId = -1;
viewport()->setAcceptDrops(true); viewport()->setAcceptDrops(true);
setDropIndicatorShown(true); setDropIndicatorShown(true);
invisibleRootItem()->setFlags( invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled ); invisibleRootItem()->setFlags( invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled );
plEM = new PlaylistEventManager( THEPL );
CONNECT( plEM, itemAdded( int, int ),
this, plItemAdded( int, int ) );
CONNECT( plEM, itemRemoved( int ),
this, plItemRemoved( int ) );
CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
this, inputItemUpdate( input_item_t * ) );
createItems(); createItems();
CONNECT( this, itemActivated( QTreeWidgetItem *, int ), CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
this, setSource( QTreeWidgetItem *) ); this, setSource( QTreeWidgetItem *) );
...@@ -69,6 +131,20 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) ...@@ -69,6 +131,20 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
// view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) ); // view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
} }
PLSelector::~PLSelector()
{
if( podcastsParent )
{
int c = podcastsParent->childCount();
for( int i = 0; i < c; i++ )
{
QTreeWidgetItem *item = podcastsParent->child(i);
input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
vlc_gc_decref( p_input );
}
}
}
void PLSelector::setSource( QTreeWidgetItem *item ) void PLSelector::setSource( QTreeWidgetItem *item )
{ {
if( !item ) if( !item )
...@@ -76,65 +152,107 @@ void PLSelector::setSource( QTreeWidgetItem *item ) ...@@ -76,65 +152,107 @@ void PLSelector::setSource( QTreeWidgetItem *item )
bool b_ok; bool b_ok;
int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok ); int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok );
if( !b_ok ) if( !b_ok || i_type == CATEGORY_TYPE )
return; return;
assert( ( i_type == PL_TYPE || i_type == ML_TYPE || i_type == SD_TYPE ) ); bool sd_loaded;
if( i_type == SD_TYPE ) if( i_type == SD_TYPE )
{ {
QString qs = item->data( 0, NAME_ROLE ).toString(); QString qs = item->data( 0, NAME_ROLE ).toString();
if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) ) ) sd_loaded = playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) );
{ if( !sd_loaded )
playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) ); playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) );
} }
}
if( i_type == SD_TYPE )
msg_Dbg( p_intf, "SD already loaded, reloading" );
playlist_Lock( THEPL ); playlist_Lock( THEPL );
playlist_item_t *pl_item = NULL; playlist_item_t *pl_item = NULL;
if( i_type == SD_TYPE ) if( i_type == SD_TYPE )
{
pl_item = playlist_ChildSearchName( THEPL->p_root_category, qtu( item->data(0, LONGNAME_ROLE ).toString() ) ); pl_item = playlist_ChildSearchName( THEPL->p_root_category, qtu( item->data(0, LONGNAME_ROLE ).toString() ) );
else if ( i_type == PL_TYPE ) if( item->data( 0, SPECIAL_ROLE ).toInt() == IS_PODCAST )
pl_item = THEPL->p_local_category; {
else if ( i_type == ML_TYPE ) if( pl_item && !sd_loaded )
pl_item = THEPL->p_ml_category; {
podcastsParentId = pl_item->i_id;
for( int i=0; i < pl_item->i_children; i++ )
addPodcastItem( pl_item->pp_children[i] );
}
pl_item = NULL; //to prevent activating it
}
}
else
pl_item = item->data( 0, PL_ITEM_ROLE ).value<playlist_item_t*>();
playlist_Unlock( THEPL ); playlist_Unlock( THEPL );
if( pl_item ) if( pl_item )
emit activated( pl_item ); emit activated( pl_item );
} }
void PLSelector::makeStandardItem( QTreeWidgetItem* item, const QString& str ) PLSelItem * PLSelector::addItem (
SelectorItemType type, const QString& str, bool drop,
QTreeWidgetItem* parentItem )
{
QTreeWidgetItem *item = parentItem ?
new QTreeWidgetItem( parentItem ) : new QTreeWidgetItem( this );
PLSelItem *selItem = new PLSelItem( item, str );
setItemWidget( item, 0, selItem );
item->setData( 0, TYPE_ROLE, (int)type );
if( !drop ) item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
return selItem;
}
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->setText( 0,str ); 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 );
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() void PLSelector::createItems()
{ {
QTreeWidgetItem *pl = new QTreeWidgetItem( this ); PLSelItem *pl = putPLData( addItem( PL_ITEM_TYPE, qtr( "Playlist" ), true ),
makeStandardItem( pl, qtr( "Playlist" ) ); THEPL->p_local_category );
pl->setData( 0, TYPE_ROLE, PL_TYPE ); pl->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
pl->setData( 0, PPL_ITEM_ROLE, QVariant::fromValue( THEPL->p_local_category ) );
PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, qtr( "Media Library" ), true ),
THEPL->p_ml_category );
ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
QTreeWidgetItem *lib = new QTreeWidgetItem( this ); QTreeWidgetItem *msrc = addItem( CATEGORY_TYPE, qtr( "Media Sources" ),
makeStandardItem( lib, qtr( "Media Library" ) ); false )->treeItem();
lib->setData( 0, TYPE_ROLE, ML_TYPE );
lib->setData( 0, PPL_ITEM_ROLE, QVariant::fromValue( THEPL->p_ml_category ) );
QTreeWidgetItem *sds = new QTreeWidgetItem( this ); QTreeWidgetItem *mfldrs = NULL;
makeStandardItem( sds, qtr( "Services" ) );
sds->setExpanded( true );
sds->setFlags( sds->flags() & ~Qt::ItemIsDropEnabled );
QTreeWidgetItem *mfldrs = new QTreeWidgetItem( sds ); QTreeWidgetItem *shouts = NULL;
makeStandardItem( mfldrs, qtr( "Media Folders" ) );
mfldrs->setFlags( mfldrs->flags() & ~Qt::ItemIsDropEnabled );
QTreeWidgetItem *shouts = new QTreeWidgetItem( sds ); msrc->setExpanded( true );
makeStandardItem( shouts, qtr( "Shoutcast" ) );
shouts->setFlags( shouts->flags() & ~Qt::ItemIsDropEnabled );
char **ppsz_longnames; char **ppsz_longnames;
char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames ); char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
...@@ -142,55 +260,45 @@ void PLSelector::createItems() ...@@ -142,55 +260,45 @@ void PLSelector::createItems()
return; return;
char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames; char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
QTreeWidgetItem *sd_item;
for( ; *ppsz_name; ppsz_name++, ppsz_longname++ ) for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
{ {
sd_item = new QTreeWidgetItem( ); //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
#define SD_IS( name ) ( !strcmp( *ppsz_name, name ) ) #define SD_IS( name ) ( !strcmp( *ppsz_name, name ) )
if( SD_IS("shoutcast") || SD_IS("shoutcasttv") || if( SD_IS("shoutcast") || SD_IS("shoutcasttv") ||
SD_IS("frenchtv") || SD_IS("freebox") ) SD_IS("frenchtv") || SD_IS("freebox") )
{ {
shouts->addChild( sd_item ); if( !shouts ) shouts = addItem( CATEGORY_TYPE, qtr( "Shoutcast" ),
makeStandardItem( sd_item, qfu(*ppsz_longname) ); false, msrc )->treeItem();
putSDData( addItem( SD_TYPE, *ppsz_longname, false, shouts ),
*ppsz_name, *ppsz_longname );
} }
else if( SD_IS("video_dir") || SD_IS("audio_dir") || SD_IS("picture_dir") ) else if( SD_IS("video_dir") || SD_IS("audio_dir") || SD_IS("picture_dir") )
{ {
mfldrs->addChild( sd_item ); if( !mfldrs ) mfldrs = addItem( CATEGORY_TYPE, qtr( "Media Folders" ),
makeStandardItem( sd_item, qfu(*ppsz_longname) ); false, msrc )->treeItem();
putSDData( addItem( SD_TYPE, *ppsz_longname, false, mfldrs ),
*ppsz_name, *ppsz_longname );
} }
else if( SD_IS("podcast") ) else if( SD_IS("podcast") )
{ {
sds->addChild( sd_item );
QLabel *lbl = new QLabel("Podcasts"); PLSelItem *podItem = addItem( SD_TYPE, qtr( "Podcasts" ), false, msrc );
lbl->setMargin(3); putSDData( podItem, *ppsz_name, *ppsz_longname );
QPushButton *btn = new QPushButton(); podItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
btn->setMaximumWidth(30); podItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
btn->setIcon( QIcon( ":/menu/preferences" ) ); CONNECT( podItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
QHBoxLayout *hbox = new QHBoxLayout();
hbox->setContentsMargins(0,0,0,0); podcastsParent = podItem->treeItem();
hbox->addWidget(lbl);
hbox->addWidget(btn);
QWidget *w = new QWidget();
w->setLayout(hbox);
CONNECT( btn, clicked(), THEDP, podcastConfigureDialog() );
setItemWidget( sd_item, 0, w );
} }
else else
{ {
sds->addChild( sd_item ); putSDData( addItem( SD_TYPE, qtr( *ppsz_longname ), false, msrc ),
makeStandardItem( sd_item, qfu(*ppsz_longname) ); *ppsz_name, *ppsz_longname );
} }
#undef SD_IS #undef SD_IS
sd_item->setData( 0, TYPE_ROLE, SD_TYPE );
sd_item->setData( 0, NAME_ROLE, qfu( *ppsz_name ) );
sd_item->setData( 0, LONGNAME_ROLE, qfu( *ppsz_longname ) );
sd_item->setFlags( sd_item->flags() & ~Qt::ItemIsDropEnabled );
free( *ppsz_name ); free( *ppsz_name );
free( *ppsz_longname ); free( *ppsz_longname );
} }
...@@ -212,9 +320,10 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index, ...@@ -212,9 +320,10 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
QVariant type = parent->data( 0, TYPE_ROLE ); QVariant type = parent->data( 0, TYPE_ROLE );
if( type == QVariant() ) return false; if( type == QVariant() ) return false;
int i_type = type.toInt(); int i_truth = parent->data( 0, SPECIAL_ROLE ).toInt();
if( i_type != PL_TYPE && i_type != ML_TYPE ) return false;
bool to_pl = i_type == PL_TYPE; if( i_truth != IS_PL && i_truth != IS_ML ) return false;
bool to_pl = ( i_truth == IS_PL );
if( data->hasFormat( "vlc/qt-playlist-item" ) ) if( data->hasFormat( "vlc/qt-playlist-item" ) )
{ {
...@@ -238,6 +347,120 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index, ...@@ -238,6 +347,120 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
return true; return true;
} }
PLSelector::~PLSelector() void PLSelector::plItemAdded( int item, int parent )
{
if( parent != podcastsParentId ) return;
playlist_Lock( THEPL );
playlist_item_t *p_item = playlist_ItemGetById( THEPL, item );
if( !p_item ) {
playlist_Unlock( THEPL );
return;
}
int c = podcastsParent->childCount();
for( int i = 0; i < c; i++ )
{
QTreeWidgetItem *podItem = podcastsParent->child(i);
if( podItem->data( 0, PL_ITEM_ID_ROLE ).toInt() == item )
{
//msg_Dbg( p_intf, "Podcast already in: (%d) %s", item, p_item->p_input->psz_uri);
playlist_Unlock( THEPL );
return;
}
}
//msg_Dbg( p_intf, "Adding podcast: (%d) %s", item, p_item->p_input->psz_uri );
addPodcastItem( p_item );
playlist_Unlock( THEPL );
podcastsParent->setExpanded( true );
}
void PLSelector::plItemRemoved( int id )
{
int c = podcastsParent->childCount();
for( int i = 0; i < c; i++ )
{
QTreeWidgetItem *item = podcastsParent->child(i);
if( item->data( 0, PL_ITEM_ID_ROLE ).toInt() == id )
{
input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
//msg_Dbg( p_intf, "Removing podcast: (%d) %s", id, p_input->psz_uri );
vlc_gc_decref( p_input );
delete item;
return;
}
}
}
void PLSelector::inputItemUpdate( input_item_t *arg )
{
int c = podcastsParent->childCount();
for( int i = 0; i < c; i++ )
{
QTreeWidgetItem *item = podcastsParent->child(i);
input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
if( p_input == arg )
{
PLSelItem *si = itemWidget( item );
char *psz_name = input_item_GetName( p_input );
si->setText( qfu( psz_name ) );
free( psz_name );
return;
}
}
}
void PLSelector::podcastAdd( PLSelItem* item )
{
bool ok;
QString url = QInputDialog::getText( this, qtr( "Subscribe" ),
qtr( "Enter URL of the podcast to subscribe to:" ),
QLineEdit::Normal, QString(), &ok );
if( !ok || url.isEmpty() ) return;
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 );
if( !p_obj ) return;
QString request("ADD:");
request += url;
var_SetString( p_obj, "podcast-request", qtu( request ) );
vlc_object_release( p_obj );
}
void PLSelector::podcastRemove( PLSelItem* item )
{
//FIXME will translators know to leave that %1 somewhere inside?
QString question ( qtr( "Do you really want to unsubscribe from %1?" ) );
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;
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 );
if( !p_obj ) return;
QString request("RM:");
char *psz_uri = input_item_GetURI( input );
request += qfu( psz_uri );
var_SetString( p_obj, "podcast-request", qtu( request ) );
vlc_object_release( p_obj );
free( psz_uri );
}
PLSelItem * PLSelector::itemWidget( QTreeWidgetItem *item )
{ {
return ( static_cast<PLSelItem*>( QTreeWidget::itemWidget( item, 0 ) ) );
} }
\ No newline at end of file
...@@ -32,38 +32,92 @@ ...@@ -32,38 +32,92 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QPainter>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include "qt4.hpp" #include "qt4.hpp"
class PlaylistWidget; class PlaylistWidget;
class PlaylistEventManager;
enum { enum SelectorItemType {
PL_TYPE, CATEGORY_TYPE,
ML_TYPE,
SD_TYPE, SD_TYPE,
PL_ITEM_TYPE
};
enum SpecialData {
IS_PODCAST = 1,
IS_PL,
IS_ML
}; };
enum { enum {
TYPE_ROLE = Qt::UserRole, TYPE_ROLE = Qt::UserRole,
PPL_ITEM_ROLE, NAME_ROLE, //QString
NAME_ROLE, LONGNAME_ROLE, //QString
LONGNAME_ROLE, PL_ITEM_ROLE, //playlist_item_t*
PL_ITEM_ID_ROLE, //playlist_item_t->i_id
IN_ITEM_ROLE, //input_item_t->i_id
SPECIAL_ROLE //SpecialData
};
enum ItemAction {
ADD_ACTION,
RM_ACTION
};
class PLSelItem : public QWidget
{
Q_OBJECT;
public:
PLSelItem( QTreeWidgetItem*, const QString& );
void setText( const QString& );
void addAction( ItemAction, const QString& toolTip = 0 );
QTreeWidgetItem *treeItem() { return qitem; }
QString text() { return lbl->text(); }
public slots:
void showAction();
void hideAction();
private slots:
void triggerAction() { emit action( this ); }
signals:
void action( PLSelItem* );
private:
void enterEvent( QEvent* );
void leaveEvent( QEvent* );
QTreeWidgetItem* qitem;
QPushButton* btnAction;
QLabel *lbl;
QHBoxLayout *layout;
}; };
class PLSelectorDelegate : public QStyledItemDelegate class PLSelectorDelegate : public QStyledItemDelegate
{ {
private: private:
/*void paint ( QPainter * painter,
const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if( index.data( TYPE_ROLE ).toInt() == CATEGORY_TYPE )
painter->fillRect( option.rect, QColor( 200,200,200 ) );
QRect r = option.rect;
r.setLeft( r.left() + 5 );
painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, index.data().toString() );
}*/
QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
QSize sz = QStyledItemDelegate::sizeHint( option, index ); QSize sz = QStyledItemDelegate::sizeHint( option, index );
if( sz.height() < 25 ) sz.setHeight(25); if( sz.height() < 23 ) sz.setHeight(23);
return sz; return sz;
} }
}; };
Q_DECLARE_METATYPE( playlist_item_t *); Q_DECLARE_METATYPE( playlist_item_t *);
Q_DECLARE_METATYPE( input_item_t *);
class PLSelector: public QTreeWidget class PLSelector: public QTreeWidget
{ {
Q_OBJECT; Q_OBJECT;
...@@ -74,12 +128,25 @@ protected: ...@@ -74,12 +128,25 @@ protected:
friend class PlaylistWidget; friend class PlaylistWidget;
private: private:
QStringList mimeTypes () const; QStringList mimeTypes () const;
void makeStandardItem( QTreeWidgetItem*, const QString& );
bool dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action ); bool dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action );
void createItems(); void createItems();
PLSelItem * addItem (
SelectorItemType type, const QString& str, bool drop,
QTreeWidgetItem* parentItem = 0 );
PLSelItem * addPodcastItem( playlist_item_t *p_item );
inline PLSelItem * itemWidget( QTreeWidgetItem * );
intf_thread_t *p_intf; intf_thread_t *p_intf;
PlaylistEventManager *plEM;
QTreeWidgetItem *podcastsParent;
int podcastsParentId;
private slots: private slots:
void setSource( QTreeWidgetItem *item ); void setSource( QTreeWidgetItem *item );
void plItemAdded( int, int );
void plItemRemoved( int );
void inputItemUpdate( input_item_t * );
void podcastAdd( PLSelItem* );
void podcastRemove( PLSelItem* );
signals: signals:
void activated( playlist_item_t * ); void activated( playlist_item_t * );
}; };
......
...@@ -295,7 +295,8 @@ void StandardPLPanel::setRoot( playlist_item_t *p_item ) ...@@ -295,7 +295,8 @@ void StandardPLPanel::setRoot( playlist_item_t *p_item )
QPL_LOCK; QPL_LOCK;
assert( p_item ); assert( p_item );
p_item = playlist_GetPreferredNode( THEPL, p_item ); playlist_item_t *p_pref_item = playlist_GetPreferredNode( THEPL, p_item );
if( p_pref_item ) p_item = p_pref_item;
/* needed for popupAdd() */ /* needed for popupAdd() */
currentRootId = p_item->i_id; currentRootId = p_item->i_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment