From b11bba670cd0f02296aaaa8ddd8c8bcf384bffdd Mon Sep 17 00:00:00 2001 From: Angelo Haller Date: Tue, 28 Aug 2012 19:32:42 +0200 Subject: [PATCH] Qt: allow to change the art Close #1624 Signed-off-by: Jean-Baptiste Kempf --- modules/gui/qt4/components/info_panels.cpp | 1 + modules/gui/qt4/components/interface_widgets.cpp | 21 +++++++++++++++++++++ modules/gui/qt4/components/interface_widgets.hpp | 1 + modules/gui/qt4/input_manager.cpp | 18 ++++++++++++++++++ modules/gui/qt4/input_manager.hpp | 1 + 5 files changed, 42 insertions(+) diff --git a/modules/gui/qt4/components/info_panels.cpp b/modules/gui/qt4/components/info_panels.cpp index bdce71c5f8..f1391162fe 100644 --- a/modules/gui/qt4/components/info_panels.cpp +++ b/modules/gui/qt4/components/info_panels.cpp @@ -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 */ diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp index 85ce5325a8..0c0127e239 100644 --- a/modules/gui/qt4/components/interface_widgets.cpp +++ b/modules/gui/qt4/components/interface_widgets.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #ifdef Q_WS_X11 # include @@ -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 ) diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp index 97b8bc6236..0b7795e9ea 100644 --- a/modules/gui/qt4/components/interface_widgets.hpp +++ b/modules/gui/qt4/components/interface_widgets.hpp @@ -248,6 +248,7 @@ public slots: void showArtUpdate( const QString& ); void showArtUpdate( input_item_t * ); void askForUpdate(); + void setArtFromFile(); }; #endif diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp index 83721ac258..7590846956 100644 --- a/modules/gui/qt4/input_manager.cpp +++ b/modules/gui/qt4/input_manager.cpp @@ -38,6 +38,7 @@ #include #include +#include #include @@ -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 ); diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp index 84ac9f9457..fd1e967bbc 100644 --- a/modules/gui/qt4/input_manager.hpp +++ b/modules/gui/qt4/input_manager.hpp @@ -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 ); -- 2.11.4.GIT