blob: 7971a6fd76008be60dbd62cab41f4bd89408a78e [file] [log] [blame]
Alexandre Lisionc5148052015-03-04 15:10:35 -05001/*
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 Lisionc5148052015-03-04 15:10:35 -050041#import <video/previewmanager.h>
42#import <video/renderer.h>
Alexandre Lision58cab672015-06-09 15:25:40 -040043#import <media/text.h>
Alexandre Lisionc5148052015-03-04 15:10:35 -050044
Alexandre Lisionf47a2562015-06-15 15:48:29 -040045#import "views/ITProgressIndicator.h"
Alexandre Lision74dd47f2015-04-14 13:47:42 -040046#import "views/CallView.h"
47
Alexandre Lisionc5148052015-03-04 15:10:35 -050048@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 Lision58cab672015-06-09 15:25:40 -040062@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 Lisiond18fa272015-06-15 11:18:03 -040068@property (unsafe_unretained) IBOutlet NSButton *muteAudioButton;
69@property (unsafe_unretained) IBOutlet NSButton *muteVideoButton;
70
Alexandre Lisionf47a2562015-06-15 15:48:29 -040071@property (unsafe_unretained) IBOutlet ITProgressIndicator *loadingIndicator;
Alexandre Lisiond18fa272015-06-15 11:18:03 -040072
Alexandre Lision58cab672015-06-09 15:25:40 -040073@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 Lisionc5148052015-03-04 15:10:35 -050077
78@property QHash<int, NSButton*> actionHash;
79
80// Video
Alexandre Lision58cab672015-06-09 15:25:40 -040081@property (unsafe_unretained) IBOutlet CallView *videoView;
Alexandre Lisionc5148052015-03-04 15:10:35 -050082@property CALayer* videoLayer;
Alexandre Lision58cab672015-06-09 15:25:40 -040083@property (unsafe_unretained) IBOutlet NSView *previewView;
Alexandre Lisionc5148052015-03-04 15:10:35 -050084@property CALayer* previewLayer;
85
86@property RendererConnectionsHolder* previewHolder;
87@property RendererConnectionsHolder* videoHolder;
Alexandre Lisionef6333a2015-03-24 12:30:31 -040088@property QMetaObject::Connection videoStarted;
Alexandre Lisionc5148052015-03-04 15:10:35 -050089
90@end
91
92@implementation CurrentCallVC
Alexandre Lisiond18fa272015-06-15 11:18:03 -040093@synthesize personLabel, actionHash, stateLabel, holdOnOffButton, hangUpButton,
94 recordOnOffButton, pickUpButton, chatButton, timeSpentLabel,
95 muteVideoButton, muteAudioButton, controlsPanel, videoView,
Alexandre Lisionf47a2562015-06-15 15:48:29 -040096 videoLayer, previewLayer, previewView, splitView, loadingIndicator;
Alexandre Lisionc5148052015-03-04 15:10:35 -050097
98@synthesize previewHolder;
99@synthesize videoHolder;
100
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400101- (void) updateAllActions
Alexandre Lisionc5148052015-03-04 15:10:35 -0500102{
103 for(int i = 0 ; i <= CallModel::instance()->userActionModel()->rowCount() ; i++) {
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400104 [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 Lisiond18fa272015-06-15 11:18:03 -0400118 NSString* imgName = (a.state == NSOnState ? @"ic_action_holdoff" : @"ic_action_hold");
119 [a setImage:[NSImage imageNamed:imgName]];
120
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400121 }
122 if(action == UserActionModel::Action::RECORD) {
123 [a setTitle:(a.state == NSOnState ? @"Record off" : @"Record")];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500124 }
125 }
126}
127
128-(void) updateCall
129{
130 QModelIndex callIdx = CallModel::instance()->selectionModel()->currentIndex();
Alexandre Lision58cab672015-06-09 15:25:40 -0400131 [personLabel setStringValue:callIdx.data(Qt::DisplayRole).toString().toNSString()];
132 [timeSpentLabel setStringValue:callIdx.data((int)Call::Role::Length).toString().toNSString()];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500133
Alexandre Lision58cab672015-06-09 15:25:40 -0400134 Call::State state = callIdx.data((int)Call::Role::State).value<Call::State>();
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400135 [loadingIndicator setHidden:YES];
136 [stateLabel setStringValue:callIdx.data((int)Call::Role::HumanStateName).toString().toNSString()];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500137 switch (state) {
Alexandre Lisione6dbf092015-04-11 17:19:35 -0400138 case Call::State::DIALING:
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400139 [loadingIndicator setHidden:NO];
Alexandre Lisione6dbf092015-04-11 17:19:35 -0400140 break;
141 case Call::State::NEW:
Alexandre Lisione6dbf092015-04-11 17:19:35 -0400142 break;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500143 case Call::State::INITIALIZATION:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400144 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400145 [loadingIndicator setHidden:NO];
146 break;
147 case Call::State::CONNECTED:
148 [videoView setShouldAcceptInteractions:NO];
149 [loadingIndicator setHidden:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500150 break;
151 case Call::State::RINGING:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400152 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500153 break;
154 case Call::State::CURRENT:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400155 [videoView setShouldAcceptInteractions:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500156 break;
157 case Call::State::HOLD:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400158 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500159 break;
160 case Call::State::BUSY:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400161 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500162 break;
163 case Call::State::OVER:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400164 [videoView setShouldAcceptInteractions:NO];
165 if(videoView.isInFullScreenMode)
166 [videoView exitFullScreenModeWithOptions:nil];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500167 break;
168 case Call::State::FAILURE:
Alexandre Lision74dd47f2015-04-14 13:47:42 -0400169 [videoView setShouldAcceptInteractions:NO];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500170 break;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500171 }
172
173}
174
175- (void)awakeFromNib
176{
177 NSLog(@"INIT CurrentCall VC");
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400178 [self.view setWantsLayer:YES];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500179 [self.view setLayer:[CALayer layer]];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500180
181 [controlsPanel setWantsLayer:YES];
182 [controlsPanel setLayer:[CALayer layer]];
183 [controlsPanel.layer setZPosition:2.0];
184 [controlsPanel.layer setBackgroundColor:[NSColor whiteColor].CGColor];
185
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400186 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 Lisiond18fa272015-06-15 11:18:03 -0400190 actionHash[ (int)UserActionModel::Action::MUTE_AUDIO] = muteAudioButton;
191 actionHash[ (int)UserActionModel::Action::MUTE_VIDEO] = muteVideoButton;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500192
Alexandre Lisionc5148052015-03-04 15:10:35 -0500193 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 Lisionc5148052015-03-04 15:10:35 -0500199
200 previewLayer = [CALayer layer];
201 [previewView setWantsLayer:YES];
202 [previewView setLayer:previewLayer];
203 [previewLayer setBackgroundColor:[NSColor blackColor].CGColor];
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400204 [previewLayer setContentsGravity:kCAGravityResizeAspectFill];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500205 [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 Lisionef6333a2015-03-24 12:30:31 -0400212 previewHolder = [[RendererConnectionsHolder alloc] init];
213 videoHolder = [[RendererConnectionsHolder alloc] init];
214
Alexandre Lisionf47a2562015-06-15 15:48:29 -0400215 [loadingIndicator setColor:[NSColor whiteColor]];
216 [loadingIndicator setNumberOfLines:100];
217 [loadingIndicator setWidthOfLine:2];
218 [loadingIndicator setLengthOfLine:2];
219 [loadingIndicator setInnerMargin:30];
220
Alexandre Lision58cab672015-06-09 15:25:40 -0400221 [self.videoView setFullScreenDelegate:self];
222
Alexandre Lisionc5148052015-03-04 15:10:35 -0500223 [self connect];
224}
225
226- (void) connect
227{
228 QObject::connect(CallModel::instance()->selectionModel(),
229 &QItemSelectionModel::currentChanged,
230 [=](const QModelIndex &current, const QModelIndex &previous) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500231 if(!current.isValid()) {
232 [self animateOut];
233 return;
234 }
Alexandre Lision58cab672015-06-09 15:25:40 -0400235 [self collapseRightView];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500236 [self updateCall];
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400237 [self updateAllActions];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500238 [self animateOut];
239 });
240
241 QObject::connect(CallModel::instance(),
242 &QAbstractItemModel::dataChanged,
243 [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500244 [self updateCall];
245 });
246
247 QObject::connect(CallModel::instance()->userActionModel(),
248 &QAbstractItemModel::dataChanged,
249 [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500250 const int first(topLeft.row()),last(bottomRight.row());
251 for(int i = first; i <= last;i++) {
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400252 [self updateActionAtIndex:i];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500253 }
254 });
255
256 QObject::connect(CallModel::instance(),
257 &CallModel::callStateChanged,
258 [self](Call* c, Call::State state) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500259 [self updateCall];
260 });
261}
262
263-(void) connectVideoSignals
264{
265 QModelIndex idx = CallModel::instance()->selectionModel()->currentIndex();
266 Call* call = CallModel::instance()->getCall(idx);
Alexandre Lision58cab672015-06-09 15:25:40 -0400267 self.videoStarted = QObject::connect(call,
Alexandre Lisionc5148052015-03-04 15:10:35 -0500268 &Call::videoStarted,
269 [=](Video::Renderer* renderer) {
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400270 NSLog(@"Video started!");
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400271 [self connectVideoRenderer:renderer];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500272 });
273
274 if(call->videoRenderer())
275 {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500276 [self connectVideoRenderer:call->videoRenderer()];
277 }
278
279 [self connectPreviewRenderer];
280
281}
282
283-(void) connectPreviewRenderer
284{
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400285 QObject::disconnect(previewHolder.frameUpdated);
286 QObject::disconnect(previewHolder.stopped);
287 QObject::disconnect(previewHolder.started);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500288 previewHolder.started = QObject::connect(Video::PreviewManager::instance(),
289 &Video::PreviewManager::previewStarted,
290 [=](Video::Renderer* renderer) {
Alexandre Lisionc5148052015-03-04 15:10:35 -0500291 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 Lisionc5148052015-03-04 15:10:35 -0500303 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 Lisionef6333a2015-03-24 12:30:31 -0400317 QObject::disconnect(videoHolder.frameUpdated);
318 QObject::disconnect(videoHolder.started);
319 QObject::disconnect(videoHolder.stopped);
Alexandre Lisionc5148052015-03-04 15:10:35 -0500320 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 Lisionc5148052015-03-04 15:10:35 -0500329 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 Lisionc5148052015-03-04 15:10:35 -0500340 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 Lisionc5148052015-03-04 15:10:35 -0500397 [self connectVideoSignals];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500398 }];
399 [self.view.layer addAnimation:animation forKey:animation.keyPath];
400
401 [CATransaction commit];
402}
403
404-(void) cleanUp
405{
Alexandre Lisionef6333a2015-03-24 12:30:31 -0400406 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 Lisionc5148052015-03-04 15:10:35 -0500412 [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 Lisionef6333a2015-03-24 12:30:31 -0400437 // first make sure everything is disconnected
Alexandre Lisionc5148052015-03-04 15:10:35 -0500438 [self cleanUp];
Alexandre Lisionc5148052015-03-04 15:10:35 -0500439 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 Lision58cab672015-06-09 15:25:40 -0400455-(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 Lisionc5148052015-03-04 15:10:35 -0500463
Alexandre Lision58cab672015-06-09 15:25:40 -0400464-(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 Lisionc5148052015-03-04 15:10:35 -0500486- (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 Lision66643432015-06-04 11:59:36 -0400495 CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::RECORD_AUDIO;
Alexandre Lisionc5148052015-03-04 15:10:35 -0500496}
497
498- (IBAction)toggleHold:(id)sender {
499 CallModel::instance()->getCall(CallModel::instance()->selectionModel()->currentIndex()) << Call::Action::HOLD;
500}
501
Alexandre Lision58cab672015-06-09 15:25:40 -0400502-(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 Lisiond18fa272015-06-15 11:18:03 -0400514- (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 Lision58cab672015-06-09 15:25:40 -0400526#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 Lisionc5148052015-03-04 15:10:35 -0500560@end