]> granicus.if.org Git - taglib/commitdiff
Continuing going through my pile-o-patches:
authorScott Wheeler <wheeler@kde.org>
Thu, 21 Jul 2005 17:33:36 +0000 (17:33 +0000)
committerScott Wheeler <wheeler@kde.org>
Thu, 21 Jul 2005 17:33:36 +0000 (17:33 +0000)
Make it possible to save files using the save() with a tag mask
without stripping the tags that do not fit the mask.  I still need
to do a little testing on this to make sure that the offsets are
still computed correctly.

BUG:96460

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

mpeg/mpegfile.cpp
mpeg/mpegfile.h

index 56c1b4870ac04165d0368b2898fb59c3453279b5..cf126ce8b724f76b1d56a741ff7b686fd826cae7 100644 (file)
@@ -263,12 +263,17 @@ bool MPEG::File::save()
 
 bool MPEG::File::save(int tags)
 {
-  if(tags == NoTags)
+  return save(tags, true);
+}
+
+bool MPEG::File::save(int tags, bool stripOthers)
+{
+  if(tags == NoTags && stripOthers)
     return strip(AllTags);
 
   if(!d->ID3v2Tag && !d->ID3v1Tag && !d->APETag) {
 
-    if(d->hasID3v1 || d->hasID3v2 || d->hasAPE)
+    if((d->hasID3v1 || d->hasID3v2 || d->hasAPE) && stripOthers)
       return strip(AllTags);
 
     return true;
@@ -299,10 +304,10 @@ bool MPEG::File::save(int tags)
 
       insert(d->ID3v2Tag->render(), d->ID3v2Location, d->ID3v2OriginalSize);
     }
-    else
+    else if(stripOthers)
       success = strip(ID3v2, false) && success;
   }
-  else if(d->hasID3v2)
+  else if(d->hasID3v2 && stripOthers)
     success = strip(ID3v2) && success;
 
   if(ID3v1 & tags) {
@@ -311,13 +316,14 @@ bool MPEG::File::save(int tags)
       seek(offset, End);
       writeBlock(d->ID3v1Tag->render());
     }
-    else
+    else if(stripOthers)
       success = strip(ID3v1) && success;
   }
-  else if(d->hasID3v1)
+  else if(d->hasID3v1 && stripOthers)
     success = strip(ID3v1, false) && success;
 
   // Dont save an APE-tag unless one has been created
+
   if((APE & tags) && d->APETag) {
     if(d->hasAPE)
       insert(d->APETag->render(), d->APELocation, d->APEOriginalSize);
@@ -338,7 +344,7 @@ bool MPEG::File::save(int tags)
       }
     }
   }
-  else if(d->hasAPE)
+  else if(d->hasAPE && stripOthers)
     success = strip(APE, false) && success;
 
   return success;
index 431523e08746036d70885032535b16bd3d4ed641..dca5ae12c7e0ac5e4715bc7a5cb56f4561eb1ec2 100644 (file)
@@ -144,6 +144,18 @@ namespace TagLib {
        */
       bool save(int tags);
 
+      /*!
+       * Save the file.  This will attempt to save all of the tag types that are
+       * specified by OR-ing together TagTypes values.  The save() method above
+       * uses AllTags.  This returns true if saving was successful.
+       *
+       * If \a stripOthers is true this strips all tags not included in the mask,
+       * but does not modify them in memory, so later calls to save() which make
+       * use of these tags will remain valid.  This also strips empty tags.
+       */
+      // BIC: combine with the above method
+      bool save(int tags, bool stripOthers);
+
       /*!
        * Returns a pointer to the ID3v2 tag of the file.
        *