+
+
+
+static int downloadCoverCallback( vlc_object_t *p_this,
+ char const *psz_var,
+ vlc_value_t oldvar, vlc_value_t newvar,
+ void *data )
+{
+ if( !strcmp( psz_var, "item-change" ) )
+ {
+ CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
+ if( art )
+ art->requestUpdate();
+ }
+ return VLC_SUCCESS;
+}
+
+CoverArtLabel::CoverArtLabel( vlc_object_t *_p_this, input_item_t *_p_input )
+ : p_this( _p_this), p_input( _p_input ), prevArt()
+{
+ setContextMenuPolicy( Qt::ActionsContextMenu );
+ CONNECT( this, updateRequested(), this, doUpdate() );
+
+ playlist_t *p_playlist = pl_Yield( p_this );
+ var_AddCallback( p_playlist, "item-change",
+ downloadCoverCallback, this );
+ pl_Release( p_this );
+
+ setMinimumHeight( 128 );
+ setMinimumWidth( 128 );
+ setMaximumHeight( 128 );
+ setMaximumWidth( 128 );
+ setScaledContents( true );
+
+ doUpdate();
+}
+
+void CoverArtLabel::downloadCover()
+{
+ if( p_input )
+ {
+ playlist_t *p_playlist = pl_Yield( p_this );
+ playlist_AskForArtEnqueue( p_playlist, p_input );
+ pl_Release( p_this );
+ }
+}
+
+void CoverArtLabel::doUpdate()
+{
+ if( !p_input )
+ {
+ setPixmap( QPixmap( ":/noart.png" ) );
+ QList< QAction* > artActions = actions();
+ if( !artActions.isEmpty() )
+ foreach( QAction *act, artActions )
+ removeAction( act );
+ prevArt = "";
+ }
+ else
+ {
+ char *psz_meta = input_item_GetArtURL( p_input );
+ if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
+ {
+ QString artUrl = qfu( psz_meta ).replace( "file://", "" );
+ if( artUrl != prevArt )
+ setPixmap( QPixmap( artUrl ) );
+ QList< QAction* > artActions = actions();
+ if( !artActions.isEmpty() )
+ {
+ foreach( QAction *act, artActions )
+ removeAction( act );
+ }
+ prevArt = artUrl;
+ }
+ else
+ {
+ if( prevArt != "" )
+ setPixmap( QPixmap( ":/noart.png" ) );
+ prevArt = "";
+ QList< QAction* > artActions = actions();
+ if( artActions.isEmpty() )
+ {
+ QAction *action = new QAction( qtr( "Download cover art" ),
+ this );
+ addAction( action );
+ CONNECT( action, triggered(),
+ this, downloadCover() );
+ }
+ }
+ free( psz_meta );
+ }
+}
+