Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 18 | */ |
| 19 | #import "CurrentCallVC.h" |
| 20 | |
| 21 | #import <QuartzCore/QuartzCore.h> |
| 22 | |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 23 | ///Qt |
| 24 | #import <QMimeData> |
| 25 | #import <QtMacExtras/qmacfunctions.h> |
| 26 | #import <QtCore/qabstractitemmodel.h> |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 27 | #import <QPixmap> |
| 28 | |
| 29 | ///LRC |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 30 | #import <video/previewmanager.h> |
| 31 | #import <video/renderer.h> |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 32 | #import <api/newcallmodel.h> |
| 33 | #import <api/call.h> |
| 34 | #import <api/conversationmodel.h> |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 35 | #import <globalinstances.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 36 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 37 | #import "AppDelegate.h" |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame] | 38 | #import "views/ITProgressIndicator.h" |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 39 | #import "views/CallView.h" |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 40 | #import "views/NSColor+RingTheme.h" |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 41 | #import "delegates/ImageManipulationDelegate.h" |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 42 | #import "ChatVC.h" |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 43 | #import "views/IconButton.h" |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 44 | #import "views/CallLayer.h" |
Anthony Léonard | 6f81975 | 2018-01-05 09:53:40 -0500 | [diff] [blame] | 45 | #import "utils.h" |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 46 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 47 | @interface RendererConnectionsHolder : NSObject |
| 48 | |
| 49 | @property QMetaObject::Connection frameUpdated; |
| 50 | @property QMetaObject::Connection started; |
| 51 | @property QMetaObject::Connection stopped; |
| 52 | |
| 53 | @end |
| 54 | |
| 55 | @implementation RendererConnectionsHolder |
| 56 | |
| 57 | @end |
| 58 | |
Kateryna Kostiuk | 1ba5a01 | 2018-12-12 17:07:38 -0500 | [diff] [blame^] | 59 | @interface CurrentCallVC () <NSPopoverDelegate> { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 60 | std::string convUid_; |
| 61 | std::string callUid_; |
| 62 | const lrc::api::account::Info *accountInfo_; |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 63 | NSTimer* refreshDurationTimer; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 64 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 65 | |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 66 | // Main container |
| 67 | @property (unsafe_unretained) IBOutlet NSSplitView* splitView; |
Kateryna Kostiuk | 89398b6 | 2018-11-20 16:45:04 -0500 | [diff] [blame] | 68 | @property (unsafe_unretained) IBOutlet NSView* backgroundImage; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 69 | @property (unsafe_unretained) IBOutlet NSBox* bluerBackgroundEffect; |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 70 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 71 | // Header info |
| 72 | @property (unsafe_unretained) IBOutlet NSView* headerContainer; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 73 | @property (unsafe_unretained) IBOutlet NSTextField* personLabel; |
| 74 | @property (unsafe_unretained) IBOutlet NSTextField* stateLabel; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 75 | @property (unsafe_unretained) IBOutlet NSTextField* timeSpentLabel; |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 76 | @property (unsafe_unretained) IBOutlet NSImageView* personPhoto; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 77 | |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 78 | @property (unsafe_unretained) IBOutlet NSImageView* outgoingPhoto; |
| 79 | @property (unsafe_unretained) IBOutlet NSTextField* outgoingPersonLabel; |
| 80 | @property (unsafe_unretained) IBOutlet NSTextField* outgoingStateLabel; |
| 81 | @property (unsafe_unretained) IBOutlet NSTextField* outgoingId; |
| 82 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 83 | // Call Controls |
| 84 | @property (unsafe_unretained) IBOutlet NSView* controlsPanel; |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 85 | |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 86 | @property (unsafe_unretained) IBOutlet IconButton* holdOnOffButton; |
| 87 | @property (unsafe_unretained) IBOutlet IconButton* hangUpButton; |
| 88 | @property (unsafe_unretained) IBOutlet IconButton* recordOnOffButton; |
| 89 | @property (unsafe_unretained) IBOutlet IconButton* pickUpButton; |
| 90 | @property (unsafe_unretained) IBOutlet IconButton* muteAudioButton; |
| 91 | @property (unsafe_unretained) IBOutlet IconButton* muteVideoButton; |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 92 | @property (unsafe_unretained) IBOutlet IconButton* transferButton; |
| 93 | @property (unsafe_unretained) IBOutlet IconButton* addParticipantButton; |
| 94 | @property (unsafe_unretained) IBOutlet IconButton* chatButton; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 95 | @property (unsafe_unretained) IBOutlet IconButton* qualityButton; |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 96 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 97 | @property (unsafe_unretained) IBOutlet NSView* advancedPanel; |
| 98 | @property (unsafe_unretained) IBOutlet IconButton* advancedButton; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 99 | @property (assign) IBOutlet NSLayoutConstraint* callRecordButtonMarginLeft; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 100 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 101 | @property (strong) NSPopover* addToContactPopover; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 102 | @property (strong) NSPopover* brokerPopoverVC; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 103 | @property (strong) IBOutlet ChatVC* chatVC; |
Alexandre Lision | f23ec5a | 2015-07-16 11:24:06 -0400 | [diff] [blame] | 104 | |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 105 | // Ringing call panel |
| 106 | @property (unsafe_unretained) IBOutlet NSView* ringingPanel; |
| 107 | @property (unsafe_unretained) IBOutlet NSImageView* incomingPersonPhoto; |
| 108 | @property (unsafe_unretained) IBOutlet NSTextField* incomingDisplayName; |
| 109 | |
| 110 | // Outgoing call panel |
| 111 | @property (unsafe_unretained) IBOutlet NSView* outgoingPanel; |
| 112 | @property (unsafe_unretained) IBOutlet ITProgressIndicator *loadingIndicator; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 113 | |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 114 | // audio only view |
| 115 | @property (unsafe_unretained) IBOutlet NSView* audioCallView; |
| 116 | @property (unsafe_unretained) IBOutlet NSImageView* audioCallPhoto; |
| 117 | @property (unsafe_unretained) IBOutlet NSTextField* audioCallTime; |
| 118 | @property (unsafe_unretained) IBOutlet NSTextField* audioCallPersonLabel; |
| 119 | @property (unsafe_unretained) IBOutlet NSTextField* audioCallPersonId; |
| 120 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 121 | // Video |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 122 | @property (unsafe_unretained) IBOutlet CallView *videoView; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 123 | @property (unsafe_unretained) IBOutlet NSView *previewView; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 124 | |
| 125 | @property RendererConnectionsHolder* previewHolder; |
| 126 | @property RendererConnectionsHolder* videoHolder; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 127 | @property QMetaObject::Connection videoStarted; |
Alexandre Lision | 4d9905e | 2016-01-22 12:01:36 -0500 | [diff] [blame] | 128 | @property QMetaObject::Connection selectedCallChanged; |
Alexandre Lision | b65c027 | 2015-07-22 15:51:29 -0400 | [diff] [blame] | 129 | @property QMetaObject::Connection messageConnection; |
| 130 | @property QMetaObject::Connection mediaAddedConnection; |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 131 | @property QMetaObject::Connection profileUpdatedConnection; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 132 | |
| 133 | @end |
| 134 | |
| 135 | @implementation CurrentCallVC |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 136 | @synthesize personLabel, personPhoto, stateLabel, holdOnOffButton, hangUpButton, |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 137 | recordOnOffButton, pickUpButton, chatButton, transferButton, addParticipantButton, timeSpentLabel, |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 138 | muteVideoButton, muteAudioButton, controlsPanel, advancedPanel, advancedButton, headerContainer, videoView, |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 139 | incomingDisplayName, incomingPersonPhoto, previewView, splitView, loadingIndicator, ringingPanel, |
| 140 | outgoingPanel, outgoingPersonLabel, outgoingStateLabel, outgoingPhoto, outgoingId, |
| 141 | callRecordButtonMarginLeft, audioCallView, audioCallPhoto, audioCallTime, audioCallPersonLabel, audioCallPersonId, backgroundImage, bluerBackgroundEffect; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 142 | |
| 143 | @synthesize previewHolder; |
| 144 | @synthesize videoHolder; |
| 145 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 146 | -(void) setCurrentCall:(const std::string&)callUid |
| 147 | conversation:(const std::string&)convUid |
| 148 | account:(const lrc::api::account::Info*)account; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 149 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 150 | if(account == nil) |
| 151 | return; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 152 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 153 | auto* callModel = account->callModel.get(); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 154 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 155 | if (not callModel->hasCall(callUid)){ |
| 156 | callUid_.clear(); |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 157 | return; |
| 158 | } |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 159 | callUid_ = callUid; |
| 160 | convUid_ = convUid; |
| 161 | accountInfo_ = account; |
Anthony Léonard | 4b0935f | 2017-12-26 12:05:22 -0500 | [diff] [blame] | 162 | [self.chatVC setConversationUid:convUid model:account->conversationModel.get()]; |
Kateryna Kostiuk | 54d7697 | 2018-06-07 15:45:07 -0400 | [diff] [blame] | 163 | auto currentCall = callModel->getCall(callUid_); |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 164 | [muteVideoButton setHidden: currentCall.isAudioOnly ? YES: NO]; |
| 165 | callRecordButtonMarginLeft.constant = currentCall.isAudioOnly ? -40.0f: 10.0f; |
| 166 | [previewView setHidden: YES]; |
Kateryna Kostiuk | d76f620 | 2018-09-11 17:15:28 -0400 | [diff] [blame] | 167 | videoView.callId = callUid; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 170 | - (void) ensureLayoutForCallStatus:(lrc::api::call::Status) status { |
| 171 | using Status = lrc::api::call::Status; |
| 172 | switch (status) { |
| 173 | case Status::IN_PROGRESS: |
| 174 | if (![videoView.layer isKindOfClass:[CallLayer class]]) { |
| 175 | [videoView setLayer:[[CallLayer alloc] init]]; |
| 176 | } |
| 177 | break; |
| 178 | default: |
| 179 | if ([videoView.layer isKindOfClass:[CallLayer class]]) { |
| 180 | [videoView setLayer:[CALayer layer]]; |
| 181 | [videoView.layer setBackgroundColor:[[NSColor blackColor] CGColor]]; |
| 182 | } |
| 183 | break; |
| 184 | } |
| 185 | holdOnOffButton.image = status == lrc::api::call::Status::PAUSED ? |
| 186 | [NSImage imageNamed:@"ic_action_holdoff.png"] : [NSImage imageNamed:@"ic_action_hold.png"]; |
| 187 | } |
| 188 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 189 | - (void)awakeFromNib |
| 190 | { |
| 191 | NSLog(@"INIT CurrentCall VC"); |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 192 | [self.view setWantsLayer:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 193 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 194 | [previewView setWantsLayer:YES]; |
Alexandre Lision | 22d615b | 2016-01-25 12:54:34 -0500 | [diff] [blame] | 195 | [previewView.layer setBackgroundColor:[NSColor blackColor].CGColor]; |
| 196 | [previewView.layer setContentsGravity:kCAGravityResizeAspectFill]; |
| 197 | [previewView.layer setFrame:previewView.frame]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 198 | |
| 199 | [controlsPanel setWantsLayer:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 200 | [controlsPanel.layer setBackgroundColor:[NSColor clearColor].CGColor]; |
| 201 | [controlsPanel.layer setFrame:controlsPanel.frame]; |
| 202 | |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 203 | previewHolder = [[RendererConnectionsHolder alloc] init]; |
| 204 | videoHolder = [[RendererConnectionsHolder alloc] init]; |
| 205 | |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame] | 206 | [loadingIndicator setColor:[NSColor whiteColor]]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 207 | [loadingIndicator setNumberOfLines:200]; |
| 208 | [loadingIndicator setWidthOfLine:4]; |
| 209 | [loadingIndicator setLengthOfLine:4]; |
| 210 | [loadingIndicator setInnerMargin:59]; |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame] | 211 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 212 | [self.videoView setCallDelegate:self]; |
Kateryna Kostiuk | 1004caa | 2018-03-29 13:48:07 -0400 | [diff] [blame] | 213 | CGColor* color = [[[NSColor blackColor] colorWithAlphaComponent:0.2] CGColor]; |
| 214 | [headerContainer.layer setBackgroundColor:color]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 215 | [bluerBackgroundEffect setWantsLayer:YES]; |
| 216 | bluerBackgroundEffect.alphaValue = 0.6; |
| 217 | [audioCallView setWantsLayer:YES]; |
| 218 | [audioCallView.layer setBackgroundColor: [[NSColor clearColor] CGColor]]; |
Kateryna Kostiuk | 89398b6 | 2018-11-20 16:45:04 -0500 | [diff] [blame] | 219 | [backgroundImage setWantsLayer: YES]; |
| 220 | backgroundImage.layer.contentsGravity = kCAGravityResizeAspectFill; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 223 | -(void) updateDurationLabel |
| 224 | { |
| 225 | if (accountInfo_ != nil) { |
| 226 | auto* callModel = accountInfo_->callModel.get(); |
| 227 | if (callModel->hasCall(callUid_)) { |
| 228 | auto& callStatus = callModel->getCall(callUid_).status; |
| 229 | if (callStatus != lrc::api::call::Status::ENDED && |
| 230 | callStatus != lrc::api::call::Status::TERMINATING && |
| 231 | callStatus != lrc::api::call::Status::INVALID) { |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 232 | if(callModel->getCall(callUid_).isAudioOnly) { |
| 233 | [audioCallTime setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())]; |
| 234 | } else { |
| 235 | [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())]; |
| 236 | } |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 237 | return; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // If call is not running anymore or accountInfo_ is not set for any reason |
| 243 | // we stop the refresh loop |
| 244 | [refreshDurationTimer invalidate]; |
| 245 | refreshDurationTimer = nil; |
| 246 | [timeSpentLabel setHidden:YES]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 247 | [audioCallView setHidden:YES]; |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 248 | } |
| 249 | |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 250 | -(void) updateCall |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 251 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 252 | if (accountInfo_ == nil) |
| 253 | return; |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 254 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 255 | auto* callModel = accountInfo_->callModel.get(); |
| 256 | if (not callModel->hasCall(callUid_)) { |
| 257 | return; |
| 258 | } |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 259 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 260 | auto currentCall = callModel->getCall(callUid_); |
| 261 | NSLog(@"\n status %@ \n",@(lrc::api::call::to_string(currentCall.status).c_str())); |
Anthony Léonard | 8ee2678 | 2018-01-05 10:23:04 -0500 | [diff] [blame] | 262 | auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel); |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 263 | if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) { |
| 264 | NSString* bestName = bestNameForConversation(*convIt, *accountInfo_->conversationModel); |
| 265 | [personLabel setStringValue:bestName]; |
| 266 | [outgoingPersonLabel setStringValue:bestName]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 267 | [audioCallPersonLabel setStringValue:bestName]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 268 | NSString* ringID = bestIDForConversation(*convIt, *accountInfo_->conversationModel); |
| 269 | if([bestName isEqualToString:ringID]) { |
| 270 | ringID = @""; |
| 271 | } |
| 272 | [outgoingId setStringValue:ringID]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 273 | [audioCallPersonId setStringValue:ringID]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 276 | [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 277 | [audioCallTime setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())]; |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 278 | if (refreshDurationTimer == nil) |
| 279 | refreshDurationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 |
| 280 | target:self |
| 281 | selector:@selector(updateDurationLabel) |
| 282 | userInfo:nil |
| 283 | repeats:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 284 | [stateLabel setStringValue:@(to_string(currentCall.status).c_str())]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 285 | [outgoingStateLabel setStringValue:@(to_string(currentCall.status).c_str())]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 286 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 287 | // Default values for this views |
| 288 | [loadingIndicator setHidden:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 289 | [ringingPanel setHidden:YES]; |
| 290 | [outgoingPanel setHidden:YES]; |
| 291 | [controlsPanel setHidden:NO]; |
| 292 | [headerContainer setHidden:NO]; |
Anthony Léonard | 4b0935f | 2017-12-26 12:05:22 -0500 | [diff] [blame] | 293 | [chatButton setHidden:NO]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 294 | [self setBackground]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 295 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 296 | using Status = lrc::api::call::Status; |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 297 | [self ensureLayoutForCallStatus:currentCall.status]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 298 | switch (currentCall.status) { |
| 299 | case Status::SEARCHING: |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 300 | case Status::CONNECTING: |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 301 | [headerContainer setHidden:YES]; |
| 302 | [outgoingPanel setHidden:NO]; |
| 303 | [outgoingPhoto setHidden:NO]; |
| 304 | [self setupContactInfo:outgoingPhoto]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 305 | [loadingIndicator setHidden:NO]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 306 | [controlsPanel setHidden:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 307 | break; |
| 308 | case Status::INCOMING_RINGING: |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 309 | [outgoingPhoto setHidden:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 310 | [controlsPanel setHidden:YES]; |
| 311 | [outgoingPanel setHidden:YES]; |
| 312 | [self setupIncoming:callUid_]; |
| 313 | break; |
| 314 | case Status::OUTGOING_RINGING: |
| 315 | [controlsPanel setHidden:YES]; |
| 316 | [outgoingPanel setHidden:NO]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 317 | [loadingIndicator setHidden:NO]; |
| 318 | [headerContainer setHidden:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 319 | break; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 320 | /*case Status::CONFERENCE: |
| 321 | [self setupConference:currentCall]; |
| 322 | break;*/ |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 323 | case Status::PAUSED: |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 324 | case Status::INACTIVE: |
| 325 | case Status::IN_PROGRESS: |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 326 | // change constraints (uncollapse avatar) |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 327 | if(currentCall.isAudioOnly) { |
| 328 | [self setUpAudioOnlyView]; |
| 329 | } else { |
| 330 | [self setUpVideoCallView]; |
| 331 | } |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 332 | break; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 333 | case Status::CONNECTED: |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 334 | break; |
| 335 | case Status::ENDED: |
| 336 | case Status::TERMINATING: |
| 337 | case Status::INVALID: |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 338 | break; |
| 339 | } |
Alexandre Lision | 4d9905e | 2016-01-22 12:01:36 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 342 | -(void) setUpVideoCallView { |
| 343 | [self setupContactInfo:personPhoto]; |
| 344 | [timeSpentLabel setHidden:NO]; |
| 345 | [outgoingPhoto setHidden:YES]; |
| 346 | [headerContainer setHidden:NO]; |
| 347 | [previewView setHidden: NO]; |
| 348 | [bluerBackgroundEffect setHidden:YES]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 349 | [backgroundImage setHidden:YES]; |
| 350 | } |
| 351 | |
| 352 | -(void) setUpAudioOnlyView { |
| 353 | [audioCallView setHidden:NO]; |
| 354 | [headerContainer setHidden:YES]; |
| 355 | [audioCallPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
| 356 | } |
| 357 | |
| 358 | -(void) setBackground { |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 359 | auto* convModel = accountInfo_->conversationModel.get(); |
| 360 | auto it = getConversationFromUid(convUid_, *convModel); |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 361 | NSImage *image= [self getContactImageOfSize:120.0 withDefaultAvatar:NO]; |
| 362 | if(image) { |
Kateryna Kostiuk | 89398b6 | 2018-11-20 16:45:04 -0500 | [diff] [blame] | 363 | CIImage * ciImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]]; |
| 364 | CIContext *context = [[CIContext alloc] init]; |
| 365 | CIFilter *clamp = [CIFilter filterWithName:@"CIAffineClamp"]; |
| 366 | [clamp setValue:[NSAffineTransform transform] forKey:@"inputTransform"]; |
| 367 | [clamp setValue:ciImage forKey: kCIInputImageKey]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 368 | CIFilter* bluerFilter = [CIFilter filterWithName:@"CIGaussianBlur"]; |
| 369 | [bluerFilter setDefaults]; |
Kateryna Kostiuk | 89398b6 | 2018-11-20 16:45:04 -0500 | [diff] [blame] | 370 | [bluerFilter setValue:[NSNumber numberWithFloat: 9] forKey:@"inputRadius"]; |
| 371 | [bluerFilter setValue:[clamp valueForKey:kCIOutputImageKey] forKey: kCIInputImageKey]; |
| 372 | CIImage *result = [bluerFilter valueForKey:kCIOutputImageKey]; |
| 373 | CGRect extent = [result extent]; |
| 374 | CGImageRef cgImage = [context createCGImage:result fromRect: [ciImage extent]]; |
| 375 | NSImage *bluredImage = [[NSImage alloc] initWithCGImage:cgImage size:NSSizeFromCGSize(CGSizeMake(image.size.width, image.size.height))]; |
| 376 | backgroundImage.layer.contents = bluredImage; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 377 | [backgroundImage setHidden:NO]; |
| 378 | } else { |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 379 | [bluerBackgroundEffect setFillColor:[NSColor ringDarkGrey]]; |
| 380 | [backgroundImage setHidden:YES]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 384 | -(NSImage *) getContactImageOfSize: (double) size withDefaultAvatar:(BOOL) shouldDrawDefault { |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 385 | auto* convModel = accountInfo_->conversationModel.get(); |
| 386 | auto convIt = getConversationFromUid(convUid_, *convModel); |
| 387 | if (convIt == convModel->allFilteredConversations().end()) { |
| 388 | return nil; |
| 389 | } |
| 390 | if(shouldDrawDefault) { |
| 391 | auto& imgManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator()); |
| 392 | QVariant photo = imgManip.conversationPhoto(*convIt, *accountInfo_, QSize(size, size), NO); |
| 393 | return QtMac::toNSImage(qvariant_cast<QPixmap>(photo)); |
| 394 | } |
| 395 | auto contact = accountInfo_->contactModel->getContact(convIt->participants[0]); |
| 396 | NSData *imageData = [[NSData alloc] initWithBase64EncodedString:@(contact.profileInfo.avatar.c_str()) options:NSDataBase64DecodingIgnoreUnknownCharacters]; |
| 397 | return [[NSImage alloc] initWithData:imageData]; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | -(void) setupContactInfo:(NSImageView*)imageView |
| 402 | { |
| 403 | [imageView setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
| 404 | } |
| 405 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 406 | -(void) setupIncoming:(const std::string&) callId |
Alexandre Lision | 4d9905e | 2016-01-22 12:01:36 -0500 | [diff] [blame] | 407 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 408 | if (accountInfo_ == nil) |
| 409 | return; |
| 410 | |
| 411 | auto* callModel = accountInfo_->callModel.get(); |
| 412 | if (not callModel->hasCall(callUid_)) { |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | auto call = callModel->getCall(callUid_); |
| 417 | auto* convModel = accountInfo_->conversationModel.get(); |
| 418 | |
| 419 | [ringingPanel setHidden:NO]; |
| 420 | [controlsPanel setHidden:YES]; |
| 421 | [headerContainer setHidden:YES]; |
Anthony Léonard | 6f81975 | 2018-01-05 09:53:40 -0500 | [diff] [blame] | 422 | auto it = getConversationFromUid(convUid_, *convModel); |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 423 | if (it != convModel->allFilteredConversations().end()) { |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 424 | [incomingPersonPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
Anthony Léonard | 8ee2678 | 2018-01-05 10:23:04 -0500 | [diff] [blame] | 425 | [incomingDisplayName setStringValue:bestNameForConversation(*it, *convModel)]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | |
| 430 | -(void) setupConference:(Call*) c |
| 431 | { |
| 432 | [videoView setShouldAcceptInteractions:YES]; |
| 433 | [self.chatButton setHidden:NO]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 434 | [self.addParticipantButton setHidden:NO]; |
| 435 | [self.transferButton setHidden:YES]; |
| 436 | } |
| 437 | |
| 438 | -(void)collapseRightView |
| 439 | { |
| 440 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 441 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 442 | NSRect leftFrame = [left frame]; |
| 443 | [right setHidden:YES]; |
| 444 | [splitView display]; |
| 445 | } |
| 446 | |
| 447 | - (void) changeCallSelection:(std::string&)callUid |
| 448 | { |
| 449 | if (accountInfo_ == nil) |
| 450 | return; |
| 451 | |
| 452 | auto* callModel = accountInfo_->callModel.get(); |
| 453 | if (not callModel->hasCall(callUid)) { |
| 454 | return; |
| 455 | } |
| 456 | |
Alexandre Lision | 4d9905e | 2016-01-22 12:01:36 -0500 | [diff] [blame] | 457 | QObject::disconnect(self.selectedCallChanged); |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 458 | self.selectedCallChanged = QObject::connect(callModel, |
| 459 | &lrc::api::NewCallModel::callStatusChanged, |
| 460 | [self](const std::string callId) { |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 461 | [self updateCall]; |
Alexandre Lision | 4d9905e | 2016-01-22 12:01:36 -0500 | [diff] [blame] | 462 | }); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | -(void) connectVideoSignals |
| 466 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 467 | if (accountInfo_ == nil) |
| 468 | return; |
| 469 | |
| 470 | auto* callModel = accountInfo_->callModel.get(); |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 471 | QObject::disconnect(self.videoStarted); |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 472 | self.videoStarted = QObject::connect(callModel, |
| 473 | &lrc::api::NewCallModel::remotePreviewStarted, |
| 474 | [self](const std::string& callId, Video::Renderer* renderer) { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 475 | [videoView setLayer:[[CallLayer alloc] init]]; |
Kateryna Kostiuk | 1004caa | 2018-03-29 13:48:07 -0400 | [diff] [blame] | 476 | [videoView setShouldAcceptInteractions:YES]; |
| 477 | [self mouseIsMoving: NO]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 478 | [self connectVideoRenderer:renderer]; |
| 479 | }); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 480 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 481 | if (callModel->hasCall(callUid_)) { |
| 482 | if (auto renderer = callModel->getRenderer(callUid_)) { |
| 483 | QObject::disconnect(self.videoStarted); |
| 484 | [self connectVideoRenderer: renderer]; |
| 485 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 486 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 487 | [self connectPreviewRenderer]; |
| 488 | |
| 489 | } |
| 490 | |
| 491 | -(void) connectPreviewRenderer |
| 492 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 493 | QObject::disconnect(previewHolder.frameUpdated); |
| 494 | QObject::disconnect(previewHolder.stopped); |
| 495 | QObject::disconnect(previewHolder.started); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 496 | previewHolder.started = QObject::connect(&Video::PreviewManager::instance(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 497 | &Video::PreviewManager::previewStarted, |
| 498 | [=](Video::Renderer* renderer) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 499 | QObject::disconnect(previewHolder.frameUpdated); |
| 500 | previewHolder.frameUpdated = QObject::connect(renderer, |
| 501 | &Video::Renderer::frameUpdated, |
| 502 | [=]() { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 503 | [self renderer:Video::PreviewManager::instance().previewRenderer() |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 504 | renderFrameForPreviewView:previewView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 505 | }); |
| 506 | }); |
| 507 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 508 | previewHolder.stopped = QObject::connect(&Video::PreviewManager::instance(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 509 | &Video::PreviewManager::previewStopped, |
| 510 | [=](Video::Renderer* renderer) { |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 511 | QObject::disconnect(previewHolder.frameUpdated); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 512 | [previewView.layer setContents:nil]; |
| 513 | }); |
| 514 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 515 | previewHolder.frameUpdated = QObject::connect(Video::PreviewManager::instance().previewRenderer(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 516 | &Video::Renderer::frameUpdated, |
| 517 | [=]() { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 518 | [self renderer:Video::PreviewManager::instance().previewRenderer() |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 519 | renderFrameForPreviewView:previewView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 520 | }); |
| 521 | } |
| 522 | |
| 523 | -(void) connectVideoRenderer: (Video::Renderer*)renderer |
| 524 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 525 | QObject::disconnect(videoHolder.frameUpdated); |
| 526 | QObject::disconnect(videoHolder.started); |
| 527 | QObject::disconnect(videoHolder.stopped); |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 528 | |
| 529 | if(renderer == nil) |
| 530 | return; |
| 531 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 532 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 533 | &Video::Renderer::frameUpdated, |
| 534 | [=]() { |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 535 | if(!renderer->isRendering()) { |
| 536 | return; |
| 537 | } |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 538 | [self renderer:renderer renderFrameForDistantView:videoView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 539 | }); |
| 540 | |
| 541 | videoHolder.started = QObject::connect(renderer, |
| 542 | &Video::Renderer::started, |
| 543 | [=]() { |
Kateryna Kostiuk | bcf24e9 | 2018-11-20 10:09:06 -0500 | [diff] [blame] | 544 | if (![videoView.layer isKindOfClass:[CallLayer class]]) { |
| 545 | [videoView setLayer:[[CallLayer alloc] init]]; |
| 546 | } |
Kateryna Kostiuk | 1004caa | 2018-03-29 13:48:07 -0400 | [diff] [blame] | 547 | [self mouseIsMoving: NO]; |
| 548 | [videoView setShouldAcceptInteractions:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 549 | QObject::disconnect(videoHolder.frameUpdated); |
| 550 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 551 | &Video::Renderer::frameUpdated, |
| 552 | [=]() { |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 553 | [self renderer:renderer renderFrameForDistantView:videoView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 554 | }); |
| 555 | }); |
| 556 | |
| 557 | videoHolder.stopped = QObject::connect(renderer, |
| 558 | &Video::Renderer::stopped, |
| 559 | [=]() { |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 560 | [(CallLayer*)videoView.layer setVideoRunning:NO]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 561 | [videoView setLayer:[CALayer layer]]; |
| 562 | [videoView.layer setBackgroundColor:[[NSColor blackColor] CGColor]]; |
Kateryna Kostiuk | 1004caa | 2018-03-29 13:48:07 -0400 | [diff] [blame] | 563 | [self mouseIsMoving: YES]; |
| 564 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 565 | QObject::disconnect(videoHolder.frameUpdated); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 566 | }); |
| 567 | } |
| 568 | |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 569 | -(void) renderer: (Video::Renderer*)renderer renderFrameForPreviewView:(NSView*) view |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 570 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 571 | QSize res = renderer->size(); |
| 572 | |
Alexandre Lision | 6731e13 | 2015-10-14 14:29:06 -0400 | [diff] [blame] | 573 | auto frame_ptr = renderer->currentFrame(); |
| 574 | auto frame_data = frame_ptr.ptr; |
| 575 | if (!frame_data) |
| 576 | return; |
| 577 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 578 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
Alexandre Lision | 6731e13 | 2015-10-14 14:29:06 -0400 | [diff] [blame] | 579 | CGContextRef newContext = CGBitmapContextCreate(frame_data, |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 580 | res.width(), |
| 581 | res.height(), |
| 582 | 8, |
| 583 | 4*res.width(), |
| 584 | colorSpace, |
| 585 | kCGImageAlphaPremultipliedLast); |
| 586 | |
| 587 | |
| 588 | CGImageRef newImage = CGBitmapContextCreateImage(newContext); |
| 589 | |
| 590 | /*We release some components*/ |
| 591 | CGContextRelease(newContext); |
| 592 | CGColorSpaceRelease(colorSpace); |
| 593 | |
| 594 | [CATransaction begin]; |
| 595 | view.layer.contents = (__bridge id)newImage; |
| 596 | [CATransaction commit]; |
| 597 | |
| 598 | CFRelease(newImage); |
| 599 | } |
| 600 | |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 601 | -(void) renderer: (Video::Renderer*)renderer renderFrameForDistantView:(CallView*) view |
| 602 | { |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 603 | auto frame_ptr = renderer->currentFrame(); |
| 604 | if (!frame_ptr.ptr) |
| 605 | return; |
| 606 | |
| 607 | CallLayer* callLayer = (CallLayer*) view.layer; |
Kateryna Kostiuk | bcf24e9 | 2018-11-20 10:09:06 -0500 | [diff] [blame] | 608 | if ([callLayer respondsToSelector:@selector(setCurrentFrame:)]) { |
| 609 | [callLayer setCurrentFrame:std::move(frame_ptr)]; |
| 610 | [callLayer setVideoRunning:YES]; |
| 611 | } |
Anthony Léonard | 14e7bf3 | 2017-06-08 08:13:16 -0400 | [diff] [blame] | 612 | } |
| 613 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 614 | - (void) initFrame |
| 615 | { |
| 616 | [self.view setFrame:self.view.superview.bounds]; |
| 617 | [self.view setHidden:YES]; |
| 618 | self.view.layer.position = self.view.frame.origin; |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 619 | [self collapseRightView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | # pragma private IN/OUT animations |
| 623 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 624 | -(void)uncollapseRightView |
| 625 | { |
| 626 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 627 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 628 | [right setHidden:NO]; |
| 629 | |
| 630 | CGFloat dividerThickness = [splitView dividerThickness]; |
| 631 | |
| 632 | // get the different frames |
| 633 | NSRect leftFrame = [left frame]; |
| 634 | NSRect rightFrame = [right frame]; |
| 635 | |
| 636 | leftFrame.size.width = (leftFrame.size.width - rightFrame.size.width - dividerThickness); |
| 637 | rightFrame.origin.x = leftFrame.size.width + dividerThickness; |
| 638 | [left setFrameSize:leftFrame.size]; |
| 639 | [right setFrame:rightFrame]; |
| 640 | [splitView display]; |
| 641 | |
| 642 | [self.chatVC takeFocus]; |
| 643 | } |
| 644 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 645 | -(void) cleanUp |
| 646 | { |
Anthony Léonard | 5c28764 | 2018-02-21 15:54:19 -0500 | [diff] [blame] | 647 | if(self.splitView.isInFullScreenMode) |
| 648 | [self.splitView exitFullScreenModeWithOptions:nil]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 649 | QObject::disconnect(videoHolder.frameUpdated); |
| 650 | QObject::disconnect(videoHolder.started); |
| 651 | QObject::disconnect(videoHolder.stopped); |
| 652 | QObject::disconnect(previewHolder.frameUpdated); |
| 653 | QObject::disconnect(previewHolder.stopped); |
| 654 | QObject::disconnect(previewHolder.started); |
Anthony Léonard | c0013bb | 2018-02-20 16:23:02 -0500 | [diff] [blame] | 655 | QObject::disconnect(self.messageConnection); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 656 | [previewView.layer setContents:nil]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 657 | [previewView setHidden: YES]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 658 | [videoView setLayer:[CALayer layer]]; |
| 659 | [videoView.layer setBackgroundColor:[[NSColor blackColor] CGColor]]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 660 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 661 | [self.chatButton setHidden:YES]; |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 662 | [self.chatButton setPressed:NO]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 663 | [self collapseRightView]; |
Alexandre Lision | 5722777 | 2016-01-15 17:19:36 -0500 | [diff] [blame] | 664 | |
| 665 | [personLabel setStringValue:@""]; |
| 666 | [timeSpentLabel setStringValue:@""]; |
| 667 | [stateLabel setStringValue:@""]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 668 | //audio view |
| 669 | [audioCallTime setStringValue:@""]; |
| 670 | [audioCallPersonId setStringValue:@""]; |
| 671 | [audioCallPersonLabel setStringValue:@""]; |
| 672 | [audioCallView setHidden:YES]; |
| 673 | [audioCallPhoto setImage:nil]; |
| 674 | //background view |
| 675 | [bluerBackgroundEffect setHidden:NO]; |
| 676 | [backgroundImage setHidden:NO]; |
Kateryna Kostiuk | 81afce7 | 2018-10-30 16:40:50 -0400 | [diff] [blame] | 677 | //outgoing view |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 678 | [outgoingPersonLabel setStringValue:@""]; |
| 679 | [outgoingStateLabel setStringValue:@""]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 680 | } |
| 681 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 682 | -(void) setupCallView |
| 683 | { |
| 684 | if (accountInfo_ == nil) |
| 685 | return; |
| 686 | |
| 687 | auto* callModel = accountInfo_->callModel.get(); |
| 688 | auto* convModel = accountInfo_->conversationModel.get(); |
| 689 | |
| 690 | // when call comes in we want to show the controls/header |
Kateryna Kostiuk | 1004caa | 2018-03-29 13:48:07 -0400 | [diff] [blame] | 691 | [self mouseIsMoving: YES]; |
| 692 | [videoView setShouldAcceptInteractions: NO]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 693 | |
| 694 | [self connectVideoSignals]; |
| 695 | /* check if text media is already present */ |
| 696 | if(not callModel->hasCall(callUid_)) |
| 697 | return; |
| 698 | |
| 699 | [loadingIndicator setAnimates:YES]; |
Andreas Traczyk | 77a50d5 | 2018-05-08 17:47:31 -0400 | [diff] [blame] | 700 | [self updateCall]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 701 | |
| 702 | /* monitor media for messaging text messaging */ |
| 703 | QObject::disconnect(self.messageConnection); |
| 704 | self.messageConnection = QObject::connect(convModel, |
| 705 | &lrc::api::ConversationModel::interactionStatusUpdated, |
| 706 | [self] (std::string convUid, |
| 707 | uint64_t msgId, |
| 708 | lrc::api::interaction::Info msg) { |
| 709 | if (msg.type == lrc::api::interaction::Type::TEXT) { |
| 710 | if(not [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]){ |
| 711 | return; |
| 712 | } |
| 713 | [self uncollapseRightView]; |
| 714 | } |
| 715 | }); |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 716 | //monitor for updated profile |
| 717 | QObject::disconnect(self.profileUpdatedConnection); |
| 718 | self.profileUpdatedConnection = |
| 719 | QObject::connect(accountInfo_->contactModel.get(), |
| 720 | &lrc::api::ContactModel::contactAdded, |
| 721 | [self](const std::string &contactUri) { |
| 722 | auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel.get()); |
| 723 | if (convIt == accountInfo_->conversationModel->allFilteredConversations().end()) { |
| 724 | return; |
| 725 | } |
| 726 | if (convIt->participants.empty()) { |
| 727 | return; |
| 728 | |
| 729 | } |
| 730 | auto& contact = accountInfo_->contactModel->getContact(convIt->participants[0]); |
| 731 | if (contact.profileInfo.type == lrc::api::profile::Type::RING && contact.profileInfo.uri == contactUri) |
| 732 | accountInfo_->conversationModel->makePermanent(convUid_); |
| 733 | [incomingPersonPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
| 734 | [outgoingPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
Kateryna Kostiuk | 732b406 | 2018-11-28 09:59:28 -0500 | [diff] [blame] | 735 | [self.delegate conversationInfoUpdatedFor:convUid_]; |
Kateryna Kostiuk | 133364b | 2018-10-31 11:36:08 -0400 | [diff] [blame] | 736 | if(accountInfo_->callModel.get()->getCall(callUid_).isAudioOnly) { |
| 737 | [audioCallPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
| 738 | [self setBackground]; |
| 739 | return; |
| 740 | } |
| 741 | [personPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]]; |
| 742 | }); |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | -(void) showWithAnimation:(BOOL)animate |
| 746 | { |
| 747 | if (!animate) { |
| 748 | [self.view setHidden:NO]; |
| 749 | [self setupCallView]; |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0); |
| 754 | [self.view setHidden:NO]; |
| 755 | |
| 756 | [CATransaction begin]; |
| 757 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 758 | [animation setFromValue:[NSValue valueWithPoint:frame.origin]]; |
| 759 | [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]]; |
| 760 | [animation setDuration:0.2f]; |
| 761 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; |
| 762 | [CATransaction setCompletionBlock:^{ |
| 763 | [self setupCallView]; |
| 764 | }]; |
| 765 | |
| 766 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 767 | [CATransaction commit]; |
| 768 | } |
| 769 | |
| 770 | -(void) hideWithAnimation:(BOOL)animate |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 771 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 772 | if(self.view.frame.origin.x < 0) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 773 | return; |
| 774 | } |
| 775 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 776 | if (!animate) { |
| 777 | [self.view setHidden:YES]; |
| 778 | return; |
| 779 | } |
| 780 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 781 | CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0); |
| 782 | [CATransaction begin]; |
| 783 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 784 | [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]]; |
| 785 | [animation setToValue:[NSValue valueWithPoint:frame.origin]]; |
| 786 | [animation setDuration:0.2f]; |
Alexandre Lision | 22d615b | 2016-01-25 12:54:34 -0500 | [diff] [blame] | 787 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 788 | |
| 789 | [CATransaction setCompletionBlock:^{ |
| 790 | [self.view setHidden:YES]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 791 | // first make sure everything is disconnected |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 792 | [self cleanUp]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 793 | // if (currentCall_) { |
| 794 | // [self animateIn]; |
| 795 | // } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 796 | }]; |
| 797 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 798 | |
| 799 | [self.view.layer setPosition:frame.origin]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 800 | [CATransaction commit]; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Debug purpose |
| 805 | */ |
| 806 | -(void) dumpFrame:(CGRect) frame WithName:(NSString*) name |
| 807 | { |
| 808 | NSLog(@"frame %@ : %f %f %f %f \n\n",name ,frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); |
| 809 | } |
| 810 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 811 | #pragma mark - Button methods |
| 812 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 813 | - (IBAction)hangUp:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 814 | if (accountInfo_ == nil) |
| 815 | return; |
| 816 | |
| 817 | auto* callModel = accountInfo_->callModel.get(); |
| 818 | |
| 819 | callModel->hangUp(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | - (IBAction)accept:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 823 | if (accountInfo_ == nil) |
| 824 | return; |
| 825 | |
Anthony Léonard | f584cc5 | 2018-01-19 12:00:19 -0500 | [diff] [blame] | 826 | // If we accept a conversation with a non trusted contact, we first accept it |
| 827 | auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel.get()); |
| 828 | if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) { |
| 829 | auto& contact = accountInfo_->contactModel->getContact(convIt->participants[0]); |
| 830 | if (contact.profileInfo.type == lrc::api::profile::Type::PENDING) |
| 831 | accountInfo_->conversationModel->makePermanent(convUid_); |
| 832 | } |
| 833 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 834 | auto* callModel = accountInfo_->callModel.get(); |
| 835 | |
| 836 | callModel->accept(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | - (IBAction)toggleRecording:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 840 | if (accountInfo_ == nil) |
| 841 | return; |
| 842 | |
| 843 | auto* callModel = accountInfo_->callModel.get(); |
| 844 | |
| 845 | callModel->toggleAudioRecord(callUid_); |
Kateryna Kostiuk | 54d7697 | 2018-06-07 15:45:07 -0400 | [diff] [blame] | 846 | [recordOnOffButton setPressed:!recordOnOffButton.isPressed]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | - (IBAction)toggleHold:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 850 | if (accountInfo_ == nil) |
| 851 | return; |
| 852 | |
| 853 | auto* callModel = accountInfo_->callModel.get(); |
Kateryna Kostiuk | 54d7697 | 2018-06-07 15:45:07 -0400 | [diff] [blame] | 854 | auto currentCall = callModel->getCall(callUid_); |
| 855 | if (currentCall.status != lrc::api::call::Status::PAUSED) { |
| 856 | holdOnOffButton.image = [NSImage imageNamed:@"ic_action_holdoff.png"]; |
| 857 | } else { |
| 858 | holdOnOffButton.image = [NSImage imageNamed:@"ic_action_hold.png"]; |
| 859 | } |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 860 | |
| 861 | callModel->togglePause(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 862 | } |
| 863 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 864 | - (IBAction)toggleAdvancedControls:(id)sender { |
| 865 | [advancedButton setPressed:!advancedButton.isPressed]; |
| 866 | [advancedPanel setHidden:![advancedButton isPressed]]; |
| 867 | } |
| 868 | |
| 869 | - (IBAction)showDialpad:(id)sender { |
| 870 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 871 | [appDelegate showDialpad]; |
| 872 | } |
| 873 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 874 | -(IBAction)toggleChat:(id)sender; |
| 875 | { |
| 876 | BOOL rightViewCollapsed = [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]; |
| 877 | if (rightViewCollapsed) { |
| 878 | [self uncollapseRightView]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 879 | } else { |
| 880 | [self collapseRightView]; |
| 881 | } |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 882 | [chatButton setPressed:rightViewCollapsed]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 883 | } |
| 884 | |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 885 | - (IBAction)muteAudio:(id)sender |
| 886 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 887 | if (accountInfo_ == nil) |
| 888 | return; |
| 889 | |
| 890 | auto* callModel = accountInfo_->callModel.get(); |
Kateryna Kostiuk | 54d7697 | 2018-06-07 15:45:07 -0400 | [diff] [blame] | 891 | auto currentCall = callModel->getCall(callUid_); |
| 892 | if (currentCall.audioMuted) { |
| 893 | muteAudioButton.image = [NSImage imageNamed:@"ic_action_audio.png"]; |
| 894 | } else { |
| 895 | muteAudioButton.image = [NSImage imageNamed:@"ic_action_mute_audio.png"]; |
| 896 | } |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 897 | callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::AUDIO); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | - (IBAction)muteVideo:(id)sender |
| 901 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 902 | if (accountInfo_ == nil) |
| 903 | return; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 904 | auto* callModel = accountInfo_->callModel.get(); |
Kateryna Kostiuk | 54d7697 | 2018-06-07 15:45:07 -0400 | [diff] [blame] | 905 | auto currentCall = callModel->getCall(callUid_); |
| 906 | if(!currentCall.isAudioOnly) { |
| 907 | if (currentCall.videoMuted) { |
| 908 | muteVideoButton.image = [NSImage imageNamed:@"ic_action_video.png"]; |
| 909 | } else { |
| 910 | muteVideoButton.image = [NSImage imageNamed:@"ic_action_mute_video.png"]; |
| 911 | } |
| 912 | } |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 913 | callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::VIDEO); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 914 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 915 | |
| 916 | - (IBAction)toggleTransferView:(id)sender { |
Kateryna Kostiuk | 1ba5a01 | 2018-12-12 17:07:38 -0500 | [diff] [blame^] | 917 | |
Alexandre Lision | f23ec5a | 2015-07-16 11:24:06 -0400 | [diff] [blame] | 918 | } |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 919 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 920 | - (IBAction)toggleAddParticipantView:(id)sender { |
Kateryna Kostiuk | 1ba5a01 | 2018-12-12 17:07:38 -0500 | [diff] [blame^] | 921 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 924 | #pragma mark - NSPopOverDelegate |
| 925 | |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 926 | - (void)popoverWillClose:(NSNotification *)notification |
| 927 | { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 928 | if (_brokerPopoverVC != nullptr) { |
| 929 | [_brokerPopoverVC performClose:self]; |
| 930 | _brokerPopoverVC = NULL; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 931 | } |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 932 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 933 | if (self.addToContactPopover != nullptr) { |
| 934 | [self.addToContactPopover performClose:self]; |
| 935 | self.addToContactPopover = NULL; |
| 936 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 937 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 938 | [self.transferButton setPressed:NO]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 939 | [self.addParticipantButton setState:NSOffState]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | - (void)popoverDidClose:(NSNotification *)notification |
| 943 | { |
| 944 | [videoView setCallDelegate:self]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | #pragma mark - ContactLinkedDelegate |
| 948 | |
| 949 | - (void)contactLinked |
| 950 | { |
| 951 | if (self.addToContactPopover != nullptr) { |
| 952 | [self.addToContactPopover performClose:self]; |
| 953 | self.addToContactPopover = NULL; |
| 954 | } |
| 955 | } |
| 956 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 957 | #pragma mark - NSSplitViewDelegate |
| 958 | |
| 959 | /* Return YES if the subview should be collapsed because the user has double-clicked on an adjacent divider. If a split view has a delegate, and the delegate responds to this message, it will be sent once for the subview before a divider when the user double-clicks on that divider, and again for the subview after the divider, but only if the delegate returned YES when sent -splitView:canCollapseSubview: for the subview in question. When the delegate indicates that both subviews should be collapsed NSSplitView's behavior is undefined. |
| 960 | */ |
| 961 | - (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex; |
| 962 | { |
| 963 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 964 | return ([subview isEqual:rightView]); |
| 965 | } |
| 966 | |
| 967 | |
| 968 | - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; |
| 969 | { |
| 970 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 971 | return ([subview isEqual:rightView]); |
| 972 | } |
| 973 | |
| 974 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 975 | # pragma mark - CallnDelegate |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 976 | |
| 977 | - (void) callShouldToggleFullScreen |
| 978 | { |
| 979 | if(self.splitView.isInFullScreenMode) |
| 980 | [self.splitView exitFullScreenModeWithOptions:nil]; |
| 981 | else { |
| 982 | NSApplicationPresentationOptions options = NSApplicationPresentationDefault +NSApplicationPresentationAutoHideDock + |
| 983 | NSApplicationPresentationAutoHideMenuBar + NSApplicationPresentationAutoHideToolbar; |
| 984 | NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:options], |
| 985 | NSFullScreenModeApplicationPresentationOptions, nil]; |
| 986 | |
| 987 | [self.splitView enterFullScreenMode:[NSScreen mainScreen] withOptions:opts]; |
| 988 | } |
| 989 | } |
| 990 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 991 | -(void) mouseIsMoving:(BOOL) move |
| 992 | { |
| 993 | [[controlsPanel animator] setAlphaValue:move]; // fade out |
| 994 | [[headerContainer animator] setAlphaValue:move]; |
| 995 | } |
| 996 | |
Kateryna Kostiuk | 89398b6 | 2018-11-20 16:45:04 -0500 | [diff] [blame] | 997 | - (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex |
| 998 | { |
| 999 | return YES; |
| 1000 | } |
| 1001 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 1002 | @end |