Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 2 | * Copyright (C) 2015-2018 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> |
| 27 | #import <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; |
| 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 46 | |
| 47 | @end |
| 48 | |
| 49 | @implementation AccAdvancedVC |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 50 | |
| 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 | |
| 57 | NS_ENUM(NSInteger, ButtonsTags) { |
| 58 | TAG_RINGTONE = 1, |
| 59 | TAG_CA_CERTIFICATE, |
| 60 | TAG_USER_CERTIFICATE, |
| 61 | TAG_PRIVATE_KEY |
| 62 | }; |
| 63 | |
| 64 | NS_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 | |
| 73 | NS_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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 89 | |
| 90 | - (void)awakeFromNib |
| 91 | { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 92 | [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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 102 | -(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 Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 115 | -(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 Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 143 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 144 | - (void)viewDidLoad { |
| 145 | [super viewDidLoad]; |
| 146 | [self update]; |
| 147 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 148 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 149 | #pragma mark - AccountAdvancedProtocol methods |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 150 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 151 | - (void) setSelectedAccount:(std::string) account { |
| 152 | self.selectedAccountID = account; |
| 153 | [self update]; |
| 154 | } |
Alexandre Lision | 19a1230 | 2016-01-25 16:02:27 -0500 | [diff] [blame] | 155 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 156 | #pragma mark - Actions |
Alexandre Lision | 19a1230 | 2016-01-25 16:02:27 -0500 | [diff] [blame] | 157 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 158 | - (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 Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 163 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 166 | - (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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 175 | - (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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 213 | switch ([sender tag]) { |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 214 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 220 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 221 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 227 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 228 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 234 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 235 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 241 | break; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 242 | } |
| 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 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 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 Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 260 | break; |
| 261 | case TURN_USERNAME_TAG: |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 262 | if(accountProperties.TURN.username != [[sender stringValue] UTF8String]) { |
| 263 | accountProperties.TURN.username = [[sender stringValue] UTF8String]; |
| 264 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 265 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 266 | break; |
| 267 | case TURN_PASSWORD_TAG: |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 268 | if(accountProperties.TURN.password != [[sender stringValue] UTF8String]) { |
| 269 | accountProperties.TURN.password = [[sender stringValue] UTF8String]; |
| 270 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 271 | } |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 272 | break; |
| 273 | case TURN_REALM_TAG: |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 274 | 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 Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 284 | break; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 285 | default: |
| 286 | break; |
| 287 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 290 | - (IBAction)moveAudioCodecUp:(id)sender { |
| 291 | NSInteger row = [audioCodecView selectedRow]; |
| 292 | if(row < 0) { |
| 293 | return; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 294 | } |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 295 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 307 | } |
| 308 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 309 | - (IBAction)moveAudioCodecDown:(id)sender { |
| 310 | NSInteger row = [audioCodecView selectedRow]; |
| 311 | if(row < 0) { |
| 312 | return; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 313 | } |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame^] | 314 | 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 Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | @end |