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