]> git.sesse.net Git - vlc/commitdiff
Qt: allow to change the art
authorAngelo Haller <angelo@szanni.org>
Tue, 28 Aug 2012 17:32:42 +0000 (19:32 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 28 Aug 2012 17:32:42 +0000 (19:32 +0200)
Close #1624
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/gui/qt4/components/info_panels.cpp
modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/components/interface_widgets.hpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp

index bdce71c5f83ee313da626ce7c234a2a2c2812dbe..f1391162fef4d8b68590e7d4c2db736fc0c7b478 100644 (file)
@@ -169,6 +169,7 @@ MetaPanel::MetaPanel( QWidget *parent,
     CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );
 
     CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
+    CONNECT( THEMIM->getIM(), artChanged( QString ), this, enterEditMode() );
 /*    CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
 
     /* We are not yet in Edit Mode */
index 85ce5325a8db7b28de59ab54c08ca3dcee5f9d44..0c0127e23967671dec75b1181fd3c923cdd49610 100644 (file)
@@ -50,6 +50,7 @@
 #include <QTimer>
 #include <QSlider>
 #include <QBitmap>
+#include <QUrl>
 
 #ifdef Q_WS_X11
 #   include <X11/Xlib.h>
@@ -520,6 +521,10 @@ CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
     CONNECT( action, triggered(), this, askForUpdate() );
     addAction( action );
 
+    action = new QAction( qtr( "Cover art from file" ), this );
+    CONNECT( action, triggered(), this, setArtFromFile() );
+    addAction( action );
+
     showArtUpdate( "" );
 }
 
@@ -570,6 +575,22 @@ void CoverArtLabel::askForUpdate()
     THEMIM->getIM()->requestArtUpdate( p_item );
 }
 
+void CoverArtLabel::setArtFromFile()
+{
+    if( !p_item )
+        return;
+
+    QString filePath = QFileDialog::getOpenFileName( this, qtr( "Choose Image" ),
+        p_intf->p_sys->filepath, qtr( "Image Files (*.gif *.jpg *.jpeg *.png)" ) );
+
+    if( filePath.isEmpty() )
+        return;
+
+    QString fileUrl = QUrl::fromLocalFile( filePath ).toString();
+
+    THEMIM->getIM()->setArt( p_item, fileUrl );
+}
+
 TimeLabel::TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType  )
     : ClickableQLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
       buffering( false ), showBuffering(false), bufVal( -1 ), displayType( _displayType )
index 97b8bc6236887d60b7f820c330747acbe5730271..0b7795e9ea882035ee2670760d39b8d09565811b 100644 (file)
@@ -248,6 +248,7 @@ public slots:
     void showArtUpdate( const QString& );
     void showArtUpdate( input_item_t * );
     void askForUpdate();
+    void setArtFromFile();
 };
 
 #endif
index 83721ac258b55ed1db1d034e8a05d93b39cb563b..75908469562889d2e739049aa4988293fea69755 100644 (file)
@@ -38,6 +38,7 @@
 #include <vlc_aout_intf.h>
 
 #include <QApplication>
+#include <QFile>
 
 #include <assert.h>
 
@@ -719,6 +720,23 @@ void InputManager::UpdateArt()
     emit artChanged( artUrl );
 }
 
+void InputManager::setArt( input_item_t *p_item, QString fileUrl )
+{
+    if( hasInput() )
+    {
+        char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
+        QString old_url = THEMIM->getIM()->decodeArtURL( p_item );
+
+        if( old_url.startsWith( QString::fromUtf8( psz_cachedir ) ) )
+            QFile( old_url ).remove(); /* Purge cached artwork */
+
+        free( psz_cachedir );
+
+        input_item_SetArtURL( p_item , fileUrl.toUtf8().constData() );
+        UpdateArt();
+    }
+}
+
 inline void InputManager::UpdateStats()
 {
     assert( p_input );
index 84ac9f9457006b74f3d4d97844579d68c03e7188..fd1e967bbc52cf12bbfa9ca15e8007032c5080a3 100644 (file)
@@ -149,6 +149,7 @@ public:
     bool hasVideo() { return hasInput() && b_video; }
     bool hasVisualisation();
     void requestArtUpdate( input_item_t *p_item );
+    void setArt( input_item_t *p_item, QString fileUrl );
 
     QString getName() { return oldName; }
     static const QString decodeArtURL( input_item_t *p_item );