blob: 8a3d08e4589f23ce11bad4c535ae81490ebd5b3c [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -04002 * Copyright (C) 2015 Savoir-faire Linux Inc.
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04003 * 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
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040040#define TURN_SERVER_TAG 9
41#define TURN_USERNAME_TAG 10
42#define TURN_PASSWORD_TAG 11
43#define TURN_REALM_TAG 12
44
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040045#import "AccAdvancedVC.h"
46
Alexandre Lision7f3164c2015-06-12 11:45:37 -040047#import <accountmodel.h>
48#import <qitemselectionmodel.h>
49
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040050@interface AccAdvancedVC ()
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040051@property (unsafe_unretained) IBOutlet NSView *registrationContainer;
52@property (unsafe_unretained) IBOutlet NSView *mainContainer;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040053
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040054@property (unsafe_unretained) IBOutlet NSTextField *registrationField;
55@property (unsafe_unretained) IBOutlet NSTextField *localPortField;
56@property (unsafe_unretained) IBOutlet NSButton *isUsingSTUN;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040057
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040058@property (unsafe_unretained) IBOutlet NSTextField *STUNserverURLField;
59@property (unsafe_unretained) IBOutlet NSTextField *minAudioRTPRange;
60@property (unsafe_unretained) IBOutlet NSTextField *maxAudioRTPRange;
61@property (unsafe_unretained) IBOutlet NSTextField *minVideoRTPRange;
62@property (unsafe_unretained) IBOutlet NSTextField *maxVideoRTPRange;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040063
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040064@property (unsafe_unretained) IBOutlet NSButton *isUsingTURN;
65@property (unsafe_unretained) IBOutlet NSTextField *turnServerURL;
66@property (unsafe_unretained) IBOutlet NSTextField *turnUsername;
67@property (unsafe_unretained) IBOutlet NSSecureTextField *turnPassword;
68@property (unsafe_unretained) IBOutlet NSTextField *turnRealm;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040069
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040070@property (unsafe_unretained) IBOutlet NSStepper *registrationStepper;
71@property (unsafe_unretained) IBOutlet NSStepper *localPortStepper;
72@property (unsafe_unretained) IBOutlet NSStepper *minAudioPortStepper;
73@property (unsafe_unretained) IBOutlet NSStepper *maxAudioPortStepper;
74@property (unsafe_unretained) IBOutlet NSStepper *minVideoPortStepper;
75@property (unsafe_unretained) IBOutlet NSStepper *maxVideoPortStepper;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040076
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040077@property (unsafe_unretained) IBOutlet NSMatrix *publishAddrAndPortRadioGroup;
78@property (unsafe_unretained) IBOutlet NSTextField *publishedAddrField;
79@property (unsafe_unretained) IBOutlet NSTextField *publishedPortField;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040080
81@end
82
83@implementation AccAdvancedVC
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040084@synthesize registrationField;
85@synthesize localPortField;
86@synthesize isUsingSTUN;
87@synthesize STUNserverURLField;
88@synthesize minAudioRTPRange;
89@synthesize maxAudioRTPRange;
90@synthesize minVideoRTPRange;
91@synthesize maxVideoRTPRange;
92@synthesize registrationStepper;
93@synthesize localPortStepper;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040094@synthesize turnPassword, isUsingTURN, turnRealm, turnServerURL, turnUsername;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040095@synthesize minAudioPortStepper;
96@synthesize maxAudioPortStepper;
97@synthesize minVideoPortStepper;
98@synthesize maxVideoPortStepper;
99@synthesize publishAddrAndPortRadioGroup;
100@synthesize publishedAddrField;
101@synthesize publishedPortField;
102
103- (void)awakeFromNib
104{
105 NSLog(@"INIT Advanced VC");
106 [registrationStepper setTag:REGISTRATION_TAG];
107 [localPortStepper setTag:LOCALPORT_TAG];
108 [minAudioPortStepper setTag:MINAUDIO_TAG];
109 [maxAudioPortStepper setTag:MAXAUDIO_TAG];
110 [minVideoPortStepper setTag:MINVIDEO_TAG];
111 [maxVideoPortStepper setTag:MAXVIDEO_TAG];
112
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400113 [turnServerURL setTag:TURN_SERVER_TAG];
114 [turnUsername setTag:TURN_USERNAME_TAG];
115 [turnPassword setTag:TURN_PASSWORD_TAG];
116 [turnRealm setTag:TURN_REALM_TAG];
117
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400118 [registrationField setTag:REGISTRATION_TAG];
119 [localPortField setTag:LOCALPORT_TAG];
120 [minAudioRTPRange setTag:MINAUDIO_TAG];
121 [maxAudioRTPRange setTag:MAXAUDIO_TAG];
122 [minVideoRTPRange setTag:MINVIDEO_TAG];
123 [maxVideoRTPRange setTag:MAXVIDEO_TAG];
124
125 [STUNserverURLField setTag:STUNURL_TAG];
126 [publishedPortField setTag:PUBLICPORT_TAG];
127 [publishedAddrField setTag:PUBLICADDR_TAG];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400128
129 QObject::connect(AccountModel::instance()->selectionModel(),
130 &QItemSelectionModel::currentChanged,
131 [=](const QModelIndex &current, const QModelIndex &previous) {
132 if(!current.isValid())
133 return;
134 [self loadAccount];
135 });
136
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400137}
138
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400139- (Account*) currentAccount
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400140{
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400141 auto accIdx = AccountModel::instance()->selectionModel()->currentIndex();
142 return AccountModel::instance()->getAccountByModelIndex(accIdx);
143}
144
145- (void)loadAccount
146{
147 auto account = [self currentAccount];
148
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400149 [self updateControlsWithTag:REGISTRATION_TAG];
150 [self updateControlsWithTag:LOCALPORT_TAG];
151 [self updateControlsWithTag:MINAUDIO_TAG];
152 [self updateControlsWithTag:MAXAUDIO_TAG];
153 [self updateControlsWithTag:MINVIDEO_TAG];
154 [self updateControlsWithTag:MAXVIDEO_TAG];
155
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400156 [STUNserverURLField setStringValue:account->sipStunServer().toNSString()];
157 [isUsingSTUN setState:account->isSipStunEnabled()?NSOnState:NSOffState];
158 [STUNserverURLField setEnabled:account->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400159
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400160 [isUsingTURN setState:account->isTurnEnabled()?NSOnState:NSOffState];
161 [self toggleTURN:isUsingTURN];
162 [turnServerURL setStringValue:account->turnServer().toNSString()];
163 [turnUsername setStringValue:account->turnServerUsername().toNSString()];
164 [turnPassword setStringValue:account->turnServerPassword().toNSString()];
165 [turnRealm setStringValue:account->turnServerRealm().toNSString()];
166
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400167 if(account->isPublishedSameAsLocal())
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400168 [publishAddrAndPortRadioGroup selectCellAtRow:0 column:0];
169 else {
170 [publishAddrAndPortRadioGroup selectCellAtRow:1 column:0];
171 }
172
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400173 [publishedAddrField setStringValue:account->publishedAddress().toNSString()];
174 [publishedPortField setIntValue:account->publishedPort()];
175 [publishedAddrField setEnabled:!account->isPublishedSameAsLocal()];
176 [publishedPortField setEnabled:!account->isPublishedSameAsLocal()];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400177
178 if(account->protocol() == Account::Protocol::RING) {
179 [self.registrationContainer setHidden:YES];
180 } else {
181 [self.registrationContainer setHidden:NO];
182 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400183}
184
185#pragma mark - NSTextFieldDelegate methods
186
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400187-(void)controlTextDidChange:(NSNotification *)notif
188{
189 NSTextField *textField = [notif object];
190 NSRange test = [[textField currentEditor] selectedRange];
191
192 [self valueDidChange:textField];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400193 //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selection change
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400194 [textField.window makeFirstResponder:textField];
195 [[textField currentEditor] setSelectedRange:test];
196}
197
198- (IBAction) valueDidChange: (id) sender
199{
200 switch ([sender tag]) {
201 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400202 [self currentAccount]->setRegistrationExpire([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400203 break;
204 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400205 [self currentAccount]->setLocalPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400206 break;
207 case STUNURL_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400208 [self currentAccount]->setSipStunServer([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400209 break;
210 case PUBLICADDR_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400211 [self currentAccount]->setPublishedAddress([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400212 break;
213 case PUBLICPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400214 [self currentAccount]->setPublishedPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400215 break;
216 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400217 [self currentAccount]->setAudioPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400218 break;
219 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400220 [self currentAccount]->setAudioPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400221 break;
222 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400223 [self currentAccount]->setVideoPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400224 break;
225 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400226 [self currentAccount]->setVideoPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400227 break;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400228 case TURN_SERVER_TAG:
229 [self currentAccount]->setTurnServer([[sender stringValue] UTF8String]);
230 break;
231 case TURN_USERNAME_TAG:
232 [self currentAccount]->setTurnServerUsername([[sender stringValue] UTF8String]);
233 break;
234 case TURN_PASSWORD_TAG:
235 [self currentAccount]->setTurnServerPassword([[sender stringValue] UTF8String]);
236 break;
237 case TURN_REALM_TAG:
238 [self currentAccount]->setTurnServerRealm([[sender stringValue] UTF8String]);
239 break;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400240 default:
241 break;
242 }
243 [self updateControlsWithTag:[sender tag]];
244}
245
246- (IBAction)toggleSTUN:(NSButton *)sender
247{
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400248 [self currentAccount]->setSipStunEnabled([sender state]);
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400249 [STUNserverURLField setEnabled:[self currentAccount]->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400250}
251
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400252- (IBAction)toggleTURN:(id)sender {
253 [self currentAccount]->setTurnEnabled([sender state]);
254 [turnServerURL setEnabled:[sender state]];
255 [turnUsername setEnabled:[sender state]];
256 [turnPassword setEnabled:[sender state]];
257 [turnRealm setEnabled:[sender state]];
258}
259
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400260- (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix
261{
262 NSInteger row = [matrix selectedRow];
263 if(row == 0) {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400264 [self currentAccount]->setPublishedSameAsLocal(YES);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400265 } else {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400266 [self currentAccount]->setPublishedSameAsLocal(NO);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400267 }
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400268 [publishedAddrField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
269 [publishedPortField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400270
271}
272
273- (void) updateControlsWithTag:(NSInteger) tag
274{
275 switch (tag) {
276 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400277 [registrationStepper setIntegerValue:[self currentAccount]->registrationExpire()];
278 [registrationField setIntegerValue:[self currentAccount]->registrationExpire()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400279 break;
280 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400281 [localPortStepper setIntegerValue:[self currentAccount]->localPort()];
282 [localPortField setIntegerValue:[self currentAccount]->localPort()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400283 break;
284 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400285 [minAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMin()];
286 [minAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400287 break;
288 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400289 [maxAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMax()];
290 [maxAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400291 break;
292 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400293 [minVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMin()];
294 [minVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400295 break;
296 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400297 [maxVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMax()];
298 [maxVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400299 break;
300 default:
301 break;
302 }
303}
304
305@end