]> git.sesse.net Git - vlc/commitdiff
Qt4: refactor album art stuff into inputmanager
authorIlkka Ollakka <ileoo@videolan.org>
Mon, 12 Jan 2009 13:24:20 +0000 (15:24 +0200)
committerIlkka Ollakka <ileoo@videolan.org>
Mon, 12 Jan 2009 13:24:20 +0000 (15:24 +0200)
 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.

modules/gui/qt4/components/info_panels.cpp
modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/components/interface_widgets.hpp
modules/gui/qt4/components/playlist/playlist.hpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp

index e47e8a75c7540d09c0889e4ce69133daf0bb52ba..30a517033931cd54a37ee207313025210be5081a 100644 (file)
@@ -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( "" );
index 69b2ace122a99b1e24a3d2221254254fe534798e..806e52c6301afe74e53580bb9d27bb2666283f57 100644 (file)
@@ -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,80 +417,22 @@ 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()
+void CoverArtLabel::doUpdate( QString url )
 {
-    if( p_input )
+    QPixmap pix;
+    if( !url.isEmpty()  && pix.load( url ) )
     {
-        playlist_t *p_playlist = pl_Hold( p_this );
-        playlist_AskForArtEnqueue( p_playlist, p_input, pl_Unlocked );
-        pl_Release( p_this );
+        setPixmap( pix );
+    }
+    else
+    {
+        setPixmap( QPixmap( ":/noart.png" ) );
     }
 }
 
 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 )
-            {
-                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 );
-    }
+    THEMIM->getIM()->requestArtUpdate();
 }
 
 TimeLabel::TimeLabel( intf_thread_t *_p_intf  ) :QLabel(), p_intf( _p_intf )
index 746b147950d82670e45905b756f31578c5dd1f27..de3d220e9599905db16d47ae27c281c59d10ba17 100644 (file)
@@ -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();
index 7b284bc67b72516891b9cd0470ca41bc034df1b1..b3f59b22ae9e50fc9c722028c147e5b874ef1559 100644 (file)
@@ -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();
index 1bc8602bae0e5d42999ee345946759f08030930e..51026448c5fac8b7a74f561fdc8ca97e3daaac28 100644 (file)
@@ -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()
index b76358314f43552cfe5c82d8e20ac69c4569167a..777da8fa9d7bf3460122eee4b1aa8fc7d8f5053b 100644 (file)
@@ -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