Commit 6d3bf716 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

Pass TrackDataModel instead of ImportTrackDataVector to importers.

So the import model can be controlled by the importers and table edits
(like checkboxes to select tracks) can be used by the importers.
parent 38b58265
......@@ -27,6 +27,7 @@
#include "amazonimporter.h"
#include <QRegExp>
#include <QDomDocument>
#include "trackdatamodel.h"
#include "kid3.h"
......@@ -34,12 +35,12 @@
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
AmazonImporter::AmazonImporter(
QObject* parent,
ImportTrackDataVector& trackDataVector)
: ServerImporter(parent, trackDataVector)
TrackDataModel* trackDataModel)
: ServerImporter(parent, trackDataModel)
{
setObjectName("AmazonImporter");
}
......@@ -116,7 +117,7 @@ void AmazonImporter::parseFindResults(const QByteArray& searchStr)
}
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......@@ -255,6 +256,7 @@ void AmazonImporter::parseAlbumResults(const QByteArray& albumStr)
}
}
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
if (getCoverArt()) {
// <input type="hidden" id="ASIN" name="ASIN" value="B0025AY48W" />
start = str.indexOf("id=\"ASIN\"");
......@@ -263,7 +265,7 @@ void AmazonImporter::parseAlbumResults(const QByteArray& albumStr)
if (start > 0) {
end = str.indexOf("\"", start + 7);
if (end > start) {
m_trackDataVector.setCoverArtUrl(
trackDataVector.setCoverArtUrl(
QString("http://www.amazon.com/dp/") +
str.mid(start + 7, end - start - 7));
}
......@@ -286,8 +288,8 @@ void AmazonImporter::parseAlbumResults(const QByteArray& albumStr)
QRegExp durationRe("(\\d+):(\\d+)");
QRegExp nrTitleRe("\\s*\\d+\\.\\s+(.*\\S)");
FrameCollection frames(framesHdr);
ImportTrackDataVector::iterator it = m_trackDataVector.begin();
bool atTrackDataListEnd = (it == m_trackDataVector.end());
ImportTrackDataVector::iterator it = trackDataVector.begin();
bool atTrackDataListEnd = (it == trackDataVector.end());
int trackNr = 1;
while (start >= 0) {
QString title;
......@@ -378,12 +380,12 @@ void AmazonImporter::parseAlbumResults(const QByteArray& albumStr)
ImportTrackData trackData;
trackData.setFrameCollection(frames);
trackData.setImportDuration(duration);
m_trackDataVector.push_back(trackData);
trackDataVector.push_back(trackData);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(duration);
++it;
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
++trackNr;
frames = framesHdr;
......@@ -394,22 +396,23 @@ void AmazonImporter::parseAlbumResults(const QByteArray& albumStr)
frames.clear();
while (!atTrackDataListEnd) {
if ((*it).getFileDuration() == 0) {
it = m_trackDataVector.erase(it);
it = trackDataVector.erase(it);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(0);
++it;
}
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
} else if (!framesHdr.empty()) {
// if there are no track data, fill frame header data
for (ImportTrackDataVector::iterator it = m_trackDataVector.begin();
it != m_trackDataVector.end();
for (ImportTrackDataVector::iterator it = trackDataVector.begin();
it != trackDataVector.end();
++it) {
(*it).setFrameCollection(framesHdr);
}
}
m_trackDataModel->setTrackData(trackDataVector);
}
/**
......
......@@ -39,10 +39,10 @@ public:
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
AmazonImporter(QObject* parent,
ImportTrackDataVector& trackDataVector);
TrackDataModel* trackDataModel);
/**
* Destructor.
......@@ -78,7 +78,7 @@ public:
virtual void parseFindResults(const QByteArray& searchStr);
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......
......@@ -26,6 +26,7 @@
#include "discogsimporter.h"
#include "serverimporterconfig.h"
#include "trackdatamodel.h"
#include "kid3.h"
#include "genres.h"
......@@ -35,11 +36,11 @@ static const char discogsServer[] = "www.discogs.com:80";
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
DiscogsImporter::DiscogsImporter(QObject* parent,
ImportTrackDataVector& trackDataVector) :
ServerImporter(parent, trackDataVector)
TrackDataModel* trackDataModel) :
ServerImporter(parent, trackDataModel)
{
setObjectName("DiscogsImporter");
}
......@@ -247,7 +248,7 @@ static bool parseCredits(const QString& str, FrameCollection& frames)
}
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......@@ -396,7 +397,8 @@ void DiscogsImporter::parseAlbumResults(const QByteArray& albumStr)
}
}
m_trackDataVector.setCoverArtUrl(QString::null);
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
trackDataVector.setCoverArtUrl(QString::null);
if (getCoverArt()) {
/*
* cover art can be found in image source
......@@ -406,7 +408,7 @@ void DiscogsImporter::parseAlbumResults(const QByteArray& albumStr)
start += 10; // skip <img src="
end = str.indexOf("\"", start);
if (end > start) {
m_trackDataVector.setCoverArtUrl(str.mid(start, end - start));
trackDataVector.setCoverArtUrl(str.mid(start, end - start));
}
}
}
......@@ -446,8 +448,8 @@ void DiscogsImporter::parseAlbumResults(const QByteArray& albumStr)
QRegExp durationRe("<td [^>]*class=\"track_duration\"[^>]*>(?:<span>)?(\\d+):(\\d+)</");
QRegExp indexRe("<td class=\"track_index\">([^<]+)$");
QRegExp rowEndRe("</td>[\\s\\r\\n]*</tr>");
ImportTrackDataVector::iterator it = m_trackDataVector.begin();
bool atTrackDataListEnd = (it == m_trackDataVector.end());
ImportTrackDataVector::iterator it = trackDataVector.begin();
bool atTrackDataListEnd = (it == trackDataVector.end());
int trackNr = 1;
start = 0;
while ((end = rowEndRe.indexIn(str, start)) > start) {
......@@ -507,12 +509,12 @@ void DiscogsImporter::parseAlbumResults(const QByteArray& albumStr)
ImportTrackData trackData;
trackData.setFrameCollection(frames);
trackData.setImportDuration(duration);
m_trackDataVector.push_back(trackData);
trackDataVector.push_back(trackData);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(duration);
++it;
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
++trackNr;
}
......@@ -523,16 +525,17 @@ void DiscogsImporter::parseAlbumResults(const QByteArray& albumStr)
frames.clear();
while (!atTrackDataListEnd) {
if ((*it).getFileDuration() == 0) {
it = m_trackDataVector.erase(it);
it = trackDataVector.erase(it);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(0);
++it;
}
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
}
}
m_trackDataModel->setTrackData(trackDataVector);
}
/**
......
......@@ -39,10 +39,10 @@ public:
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
DiscogsImporter(QObject* parent,
ImportTrackDataVector& trackDataVector);
TrackDataModel* trackDataModel);
/**
* Destructor.
......@@ -72,7 +72,7 @@ public:
virtual void parseFindResults(const QByteArray& searchStr);
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......
......@@ -33,6 +33,7 @@
#include <QHeaderView>
#include "fileproxymodel.h"
#include "modeliterator.h"
#include "taggedfile.h"
#include "kid3.h"
#include "externalprocess.h"
#include "qtcompatmac.h"
......
......@@ -114,7 +114,6 @@ QVariant FrameTableModel::data(const QModelIndex& index, int role) const
return it->getValue();
} else if (role == Qt::CheckStateRole && index.column() == CI_Enable) {
return m_frameSelected.at(index.row()) ? Qt::Checked : Qt::Unchecked;
return false;
} else if (role == Qt::BackgroundColorRole) {
if (index.column() == CI_Enable) {
return Kid3App::s_miscCfg.m_markChanges &&
......
......@@ -26,6 +26,7 @@
#include "freedbimporter.h"
#include "serverimporterconfig.h"
#include "trackdatamodel.h"
#include "kid3.h"
#include "genres.h"
......@@ -35,11 +36,11 @@ static const char gnudbServer[] = "www.gnudb.org:80";
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
FreedbImporter::FreedbImporter(QObject* parent,
ImportTrackDataVector& trackDataVector) :
ServerImporter(parent, trackDataVector)
TrackDataModel* trackDataModel) :
ServerImporter(parent, trackDataModel)
{
setObjectName("FreedbImporter");
}
......@@ -219,7 +220,7 @@ static void parseFreedbAlbumData(const QString& text,
}
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......@@ -231,10 +232,11 @@ void FreedbImporter::parseAlbumResults(const QByteArray& albumStr)
parseFreedbTrackDurations(text, trackDuration);
parseFreedbAlbumData(text, framesHdr);
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
FrameCollection frames(framesHdr);
ImportTrackDataVector::iterator it = m_trackDataVector.begin();
ImportTrackDataVector::iterator it = trackDataVector.begin();
QList<int>::const_iterator tdit = trackDuration.begin();
bool atTrackDataListEnd = (it == m_trackDataVector.end());
bool atTrackDataListEnd = (it == trackDataVector.end());
int pos = 0;
int idx, oldpos = pos;
int tracknr = 0;
......@@ -257,12 +259,12 @@ void FreedbImporter::parseAlbumResults(const QByteArray& albumStr)
ImportTrackData trackData;
trackData.setFrameCollection(frames);
trackData.setImportDuration(duration);
m_trackDataVector.push_back(trackData);
trackDataVector.push_back(trackData);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(duration);
++it;
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
frames = framesHdr;
oldpos = pos;
......@@ -271,14 +273,15 @@ void FreedbImporter::parseAlbumResults(const QByteArray& albumStr)
frames.clear();
while (!atTrackDataListEnd) {
if ((*it).getFileDuration() == 0) {
it = m_trackDataVector.erase(it);
it = trackDataVector.erase(it);
} else {
(*it).setFrameCollection(frames);
(*it).setImportDuration(0);
++it;
}
atTrackDataListEnd = (it == m_trackDataVector.end());
atTrackDataListEnd = (it == trackDataVector.end());
}
m_trackDataModel->setTrackData(trackDataVector);
}
/**
......
......@@ -39,10 +39,10 @@ public:
* Constructor.
*
* @param parent parent object
* @param trackDataVector track data to be filled with imported values
* @param trackDataModel track data to be filled with imported values
*/
FreedbImporter(QObject* parent,
ImportTrackDataVector& trackDataVector);
TrackDataModel* trackDataModel);
/**
* Destructor.
......@@ -78,7 +78,7 @@ public:
virtual void parseFindResults(const QByteArray& searchStr);
/**
* Parse result of album request and populate m_trackDataVector with results.
* Parse result of album request and populate m_trackDataModel with results.
*
* @param albumStr album data received
*/
......
......@@ -75,14 +75,14 @@
*
* @param parent parent widget
* @param caption dialog title
* @param trackDataList track data to be filled with imported values,
* @param trackDataModel track data to be filled with imported values,
* is passed with durations of files set
*/
ImportDialog::ImportDialog(QWidget* parent, QString& caption,
ImportTrackDataVector& trackDataList) :
TrackDataModel* trackDataModel) :
QDialog(parent), m_trackDataImported(false),
m_autoStartSubDialog(ASD_None),
m_trackDataVector(trackDataList)
m_trackDataModel(trackDataModel)
{
setObjectName("ImportDialog");
setModal(true);
......@@ -104,7 +104,6 @@ ImportDialog::ImportDialog(QWidget* parent, QString& caption,
vlayout->setSpacing(6);
vlayout->setMargin(6);
m_trackDataModel = new TrackDataModel(this);
m_trackDataTable = new QTableView(this);
m_trackDataTable->setModel(m_trackDataModel);
m_trackDataTable->resizeColumnsToContents();
......@@ -216,7 +215,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(onOkButtonClicked()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
vlayout->addLayout(hlayout);
}
......@@ -274,7 +273,7 @@ void ImportDialog::fromServer()
void ImportDialog::fromText()
{
if (!m_textImportDialog) {
m_textImportDialog = new TextImportDialog(this, m_trackDataVector);
m_textImportDialog = new TextImportDialog(this, m_trackDataModel);
connect(m_textImportDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreviewAfterImport()));
}
......@@ -288,7 +287,7 @@ void ImportDialog::fromText()
void ImportDialog::fromTags()
{
if (!m_tagImportDialog) {
m_tagImportDialog = new TagImportDialog(this, m_trackDataVector);
m_tagImportDialog = new TagImportDialog(this, m_trackDataModel);
connect(m_tagImportDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreview()));
}
......@@ -310,8 +309,9 @@ void ImportDialog::displayServerImportDialog(ServerImporter* source)
}
if (m_serverImportDialog) {
m_serverImportDialog->setImportSource(source);
m_serverImportDialog->setArtistAlbum(m_trackDataVector.getArtist(),
m_trackDataVector.getAlbum());
m_serverImportDialog->setArtistAlbum(
m_trackDataModel->trackData().getArtist(),
m_trackDataModel->trackData().getAlbum());
m_serverImportDialog->show();
}
}
......@@ -335,7 +335,7 @@ void ImportDialog::hideSubdialogs()
void ImportDialog::fromFreedb()
{
if (!m_freedbImporter) {
m_freedbImporter = new FreedbImporter(this, m_trackDataVector);
m_freedbImporter = new FreedbImporter(this, m_trackDataModel);
}
displayServerImportDialog(m_freedbImporter);
}
......@@ -346,7 +346,7 @@ void ImportDialog::fromFreedb()
void ImportDialog::fromTrackType()
{
if (!m_trackTypeImporter) {
m_trackTypeImporter = new TrackTypeImporter(this, m_trackDataVector);
m_trackTypeImporter = new TrackTypeImporter(this, m_trackDataModel);
}
displayServerImportDialog(m_trackTypeImporter);
}
......@@ -358,7 +358,7 @@ void ImportDialog::fromMusicBrainzRelease()
{
if (!m_musicBrainzReleaseImporter) {
m_musicBrainzReleaseImporter =
new MusicBrainzReleaseImporter(this, m_trackDataVector);
new MusicBrainzReleaseImporter(this, m_trackDataModel);
}
displayServerImportDialog(m_musicBrainzReleaseImporter);
}
......@@ -369,7 +369,7 @@ void ImportDialog::fromMusicBrainzRelease()
void ImportDialog::fromDiscogs()
{
if (!m_discogsImporter) {
m_discogsImporter = new DiscogsImporter(this, m_trackDataVector);
m_discogsImporter = new DiscogsImporter(this, m_trackDataModel);
}
displayServerImportDialog(m_discogsImporter);
}
......@@ -380,7 +380,7 @@ void ImportDialog::fromDiscogs()
void ImportDialog::fromAmazon()
{
if (!m_amazonImporter) {
m_amazonImporter = new AmazonImporter(this, m_trackDataVector);
m_amazonImporter = new AmazonImporter(this, m_trackDataModel);
}
displayServerImportDialog(m_amazonImporter);
}
......@@ -392,7 +392,7 @@ void ImportDialog::fromMusicBrainz()
{
#ifdef HAVE_TUNEPIMP
if (!m_musicBrainzDialog) {
m_musicBrainzDialog = new MusicBrainzDialog(this, m_trackDataVector);
m_musicBrainzDialog = new MusicBrainzDialog(this, m_trackDataModel);
connect(m_musicBrainzDialog, SIGNAL(trackDataUpdated()),
this, SLOT(showPreviewAfterImport()));
}
......@@ -481,7 +481,6 @@ void ImportDialog::setAutoStartSubDialog(AutoStartSubDialog asd)
void ImportDialog::clear()
{
m_trackDataImported = false;
m_trackDataModel->setTrackData(ImportTrackDataVector());
m_serverComboBox->setCurrentIndex(Kid3App::s_genCfg.m_importServer);
m_destComboBox->setCurrentIndex(Kid3App::s_genCfg.m_importDest);
......@@ -508,7 +507,6 @@ void ImportDialog::showPreview()
int maxDiff;
getTimeDifferenceCheck(diffCheckEnable, maxDiff);
m_trackDataModel->setTimeDifferenceCheck(diffCheckEnable, maxDiff);
m_trackDataModel->setTrackData(m_trackDataVector);
m_trackDataTable->scrollToTop();
m_trackDataTable->resizeColumnsToContents();
m_trackDataTable->resizeRowsToContents();
......@@ -607,30 +605,22 @@ void ImportDialog::moveTableRow(int, int fromIndex, int toIndex) {
vHeader->moveSection(toIndex, fromIndex);
connect(vHeader, SIGNAL(sectionMoved(int, int, int)), this, SLOT(moveTableRow(int, int, int)));
}
int numTracks = static_cast<int>(m_trackDataVector.size());
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
int numTracks = static_cast<int>(trackDataVector.size());
if (fromIndex < numTracks && toIndex < numTracks) {
// swap elements but keep file durations and names
ImportTrackData fromData(m_trackDataVector[fromIndex]);
ImportTrackData toData(m_trackDataVector[toIndex]);
m_trackDataVector[fromIndex].setFrameCollection(toData.getFrameCollection());
m_trackDataVector[toIndex].setFrameCollection(fromData.getFrameCollection());
m_trackDataVector[fromIndex].setImportDuration(toData.getImportDuration());
m_trackDataVector[toIndex].setImportDuration(fromData.getImportDuration());
ImportTrackData fromData(trackDataVector[fromIndex]);
ImportTrackData toData(trackDataVector[toIndex]);
trackDataVector[fromIndex].setFrameCollection(toData.getFrameCollection());
trackDataVector[toIndex].setFrameCollection(fromData.getFrameCollection());
trackDataVector[fromIndex].setImportDuration(toData.getImportDuration());
trackDataVector[toIndex].setImportDuration(fromData.getImportDuration());
m_trackDataModel->setTrackData(trackDataVector);
// redisplay the table
showPreview();
}
}
/**
* 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.
*/
......@@ -652,7 +642,9 @@ void ImportDialog::changeTagDestination()
tagVersion = TrackData::TagV2V1;
}
m_trackDataVector.readTags(tagVersion);
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
trackDataVector.readTags(tagVersion);
m_trackDataModel->setTrackData(trackDataVector);
showPreview();
}
}
......@@ -665,7 +657,7 @@ void ImportDialog::matchWithLength()
bool diffCheckEnable;
int maxDiff;
getTimeDifferenceCheck(diffCheckEnable, maxDiff);
if (TrackDataMatcher::matchWithLength(m_trackDataVector, diffCheckEnable, maxDiff))
if (TrackDataMatcher::matchWithLength(m_trackDataModel, diffCheckEnable, maxDiff))
showPreview();
}
......@@ -674,7 +666,7 @@ void ImportDialog::matchWithLength()
*/
void ImportDialog::matchWithTrack()
{
if (TrackDataMatcher::matchWithTrack(m_trackDataVector))
if (TrackDataMatcher::matchWithTrack(m_trackDataModel))
showPreview();
}
......@@ -683,6 +675,6 @@ void ImportDialog::matchWithTrack()
*/
void ImportDialog::matchWithTitle()
{
if (TrackDataMatcher::matchWithTitle(m_trackDataVector))
if (TrackDataMatcher::matchWithTitle(m_trackDataModel))
showPreview();
}
......@@ -29,7 +29,6 @@
#include <QDialog>
#include "config.h"
#include "trackdata.h"
#include "importconfig.h"
class QString;
......@@ -82,11 +81,11 @@ public:
*
* @param parent parent widget
* @param caption dialog title
* @param trackDataList track data to be filled with imported values,
* @param trackDataModel track data to be filled with imported values,
* is passed with durations of files set
*/
ImportDialog(QWidget* parent, QString& caption,
ImportTrackDataVector& trackDataList);
TrackDataModel* trackDataModel);
/**
* Destructor.
*/
......@@ -231,11 +230,6 @@ private slots:
*/
void changeTagDestination();
/**
* Called when OK is clicked.
*/
void onOkButtonClicked();
private:
/**
* Get time difference check configuration.
......@@ -284,8 +278,6 @@ private:
TextImportDialog* m_textImportDialog;
/** Tag import dialog */
TagImportDialog* m_tagImportDialog;
/** track data */
ImportTrackDataVector& m_trackDataVector;
};
#endif
......@@ -95,6 +95,7 @@
#include "fileproxymodel.h"
#include "dirproxymodel.h"
#include "modeliterator.h"
#include "trackdatamodel.h"
#include "dirlist.h"
#include "pictureframe.h"
#ifdef HAVE_ID3LIB
......@@ -145,6 +146,7 @@ Kid3App::Kid3App() :
m_fileSystemModel(new QFileSystemModel(this)),
m_fileProxyModel(new FileProxyModel(this)),
m_dirProxyModel(new DirProxyModel(this)),
m_trackDataModel(new TrackDataModel(this)),
m_downloadToAllFilesInDir(false),
m_importDialog(0), m_browseCoverArtDialog(0),
m_exportDialog(0), m_renDirDialog(0),
......@@ -1698,7 +1700,7 @@ void Kid3App::setupImportDialog()
tagVersion = TrackData::TagV2V1;