Commit 4dd472bb authored by Jean-Philippe Andre's avatar Jean-Philippe Andre

Qt: create a CoverArtLabel

This Widget (base QLabel) is designed to show the cover art. It handles right-click, and show a context menu that has only one entry:

- Download cover art

When the user clicks it, vlc downloads the cover art (or finds it in the cache), and displays it when downloaded
parent 355d80f1
......@@ -205,7 +205,8 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
backgroundLayout->setColumnStretch( 0, 1 );
backgroundLayout->setColumnStretch( 2, 1 );
CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
this, updateArt( input_item_t* ) );
}
BackgroundWidget::~BackgroundWidget()
......@@ -219,18 +220,28 @@ void BackgroundWidget::resizeEvent( QResizeEvent * event )
label->show();
}
void BackgroundWidget::updateArt( QString url )
void BackgroundWidget::updateArt( input_item_t *p_item )
{
QString url;
if( p_item )
{
char *psz_art = input_item_GetArtURL( p_item );
url = psz_art;
free( psz_art );
}
if( url.isEmpty() )
{
if( QDate::currentDate().dayOfYear() >= 354 )
label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
else
label->setPixmap( QPixmap( ":/vlc128.png" ) );
return;
}
else
{
url = url.replace( "file://", QString("" ) );
/* Taglib seems to define a attachment://, It won't work yet */
url = url.replace( "attachment://", QString("" ) );
label->setPixmap( QPixmap( url ) );
}
}
......@@ -1433,3 +1444,96 @@ void SpeedControlWidget::resetRate()
{
THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
}
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 );
}
}
......@@ -100,7 +100,7 @@ private:
virtual void resizeEvent( QResizeEvent * event );
public slots:
void toggle(){ TOGGLEV( this ); }
void updateArt( QString );
void updateArt( input_item_t* );
};
#if 0
......@@ -376,4 +376,28 @@ private slots:
void resetRate();
};
class CoverArtLabel : public QLabel
{
Q_OBJECT
public:
CoverArtLabel( vlc_object_t *p_this, input_item_t *p_input = NULL );
virtual ~CoverArtLabel() {};
private:
input_item_t *p_input;
vlc_object_t *p_this;
QString prevArt;
public slots:
void requestUpdate() { emit updateRequested(); };
void update( input_item_t* p_item )
{ p_input = p_item; requestUpdate(); }
private slots:
void doUpdate();
void downloadCover();
signals:
void updateRequested();
};
#endif
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