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 | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame^] | 127 | [a setHighlighted:(idx.data(Qt::CheckStateRole) == Qt::Checked) ? YES : NO]; |
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 | return; |
| 249 | } |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 250 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 251 | CallModel::instance().selectCall(call); |
| 252 | |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 253 | if (call->state() == Call::State::HOLD) { |
| 254 | call << Call::Action::HOLD; |
| 255 | } |
| 256 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 257 | [self collapseRightView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 258 | [self updateCall]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 259 | [self updateAllActions]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 260 | }); |
| 261 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 262 | QObject::connect(CallModel::instance().userActionModel(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 263 | &QAbstractItemModel::dataChanged, |
| 264 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 265 | const int first(topLeft.row()),last(bottomRight.row()); |
| 266 | for(int i = first; i <= last;i++) { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 267 | [self updateActionAtIndex:i]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 268 | } |
| 269 | }); |
| 270 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 271 | QObject::connect(&CallModel::instance(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 272 | &CallModel::callStateChanged, |
| 273 | [self](Call* c, Call::State state) { |
Alexandre Lision | 5722777 | 2016-01-15 17:19:36 -0500 | [diff] [blame] | 274 | auto current = CallModel::instance().selectionModel()->currentIndex(); |
| 275 | if (!current.isValid()) |
| 276 | [self animateOut]; |
| 277 | else if (CallModel::instance().getIndex(c) == current) { |
| 278 | if (c->state() == Call::State::OVER) { |
| 279 | [self animateOut]; |
| 280 | } else { |
| 281 | [self updateCall]; |
| 282 | } |
| 283 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 284 | }); |
| 285 | } |
| 286 | |
Alexandre Lision | b65c027 | 2015-07-22 15:51:29 -0400 | [diff] [blame] | 287 | - (void) monitorIncomingTextMessages:(Media::Text*) media |
| 288 | { |
| 289 | /* connect to incoming chat messages to open the chat view */ |
| 290 | QObject::disconnect(self.messageConnection); |
| 291 | self.messageConnection = QObject::connect(media, |
| 292 | &Media::Text::messageReceived, |
| 293 | [self] (const QMap<QString,QString>& m) { |
| 294 | if([[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]) |
| 295 | [self uncollapseRightView]; |
| 296 | }); |
| 297 | } |
| 298 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 299 | -(void) connectVideoSignals |
| 300 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 301 | QModelIndex idx = CallModel::instance().selectionModel()->currentIndex(); |
| 302 | Call* call = CallModel::instance().getCall(idx); |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 303 | QObject::disconnect(self.videoStarted); |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 304 | self.videoStarted = QObject::connect(call, |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 305 | &Call::videoStarted, |
| 306 | [=](Video::Renderer* renderer) { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 307 | NSLog(@"Video started!"); |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 308 | [self connectVideoRenderer:renderer]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 309 | }); |
| 310 | |
| 311 | if(call->videoRenderer()) |
| 312 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 313 | [self connectVideoRenderer:call->videoRenderer()]; |
| 314 | } |
| 315 | |
| 316 | [self connectPreviewRenderer]; |
| 317 | |
| 318 | } |
| 319 | |
| 320 | -(void) connectPreviewRenderer |
| 321 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 322 | QObject::disconnect(previewHolder.frameUpdated); |
| 323 | QObject::disconnect(previewHolder.stopped); |
| 324 | QObject::disconnect(previewHolder.started); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 325 | previewHolder.started = QObject::connect(&Video::PreviewManager::instance(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 326 | &Video::PreviewManager::previewStarted, |
| 327 | [=](Video::Renderer* renderer) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 328 | QObject::disconnect(previewHolder.frameUpdated); |
| 329 | previewHolder.frameUpdated = QObject::connect(renderer, |
| 330 | &Video::Renderer::frameUpdated, |
| 331 | [=]() { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 332 | [self renderer:Video::PreviewManager::instance().previewRenderer() |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 333 | renderFrameForView:previewView]; |
| 334 | }); |
| 335 | }); |
| 336 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 337 | previewHolder.stopped = QObject::connect(&Video::PreviewManager::instance(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 338 | &Video::PreviewManager::previewStopped, |
| 339 | [=](Video::Renderer* renderer) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 340 | QObject::disconnect(previewHolder.frameUpdated); |
| 341 | [previewView.layer setContents:nil]; |
| 342 | }); |
| 343 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 344 | previewHolder.frameUpdated = QObject::connect(Video::PreviewManager::instance().previewRenderer(), |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 345 | &Video::Renderer::frameUpdated, |
| 346 | [=]() { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 347 | [self renderer:Video::PreviewManager::instance().previewRenderer() |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 348 | renderFrameForView:previewView]; |
| 349 | }); |
| 350 | } |
| 351 | |
| 352 | -(void) connectVideoRenderer: (Video::Renderer*)renderer |
| 353 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 354 | QObject::disconnect(videoHolder.frameUpdated); |
| 355 | QObject::disconnect(videoHolder.started); |
| 356 | QObject::disconnect(videoHolder.stopped); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 357 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 358 | &Video::Renderer::frameUpdated, |
| 359 | [=]() { |
| 360 | [self renderer:renderer renderFrameForView:videoView]; |
| 361 | }); |
| 362 | |
| 363 | videoHolder.started = QObject::connect(renderer, |
| 364 | &Video::Renderer::started, |
| 365 | [=]() { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 366 | QObject::disconnect(videoHolder.frameUpdated); |
| 367 | videoHolder.frameUpdated = QObject::connect(renderer, |
| 368 | &Video::Renderer::frameUpdated, |
| 369 | [=]() { |
| 370 | [self renderer:renderer renderFrameForView:videoView]; |
| 371 | }); |
| 372 | }); |
| 373 | |
| 374 | videoHolder.stopped = QObject::connect(renderer, |
| 375 | &Video::Renderer::stopped, |
| 376 | [=]() { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 377 | QObject::disconnect(videoHolder.frameUpdated); |
| 378 | [videoView.layer setContents:nil]; |
| 379 | }); |
| 380 | } |
| 381 | |
| 382 | -(void) renderer: (Video::Renderer*)renderer renderFrameForView:(NSView*) view |
| 383 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 384 | QSize res = renderer->size(); |
| 385 | |
Alexandre Lision | 6731e13 | 2015-10-14 14:29:06 -0400 | [diff] [blame] | 386 | auto frame_ptr = renderer->currentFrame(); |
| 387 | auto frame_data = frame_ptr.ptr; |
| 388 | if (!frame_data) |
| 389 | return; |
| 390 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 391 | |
| 392 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
Alexandre Lision | 6731e13 | 2015-10-14 14:29:06 -0400 | [diff] [blame] | 393 | CGContextRef newContext = CGBitmapContextCreate(frame_data, |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 394 | res.width(), |
| 395 | res.height(), |
| 396 | 8, |
| 397 | 4*res.width(), |
| 398 | colorSpace, |
| 399 | kCGImageAlphaPremultipliedLast); |
| 400 | |
| 401 | |
| 402 | CGImageRef newImage = CGBitmapContextCreateImage(newContext); |
| 403 | |
| 404 | /*We release some components*/ |
| 405 | CGContextRelease(newContext); |
| 406 | CGColorSpaceRelease(colorSpace); |
| 407 | |
| 408 | [CATransaction begin]; |
| 409 | view.layer.contents = (__bridge id)newImage; |
| 410 | [CATransaction commit]; |
| 411 | |
| 412 | CFRelease(newImage); |
| 413 | } |
| 414 | |
| 415 | - (void) initFrame |
| 416 | { |
| 417 | [self.view setFrame:self.view.superview.bounds]; |
| 418 | [self.view setHidden:YES]; |
| 419 | self.view.layer.position = self.view.frame.origin; |
Alexandre Lision | bb5dbcd | 2015-07-09 16:36:47 -0400 | [diff] [blame] | 420 | [self collapseRightView]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | # pragma private IN/OUT animations |
| 424 | |
| 425 | -(void) animateIn |
| 426 | { |
| 427 | NSLog(@"animateIn"); |
| 428 | CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0); |
| 429 | [self.view setHidden:NO]; |
| 430 | |
| 431 | [CATransaction begin]; |
| 432 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 433 | [animation setFromValue:[NSValue valueWithPoint:frame.origin]]; |
| 434 | [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]]; |
| 435 | [animation setDuration:0.2f]; |
| 436 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 437 | [CATransaction setCompletionBlock:^{ |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 438 | |
| 439 | // when call comes in we want to show the controls/header |
| 440 | [self mouseIsMoving:YES]; |
| 441 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 442 | [self connectVideoSignals]; |
Alexandre Lision | b65c027 | 2015-07-22 15:51:29 -0400 | [diff] [blame] | 443 | /* check if text media is already present */ |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 444 | if(!CallModel::instance().selectedCall()) |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 445 | return; |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 446 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 447 | QObject::connect(CallModel::instance().selectedCall(), |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 448 | &Call::changed, |
| 449 | [=]() { |
| 450 | [self updateCall]; |
| 451 | }); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 452 | if (CallModel::instance().selectedCall()->hasMedia(Media::Media::Type::TEXT, Media::Media::Direction::IN)) { |
| 453 | 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] | 454 | [self monitorIncomingTextMessages:text]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 455 | } else if (CallModel::instance().selectedCall()->hasMedia(Media::Media::Type::TEXT, Media::Media::Direction::OUT)) { |
| 456 | 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] | 457 | [self monitorIncomingTextMessages:text]; |
| 458 | } else { |
| 459 | /* monitor media for messaging text messaging */ |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 460 | self.mediaAddedConnection = QObject::connect(CallModel::instance().selectedCall(), |
Alexandre Lision | b65c027 | 2015-07-22 15:51:29 -0400 | [diff] [blame] | 461 | &Call::mediaAdded, |
| 462 | [self] (Media::Media* media) { |
| 463 | if (media->type() == Media::Media::Type::TEXT) { [self monitorIncomingTextMessages:(Media::Text*)media]; |
| 464 | QObject::disconnect(self.mediaAddedConnection); |
| 465 | } |
| 466 | }); |
| 467 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 468 | }]; |
| 469 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 470 | |
| 471 | [CATransaction commit]; |
| 472 | } |
| 473 | |
| 474 | -(void) cleanUp |
| 475 | { |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 476 | QObject::disconnect(videoHolder.frameUpdated); |
| 477 | QObject::disconnect(videoHolder.started); |
| 478 | QObject::disconnect(videoHolder.stopped); |
| 479 | QObject::disconnect(previewHolder.frameUpdated); |
| 480 | QObject::disconnect(previewHolder.stopped); |
| 481 | QObject::disconnect(previewHolder.started); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 482 | [videoView.layer setContents:nil]; |
| 483 | [previewView.layer setContents:nil]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 484 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 485 | [_brokerPopoverVC performClose:self]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 486 | [self.addToContactPopover performClose:self]; |
Alexandre Lision | 0e66aea | 2015-11-02 16:36:30 -0500 | [diff] [blame] | 487 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 488 | [self.chatButton setHidden:YES]; |
| 489 | [self.addParticipantButton setHidden:YES]; |
| 490 | [self.transferButton setHidden:YES]; |
| 491 | |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 492 | [self.chatButton setState:NSOffState]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 493 | [self.mergeCallsButton setState:NSOffState]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 494 | [self collapseRightView]; |
Alexandre Lision | 5722777 | 2016-01-15 17:19:36 -0500 | [diff] [blame] | 495 | |
| 496 | [personLabel setStringValue:@""]; |
| 497 | [timeSpentLabel setStringValue:@""]; |
| 498 | [stateLabel setStringValue:@""]; |
| 499 | [self.addContactButton setHidden:YES]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | -(void) animateOut |
| 503 | { |
| 504 | NSLog(@"animateOut"); |
| 505 | if(self.view.frame.origin.x < 0) { |
| 506 | NSLog(@"Already hidden"); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | |
| 510 | CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0); |
| 511 | [CATransaction begin]; |
| 512 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 513 | [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]]; |
| 514 | [animation setToValue:[NSValue valueWithPoint:frame.origin]]; |
| 515 | [animation setDuration:0.2f]; |
| 516 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 517 | |
| 518 | [CATransaction setCompletionBlock:^{ |
| 519 | [self.view setHidden:YES]; |
Alexandre Lision | ef6333a | 2015-03-24 12:30:31 -0400 | [diff] [blame] | 520 | // first make sure everything is disconnected |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 521 | [self cleanUp]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 522 | if (RecentModel::instance().getActiveCall(RecentModel::instance().selectionModel()->currentIndex())) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 523 | [self animateIn]; |
| 524 | } |
| 525 | }]; |
| 526 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
Alexandre Lision | a1c6d75 | 2015-06-23 12:27:38 -0400 | [diff] [blame] | 527 | |
| 528 | [self.view.layer setPosition:frame.origin]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 529 | [CATransaction commit]; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * Debug purpose |
| 534 | */ |
| 535 | -(void) dumpFrame:(CGRect) frame WithName:(NSString*) name |
| 536 | { |
| 537 | NSLog(@"frame %@ : %f %f %f %f \n\n",name ,frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); |
| 538 | } |
| 539 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 540 | -(void)collapseRightView |
| 541 | { |
| 542 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 543 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 544 | NSRect leftFrame = [left frame]; |
| 545 | [right setHidden:YES]; |
| 546 | [splitView display]; |
| 547 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 548 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 549 | -(void)uncollapseRightView |
| 550 | { |
| 551 | NSView *left = [[splitView subviews] objectAtIndex:0]; |
| 552 | NSView *right = [[splitView subviews] objectAtIndex:1]; |
| 553 | [right setHidden:NO]; |
| 554 | |
| 555 | CGFloat dividerThickness = [splitView dividerThickness]; |
| 556 | |
| 557 | // get the different frames |
| 558 | NSRect leftFrame = [left frame]; |
| 559 | NSRect rightFrame = [right frame]; |
| 560 | |
| 561 | leftFrame.size.width = (leftFrame.size.width - rightFrame.size.width - dividerThickness); |
| 562 | rightFrame.origin.x = leftFrame.size.width + dividerThickness; |
| 563 | [left setFrameSize:leftFrame.size]; |
| 564 | [right setFrame:rightFrame]; |
| 565 | [splitView display]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 566 | |
| 567 | [self.chatVC takeFocus]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
| 571 | #pragma mark - Button methods |
| 572 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 573 | - (IBAction)addToContact:(NSButton*) sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 574 | auto contactmethod = CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex())->peerContactMethod(); |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 575 | |
| 576 | if (self.addToContactPopover != nullptr) { |
| 577 | [self.addToContactPopover performClose:self]; |
| 578 | self.addToContactPopover = NULL; |
| 579 | } else if (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder()) { |
| 580 | auto* editorVC = [[PersonLinkerVC alloc] initWithNibName:@"PersonLinker" bundle:nil]; |
| 581 | [editorVC setMethodToLink:contactmethod]; |
| 582 | [editorVC setContactLinkedDelegate:self]; |
| 583 | self.addToContactPopover = [[NSPopover alloc] init]; |
| 584 | [self.addToContactPopover setContentSize:editorVC.view.frame.size]; |
| 585 | [self.addToContactPopover setContentViewController:editorVC]; |
| 586 | [self.addToContactPopover setAnimates:YES]; |
| 587 | [self.addToContactPopover setBehavior:NSPopoverBehaviorTransient]; |
| 588 | [self.addToContactPopover setDelegate:self]; |
| 589 | |
| 590 | [self.addToContactPopover showRelativeToRect:sender.bounds ofView:sender preferredEdge:NSMaxXEdge]; |
| 591 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 592 | |
| 593 | [videoView setCallDelegate:nil]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 594 | } |
| 595 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 596 | - (IBAction)hangUp:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 597 | CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex()) << Call::Action::REFUSE; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | - (IBAction)accept:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 601 | CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex()) << Call::Action::ACCEPT; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | - (IBAction)toggleRecording:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 605 | CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex()) << Call::Action::RECORD_AUDIO; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | - (IBAction)toggleHold:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 609 | CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex()) << Call::Action::HOLD; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 610 | } |
| 611 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 612 | -(IBAction)toggleChat:(id)sender; |
| 613 | { |
| 614 | BOOL rightViewCollapsed = [[self splitView] isSubviewCollapsed:[[[self splitView] subviews] objectAtIndex: 1]]; |
| 615 | if (rightViewCollapsed) { |
| 616 | [self uncollapseRightView]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 617 | CallModel::instance().getCall(CallModel::instance().selectionModel()->currentIndex())->addOutgoingMedia<Media::Text>(); |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 618 | } else { |
| 619 | [self collapseRightView]; |
| 620 | } |
| 621 | [chatButton setState:rightViewCollapsed]; |
| 622 | } |
| 623 | |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 624 | - (IBAction)muteAudio:(id)sender |
| 625 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 626 | UserActionModel* uam = CallModel::instance().userActionModel(); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 627 | uam << UserActionModel::Action::MUTE_AUDIO; |
| 628 | } |
| 629 | |
| 630 | - (IBAction)muteVideo:(id)sender |
| 631 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 632 | UserActionModel* uam = CallModel::instance().userActionModel(); |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 633 | uam << UserActionModel::Action::MUTE_VIDEO; |
| 634 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 635 | |
| 636 | - (IBAction)toggleTransferView:(id)sender { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 637 | if (_brokerPopoverVC != nullptr) { |
| 638 | [_brokerPopoverVC performClose:self]; |
| 639 | _brokerPopoverVC = NULL; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 640 | [self.transferButton setState:NSOffState]; |
| 641 | } else { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 642 | auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::TRANSFER]; |
| 643 | _brokerPopoverVC = [[NSPopover alloc] init]; |
| 644 | [_brokerPopoverVC setContentSize:brokerVC.view.frame.size]; |
| 645 | [_brokerPopoverVC setContentViewController:brokerVC]; |
| 646 | [_brokerPopoverVC setAnimates:YES]; |
| 647 | [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient]; |
| 648 | [_brokerPopoverVC setDelegate:self]; |
| 649 | [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 650 | [videoView setCallDelegate:nil]; |
| 651 | } |
Alexandre Lision | f23ec5a | 2015-07-16 11:24:06 -0400 | [diff] [blame] | 652 | } |
Alexandre Lision | d18fa27 | 2015-06-15 11:18:03 -0400 | [diff] [blame] | 653 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 654 | - (IBAction)toggleAddParticipantView:(id)sender { |
| 655 | if (_brokerPopoverVC != nullptr) { |
| 656 | [_brokerPopoverVC performClose:self]; |
| 657 | _brokerPopoverVC = NULL; |
| 658 | [self.addParticipantButton setState:NSOffState]; |
| 659 | } else { |
| 660 | auto* brokerVC = [[BrokerVC alloc] initWithMode:BrokerMode::CONFERENCE]; |
| 661 | _brokerPopoverVC = [[NSPopover alloc] init]; |
| 662 | [_brokerPopoverVC setContentSize:brokerVC.view.frame.size]; |
| 663 | [_brokerPopoverVC setContentViewController:brokerVC]; |
| 664 | [_brokerPopoverVC setAnimates:YES]; |
| 665 | [_brokerPopoverVC setBehavior:NSPopoverBehaviorTransient]; |
| 666 | [_brokerPopoverVC setDelegate:self]; |
| 667 | [_brokerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge]; |
| 668 | [videoView setCallDelegate:nil]; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * Merge current call with its parent call |
| 674 | */ |
| 675 | - (IBAction)mergeCalls:(id)sender |
| 676 | { |
| 677 | auto current = CallModel::instance().selectedCall(); |
| 678 | current->joinToParent(); |
| 679 | } |
| 680 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 681 | #pragma mark - NSPopOverDelegate |
| 682 | |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 683 | - (void)popoverWillClose:(NSNotification *)notification |
| 684 | { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 685 | if (_brokerPopoverVC != nullptr) { |
| 686 | [_brokerPopoverVC performClose:self]; |
| 687 | _brokerPopoverVC = NULL; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 688 | } |
Alexandre Lision | 266fca0 | 2015-09-28 14:47:05 -0400 | [diff] [blame] | 689 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 690 | if (self.addToContactPopover != nullptr) { |
| 691 | [self.addToContactPopover performClose:self]; |
| 692 | self.addToContactPopover = NULL; |
| 693 | } |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 694 | |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 695 | [self.addContactButton setState:NSOffState]; |
| 696 | [self.transferButton setState:NSOffState]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 697 | [self.addParticipantButton setState:NSOffState]; |
Alexandre Lision | 883719f | 2015-10-22 17:37:45 -0400 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | - (void)popoverDidClose:(NSNotification *)notification |
| 701 | { |
| 702 | [videoView setCallDelegate:self]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | #pragma mark - ContactLinkedDelegate |
| 706 | |
| 707 | - (void)contactLinked |
| 708 | { |
| 709 | if (self.addToContactPopover != nullptr) { |
| 710 | [self.addToContactPopover performClose:self]; |
| 711 | self.addToContactPopover = NULL; |
| 712 | } |
| 713 | } |
| 714 | |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 715 | #pragma mark - NSSplitViewDelegate |
| 716 | |
| 717 | /* 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. |
| 718 | */ |
| 719 | - (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex; |
| 720 | { |
| 721 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 722 | return ([subview isEqual:rightView]); |
| 723 | } |
| 724 | |
| 725 | |
| 726 | - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; |
| 727 | { |
| 728 | NSView* rightView = [[splitView subviews] objectAtIndex:1]; |
| 729 | return ([subview isEqual:rightView]); |
| 730 | } |
| 731 | |
| 732 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 733 | # pragma mark - CallnDelegate |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 734 | |
| 735 | - (void) callShouldToggleFullScreen |
| 736 | { |
| 737 | if(self.splitView.isInFullScreenMode) |
| 738 | [self.splitView exitFullScreenModeWithOptions:nil]; |
| 739 | else { |
| 740 | NSApplicationPresentationOptions options = NSApplicationPresentationDefault +NSApplicationPresentationAutoHideDock + |
| 741 | NSApplicationPresentationAutoHideMenuBar + NSApplicationPresentationAutoHideToolbar; |
| 742 | NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:options], |
| 743 | NSFullScreenModeApplicationPresentationOptions, nil]; |
| 744 | |
| 745 | [self.splitView enterFullScreenMode:[NSScreen mainScreen] withOptions:opts]; |
| 746 | } |
| 747 | } |
| 748 | |
Alexandre Lision | a1eee3c | 2015-08-10 13:44:51 -0400 | [diff] [blame] | 749 | -(void) mouseIsMoving:(BOOL) move |
| 750 | { |
| 751 | [[controlsPanel animator] setAlphaValue:move]; // fade out |
| 752 | [[headerContainer animator] setAlphaValue:move]; |
| 753 | } |
| 754 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 755 | @end |