From 14b8aa772fc33a1ab4ab0b0aee4d03d63ee31fdd Mon Sep 17 00:00:00 2001 From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Wed, 11 Nov 2020 10:40:15 -0500 Subject: [PATCH] profile: save account avatar in PNG Change-Id: I4b83d669e337af60052040cf9f275c8fbf2e35f6 --- src/AccRingGeneralVC.mm | 10 +++++++--- src/AccSipGeneralVC.mm | 8 ++++++-- src/AddSIPAccountVC.mm | 8 ++++++-- src/RingWizardNewAccountVC.mm | 8 ++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/AccRingGeneralVC.mm b/src/AccRingGeneralVC.mm index 0616a2f7..93a4eec8 100644 --- a/src/AccRingGeneralVC.mm +++ b/src/AccRingGeneralVC.mm @@ -253,7 +253,7 @@ typedef NS_ENUM(NSInteger, TagViews) { returnCode:(NSInteger) code contextInfo:(void*) contextInfo { - //do nothing when editing canceled + //do nothing when editing canceled if (code == 0) { return; } @@ -264,8 +264,12 @@ typedef NS_ENUM(NSInteger, TagViews) { [photoView setImage: [outputImage roundCorners: outputImage.size.height * 0.5]]; [photoView setBordered:NO]; [addProfilePhotoImage setHidden:YES]; - auto imageToBytes = QByteArray::fromNSData([outputImage TIFFRepresentation]).toBase64(); - self.accountModel->setAvatar(self.selectedAccountID, QString(imageToBytes)); + NSData* imageData = [outputImage TIFFRepresentation]; + NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData]; + NSDictionary *properties = [[NSDictionary alloc] init]; + imageData = [imageRep representationUsingType:NSPNGFileType properties: properties]; + NSString * dataString = [imageData base64EncodedStringWithOptions:0]; + self.accountModel->setAvatar(self.selectedAccountID, QString::fromNSString(dataString)); } else if(!photoView.image) { [photoView setBordered:YES]; [addProfilePhotoImage setHidden:NO]; diff --git a/src/AccSipGeneralVC.mm b/src/AccSipGeneralVC.mm index 697db387..7bdff361 100644 --- a/src/AccSipGeneralVC.mm +++ b/src/AccSipGeneralVC.mm @@ -98,8 +98,12 @@ typedef NS_ENUM(NSInteger, TagViews) { outputImage = [outputImage imageResizeInsideMax: newSize]; [photoView setImage: [outputImage roundCorners: outputImage.size.height * 0.5]]; [addProfilePhotoImage setHidden:YES]; - auto imageToBytes = QByteArray::fromNSData([outputImage TIFFRepresentation]).toBase64(); - self.accountModel->setAvatar(self.selectedAccountID, QString(imageToBytes)); + NSData* imageData = [outputImage TIFFRepresentation]; + NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData]; + NSDictionary *properties = [[NSDictionary alloc] init]; + imageData = [imageRep representationUsingType:NSPNGFileType properties: properties]; + NSString * dataString = [imageData base64EncodedStringWithOptions:0]; + self.accountModel->setAvatar(self.selectedAccountID, QString::fromNSString(dataString)); } else if(!photoView.image) { [photoView setBordered:YES]; [addProfilePhotoImage setHidden:NO]; diff --git a/src/AddSIPAccountVC.mm b/src/AddSIPAccountVC.mm index 58679693..6e07386c 100644 --- a/src/AddSIPAccountVC.mm +++ b/src/AddSIPAccountVC.mm @@ -85,8 +85,12 @@ NSTimer* timeoutTimer; [self] (const QString& accountID) { if([photoView image]) { NSImage *avatarImage = [photoView image]; - auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64(); - self.accountModel->setAvatar(accountID, QString(imageToBytes)); + NSData* imageData = [avatarImage TIFFRepresentation]; + NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData]; + NSDictionary *properties = [[NSDictionary alloc] init]; + imageData = [imageRep representationUsingType:NSPNGFileType properties: properties]; + NSString * dataString = [imageData base64EncodedStringWithOptions:0]; + self.accountModel->setAvatar(accountID, QString::fromNSString(dataString)); } lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(accountID); if(![serverField.stringValue isEqualToString:@""]) { diff --git a/src/RingWizardNewAccountVC.mm b/src/RingWizardNewAccountVC.mm index d1cd0e21..79f4708b 100644 --- a/src/RingWizardNewAccountVC.mm +++ b/src/RingWizardNewAccountVC.mm @@ -269,8 +269,12 @@ BOOL isRendevous = false; //set account avatar if([photoView image]) { NSImage *avatarImage = [photoView image]; - auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64(); - self.accountModel->setAvatar(accountID, QString(imageToBytes)); + NSData* imageData = [avatarImage TIFFRepresentation]; + NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData]; + NSDictionary *properties = [[NSDictionary alloc] init]; + imageData = [imageRep representationUsingType:NSPNGFileType properties: properties]; + NSString * dataString = [imageData base64EncodedStringWithOptions:0]; + self.accountModel->setAvatar(accountID, QString::fromNSString(dataString)); } //register username if (self.registeredName && ![self.registeredName isEqualToString:@""]) { -- GitLab