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