From cfec2c95475aec87dc9b6ff7314a6bf663d4c286 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Tue, 9 Jun 2015 15:06:29 -0400 Subject: [PATCH] contacts: fix photo rendering There were two issues here: - photos were not stored inline in vcards (I saw it though but it is no longer the case). We need to access the field imageData to retrieve it. - defaultUserPhoto was not displaying properly the fallback image Refs #75128 Change-Id: Ia3cd297d160e78c850068cc3add91458c27930d9 --- src/backends/AddressBookBackend.mm | 10 +++++++++- src/delegates/ImageManipulationDelegate.mm | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backends/AddressBookBackend.mm b/src/backends/AddressBookBackend.mm index 34f3ec73..f98e7736 100644 --- a/src/backends/AddressBookBackend.mm +++ b/src/backends/AddressBookBackend.mm @@ -38,6 +38,7 @@ #import <QtWidgets/QApplication> #import <QtCore/QStandardPaths> #import <QTimer> +#import <QPixmap> #import <QtGlobal> //Ring @@ -202,14 +203,21 @@ void AddressBookBackend::asyncLoad(int startingPoint) for (int i = startingPoint; i < endPoint; ++i) { - Person* person = new Person(QByteArray::fromNSData(((ABPerson*)[everyone objectAtIndex:i]).vCardRepresentation), + ABPerson* abPerson = ((ABPerson*)[everyone objectAtIndex:i]); + + Person* person = new Person(QByteArray::fromNSData(abPerson.vCardRepresentation), Person::Encoding::vCard, this); + + if(abPerson.imageData) + person->setPhoto(QVariant(QPixmap::fromImage(QImage::fromData(QByteArray::fromNSData((abPerson.imageData)))))); + if([person->formattedName().toNSString() isEqualToString:@""] && [person->secondName().toNSString() isEqualToString:@""] && [person->firstName().toNSString() isEqualToString:@""]) { continue; } + person->setCollection(this); editor<Person>()->addExisting(person); diff --git a/src/delegates/ImageManipulationDelegate.mm b/src/delegates/ImageManipulationDelegate.mm index 8c5cd0c2..fb0b91eb 100644 --- a/src/delegates/ImageManipulationDelegate.mm +++ b/src/delegates/ImageManipulationDelegate.mm @@ -137,9 +137,10 @@ QPixmap ImageManipulationDelegate::drawDefaultUserPixmap(const QSize& size, bool CGImageRef ImageManipulationDelegate::resizeCGImage(CGImageRef image, const QSize& size) { // create context, keeping original image properties CGColorSpaceRef colorspace = CGImageGetColorSpace(image); + CGContextRef context = CGBitmapContextCreate(NULL, size.width(), size.height(), CGImageGetBitsPerComponent(image), - CGImageGetBytesPerRow(image), + size.width() * CGImageGetBitsPerComponent(image), colorspace, CGImageGetAlphaInfo(image)); CGColorSpaceRelease(colorspace); -- GitLab