Commit 8cc3d3c2 authored by Ilkka Ollakka's avatar Ilkka Ollakka

Qt4: refactor album art stuff into inputmanager

 Input manager now emits signal for album art and gives
 url to art itself, so CoverArt or Background-widgets don't
 need to parse it themself, and CoverArt don't need to use
 those callbacks. This ways both get same image too.
parent 802ec3e2
...@@ -106,7 +106,7 @@ MetaPanel::MetaPanel( QWidget *parent, ...@@ -106,7 +106,7 @@ MetaPanel::MetaPanel( QWidget *parent,
line++; line++;
/* ART_URL */ /* ART_URL */
art_cover = new CoverArtLabel( this, VLC_OBJECT( p_intf ) ); art_cover = new CoverArtLabel( this, p_intf );
metaLayout->addWidget( art_cover, line, 8, 4, 2, Qt::AlignRight ); metaLayout->addWidget( art_cover, line, 8, 4, 2, Qt::AlignRight );
/* Settings is unused */ /* Settings is unused */
...@@ -226,8 +226,6 @@ void MetaPanel::update( input_item_t *p_item ) ...@@ -226,8 +226,6 @@ void MetaPanel::update( input_item_t *p_item )
#undef UPDATE_META_INT #undef UPDATE_META_INT
#undef UPDATE_META #undef UPDATE_META
/* Update Art */
art_cover->update( p_item );
} }
/** /**
...@@ -321,7 +319,6 @@ void MetaPanel::clear() ...@@ -321,7 +319,6 @@ void MetaPanel::clear()
language_text->clear(); language_text->clear();
nowplaying_text->clear(); nowplaying_text->clear();
publisher_text->clear(); publisher_text->clear();
art_cover->update( NULL );
setEditMode( false ); setEditMode( false );
emit uriSet( "" ); emit uriSet( "" );
......
...@@ -182,8 +182,8 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) ...@@ -182,8 +182,8 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
backgroundLayout->setColumnStretch( 0, 1 ); backgroundLayout->setColumnStretch( 0, 1 );
backgroundLayout->setColumnStretch( 2, 1 ); backgroundLayout->setColumnStretch( 2, 1 );
CONNECT( THEMIM->getIM(), artChanged( input_item_t* ), CONNECT( THEMIM->getIM(), artChanged( QString ),
this, updateArt( input_item_t* ) ); this, updateArt( QString ) );
} }
BackgroundWidget::~BackgroundWidget() BackgroundWidget::~BackgroundWidget()
...@@ -197,16 +197,8 @@ void BackgroundWidget::resizeEvent( QResizeEvent * event ) ...@@ -197,16 +197,8 @@ void BackgroundWidget::resizeEvent( QResizeEvent * event )
label->show(); label->show();
} }
void BackgroundWidget::updateArt( input_item_t *p_item ) void BackgroundWidget::updateArt( QString url )
{ {
QString url;
if( p_item )
{
char *psz_art = input_item_GetArtURL( p_item );
url = psz_art;
free( psz_art );
}
if( url.isEmpty() ) if( url.isEmpty() )
{ {
if( QDate::currentDate().dayOfYear() >= 354 ) if( QDate::currentDate().dayOfYear() >= 354 )
...@@ -216,9 +208,6 @@ void BackgroundWidget::updateArt( input_item_t *p_item ) ...@@ -216,9 +208,6 @@ void BackgroundWidget::updateArt( input_item_t *p_item )
} }
else 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 ) ); label->setPixmap( QPixmap( url ) );
} }
} }
...@@ -411,32 +400,13 @@ void SpeedControlWidget::resetRate() ...@@ -411,32 +400,13 @@ void SpeedControlWidget::resetRate()
THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT ); THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
} }
static int downloadCoverCallback( vlc_object_t *p_this, CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
char const *psz_var, : QLabel( parent ), p_intf( _p_i )
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( QWidget *parent,
vlc_object_t *_p_this,
input_item_t *_p_input )
: QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
{ {
setContextMenuPolicy( Qt::ActionsContextMenu ); setContextMenuPolicy( Qt::ActionsContextMenu );
CONNECT( this, updateRequested(), this, doUpdate() ); CONNECT( this, updateRequested(), this, doUpdate() );
CONNECT( THEMIM->getIM(), artChanged( QString ),
playlist_t *p_playlist = pl_Hold( p_this ); this, doUpdate( QString ) );
var_AddCallback( p_playlist, "item-change",
downloadCoverCallback, this );
pl_Release( p_this );
setMinimumHeight( 128 ); setMinimumHeight( 128 );
setMinimumWidth( 128 ); setMinimumWidth( 128 );
...@@ -447,80 +417,22 @@ CoverArtLabel::CoverArtLabel( QWidget *parent, ...@@ -447,80 +417,22 @@ CoverArtLabel::CoverArtLabel( QWidget *parent,
doUpdate(); doUpdate();
} }
CoverArtLabel::~CoverArtLabel() void CoverArtLabel::doUpdate( QString url )
{
playlist_t *p_playlist = pl_Hold( p_this );
var_DelCallback( p_playlist, "item-change", downloadCoverCallback, this );
pl_Release( p_this );
if( p_input )
vlc_gc_decref( p_input );
};
void CoverArtLabel::downloadCover()
{ {
if( p_input ) QPixmap pix;
if( !url.isEmpty() && pix.load( url ) )
{ {
playlist_t *p_playlist = pl_Hold( p_this ); setPixmap( pix );
playlist_AskForArtEnqueue( p_playlist, p_input, pl_Unlocked ); }
pl_Release( p_this ); else
{
setPixmap( QPixmap( ":/noart.png" ) );
} }
} }
void CoverArtLabel::doUpdate() void CoverArtLabel::doUpdate()
{ {
if( !p_input ) THEMIM->getIM()->requestArtUpdate();
{
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 )
{
QPixmap pix;
if( pix.load( artUrl ) )
setPixmap( pix );
else
{
msg_Dbg( p_this, "Qt could not load image '%s'",
qtu( artUrl ) );
setPixmap( QPixmap( ":/noart.png" ) );
}
}
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 );
}
} }
TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf ) TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
......
...@@ -105,7 +105,7 @@ private: ...@@ -105,7 +105,7 @@ private:
public slots: public slots:
void toggle(){ TOGGLEV( this ); } void toggle(){ TOGGLEV( this ); }
void updateArt( input_item_t* ); void updateArt( QString );
}; };
#if 0 #if 0
...@@ -193,30 +193,22 @@ class CoverArtLabel : public QLabel ...@@ -193,30 +193,22 @@ class CoverArtLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
CoverArtLabel( QWidget *parent, CoverArtLabel( QWidget *parent, intf_thread_t * );
vlc_object_t *p_this, virtual ~CoverArtLabel(){};
input_item_t *p_input = NULL );
virtual ~CoverArtLabel();
private: private:
input_item_t *p_input; intf_thread_t *p_intf;
vlc_object_t *p_this;
QString prevArt;
public slots: public slots:
void requestUpdate() { emit updateRequested(); }; void requestUpdate() { emit updateRequested(); };
void update( input_item_t* p_item ) void update( )
{ {
if( p_input ) vlc_gc_decref( p_input );
if( ( p_input = p_item ) )
vlc_gc_incref( p_input );
requestUpdate(); requestUpdate();
} }
private slots: private slots:
void doUpdate(); void doUpdate();
void downloadCover(); void doUpdate(QString);
signals: signals:
void updateRequested(); void updateRequested();
......
...@@ -70,7 +70,7 @@ class ArtLabel : public CoverArtLabel ...@@ -70,7 +70,7 @@ class ArtLabel : public CoverArtLabel
Q_OBJECT Q_OBJECT
public: public:
ArtLabel( QWidget *parent, intf_thread_t *intf ) ArtLabel( QWidget *parent, intf_thread_t *intf )
: CoverArtLabel( parent, VLC_OBJECT( intf ) ) {}; : CoverArtLabel( parent, intf ) {};
void mouseDoubleClickEvent( QMouseEvent *event ) void mouseDoubleClickEvent( QMouseEvent *event )
{ {
THEDP->mediaInfoDialog(); THEDP->mediaInfoDialog();
......
...@@ -199,7 +199,7 @@ void InputManager::customEvent( QEvent *event ) ...@@ -199,7 +199,7 @@ void InputManager::customEvent( QEvent *event )
case ItemChanged_Type: case ItemChanged_Type:
UpdateStatus(); UpdateStatus();
// UpdateName(); // UpdateName();
// UpdateArt(); UpdateArt();
break; break;
case ItemStateChanged_Type: case ItemStateChanged_Type:
// TODO: Fusion with above state // TODO: Fusion with above state
...@@ -533,10 +533,31 @@ void InputManager::UpdateCaching() ...@@ -533,10 +533,31 @@ void InputManager::UpdateCaching()
} }
} }
inline void InputManager::UpdateArt() void InputManager::requestArtUpdate()
{ {
if( hasInput() )
{
playlist_t *p_playlist = pl_Hold( p_intf );
playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
pl_Release( p_intf );
}
}
void InputManager::UpdateArt()
{
QString url;
if( hasInput() )
{
char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
url = psz_art;
free( psz_art );
}
url = url.replace( "file://", QString("" ) );
/* Taglib seems to define a attachment://, It won't work yet */
url = url.replace( "attachment://", QString("" ) );
/* Update Art meta */ /* Update Art meta */
emit artChanged( input_GetItem( p_input ) ); emit artChanged( url );
} }
inline void InputManager::UpdateStats() inline void InputManager::UpdateStats()
......
...@@ -97,6 +97,7 @@ public: ...@@ -97,6 +97,7 @@ public:
bool hasAudio(); bool hasAudio();
bool hasVideo() { return hasInput() && b_video; } bool hasVideo() { return hasInput() && b_video; }
void requestArtUpdate();
QString getName() { return oldName; } QString getName() { return oldName; }
...@@ -169,7 +170,7 @@ signals: ...@@ -169,7 +170,7 @@ signals:
void statisticsUpdated( input_item_t* ); void statisticsUpdated( input_item_t* );
void infoChanged( input_item_t* ); void infoChanged( input_item_t* );
void metaChanged( input_item_t* ); void metaChanged( input_item_t* );
void artChanged( input_item_t* ); void artChanged( QString );
/// Play/pause status /// Play/pause status
void statusChanged( int ); void statusChanged( int );
/// Teletext /// Teletext
......
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