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