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,
line++;
/* 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 );
/* Settings is unused */
......@@ -226,8 +226,6 @@ void MetaPanel::update( input_item_t *p_item )
#undef UPDATE_META_INT
#undef UPDATE_META
/* Update Art */
art_cover->update( p_item );
}
/**
......@@ -321,7 +319,6 @@ void MetaPanel::clear()
language_text->clear();
nowplaying_text->clear();
publisher_text->clear();
art_cover->update( NULL );
setEditMode( false );
emit uriSet( "" );
......
......@@ -182,8 +182,8 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
backgroundLayout->setColumnStretch( 0, 1 );
backgroundLayout->setColumnStretch( 2, 1 );
CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
this, updateArt( input_item_t* ) );
CONNECT( THEMIM->getIM(), artChanged( QString ),
this, updateArt( QString ) );
}
BackgroundWidget::~BackgroundWidget()
......@@ -197,16 +197,8 @@ void BackgroundWidget::resizeEvent( QResizeEvent * event )
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( QDate::currentDate().dayOfYear() >= 354 )
......@@ -216,9 +208,6 @@ void BackgroundWidget::updateArt( input_item_t *p_item )
}
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 ) );
}
}
......@@ -411,32 +400,13 @@ 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( QWidget *parent,
vlc_object_t *_p_this,
input_item_t *_p_input )
: QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
: QLabel( parent ), p_intf( _p_i )
{
setContextMenuPolicy( Qt::ActionsContextMenu );
CONNECT( this, updateRequested(), this, doUpdate() );
playlist_t *p_playlist = pl_Hold( p_this );
var_AddCallback( p_playlist, "item-change",
downloadCoverCallback, this );
pl_Release( p_this );
CONNECT( THEMIM->getIM(), artChanged( QString ),
this, doUpdate( QString ) );
setMinimumHeight( 128 );
setMinimumWidth( 128 );
......@@ -447,82 +417,24 @@ CoverArtLabel::CoverArtLabel( QWidget *parent,
doUpdate();
}
CoverArtLabel::~CoverArtLabel()
{
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 )
{
playlist_t *p_playlist = pl_Hold( p_this );
playlist_AskForArtEnqueue( p_playlist, p_input, pl_Unlocked );
pl_Release( p_this );
}
}
void CoverArtLabel::doUpdate()
void CoverArtLabel::doUpdate( QString url )
{
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 )
{
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() )
if( !url.isEmpty() && pix.load( url ) )
{
foreach( QAction *act, artActions )
removeAction( act );
}
prevArt = artUrl;
setPixmap( pix );
}
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 );
}
}
void CoverArtLabel::doUpdate()
{
THEMIM->getIM()->requestArtUpdate();
}
TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
{
b_remainingTime = false;
......
......@@ -105,7 +105,7 @@ private:
public slots:
void toggle(){ TOGGLEV( this ); }
void updateArt( input_item_t* );
void updateArt( QString );
};
#if 0
......@@ -193,30 +193,22 @@ class CoverArtLabel : public QLabel
{
Q_OBJECT
public:
CoverArtLabel( QWidget *parent,
vlc_object_t *p_this,
input_item_t *p_input = NULL );
virtual ~CoverArtLabel();
CoverArtLabel( QWidget *parent, intf_thread_t * );
virtual ~CoverArtLabel(){};
private:
input_item_t *p_input;
vlc_object_t *p_this;
QString prevArt;
intf_thread_t *p_intf;
public slots:
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();
}
private slots:
void doUpdate();
void downloadCover();
void doUpdate(QString);
signals:
void updateRequested();
......
......@@ -70,7 +70,7 @@ class ArtLabel : public CoverArtLabel
Q_OBJECT
public:
ArtLabel( QWidget *parent, intf_thread_t *intf )
: CoverArtLabel( parent, VLC_OBJECT( intf ) ) {};
: CoverArtLabel( parent, intf ) {};
void mouseDoubleClickEvent( QMouseEvent *event )
{
THEDP->mediaInfoDialog();
......
......@@ -199,7 +199,7 @@ void InputManager::customEvent( QEvent *event )
case ItemChanged_Type:
UpdateStatus();
// UpdateName();
// UpdateArt();
UpdateArt();
break;
case ItemStateChanged_Type:
// TODO: Fusion with above state
......@@ -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 */
emit artChanged( input_GetItem( p_input ) );
emit artChanged( url );
}
inline void InputManager::UpdateStats()
......
......@@ -97,6 +97,7 @@ public:
bool hasAudio();
bool hasVideo() { return hasInput() && b_video; }
void requestArtUpdate();
QString getName() { return oldName; }
......@@ -169,7 +170,7 @@ signals:
void statisticsUpdated( input_item_t* );
void infoChanged( input_item_t* );
void metaChanged( input_item_t* );
void artChanged( input_item_t* );
void artChanged( QString );
/// Play/pause status
void statusChanged( int );
/// 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