]> granicus.if.org Git - taglib/commitdiff
Instead of returning 0 on finding a deprecated frame type, create an
authorScott Wheeler <wheeler@kde.org>
Tue, 17 May 2005 23:57:23 +0000 (23:57 +0000)
committerScott Wheeler <wheeler@kde.org>
Tue, 17 May 2005 23:57:23 +0000 (23:57 +0000)
UnknownFrame and set the flag to discard it on write.

As a special bonus this meant implementing the discard-on-tag-alter
flag.

BUG:100515

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@415248 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

mpeg/id3v2/id3v2frame.cpp
mpeg/id3v2/id3v2frame.h
mpeg/id3v2/id3v2framefactory.cpp
mpeg/id3v2/id3v2tag.cpp

index 0675483cea886bc7c5a95a2d1ebce095aa20c2d4..f58e3500442f59117a19c6244cb769dee27fd7d4 100644 (file)
@@ -417,6 +417,11 @@ bool Frame::Header::tagAlterPreservation() const
   return d->tagAlterPreservation;
 }
 
+void Frame::Header::setTagAlterPreservation(bool preserve)
+{
+  d->tagAlterPreservation = preserve;
+}
+
 bool Frame::Header::fileAlterPreservation() const
 {
   return d->fileAlterPreservation;
index 392bb71aa84818ce5d648e1ecd2b0ead58e35a06..886077158b35cda82ee76d49625dd86829350feb 100644 (file)
@@ -29,6 +29,7 @@ namespace TagLib {
 
   namespace ID3v2 {
 
+    class Tag;
     class FrameFactory;
 
     //! ID3v2 frame implementation
@@ -44,6 +45,7 @@ namespace TagLib {
 
     class Frame
     {
+      friend class Tag;
       friend class FrameFactory;
 
     public:
@@ -295,10 +297,27 @@ namespace TagLib {
       /*!
        * Returns true if the flag for tag alter preservation is set.
        *
-       * \note This flag is currently ignored internally in TagLib.
+       * The semantics are a little backwards from what would seem natural
+       * (setting the preservation flag to throw away the frame), but this
+       * follows the ID3v2 standard.
+       *
+       * \see setTagAlterPreservation()
        */
       bool tagAlterPreservation() const;
 
+      /*!
+       * Sets the flag for preservation of this frame if the tag is set.  If
+       * this is set to true the frame will not be written when the tag is
+       * saved.
+       *
+       * The semantics are a little backwards from what would seem natural
+       * (setting the preservation flag to throw away the frame), but this
+       * follows the ID3v2 standard.
+       *
+       * \see tagAlterPreservation()
+       */
+      void setTagAlterPreservation(bool discard);
+
       /*!
        * Returns true if the flag for file alter preservation is set.
        *
index 1d695d08752d698a2ca1170d9b8edf18396aa0e9..1755b4d3c7f23ce4b61022f1d9987dcd3d1233b3 100644 (file)
@@ -99,8 +99,8 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const
   }
 
   if(!updateFrame(header)) {
-    delete header;
-    return 0;
+    header->setTagAlterPreservation(true);
+    return new UnknownFrame(data, header);
   }
 
   // updateFrame() might have updated the frame ID.
index 3daa1515d96651cbecd29574adf815b5e4e85be6..1032489fe87b38a4e3ce0558fdedeac3f8119768 100644 (file)
@@ -343,8 +343,10 @@ ByteVector ID3v2::Tag::render() const
 
   // Loop through the frames rendering them and adding them to the tagData.
 
-  for(FrameList::Iterator it = d->frameList.begin(); it != d->frameList.end(); it++)
-    tagData.append((*it)->render());
+  for(FrameList::Iterator it = d->frameList.begin(); it != d->frameList.end(); it++) {
+    if(!(*it)->header()->tagAlterPreservation())
+      tagData.append((*it)->render());
+  }
 
   // Compute the amount of padding, and append that to tagData.