Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 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. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | #import "CurrentCallVC.h" |
| 31 | |
| 32 | #import <QuartzCore/QuartzCore.h> |
| 33 | |
| 34 | #import <call.h> |
| 35 | #import <callmodel.h> |
| 36 | #import <useractionmodel.h> |
| 37 | #import <contactmethod.h> |
| 38 | #import <qabstractitemmodel.h> |
| 39 | #import <QItemSelectionModel> |
| 40 | #import <QItemSelection> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 41 | #import <video/previewmanager.h> |
| 42 | #import <video/renderer.h> |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 43 | #import <media/text.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 44 | |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 45 | #import "views/ITProgressIndicator.h" |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 46 | #import "views/CallView.h" |
| 47 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 48 | @interface RendererConnectionsHolder : NSObject |
| 49 | |
| 50 | @property QMetaObject::Connection frameUpdated; |
| 51 | @property QMetaObject::Connection started; |
| 52 | @property QMetaObject::Connection stopped; |
| 53 | |
| 54 | @end |
| 55 | |
| 56 | @implementation RendererConnectionsHolder |
| 57 | |
| 58 | @end |
| 59 | |
| 60 | @interface CurrentCallVC () |
| 61 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 62 | @property (unsafe_unretained) IBOutlet NSTextField *personLabel; |
| 63 | @property (unsafe_unretained) IBOutlet NSTextField *stateLabel; |
| 64 | @property (unsafe_unretained) IBOutlet NSButton *holdOnOffButton; |
| 65 | @property (unsafe_unretained) IBOutlet NSButton *hangUpButton; |
| 66 | @property (unsafe_unretained) IBOutlet NSButton *recordOnOffButton; |
| 67 | @property (unsafe_unretained) IBOutlet NSButton *pickUpButton; |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 68 | @property (unsafe_unretained) IBOutlet NSButton *muteAudioButton; |
| 69 | @property (unsafe_unretained) IBOutlet NSButton *muteVideoButton; |
| 70 | |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 71 | @property (unsafe_unretained) IBOutlet ITProgressIndicator *loadingIndicator; |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 72 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 73 | @property (unsafe_unretained) IBOutlet NSTextField *timeSpentLabel; |
| 74 | @property (unsafe_unretained) IBOutlet NSView *controlsPanel; |
| 75 | @property (unsafe_unretained) IBOutlet NSSplitView *splitView; |
| 76 | @property (unsafe_unretained) IBOutlet NSButton *chatButton; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 77 | |
| 78 | @property QHash<int, NSButton*> actionHash; |
| 79 | |
| 80 | // Video |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 81 | @property (unsafe_unretained) IBOutlet CallView *videoView; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 82 | @property CALayer* videoLayer; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 83 | @property (unsafe_unretained) IBOutlet NSView *previewView; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 84 | @property CALayer* previewLayer; |
| 85 | |
| 86 | @property RendererConnectionsHolder* previewHolder; |
| 87 | @property RendererConnectionsHolder* videoHolder; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 88 | @property QMetaObject::Connection videoStarted; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 89 | |
| 90 | @end |
| 91 | |
| 92 | @implementation CurrentCallVC |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 93 | @synthesize personLabel, actionHash, stateLabel, holdOnOffButton, hangUpButton, |
| 94 | recordOnOffButton, pickUpButton, chatButton, timeSpentLabel, |
| 95 | muteVideoButton, muteAudioButton, controlsPanel, videoView, |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 96 | videoLayer, previewLayer, previewView, splitView, loadingIndicator; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 97 | |
| 98 | @synthesize previewHolder; |
| 99 | @synthesize videoHolder; |
| 100 | |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 101 | - (void) updateAllActions |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 102 | { |
| 103 | for(int i = 0 ; i <= CallModel::instance()->userActionModel()->rowCount() ; i++) { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 104 | [self updateActionAtIndex:i]; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | - (void) updateActionAtIndex:(int) row |
| 109 | { |
| 110 | const QModelIndex& idx = CallModel::instance()->userActionModel()->index(row,0); |
| 111 | UserActionModel::Action action = qvariant_cast<UserActionModel::Action>(idx.data(UserActionModel::Role::ACTION)); |
| 112 | NSButton* a = actionHash[(int) action]; |
| 113 | if (a != nil) { |
| 114 | [a setEnabled:(idx.flags() & Qt::ItemIsEnabled)]; |
| 115 | [a setState:(idx.data(Qt::CheckStateRole) == Qt::Checked) ? NSOnState : NSOffState]; |
| 116 | |
| 117 | if(action == UserActionModel::Action::HOLD) { |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 118 | NSString* imgName = (a.state == NSOnState ? @"ic_action_holdoff" : @"ic_action_hold"); |
| 119 | [a setImage:[NSImage imageNamed:imgName]]; |
| 120 | |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 121 | } |
| 122 | if(action == UserActionModel::Action::RECORD) { |
| 123 | [a setTitle:(a.state == NSOnState ? @"Record off" : @"Record")]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | -(void) updateCall |
| 129 | { |
| 130 | QModelIndex callIdx = CallModel::instance()->selectionModel()->currentIndex(); |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 131 | [personLabel setStringValue:callIdx.data(Qt::DisplayRole).toString().toNSString()]; |
| 132 | [timeSpentLabel setStringValue:callIdx.data((int)Call::Role::Length).toString().toNSString()]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 133 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 134 | Call::State state = callIdx.data((int)Call::Role::State).value<Call::State>(); |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 135 | [loadingIndicator setHidden:YES]; |
| 136 | [stateLabel setStringValue:callIdx.data((int)Call::Role::HumanStateName).toString().toNSString()]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 137 | switch (state) { |
Alexandre Lision | e6dbf09 | 2015-04-11 17:19:35 -0400 | [diff] [blame] | 138 | case Call::State::DIALING: |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 139 | [loadingIndicator setHidden:NO]; |
Alexandre Lision | e6dbf09 | 2015-04-11 17:19:35 -0400 | [diff] [blame] | 140 | break; |
| 141 | case Call::State::NEW: |
Alexandre Lision | e6dbf09 | 2015-04-11 17:19:35 -0400 | [diff] [blame] | 142 | break; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 143 | case Call::State::INITIALIZATION: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 144 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 145 | [loadingIndicator setHidden:NO]; |
| 146 | break; |
| 147 | case Call::State::CONNECTED: |
| 148 | [videoView setShouldAcceptInteractions:NO]; |
| 149 | [loadingIndicator setHidden:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 150 | break; |
| 151 | case Call::State::RINGING: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 152 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 153 | break; |
| 154 | case Call::State::CURRENT: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 155 | [videoView setShouldAcceptInteractions:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 156 | break; |
| 157 | case Call::State::HOLD: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 158 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 159 | break; |
| 160 | case Call::State::BUSY: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 161 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 162 | break; |
| 163 | case Call::State::OVER: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 164 | [videoView setShouldAcceptInteractions:NO]; |
| 165 | if(videoView.isInFullScreenMode) |
| 166 | [videoView exitFullScreenModeWithOptions:nil]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 167 | break; |
| 168 | case Call::State::FAILURE: |
Alexandre Lision | 74dd47f | 2015-04-14 13:47:42 -0400 | [diff] [blame] | 169 | [videoView setShouldAcceptInteractions:NO]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 170 | break; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | - (void)awakeFromNib |
| 176 | { |
| 177 | NSLog(@"INIT CurrentCall VC"); |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 178 | [self.view setWantsLayer:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 179 | [self.view setLayer:[CALayer layer]]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 180 | |
| 181 | [controlsPanel setWantsLayer:YES]; |
| 182 | [controlsPanel setLayer:[CALayer layer]]; |
| 183 | [controlsPanel.layer setZPosition:2.0]; |
| 184 | [controlsPanel.layer setBackgroundColor:[NSColor whiteColor].CGColor]; |
| 185 | |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 186 | actionHash[ (int)UserActionModel::Action::ACCEPT] = pickUpButton; |
| 187 | actionHash[ (int)UserActionModel::Action::HOLD ] = holdOnOffButton; |
| 188 | actionHash[ (int)UserActionModel::Action::RECORD] = recordOnOffButton; |
| 189 | actionHash[ (int)UserActionModel::Action::HANGUP] = hangUpButton; |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 190 | actionHash[ (int)UserActionModel::Action::MUTE_AUDIO] = muteAudioButton; |
| 191 | actionHash[ (int)UserActionModel::Action::MUTE_VIDEO] = muteVideoButton; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 192 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 193 | videoLayer = [CALayer layer]; |
| 194 | [videoView setWantsLayer:YES]; |
| 195 | [videoView setLayer:videoLayer]; |
| 196 | [videoView.layer setBackgroundColor:[NSColor blackColor].CGColor]; |
| 197 | [videoView.layer setFrame:videoView.frame]; |
| 198 | [videoView.layer setContentsGravity:kCAGravityResizeAspect]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 199 | |
| 200 | previewLayer = [CALayer layer]; |
| 201 | [previewView setWantsLayer:YES]; |
| 202 | [previewView setLayer:previewLayer]; |
| 203 | [previewLayer setBackgroundColor:[NSColor blackColor].CGColor]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 204 | [previewLayer setContentsGravity:kCAGravityResizeAspectFill]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 205 | [previewLayer setFrame:previewView.frame]; |
| 206 | |
| 207 | [controlsPanel setWantsLayer:YES]; |
| 208 | [controlsPanel setLayer:[CALayer layer]]; |
| 209 | [controlsPanel.layer setBackgroundColor:[NSColor clearColor].CGColor]; |
| 210 | [controlsPanel.layer setFrame:controlsPanel.frame]; |
| 211 | |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 212 | previewHolder = [[RendererConnectionsHolder alloc] init]; |
| 213 | videoHolder = [[RendererConnectionsHolder alloc] init]; |
| 214 | |
Alexandre Lision | f47a256 | 2015-06-15 15:48:29 -0400 | [diff] [blame^] | 215 | [loadingIndicator setColor:[NSColor whiteColor]]; |
| 216 | [loadingIndicator setNumberOfLines:100]; |
| 217 | [loadingIndicator setWidthOfLine:2]; |
| 218 | [loadingIndicator setLengthOfLine:2]; |
| 219 | [loadingIndicator setInnerMargin:30]; |
| 220 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 221 | [self.videoView setFullScreenDelegate:self]; |
| 222 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 223 | [self connect]; |
| 224 | } |
| 225 | |
| 226 | - (void) connect |
| 227 | { |
| 228 | QObject::connect(CallModel::instance()->selectionModel(), |
| 229 | &QItemSelectionModel::currentChanged, |
| 230 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 231 | if(!current.isValid()) { |
| 232 | [self animateOut]; |
| 233 | return; |
| 234 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 235 | [self collapseRightView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 236 | [self updateCall]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 237 | [self updateAllActions]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 238 | [self animateOut]; |
| 239 | }); |
| 240 | |
| 241 | QObject::connect(CallModel::instance(), |
| 242 | &QAbstractItemModel::dataChanged, |
| 243 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 244 | [self updateCall]; |
| 245 | }); |
| 246 | |
| 247 | QObject::connect(CallModel::instance()->userActionModel(), |
| 248 | &QAbstractItemModel::dataChanged, |
| 249 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 250 | const int first(topLeft.row()),last(bottomRight.row()); |
| 251 | for(int i = first; i <= last;i++) { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 252 | [self updateActionAtIndex:i]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 253 | } |
| 254 | }); |
| 255 | |
| 256 | QObject::connect(CallModel::instance(), |
| 257 | &CallModel::callStateChanged, |
| 258 | [self](Call* c, Call::State state) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 259 | [self updateCall]; |
| 260 | }); |
| 261 | } |
| 262 | |
| 263 | -(void) connectVideoSignals |
| 264 | { |
| 265 | QModelIndex idx = CallModel::instance()->selectionModel()->currentIndex(); |
| 266 | Call* call = CallModel::instance()->getCall(idx); |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 267 | self.videoStarted = QObject::connect(call, |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 268 | &Call::videoStarted, |
| 269 | [=](Video::Renderer* renderer) { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 270 | NSLog(@"Video started!"); |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 271 | [self connectVideoRenderer:renderer]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 272 | }); |
| 273 | |
| 274 | if(call->videoRenderer()) |
| 275 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 276 | [self connectVideoRenderer:call->videoRenderer()]; |
| 277 | } |
| 278 | |
| 279 | [self connectPreviewRenderer]; |
| 280 | |
| 281 | } |
| 282 | |
| 283 | -(void) connectPreviewRenderer |
| 284 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 285 | QObject::disconnect(previewHolder.frameUpdated); |
| 286 | QObject::disconnect(previewHolder.stopped); |
| 287 | QObject::disconnect(previewHolder.started); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 288 | previewHolder.started = QObject::connect(Video::PreviewManager::instance(), |
| 289 | &Video::PreviewManager::previewStarted, |
| 290 | [=](Video::Renderer* renderer) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 291 | QObject::disconnect(previewHolder.frameUpdated); |
| 292 | previewHolder.frameUpdated = QObject::connect(renderer, |
| 293 | &Video::Renderer::frameUpdated, |
| 294 | [=]() { |
| 295 | [self renderer:Video::PreviewManager::instance()->previewRenderer() |
| 296 | renderFrameForView:previewView]; |
| 297 | }); |
| 298 | }); |
| 299 | |
| 300 | previewHolder.stopped = QObject::connect(Video::PreviewManager::instance(), |
| 301 | &Video::PreviewManager::previewStopped, |
| 302 | [=](Video::Renderer* renderer) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 303 | QObject::disconnect(previewHolder.frameUpdated); |
| 304 | [previewView.layer setContents:nil]; |
| 305 | }); |
| 306 | |
| 307 | previewHolder.frameUpdated = QObject::connect(Video::PreviewManager::instance()->previewRenderer(), |
| 308 | &Video::Renderer::frameUpdated, |
| 309 | [=]() { |
| 310 | [self renderer:Video::PreviewManager::instance()->previewRenderer() |
| 311 | renderFrameForView:previewView]; |
| 312 | }); |
| 313 | } |
| 314 | |
| 315 | -(void) connectVideoRenderer: (Video::Renderer*)renderer |
| 316 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 317 | QObject::disconnect(videoHolder.frameUpdated); |
| 318 | QObject::disconnect(videoHolder.started); |
| 319 | QObject::disconnect(videoHolder.stopped); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 320 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 321 | &Video::Renderer::frameUpdated, |
| 322 | [=]() { |
| 323 | [self renderer:renderer renderFrameForView:videoView]; |
| 324 | }); |
| 325 | |
| 326 | videoHolder.started = QObject::connect(renderer, |
| 327 | &Video::Renderer::started, |
| 328 | [=]() { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 329 | QObject::disconnect(videoHolder.frameUpdated); |
| 330 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 331 | &Video::Renderer::frameUpdated, |
| 332 | [=]() { |
| 333 | [self renderer:renderer renderFrameForView:videoView]; |
| 334 | }); |
| 335 | }); |
| 336 | |
| 337 | videoHolder.stopped = QObject::connect(renderer, |
| 338 | &Video::Renderer::stopped, |
| 339 | [=]() { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 340 | QObject::disconnect(videoHolder.frameUpdated); |
| 341 | [videoView.layer setContents:nil]; |
| 342 | }); |
| 343 | } |
| 344 | |
| 345 | -(void) renderer: (Video::Renderer*)renderer renderFrameForView:(NSView*) view |
| 346 | { |
| 347 | const QByteArray& data = renderer->currentFrame(); |
| 348 | QSize res = renderer->size(); |
| 349 | |
| 350 | auto buf = reinterpret_cast<const unsigned char*>(data.data()); |
| 351 | |
| 352 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 353 | CGContextRef newContext = CGBitmapContextCreate((void *)buf, |
| 354 | res.width(), |
| 355 | res.height(), |
| 356 | 8, |
| 357 | 4*res.width(), |
| 358 | colorSpace, |
| 359 | kCGImageAlphaPremultipliedLast); |
| 360 | |
| 361 | |
| 362 | CGImageRef newImage = CGBitmapContextCreateImage(newContext); |
| 363 | |
| 364 | /*We release some components*/ |
| 365 | CGContextRelease(newContext); |
| 366 | CGColorSpaceRelease(colorSpace); |
| 367 | |
| 368 | [CATransaction begin]; |
| 369 | view.layer.contents = (__bridge id)newImage; |
| 370 | [CATransaction commit]; |
| 371 | |
| 372 | CFRelease(newImage); |
| 373 | } |
| 374 | |
| 375 | - (void) initFrame |
| 376 | { |
| 377 | [self.view setFrame:self.view.superview.bounds]; |
| 378 | [self.view setHidden:YES]; |
| 379 | self.view.layer.position = self.view.frame.origin; |
| 380 | } |
| 381 | |
| 382 | # pragma private IN/OUT animations |
| 383 | |
| 384 | -(void) animateIn |
| 385 | { |
| 386 | NSLog(@"animateIn"); |
| 387 | CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0); |
| 388 | [self.view setHidden:NO]; |
| 389 | |
| 390 | [CATransaction begin]; |
| 391 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 392 | [animation setFromValue:[NSValue valueWithPoint:frame.origin]]; |
| 393 | [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]]; |
| 394 | [animation setDuration:0.2f]; |
| 395 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 396 | [CATransaction setCompletionBlock:^{ |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 397 | [self connectVideoSignals]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 398 | }]; |
| 399 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 400 | |
| 401 | [CATransaction commit]; |
| 402 | } |
| 403 | |
| 404 | -(void) cleanUp |
| 405 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 406 | QObject::disconnect(videoHolder.frameUpdated); |
| 407 | QObject::disconnect(videoHolder.started); |
| 408 | QObject::disconnect(videoHolder.stopped); |
| 409 | QObject::disconnect(previewHolder.frameUpdated); |
| 410 | QObject::disconnect(previewHolder.stopped); |
| 411 | QObject::disconnect(previewHolder.started); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 412 | [videoView.layer setContents:nil]; |
| 413 | [previewView.layer setContents:nil]; |
| 414 | } |
| 415 | |
| 416 | -(void) animateOut |
| 417 | { |
| 418 | NSLog(@"animateOut"); |
| 419 | if(self.view.frame.origin.x < 0) { |
| 420 | NSLog(@"Already hidden"); |
| 421 | if (CallModel::instance()->selectionModel()->currentIndex().isValid()) { |
| 422 | [self animateIn]; |
| 423 | } |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0); |
| 428 | [CATransaction begin]; |
| 429 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 430 | [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]]; |
| 431 | [animation setToValue:[NSValue valueWithPoint:frame.origin]]; |
| 432 | [animation setDuration:0.2f]; |
| 433 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 434 | |
| 435 | [CATransaction setCompletionBlock:^{ |
| 436 | [self.view setHidden:YES]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 437 | // first make sure everything is disconnected |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 438 | [self cleanUp]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 439 | if (CallModel::instance()->selectionModel()->currentIndex().isValid()) { |
| 440 | [self animateIn]; |
| 441 | } |
| 442 | }]; |
| 443 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 444 | [CATransaction commit]; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Debug purpose |
| 449 | */ |
| 450 | -(void) dumpFrame:(CGRect) frame WithName:(NSString*) name |
| 451 | { |
| 452 | NSLog(@"frame %@ : %f %f %f %f \n\n",name ,frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); |
| 453 | } |
| 454 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 455 | -(void)collapseRightView |
| 456 | { |
| 457 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 458 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 459 | NSRect leftFrame = [left frame]; |
| 460 | [right setHidden:YES]; |
| 461 | [splitView display]; |
| 462 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 463 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 464 | -(void)uncollapseRightView |
| 465 | { |
| 466 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 467 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 468 | [right setHidden:NO]; |
| 469 | |
| 470 | CGFloat dividerThickness = [splitView dividerThickness]; |
| 471 | |
| 472 | // get the different frames |
| 473 | NSRect leftFrame = [left frame]; |
| 474 | NSRect rightFrame = [right frame]; |
| 475 | |
| 476 | leftFrame.size.width = (leftFrame.size.width - rightFrame.size.width - dividerThickness); |
| 477 | rightFrame.origin.x = leftFrame.size.width + dividerThickness; |
| 478 | [left setFrameSize:leftFrame.size]; |
| 479 | [right setFrame:rightFrame]; |
| 480 | [splitView display]; |
| 481 | } |
| 482 | |
| 483 | |
| 484 | #pragma mark - Button methods |
| 485 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 486 | - (IBAction)hangUp:(id)sender { |
| 487 | CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::REFUSE; |
| 488 | } |
| 489 | |
| 490 | - (IBAction)accept:(id)sender { |
| 491 | CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::ACCEPT; |
| 492 | } |
| 493 | |
| 494 | - (IBAction)toggleRecording:(id)sender { |
Alexandre Lision | 6664343 | 2015-06-04 11:59:36 -0400 | [diff] [blame] | 495 | CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::RECORD_AUDIO; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | - (IBAction)toggleHold:(id)sender { |
| 499 | CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::HOLD; |
| 500 | } |
| 501 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 502 | -(IBAction)toggleChat:(id)sender; |
| 503 | { |
| 504 | BOOL rightViewCollapsed = [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]; |
| 505 | if (rightViewCollapsed) { |
| 506 | [self uncollapseRightView]; |
| 507 | CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex())->addOutgoingMedia<Media::Text>(); |
| 508 | } else { |
| 509 | [self collapseRightView]; |
| 510 | } |
| 511 | [chatButton setState:rightViewCollapsed]; |
| 512 | } |
| 513 | |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 514 | - (IBAction)muteAudio:(id)sender |
| 515 | { |
| 516 | UserActionModel* uam = CallModel::instance()->userActionModel(); |
| 517 | uam << UserActionModel::Action::MUTE_AUDIO; |
| 518 | } |
| 519 | |
| 520 | - (IBAction)muteVideo:(id)sender |
| 521 | { |
| 522 | UserActionModel* uam = CallModel::instance()->userActionModel(); |
| 523 | uam << UserActionModel::Action::MUTE_VIDEO; |
| 524 | } |
| 525 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 526 | #pragma mark - NSSplitViewDelegate |
| 527 | |
| 528 | /* 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. |
| 529 | */ |
| 530 | - (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex; |
| 531 | { |
| 532 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 533 | return ([subview isEqual:rightView]); |
| 534 | } |
| 535 | |
| 536 | |
| 537 | - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; |
| 538 | { |
| 539 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 540 | return ([subview isEqual:rightView]); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | # pragma mark - FullScreenDelegate |
| 545 | |
| 546 | - (void) callShouldToggleFullScreen |
| 547 | { |
| 548 | if(self.splitView.isInFullScreenMode) |
| 549 | [self.splitView exitFullScreenModeWithOptions:nil]; |
| 550 | else { |
| 551 | NSApplicationPresentationOptions options = NSApplicationPresentationDefault +NSApplicationPresentationAutoHideDock + |
| 552 | NSApplicationPresentationAutoHideMenuBar + NSApplicationPresentationAutoHideToolbar; |
| 553 | NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:options], |
| 554 | NSFullScreenModeApplicationPresentationOptions, nil]; |
| 555 | |
| 556 | [self.splitView enterFullScreenMode:[NSScreen mainScreen] withOptions:opts]; |
| 557 | } |
| 558 | } |
| 559 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 560 | @end |