Commit a656fba9 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

use enhanced ImportTrackData instead of StandardTags in FileFilter, so that all frames can be used

parent a612d886
......@@ -33,15 +33,8 @@
* Constructor.
*/
FileFilter::FileFilter() :
m_parser(QStringList() << "equals" << "contains" << "matches"),
m_longCodes(QStringList() << "file" << "filepath" << "extension" <<
"tag1" << "tag2")
m_parser(QStringList() << "equals" << "contains" << "matches")
{
m_shortCodes[0] = 'f';
m_shortCodes[1] = 'p';
m_shortCodes[2] = 'e';
m_shortCodes[3] = 'O';
m_shortCodes[4] = 'o';
}
/**
......@@ -73,23 +66,18 @@ QString FileFilter::formatString(const QString& format)
if (format.QCM_indexOf('%') == -1) {
return format;
}
QString str = m_standardTags12.formatString(format);
if (str.QCM_indexOf('%') == -1) {
return str;
}
str.replace(QString("%2"), QString("%"));
str = m_standardTags2.formatString(str);
if (str.QCM_indexOf('%') == -1) {
return str;
}
str.replace(QString("%1"), QString("%"));
str = m_standardTags1.formatString(str);
if (str.QCM_indexOf('%') == -1) {
return str;
QString str(format);
str.replace(QString("%1"), QString("\v1"));
str.replace(QString("%2"), QString("\v2"));
str = m_trackData12.formatString(str);
if (str.QCM_indexOf('\v') != -1) {
str.replace(QString("\v2"), QString("%"));
str = m_trackData2.formatString(str);
if (str.QCM_indexOf('\v') != -1) {
str.replace(QString("\v1"), QString("%"));
str = m_trackData1.formatString(str);
}
}
str = StandardTags::replacePercentCodes(str, m_shortCodes, m_longCodes,
m_replaceStr, s_numCodes);
return str;
}
......@@ -105,27 +93,7 @@ QString FileFilter::getFormatToolTip(bool onlyRows)
{
QString str;
if (!onlyRows) str += "<table>\n";
str += StandardTags::getFormatToolTip(true);
str += "<tr><td>%f</td><td>%{file}</td><td>";
str += QCM_translate("Filename");
str += "</td></tr>\n";
str += "<tr><td>%p</td><td>%{filepath}</td><td>";
str += QCM_translate(I18N_NOOP("Absolute path to file"));
str += "</td></tr>\n";
str += "<tr><td>%e</td><td>%{extension}</td><td>";
str += QCM_translate(I18N_NOOP("Extension"));
str += "</td></tr>\n";
str += "<tr><td>%O</td><td>%{tag1}</td><td>";
str += QCM_translate("Tag 1");
str += "</td></tr>\n";
str += "<tr><td>%o</td><td>%{tag2}</td><td>";
str += QCM_translate("Tag 2");
str += "</td></tr>\n";
str += TrackDataFormatReplacer::getToolTip(true);
str += "<tr><td>%1a...</td><td>%1{artist}...</td><td>";
str += QCM_translate("Tag 1");
......@@ -208,16 +176,17 @@ bool FileFilter::filter(TaggedFile& taggedFile, bool* ok)
if (ok) *ok = true;
return true;
}
taggedFile.getStandardTagsV1(&m_standardTags1);
taggedFile.getStandardTagsV2(&m_standardTags2);
m_standardTags12 = m_standardTags2;
m_standardTags12.merge(m_standardTags1);
m_replaceStr[0] = taggedFile.getFilename();
m_replaceStr[1] = taggedFile.getAbsFilename();
m_replaceStr[2] = taggedFile.getFileExtension();
m_replaceStr[3] = taggedFile.getTagFormatV1();
m_replaceStr[4] = taggedFile.getTagFormatV2();
m_trackData1.clear();
m_trackData1.setAbsFilename(taggedFile.getAbsFilename());
m_trackData1.setFileDuration(taggedFile.getDuration());
m_trackData1.setFileExtension(taggedFile.getFileExtension());
m_trackData1.setTagFormatV1(taggedFile.getTagFormatV1());
m_trackData1.setTagFormatV2(taggedFile.getTagFormatV2());
m_trackData2 = m_trackData1;
taggedFile.getAllFramesV1(m_trackData1);
taggedFile.getAllFramesV2(m_trackData2);
m_trackData12 = m_trackData2;
m_trackData12.merge(m_trackData1);
bool result = parse();
if (m_parser.hasError()) {
......
......@@ -28,7 +28,7 @@
#define FILEFILTER_H
#include "expressionparser.h"
#include "standardtags.h"
#include "importtrackdata.h"
#include <qobject.h>
#include <qstring.h>
......@@ -104,14 +104,9 @@ private:
QString m_filterExpression;
ExpressionParser m_parser;
StandardTags m_standardTags1;
StandardTags m_standardTags2;
StandardTags m_standardTags12;
static const int s_numCodes = 5;
const QStringList m_longCodes;
QChar m_shortCodes[s_numCodes];
QString m_replaceStr[s_numCodes];
ImportTrackData m_trackData1;
ImportTrackData m_trackData2;
ImportTrackData m_trackData12;
};
#endif
......@@ -79,7 +79,10 @@ QString TrackDataFormatReplacer::getReplacement(const QString& code) const
{ 'u', "url" },
{ 'd', "duration" },
{ 'D', "seconds" },
{ 'n', "tracks" }
{ 'n', "tracks" },
{ 'e', "extension" },
{ 'O', "tag1" },
{ 'o', "tag2" }
};
#if QT_VERSION >= 0x040000
const char c = code[0].toLatin1();
......@@ -124,6 +127,12 @@ QString TrackDataFormatReplacer::getReplacement(const QString& code) const
result = QString::number(m_trackData.getFileDuration());
} else if (name == "tracks") {
result = QString::number(m_numTracks);
} else if (name == "extension") {
result = m_trackData.getFileExtension();
} else if (name == "tag1") {
result = m_trackData.getTagFormatV1();
} else if (name == "tag2") {
result = m_trackData.getTagFormatV2();
}
}
}
......@@ -169,6 +178,18 @@ QString TrackDataFormatReplacer::getToolTip(bool onlyRows)
str += QCM_translate(I18N_NOOP("Number of tracks"));
str += "</td></tr>\n";
str += "<tr><td>%e</td><td>%{extension}</td><td>";
str += QCM_translate(I18N_NOOP("Extension"));
str += "</td></tr>\n";
str += "<tr><td>%O</td><td>%{tag1}</td><td>";
str += QCM_translate("Tag 1");
str += "</td></tr>\n";
str += "<tr><td>%o</td><td>%{tag2}</td><td>";
str += QCM_translate("Tag 2");
str += "</td></tr>\n";
if (!onlyRows) str += "</table>\n";
return str;
}
......@@ -204,3 +225,18 @@ QString ImportTrackData::getFormatToolTip(bool onlyRows)
{
return TrackDataFormatReplacer::getToolTip(onlyRows);
}
/**
* Get file extension including the dot.
*
* @return file extension, e.g. ".mp3".
*/
QString ImportTrackData::getFileExtension() const
{
if (!m_fileExtension.isEmpty()) {
return m_fileExtension;
} else {
int dotPos = m_absFilename.QCM_lastIndexOf(".");
return dotPos != -1 ? m_absFilename.mid(dotPos) : QString();
}
}
......@@ -88,12 +88,67 @@ public:
*/
QString getAbsFilename() const { return m_absFilename; }
/**
* Set absolute filename.
*
* @param absFilename absolute file path
*/
void setAbsFilename(const QString& absFilename) {
m_absFilename = absFilename;
}
/**
* Get file extension including the dot.
*
* @return file extension, e.g. ".mp3".
*/
QString getFileExtension() const;
/**
* Set file extension.
* @param fileExtension file extension
*/
void setFileExtension(const QString& fileExtension) {
m_fileExtension = fileExtension;
}
/**
* Get the format of tag 1.
*
* @return string describing format of tag 1,
* e.g. "ID3v1.1", "ID3v2.3", "Vorbis", "APE",
* QString::null if unknown.
*/
QString getTagFormatV1() const { return m_tagFormatV1; }
/**
* Set the format of tag 1.
* @param tagFormatV1 string describing format of tag 1
*/
void setTagFormatV1(const QString& tagFormatV1) { m_tagFormatV1 = tagFormatV1; }
/**
* Get the format of tag 2.
*
* @return string describing format of tag 2,
* e.g. "ID3v2.3", "Vorbis", "APE",
* QString::null if unknown.
*/
QString getTagFormatV2() const { return m_tagFormatV2; }
/**
* Set the format of tag 2.
* @param tagFormatV2 string describing format of tag 2
*/
void setTagFormatV2(const QString& tagFormatV2) { m_tagFormatV2 = tagFormatV2; }
/**
* Format a string from track data.
* Supported format fields:
* Those supported by TrackDataFormatReplacer::getReplacement()
*
* @param format format specification
* @param format format specification
* @param numTracks number of tracks in album
*
* @return formatted string.
*/
......@@ -129,6 +184,9 @@ private:
int m_fileDuration;
int m_importDuration;
QString m_absFilename;
QString m_fileExtension;
QString m_tagFormatV1;
QString m_tagFormatV2;
};
/**
......
......@@ -1963,6 +1963,9 @@ void Kid3App::setExportData(int src)
#endif
ImportTrackData trackData(taggedFile->getAbsFilename(),
taggedFile->getDuration());
trackData.setFileExtension(taggedFile->getFileExtension());
trackData.setTagFormatV1(taggedFile->getTagFormatV1());
trackData.setTagFormatV2(taggedFile->getTagFormatV2());
if (src == ExportDialog::SrcV1) {
taggedFile->getAllFramesV1(trackData);
} else {
......
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