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())); |
Anthony Léonard | 8ee2678 | 2018-01-05 10:23:04 -0500 | [diff] [blame] | 216 | auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel); |
| 217 | if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) |
| 218 | [personLabel setStringValue:bestNameForConversation(*convIt, *accountInfo_->conversationModel)]; |
Anthony Léonard | 66a050c | 2018-01-03 16:32:34 -0500 | [diff] [blame] | 219 | [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())]; |
| 220 | [timeSpentLabel setHidden:NO]; |
| 221 | if (refreshDurationTimer == nil) |
| 222 | refreshDurationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 |
| 223 | target:self |
| 224 | selector:@selector(updateDurationLabel) |
| 225 | userInfo:nil |
| 226 | repeats:YES]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 227 | [stateLabel setStringValue:@(to_string(currentCall.status).c_str())]; |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 228 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 229 | if (firstRun) { |
| 230 | //QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(current, QSize(100,100)); |
| 231 | //[personPhoto setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))]; |
| 232 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 233 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 234 | // Default values for this views |
| 235 | [loadingIndicator setHidden:YES]; |
| 236 | [videoView setShouldAcceptInteractions:NO]; |
| 237 | [ringingPanel setHidden:YES]; |
| 238 | [outgoingPanel setHidden:YES]; |
| 239 | [controlsPanel setHidden:NO]; |
| 240 | [headerContainer setHidden:NO]; |
Anthony Léonard | 4b0935f | 2017-12-26 12:05:22 -0500 | [diff] [blame] | 241 | [chatButton setHidden:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 242 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 243 | using Status = lrc::api::call::Status; |
| 244 | switch (currentCall.status) { |
| 245 | case Status::SEARCHING: |
| 246 | case Status::OUTGOING_REQUESTED: |
| 247 | case Status::CONNECTING: |
| 248 | [loadingIndicator setHidden:NO]; |
| 249 | break; |
| 250 | case Status::INCOMING_RINGING: |
| 251 | [controlsPanel setHidden:YES]; |
| 252 | [outgoingPanel setHidden:YES]; |
| 253 | [self setupIncoming:callUid_]; |
| 254 | break; |
| 255 | case Status::OUTGOING_RINGING: |
| 256 | [controlsPanel setHidden:YES]; |
| 257 | [outgoingPanel setHidden:NO]; |
| 258 | break; |
| 259 | // case Status::CONFERENCE: |
| 260 | // [self setupConference:currentCall]; |
| 261 | // break; |
| 262 | case Status::PAUSED: |
| 263 | case Status::PEER_PAUSED: |
| 264 | case Status::INACTIVE: |
| 265 | case Status::IN_PROGRESS: |
| 266 | case Status::CONNECTED: |
| 267 | case Status::AUTO_ANSWERING: |
| 268 | break; |
| 269 | case Status::ENDED: |
| 270 | case Status::TERMINATING: |
| 271 | case Status::INVALID: |
| 272 | [controlsPanel setHidden:YES]; |
| 273 | [outgoingPanel setHidden:NO]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 274 | [self hideWithAnimation:false]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 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))]; |
Anthony Léonard | 8ee2678 | 2018-01-05 10:23:04 -0500 | [diff] [blame] | 301 | [incomingDisplayName setStringValue:bestNameForConversation(*it, *convModel)]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 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) cleanUp |
| 508 | { |
Anthony Léonard | 5c28764 | 2018-02-21 15:54:19 -0500 | [diff] [blame] | 509 | if(self.splitView.isInFullScreenMode) |
| 510 | [self.splitView exitFullScreenModeWithOptions:nil]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 511 | QObject::disconnect(videoHolder.frameUpdated); |
| 512 | QObject::disconnect(videoHolder.started); |
| 513 | QObject::disconnect(videoHolder.stopped); |
| 514 | QObject::disconnect(previewHolder.frameUpdated); |
| 515 | QObject::disconnect(previewHolder.stopped); |
| 516 | QObject::disconnect(previewHolder.started); |
Anthony Léonard | c0013bb | 2018-02-20 16:23:02 -0500 | [diff] [blame] | 517 | QObject::disconnect(self.messageConnection); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 518 | [previewView.layer setContents:nil]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 519 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 520 | [_brokerPopoverVC performClose:self]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 521 | [self.addToContactPopover performClose:self]; |
Alexandre Lision | 0e66aea | 2015-11-02 16:36:30 -0500 | [diff] [blame] | 522 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 523 | [self.chatButton setHidden:YES]; |
| 524 | [self.addParticipantButton setHidden:YES]; |
| 525 | [self.transferButton setHidden:YES]; |
| 526 | |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 527 | [self.chatButton setPressed:NO]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 528 | [self.mergeCallsButton setState:NSOffState]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 529 | [self collapseRightView]; |
Alexandre Lision | 5722777 | 2016-01-15 17:19:36 -0500 | [diff] [blame] | 530 | |
| 531 | [personLabel setStringValue:@""]; |
| 532 | [timeSpentLabel setStringValue:@""]; |
| 533 | [stateLabel setStringValue:@""]; |
| 534 | [self.addContactButton setHidden:YES]; |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 535 | |
| 536 | [advancedButton setPressed:NO]; |
| 537 | [advancedPanel setHidden:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 538 | } |
| 539 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 540 | -(void) setupCallView |
| 541 | { |
| 542 | if (accountInfo_ == nil) |
| 543 | return; |
| 544 | |
| 545 | auto* callModel = accountInfo_->callModel.get(); |
| 546 | auto* convModel = accountInfo_->conversationModel.get(); |
| 547 | |
| 548 | // when call comes in we want to show the controls/header |
| 549 | [self mouseIsMoving:YES]; |
| 550 | |
| 551 | [self connectVideoSignals]; |
| 552 | /* check if text media is already present */ |
| 553 | if(not callModel->hasCall(callUid_)) |
| 554 | return; |
| 555 | |
| 556 | [loadingIndicator setAnimates:YES]; |
| 557 | [self updateCall:YES]; |
| 558 | |
| 559 | /* monitor media for messaging text messaging */ |
| 560 | QObject::disconnect(self.messageConnection); |
| 561 | self.messageConnection = QObject::connect(convModel, |
| 562 | &lrc::api::ConversationModel::interactionStatusUpdated, |
| 563 | [self] (std::string convUid, |
| 564 | uint64_t msgId, |
| 565 | lrc::api::interaction::Info msg) { |
| 566 | if (msg.type == lrc::api::interaction::Type::TEXT) { |
| 567 | if(not [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]){ |
| 568 | return; |
| 569 | } |
| 570 | [self uncollapseRightView]; |
| 571 | } |
| 572 | }); |
| 573 | } |
| 574 | |
| 575 | -(void) showWithAnimation:(BOOL)animate |
| 576 | { |
| 577 | if (!animate) { |
| 578 | [self.view setHidden:NO]; |
| 579 | [self setupCallView]; |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0); |
| 584 | [self.view setHidden:NO]; |
| 585 | |
| 586 | [CATransaction begin]; |
| 587 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 588 | [animation setFromValue:[NSValue valueWithPoint:frame.origin]]; |
| 589 | [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]]; |
| 590 | [animation setDuration:0.2f]; |
| 591 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; |
| 592 | [CATransaction setCompletionBlock:^{ |
| 593 | [self setupCallView]; |
| 594 | }]; |
| 595 | |
| 596 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 597 | [CATransaction commit]; |
| 598 | } |
| 599 | |
| 600 | -(void) hideWithAnimation:(BOOL)animate |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 601 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 602 | if(self.view.frame.origin.x < 0) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 603 | return; |
| 604 | } |
| 605 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 606 | if (!animate) { |
| 607 | [self.view setHidden:YES]; |
| 608 | return; |
| 609 | } |
| 610 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 611 | CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0); |
| 612 | [CATransaction begin]; |
| 613 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 614 | [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]]; |
| 615 | [animation setToValue:[NSValue valueWithPoint:frame.origin]]; |
| 616 | [animation setDuration:0.2f]; |
Alexandre Lision | 22d615b | 2016-01-25 12:54:34 -0500 | [diff] [blame] | 617 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 618 | |
| 619 | [CATransaction setCompletionBlock:^{ |
| 620 | [self.view setHidden:YES]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 621 | // first make sure everything is disconnected |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 622 | [self cleanUp]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 623 | // if (currentCall_) { |
| 624 | // [self animateIn]; |
| 625 | // } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 626 | }]; |
| 627 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 628 | |
| 629 | [self.view.layer setPosition:frame.origin]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 630 | [CATransaction commit]; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Debug purpose |
| 635 | */ |
| 636 | -(void) dumpFrame:(CGRect) frame WithName:(NSString*) name |
| 637 | { |
| 638 | NSLog(@"frame %@ : %f %f %f %f \n\n",name ,frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); |
| 639 | } |
| 640 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 641 | #pragma mark - Button methods |
| 642 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 643 | - (IBAction)hangUp:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 644 | if (accountInfo_ == nil) |
| 645 | return; |
| 646 | |
| 647 | auto* callModel = accountInfo_->callModel.get(); |
| 648 | |
| 649 | callModel->hangUp(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | - (IBAction)accept:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 653 | if (accountInfo_ == nil) |
| 654 | return; |
| 655 | |
Anthony Léonard | f584cc5 | 2018-01-19 12:00:19 -0500 | [diff] [blame] | 656 | // If we accept a conversation with a non trusted contact, we first accept it |
| 657 | auto convIt = getConversationFromUid(convUid_, *accountInfo_->conversationModel.get()); |
| 658 | if (convIt != accountInfo_->conversationModel->allFilteredConversations().end()) { |
| 659 | auto& contact = accountInfo_->contactModel->getContact(convIt->participants[0]); |
| 660 | if (contact.profileInfo.type == lrc::api::profile::Type::PENDING) |
| 661 | accountInfo_->conversationModel->makePermanent(convUid_); |
| 662 | } |
| 663 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 664 | auto* callModel = accountInfo_->callModel.get(); |
| 665 | |
| 666 | callModel->accept(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | - (IBAction)toggleRecording:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 670 | if (accountInfo_ == nil) |
| 671 | return; |
| 672 | |
| 673 | auto* callModel = accountInfo_->callModel.get(); |
| 674 | |
| 675 | callModel->toggleAudioRecord(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | - (IBAction)toggleHold:(id)sender { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 679 | if (accountInfo_ == nil) |
| 680 | return; |
| 681 | |
| 682 | auto* callModel = accountInfo_->callModel.get(); |
| 683 | |
| 684 | callModel->togglePause(callUid_); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 685 | } |
| 686 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 687 | - (IBAction)toggleAdvancedControls:(id)sender { |
| 688 | [advancedButton setPressed:!advancedButton.isPressed]; |
| 689 | [advancedPanel setHidden:![advancedButton isPressed]]; |
| 690 | } |
| 691 | |
| 692 | - (IBAction)showDialpad:(id)sender { |
| 693 | AppDelegate* appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate]; |
| 694 | [appDelegate showDialpad]; |
| 695 | } |
| 696 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 697 | -(IBAction)toggleChat:(id)sender; |
| 698 | { |
| 699 | BOOL rightViewCollapsed = [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]; |
| 700 | if (rightViewCollapsed) { |
| 701 | [self uncollapseRightView]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 702 | } else { |
| 703 | [self collapseRightView]; |
| 704 | } |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 705 | [chatButton setPressed:rightViewCollapsed]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 706 | } |
| 707 | |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 708 | - (IBAction)muteAudio:(id)sender |
| 709 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 710 | if (accountInfo_ == nil) |
| 711 | return; |
| 712 | |
| 713 | auto* callModel = accountInfo_->callModel.get(); |
| 714 | |
| 715 | callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::AUDIO); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | - (IBAction)muteVideo:(id)sender |
| 719 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 720 | if (accountInfo_ == nil) |
| 721 | return; |
| 722 | |
| 723 | auto* callModel = accountInfo_->callModel.get(); |
| 724 | |
| 725 | callModel->toggleMedia(callUid_, lrc::api::NewCallModel::Media::VIDEO); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 726 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 727 | |
| 728 | - (IBAction)toggleTransferView:(id)sender { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 729 | if (_brokerPopoverVC != nullptr) { |
| 730 | [_brokerPopoverVC performClose:self]; |
| 731 | _brokerPopoverVC = NULL; |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 732 | [self.transferButton setPressed:NO]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 733 | } else { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 734 | auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::TRANSFER]; |
| 735 | _brokerPopoverVC = [[NSPopover alloc] init]; |
| 736 | [_brokerPopoverVC setContentSize:brokerVC.view.frame.size]; |
| 737 | [_brokerPopoverVC setContentViewController:brokerVC]; |
| 738 | [_brokerPopoverVC setAnimates:YES]; |
| 739 | [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient]; |
| 740 | [_brokerPopoverVC setDelegate:self]; |
| 741 | [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 742 | [videoView setCallDelegate:nil]; |
| 743 | } |
Alexandre Lision | f23ec5a | 2015-07-16 11:24:06 -0400 | [diff] [blame] | 744 | } |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 745 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 746 | - (IBAction)toggleAddParticipantView:(id)sender { |
| 747 | if (_brokerPopoverVC != nullptr) { |
| 748 | [_brokerPopoverVC performClose:self]; |
| 749 | _brokerPopoverVC = NULL; |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 750 | [self.addParticipantButton setPressed:NO]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 751 | } else { |
| 752 | auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::CONFERENCE]; |
| 753 | _brokerPopoverVC = [[NSPopover alloc] init]; |
| 754 | [_brokerPopoverVC setContentSize:brokerVC.view.frame.size]; |
| 755 | [_brokerPopoverVC setContentViewController:brokerVC]; |
| 756 | [_brokerPopoverVC setAnimates:YES]; |
| 757 | [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient]; |
| 758 | [_brokerPopoverVC setDelegate:self]; |
| 759 | [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge]; |
| 760 | [videoView setCallDelegate:nil]; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Merge current call with its parent call |
| 766 | */ |
| 767 | - (IBAction)mergeCalls:(id)sender |
| 768 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 769 | // auto current = CallModel::instance().selectedCall(); |
| 770 | // current->joinToParent(); |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 771 | } |
| 772 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 773 | #pragma mark - NSPopOverDelegate |
| 774 | |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 775 | - (void)popoverWillClose:(NSNotification *)notification |
| 776 | { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 777 | if (_brokerPopoverVC != nullptr) { |
| 778 | [_brokerPopoverVC performClose:self]; |
| 779 | _brokerPopoverVC = NULL; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 780 | } |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 781 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 782 | if (self.addToContactPopover != nullptr) { |
| 783 | [self.addToContactPopover performClose:self]; |
| 784 | self.addToContactPopover = NULL; |
| 785 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 786 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 787 | [self.addContactButton setPressed:NO]; |
| 788 | [self.transferButton setPressed:NO]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 789 | [self.addParticipantButton setState:NSOffState]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | - (void)popoverDidClose:(NSNotification *)notification |
| 793 | { |
| 794 | [videoView setCallDelegate:self]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | #pragma mark - ContactLinkedDelegate |
| 798 | |
| 799 | - (void)contactLinked |
| 800 | { |
| 801 | if (self.addToContactPopover != nullptr) { |
| 802 | [self.addToContactPopover performClose:self]; |
| 803 | self.addToContactPopover = NULL; |
| 804 | } |
| 805 | } |
| 806 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 807 | #pragma mark - NSSplitViewDelegate |
| 808 | |
| 809 | /* 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. |
| 810 | */ |
| 811 | - (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex; |
| 812 | { |
| 813 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 814 | return ([subview isEqual:rightView]); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; |
| 819 | { |
| 820 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 821 | return ([subview isEqual:rightView]); |
| 822 | } |
| 823 | |
| 824 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 825 | # pragma mark - CallnDelegate |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 826 | |
| 827 | - (void) callShouldToggleFullScreen |
| 828 | { |
| 829 | if(self.splitView.isInFullScreenMode) |
| 830 | [self.splitView exitFullScreenModeWithOptions:nil]; |
| 831 | else { |
| 832 | NSApplicationPresentationOptions options = NSApplicationPresentationDefault +NSApplicationPresentationAutoHideDock + |
| 833 | NSApplicationPresentationAutoHideMenuBar + NSApplicationPresentationAutoHideToolbar; |
| 834 | NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:options], |
| 835 | NSFullScreenModeApplicationPresentationOptions, nil]; |
| 836 | |
| 837 | [self.splitView enterFullScreenMode:[NSScreen mainScreen] withOptions:opts]; |
| 838 | } |
| 839 | } |
| 840 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 841 | -(void) mouseIsMoving:(BOOL) move |
| 842 | { |
| 843 | [[controlsPanel animator] setAlphaValue:move]; // fade out |
| 844 | [[headerContainer animator] setAlphaValue:move]; |
| 845 | } |
| 846 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 847 | @end |