]> granicus.if.org Git - taglib/commitdiff
Make it possible to strip tags without deleting them (again). This is
authorScott Wheeler <wheeler@kde.org>
Mon, 26 Jul 2004 02:22:05 +0000 (02:22 +0000)
committerScott Wheeler <wheeler@kde.org>
Mon, 26 Jul 2004 02:22:05 +0000 (02:22 +0000)
used by MPEG::File::save() so that tags that aren't explicitly saves still
exist in memory.

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

mpeg/mpegfile.cpp
mpeg/mpegfile.h

index 3c89ce3888e033c389d5c62f6f60ba1ab334d6ed..3ecc16254be0f2f724ca20b85c9de4a5fd8d73c5 100644 (file)
@@ -289,7 +289,7 @@ bool MPEG::File::save(int tags)
       insert(d->ID3v2Tag->render(), d->ID3v2Location, d->ID3v2OriginalSize);
     }
     else
-      success = strip(ID3v2) && success;
+      success = strip(ID3v2, false) && success;
   }
   else if(d->hasID3v2)
     success = strip(ID3v2) && success;
@@ -304,7 +304,7 @@ bool MPEG::File::save(int tags)
       success = strip(ID3v1) && success;
   }
   else if(d->hasID3v1)
-    success = strip(ID3v1) && success;
+    success = strip(ID3v1, false) && success;
 
   return success;
 }
@@ -332,6 +332,11 @@ ID3v1::Tag *MPEG::File::ID3v1Tag(bool create)
 }
 
 bool MPEG::File::strip(int tags)
+{
+  return strip(tags, true);
+}
+
+bool MPEG::File::strip(int tags, bool freeMemory)
 {
   if(readOnly()) {
     debug("MPEG::File::strip() - Cannot strip tags from a read only file.");
@@ -343,8 +348,10 @@ bool MPEG::File::strip(int tags)
     d->ID3v2Location = -1;
     d->ID3v2OriginalSize = 0;
     d->hasID3v2 = false;
-    delete d->ID3v2Tag;
-    d->ID3v2Tag = 0;
+    if(freeMemory) {
+      delete d->ID3v2Tag;
+      d->ID3v2Tag = 0;
+    }
 
     // v1 tag location has changed, update if it exists
     if(d->ID3v1Tag)
@@ -355,8 +362,10 @@ bool MPEG::File::strip(int tags)
     truncate(d->ID3v1Location);
     d->ID3v1Location = -1;
     d->hasID3v1 = false;
-    delete d->ID3v1Tag;
-    d->ID3v1Tag = 0;
+    if(freeMemory) {
+      delete d->ID3v1Tag;
+      d->ID3v1Tag = 0;
+    }
   }
 
   return true;
index a410cf84c2a127a9974585fd3ff1618dadfcb3aa..334b58d1dd1b09da671bce99de7be94f16482b34 100644 (file)
@@ -171,11 +171,24 @@ namespace TagLib {
        * file.  By default it strips all tags.  It returns true if the tags are
        * successfully stripped.
        *
+       * This is equivalent to strip(tags, true)
+       *
        * \note This will also invalidate pointers to the ID3v2 and ID3v1 tags
        * as their memory will be freed.
        */
       bool strip(int tags = AllTags);
 
+      /*!
+       * This will strip the tags that match the OR-ed together TagTypes from the
+       * file.  By default it strips all tags.  It returns true if the tags are
+       * successfully stripped.
+       *
+       * If \a freeMemory is true the ID3v1 and ID3v2 tags will be deleted and
+       * pointers to them will be invalidated.
+       */
+      // BIC: merge with the method above
+      bool strip(int tags, bool freeMemory);
+
       /*!
        * Set the ID3v2::FrameFactory to something other than the default.
        *