diff --git a/src/libtomahawk/.filemetadata.swo b/src/libtomahawk/.filemetadata.swo new file mode 100644 index 000000000..49da86f09 Binary files /dev/null and b/src/libtomahawk/.filemetadata.swo differ diff --git a/src/libtomahawk/.filemetadata.swp b/src/libtomahawk/.filemetadata.swp new file mode 100644 index 000000000..e309c7bab Binary files /dev/null and b/src/libtomahawk/.filemetadata.swp differ diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 62e6ce9b2..be85739dc 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -269,6 +269,7 @@ set( libSources filemetadata/taghandlers/id3v2tag.cpp filemetadata/taghandlers/mp4tag.cpp filemetadata/taghandlers/oggtag.cpp + filemetadata/MetadataEditor.cpp network/BufferIoDevice.cpp network/MsgProcessor.cpp @@ -317,6 +318,7 @@ set( libUI ${libUI} widgets/infowidgets/TrackInfoWidget.ui playlist/topbar/TopBar.ui playlist/QueueView.ui + filemetadata/MetadataEditor.ui context/ContextWidget.ui infobar/InfoBar.ui accounts/AccountFactoryWrapper.ui diff --git a/src/libtomahawk/ContextMenu.cpp b/src/libtomahawk/ContextMenu.cpp index faaac4bbe..d03ff389f 100644 --- a/src/libtomahawk/ContextMenu.cpp +++ b/src/libtomahawk/ContextMenu.cpp @@ -23,11 +23,15 @@ #include "PlaylistView.h" #include "ViewManager.h" #include "Query.h" +#include "Result.h" +#include "Collection.h" #include "Source.h" #include "Artist.h" #include "Album.h" + #include "utils/Logger.h" #include "audio/AudioEngine.h" +#include "filemetadata/MetadataEditor.h" using namespace Tomahawk; @@ -39,7 +43,7 @@ ContextMenu::ContextMenu( QWidget* parent ) m_sigmap = new QSignalMapper( this ); connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( onTriggered( int ) ) ); - m_supportedActions = ActionPlay | ActionQueue | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage; + m_supportedActions = ActionPlay | ActionQueue | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage | ActionEditMetadata; } @@ -107,6 +111,18 @@ ContextMenu::setQueries( const QList& queries ) if ( m_supportedActions & ActionPage && itemCount() == 1 ) m_sigmap->setMapping( addAction( tr( "&Show Track Page" ) ), ActionPage ); + if ( m_supportedActions & ActionEditMetadata && itemCount() == 1 ) { + + if ( m_queries.first()->results().isEmpty() ) + return; + + Tomahawk::result_ptr result = m_queries.first()->results().first(); + if ( result->collection() && result->collection()->source() && + result->collection()->source()->isLocal() ) { + m_sigmap->setMapping( addAction( tr( "Edit Metadata") ), ActionEditMetadata ); + } + } + addSeparator(); if ( m_supportedActions & ActionDelete ) @@ -240,6 +256,13 @@ ContextMenu::onTriggered( int action ) AudioEngine::instance()->setStopAfterTrack( m_queries.first() ); break; + case ActionEditMetadata: + if ( !m_queries.first()->results().isEmpty() ) { + MetadataEditor* d = new MetadataEditor( m_queries.first()->results().first(), this ); + d->show(); + } + break; + default: emit triggered( action ); } diff --git a/src/libtomahawk/ContextMenu.h b/src/libtomahawk/ContextMenu.h index 9f1e28def..5f757c5b8 100644 --- a/src/libtomahawk/ContextMenu.h +++ b/src/libtomahawk/ContextMenu.h @@ -42,7 +42,8 @@ public: ActionCopyLink = 8, ActionLove = 16, ActionStopAfter = 32, - ActionPage = 64 + ActionPage = 64, + ActionEditMetadata = 128 }; explicit ContextMenu( QWidget* parent = 0 ); diff --git a/src/libtomahawk/filemetadata/.MetadataEditor.cpp.swp b/src/libtomahawk/filemetadata/.MetadataEditor.cpp.swp new file mode 100644 index 000000000..4f81dec98 Binary files /dev/null and b/src/libtomahawk/filemetadata/.MetadataEditor.cpp.swp differ diff --git a/src/libtomahawk/filemetadata/MetadataEditor.cpp b/src/libtomahawk/filemetadata/MetadataEditor.cpp new file mode 100644 index 000000000..378b120f2 --- /dev/null +++ b/src/libtomahawk/filemetadata/MetadataEditor.cpp @@ -0,0 +1,119 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Christopher Reichert + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "MetadataEditor.h" +#include "ui_MetadataEditor.h" + +#include +#include +#include +#include + +#include "Result.h" +#include "Artist.h" +#include "Album.h" +#include "Typedefs.h" +#include "ScanManager.h" + +#include "taglib/fileref.h" +#include "filemetadata/taghandlers/tag.h" + +MetadataEditor::MetadataEditor( Tomahawk::result_ptr result, QWidget *parent ) + : QDialog( parent ) + , ui( new Ui::MetadataEditor ) + , m_result( result ) +{ + ui->setupUi( this ); + setWindowTitle( QString( result->track() + tr( " Properties" ) ) ); + setAttribute( Qt::WA_DeleteOnClose ); + + setTitle( result->track() ); + setArtist( result->artist()->name() ); + setAlbum( result->album()->name() ); + setDiscNumber( result->albumpos() ); + + connect( ui->buttonBox, SIGNAL( accepted() ), SLOT( writeMetadata() ) ); + connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( close() ) ); +} + + +void +MetadataEditor::writeMetadata() +{ + QFileInfo fi( QUrl( m_result->url() ).toLocalFile() ); + + QByteArray fileName = QFile::encodeName( fi.canonicalFilePath() ); + const char *encodedName = fileName.constData(); + + TagLib::FileRef f( encodedName ); + Tomahawk::Tag* tag = Tomahawk::Tag::fromFile( f ); + + if ( title() != m_result->track() ) { + tag->setTitle( title() ); + m_result->setTrack( title() ); + } + + Tomahawk::artist_ptr newArtist = Tomahawk::Artist::get( artist() ); + if ( artist() != m_result->artist()->name() ) { + tag->setArtist( artist() ); + m_result->setArtist( newArtist ); + } + + if( album() != m_result->album()->name() ) { + tag->setAlbum( album() ); + m_result->setAlbum( Tomahawk::Album::get( newArtist, album() ) ); + } + + tag->setTrack( discnumber() ); + m_result->setDiscNumber( discnumber() ); + + f.save(); + + QStringList files = QStringList( fileName ); + ScanManager::instance()->runFileScan( files ); + close(); +} + + +void +MetadataEditor::setTitle( const QString& title ) +{ + ui->titleLineEdit->setText( title ); +} + + +void +MetadataEditor::setArtist( const QString& artist ) +{ + ui->artistLineEdit->setText( artist ); +} + + +void +MetadataEditor::setAlbum( const QString& album ) +{ + ui->albumLineEdit->setText( album ); +} + + +void +MetadataEditor::setDiscNumber( unsigned int num ) +{ + ui->discNumberSpinBox->setValue( num ); +} + diff --git a/src/libtomahawk/filemetadata/MetadataEditor.h b/src/libtomahawk/filemetadata/MetadataEditor.h new file mode 100644 index 000000000..79f3ff32f --- /dev/null +++ b/src/libtomahawk/filemetadata/MetadataEditor.h @@ -0,0 +1,60 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Christopher Reichert + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef METADATAEDITOR_H +#define METADATAEDITOR_H + +#include +#include +#include + +#include "ui_MetadataEditor.h" +#include "Result.h" +#include "Typedefs.h" + +class QString; + + +class MetadataEditor : public QDialog +{ +Q_OBJECT + +public: + MetadataEditor( Tomahawk::result_ptr result, QWidget* parent = 0 ); + ~MetadataEditor() {}; + + QString title() { return ui->titleLineEdit->text(); } + QString artist() { return ui->artistLineEdit->text(); } + QString album() { return ui->albumLineEdit->text(); } + int discnumber() { return ui->discNumberSpinBox->value(); } + +private slots: + void writeMetadata(); + + void setTitle( const QString& title ); + void setArtist( const QString& artist ); + void setAlbum( const QString& album ); + void setDiscNumber( unsigned int num ); + +private: + Ui::MetadataEditor* ui; + + Tomahawk::result_ptr m_result; +}; + +#endif // METADATAEDITOR_H diff --git a/src/libtomahawk/filemetadata/MetadataEditor.ui b/src/libtomahawk/filemetadata/MetadataEditor.ui new file mode 100644 index 000000000..c690c8bb9 --- /dev/null +++ b/src/libtomahawk/filemetadata/MetadataEditor.ui @@ -0,0 +1,166 @@ + + + MetadataEditor + + + + 0 + 0 + 367 + 223 + + + + Form + + + + + + + 0 + 0 + + + + Tags + + + false + + + false + + + + + + Title: + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Title... + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Artist... + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Album... + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + QAbstractSpinBox::NoButtons + + + 1 + + + + + + + Artist: + + + + + + + Album + + + + + + + Disc Number: + + + + + + + + + + + + false + + + Back + + + + + + + false + + + Forward + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + diff --git a/src/libtomahawk/filemetadata/ScanManager.cpp b/src/libtomahawk/filemetadata/ScanManager.cpp index 5c0c18b07..889fa58c1 100644 --- a/src/libtomahawk/filemetadata/ScanManager.cpp +++ b/src/libtomahawk/filemetadata/ScanManager.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "MusicScanner.h" #include "TomahawkSettings.h" @@ -179,6 +180,8 @@ bool ScanManager::runFileScan( const QStringList &paths ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + foreach( const QString& path, paths ) + m_currScannerPaths.insert( path ); if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) ) return false; @@ -191,7 +194,6 @@ ScanManager::runFileScan( const QStringList &paths ) m_scanTimer->stop(); m_musicScannerThreadController = new QThread( this ); - m_currScannerPaths = paths; m_currScanMode = FileScan; QMetaObject::invokeMethod( this, "runScan", Qt::QueuedConnection ); @@ -231,7 +233,7 @@ ScanManager::runScan() { tLog( LOGVERBOSE ) << Q_FUNC_INFO; - QStringList paths = m_currScannerPaths.empty() ? TomahawkSettings::instance()->scannerPaths() : m_currScannerPaths; + QStringList paths = m_currScannerPaths.empty() ? TomahawkSettings::instance()->scannerPaths() : m_currScannerPaths.toList(); if ( m_musicScannerThreadController || !m_scanner.isNull() ) //still running if these are not zero { @@ -263,7 +265,7 @@ ScanManager::scannerFinished() } m_scanTimer->start(); - m_currScannerPaths = QStringList(); + m_currScannerPaths = QSet< QString >(); SourceList::instance()->getLocal()->scanningFinished( 0 ); emit finished(); } diff --git a/src/libtomahawk/filemetadata/ScanManager.h b/src/libtomahawk/filemetadata/ScanManager.h index 715260233..6c04e51fd 100644 --- a/src/libtomahawk/filemetadata/ScanManager.h +++ b/src/libtomahawk/filemetadata/ScanManager.h @@ -73,7 +73,7 @@ private: ScanMode m_currScanMode; QWeakPointer< MusicScanner > m_scanner; QThread* m_musicScannerThreadController; - QStringList m_currScannerPaths; + QSet< QString > m_currScannerPaths; QStringList m_cachedScannerDirs; QTimer* m_scanTimer;