Commit 133364b8 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

UI: update contact avatar

This patch updates avatars after receiving vCard.

Change-Id: Icef2d0c9bb09090eea182971b952aa4e901e4818
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 23222fe5
......@@ -28,9 +28,16 @@
class Call;
@protocol CallViewControllerDelegate
-(void) conversationInfoUpdatedFor:(const std::string&) conversationID;
@end
@interface CurrentCallVC : NSViewController <NSSplitViewDelegate, CallDelegate> {
}
@property (retain, nonatomic) id <CallViewControllerDelegate> delegate;
-(void) initFrame;
-(void) showWithAnimation:(BOOL)animate;
-(void) hideWithAnimation:(BOOL)animate;
......
......@@ -132,6 +132,7 @@
@property QMetaObject::Connection selectedCallChanged;
@property QMetaObject::Connection messageConnection;
@property QMetaObject::Connection mediaAddedConnection;
@property QMetaObject::Connection profileUpdatedConnection;
@end
......@@ -353,16 +354,14 @@
[backgroundImage setImage: image];
[backgroundImage setHidden:NO];
} else {
// [bluerBackgroundEffect setHidden:YES];
[bluerBackgroundEffect.layer setBackgroundFilters:nil];
[bluerBackgroundEffect setFillColor:[NSColor ringDarkGrey]];
[backgroundImage setHidden:YES];
[backgroundImage setImage:nil];
// [videoView.layer setBackgroundColor:[[NSColor ringDarkGrey] CGColor]];
}
}
-(NSImage *) getContactImageOfSize: (double) size withDefaultAvatar:(BOOL) shouldDrawDefault {
-(NSImage *) getContactImageOfSize: (double) size withDefaultAvatar:(BOOL) shouldDrawDefault {
auto* convModel = accountInfo_->conversationModel.get();
auto convIt = getConversationFromUid(convUid_, *convModel);
if (convIt == convModel->allFilteredConversations().end()) {
......@@ -691,6 +690,33 @@
[self uncollapseRightView];
}
});
//monitor for updated profile
QObject::disconnect(self.profileUpdatedConnection);
self.profileUpdatedConnection =
QObject::connect(accountInfo_->contactModel.get(),
&lrc::api::ContactModel::contactAdded,
[self](const std::string &contactUri) {
auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel.get());
if (convIt == accountInfo_->conversationModel->allFilteredConversations().end()) {
return;
}
if (convIt->participants.empty()) {
return;
}
auto& contact = accountInfo_->contactModel->getContact(convIt->participants[0]);
if (contact.profileInfo.type == lrc::api::profile::Type::RING && contact.profileInfo.uri == contactUri)
accountInfo_->conversationModel->makePermanent(convUid_);
[incomingPersonPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]];
[outgoingPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]];
[self.delegate conversationInfoUpdatedFor:convUid_];
if(accountInfo_->callModel.get()->getCall(callUid_).isAudioOnly) {
[audioCallPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]];
[self setBackground];
return;
}
[personPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]];
});
}
-(void) showWithAnimation:(BOOL)animate
......
......@@ -19,6 +19,7 @@
#import <Cocoa/Cocoa.h>
#import "LrcModelsProtocol.h"
#import "ChooseAccountVC.h"
#import "CurrentCallVC.h"
namespace lrc {
namespace api {
......@@ -28,7 +29,7 @@ namespace lrc {
}
}
@interface RingWindowController : NSWindowController <NSSharingServicePickerDelegate, ChooseAccountDelegate, LrcModelsProtocol> {
@interface RingWindowController : NSWindowController <NSSharingServicePickerDelegate, ChooseAccountDelegate, LrcModelsProtocol, CallViewControllerDelegate> {
IBOutlet NSView *currentView;
}
......
......@@ -178,6 +178,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
self.window.titleVisibility = NSWindowTitleHidden;
currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
currentCallVC.delegate = self;
conversationVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self];
// toolbar items
//chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:self.accountModel delegate:self];
......@@ -527,4 +528,10 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
}
}
#pragma mark - CallViewControllerDelegate
-(void) conversationInfoUpdatedFor:(const std::string&) conversationID {
[smartViewVC reloadConversationWithUid:@(conversationID.c_str())];
}
@end
......@@ -65,4 +65,6 @@ namespace lrc {
*/
-(void) clearConversationModel;
-(void) reloadConversationWithUid:(NSString *)uid;
@end
......@@ -229,6 +229,9 @@ namespace Interfaces {
QPixmap pxm;
const int radius = size.height() / 2;
/*
* we could not now clear cache and image coul be outdated
* so do not use cache now
// Check cache
auto index = QStringLiteral("%1%2%3").arg(size.width())
.arg(size.height())
......@@ -237,6 +240,7 @@ namespace Interfaces {
if (convPixmCache.contains(index)) {
return convPixmCache.value(index);
}
*/
auto contactPhoto = qvariant_cast<QPixmap>(personPhoto(QByteArray::fromStdString(avatar)));
contactPhoto = contactPhoto.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
......@@ -272,7 +276,7 @@ namespace Interfaces {
painter.drawRoundedRect(0,0,pxm.height(),pxm.height(),radius,radius);
// Save in cache
convPixmCache.insert(index, pxm);
//convPixmCache.insert(index, pxm);
return pxm;
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment