Switch the return type of File::save() from void to bool to provide a little

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
This commit is contained in:
Scott Wheeler 2004-06-23 18:35:52 +00:00
parent 5f2e59150c
commit 420541441c
7 changed files with 39 additions and 28 deletions

View 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)

View 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.

View 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;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -73,7 +73,7 @@ namespace TagLib {
*/
const PageHeader *lastPageHeader();
virtual void save();
virtual bool save();
protected:
/*!

View 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();
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -83,7 +83,7 @@ namespace TagLib {
*/
virtual Properties *audioProperties() const;
virtual void save();
virtual bool save();
private:
File(const File &);

View 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.