blob: 39dc7e97bfeeb450fcc3a3d31fbccb44c19d80b1 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -04002 * Copyright (C) 2015-2018 Savoir-faire Linux Inc.
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -04004 * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040019 */
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040020#import "AccAdvancedVC.h"
21
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040022//LRC
23#import <api/lrc.h>
24#import <api/newaccountmodel.h>
25#import <api/newdevicemodel.h>
26#import <api/newcodecmodel.h>
27#import <account.h>
Alexandre Lision19a12302016-01-25 16:02:27 -050028
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040029@interface AccAdvancedVC ()
30
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040031@property (unsafe_unretained) IBOutlet NSButton* ringtoneSelectionButton;
32@property (unsafe_unretained) IBOutlet NSButton* enableRingtone;
33@property (unsafe_unretained) IBOutlet NSButton* autoAnswer;
34@property (unsafe_unretained) IBOutlet NSButton* toggleUPnPButton;
35@property (unsafe_unretained) IBOutlet NSButton* useTURNButton;
36@property (unsafe_unretained) IBOutlet NSButton* useSTUNButton;
37@property (unsafe_unretained) IBOutlet NSButton *toggleVideoButton;
38@property (unsafe_unretained) IBOutlet NSTableView* audioCodecView;
39@property (unsafe_unretained) IBOutlet NSTableView* videoCodecView;
40@property (unsafe_unretained) IBOutlet NSTextField *turnAddressField;
41@property (unsafe_unretained) IBOutlet NSTextField *turnUsernameField;
42@property (unsafe_unretained) IBOutlet NSSecureTextField *turnPasswordField;
43@property (unsafe_unretained) IBOutlet NSTextField *turnRealmField;
44@property (unsafe_unretained) IBOutlet NSTextField *stunAddressField;
45@property (unsafe_unretained) IBOutlet NSButton *disableVideoButton;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040046
47@end
48
49@implementation AccAdvancedVC
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040050
51@synthesize audioCodecView, videoCodecView;
52@synthesize privateKeyPaswordField, turnAddressField, turnUsernameField, turnPasswordField, turnRealmField, stunAddressField;
53@synthesize ringtoneSelectionButton, selectCACertificateButton, selectUserCertificateButton, selectPrivateKeyButton;
54@synthesize enableRingtone, toggleVideoButton, autoAnswer, toggleUPnPButton, useTURNButton, useSTUNButton, disableVideoButton;
55@synthesize accountModel;
56
57NS_ENUM(NSInteger, ButtonsTags) {
58 TAG_RINGTONE = 1,
59 TAG_CA_CERTIFICATE,
60 TAG_USER_CERTIFICATE,
61 TAG_PRIVATE_KEY
62};
63
64NS_ENUM(NSInteger, TextFieldsViews) {
65 PRIVATE_KEY_PASSWORG_TAG = 1,
66 TURN_ADDRESS_TAG,
67 TURN_USERNAME_TAG,
68 TURN_PASSWORD_TAG,
69 TURN_REALM_TAG,
70 STUN_ADDRESS_TAG
71};
72
73NS_ENUM(NSInteger, tablesViews) {
74 AUDIO_CODEC_NAME_TAG = 1,
75 AUDIO_CODEC_SAMPLERATE_TAG,
76 AUDIO_CODEC_ENABLE_TAG,
77 VIDEO_CODEC_NAME_TAG,
78 VIDIO_CODEC_ENABLE_TAG
79};
80
81-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel
82{
83 if (self = [self initWithNibName: nibNameOrNil bundle:nibBundleOrNil])
84 {
85 self.accountModel= accountModel;
86 }
87 return self;
88}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040089
90- (void)awakeFromNib
91{
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040092 [super awakeFromNib];
93 audioCodecView.delegate = self;
94 audioCodecView.dataSource = self;
95 videoCodecView.delegate = self;
96 videoCodecView.dataSource = self;
97 [disableVideoButton setWantsLayer:YES];
98 disableVideoButton.layer.backgroundColor = [[NSColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:0.3] CGColor];
99 [self setTags];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400100}
101
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400102-(void) setTags {
103 [ringtoneSelectionButton setTag: TAG_RINGTONE];
104 [selectCACertificateButton setTag: TAG_CA_CERTIFICATE];
105 [selectUserCertificateButton setTag: TAG_USER_CERTIFICATE];
106 [selectPrivateKeyButton setTag: TAG_PRIVATE_KEY];
107 [privateKeyPaswordField setTag: PRIVATE_KEY_PASSWORG_TAG];
108 [turnAddressField setTag: TURN_ADDRESS_TAG];
109 [turnUsernameField setTag: TURN_USERNAME_TAG];
110 [turnPasswordField setTag: TURN_PASSWORD_TAG];
111 [turnRealmField setTag: TURN_REALM_TAG];
112 [stunAddressField setTag: STUN_ADDRESS_TAG];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400113}
114
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400115-(void) update {
116 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
117 [ringtoneSelectionButton setTitle: [@(accountProperties.Ringtone.ringtonePath.c_str()) lastPathComponent]];
118 [enableRingtone setState :accountProperties.Ringtone.ringtoneEnabled];
119 [autoAnswer setState: accountProperties.autoAnswer];
120 [selectPrivateKeyButton setTitle: [@(accountProperties.TLS.privateKeyFile.c_str()) lastPathComponent]];
121 [selectUserCertificateButton setTitle:[@(accountProperties.TLS.certificateFile.c_str()) lastPathComponent]];
122 [selectCACertificateButton setTitle: [@(accountProperties.TLS.certificateListFile.c_str()) lastPathComponent]];
123 [toggleUPnPButton setState:accountProperties.upnpEnabled];
124 [useTURNButton setState:accountProperties.TURN.enable];
125 [useSTUNButton setState:accountProperties.STUN.enable];
126 [privateKeyPaswordField setStringValue:@(accountProperties.TLS.password.c_str())];
127 [turnAddressField setStringValue:@(accountProperties.TURN.server.c_str())];
128 [turnUsernameField setStringValue:@(accountProperties.TURN.username.c_str())];
129 [turnPasswordField setStringValue:@(accountProperties.TURN.password.c_str())];
130 [turnRealmField setStringValue:@(accountProperties.TURN.realm.c_str())];
131 [stunAddressField setStringValue:@(accountProperties.STUN.server.c_str())];
132 [stunAddressField setEditable:accountProperties.STUN.enable];
133 [turnAddressField setEditable:accountProperties.TURN.enable];
134 [turnUsernameField setEditable:accountProperties.TURN.enable];
135 [turnPasswordField setEditable:accountProperties.TURN.enable];
136 [turnRealmField setEditable:accountProperties.TURN.enable];
137 [disableVideoButton setHidden:accountProperties.Video.videoEnabled];
138 [toggleVideoButton setState:accountProperties.Video.videoEnabled];
139 [videoCodecView setEnabled:accountProperties.Video.videoEnabled];
140 [audioCodecView reloadData];
141 [videoCodecView reloadData];
142}
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400143
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400144- (void)viewDidLoad {
145 [super viewDidLoad];
146 [self update];
147}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400148
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400149#pragma mark - AccountAdvancedProtocol methods
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400150
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400151- (void) setSelectedAccount:(std::string) account {
152 self.selectedAccountID = account;
153 [self update];
154}
Alexandre Lision19a12302016-01-25 16:02:27 -0500155
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400156#pragma mark - Actions
Alexandre Lision19a12302016-01-25 16:02:27 -0500157
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400158- (IBAction)autoAnswerCall:(id)sender {
159 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
160 if( accountProperties.autoAnswer != [sender state]) {
161 accountProperties.autoAnswer = [sender state];
162 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400163 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400164}
165
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400166- (IBAction)autoEnableRingtone:(id)sender {
167 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
168 if(accountProperties.Ringtone.ringtoneEnabled != [sender state]) {
169 accountProperties.Ringtone.ringtoneEnabled = [sender state];
170 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
171 [ringtoneSelectionButton setEnabled:[sender state]];
172 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400173}
174
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400175- (IBAction)togleUPnP:(id)sender {
176 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
177 if( accountProperties.upnpEnabled != [sender state]) {
178 accountProperties.upnpEnabled = [sender state];
179 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
180 }
181}
182
183- (IBAction)useTURN:(id)sender {
184 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
185 if( accountProperties.TURN.enable != [sender state]) {
186 accountProperties.TURN.enable = [sender state];
187 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
188 [turnAddressField setEditable:[sender state]];
189 [turnUsernameField setEditable:[sender state]];
190 [turnPasswordField setEditable:[sender state]];
191 [turnRealmField setEditable:[sender state]];
192 }
193}
194
195- (IBAction)useSTUN:(id)sender {
196 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
197 if( accountProperties.STUN.enable != [sender state]) {
198 accountProperties.STUN.enable = [sender state];
199 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
200 [stunAddressField setEditable:[sender state]];
201 }
202}
203
204- (IBAction)selectFile:(id)sender {
205 NSOpenPanel *panel = [NSOpenPanel openPanel];
206 [panel setAllowsMultipleSelection:NO];
207 [panel setCanChooseDirectories:NO];
208 [panel setCanChooseFiles:YES];
209 if ([panel runModal] != NSFileHandlingPanelOKButton) return;
210 if ([[panel URLs] lastObject] == nil) return;
211 NSString * path = [[[panel URLs] lastObject] path];
212 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400213 switch ([sender tag]) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400214 case TAG_RINGTONE:
215 if(accountProperties.Ringtone.ringtonePath != [path UTF8String]) {
216 accountProperties.Ringtone.ringtonePath = [path UTF8String];
217 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
218 [ringtoneSelectionButton setTitle:[path lastPathComponent]];
219 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400220 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400221 case TAG_CA_CERTIFICATE:
222 if(accountProperties.TLS.certificateListFile != [path UTF8String] ) {
223 accountProperties.TLS.certificateListFile = [path UTF8String];
224 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
225 [selectCACertificateButton setTitle:[path lastPathComponent]];
226 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400227 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400228 case TAG_USER_CERTIFICATE:
229 if(accountProperties.TLS.certificateFile != [path UTF8String] ) {
230 accountProperties.TLS.certificateFile = [path UTF8String];
231 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
232 [selectUserCertificateButton setTitle:[path lastPathComponent]];
233 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400234 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400235 case TAG_PRIVATE_KEY:
236 if(accountProperties.TLS.privateKeyFile != [path UTF8String] ) {
237 accountProperties.TLS.privateKeyFile = [path UTF8String];
238 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
239 [selectPrivateKeyButton setTitle:[path lastPathComponent]];
240 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400241 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400242 }
243}
244
245- (IBAction)valueDidChange:(id)sender
246{
247 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
248 switch ([sender tag]) {
249 case PRIVATE_KEY_PASSWORG_TAG:
250 if(accountProperties.TLS.password != [[sender stringValue] UTF8String]) {
251 accountProperties.TLS.password = [[sender stringValue] UTF8String];
252 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
253 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400254 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400255 case TURN_ADDRESS_TAG:
256 if(accountProperties.TURN.server != [[sender stringValue] UTF8String]) {
257 accountProperties.TURN.server = [[sender stringValue] UTF8String];
258 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
259 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400260 break;
261 case TURN_USERNAME_TAG:
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400262 if(accountProperties.TURN.username != [[sender stringValue] UTF8String]) {
263 accountProperties.TURN.username = [[sender stringValue] UTF8String];
264 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
265 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400266 break;
267 case TURN_PASSWORD_TAG:
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400268 if(accountProperties.TURN.password != [[sender stringValue] UTF8String]) {
269 accountProperties.TURN.password = [[sender stringValue] UTF8String];
270 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
271 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400272 break;
273 case TURN_REALM_TAG:
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400274 if(accountProperties.TURN.realm != [[sender stringValue] UTF8String]) {
275 accountProperties.TURN.realm = [[sender stringValue] UTF8String];
276 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
277 }
278 break;
279 case STUN_ADDRESS_TAG:
280 if(accountProperties.STUN.server != [[sender stringValue] UTF8String]) {
281 accountProperties.STUN.server = [[sender stringValue] UTF8String];
282 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
283 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400284 break;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400285 default:
286 break;
287 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400288}
289
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400290- (IBAction)moveAudioCodecUp:(id)sender {
291 NSInteger row = [audioCodecView selectedRow];
292 if(row < 0) {
293 return;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400294 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400295 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
296 auto codec = audioCodecs.begin();
297 std::advance(codec, row);
298 if (codec == audioCodecs.end()) {
299 return;
300 }
301 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec->id, false);
302 [audioCodecView reloadData];
303 row = row == 0 ? row: row-1;
304 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
305 [audioCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
306 [audioCodecView scrollRowToVisible:row];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400307}
308
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400309- (IBAction)moveAudioCodecDown:(id)sender {
310 NSInteger row = [audioCodecView selectedRow];
311 if(row < 0) {
312 return;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400313 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400314 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
315 auto codec = audioCodecs.begin();
316 std::advance(codec, row);
317 if (codec == audioCodecs.end()) {
318 return;
319 }
320 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec->id, false);
321 [audioCodecView reloadData];
322 row = (row == ([audioCodecView numberOfRows] - 1)) ? row: row+1;
323 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
324 [audioCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
325 [audioCodecView scrollRowToVisible:row];
326}
327
328- (IBAction)moveVideoCodecUp:(id)sender {
329 NSInteger row = [videoCodecView selectedRow];
330 if(row < 0) {
331 return;
332 }
333 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
334 auto codec = videoCodecs.begin();
335 std::advance(codec, row);
336 if (codec == videoCodecs.end()) {
337 return;
338 }
339 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec->id, YES);
340 [videoCodecView reloadData];
341 row = row == 0 ? row: row-1;
342 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
343 [videoCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
344 [videoCodecView scrollRowToVisible:row];
345}
346
347- (IBAction)moveVideoCodecDown:(id)sender {
348 NSInteger row = [videoCodecView selectedRow];
349 if(row < 0) {
350 return;
351 }
352 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
353 auto codec = videoCodecs.begin();
354 std::advance(codec, row);
355 if (codec == videoCodecs.end()) {
356 return;
357 }
358 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec->id, YES);
359 [videoCodecView reloadData];
360 row = row == [videoCodecView numberOfRows] - 1 ? row: row+1;
361 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
362 [videoCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
363 [videoCodecView scrollRowToVisible:row];
364}
365
366- (IBAction)toggleVideoEnabled:(id)sender {
367 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
368 if(accountProperties.Video.videoEnabled != [sender state]) {
369 accountProperties.Video.videoEnabled = [sender state];
370 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
371 [videoCodecView setEnabled:[sender state]];
372 [videoCodecView reloadData];
373 [disableVideoButton setHidden:[sender state]];
374 }
375}
376
377- (IBAction)enableAudioCodec:(id)sender
378{
379 NSInteger row = [audioCodecView rowForView:sender];
380 if(row < 0) {
381 return;
382 }
383 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
384 auto codec = audioCodecs.begin();
385 std::advance(codec, row);
386 if (codec != audioCodecs.end() && codec->enabled != [sender state]) {
387 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->enable(codec->id, [sender state]);
388 }
389}
390
391- (IBAction)enableVideoCodec:(id)sender
392{
393 NSInteger row = [videoCodecView rowForView:sender];
394 if(row < 0) {
395 return;
396 }
397 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
398 auto codec = videoCodecs.begin();
399 std::advance(codec, row);
400 if (codec != videoCodecs.end() && codec->enabled != [sender state]) {
401 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->enable(codec->id, [sender state]);
402 }
403}
404
405#pragma mark - NSTableViewDelegate methods
406- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
407{
408 if(tableView == audioCodecView) {
409 NSTableCellView* audioCodecView = [tableView makeViewWithIdentifier:@"TableCellAudioCodecItem" owner:self];
410 NSTextField* nameLabel = [audioCodecView viewWithTag: AUDIO_CODEC_NAME_TAG];
411 NSTextField* samplerateLabel = [audioCodecView viewWithTag: AUDIO_CODEC_SAMPLERATE_TAG];
412 NSButton* codecEnableButton = [audioCodecView viewWithTag: AUDIO_CODEC_ENABLE_TAG];
413 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
414 auto codec = audioCodecs.begin();
415 std::advance(codec, row);
416 if (codec != audioCodecs.end()) {
417 [nameLabel setStringValue: @(codec->name.c_str())];
418 [samplerateLabel setStringValue: [@(codec->samplerate.c_str()) stringByAppendingString:@" Hz"]];
419 [codecEnableButton setState:codec->enabled];
420 [codecEnableButton setAction:@selector(enableAudioCodec:)];
421 [codecEnableButton setTarget:self];
422 return audioCodecView;
423 }
424 } else if (tableView == videoCodecView) {
425 NSTableCellView* videoCodecView = [tableView makeViewWithIdentifier:@"TableCellVideoCodecItem" owner:self];
426 NSTextField* nameLabel = [videoCodecView viewWithTag: VIDEO_CODEC_NAME_TAG];
427 NSButton* codecEnableButton = [audioCodecView viewWithTag: VIDIO_CODEC_ENABLE_TAG];
428 nameLabel.textColor = [tableView isEnabled] ? [NSColor labelColor] : [NSColor lightGrayColor];
429 [codecEnableButton setEnabled:[tableView isEnabled]];
430 auto codecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
431 auto codec = codecs.begin();
432 std::advance(codec, row);
433 if (codec != codecs.end()) {
434 [nameLabel setStringValue: @(codec->name.c_str())];
435 [codecEnableButton setState:codec->enabled];
436 [codecEnableButton setAction:@selector(enableVideoCodec:)];
437 [codecEnableButton setTarget:self];
438 return videoCodecView;
439 }
440 }
441}
442
443- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
444{
445 if(![tableView isEnabled]) {
446 return nil;
447 }
448 return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
449}
450
451#pragma mark - NSTableViewDataSource methods
452
453- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
454 if(tableView == audioCodecView) {
455 return self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs().size();
456 } else if (tableView == videoCodecView){
457 return self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs().size();
458 }
459 return 0;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400460}
461
462@end