Switch the return type of File::save() from void to bool to provide a little
authorScott Wheeler <wheeler@kde.org>
Wed, 23 Jun 2004 18:35:52 +0000 (18:35 +0000)
committerScott Wheeler <wheeler@kde.org>
Wed, 23 Jun 2004 18:35:52 +0000 (18:35 +0000)
bit of feedback on whether or not the safe operation worked.

CCMAIL:83882@bugs.kde.org

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

mpeg/mpegfile.cpp
mpeg/mpegfile.h
ogg/oggfile.cpp
ogg/oggfile.h
ogg/vorbis/vorbisfile.cpp
ogg/vorbis/vorbisfile.h
toolkit/tfile.h

index 196e85521b63cadd828814ce5092d1c1c8a70ac4..4ec621026efe7fb71202c5377cde1da4331c72b6 100644 (file)
@@ -245,29 +245,27 @@ MPEG::Properties *MPEG::File::audioProperties() const
   return d->properties;
 }
 
-void MPEG::File::save()
+bool MPEG::File::save()
 {
-  save(ID3v1 | ID3v2);
+  return save(ID3v1 | ID3v2);
 }
 
-void MPEG::File::save(int tags)
+bool MPEG::File::save(int tags)
 {
-  if(tags == NoTags) {
-    strip(AllTags);
-    return;
-  }
+  if(tags == NoTags)
+    return strip(AllTags);
 
   if(!d->ID3v2Tag && !d->ID3v1Tag) {
 
     if(d->hasID3v1 || d->hasID3v2)
-      strip(AllTags);
+      return strip(AllTags);
 
-    return;
+    return true;
   }
 
   if(readOnly()) {
     debug("MPEG::File::save() -- File is read only.");
-    return;
+    return false;
   }
 
   // Create the tags if we've been asked to.  Copy the values from the tag that
@@ -279,6 +277,7 @@ void MPEG::File::save(int tags)
   if(tags & ID3v1 && d->ID3v2Tag)
     Tag::duplicate(d->ID3v2Tag, ID3v1Tag(true), false);
 
+  bool success = true;
 
   if(ID3v2 & tags) {
 
@@ -290,10 +289,10 @@ void MPEG::File::save(int tags)
       insert(d->ID3v2Tag->render(), d->ID3v2Location, d->ID3v2OriginalSize);
     }
     else
-      strip(ID3v2);
+      success = strip(ID3v2) && success;
   }
   else if(d->hasID3v2)
-    strip(ID3v2);
+    success = strip(ID3v2) && success;
 
   if(ID3v1 & tags) {
     if(d->ID3v1Tag && !d->ID3v1Tag->isEmpty()) {
@@ -302,10 +301,12 @@ void MPEG::File::save(int tags)
       writeBlock(d->ID3v1Tag->render());
     }
     else
-      strip(ID3v1);
+      success = strip(ID3v1) && success;
   }
   else if(d->hasID3v1)
-    strip(ID3v1);
+    success = strip(ID3v1) && success;
+
+  return success;
 }
 
 ID3v2::Tag *MPEG::File::ID3v2Tag(bool create)
@@ -330,11 +331,11 @@ ID3v1::Tag *MPEG::File::ID3v1Tag(bool create)
   return d->ID3v1Tag;
 }
 
-void MPEG::File::strip(int tags)
+bool MPEG::File::strip(int tags)
 {
   if(readOnly()) {
     debug("MPEG::File::strip() - Cannot strip tags from a read only file.");
-    return;
+    return false;
   }
 
   if(tags & ID3v2 && d->hasID3v2)
@@ -345,6 +346,8 @@ void MPEG::File::strip(int tags)
     d->ID3v1Location = -1;
     d->hasID3v1 = false;
   }
+
+  return true;
 }
 
 void MPEG::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory)
