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