blob: e1d2592f7a3c733caa447ac9f495584a3fd05be7 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 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.
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040018 */
19#define REGISTRATION_TAG 0
20#define LOCALPORT_TAG 1
21#define STUNURL_TAG 2
22#define PUBLICADDR_TAG 3
23#define PUBLICPORT_TAG 4
24#define MINAUDIO_TAG 5
25#define MAXAUDIO_TAG 6
26#define MINVIDEO_TAG 7
27#define MAXVIDEO_TAG 8
28
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040029#define TURN_SERVER_TAG 9
30#define TURN_USERNAME_TAG 10
31#define TURN_PASSWORD_TAG 11
32#define TURN_REALM_TAG 12
33
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040034#import "AccAdvancedVC.h"
35
Alexandre Lision19a12302016-01-25 16:02:27 -050036///Qt
Alexandre Lision7f3164c2015-06-12 11:45:37 -040037#import <qitemselectionmodel.h>
38
Alexandre Lision19a12302016-01-25 16:02:27 -050039///LRC
40#import <accountmodel.h>
41#import <credentialmodel.h>
42#import <credential.h>
43
44
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040045@interface AccAdvancedVC ()
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040046@property (unsafe_unretained) IBOutlet NSView *registrationContainer;
47@property (unsafe_unretained) IBOutlet NSView *mainContainer;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040048
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040049@property (unsafe_unretained) IBOutlet NSTextField *registrationField;
50@property (unsafe_unretained) IBOutlet NSTextField *localPortField;
51@property (unsafe_unretained) IBOutlet NSButton *isUsingSTUN;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040052
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040053@property (unsafe_unretained) IBOutlet NSTextField *STUNserverURLField;
54@property (unsafe_unretained) IBOutlet NSTextField *minAudioRTPRange;
55@property (unsafe_unretained) IBOutlet NSTextField *maxAudioRTPRange;
56@property (unsafe_unretained) IBOutlet NSTextField *minVideoRTPRange;
57@property (unsafe_unretained) IBOutlet NSTextField *maxVideoRTPRange;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040058
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040059@property (unsafe_unretained) IBOutlet NSButton *isUsingTURN;
60@property (unsafe_unretained) IBOutlet NSTextField *turnServerURL;
61@property (unsafe_unretained) IBOutlet NSTextField *turnUsername;
62@property (unsafe_unretained) IBOutlet NSSecureTextField *turnPassword;
63@property (unsafe_unretained) IBOutlet NSTextField *turnRealm;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040064
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040065@property (unsafe_unretained) IBOutlet NSStepper *registrationStepper;
66@property (unsafe_unretained) IBOutlet NSStepper *localPortStepper;
67@property (unsafe_unretained) IBOutlet NSStepper *minAudioPortStepper;
68@property (unsafe_unretained) IBOutlet NSStepper *maxAudioPortStepper;
69@property (unsafe_unretained) IBOutlet NSStepper *minVideoPortStepper;
70@property (unsafe_unretained) IBOutlet NSStepper *maxVideoPortStepper;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040071
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040072@property (unsafe_unretained) IBOutlet NSMatrix *publishAddrAndPortRadioGroup;
73@property (unsafe_unretained) IBOutlet NSTextField *publishedAddrField;
74@property (unsafe_unretained) IBOutlet NSTextField *publishedPortField;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040075
76@end
77
78@implementation AccAdvancedVC
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040079@synthesize registrationField;
80@synthesize localPortField;
81@synthesize isUsingSTUN;
82@synthesize STUNserverURLField;
83@synthesize minAudioRTPRange;
84@synthesize maxAudioRTPRange;
85@synthesize minVideoRTPRange;
86@synthesize maxVideoRTPRange;
87@synthesize registrationStepper;
88@synthesize localPortStepper;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040089@synthesize turnPassword, isUsingTURN, turnRealm, turnServerURL, turnUsername;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040090@synthesize minAudioPortStepper;
91@synthesize maxAudioPortStepper;
92@synthesize minVideoPortStepper;
93@synthesize maxVideoPortStepper;
94@synthesize publishAddrAndPortRadioGroup;
95@synthesize publishedAddrField;
96@synthesize publishedPortField;
97
98- (void)awakeFromNib
99{
100 NSLog(@"INIT Advanced VC");
101 [registrationStepper setTag:REGISTRATION_TAG];
102 [localPortStepper setTag:LOCALPORT_TAG];
103 [minAudioPortStepper setTag:MINAUDIO_TAG];
104 [maxAudioPortStepper setTag:MAXAUDIO_TAG];
105 [minVideoPortStepper setTag:MINVIDEO_TAG];
106 [maxVideoPortStepper setTag:MAXVIDEO_TAG];
107
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400108 [turnServerURL setTag:TURN_SERVER_TAG];
109 [turnUsername setTag:TURN_USERNAME_TAG];
110 [turnPassword setTag:TURN_PASSWORD_TAG];
111 [turnRealm setTag:TURN_REALM_TAG];
112
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400113 [registrationField setTag:REGISTRATION_TAG];
114 [localPortField setTag:LOCALPORT_TAG];
115 [minAudioRTPRange setTag:MINAUDIO_TAG];
116 [maxAudioRTPRange setTag:MAXAUDIO_TAG];
117 [minVideoRTPRange setTag:MINVIDEO_TAG];
118 [maxVideoRTPRange setTag:MAXVIDEO_TAG];
119
120 [STUNserverURLField setTag:STUNURL_TAG];
121 [publishedPortField setTag:PUBLICPORT_TAG];
122 [publishedAddrField setTag:PUBLICADDR_TAG];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400123
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400124 QObject::connect(AccountModel::instance().selectionModel(),
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400125 &QItemSelectionModel::currentChanged,
126 [=](const QModelIndex &current, const QModelIndex &previous) {
127 if(!current.isValid())
128 return;
129 [self loadAccount];
130 });
131
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400132}
133
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400134- (Account*) currentAccount
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400135{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400136 auto accIdx = AccountModel::instance().selectionModel()->currentIndex();
137 return AccountModel::instance().getAccountByModelIndex(accIdx);
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400138}
139
140- (void)loadAccount
141{
142 auto account = [self currentAccount];
143
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400144 [self updateControlsWithTag:REGISTRATION_TAG];
145 [self updateControlsWithTag:LOCALPORT_TAG];
146 [self updateControlsWithTag:MINAUDIO_TAG];
147 [self updateControlsWithTag:MAXAUDIO_TAG];
148 [self updateControlsWithTag:MINVIDEO_TAG];
149 [self updateControlsWithTag:MAXVIDEO_TAG];
150
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400151 [STUNserverURLField setStringValue:account->sipStunServer().toNSString()];
152 [isUsingSTUN setState:account->isSipStunEnabled()?NSOnState:NSOffState];
153 [STUNserverURLField setEnabled:account->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400154
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400155 [isUsingTURN setState:account->isTurnEnabled()?NSOnState:NSOffState];
156 [self toggleTURN:isUsingTURN];
157 [turnServerURL setStringValue:account->turnServer().toNSString()];
Alexandre Lision19a12302016-01-25 16:02:27 -0500158
159 auto turnCreds = account->credentialModel()->primaryCredential(Credential::Type::TURN);
160
161 [turnUsername setStringValue:turnCreds->username().toNSString()];
162 [turnPassword setStringValue:turnCreds->password().toNSString()];
163 [turnRealm setStringValue:turnCreds->realm().toNSString()];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400164
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400165 if(account->isPublishedSameAsLocal())
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400166 [publishAddrAndPortRadioGroup selectCellAtRow:0 column:0];
167 else {
168 [publishAddrAndPortRadioGroup selectCellAtRow:1 column:0];
169 }
170
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400171 [publishedAddrField setStringValue:account->publishedAddress().toNSString()];
172 [publishedPortField setIntValue:account->publishedPort()];
173 [publishedAddrField setEnabled:!account->isPublishedSameAsLocal()];
174 [publishedPortField setEnabled:!account->isPublishedSameAsLocal()];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400175
176 if(account->protocol() == Account::Protocol::RING) {
177 [self.registrationContainer setHidden:YES];
178 } else {
179 [self.registrationContainer setHidden:NO];
180 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400181}
182
183#pragma mark - NSTextFieldDelegate methods
184
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400185-(void)controlTextDidChange:(NSNotification *)notif
186{
187 NSTextField *textField = [notif object];
188 NSRange test = [[textField currentEditor] selectedRange];
189
190 [self valueDidChange:textField];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400191 //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selection change
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400192 [textField.window makeFirstResponder:textField];
193 [[textField currentEditor] setSelectedRange:test];
194}
195
196- (IBAction) valueDidChange: (id) sender
197{
198 switch ([sender tag]) {
199 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400200 [self currentAccount]->setRegistrationExpire([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400201 break;
202 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400203 [self currentAccount]->setLocalPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400204 break;
205 case STUNURL_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400206 [self currentAccount]->setSipStunServer([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400207 break;
208 case PUBLICADDR_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400209 [self currentAccount]->setPublishedAddress([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400210 break;
211 case PUBLICPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400212 [self currentAccount]->setPublishedPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400213 break;
214 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400215 [self currentAccount]->setAudioPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400216 break;
217 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400218 [self currentAccount]->setAudioPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400219 break;
220 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400221 [self currentAccount]->setVideoPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400222 break;
223 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400224 [self currentAccount]->setVideoPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400225 break;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400226 case TURN_SERVER_TAG:
227 [self currentAccount]->setTurnServer([[sender stringValue] UTF8String]);
228 break;
229 case TURN_USERNAME_TAG:
Alexandre Lision19a12302016-01-25 16:02:27 -0500230 [self currentAccount]->credentialModel()->primaryCredential(Credential::Type::TURN)->setUsername([[sender stringValue] UTF8String]);
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400231 break;
232 case TURN_PASSWORD_TAG:
Alexandre Lision19a12302016-01-25 16:02:27 -0500233 [self currentAccount]->credentialModel()->primaryCredential(Credential::Type::TURN)->setPassword([[sender stringValue] UTF8String]);
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400234 break;
235 case TURN_REALM_TAG:
Alexandre Lision19a12302016-01-25 16:02:27 -0500236 [self currentAccount]->credentialModel()->primaryCredential(Credential::Type::TURN)->setRealm([[sender stringValue] UTF8String]);
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400237 break;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400238 default:
239 break;
240 }
241 [self updateControlsWithTag:[sender tag]];
242}
243
244- (IBAction)toggleSTUN:(NSButton *)sender
245{
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400246 [self currentAccount]->setSipStunEnabled([sender state]);
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400247 [STUNserverURLField setEnabled:[self currentAccount]->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400248}
249
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400250- (IBAction)toggleTURN:(id)sender {
251 [self currentAccount]->setTurnEnabled([sender state]);
252 [turnServerURL setEnabled:[sender state]];
253 [turnUsername setEnabled:[sender state]];
254 [turnPassword setEnabled:[sender state]];
255 [turnRealm setEnabled:[sender state]];
256}
257
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400258- (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix
259{
260 NSInteger row = [matrix selectedRow];
261 if(row == 0) {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400262 [self currentAccount]->setPublishedSameAsLocal(YES);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400263 } else {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400264 [self currentAccount]->setPublishedSameAsLocal(NO);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400265 }
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400266 [publishedAddrField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
267 [publishedPortField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400268
269}
270
271- (void) updateControlsWithTag:(NSInteger) tag
272{
273 switch (tag) {
274 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400275 [registrationStepper setIntegerValue:[self currentAccount]->registrationExpire()];
276 [registrationField setIntegerValue:[self currentAccount]->registrationExpire()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400277 break;
278 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400279 [localPortStepper setIntegerValue:[self currentAccount]->localPort()];
280 [localPortField setIntegerValue:[self currentAccount]->localPort()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400281 break;
282 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400283 [minAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMin()];
284 [minAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400285 break;
286 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400287 [maxAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMax()];
288 [maxAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400289 break;
290 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400291 [minVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMin()];
292 [minVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400293 break;
294 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400295 [maxVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMax()];
296 [maxVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400297 break;
298 default:
299 break;
300 }
301}
302
303@end