mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 15:01:11 +02:00
Metadata editor initial commit.
This commit is contained in:
BIN
src/libtomahawk/.filemetadata.swo
Normal file
BIN
src/libtomahawk/.filemetadata.swo
Normal file
Binary file not shown.
BIN
src/libtomahawk/.filemetadata.swp
Normal file
BIN
src/libtomahawk/.filemetadata.swp
Normal file
Binary file not shown.
@@ -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
|
||||
|
@@ -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<Tomahawk::query_ptr>& 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 );
|
||||
}
|
||||
|
@@ -42,7 +42,8 @@ public:
|
||||
ActionCopyLink = 8,
|
||||
ActionLove = 16,
|
||||
ActionStopAfter = 32,
|
||||
ActionPage = 64
|
||||
ActionPage = 64,
|
||||
ActionEditMetadata = 128
|
||||
};
|
||||
|
||||
explicit ContextMenu( QWidget* parent = 0 );
|
||||
|
BIN
src/libtomahawk/filemetadata/.MetadataEditor.cpp.swp
Normal file
BIN
src/libtomahawk/filemetadata/.MetadataEditor.cpp.swp
Normal file
Binary file not shown.
119
src/libtomahawk/filemetadata/MetadataEditor.cpp
Normal file
119
src/libtomahawk/filemetadata/MetadataEditor.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2012, Christopher Reichert <creichert07@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MetadataEditor.h"
|
||||
#include "ui_MetadataEditor.h"
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#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 );
|
||||
}
|
||||
|
60
src/libtomahawk/filemetadata/MetadataEditor.h
Normal file
60
src/libtomahawk/filemetadata/MetadataEditor.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2012, Christopher Reichert <creichert07@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef METADATAEDITOR_H
|
||||
#define METADATAEDITOR_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QSpinBox>
|
||||
|
||||
#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
|
166
src/libtomahawk/filemetadata/MetadataEditor.ui
Normal file
166
src/libtomahawk/filemetadata/MetadataEditor.ui
Normal file
@@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MetadataEditor</class>
|
||||
<widget class="QWidget" name="MetadataEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>367</width>
|
||||
<height>223</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Tags</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Title:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="titleLineEdit">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Title...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="artistLineEdit">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Artist...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QLineEdit" name="albumLineEdit">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Album...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="1">
|
||||
<widget class="QSpinBox" name="discNumberSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Artist:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Album</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Disc Number:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Back</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Forward</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -22,6 +22,7 @@
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QSet>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user