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