X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fselector.cpp;h=25e92aac7bfbd0564194e778ee3a168385314b8f;hb=873e5edb26e043859d184d10a818ba984706f850;hp=09305f6aa9e11e340cb95f4b484d94cfe4e17c86;hpb=4fe7b1248d1efb1f3d4970c39db646de6bb3e9e6;p=vlc diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp index 09305f6aa9..25e92aac7b 100644 --- a/modules/gui/qt4/components/playlist/selector.cpp +++ b/modules/gui/qt4/components/playlist/selector.cpp @@ -29,7 +29,7 @@ #include #include "components/playlist/selector.hpp" -#include "playlist_item.hpp" +#include "playlist_model.hpp" #include "qt4.hpp" #include "../../dialogs_provider.hpp" #include "playlist.hpp" @@ -44,6 +44,20 @@ #include #include +void SelectorActionButton::paintEvent( QPaintEvent *event ) +{ + QPainter p( this ); + QColor color = palette().color( QPalette::HighlightedText ); + color.setAlpha( 80 ); + if( underMouse() ) + p.fillRect( rect(), color ); + p.setPen( color ); + int frame = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this ); + p.drawLine( rect().topLeft() + QPoint( 0, frame ), + rect().bottomLeft() - QPoint( 0, frame ) ); + QVLCFramelessButton::paintEvent( event ); +} + PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text ) : qitem(i), lblAction( NULL) { @@ -51,13 +65,14 @@ PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text ) layout->setContentsMargins(0,0,0,0); layout->addSpacing( 3 ); - lbl = new QLabel( text ); + lbl = new QVLCElidingLabel( text ); layout->addWidget(lbl, 1); setLayout( layout ); - setMinimumHeight( 22 ); //Action icon height plus 6 + int height = qMax( 22, fontMetrics().height() + 8 ); + setMinimumHeight( height ); } void PLSelItem::addAction( ItemAction act, const QString& tooltip ) @@ -74,13 +89,14 @@ void PLSelItem::addAction( ItemAction act, const QString& tooltip ) icon = QIcon( ":/buttons/playlist/playlist_remove" ); break; } - lblAction = new QVLCIconLabel( icon ); + lblAction = new SelectorActionButton(); + lblAction->setIcon( icon ); + lblAction->setMinimumWidth( lblAction->sizeHint().width() + 6 ); if( !tooltip.isEmpty() ) lblAction->setToolTip( tooltip ); layout->addWidget( lblAction, 0 ); lblAction->hide(); - layout->addSpacing( 3 ); CONNECT( lblAction, clicked(), this, triggerAction() ); } @@ -101,7 +117,7 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) setFrameStyle( QFrame::NoFrame ); viewport()->setAutoFillBackground( false ); setIconSize( QSize( 24,24 ) ); - setIndentation( 14 ); + setIndentation( 12 ); header()->hide(); setRootIsDecorated( true ); setAlternatingRowColors( false ); @@ -116,8 +132,8 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) this, plItemAdded( int, int ) ); CONNECT( THEMIM, playlistItemRemoved( int ), this, plItemRemoved( int ) ); - CONNECT( THEMIM->getIM(), metaChanged( input_item_t *), - this, inputItemUpdate( input_item_t * ) ); + DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *), + this, inputItemUpdate( input_item_t * ) ); createItems(); CONNECT( this, itemActivated( QTreeWidgetItem *, int ), @@ -225,17 +241,17 @@ PLSelItem * putPLData( PLSelItem* item, playlist_item_t* plItem ) 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; + 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() @@ -248,46 +264,53 @@ void PLSelector::createItems() THEPL->p_media_library ); ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) ); - QTreeWidgetItem *mfldrs = NULL; - - QTreeWidgetItem *shouts = NULL; + 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; - char **ppsz_names = vlc_sd_GetNames( THEPL, &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; - for( ; *ppsz_name; ppsz_name++, ppsz_longname++ ) + 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 ); -#define SD_IS( name ) ( !strcmp( *ppsz_name, name ) ) - if( SD_IS("shoutcast") || SD_IS("shoutcasttv") || - SD_IS("frenchtv") || SD_IS("freebox") ) + if( *p_category == SD_CAT_INTERNET ) { - if( !shouts ) shouts = addItem( CATEGORY_TYPE, qtr( "Shoutcast" ), - false )->treeItem(); - putSDData( addItem( SD_TYPE, *ppsz_longname, false, shouts ), + 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( SD_IS("video_dir") || SD_IS("audio_dir") || SD_IS("picture_dir") ) + else if( *p_category == SD_CAT_LAN ) { - if( !mfldrs ) mfldrs = addItem( CATEGORY_TYPE, qtr( "Media Folders" ), - false )->treeItem(); - putSDData( addItem( SD_TYPE, *ppsz_longname, false, mfldrs ), + putSDData( addItem( SD_TYPE, *ppsz_longname, false, lan ), *ppsz_name, *ppsz_longname ); } - else if( SD_IS("podcast") ) + else if( *p_category == SD_CAT_MYCOMPUTER ) { - - PLSelItem *podItem = addItem( SD_TYPE, qtr( "Podcasts" ), false ); - putSDData( podItem, *ppsz_name, *ppsz_longname ); - podItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) ); - podItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) ); - CONNECT( podItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) ); - - podcastsParent = podItem->treeItem(); + putSDData( addItem( SD_TYPE, *ppsz_longname, false, mycomp ), + *ppsz_name, *ppsz_longname ); } else { @@ -295,19 +318,23 @@ void PLSelector::createItems() *ppsz_name, *ppsz_longname ); } -#undef SD_IS - 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; - types << "vlc/qt-playlist-item"; + types << "vlc/qt-input-items"; return types; } @@ -323,28 +350,34 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index, 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" ) ) + const PlMimeData *plMimeData = qobject_cast( data ); + if( !plMimeData ) return false; + + QList inputItems = plMimeData->inputItems(); + + playlist_Lock( THEPL ); + + foreach( input_item_t *p_input, inputItems ) { - QByteArray encodedData = data->data( "vlc/qt-playlist-item" ); - QDataStream stream( &encodedData, QIODevice::ReadOnly ); - playlist_Lock( THEPL ); - while( !stream.atEnd() ) - { - PLItem *item; - stream.readRawData( (char*)&item, sizeof(PLItem*) ); - input_item_t *pl_input =item->inputItem(); - playlist_AddExt ( THEPL, - pl_input->psz_uri, pl_input->psz_name, - PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END, - pl_input->i_duration, - pl_input->i_options, pl_input->ppsz_options, pl_input->optflagc, - to_pl, true ); - } - playlist_Unlock( THEPL ); + playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input ); + if( !p_item ) continue; + + playlist_NodeAddCopy( THEPL, p_item, + to_pl ? THEPL->p_playing : THEPL->p_media_library, + PLAYLIST_END ); } + + playlist_Unlock( THEPL ); + return true; } +void PLSelector::dragMoveEvent ( QDragMoveEvent * event ) +{ + event->setDropAction( Qt::CopyAction ); + QAbstractItemView::dragMoveEvent( event ); +} + void PLSelector::plItemAdded( int item, int parent ) { if( parent != podcastsParentId ) return; @@ -427,14 +460,13 @@ void PLSelector::podcastAdd( PLSelItem* item ) if( !p_obj ) return; QString request("ADD:"); - request += url; + request += url.trimmed(); 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 = @@ -468,9 +500,7 @@ void PLSelector::drawBranches ( QPainter * painter, const QRect & rect, const QM if( !model()->hasChildren( index ) ) return; QStyleOption option; option.initFrom( this ); - option.rect = rect; - /*option.state = QStyle::State_Children; - if( isExpanded( index ) ) option.state |= QStyle::State_Open;*/ + option.rect = rect.adjusted( rect.width() - indentation(), 0, 0, 0 ); style()->drawPrimitive( isExpanded( index ) ? QStyle::PE_IndicatorArrowDown : QStyle::PE_IndicatorArrowRight, &option, painter );