[vlc-devel] commit: Qt: create a CoverArtLabel (Jean-Philippe Andre )
git version control
git at videolan.org
Sun Sep 7 09:49:54 CEST 2008
vlc | branch: 0.9-bugfix | Jean-Philippe Andre <jpeg at via.ecp.fr> | Wed Sep 3 23:58:06 2008 -0400| [ce87dedcb99fe1510488ef7e9726700ebccdbd50] | committer: Jean-Baptiste Kempf
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
(cherry picked from commit 4dd472bb412a29deef6d5a5424aaa081d27a5faf)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce87dedcb99fe1510488ef7e9726700ebccdbd50
---
modules/gui/qt4/components/interface_widgets.cpp | 110 +++++++++++++++++++++-
modules/gui/qt4/components/interface_widgets.hpp | 26 +++++-
2 files changed, 132 insertions(+), 4 deletions(-)
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index 17ca316..7612643 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -213,7 +213,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()
@@ -227,18 +228,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 ) );
}
}
@@ -1448,3 +1459,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 );
+ }
+}
+
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 847f948..535ca32 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -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
More information about the vlc-devel
mailing list