blob: 9165da9c77e8388120143ff64875f19712b65361 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
Sébastien Blin029ffa82019-01-02 17:43:48 -05002 * Copyright (C) 2015-2019 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>
Kateryna Kostiukbe7e2e42019-07-26 17:44:12 -040027#import <api/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;
Kateryna Kostiukc6c3fa52020-08-14 12:43:27 -040033@property (unsafe_unretained) IBOutlet NSButton* toggleAccountDiscoveryButton;
34@property (unsafe_unretained) IBOutlet NSButton* togglePeersDiscoveryButton;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040035@property (unsafe_unretained) IBOutlet NSButton* autoAnswer;
36@property (unsafe_unretained) IBOutlet NSButton* toggleUPnPButton;
37@property (unsafe_unretained) IBOutlet NSButton* useTURNButton;
38@property (unsafe_unretained) IBOutlet NSButton* useSTUNButton;
39@property (unsafe_unretained) IBOutlet NSButton *toggleVideoButton;
40@property (unsafe_unretained) IBOutlet NSTableView* audioCodecView;
41@property (unsafe_unretained) IBOutlet NSTableView* videoCodecView;
42@property (unsafe_unretained) IBOutlet NSTextField *turnAddressField;
43@property (unsafe_unretained) IBOutlet NSTextField *turnUsernameField;
44@property (unsafe_unretained) IBOutlet NSSecureTextField *turnPasswordField;
45@property (unsafe_unretained) IBOutlet NSTextField *turnRealmField;
46@property (unsafe_unretained) IBOutlet NSTextField *stunAddressField;
47@property (unsafe_unretained) IBOutlet NSButton *disableVideoButton;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040048
49@end
50
51@implementation AccAdvancedVC
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040052
53@synthesize audioCodecView, videoCodecView;
54@synthesize privateKeyPaswordField, turnAddressField, turnUsernameField, turnPasswordField, turnRealmField, stunAddressField;
Kateryna Kostiukc6c3fa52020-08-14 12:43:27 -040055@synthesize ringtoneSelectionButton, selectCACertificateButton, selectUserCertificateButton, selectPrivateKeyButton, toggleAccountDiscoveryButton, togglePeersDiscoveryButton;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040056@synthesize enableRingtone, toggleVideoButton, autoAnswer, toggleUPnPButton, useTURNButton, useSTUNButton, disableVideoButton;
57@synthesize accountModel;
58
59NS_ENUM(NSInteger, ButtonsTags) {
60 TAG_RINGTONE = 1,
61 TAG_CA_CERTIFICATE,
62 TAG_USER_CERTIFICATE,
63 TAG_PRIVATE_KEY
64};
65
66NS_ENUM(NSInteger, TextFieldsViews) {
67 PRIVATE_KEY_PASSWORG_TAG = 1,
68 TURN_ADDRESS_TAG,
69 TURN_USERNAME_TAG,
70 TURN_PASSWORD_TAG,
71 TURN_REALM_TAG,
72 STUN_ADDRESS_TAG
73};
74
75NS_ENUM(NSInteger, tablesViews) {
76 AUDIO_CODEC_NAME_TAG = 1,
77 AUDIO_CODEC_SAMPLERATE_TAG,
78 AUDIO_CODEC_ENABLE_TAG,
79 VIDEO_CODEC_NAME_TAG,
80 VIDIO_CODEC_ENABLE_TAG
81};
82
83-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel
84{
85 if (self = [self initWithNibName: nibNameOrNil bundle:nibBundleOrNil])
86 {
87 self.accountModel= accountModel;
88 }
89 return self;
90}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040091
92- (void)awakeFromNib
93{
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040094 [super awakeFromNib];
95 audioCodecView.delegate = self;
96 audioCodecView.dataSource = self;
97 videoCodecView.delegate = self;
98 videoCodecView.dataSource = self;
99 [disableVideoButton setWantsLayer:YES];
100 disableVideoButton.layer.backgroundColor = [[NSColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:0.3] CGColor];
101 [self setTags];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400102}
103
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400104-(void) setTags {
105 [ringtoneSelectionButton setTag: TAG_RINGTONE];
106 [selectCACertificateButton setTag: TAG_CA_CERTIFICATE];
107 [selectUserCertificateButton setTag: TAG_USER_CERTIFICATE];
108 [selectPrivateKeyButton setTag: TAG_PRIVATE_KEY];
109 [privateKeyPaswordField setTag: PRIVATE_KEY_PASSWORG_TAG];
110 [turnAddressField setTag: TURN_ADDRESS_TAG];
111 [turnUsernameField setTag: TURN_USERNAME_TAG];
112 [turnPasswordField setTag: TURN_PASSWORD_TAG];
113 [turnRealmField setTag: TURN_REALM_TAG];
114 [stunAddressField setTag: STUN_ADDRESS_TAG];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400115}
116
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400117-(void) update {
118 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400119 [ringtoneSelectionButton setTitle: [accountProperties.Ringtone.ringtonePath.toNSString() lastPathComponent]];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400120 [enableRingtone setState :accountProperties.Ringtone.ringtoneEnabled];
121 [autoAnswer setState: accountProperties.autoAnswer];
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400122 [selectPrivateKeyButton setTitle: [accountProperties.TLS.privateKeyFile.toNSString() lastPathComponent]];
123 [selectUserCertificateButton setTitle:[accountProperties.TLS.certificateFile.toNSString() lastPathComponent]];
124 [selectCACertificateButton setTitle: [accountProperties.TLS.certificateListFile.toNSString() lastPathComponent]];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400125 [toggleUPnPButton setState:accountProperties.upnpEnabled];
126 [useTURNButton setState:accountProperties.TURN.enable];
127 [useSTUNButton setState:accountProperties.STUN.enable];
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400128 [privateKeyPaswordField setStringValue:accountProperties.TLS.password.toNSString()];
129 [turnAddressField setStringValue:accountProperties.TURN.server.toNSString()];
130 [turnUsernameField setStringValue:accountProperties.TURN.username.toNSString()];
131 [turnPasswordField setStringValue:accountProperties.TURN.password.toNSString()];
132 [turnRealmField setStringValue:accountProperties.TURN.realm.toNSString()];
133 [stunAddressField setStringValue:accountProperties.STUN.server.toNSString()];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400134 [stunAddressField setEditable:accountProperties.STUN.enable];
135 [turnAddressField setEditable:accountProperties.TURN.enable];
136 [turnUsernameField setEditable:accountProperties.TURN.enable];
137 [turnPasswordField setEditable:accountProperties.TURN.enable];
138 [turnRealmField setEditable:accountProperties.TURN.enable];
139 [disableVideoButton setHidden:accountProperties.Video.videoEnabled];
140 [toggleVideoButton setState:accountProperties.Video.videoEnabled];
141 [videoCodecView setEnabled:accountProperties.Video.videoEnabled];
142 [audioCodecView reloadData];
143 [videoCodecView reloadData];
Kateryna Kostiukc6c3fa52020-08-14 12:43:27 -0400144 [toggleAccountDiscoveryButton setState:accountProperties.accountPublish];
145 [togglePeersDiscoveryButton setState:accountProperties.accountDiscovery];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400146}
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400147
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400148- (void)viewDidLoad {
149 [super viewDidLoad];
150 [self update];
151}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400152
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400153#pragma mark - AccountAdvancedProtocol methods
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400154
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400155- (void) setSelectedAccount:(const QString&) account {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400156 self.selectedAccountID = account;
157 [self update];
158}
Alexandre Lision19a12302016-01-25 16:02:27 -0500159
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400160#pragma mark - Actions
Alexandre Lision19a12302016-01-25 16:02:27 -0500161
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400162- (IBAction)autoAnswerCall:(id)sender {
163 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
164 if( accountProperties.autoAnswer != [sender state]) {
165 accountProperties.autoAnswer = [sender state];
166 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400167 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400168}
169
Kateryna Kostiukc6c3fa52020-08-14 12:43:27 -0400170- (IBAction)toggleAccountDiscovery:(id)sender {
171 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
172 if( accountProperties.accountPublish != [sender state]) {
173 accountProperties.accountPublish = [sender state];
174 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
175 }
176}
177
178- (IBAction)togglePeersDiscovery:(id)sender {
179 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
180 if( accountProperties.accountDiscovery != [sender state]) {
181 accountProperties.accountDiscovery = [sender state];
182 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
183 }
184}
185
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400186- (IBAction)autoEnableRingtone:(id)sender {
187 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
188 if(accountProperties.Ringtone.ringtoneEnabled != [sender state]) {
189 accountProperties.Ringtone.ringtoneEnabled = [sender state];
190 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
191 [ringtoneSelectionButton setEnabled:[sender state]];
192 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400193}
194
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400195- (IBAction)togleUPnP:(id)sender {
196 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
197 if( accountProperties.upnpEnabled != [sender state]) {
198 accountProperties.upnpEnabled = [sender state];
199 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
200 }
201}
202
203- (IBAction)useTURN:(id)sender {
204 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
205 if( accountProperties.TURN.enable != [sender state]) {
206 accountProperties.TURN.enable = [sender state];
207 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
208 [turnAddressField setEditable:[sender state]];
209 [turnUsernameField setEditable:[sender state]];
210 [turnPasswordField setEditable:[sender state]];
211 [turnRealmField setEditable:[sender state]];
212 }
213}
214
215- (IBAction)useSTUN:(id)sender {
216 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
217 if( accountProperties.STUN.enable != [sender state]) {
218 accountProperties.STUN.enable = [sender state];
219 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
220 [stunAddressField setEditable:[sender state]];
221 }
222}
223
224- (IBAction)selectFile:(id)sender {
225 NSOpenPanel *panel = [NSOpenPanel openPanel];
226 [panel setAllowsMultipleSelection:NO];
227 [panel setCanChooseDirectories:NO];
228 [panel setCanChooseFiles:YES];
229 if ([panel runModal] != NSFileHandlingPanelOKButton) return;
230 if ([[panel URLs] lastObject] == nil) return;
231 NSString * path = [[[panel URLs] lastObject] path];
232 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400233 switch ([sender tag]) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400234 case TAG_RINGTONE:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400235 if(accountProperties.Ringtone.ringtonePath != QString::fromNSString(path)) {
236 accountProperties.Ringtone.ringtonePath = QString::fromNSString(path);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400237 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
238 [ringtoneSelectionButton setTitle:[path lastPathComponent]];
239 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400240 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400241 case TAG_CA_CERTIFICATE:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400242 if(accountProperties.TLS.certificateListFile != QString::fromNSString(path)) {
243 accountProperties.TLS.certificateListFile = QString::fromNSString(path);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400244 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
245 [selectCACertificateButton setTitle:[path lastPathComponent]];
246 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400247 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400248 case TAG_USER_CERTIFICATE:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400249 if(accountProperties.TLS.certificateFile != QString::fromNSString(path)) {
250 accountProperties.TLS.certificateFile = QString::fromNSString(path);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400251 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
252 [selectUserCertificateButton setTitle:[path lastPathComponent]];
253 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400254 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400255 case TAG_PRIVATE_KEY:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400256 if(accountProperties.TLS.privateKeyFile != QString::fromNSString(path)) {
257 accountProperties.TLS.privateKeyFile = QString::fromNSString(path);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400258 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
259 [selectPrivateKeyButton setTitle:[path lastPathComponent]];
260 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400261 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400262 }
263}
264
265- (IBAction)valueDidChange:(id)sender
266{
267 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
268 switch ([sender tag]) {
269 case PRIVATE_KEY_PASSWORG_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400270 if(accountProperties.TLS.password != QString::fromNSString([sender stringValue])) {
271 accountProperties.TLS.password = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400272 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
273 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400274 break;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400275 case TURN_ADDRESS_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400276 if(accountProperties.TURN.server != QString::fromNSString([sender stringValue])) {
277 accountProperties.TURN.server = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400278 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
279 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400280 break;
281 case TURN_USERNAME_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400282 if(accountProperties.TURN.username != QString::fromNSString([sender stringValue])) {
283 accountProperties.TURN.username = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400284 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
285 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400286 break;
287 case TURN_PASSWORD_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400288 if(accountProperties.TURN.password != QString::fromNSString([sender stringValue])) {
289 accountProperties.TURN.password = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400290 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
291 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400292 break;
293 case TURN_REALM_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400294 if(accountProperties.TURN.realm != QString::fromNSString([sender stringValue])) {
295 accountProperties.TURN.realm = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400296 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
297 }
298 break;
299 case STUN_ADDRESS_TAG:
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400300 if(accountProperties.STUN.server != QString::fromNSString([sender stringValue])) {
301 accountProperties.STUN.server = QString::fromNSString([sender stringValue]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400302 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
303 }
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400304 break;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400305 default:
306 break;
307 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400308}
309
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400310- (IBAction)moveAudioCodecUp:(id)sender {
311 NSInteger row = [audioCodecView selectedRow];
312 if(row < 0) {
313 return;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400314 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400315 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400316 if ((audioCodecs.size() - 1) < row) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400317 return;
318 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400319 auto codec = audioCodecs[row];
320 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec.id, false);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400321 [audioCodecView reloadData];
322 row = row == 0 ? row: row-1;
323 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
324 [audioCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
325 [audioCodecView scrollRowToVisible:row];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400326}
327
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400328- (IBAction)moveAudioCodecDown:(id)sender {
329 NSInteger row = [audioCodecView selectedRow];
330 if(row < 0) {
331 return;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400332 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400333 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400334 if ((audioCodecs.size() - 1) < row) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400335 return;
336 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400337 auto codec = audioCodecs[row];
338 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec.id, false);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400339 [audioCodecView reloadData];
340 row = (row == ([audioCodecView numberOfRows] - 1)) ? row: row+1;
341 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
342 [audioCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
343 [audioCodecView scrollRowToVisible:row];
344}
345
346- (IBAction)moveVideoCodecUp:(id)sender {
347 NSInteger row = [videoCodecView selectedRow];
348 if(row < 0) {
349 return;
350 }
351 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400352 if ((videoCodecs.size() - 1) < row) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400353 return;
354 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400355 auto codec = videoCodecs[row];
356 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec.id, YES);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400357 [videoCodecView reloadData];
358 row = row == 0 ? row: row-1;
359 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
360 [videoCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
361 [videoCodecView scrollRowToVisible:row];
362}
363
364- (IBAction)moveVideoCodecDown:(id)sender {
365 NSInteger row = [videoCodecView selectedRow];
366 if(row < 0) {
367 return;
368 }
369 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400370 if ((videoCodecs.size() - 1) < row) {
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400371 return;
372 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400373 auto codec = videoCodecs[row];
374 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec.id, YES);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400375 [videoCodecView reloadData];
376 row = row == [videoCodecView numberOfRows] - 1 ? row: row+1;
377 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: row];
378 [videoCodecView selectRowIndexes:indexSet byExtendingSelection: NO];
379 [videoCodecView scrollRowToVisible:row];
380}
381
382- (IBAction)toggleVideoEnabled:(id)sender {
383 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
384 if(accountProperties.Video.videoEnabled != [sender state]) {
385 accountProperties.Video.videoEnabled = [sender state];
386 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
387 [videoCodecView setEnabled:[sender state]];
388 [videoCodecView reloadData];
389 [disableVideoButton setHidden:[sender state]];
390 }
391}
392
393- (IBAction)enableAudioCodec:(id)sender
394{
395 NSInteger row = [audioCodecView rowForView:sender];
396 if(row < 0) {
397 return;
398 }
399 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400400 if ((audioCodecs.size()-1) < row) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400401 return;
402 }
403 auto codec = audioCodecs[row];
404 if (codec.enabled != [sender state]) {
405 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->enable(codec.id, [sender state]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400406 }
407}
408
409- (IBAction)enableVideoCodec:(id)sender
410{
411 NSInteger row = [videoCodecView rowForView:sender];
412 if(row < 0) {
413 return;
414 }
415 auto videoCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400416 if ((videoCodecs.size()-1) < row) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400417 return;
418 }
419 auto codec = videoCodecs[row];
420 if (codec.enabled != [sender state]) {
421 self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->enable(codec.id, [sender state]);
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400422 }
423}
424
425#pragma mark - NSTableViewDelegate methods
426- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
427{
428 if(tableView == audioCodecView) {
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400429 NSTableCellView* audioCodecCell = [tableView makeViewWithIdentifier:@"TableCellAudioCodecItem" owner:self];
430 NSTextField* nameLabel = [audioCodecCell viewWithTag: AUDIO_CODEC_NAME_TAG];
431 NSTextField* samplerateLabel = [audioCodecCell viewWithTag: AUDIO_CODEC_SAMPLERATE_TAG];
432 NSButton* codecEnableButton = [audioCodecCell viewWithTag: AUDIO_CODEC_ENABLE_TAG];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400433 auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400434 if ((audioCodecs.size() - 1) < row) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400435 return nil;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400436 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400437 auto codec = audioCodecs[row];
438 [nameLabel setStringValue: codec.name.toNSString()];
439 [samplerateLabel setStringValue: [codec.samplerate.toNSString() stringByAppendingString:@" Hz"]];
440 [codecEnableButton setState:codec.enabled];
441 [codecEnableButton setAction:@selector(enableAudioCodec:)];
442 [codecEnableButton setTarget:self];
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400443 return audioCodecCell;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400444 } else if (tableView == videoCodecView) {
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400445 NSTableCellView* videoCodecCell = [tableView makeViewWithIdentifier:@"TableCellVideoCodecItem" owner:self];
446 NSTextField* nameLabel = [videoCodecCell viewWithTag: VIDEO_CODEC_NAME_TAG];
447 NSButton* codecEnableButton = [videoCodecCell viewWithTag: VIDIO_CODEC_ENABLE_TAG];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400448 nameLabel.textColor = [tableView isEnabled] ? [NSColor labelColor] : [NSColor lightGrayColor];
449 [codecEnableButton setEnabled:[tableView isEnabled]];
450 auto codecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs();
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400451 if ((codecs.size() - 1) < row) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400452 return nil;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400453 }
Kateryna Kostiukc867eb92020-03-08 13:15:17 -0400454 auto codec = codecs[row];
455 [nameLabel setStringValue: codec.name.toNSString()];
456 [codecEnableButton setState:codec.enabled];
457 [codecEnableButton setAction:@selector(enableVideoCodec:)];
458 [codecEnableButton setTarget:self];
Kateryna Kostiuk83cb86d2020-03-23 15:43:52 -0400459 return videoCodecCell;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400460 }
461}
462
463- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
464{
465 if(![tableView isEnabled]) {
466 return nil;
467 }
468 return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
469}
470
471#pragma mark - NSTableViewDataSource methods
472
473- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
474 if(tableView == audioCodecView) {
475 return self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs().size();
476 } else if (tableView == videoCodecView){
477 return self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs().size();
478 }
479 return 0;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400480}
481
482@end