From 8dbb3f39280e6c97cfee687b266e64d63d96e420 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Sun, 24 Jun 2007 00:22:18 +0000 Subject: [PATCH] Reverts [20669] Adds a button into qt4 media information to write modified meta data to the file --- include/vlc_common.h | 1 + include/vlc_meta.h | 6 +++ modules/gui/qt4/components/infopanels.cpp | 54 +++++++++++++++++++++++ modules/gui/qt4/components/infopanels.hpp | 2 + modules/gui/qt4/dialogs/mediainfo.cpp | 1 + modules/meta_engine/taglib.cpp | 24 +++++----- 6 files changed, 75 insertions(+), 13 deletions(-) diff --git a/include/vlc_common.h b/include/vlc_common.h index 9707358799..0aef0661c6 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -429,6 +429,7 @@ typedef struct vlm_message_t vlm_message_t; /* divers */ typedef struct vlc_meta_t vlc_meta_t; +typedef struct meta_export_t meta_export_t; /* Stats */ typedef struct counter_t counter_t; diff --git a/include/vlc_meta.h b/include/vlc_meta.h index 3a528de4c9..28bd4acfce 100644 --- a/include/vlc_meta.h +++ b/include/vlc_meta.h @@ -227,6 +227,12 @@ enum { ALBUM_ART_ALL }; +struct meta_export_t +{ + input_item_t *p_item; + const char *psz_file; +}; + #define VLC_META_ENGINE_TITLE 0x00000001 #define VLC_META_ENGINE_ARTIST 0x00000004 #define VLC_META_ENGINE_GENRE 0x00000008 diff --git a/modules/gui/qt4/components/infopanels.cpp b/modules/gui/qt4/components/infopanels.cpp index 499f1ab0fb..52cda41e5d 100644 --- a/modules/gui/qt4/components/infopanels.cpp +++ b/modules/gui/qt4/components/infopanels.cpp @@ -114,6 +114,11 @@ MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) : ADD_META_B( VLC_META_ENCODED_BY, publisher_text ); ADD_META_B( VLC_META_DESCRIPTION, description_text ); // Comment Two lines? + QPushButton *write = new QPushButton( qtr( "&Write" ) ); + l->addWidget( write, line, 0 ); + + BUTTONACT( write, saveMeta() ); + /* ADD_META( TRACKID) DO NOT SHOW it */ /* ADD_URI - DO not show it, done outside */ @@ -127,6 +132,55 @@ MetaPanel::~MetaPanel() { } +void MetaPanel::saveMeta() +{ + playlist_t *p_playlist; + + meta_export_t p_export; + p_export.p_item = p_input; + + /* we can write meta data only in a file */ + if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \ + ( p_input->i_type == ITEM_TYPE_VFILE ) ) + /* some audio files are detected as video files */ + { + char *psz_uri = p_input->psz_uri; + if( !strncmp( psz_uri, "file://", 7 ) ) + psz_uri += 7; /* strlen("file://") = 7 */ + + p_export.psz_file = strndup( psz_uri, PATH_MAX ); + } + else + return; + + /* now we read the modified meta data */ + free( p_input->p_meta->psz_artist ); + p_input->p_meta->psz_artist = strdup( artist_text->text().toUtf8() ); + free( p_input->p_meta->psz_album ); + p_input->p_meta->psz_album = strdup( collection_text->text().toUtf8() ); + free( p_input->p_meta->psz_genre ); + p_input->p_meta->psz_genre = strdup( genre_text->text().toUtf8() ); + free( p_input->p_meta->psz_date ); + p_input->p_meta->psz_date = (char*) malloc(5); + snprintf( p_input->p_meta->psz_date, 5, "%d", date_text->value() ); + free( p_input->p_meta->psz_tracknum ); + p_input->p_meta->psz_tracknum = (char*) malloc(5); + snprintf( p_input->p_meta->psz_tracknum, 5, "%d", seqnum_text->value() ); + free( p_input->p_meta->psz_title ); + p_input->p_meta->psz_title = strdup( title_text->text().toUtf8() ); + + p_playlist = pl_Yield( p_intf ); + + PL_LOCK; + p_playlist->p_private = &p_export; + + module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 ); + if( p_mod ) + module_Unneed( p_playlist, p_mod ); + PL_UNLOCK; + pl_Release( p_playlist ); +} + void MetaPanel::update( input_item_t *p_item ) { char *psz_meta; diff --git a/modules/gui/qt4/components/infopanels.hpp b/modules/gui/qt4/components/infopanels.hpp index 54fce5d230..7a95dfa9ec 100644 --- a/modules/gui/qt4/components/infopanels.hpp +++ b/modules/gui/qt4/components/infopanels.hpp @@ -53,6 +53,7 @@ class MetaPanel: public QWidget public: MetaPanel( QWidget *, intf_thread_t * ); virtual ~MetaPanel(); + input_item_t *p_input; private: intf_thread_t *p_intf; QLineEdit *uri_text; @@ -74,6 +75,7 @@ private: public slots: void update( input_item_t * ); void clear(); + void saveMeta(); signals: void uriSet( QString ); }; diff --git a/modules/gui/qt4/dialogs/mediainfo.cpp b/modules/gui/qt4/dialogs/mediainfo.cpp index 75bbe4e6a4..9efb50d4bd 100644 --- a/modules/gui/qt4/dialogs/mediainfo.cpp +++ b/modules/gui/qt4/dialogs/mediainfo.cpp @@ -142,6 +142,7 @@ void MediaInfoDialog::update() void MediaInfoDialog::update( input_item_t *p_item, bool update_info, bool update_meta ) { + MP->p_input = p_item; if( update_info ) IP->update( p_item ); if( update_meta ) diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp index bf9dd0c96c..bb3958aaba 100644 --- a/modules/meta_engine/taglib.cpp +++ b/modules/meta_engine/taglib.cpp @@ -166,29 +166,25 @@ static int ReadMeta( vlc_object_t *p_this ) return VLC_EGENERIC; } +#define SET(a,b) if(b) tag->set##a( b ); + static int WriteMeta( vlc_object_t *p_this ) { - input_item_t *p_item = (input_item_t *)p_this; - - char *psz_uri = p_item->psz_uri; - /* we can write meta data only in a file */ - if( !strncmp( psz_uri, "file://", 7 ) ) - psz_uri += 7; - /* if the file is specified with its path, not prefixed with file:// */ - else if( strncmp( psz_uri, "/", 1 ) ) - return VLC_EGENERIC; + playlist_t *p_playlist = (playlist_t *)p_this; + meta_export_t *p_export = (meta_export_t *)p_playlist->p_private; + input_item_t *p_item = p_export->p_item; - TagLib::FileRef f( psz_uri ); + TagLib::FileRef f( p_export->psz_file ); if( !f.isNull() && f.tag() ) { TagLib::Tag *tag = f.tag(); - tag->setArtist( p_item->p_meta->psz_artist ); + SET( Artist, p_item->p_meta->psz_artist ); if( p_item->p_meta->psz_title ) tag->setTitle( p_item->p_meta->psz_title ); else tag->setTitle( p_item->psz_name ); - tag->setAlbum( p_item->p_meta->psz_album ); - tag->setGenre( p_item->p_meta->psz_genre ); + SET( Album, p_item->p_meta->psz_album ); + SET( Genre, p_item->p_meta->psz_genre ); if( p_item->p_meta->psz_date ) tag->setYear( atoi( p_item->p_meta->psz_date ) ); if( p_item->p_meta->psz_tracknum ) @@ -196,6 +192,8 @@ static int WriteMeta( vlc_object_t *p_this ) f.save(); return VLC_SUCCESS; } + msg_Err( p_this, "File %s can't be opened for tag writing\n", + p_export->psz_file ); return VLC_EGENERIC; } -- 2.39.5