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