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