index c70ca272b169ce8a5848f844dfcec4347dfb8180..4b53ada201bee112b771769dbe49fd39fdb010e8 100644 (file)
@@ -114,7 +114,8 @@ namespace TagLib {
 
       /*!
        * Save the file.  If at least one tag -- ID3v1 or ID3v2 -- exists this
-       * will duplicate its content into the other tag.
+       * will duplicate its content into the other tag.  This returns true
+       * if saving was successful.
        *
        * If neither exists or if both tags are empty, this will strip the tags
        * from the file.
@@ -126,18 +127,18 @@ namespace TagLib {
        *
        * \see save(int tags)
        */
-      virtual void save();
+      virtual bool save();
 
       /*!
        * 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.
+       * uses AllTags.  This returns true if saving was successful.
        *
        * 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.
        */
-      void save(int tags);
+      bool save(int tags);
 
       /*!
        * Returns a pointer to the ID3v2 tag of the file.
@@ -169,7 +170,7 @@ namespace TagLib {
        * This will strip the tags that match the OR-ed together TagTypes from the
        * file.  By default it strips all tags.
        */
-      void strip(int tags = AllTags);
+      bool strip(int tags = AllTags);
 
       /*!
        * Set the ID3v2::FrameFactory to something other than the default.
index 07340479fe35c0784e9f94002e149fd131678390..357a30edd5ef8107bccbb7c14ebd639690dc7b2a 100644 (file)
@@ -176,8 +176,13 @@ const Ogg::PageHeader *Ogg::File::lastPageHeader()
   return d->lastPageHeader->isValid() ? d->lastPageHeader : 0;
 }
 
-void Ogg::File::save()
+bool Ogg::File::save()
 {
+  if(readOnly()) {
+    debug("Ogg::File::save() - Cannot save to a read only file.");
+    return false;
+  }
+
   List<int> pageGroup;
 
   for(List<int>::ConstIterator it = d->dirtyPages.begin(); it != d->dirtyPages.end(); ++it) {
@@ -191,6 +196,8 @@ void Ogg::File::save()
   writePageGroup(pageGroup);
   d->dirtyPages.clear();
   d->dirtyPackets.clear();
+
+  return true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 29a0f6502d615df74abf02059407d3c944de97b8..0ca59dd995612abf0d175fde2986c120fb4874fd 100644 (file)
@@ -73,7 +73,7 @@ namespace TagLib {
        */
       const PageHeader *lastPageHeader();
 
-      virtual void save();
+      virtual bool save();
 
     protected:
       /*!
index 1b6b41fc33e8a835b73d3d86c3da73dfae38b19b..a6e8b94c960bd3924f78da46bef4bb33e8a4d930 100644 (file)
@@ -79,7 +79,7 @@ Vorbis::Properties *Vorbis::File::audioProperties() const
   return d->properties;
 }
 
-void Vorbis::File::save()
+bool Vorbis::File::save()
 {
   ByteVector v(vorbisCommentHeaderID);
 
@@ -89,7 +89,7 @@ void Vorbis::File::save()
 
   setPacket(1, v);
 
-  Ogg::File::save();
+  return Ogg::File::save();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index cc1e9f9cffedd6a967a6a25a66dfd0f9f3190540..f85e4bee691456369017dbac8bde5fc74beb51cd 100644 (file)
@@ -83,7 +83,7 @@ namespace TagLib {
        */
       virtual Properties *audioProperties() const;
 
-      virtual void save();
+      virtual bool save();
 
     private:
       File(const File &);
index 0c48e56527b4c02f193b4ea8d1a148b3e56cfbb5..bde30d2000a9269eda0b3c41e906cc99036504bf 100644 (file)
@@ -79,9 +79,9 @@ namespace TagLib {
 
     /*!
      * Save the file and its associated tags.  This should be reimplemented in
-     * the concrete subclasses.
+     * the concrete subclasses.  Returns true if the save succeeds.
      */
-    virtual void save() = 0;
+    virtual bool save() = 0;
 
     /*!
      * Reads a block of size \a length at the current get pointer.