Permalink
Browse files

Check for pictures with state { Added, Removed} in HasUnsavedChanges()

  • Loading branch information...
1 parent 116e092 commit aed2ec31a99f30a4f5aeade5d680af54570cd171 @sbooth committed Mar 3, 2012
Showing with 15 additions and 1 deletion.
  1. +15 −1 Metadata/AudioMetadata.cpp
View
@@ -539,6 +539,10 @@ bool AudioMetadata::HasUnsavedChanges() const
return true;
for(auto picture : mPictures) {
+ // TODO: Remove this check once std::shared_ptr is used (because no pictures with this state should be present in mPictures)
+ if(AttachedPicture::ChangeState::Added & picture->mState && AttachedPicture::ChangeState::Removed & picture->mState)
+ continue;
+
if(AttachedPicture::ChangeState::Added & picture->mState || AttachedPicture::ChangeState::Removed & picture->mState || picture->HasUnsavedChanges())
return true;
}
@@ -931,11 +935,21 @@ void AudioMetadata::AttachPicture(AttachedPicture *picture)
void AudioMetadata::RemoveAttachedPicture(AttachedPicture *picture)
{
if(picture) {
- // lambda support isn't in the Xcode 4.3 version of clang
// auto match = std::find_if(mPictures.begin(), mPictures.end(), [] (AttachedPicture *p) -> bool { p == picture; });
auto match = std::find_if(mPictures.begin(), mPictures.end(), PointerIdentityComparator<AttachedPicture>(picture));
if(match != mPictures.end())
(*match)->mState |= AttachedPicture::ChangeState::Removed;
+
+#if 0
+ // TODO: It would be more correct to remove picture from mPictures if the state is Added
+ // but that necessitates std::shared_ptr since picture can't be immediately deleted (in use by the caller)
+ if(match != mPictures.end()) {
+ if((*match)->mState & AttachedPicture::ChangeState::Added)
+ mPictures.erase(match);
+ else
+ (*match)->mState |= AttachedPicture::ChangeState::Removed;
+ }
+#endif
}
}

0 comments on commit aed2ec3

Please sign in to comment.