Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | #define REGISTRATION_TAG 0 |
| 31 | #define LOCALPORT_TAG 1 |
| 32 | #define STUNURL_TAG 2 |
| 33 | #define PUBLICADDR_TAG 3 |
| 34 | #define PUBLICPORT_TAG 4 |
| 35 | #define MINAUDIO_TAG 5 |
| 36 | #define MAXAUDIO_TAG 6 |
| 37 | #define MINVIDEO_TAG 7 |
| 38 | #define MAXVIDEO_TAG 8 |
| 39 | |
| 40 | #import "AccAdvancedVC.h" |
| 41 | |
| 42 | @interface AccAdvancedVC () |
| 43 | |
| 44 | @property Account* privateAccount; |
| 45 | @property (assign) IBOutlet NSTextField *registrationField; |
| 46 | @property (assign) IBOutlet NSTextField *localPortField; |
| 47 | @property (assign) IBOutlet NSButton *isUsingSTUN; |
| 48 | |
| 49 | @property (assign) IBOutlet NSTextField *STUNserverURLField; |
| 50 | @property (assign) IBOutlet NSTextField *minAudioRTPRange; |
| 51 | @property (assign) IBOutlet NSTextField *maxAudioRTPRange; |
| 52 | @property (assign) IBOutlet NSTextField *minVideoRTPRange; |
| 53 | @property (assign) IBOutlet NSTextField *maxVideoRTPRange; |
| 54 | |
| 55 | |
| 56 | @property (assign) IBOutlet NSStepper *registrationStepper; |
| 57 | @property (assign) IBOutlet NSStepper *localPortStepper; |
| 58 | @property (assign) IBOutlet NSStepper *minAudioPortStepper; |
| 59 | @property (assign) IBOutlet NSStepper *maxAudioPortStepper; |
| 60 | @property (assign) IBOutlet NSStepper *minVideoPortStepper; |
| 61 | @property (assign) IBOutlet NSStepper *maxVideoPortStepper; |
| 62 | |
| 63 | @property (assign) IBOutlet NSMatrix *publishAddrAndPortRadioGroup; |
| 64 | @property (assign) IBOutlet NSTextField *publishedAddrField; |
| 65 | @property (assign) IBOutlet NSTextField *publishedPortField; |
| 66 | |
| 67 | @end |
| 68 | |
| 69 | @implementation AccAdvancedVC |
| 70 | @synthesize privateAccount; |
| 71 | @synthesize registrationField; |
| 72 | @synthesize localPortField; |
| 73 | @synthesize isUsingSTUN; |
| 74 | @synthesize STUNserverURLField; |
| 75 | @synthesize minAudioRTPRange; |
| 76 | @synthesize maxAudioRTPRange; |
| 77 | @synthesize minVideoRTPRange; |
| 78 | @synthesize maxVideoRTPRange; |
| 79 | @synthesize registrationStepper; |
| 80 | @synthesize localPortStepper; |
| 81 | @synthesize minAudioPortStepper; |
| 82 | @synthesize maxAudioPortStepper; |
| 83 | @synthesize minVideoPortStepper; |
| 84 | @synthesize maxVideoPortStepper; |
| 85 | @synthesize publishAddrAndPortRadioGroup; |
| 86 | @synthesize publishedAddrField; |
| 87 | @synthesize publishedPortField; |
| 88 | |
| 89 | - (void)awakeFromNib |
| 90 | { |
| 91 | NSLog(@"INIT Advanced VC"); |
| 92 | [registrationStepper setTag:REGISTRATION_TAG]; |
| 93 | [localPortStepper setTag:LOCALPORT_TAG]; |
| 94 | [minAudioPortStepper setTag:MINAUDIO_TAG]; |
| 95 | [maxAudioPortStepper setTag:MAXAUDIO_TAG]; |
| 96 | [minVideoPortStepper setTag:MINVIDEO_TAG]; |
| 97 | [maxVideoPortStepper setTag:MAXVIDEO_TAG]; |
| 98 | |
| 99 | [registrationField setTag:REGISTRATION_TAG]; |
| 100 | [localPortField setTag:LOCALPORT_TAG]; |
| 101 | [minAudioRTPRange setTag:MINAUDIO_TAG]; |
| 102 | [maxAudioRTPRange setTag:MAXAUDIO_TAG]; |
| 103 | [minVideoRTPRange setTag:MINVIDEO_TAG]; |
| 104 | [maxVideoRTPRange setTag:MAXVIDEO_TAG]; |
| 105 | |
| 106 | [STUNserverURLField setTag:STUNURL_TAG]; |
| 107 | [publishedPortField setTag:PUBLICPORT_TAG]; |
| 108 | [publishedAddrField setTag:PUBLICADDR_TAG]; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | - (void)loadAccount:(Account *)account |
| 113 | { |
| 114 | privateAccount = account; |
| 115 | [self updateControlsWithTag:REGISTRATION_TAG]; |
| 116 | [self updateControlsWithTag:LOCALPORT_TAG]; |
| 117 | [self updateControlsWithTag:MINAUDIO_TAG]; |
| 118 | [self updateControlsWithTag:MAXAUDIO_TAG]; |
| 119 | [self updateControlsWithTag:MINVIDEO_TAG]; |
| 120 | [self updateControlsWithTag:MAXVIDEO_TAG]; |
| 121 | |
| 122 | [STUNserverURLField setStringValue:privateAccount->sipStunServer().toNSString()]; |
| 123 | [isUsingSTUN setState:privateAccount->isSipStunEnabled()?NSOnState:NSOffState]; |
| 124 | [STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()]; |
| 125 | |
| 126 | if(privateAccount->isPublishedSameAsLocal()) |
| 127 | [publishAddrAndPortRadioGroup selectCellAtRow:0 column:0]; |
| 128 | else { |
| 129 | [publishAddrAndPortRadioGroup selectCellAtRow:1 column:0]; |
| 130 | } |
| 131 | |
| 132 | [publishedAddrField setStringValue:privateAccount->publishedAddress().toNSString()]; |
| 133 | [publishedPortField setIntValue:privateAccount->publishedPort()]; |
| 134 | [publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()]; |
| 135 | [publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()]; |
| 136 | } |
| 137 | |
| 138 | #pragma mark - NSTextFieldDelegate methods |
| 139 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 140 | -(void)controlTextDidChange:(NSNotification *)notif |
| 141 | { |
| 142 | NSTextField *textField = [notif object]; |
| 143 | NSRange test = [[textField currentEditor] selectedRange]; |
| 144 | |
| 145 | [self valueDidChange:textField]; |
| 146 | //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selction change |
| 147 | [textField.window makeFirstResponder:textField]; |
| 148 | [[textField currentEditor] setSelectedRange:test]; |
| 149 | } |
| 150 | |
| 151 | - (IBAction) valueDidChange: (id) sender |
| 152 | { |
| 153 | switch ([sender tag]) { |
| 154 | case REGISTRATION_TAG: |
| 155 | privateAccount->setRegistrationExpire([sender integerValue]); |
| 156 | break; |
| 157 | case LOCALPORT_TAG: |
| 158 | privateAccount->setLocalPort([sender integerValue]); |
| 159 | break; |
| 160 | case STUNURL_TAG: |
| 161 | privateAccount->setSipStunServer([[sender stringValue] UTF8String]); |
| 162 | break; |
| 163 | case PUBLICADDR_TAG: |
| 164 | privateAccount->setPublishedAddress([[sender stringValue] UTF8String]); |
| 165 | break; |
| 166 | case PUBLICPORT_TAG: |
| 167 | privateAccount->setPublishedPort([sender integerValue]); |
| 168 | break; |
| 169 | case MINAUDIO_TAG: |
| 170 | privateAccount->setAudioPortMin([sender integerValue]); |
| 171 | break; |
| 172 | case MAXAUDIO_TAG: |
| 173 | privateAccount->setAudioPortMax([sender integerValue]); |
| 174 | break; |
| 175 | case MINVIDEO_TAG: |
| 176 | privateAccount->setVideoPortMin([sender integerValue]); |
| 177 | break; |
| 178 | case MAXVIDEO_TAG: |
| 179 | privateAccount->setVideoPortMax([sender integerValue]); |
| 180 | break; |
| 181 | default: |
| 182 | break; |
| 183 | } |
| 184 | [self updateControlsWithTag:[sender tag]]; |
| 185 | } |
| 186 | |
| 187 | - (IBAction)toggleSTUN:(NSButton *)sender |
| 188 | { |
| 189 | privateAccount->setSipStunEnabled([sender state]==NSOnState); |
| 190 | [STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()]; |
| 191 | } |
| 192 | |
| 193 | - (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix |
| 194 | { |
| 195 | NSInteger row = [matrix selectedRow]; |
| 196 | if(row == 0) { |
| 197 | privateAccount->setPublishedSameAsLocal(YES); |
| 198 | } else { |
| 199 | privateAccount->setPublishedSameAsLocal(NO); |
| 200 | } |
| 201 | [publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()]; |
| 202 | [publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()]; |
| 203 | |
| 204 | } |
| 205 | |
| 206 | - (void) updateControlsWithTag:(NSInteger) tag |
| 207 | { |
| 208 | switch (tag) { |
| 209 | case REGISTRATION_TAG: |
| 210 | [registrationStepper setIntegerValue:privateAccount->registrationExpire()]; |
| 211 | [registrationField setIntegerValue:privateAccount->registrationExpire()]; |
| 212 | break; |
| 213 | case LOCALPORT_TAG: |
| 214 | [localPortStepper setIntegerValue:privateAccount->localPort()]; |
| 215 | [localPortField setIntegerValue:privateAccount->localPort()]; |
| 216 | break; |
| 217 | case MINAUDIO_TAG: |
| 218 | [minAudioPortStepper setIntegerValue:privateAccount->audioPortMin()]; |
| 219 | [minAudioRTPRange setIntegerValue:privateAccount->audioPortMin()]; |
| 220 | break; |
| 221 | case MAXAUDIO_TAG: |
| 222 | [maxAudioPortStepper setIntegerValue:privateAccount->audioPortMax()]; |
| 223 | [maxAudioRTPRange setIntegerValue:privateAccount->audioPortMax()]; |
| 224 | break; |
| 225 | case MINVIDEO_TAG: |
| 226 | [minVideoPortStepper setIntegerValue:privateAccount->videoPortMin()]; |
| 227 | [minVideoRTPRange setIntegerValue:privateAccount->videoPortMin()]; |
| 228 | break; |
| 229 | case MAXVIDEO_TAG: |
| 230 | [maxVideoPortStepper setIntegerValue:privateAccount->videoPortMax()]; |
| 231 | [maxVideoRTPRange setIntegerValue:privateAccount->videoPortMax()]; |
| 232 | break; |
| 233 | default: |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | @end |