blob: 27b447786c75d166795cab4409d40206861a7a6e [file] [log] [blame]
Alexandre Lisionc5148052015-03-04 15:10:35 -05001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lisionc5148052015-03-04 15:10:35 -05003 * 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 Lisionc5148052015-03-04 15:10:35 -050018 */
19#import "CurrentCallVC.h"
20
21#import <QuartzCore/QuartzCore.h>
22
Alexandre Lision210fe212016-01-27 11:15:13 -050023///Qt
24#import <QMimeData>
25#import <QtMacExtras/qmacfunctions.h>
26#import <QtCore/qabstractitemmodel.h>
27#import <QItemSelectionModel>
28#import <QItemSelection>
29#import <QPixmap>
30
31///LRC
Alexandre Lisionc5148052015-03-04 15:10:35 -050032#import <video/previewmanager.h>
33#import <video/renderer.h>
Olivier Soldano994971f2017-12-05 16:30:12 -050034#import <api/newcallmodel.h>
35#import <api/call.h>
36#import <api/conversationmodel.h>
Alexandre Lision210fe212016-01-27 11:15:13 -050037#import <globalinstances.h>
Alexandre Lisionc5148052015-03-04 15:10:35 -050038
Alexandre Lision62005312016-01-28 15:55:16 -050039#import "AppDelegate.h"
Alexandre Lisionf47a2562015-06-15 15:48:29 -040040#import "views/ITProgressIndicator.h"
Alexandre Lision74dd47f2015-04-14 13:47:42 -040041#import "views/CallView.h"
Alexandre Lision210fe212016-01-27 11:15:13 -050042#import "delegates/ImageManipulationDelegate.h"
Alexandre Lision2db8f472015-07-22 15:05:46 -040043#import "PersonLinkerVC.h"
Alexandre Lision16d9c0a2015-08-10 12:05:15 -040044#import "ChatVC.h"
Alexandre Lision883719f2015-10-22 17:37:45 -040045#import "BrokerVC.h"
Alexandre Lision4baba4c2016-02-11 13:00:57 -050046#import "views/IconButton.h"
Anthony Léonard14e7bf32017-06-08 08:13:16 -040047#import "views/CallLayer.h"
Anthony Léonard6f819752018-01-05 09:53:40 -050048#import "utils.h"
Alexandre Lision74dd47f2015-04-14 13:47:42 -040049
Alexandre Lisionc5148052015-03-04 15:10:35 -050050@interface RendererConnectionsHolder : NSObject
51
52@property QMetaObject::Connection frameUpdated;
53@property QMetaObject::Connection started;
54@property QMetaObject::Connection stopped;
55
56@end
57
58@implementation RendererConnectionsHolder
59
60@end
61
Olivier Soldano994971f2017-12-05 16:30:12 -050062@interface CurrentCallVC () <NSPopoverDelegate, ContactLinkedDelegate> {
63 std::string convUid_;
64 std::string callUid_;
65 const lrc::api::account::Info *accountInfo_;
Anthony Léonard66a050c2018-01-03 16:32:34 -050066 NSTimer* refreshDurationTimer;
Olivier Soldano994971f2017-12-05 16:30:12 -050067}
Alexandre Lisionc5148052015-03-04 15:10:35 -050068
Alexandre Lision210fe212016-01-27 11:15:13 -050069// Main container
70@property (unsafe_unretained) IBOutlet NSSplitView* splitView;
71
Alexandre Lision89edc6a2015-11-09 11:30:47 -050072// Header info
73@property (unsafe_unretained) IBOutlet NSView* headerContainer;
Alexandre Lision883719f2015-10-22 17:37:45 -040074@property (unsafe_unretained) IBOutlet NSTextField* personLabel;
75@property (unsafe_unretained) IBOutlet NSTextField* stateLabel;
Alexandre Lision89edc6a2015-11-09 11:30:47 -050076@property (unsafe_unretained) IBOutlet NSTextField* timeSpentLabel;
Alexandre Lision210fe212016-01-27 11:15:13 -050077@property (unsafe_unretained) IBOutlet NSImageView* personPhoto;
Alexandre Lision89edc6a2015-11-09 11:30:47 -050078
Andreas Traczyk77a50d52018-05-08 17:47:31 -040079@property (unsafe_unretained) IBOutlet NSImageView* outgoingPhoto;
80@property (unsafe_unretained) IBOutlet NSTextField* outgoingPersonLabel;
81@property (unsafe_unretained) IBOutlet NSTextField* outgoingStateLabel;
82@property (unsafe_unretained) IBOutlet NSTextField* outgoingId;
83
Alexandre Lision89edc6a2015-11-09 11:30:47 -050084// Call Controls
85@property (unsafe_unretained) IBOutlet NSView* controlsPanel;
Alexandre Lision62005312016-01-28 15:55:16 -050086
Alexandre Lision4baba4c2016-02-11 13:00:57 -050087@property (unsafe_unretained) IBOutlet IconButton* holdOnOffButton;
88@property (unsafe_unretained) IBOutlet IconButton* hangUpButton;
89@property (unsafe_unretained) IBOutlet IconButton* recordOnOffButton;
90@property (unsafe_unretained) IBOutlet IconButton* pickUpButton;
91@property (unsafe_unretained) IBOutlet IconButton* muteAudioButton;
92@property (unsafe_unretained) IBOutlet IconButton* muteVideoButton;
Alexandre Lision4baba4c2016-02-11 13:00:57 -050093@property (unsafe_unretained) IBOutlet IconButton* transferButton;
94@property (unsafe_unretained) IBOutlet IconButton* addParticipantButton;
95@property (unsafe_unretained) IBOutlet IconButton* chatButton;
Andreas Traczyk77a50d52018-05-08 17:47:31 -040096@property (unsafe_unretained) IBOutlet IconButton* qualityButton;
Alexandre Lisiond18fa272015-06-15 11:18:03 -040097
Alexandre Lision62005312016-01-28 15:55:16 -050098@property (unsafe_unretained) IBOutlet NSView* advancedPanel;
99@property (unsafe_unretained) IBOutlet IconButton* advancedButton;
100
Alexandre Lisiond18fa272015-06-15 11:18:03 -0400101
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500102// Join call panel
103@property (unsafe_unretained) IBOutlet NSView* joinPanel;
104@property (unsafe_unretained) IBOutlet NSButton* mergeCallsButton;
105
Alexandre Lision2db8f472015-07-22 15:05:46 -0400106@property (strong) NSPopover* addToContactPopover;
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500107@property (strong) NSPopover* brokerPopoverVC;
Alexandre Lision883719f2015-10-22 17:37:45 -0400108@property (strong) IBOutlet ChatVC* chatVC;
Alexandre Lisionf23ec5a2015-07-16 11:24:06 -0400109
Alexandre Lision210fe212016-01-27 11:15:13 -0500110// Ringing call panel
111@property (unsafe_unretained) IBOutlet NSView* ringingPanel;
112@property (unsafe_unretained) IBOutlet NSImageView* incomingPersonPhoto;
113@property (unsafe_unretained) IBOutlet NSTextField* incomingDisplayName;
114
115// Outgoing call panel
116@property (unsafe_unretained) IBOutlet NSView* outgoingPanel;
117@property (unsafe_unretained) IBOutlet ITProgressIndicator *loadingIndicator;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500118
119// Video
Alexandre Lision58cab672015-06-09 15:25:40 -0400120@property (unsafe_unretained) IBOutlet CallView *videoView;
Alexandre Lision58cab672015-06-09 15:25:40 -0400121@property (unsafe_unretained) IBOutlet NSView *previewView;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500122
123@property RendererConnectionsHolder* previewHolder;
124@property RendererConnectionsHolder* videoHolder;
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400125@property QMetaObject::Connection videoStarted;
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500126@property QMetaObject::Connection selectedCallChanged;
Alexandre Lisionb65c0272015-07-22 15:51:29 -0400127@property QMetaObject::Connection messageConnection;
128@property QMetaObject::Connection mediaAddedConnection;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500129
130@end
131
132@implementation CurrentCallVC
Olivier Soldano994971f2017-12-05 16:30:12 -0500133@synthesize personLabel, personPhoto, stateLabel, holdOnOffButton, hangUpButton,
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500134 recordOnOffButton, pickUpButton, chatButton, transferButton, addParticipantButton, timeSpentLabel,
Olivier Soldano994971f2017-12-05 16:30:12 -0500135 muteVideoButton, muteAudioButton, controlsPanel, advancedPanel, advancedButton, headerContainer, videoView,
136 incomingDisplayName, incomingPersonPhoto, previewView, splitView, loadingIndicator, ringingPanel, joinPanel,
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400137 outgoingPanel, outgoingPersonLabel, outgoingStateLabel, outgoingPhoto, outgoingId;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500138
139@synthesize previewHolder;
140@synthesize videoHolder;
141
Olivier Soldano994971f2017-12-05 16:30:12 -0500142-(void) setCurrentCall:(const std::string&)callUid
143 conversation:(const std::string&)convUid
144 account:(const lrc::api::account::Info*)account;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500145{
Olivier Soldano994971f2017-12-05 16:30:12 -0500146 if(account == nil)
147 return;
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400148
Olivier Soldano994971f2017-12-05 16:30:12 -0500149 auto* callModel = account->callModel.get();
Alexandre Lisionc5148052015-03-04 15:10:35 -0500150
Olivier Soldano994971f2017-12-05 16:30:12 -0500151 if (not callModel->hasCall(callUid)){
152 callUid_.clear();
Alexandre Lision2db8f472015-07-22 15:05:46 -0400153 return;
154 }
Olivier Soldano994971f2017-12-05 16:30:12 -0500155 callUid_ = callUid;
156 convUid_ = convUid;
157 accountInfo_ = account;
Anthony Léonard4b0935f2017-12-26 12:05:22 -0500158 [self.chatVC setConversationUid:convUid model:account->conversationModel.get()];
Kateryna Kostiuk54d76972018-06-07 15:45:07 -0400159 auto currentCall = callModel->getCall(callUid_);
160 if(currentCall.isAudioOnly) {
161 muteVideoButton.image = [NSImage imageNamed:@"ic_action_mute_video.png"];
162 }
Kateryna Kostiukd76f6202018-09-11 17:15:28 -0400163 videoView.callId = callUid;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500164}
165
166- (void)awakeFromNib
167{
168 NSLog(@"INIT CurrentCall VC");
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400169 [self.view setWantsLayer:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500170
Alexandre Lisionc5148052015-03-04 15:10:35 -0500171 [previewView setWantsLayer:YES];
Alexandre Lision22d615b2016-01-25 12:54:34 -0500172 [previewView.layer setBackgroundColor:[NSColor blackColor].CGColor];
173 [previewView.layer setContentsGravity:kCAGravityResizeAspectFill];
174 [previewView.layer setFrame:previewView.frame];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500175
176 [controlsPanel setWantsLayer:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500177 [controlsPanel.layer setBackgroundColor:[NSColor clearColor].CGColor];
178 [controlsPanel.layer setFrame:controlsPanel.frame];
179
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400180 previewHolder = [[RendererConnectionsHolder alloc] init];
181 videoHolder = [[RendererConnectionsHolder alloc] init];
182
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400183 [loadingIndicator setColor:[NSColor whiteColor]];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400184 [loadingIndicator setNumberOfLines:200];
185 [loadingIndicator setWidthOfLine:4];
186 [loadingIndicator setLengthOfLine:4];
187 [loadingIndicator setInnerMargin:59];
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400188
Alexandre Lisiona1eee3c2015-08-10 13:44:51 -0400189 [self.videoView setCallDelegate:self];
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400190 CGColor* color = [[[NSColor blackColor] colorWithAlphaComponent:0.2] CGColor];
191 [headerContainer.layer setBackgroundColor:color];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500192}
193
Anthony Léonard66a050c2018-01-03 16:32:34 -0500194-(void) updateDurationLabel
195{
196 if (accountInfo_ != nil) {
197 auto* callModel = accountInfo_->callModel.get();
198 if (callModel->hasCall(callUid_)) {
199 auto& callStatus = callModel->getCall(callUid_).status;
200 if (callStatus != lrc::api::call::Status::ENDED &&
201 callStatus != lrc::api::call::Status::TERMINATING &&
202 callStatus != lrc::api::call::Status::INVALID) {
203 [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())];
204 return;
205 }
206 }
207 }
208
209 // If call is not running anymore or accountInfo_ is not set for any reason
210 // we stop the refresh loop
211 [refreshDurationTimer invalidate];
212 refreshDurationTimer = nil;
213 [timeSpentLabel setHidden:YES];
214}
215
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400216-(void) updateCall
Alexandre Lisionc5148052015-03-04 15:10:35 -0500217{
Olivier Soldano994971f2017-12-05 16:30:12 -0500218 if (accountInfo_ == nil)
219 return;
Alexandre Lisionbb5dbcd2015-07-09 16:36:47 -0400220
Olivier Soldano994971f2017-12-05 16:30:12 -0500221 auto* callModel = accountInfo_->callModel.get();
222 if (not callModel->hasCall(callUid_)) {
223 return;
224 }
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500225
Olivier Soldano994971f2017-12-05 16:30:12 -0500226 auto currentCall = callModel->getCall(callUid_);
227 NSLog(@"\n status %@ \n",@(lrc::api::call::to_string(currentCall.status).c_str()));
Anthony Léonard8ee26782018-01-05 10:23:04 -0500228 auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel);
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400229 if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) {
230 NSString* bestName = bestNameForConversation(*convIt, *accountInfo_->conversationModel);
231 [personLabel setStringValue:bestName];
232 [outgoingPersonLabel setStringValue:bestName];
233 NSString* ringID = bestIDForConversation(*convIt, *accountInfo_->conversationModel);
234 if([bestName isEqualToString:ringID]) {
235 ringID = @"";
236 }
237 [outgoingId setStringValue:ringID];
238 }
239
Anthony Léonard66a050c2018-01-03 16:32:34 -0500240 [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())];
Anthony Léonard66a050c2018-01-03 16:32:34 -0500241 if (refreshDurationTimer == nil)
242 refreshDurationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
243 target:self
244 selector:@selector(updateDurationLabel)
245 userInfo:nil
246 repeats:YES];
Olivier Soldano994971f2017-12-05 16:30:12 -0500247 [stateLabel setStringValue:@(to_string(currentCall.status).c_str())];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400248 [outgoingStateLabel setStringValue:@(to_string(currentCall.status).c_str())];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500249
Olivier Soldano994971f2017-12-05 16:30:12 -0500250 // Default values for this views
251 [loadingIndicator setHidden:YES];
Olivier Soldano994971f2017-12-05 16:30:12 -0500252 [ringingPanel setHidden:YES];
253 [outgoingPanel setHidden:YES];
254 [controlsPanel setHidden:NO];
255 [headerContainer setHidden:NO];
Anthony Léonard4b0935f2017-12-26 12:05:22 -0500256 [chatButton setHidden:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500257
Olivier Soldano994971f2017-12-05 16:30:12 -0500258 using Status = lrc::api::call::Status;
259 switch (currentCall.status) {
260 case Status::SEARCHING:
Olivier Soldano994971f2017-12-05 16:30:12 -0500261 case Status::CONNECTING:
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400262 [headerContainer setHidden:YES];
263 [outgoingPanel setHidden:NO];
264 [outgoingPhoto setHidden:NO];
265 [self setupContactInfo:outgoingPhoto];
Olivier Soldano994971f2017-12-05 16:30:12 -0500266 [loadingIndicator setHidden:NO];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400267 [controlsPanel setHidden:YES];
Olivier Soldano994971f2017-12-05 16:30:12 -0500268 break;
269 case Status::INCOMING_RINGING:
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400270 [outgoingPhoto setHidden:YES];
Olivier Soldano994971f2017-12-05 16:30:12 -0500271 [controlsPanel setHidden:YES];
272 [outgoingPanel setHidden:YES];
273 [self setupIncoming:callUid_];
274 break;
275 case Status::OUTGOING_RINGING:
276 [controlsPanel setHidden:YES];
277 [outgoingPanel setHidden:NO];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400278 [loadingIndicator setHidden:NO];
279 [headerContainer setHidden:YES];
Olivier Soldano994971f2017-12-05 16:30:12 -0500280 break;
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400281 /*case Status::CONFERENCE:
282 [self setupConference:currentCall];
283 break;*/
Olivier Soldano994971f2017-12-05 16:30:12 -0500284 case Status::PAUSED:
Olivier Soldano994971f2017-12-05 16:30:12 -0500285 case Status::INACTIVE:
286 case Status::IN_PROGRESS:
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400287 // change constraints (uncollapse avatar)
288 [self setupContactInfo:personPhoto];
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400289 [timeSpentLabel setHidden:NO];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400290 [outgoingPhoto setHidden:YES];
291 [headerContainer setHidden:NO];
292 break;
Olivier Soldano994971f2017-12-05 16:30:12 -0500293 case Status::CONNECTED:
Olivier Soldano994971f2017-12-05 16:30:12 -0500294 break;
295 case Status::ENDED:
296 case Status::TERMINATING:
297 case Status::INVALID:
298 [controlsPanel setHidden:YES];
299 [outgoingPanel setHidden:NO];
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400300 [self hideWithAnimation:false];
Olivier Soldano994971f2017-12-05 16:30:12 -0500301 break;
302 }
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500303
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500304}
305
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400306-(void) setupContactInfo:(NSImageView*)imageView
307{
308 auto* convModel = accountInfo_->conversationModel.get();
309 auto it = getConversationFromUid(convUid_, *convModel);
310 if (it != convModel->allFilteredConversations().end()) {
311 auto& imgManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
312 QVariant photo = imgManip.conversationPhoto(*it, *accountInfo_, QSize(120, 120), NO);
313 [imageView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
314 }
315}
316
Olivier Soldano994971f2017-12-05 16:30:12 -0500317-(void) setupIncoming:(const std::string&) callId
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500318{
Olivier Soldano994971f2017-12-05 16:30:12 -0500319 if (accountInfo_ == nil)
320 return;
321
322 auto* callModel = accountInfo_->callModel.get();
323 if (not callModel->hasCall(callUid_)) {
324 return;
325 }
326
327 auto call = callModel->getCall(callUid_);
328 auto* convModel = accountInfo_->conversationModel.get();
329
330 [ringingPanel setHidden:NO];
331 [controlsPanel setHidden:YES];
332 [headerContainer setHidden:YES];
Anthony Léonard6f819752018-01-05 09:53:40 -0500333 auto it = getConversationFromUid(convUid_, *convModel);
Olivier Soldano994971f2017-12-05 16:30:12 -0500334 if (it != convModel->allFilteredConversations().end()) {
335 auto& imgManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
336 QVariant photo = imgManip.conversationPhoto(*it, *accountInfo_);
337 [incomingPersonPhoto setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
Anthony Léonard8ee26782018-01-05 10:23:04 -0500338 [incomingDisplayName setStringValue:bestNameForConversation(*it, *convModel)];
Olivier Soldano994971f2017-12-05 16:30:12 -0500339 }
340}
341
342
343-(void) setupConference:(Call*) c
344{
345 [videoView setShouldAcceptInteractions:YES];
346 [self.chatButton setHidden:NO];
347 [joinPanel setHidden:YES];
348 [self.addParticipantButton setHidden:NO];
349 [self.transferButton setHidden:YES];
350}
351
352-(void)collapseRightView
353{
354 NSView *right = [[splitView subviews] objectAtIndex:1];
355 NSView *left = [[splitView subviews] objectAtIndex:0];
356 NSRect leftFrame = [left frame];
357 [right setHidden:YES];
358 [splitView display];
359}
360
361- (void) changeCallSelection:(std::string&)callUid
362{
363 if (accountInfo_ == nil)
364 return;
365
366 auto* callModel = accountInfo_->callModel.get();
367 if (not callModel->hasCall(callUid)) {
368 return;
369 }
370
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500371 QObject::disconnect(self.selectedCallChanged);
Olivier Soldano994971f2017-12-05 16:30:12 -0500372 self.selectedCallChanged = QObject::connect(callModel,
373 &lrc::api::NewCallModel::callStatusChanged,
374 [self](const std::string callId) {
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400375 [self updateCall];
Alexandre Lision4d9905e2016-01-22 12:01:36 -0500376 });
Alexandre Lisionc5148052015-03-04 15:10:35 -0500377}
378
379-(void) connectVideoSignals
380{
Olivier Soldano994971f2017-12-05 16:30:12 -0500381 if (accountInfo_ == nil)
382 return;
383
384 auto* callModel = accountInfo_->callModel.get();
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500385 QObject::disconnect(self.videoStarted);
Olivier Soldano994971f2017-12-05 16:30:12 -0500386 self.videoStarted = QObject::connect(callModel,
387 &lrc::api::NewCallModel::remotePreviewStarted,
388 [self](const std::string& callId, Video::Renderer* renderer) {
389 NSLog(@"Video started!");
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400390 [videoView setShouldAcceptInteractions:YES];
391 [self mouseIsMoving: NO];
Olivier Soldano994971f2017-12-05 16:30:12 -0500392 [self connectVideoRenderer:renderer];
393 });
Alexandre Lisionc5148052015-03-04 15:10:35 -0500394
Olivier Soldano994971f2017-12-05 16:30:12 -0500395 if (callModel->hasCall(callUid_)) {
396 if (auto renderer = callModel->getRenderer(callUid_)) {
397 QObject::disconnect(self.videoStarted);
398 [self connectVideoRenderer: renderer];
399 }
Alexandre Lisionc5148052015-03-04 15:10:35 -0500400 }
Alexandre Lisionc5148052015-03-04 15:10:35 -0500401 [self connectPreviewRenderer];
402
403}
404
405-(void) connectPreviewRenderer
406{
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400407 QObject::disconnect(previewHolder.frameUpdated);
408 QObject::disconnect(previewHolder.stopped);
409 QObject::disconnect(previewHolder.started);
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400410 previewHolder.started = QObject::connect(&Video::PreviewManager::instance(),
Alexandre Lisionc5148052015-03-04 15:10:35 -0500411 &Video::PreviewManager::previewStarted,
412 [=](Video::Renderer* renderer) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500413 QObject::disconnect(previewHolder.frameUpdated);
414 previewHolder.frameUpdated = QObject::connect(renderer,
415 &Video::Renderer::frameUpdated,
416 [=]() {
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400417 [self renderer:Video::PreviewManager::instance().previewRenderer()
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400418 renderFrameForPreviewView:previewView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500419 });
420 });
421
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400422 previewHolder.stopped = QObject::connect(&Video::PreviewManager::instance(),
Alexandre Lisionc5148052015-03-04 15:10:35 -0500423 &Video::PreviewManager::previewStopped,
424 [=](Video::Renderer* renderer) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500425 QObject::disconnect(previewHolder.frameUpdated);
426 [previewView.layer setContents:nil];
427 });
428
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400429 previewHolder.frameUpdated = QObject::connect(Video::PreviewManager::instance().previewRenderer(),
Alexandre Lisionc5148052015-03-04 15:10:35 -0500430 &Video::Renderer::frameUpdated,
431 [=]() {
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400432 [self renderer:Video::PreviewManager::instance().previewRenderer()
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400433 renderFrameForPreviewView:previewView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500434 });
435}
436
437-(void) connectVideoRenderer: (Video::Renderer*)renderer
438{
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400439 QObject::disconnect(videoHolder.frameUpdated);
440 QObject::disconnect(videoHolder.started);
441 QObject::disconnect(videoHolder.stopped);
Olivier Soldano994971f2017-12-05 16:30:12 -0500442
443 if(renderer == nil)
444 return;
445
Alexandre Lisionc5148052015-03-04 15:10:35 -0500446 videoHolder.frameUpdated = QObject::connect(renderer,
447 &Video::Renderer::frameUpdated,
448 [=]() {
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400449 [self renderer:renderer renderFrameForDistantView:videoView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500450 });
451
452 videoHolder.started = QObject::connect(renderer,
453 &Video::Renderer::started,
454 [=]() {
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400455 [self mouseIsMoving: NO];
456 [videoView setShouldAcceptInteractions:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500457 QObject::disconnect(videoHolder.frameUpdated);
458 videoHolder.frameUpdated = QObject::connect(renderer,
459 &Video::Renderer::frameUpdated,
460 [=]() {
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400461 [self renderer:renderer renderFrameForDistantView:videoView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500462 });
463 });
464
465 videoHolder.stopped = QObject::connect(renderer,
466 &Video::Renderer::stopped,
467 [=]() {
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400468 [self mouseIsMoving: YES];
469 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500470 QObject::disconnect(videoHolder.frameUpdated);
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400471 [(CallLayer*)videoView.layer setVideoRunning:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500472 });
473}
474
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400475-(void) renderer: (Video::Renderer*)renderer renderFrameForPreviewView:(NSView*) view
Alexandre Lisionc5148052015-03-04 15:10:35 -0500476{
Alexandre Lisionc5148052015-03-04 15:10:35 -0500477 QSize res = renderer->size();
478
Alexandre Lision6731e132015-10-14 14:29:06 -0400479 auto frame_ptr = renderer->currentFrame();
480 auto frame_data = frame_ptr.ptr;
481 if (!frame_data)
482 return;
483
Alexandre Lisionc5148052015-03-04 15:10:35 -0500484 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
Alexandre Lision6731e132015-10-14 14:29:06 -0400485 CGContextRef newContext = CGBitmapContextCreate(frame_data,
Alexandre Lisionc5148052015-03-04 15:10:35 -0500486 res.width(),
487 res.height(),
488 8,
489 4*res.width(),
490 colorSpace,
491 kCGImageAlphaPremultipliedLast);
492
493
494 CGImageRef newImage = CGBitmapContextCreateImage(newContext);
495
496 /*We release some components*/
497 CGContextRelease(newContext);
498 CGColorSpaceRelease(colorSpace);
499
500 [CATransaction begin];
501 view.layer.contents = (__bridge id)newImage;
502 [CATransaction commit];
503
504 CFRelease(newImage);
505}
506
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400507-(void) renderer: (Video::Renderer*)renderer renderFrameForDistantView:(CallView*) view
508{
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400509 auto frame_ptr = renderer->currentFrame();
510 if (!frame_ptr.ptr)
511 return;
512
513 CallLayer* callLayer = (CallLayer*) view.layer;
514
Anthony Léonarda9d7c8e2018-01-03 14:41:17 -0500515 [callLayer setCurrentFrame:std::move(frame_ptr)];
Anthony Léonard14e7bf32017-06-08 08:13:16 -0400516 [callLayer setVideoRunning:YES];
517}
518
Alexandre Lisionc5148052015-03-04 15:10:35 -0500519- (void) initFrame
520{
521 [self.view setFrame:self.view.superview.bounds];
522 [self.view setHidden:YES];
523 self.view.layer.position = self.view.frame.origin;
Alexandre Lisionbb5dbcd2015-07-09 16:36:47 -0400524 [self collapseRightView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500525}
526
527# pragma private IN/OUT animations
528
Olivier Soldano994971f2017-12-05 16:30:12 -0500529-(void)uncollapseRightView
530{
531 NSView *left = [[splitView subviews] objectAtIndex:0];
532 NSView *right = [[splitView subviews] objectAtIndex:1];
533 [right setHidden:NO];
534
535 CGFloat dividerThickness = [splitView dividerThickness];
536
537 // get the different frames
538 NSRect leftFrame = [left frame];
539 NSRect rightFrame = [right frame];
540
541 leftFrame.size.width = (leftFrame.size.width - rightFrame.size.width - dividerThickness);
542 rightFrame.origin.x = leftFrame.size.width + dividerThickness;
543 [left setFrameSize:leftFrame.size];
544 [right setFrame:rightFrame];
545 [splitView display];
546
547 [self.chatVC takeFocus];
548}
549
Alexandre Lisionc5148052015-03-04 15:10:35 -0500550-(void) cleanUp
551{
Anthony Léonard5c287642018-02-21 15:54:19 -0500552 if(self.splitView.isInFullScreenMode)
553 [self.splitView exitFullScreenModeWithOptions:nil];
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400554 QObject::disconnect(videoHolder.frameUpdated);
555 QObject::disconnect(videoHolder.started);
556 QObject::disconnect(videoHolder.stopped);
557 QObject::disconnect(previewHolder.frameUpdated);
558 QObject::disconnect(previewHolder.stopped);
559 QObject::disconnect(previewHolder.started);
Anthony Léonardc0013bb2018-02-20 16:23:02 -0500560 QObject::disconnect(self.messageConnection);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500561 [previewView.layer setContents:nil];
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400562 [(CallLayer*)videoView.layer setVideoRunning:NO];
Alexandre Lision883719f2015-10-22 17:37:45 -0400563
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500564 [_brokerPopoverVC performClose:self];
Alexandre Lision883719f2015-10-22 17:37:45 -0400565 [self.addToContactPopover performClose:self];
Alexandre Lision0e66aea2015-11-02 16:36:30 -0500566
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500567 [self.chatButton setHidden:YES];
568 [self.addParticipantButton setHidden:YES];
569 [self.transferButton setHidden:YES];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400570 [self.qualityButton setHidden:YES];
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500571
Alexandre Lision4baba4c2016-02-11 13:00:57 -0500572 [self.chatButton setPressed:NO];
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500573 [self.mergeCallsButton setState:NSOffState];
Alexandre Lision883719f2015-10-22 17:37:45 -0400574 [self collapseRightView];
Alexandre Lision57227772016-01-15 17:19:36 -0500575
576 [personLabel setStringValue:@""];
577 [timeSpentLabel setStringValue:@""];
578 [stateLabel setStringValue:@""];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400579
580 [outgoingPersonLabel setStringValue:@""];
581 [outgoingStateLabel setStringValue:@""];
Alexandre Lision62005312016-01-28 15:55:16 -0500582
583 [advancedButton setPressed:NO];
584 [advancedPanel setHidden:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500585}
586
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400587-(void) setupCallView
588{
589 if (accountInfo_ == nil)
590 return;
591
592 auto* callModel = accountInfo_->callModel.get();
593 auto* convModel = accountInfo_->conversationModel.get();
594
595 // when call comes in we want to show the controls/header
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400596 [self mouseIsMoving: YES];
597 [videoView setShouldAcceptInteractions: NO];
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400598
599 [self connectVideoSignals];
600 /* check if text media is already present */
601 if(not callModel->hasCall(callUid_))
602 return;
603
604 [loadingIndicator setAnimates:YES];
Andreas Traczyk77a50d52018-05-08 17:47:31 -0400605 [self updateCall];
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400606
607 /* monitor media for messaging text messaging */
608 QObject::disconnect(self.messageConnection);
609 self.messageConnection = QObject::connect(convModel,
610 &lrc::api::ConversationModel::interactionStatusUpdated,
611 [self] (std::string convUid,
612 uint64_t msgId,
613 lrc::api::interaction::Info msg) {
614 if (msg.type == lrc::api::interaction::Type::TEXT) {
615 if(not [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]){
616 return;
617 }
618 [self uncollapseRightView];
619 }
620 });
621}
622
623-(void) showWithAnimation:(BOOL)animate
624{
625 if (!animate) {
626 [self.view setHidden:NO];
627 [self setupCallView];
628 return;
629 }
630
631 CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0);
632 [self.view setHidden:NO];
633
634 [CATransaction begin];
635 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
636 [animation setFromValue:[NSValue valueWithPoint:frame.origin]];
637 [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]];
638 [animation setDuration:0.2f];
639 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
640 [CATransaction setCompletionBlock:^{
641 [self setupCallView];
642 }];
643
644 [self.view.layer addAnimation:animation forKey:animation.keyPath];
645 [CATransaction commit];
646}
647
648-(void) hideWithAnimation:(BOOL)animate
Alexandre Lisionc5148052015-03-04 15:10:35 -0500649{
Alexandre Lisionc5148052015-03-04 15:10:35 -0500650 if(self.view.frame.origin.x < 0) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500651 return;
652 }
653
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400654 if (!animate) {
Kateryna Kostiuk1004caa2018-03-29 13:48:07 -0400655 [self cleanUp];
Andreas Traczykecdc4fa2018-03-22 16:11:47 -0400656 [self.view setHidden:YES];
657 return;
658 }
659
Alexandre Lisionc5148052015-03-04 15:10:35 -0500660 CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0);
661 [CATransaction begin];
662 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
663 [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]];
664 [animation setToValue:[NSValue valueWithPoint:frame.origin]];
665 [animation setDuration:0.2f];
Alexandre Lision22d615b2016-01-25 12:54:34 -0500666 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500667
668 [CATransaction setCompletionBlock:^{
669 [self.view setHidden:YES];
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400670 // first make sure everything is disconnected
Alexandre Lisionc5148052015-03-04 15:10:35 -0500671 [self cleanUp];
Olivier Soldano994971f2017-12-05 16:30:12 -0500672// if (currentCall_) {
673// [self animateIn];
674// }
Alexandre Lisionc5148052015-03-04 15:10:35 -0500675 }];
676 [self.view.layer addAnimation:animation forKey:animation.keyPath];
Alexandre Lisiona1c6d752015-06-23 12:27:38 -0400677
678 [self.view.layer setPosition:frame.origin];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500679 [CATransaction commit];
680}
681
682/**
683 * Debug purpose
684 */
685-(void) dumpFrame:(CGRect) frame WithName:(NSString*) name
686{
687 NSLog(@"frame %@ : %f %f %f %f \n\n",name ,frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
688}
689
Alexandre Lision58cab672015-06-09 15:25:40 -0400690#pragma mark - Button methods
691
Alexandre Lisionc5148052015-03-04 15:10:35 -0500692- (IBAction)hangUp:(id)sender {
Olivier Soldano994971f2017-12-05 16:30:12 -0500693 if (accountInfo_ == nil)
694 return;
695
696 auto* callModel = accountInfo_->callModel.get();
697
698 callModel->hangUp(callUid_);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500699}
700
701- (IBAction)accept:(id)sender {
Olivier Soldano994971f2017-12-05 16:30:12 -0500702 if (accountInfo_ == nil)
703 return;
704
Anthony Léonardf584cc52018-01-19 12:00:19 -0500705 // If we accept a conversation with a non trusted contact, we first accept it
706 auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel.get());
707 if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) {
708 auto& contact = accountInfo_->contactModel->getContact(convIt->participants[0]);
709 if (contact.profileInfo.type == lrc::api::profile::Type::PENDING)
710 accountInfo_->conversationModel->makePermanent(convUid_);
711 }
712
Olivier Soldano994971f2017-12-05 16:30:12 -0500713 auto* callModel = accountInfo_->callModel.get();
714
715 callModel->accept(callUid_);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500716}
717
718- (IBAction)toggleRecording:(id)sender {
Olivier Soldano994971f2017-12-05 16:30:12 -0500719 if (accountInfo_ == nil)
720 return;
721
722 auto* callModel = accountInfo_->callModel.get();
723
724 callModel->toggleAudioRecord(callUid_);
Kateryna Kostiuk54d76972018-06-07 15:45:07 -0400725 [recordOnOffButton setPressed:!recordOnOffButton.isPressed];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500726}
727
728- (IBAction)toggleHold:(id)sender {
Olivier Soldano994971f2017-12-05 16:30:12 -0500729 if (accountInfo_ == nil)
730 return;
731
732 auto* callModel = accountInfo_->callModel.get();
Kateryna Kostiuk54d76972018-06-07 15:45:07 -0400733 auto currentCall = callModel->getCall(callUid_);
734 if (currentCall.status != lrc::api::call::Status::PAUSED) {
735 holdOnOffButton.image = [NSImage imageNamed:@"ic_action_holdoff.png"];
736 } else {
737 holdOnOffButton.image = [NSImage imageNamed:@"ic_action_hold.png"];
738 }
Olivier Soldano994971f2017-12-05 16:30:12 -0500739
740 callModel->togglePause(callUid_);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500741}
742
Alexandre Lision62005312016-01-28 15:55:16 -0500743- (IBAction)toggleAdvancedControls:(id)sender {
744 [advancedButton setPressed:!advancedButton.isPressed];
745 [advancedPanel setHidden:![advancedButton isPressed]];
746}
747
748- (IBAction)showDialpad:(id)sender {
749 AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
750 [appDelegate showDialpad];
751}
752
Alexandre Lision58cab672015-06-09 15:25:40 -0400753-(IBAction)toggleChat:(id)sender;
754{
755 BOOL rightViewCollapsed = [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]];
756 if (rightViewCollapsed) {
757 [self uncollapseRightView];
Alexandre Lision58cab672015-06-09 15:25:40 -0400758 } else {
759 [self collapseRightView];
760 }
Alexandre Lision62005312016-01-28 15:55:16 -0500761 [chatButton setPressed:rightViewCollapsed];
Alexandre Lision58cab672015-06-09 15:25:40 -0400762}
763
Alexandre Lisiond18fa272015-06-15 11:18:03 -0400764- (IBAction)muteAudio:(id)sender
765{
Olivier Soldano994971f2017-12-05 16:30:12 -0500766 if (accountInfo_ == nil)
767 return;
768
769 auto* callModel = accountInfo_->callModel.get();
Kateryna Kostiuk54d76972018-06-07 15:45:07 -0400770 auto currentCall = callModel->getCall(callUid_);
771 if (currentCall.audioMuted) {
772 muteAudioButton.image = [NSImage imageNamed:@"ic_action_audio.png"];
773 } else {
774 muteAudioButton.image = [NSImage imageNamed:@"ic_action_mute_audio.png"];
775 }
Olivier Soldano994971f2017-12-05 16:30:12 -0500776 callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::AUDIO);
Alexandre Lisiond18fa272015-06-15 11:18:03 -0400777}
778
779- (IBAction)muteVideo:(id)sender
780{
Olivier Soldano994971f2017-12-05 16:30:12 -0500781 if (accountInfo_ == nil)
782 return;
Olivier Soldano994971f2017-12-05 16:30:12 -0500783 auto* callModel = accountInfo_->callModel.get();
Kateryna Kostiuk54d76972018-06-07 15:45:07 -0400784 auto currentCall = callModel->getCall(callUid_);
785 if(!currentCall.isAudioOnly) {
786 if (currentCall.videoMuted) {
787 muteVideoButton.image = [NSImage imageNamed:@"ic_action_video.png"];
788 } else {
789 muteVideoButton.image = [NSImage imageNamed:@"ic_action_mute_video.png"];
790 }
791 }
Olivier Soldano994971f2017-12-05 16:30:12 -0500792 callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::VIDEO);
Alexandre Lisiond18fa272015-06-15 11:18:03 -0400793}
Alexandre Lision883719f2015-10-22 17:37:45 -0400794
795- (IBAction)toggleTransferView:(id)sender {
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500796 if (_brokerPopoverVC != nullptr) {
797 [_brokerPopoverVC performClose:self];
798 _brokerPopoverVC = NULL;
Alexandre Lision62005312016-01-28 15:55:16 -0500799 [self.transferButton setPressed:NO];
Alexandre Lision883719f2015-10-22 17:37:45 -0400800 } else {
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500801 auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::TRANSFER];
802 _brokerPopoverVC = [[NSPopover alloc] init];
803 [_brokerPopoverVC setContentSize:brokerVC.view.frame.size];
804 [_brokerPopoverVC setContentViewController:brokerVC];
805 [_brokerPopoverVC setAnimates:YES];
806 [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient];
807 [_brokerPopoverVC setDelegate:self];
808 [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
Alexandre Lision883719f2015-10-22 17:37:45 -0400809 [videoView setCallDelegate:nil];
810 }
Alexandre Lisionf23ec5a2015-07-16 11:24:06 -0400811}
Alexandre Lisiond18fa272015-06-15 11:18:03 -0400812
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500813- (IBAction)toggleAddParticipantView:(id)sender {
814 if (_brokerPopoverVC != nullptr) {
815 [_brokerPopoverVC performClose:self];
816 _brokerPopoverVC = NULL;
Alexandre Lision62005312016-01-28 15:55:16 -0500817 [self.addParticipantButton setPressed:NO];
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500818 } else {
819 auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::CONFERENCE];
820 _brokerPopoverVC = [[NSPopover alloc] init];
821 [_brokerPopoverVC setContentSize:brokerVC.view.frame.size];
822 [_brokerPopoverVC setContentViewController:brokerVC];
823 [_brokerPopoverVC setAnimates:YES];
824 [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient];
825 [_brokerPopoverVC setDelegate:self];
826 [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
827 [videoView setCallDelegate:nil];
828 }
829}
830
831/**
832 * Merge current call with its parent call
833 */
834- (IBAction)mergeCalls:(id)sender
835{
Olivier Soldano994971f2017-12-05 16:30:12 -0500836// auto current = CallModel::instance().selectedCall();
837// current->joinToParent();
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500838}
839
Alexandre Lision2db8f472015-07-22 15:05:46 -0400840#pragma mark - NSPopOverDelegate
841
Alexandre Lision266fca02015-09-28 14:47:05 -0400842- (void)popoverWillClose:(NSNotification *)notification
843{
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500844 if (_brokerPopoverVC != nullptr) {
845 [_brokerPopoverVC performClose:self];
846 _brokerPopoverVC = NULL;
Alexandre Lision883719f2015-10-22 17:37:45 -0400847 }
Alexandre Lision266fca02015-09-28 14:47:05 -0400848
Alexandre Lision2db8f472015-07-22 15:05:46 -0400849 if (self.addToContactPopover != nullptr) {
850 [self.addToContactPopover performClose:self];
851 self.addToContactPopover = NULL;
852 }
Alexandre Lision883719f2015-10-22 17:37:45 -0400853
Alexandre Lision62005312016-01-28 15:55:16 -0500854 [self.transferButton setPressed:NO];
Alexandre Lision89edc6a2015-11-09 11:30:47 -0500855 [self.addParticipantButton setState:NSOffState];
Alexandre Lision883719f2015-10-22 17:37:45 -0400856}
857
858- (void)popoverDidClose:(NSNotification *)notification
859{
860 [videoView setCallDelegate:self];
Alexandre Lision2db8f472015-07-22 15:05:46 -0400861}
862
863#pragma mark - ContactLinkedDelegate
864
865- (void)contactLinked
866{
867 if (self.addToContactPopover != nullptr) {
868 [self.addToContactPopover performClose:self];
869 self.addToContactPopover = NULL;
870 }
871}
872
Alexandre Lision58cab672015-06-09 15:25:40 -0400873#pragma mark - NSSplitViewDelegate
874
875/* 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.
876 */
877- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex;
878{
879 NSView* rightView = [[splitView subviews] objectAtIndex:1];
880 return ([subview isEqual:rightView]);
881}
882
883
884- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview;
885{
886 NSView* rightView = [[splitView subviews] objectAtIndex:1];
887 return ([subview isEqual:rightView]);
888}
889
890
Alexandre Lisiona1eee3c2015-08-10 13:44:51 -0400891# pragma mark - CallnDelegate
Alexandre Lision58cab672015-06-09 15:25:40 -0400892
893- (void) callShouldToggleFullScreen
894{
895 if(self.splitView.isInFullScreenMode)
896 [self.splitView exitFullScreenModeWithOptions:nil];
897 else {
898 NSApplicationPresentationOptions options = NSApplicationPresentationDefault +NSApplicationPresentationAutoHideDock +
899 NSApplicationPresentationAutoHideMenuBar + NSApplicationPresentationAutoHideToolbar;
900 NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:options],
901 NSFullScreenModeApplicationPresentationOptions, nil];
902
903 [self.splitView enterFullScreenMode:[NSScreen mainScreen] withOptions:opts];
904 }
905}
906
Alexandre Lisiona1eee3c2015-08-10 13:44:51 -0400907-(void) mouseIsMoving:(BOOL) move
908{
909 [[controlsPanel animator] setAlphaValue:move]; // fade out
910 [[headerContainer animator] setAlphaValue:move];
911}
912
Alexandre Lisionc5148052015-03-04 15:10:35 -0500913@end