Commit 604b39b6 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

special handling of ID3v2 comment frames with non-empty description: display...

special handling of ID3v2 comment frames with non-empty description: display description as frame name, do not replace them by normal comments
parent c4e03570
......@@ -551,10 +551,16 @@ static bool setTextField(ID3_Tag* tag, ID3_FrameID id, const QString& text,
ID3_Frame* frame = NULL;
bool removeOnly = removeEmpty && text.isEmpty();
if (replace || removeOnly) {
frame = tag->Find(id);
frame = tag->RemoveFrame(frame);
delete frame;
changed = true;
if (id != ID3FID_COMMENT) {
frame = tag->Find(id);
} else {
frame = tag->Find(ID3FID_COMMENT, ID3FN_DESCRIPTION, "");
}
if (frame) {
frame = tag->RemoveFrame(frame);
delete frame;
changed = true;
}
}
if (!removeOnly && (replace || tag->Find(id) == NULL)) {
frame = new ID3_Frame(id);
......@@ -1804,7 +1810,8 @@ void Mp3File::getAllFramesV2(FrameCollection& frames)
Frame frame(type, "", name, i++);
frame.setValue(getFieldsFromId3Frame(id3Frame, frame.fieldList()));
if (id3Frame->GetID() == ID3FID_USERTEXT ||
id3Frame->GetID() == ID3FID_WWWUSER) {
id3Frame->GetID() == ID3FID_WWWUSER ||
id3Frame->GetID() == ID3FID_COMMENT) {
const Frame::FieldList& fields = frame.getFieldList();
for (Frame::FieldList::const_iterator it = fields.begin();
it != fields.end();
......@@ -1813,6 +1820,7 @@ void Mp3File::getAllFramesV2(FrameCollection& frames)
QString description = (*it).m_value.toString();
if (!description.isEmpty()) {
frame.setInternalName(QString(name) + '\n' + description);
frame.setType(Frame::FT_Other);
}
break;
}
......
......@@ -942,6 +942,26 @@ static TagLib::String::Type getTextEncodingConfig(bool unicode)
return enc;
}
/**
* Remove the first COMM frame with an empty description.
*
* @param id3v2Tag ID3v2 tag
*/
static void removeCommentFrame(TagLib::ID3v2::Tag* id3v2Tag)
{
const TagLib::ID3v2::FrameList& frameList = id3v2Tag->frameList("COMM");
for (TagLib::ID3v2::FrameList::ConstIterator it = frameList.begin();
it != frameList.end();
++it) {
TagLib::ID3v2::CommentsFrame* id3Frame =
dynamic_cast<TagLib::ID3v2::CommentsFrame*>(*it);
if (id3Frame && id3Frame->description().isEmpty()) {
id3v2Tag->removeFrame(id3Frame, true);
break;
}
}
}
/**
* Write a Unicode field if the tag is ID3v2 and Latin-1 is not sufficient.
*
......@@ -958,9 +978,13 @@ bool setId3v2Unicode(TagLib::Tag* tag, const QString& qstr, const TagLib::String
if (tag && (id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(tag)) != 0) {
// first check if this string needs to be stored as unicode
TagLib::String::Type enc = getTextEncodingConfig(needsUnicode(qstr));
if (enc != TagLib::String::Latin1) {
TagLib::ByteVector id(frameId);
id3v2Tag->removeFrames(id);
TagLib::ByteVector id(frameId);
if (enc != TagLib::String::Latin1 || id == "COMM") {
if (id == "COMM") {
removeCommentFrame(id3v2Tag);
} else {
id3v2Tag->removeFrames(id);
}
if (!tstr.isEmpty()) {
TagLib::ID3v2::Frame* frame;
if (frameId[0] != 'C') {
......@@ -1702,7 +1726,13 @@ static QString getFieldsFromCommFrame(
field.m_id = Frame::Field::ID_Language;
TagLib::ByteVector bvLang = commFrame->language();
field.m_value = QString(QCM_QCString(bvLang.data(), bvLang.size() + 1));
field.m_value = QString(
#if QT_VERSION >= 0x040000
QByteArray(bvLang.data(), bvLang.size())
#else
QCString(bvLang.data(), bvLang.size() + 1)
#endif
);
fields.push_back(field);
field.m_id = Frame::Field::ID_Description;
......@@ -2963,7 +2993,8 @@ void TagLibFile::getAllFramesV2(FrameCollection& frames)
getTypeStringForFrameId((*it)->frameID(), type, name);
Frame frame(type, TStringToQString((*it)->toString()), name, i++);
frame.setValue(getFieldsFromId3Frame(*it, frame.fieldList(), type));
if ((*it)->frameID().mid(1, 3) == "XXX") {
if ((*it)->frameID().mid(1, 3) == "XXX" ||
type == Frame::FT_Comment) {
const Frame::FieldList& fields = frame.getFieldList();
for (Frame::FieldList::const_iterator it = fields.begin();
it != fields.end();
......@@ -2976,6 +3007,7 @@ void TagLibFile::getAllFramesV2(FrameCollection& frames)
description = description.mid(11);
}
frame.setInternalName(QString(name) + '\n' + description);
frame.setType(Frame::FT_Other);
}
break;
}
......
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