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