From c5ad9251b18a7d143308944dfb50a6e4dbdbd6a7 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 4 May 2017 15:41:25 +0200 Subject: [PATCH] fix(src/components/contact/VcardModel): `removeBelcardPhoto` handle all linphone desktop photos --- .../src/components/contact/VcardModel.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/linphone-desktop/src/components/contact/VcardModel.cpp b/linphone-desktop/src/components/contact/VcardModel.cpp index d6eedbdec..4028a9fb8 100644 --- a/linphone-desktop/src/components/contact/VcardModel.cpp +++ b/linphone-desktop/src/components/contact/VcardModel.cpp @@ -58,14 +58,13 @@ inline shared_ptr findBelCardValue (const list > &list, const Q return nullptr; } +inline bool isLinphoneDesktopPhoto (const shared_ptr &photo) { + return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME); +} + inline shared_ptr findBelcardPhoto (const shared_ptr &belcard) { const list > &photos = belcard->getPhotos(); - auto it = find_if( - photos.cbegin(), photos.cend(), [](const shared_ptr &photo) { - return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME); - } - ); - + auto it = find_if(photos.cbegin(), photos.cend(), isLinphoneDesktopPhoto); if (it != photos.cend()) return *it; @@ -73,17 +72,22 @@ inline shared_ptr findBelcardPhoto (const shared_ptr &belcard) { - shared_ptr oldPhoto = findBelcardPhoto(belcard); - if (oldPhoto) { + list > photos; + for (const auto photo : belcard->getPhotos()) { + if (isLinphoneDesktopPhoto(photo)) + photos.push_back(photo); + } + + for (const auto photo : photos) { QString imagePath( ::Utils::linphoneStringToQString( - Paths::getAvatarsDirPath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1) + Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(VCARD_SCHEME) - 1) ) ); if (!QFile::remove(imagePath)) qWarning() << QStringLiteral("Unable to remove `%1`.").arg(imagePath); - belcard->removePhoto(oldPhoto); + belcard->removePhoto(photo); } }