Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | 029ffa8 | 2019-01-02 17:43:48 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2019 Savoir-faire Linux Inc. |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 4 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 5 | * |
| 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 19 | */ |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 20 | #import "AccAdvancedVC.h" |
| 21 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 22 | //LRC |
| 23 | #import <api/lrc.h> |
| 24 | #import <api/newaccountmodel.h> |
| 25 | #import <api/newdevicemodel.h> |
| 26 | #import <api/newcodecmodel.h> |
Kateryna Kostiuk | be7e2e4 | 2019-07-26 17:44:12 -0400 | [diff] [blame] | 27 | #import <api/account.h> |
Alexandre Lision | 19a1230 | 2016-01-25 16:02:27 -0500 | [diff] [blame] | 28 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 29 | @interface AccAdvancedVC () |
| 30 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 31 | @property (unsafe_unretained) IBOutlet NSButton* ringtoneSelectionButton; |
| 32 | @property (unsafe_unretained) IBOutlet NSButton* enableRingtone; |
Kateryna Kostiuk | c6c3fa5 | 2020-08-14 12:43:27 -0400 | [diff] [blame] | 33 | @property (unsafe_unretained) IBOutlet NSButton* toggleAccountDiscoveryButton; |
| 34 | @property (unsafe_unretained) IBOutlet NSButton* togglePeersDiscoveryButton; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 35 | @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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 48 | |
| 49 | @end |
| 50 | |
| 51 | @implementation AccAdvancedVC |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 52 | |
| 53 | @synthesize audioCodecView, videoCodecView; |
| 54 | @synthesize privateKeyPaswordField, turnAddressField, turnUsernameField, turnPasswordField, turnRealmField, stunAddressField; |
Kateryna Kostiuk | c6c3fa5 | 2020-08-14 12:43:27 -0400 | [diff] [blame] | 55 | @synthesize ringtoneSelectionButton, selectCACertificateButton, selectUserCertificateButton, selectPrivateKeyButton, toggleAccountDiscoveryButton, togglePeersDiscoveryButton; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 56 | @synthesize enableRingtone, toggleVideoButton, autoAnswer, toggleUPnPButton, useTURNButton, useSTUNButton, disableVideoButton; |
| 57 | @synthesize accountModel; |
| 58 | |
| 59 | NS_ENUM(NSInteger, ButtonsTags) { |
| 60 | TAG_RINGTONE = 1, |
| 61 | TAG_CA_CERTIFICATE, |
| 62 | TAG_USER_CERTIFICATE, |
| 63 | TAG_PRIVATE_KEY |
| 64 | }; |
| 65 | |
| 66 | NS_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 | |
| 75 | NS_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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 91 | |
| 92 | - (void)awakeFromNib |
| 93 | { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 94 | [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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 104 | -(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 Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 117 | -(void) update { |
| 118 | lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID); |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 119 | [ringtoneSelectionButton setTitle: [accountProperties.Ringtone.ringtonePath.toNSString() lastPathComponent]]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 120 | [enableRingtone setState :accountProperties.Ringtone.ringtoneEnabled]; |
| 121 | [autoAnswer setState: accountProperties.autoAnswer]; |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 122 | [selectPrivateKeyButton setTitle: [accountProperties.TLS.privateKeyFile.toNSString() lastPathComponent]]; |
| 123 | [selectUserCertificateButton setTitle:[accountProperties.TLS.certificateFile.toNSString() lastPathComponent]]; |
| 124 | [selectCACertificateButton setTitle: [accountProperties.TLS.certificateListFile.toNSString() lastPathComponent]]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 125 | [toggleUPnPButton setState:accountProperties.upnpEnabled]; |
| 126 | [useTURNButton setState:accountProperties.TURN.enable]; |
| 127 | [useSTUNButton setState:accountProperties.STUN.enable]; |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 128 | [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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 134 | [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 Kostiuk | c6c3fa5 | 2020-08-14 12:43:27 -0400 | [diff] [blame] | 144 | [toggleAccountDiscoveryButton setState:accountProperties.accountPublish]; |
| 145 | [togglePeersDiscoveryButton setState:accountProperties.accountDiscovery]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 146 | } |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 147 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 148 | - (void)viewDidLoad { |
| 149 | [super viewDidLoad]; |
| 150 | [self update]; |
| 151 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 152 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 153 | #pragma mark - AccountAdvancedProtocol methods |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 154 | |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 155 | - (void) setSelectedAccount:(const QString&) account { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 156 | self.selectedAccountID = account; |
| 157 | [self update]; |
| 158 | } |
Alexandre Lision | 19a1230 | 2016-01-25 16:02:27 -0500 | [diff] [blame] | 159 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 160 | #pragma mark - Actions |
Alexandre Lision | 19a1230 | 2016-01-25 16:02:27 -0500 | [diff] [blame] | 161 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 162 | - (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 Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 167 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Kateryna Kostiuk | c6c3fa5 | 2020-08-14 12:43:27 -0400 | [diff] [blame] | 170 | - (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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 186 | - (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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 195 | - (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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 233 | switch ([sender tag]) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 234 | case TAG_RINGTONE: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 235 | if(accountProperties.Ringtone.ringtonePath != QString::fromNSString(path)) { |
| 236 | accountProperties.Ringtone.ringtonePath = QString::fromNSString(path); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 237 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 238 | [ringtoneSelectionButton setTitle:[path lastPathComponent]]; |
| 239 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 240 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 241 | case TAG_CA_CERTIFICATE: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 242 | if(accountProperties.TLS.certificateListFile != QString::fromNSString(path)) { |
| 243 | accountProperties.TLS.certificateListFile = QString::fromNSString(path); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 244 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 245 | [selectCACertificateButton setTitle:[path lastPathComponent]]; |
| 246 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 247 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 248 | case TAG_USER_CERTIFICATE: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 249 | if(accountProperties.TLS.certificateFile != QString::fromNSString(path)) { |
| 250 | accountProperties.TLS.certificateFile = QString::fromNSString(path); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 251 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 252 | [selectUserCertificateButton setTitle:[path lastPathComponent]]; |
| 253 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 254 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 255 | case TAG_PRIVATE_KEY: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 256 | if(accountProperties.TLS.privateKeyFile != QString::fromNSString(path)) { |
| 257 | accountProperties.TLS.privateKeyFile = QString::fromNSString(path); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 258 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 259 | [selectPrivateKeyButton setTitle:[path lastPathComponent]]; |
| 260 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 261 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 262 | } |
| 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 Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 270 | if(accountProperties.TLS.password != QString::fromNSString([sender stringValue])) { |
| 271 | accountProperties.TLS.password = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 272 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 273 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 274 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 275 | case TURN_ADDRESS_TAG: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 276 | if(accountProperties.TURN.server != QString::fromNSString([sender stringValue])) { |
| 277 | accountProperties.TURN.server = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 278 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 279 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 280 | break; |
| 281 | case TURN_USERNAME_TAG: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 282 | if(accountProperties.TURN.username != QString::fromNSString([sender stringValue])) { |
| 283 | accountProperties.TURN.username = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 284 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 285 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 286 | break; |
| 287 | case TURN_PASSWORD_TAG: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 288 | if(accountProperties.TURN.password != QString::fromNSString([sender stringValue])) { |
| 289 | accountProperties.TURN.password = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 290 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 291 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 292 | break; |
| 293 | case TURN_REALM_TAG: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 294 | if(accountProperties.TURN.realm != QString::fromNSString([sender stringValue])) { |
| 295 | accountProperties.TURN.realm = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 296 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 297 | } |
| 298 | break; |
| 299 | case STUN_ADDRESS_TAG: |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 300 | if(accountProperties.STUN.server != QString::fromNSString([sender stringValue])) { |
| 301 | accountProperties.STUN.server = QString::fromNSString([sender stringValue]); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 302 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 303 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 304 | break; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 305 | default: |
| 306 | break; |
| 307 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 310 | - (IBAction)moveAudioCodecUp:(id)sender { |
| 311 | NSInteger row = [audioCodecView selectedRow]; |
| 312 | if(row < 0) { |
| 313 | return; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 314 | } |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 315 | auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs(); |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 316 | if ((audioCodecs.size() - 1) < row) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 317 | return; |
| 318 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 319 | auto codec = audioCodecs[row]; |
| 320 | self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec.id, false); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 321 | [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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 326 | } |
| 327 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 328 | - (IBAction)moveAudioCodecDown:(id)sender { |
| 329 | NSInteger row = [audioCodecView selectedRow]; |
| 330 | if(row < 0) { |
| 331 | return; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 332 | } |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 333 | auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs(); |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 334 | if ((audioCodecs.size() - 1) < row) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 335 | return; |
| 336 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 337 | auto codec = audioCodecs[row]; |
| 338 | self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec.id, false); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 339 | [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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 352 | if ((videoCodecs.size() - 1) < row) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 353 | return; |
| 354 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 355 | auto codec = videoCodecs[row]; |
| 356 | self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->increasePriority(codec.id, YES); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 357 | [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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 370 | if ((videoCodecs.size() - 1) < row) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 371 | return; |
| 372 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 373 | auto codec = videoCodecs[row]; |
| 374 | self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->decreasePriority(codec.id, YES); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 375 | [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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 400 | if ((audioCodecs.size()-1) < row) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 401 | 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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 406 | } |
| 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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 416 | if ((videoCodecs.size()-1) < row) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 417 | 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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | #pragma mark - NSTableViewDelegate methods |
| 426 | - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
| 427 | { |
| 428 | if(tableView == audioCodecView) { |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 429 | 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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 433 | auto audioCodecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getAudioCodecs(); |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 434 | if ((audioCodecs.size() - 1) < row) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 435 | return nil; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 436 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 437 | 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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 443 | return audioCodecCell; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 444 | } else if (tableView == videoCodecView) { |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 445 | 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 Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 448 | nameLabel.textColor = [tableView isEnabled] ? [NSColor labelColor] : [NSColor lightGrayColor]; |
| 449 | [codecEnableButton setEnabled:[tableView isEnabled]]; |
| 450 | auto codecs = self.accountModel->getAccountInfo(self.selectedAccountID).codecModel->getVideoCodecs(); |
Kateryna Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 451 | if ((codecs.size() - 1) < row) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 452 | return nil; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 453 | } |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 454 | 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 Kostiuk | 83cb86d | 2020-03-23 15:43:52 -0400 | [diff] [blame] | 459 | return videoCodecCell; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 460 | } |
| 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @end |