Commit 03203fd0 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

Import dialog displays current tags and allows editing tags in table.

parent 1b03a647
......@@ -79,7 +79,7 @@
*/
ImportDialog::ImportDialog(QWidget* parent, QString& caption,
ImportTrackDataVector& trackDataList) :
QDialog(parent),
QDialog(parent), m_trackDataImported(false),
m_autoStartSubDialog(ASD_None),
m_trackDataVector(trackDataList)
{
......@@ -149,6 +149,8 @@ ImportDialog::ImportDialog(QWidget* parent, QString& caption,
m_destComboBox->insertItem(ImportConfig::DestV1, i18n("Tag 1"));
m_destComboBox->insertItem(ImportConfig::DestV2, i18n("Tag 2"));
m_destComboBox->insertItem(ImportConfig::DestV1V2, i18n("Tag 1 and Tag 2"));
connect(m_destComboBox, SIGNAL(activated(int)),
this, SLOT(changeTagDestination()));
destLabel->setBuddy(m_destComboBox);
butlayout->addWidget(m_destComboBox);
vlayout->addWidget(butbox);
......@@ -201,7 +203,7 @@ ImportDialog::ImportDialog(QWidget* parent, QString& caption,
hlayout->addWidget(cancelButton);
connect(helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
connect(saveButton, SIGNAL(clicked()), this, SLOT(saveConfig()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(okButton, SIGNAL(clicked()), this, SLOT(onOkButtonClicked()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
vlayout->addLayout(hlayout);
}
......@@ -261,23 +263,23 @@ void ImportDialog::fromText()
if (!m_textImportDialog) {
m_textImportDialog = new TextImportDialog(this, m_trackDataVector);
connect(m_textImportDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreview()));
this, SLOT(showPreviewAfterImport()));
}
m_textImportDialog->clear();
m_textImportDialog->show();
}
/**
* Display dialog with import source.
* Display server import dialog.
*
* @param source import source
*/
void ImportDialog::displayImportSourceDialog(ServerImporter* source)
void ImportDialog::displayServerImportDialog(ServerImporter* source)
{
if (!m_serverImportDialog) {
m_serverImportDialog = new ServerImportDialog(this);
connect(m_serverImportDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreview()));
this, SLOT(showPreviewAfterImport()));
}
if (m_serverImportDialog) {
m_serverImportDialog->setImportSource(source);
......@@ -306,7 +308,7 @@ void ImportDialog::fromFreedb()
if (!m_freedbImporter) {
m_freedbImporter = new FreedbImporter(this, m_trackDataVector);
}
displayImportSourceDialog(m_freedbImporter);
displayServerImportDialog(m_freedbImporter);
}
/**
......@@ -317,7 +319,7 @@ void ImportDialog::fromTrackType()
if (!m_trackTypeImporter) {
m_trackTypeImporter = new TrackTypeImporter(this, m_trackDataVector);
}
displayImportSourceDialog(m_trackTypeImporter);
displayServerImportDialog(m_trackTypeImporter);
}
/**
......@@ -329,7 +331,7 @@ void ImportDialog::fromMusicBrainzRelease()
m_musicBrainzReleaseImporter =
new MusicBrainzReleaseImporter(this, m_trackDataVector);
}
displayImportSourceDialog(m_musicBrainzReleaseImporter);
displayServerImportDialog(m_musicBrainzReleaseImporter);
}
/**
......@@ -340,7 +342,7 @@ void ImportDialog::fromDiscogs()
if (!m_discogsImporter) {
m_discogsImporter = new DiscogsImporter(this, m_trackDataVector);
}
displayImportSourceDialog(m_discogsImporter);
displayServerImportDialog(m_discogsImporter);
}
/**
......@@ -351,7 +353,7 @@ void ImportDialog::fromAmazon()
if (!m_amazonImporter) {
m_amazonImporter = new AmazonImporter(this, m_trackDataVector);
}
displayImportSourceDialog(m_amazonImporter);
displayServerImportDialog(m_amazonImporter);
}
/**
......@@ -363,7 +365,7 @@ void ImportDialog::fromMusicBrainz()
if (!m_musicBrainzDialog) {
m_musicBrainzDialog = new MusicBrainzDialog(this, m_trackDataVector);
connect(m_musicBrainzDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreview()));
this, SLOT(showPreviewAfterImport()));
}
if (m_musicBrainzDialog) {
m_musicBrainzDialog->initTable();
......@@ -449,6 +451,7 @@ void ImportDialog::setAutoStartSubDialog(AutoStartSubDialog asd)
*/
void ImportDialog::clear()
{
m_trackDataImported = false;
m_trackDataModel->setTrackData(ImportTrackDataVector());
m_serverComboBox->setCurrentIndex(Kid3App::s_genCfg.m_importServer);
......@@ -462,12 +465,15 @@ void ImportDialog::clear()
resize(Kid3App::s_genCfg.m_importWindowWidth,
Kid3App::s_genCfg.m_importWindowHeight);
}
showPreview();
}
/**
* Show fields to import in text as preview in table.
*/
void ImportDialog::showPreview() {
void ImportDialog::showPreview()
{
// make time difference check
bool diffCheckEnable;
int maxDiff;
......@@ -479,6 +485,17 @@ void ImportDialog::showPreview() {
m_trackDataTable->resizeRowsToContents();
}
/**
* Show fields to import in text as preview in table.
* This method also marks that an import was made and thus switching the tag
* version is no longer possible.
*/
void ImportDialog::showPreviewAfterImport()
{
m_trackDataImported = true;
showPreview();
}
/**
* Get import destination.
*
......@@ -575,6 +592,42 @@ void ImportDialog::moveTableRow(int, int fromIndex, int toIndex) {
}
}
/**
* Called when OK is clicked.
*/
void ImportDialog::onOkButtonClicked()
{
// Set changes made in the table in the track data.
m_trackDataVector = m_trackDataModel->getTrackData();
accept();
}
/**
* Called when the destination combo box value is changed.
*/
void ImportDialog::changeTagDestination()
{
// Prevent switching of track data after an import.
if (!m_trackDataImported) {
ImportConfig::ImportDestination dest = getDestination();
TrackData::TagVersion tagVersion = TrackData::TagNone;
switch (dest) {
case ImportConfig::DestV1:
tagVersion = TrackData::TagV1;
break;
case ImportConfig::DestV2:
tagVersion = TrackData::TagV2;
break;
case ImportConfig::DestV1V2:
tagVersion = TrackData::TagV2V1;
}
m_trackDataVector.readTags(tagVersion);
showPreview();
}
}
/**
* Match import data with length.
*/
......
......@@ -163,6 +163,13 @@ private slots:
*/
void showPreview();
/**
* Show fields to import in text as preview in table.
* This method also marks that an import was made and thus switching the tag
* version is no longer possible.
*/
void showPreviewAfterImport();
/**
* Match import data with length.
*/
......@@ -213,6 +220,16 @@ private slots:
*/
void hideSubdialogs();
/**
* Called when the destination combo box value is changed.
*/
void changeTagDestination();
/**
* Called when OK is clicked.
*/
void onOkButtonClicked();
private:
/**
* Get time difference check configuration.
......@@ -223,12 +240,15 @@ private:
void getTimeDifferenceCheck(bool& enable, int& maxDiff) const;
/**
* Display dialog with import source.
* Display server import dialog.
*
* @param source import source
*/
void displayImportSourceDialog(ServerImporter* source);
void displayServerImportDialog(ServerImporter* source);
/** true if an import has been made, reset by clear() */
bool m_trackDataImported;
/** Subdialog to open when starting */
AutoStartSubDialog m_autoStartSubDialog;
/** Preview table */
QTableView* m_trackDataTable;
......
......@@ -1686,13 +1686,27 @@ bool Kid3App::slotCreatePlaylist()
*/
void Kid3App::setupImportDialog()
{
TrackData::TagVersion tagVersion = TrackData::TagNone;
switch (s_genCfg.m_importDest) {
case ImportConfig::DestV1:
tagVersion = TrackData::TagV1;
break;
case ImportConfig::DestV2:
tagVersion = TrackData::TagV2;
break;
case ImportConfig::DestV1V2:
tagVersion = TrackData::TagV2V1;
}
m_trackDataList.clearData();
TaggedFileOfDirectoryIterator it(m_view->getFileList()->currentOrRootIndex());
while (it.hasNext()) {
TaggedFile* taggedFile = it.next();
taggedFile->readTags(false);
m_trackDataList.push_back(ImportTrackData(
*taggedFile, ImportTrackData::TagNone));
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
taggedFile = FileProxyModel::readWithTagLibIfId3V24(taggedFile);
#endif
m_trackDataList.push_back(ImportTrackData(*taggedFile, tagVersion));
}
if (!m_importDialog) {
......
......@@ -473,3 +473,37 @@ QString ImportTrackDataVector::getFrame(Frame::Type type) const
}
return result;
}
/**
* Read the tags from the files.
* This can be used to fill the track data with another tag version.
*
* @param tagVersion tag version to read
*/
void ImportTrackDataVector::readTags(ImportTrackData::TagVersion tagVersion)
{
for (iterator it = begin(); it != end(); ++it) {
TaggedFile* taggedFile = it->getTaggedFile();
if (taggedFile->isChanged()) {
qDebug("changed: %s", qPrintable(taggedFile->getFilename()));
}
switch (tagVersion) {
case ImportTrackData::TagV1:
taggedFile->getAllFramesV1(*it);
break;
case ImportTrackData::TagV2:
taggedFile->getAllFramesV2(*it);
break;
case ImportTrackData::TagV2V1:
{
FrameCollection framesV1;
taggedFile->getAllFramesV1(framesV1);
taggedFile->getAllFramesV2(*it);
it->merge(framesV1);
break;
}
case ImportTrackData::TagNone:
;
}
}
}
......@@ -238,6 +238,14 @@ public:
*/
void setCoverArtUrl(const QString& coverArtUrl) { m_coverArtUrl = coverArtUrl; }
/**
* Read the tags from the files.
* This can be used to fill the track data with another tag version.
*
* @param tagVersion tag version to read
*/
void readTags(ImportTrackData::TagVersion tagVersion);
private:
/**
* Get frame from first track.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment