Commit 065aaf26 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

Selected Account: update image

Update image for selected account when profile photo is changed

Change-Id: Ia6a2d477309c9dbd20bb091a45652195994bbd33
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 067dec6d
......@@ -54,6 +54,7 @@ Boolean menuNeedsUpdate;
NSMenu* accountsMenu;
NSMenuItem* selectedMenuItem;
QMetaObject::Connection accountUpdate;
QMetaObject::Connection personUpdate;
AccountSelectionManager* accountManager;
- (void)awakeFromNib
......@@ -63,10 +64,23 @@ AccountSelectionManager* accountManager;
profileImage.layer.masksToBounds = YES;
accountManager = [[AccountSelectionManager alloc] init];
if (auto pro = ProfileModel::instance().selectedProfile()) {
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(pro->person(), {140,140});
if (ProfileModel::instance().selectedProfile() && ProfileModel::instance().selectedProfile()->person()) {
Person* person = ProfileModel::instance().selectedProfile()->person();
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(person, {140,140});
[profileImage setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
QObject::disconnect(personUpdate);
personUpdate = QObject::connect(person,
&Person::changed,
[=] {
//give time to cach to be updated and then change image
dispatch_time_t updateTime = dispatch_time(DISPATCH_TIME_NOW, 1);
dispatch_after(updateTime, dispatch_get_main_queue(), ^(void){
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(person, {140,140});
[profileImage setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
});
});
}
accountsMenu = [[NSMenu alloc] initWithTitle:@""];
[accountsMenu setDelegate:self];
accountSelectionButton.menu = accountsMenu;
......
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