blob: 2c4b38ac09f0576a8dd32f1946658971bea9bbf5 [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 Lision7f3164c2015-06-12 11:45:37 -040036#import <accountmodel.h>
37#import <qitemselectionmodel.h>
38
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040039@interface AccAdvancedVC ()
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040040@property (unsafe_unretained) IBOutlet NSView *registrationContainer;
41@property (unsafe_unretained) IBOutlet NSView *mainContainer;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040042
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040043@property (unsafe_unretained) IBOutlet NSTextField *registrationField;
44@property (unsafe_unretained) IBOutlet NSTextField *localPortField;
45@property (unsafe_unretained) IBOutlet NSButton *isUsingSTUN;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040046
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040047@property (unsafe_unretained) IBOutlet NSTextField *STUNserverURLField;
48@property (unsafe_unretained) IBOutlet NSTextField *minAudioRTPRange;
49@property (unsafe_unretained) IBOutlet NSTextField *maxAudioRTPRange;
50@property (unsafe_unretained) IBOutlet NSTextField *minVideoRTPRange;
51@property (unsafe_unretained) IBOutlet NSTextField *maxVideoRTPRange;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040052
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040053@property (unsafe_unretained) IBOutlet NSButton *isUsingTURN;
54@property (unsafe_unretained) IBOutlet NSTextField *turnServerURL;
55@property (unsafe_unretained) IBOutlet NSTextField *turnUsername;
56@property (unsafe_unretained) IBOutlet NSSecureTextField *turnPassword;
57@property (unsafe_unretained) IBOutlet NSTextField *turnRealm;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040058
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040059@property (unsafe_unretained) IBOutlet NSStepper *registrationStepper;
60@property (unsafe_unretained) IBOutlet NSStepper *localPortStepper;
61@property (unsafe_unretained) IBOutlet NSStepper *minAudioPortStepper;
62@property (unsafe_unretained) IBOutlet NSStepper *maxAudioPortStepper;
63@property (unsafe_unretained) IBOutlet NSStepper *minVideoPortStepper;
64@property (unsafe_unretained) IBOutlet NSStepper *maxVideoPortStepper;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040065
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040066@property (unsafe_unretained) IBOutlet NSMatrix *publishAddrAndPortRadioGroup;
67@property (unsafe_unretained) IBOutlet NSTextField *publishedAddrField;
68@property (unsafe_unretained) IBOutlet NSTextField *publishedPortField;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040069
70@end
71
72@implementation AccAdvancedVC
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040073@synthesize registrationField;
74@synthesize localPortField;
75@synthesize isUsingSTUN;
76@synthesize STUNserverURLField;
77@synthesize minAudioRTPRange;
78@synthesize maxAudioRTPRange;
79@synthesize minVideoRTPRange;
80@synthesize maxVideoRTPRange;
81@synthesize registrationStepper;
82@synthesize localPortStepper;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -040083@synthesize turnPassword, isUsingTURN, turnRealm, turnServerURL, turnUsername;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040084@synthesize minAudioPortStepper;
85@synthesize maxAudioPortStepper;
86@synthesize minVideoPortStepper;
87@synthesize maxVideoPortStepper;
88@synthesize publishAddrAndPortRadioGroup;
89@synthesize publishedAddrField;
90@synthesize publishedPortField;
91
92- (void)awakeFromNib
93{
94 NSLog(@"INIT Advanced VC");
95 [registrationStepper setTag:REGISTRATION_TAG];
96 [localPortStepper setTag:LOCALPORT_TAG];
97 [minAudioPortStepper setTag:MINAUDIO_TAG];
98 [maxAudioPortStepper setTag:MAXAUDIO_TAG];
99 [minVideoPortStepper setTag:MINVIDEO_TAG];
100 [maxVideoPortStepper setTag:MAXVIDEO_TAG];
101
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400102 [turnServerURL setTag:TURN_SERVER_TAG];
103 [turnUsername setTag:TURN_USERNAME_TAG];
104 [turnPassword setTag:TURN_PASSWORD_TAG];
105 [turnRealm setTag:TURN_REALM_TAG];
106
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400107 [registrationField setTag:REGISTRATION_TAG];
108 [localPortField setTag:LOCALPORT_TAG];
109 [minAudioRTPRange setTag:MINAUDIO_TAG];
110 [maxAudioRTPRange setTag:MAXAUDIO_TAG];
111 [minVideoRTPRange setTag:MINVIDEO_TAG];
112 [maxVideoRTPRange setTag:MAXVIDEO_TAG];
113
114 [STUNserverURLField setTag:STUNURL_TAG];
115 [publishedPortField setTag:PUBLICPORT_TAG];
116 [publishedAddrField setTag:PUBLICADDR_TAG];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400117
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400118 QObject::connect(AccountModel::instance().selectionModel(),
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400119 &QItemSelectionModel::currentChanged,
120 [=](const QModelIndex &current, const QModelIndex &previous) {
121 if(!current.isValid())
122 return;
123 [self loadAccount];
124 });
125
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400126}
127
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400128- (Account*) currentAccount
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400129{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400130 auto accIdx = AccountModel::instance().selectionModel()->currentIndex();
131 return AccountModel::instance().getAccountByModelIndex(accIdx);
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400132}
133
134- (void)loadAccount
135{
136 auto account = [self currentAccount];
137
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400138 [self updateControlsWithTag:REGISTRATION_TAG];
139 [self updateControlsWithTag:LOCALPORT_TAG];
140 [self updateControlsWithTag:MINAUDIO_TAG];
141 [self updateControlsWithTag:MAXAUDIO_TAG];
142 [self updateControlsWithTag:MINVIDEO_TAG];
143 [self updateControlsWithTag:MAXVIDEO_TAG];
144
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400145 [STUNserverURLField setStringValue:account->sipStunServer().toNSString()];
146 [isUsingSTUN setState:account->isSipStunEnabled()?NSOnState:NSOffState];
147 [STUNserverURLField setEnabled:account->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400148
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400149 [isUsingTURN setState:account->isTurnEnabled()?NSOnState:NSOffState];
150 [self toggleTURN:isUsingTURN];
151 [turnServerURL setStringValue:account->turnServer().toNSString()];
152 [turnUsername setStringValue:account->turnServerUsername().toNSString()];
153 [turnPassword setStringValue:account->turnServerPassword().toNSString()];
154 [turnRealm setStringValue:account->turnServerRealm().toNSString()];
155
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400156 if(account->isPublishedSameAsLocal())
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400157 [publishAddrAndPortRadioGroup selectCellAtRow:0 column:0];
158 else {
159 [publishAddrAndPortRadioGroup selectCellAtRow:1 column:0];
160 }
161
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400162 [publishedAddrField setStringValue:account->publishedAddress().toNSString()];
163 [publishedPortField setIntValue:account->publishedPort()];
164 [publishedAddrField setEnabled:!account->isPublishedSameAsLocal()];
165 [publishedPortField setEnabled:!account->isPublishedSameAsLocal()];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400166
167 if(account->protocol() == Account::Protocol::RING) {
168 [self.registrationContainer setHidden:YES];
169 } else {
170 [self.registrationContainer setHidden:NO];
171 }
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400172}
173
174#pragma mark - NSTextFieldDelegate methods
175
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400176-(void)controlTextDidChange:(NSNotification *)notif
177{
178 NSTextField *textField = [notif object];
179 NSRange test = [[textField currentEditor] selectedRange];
180
181 [self valueDidChange:textField];
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400182 //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selection change
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400183 [textField.window makeFirstResponder:textField];
184 [[textField currentEditor] setSelectedRange:test];
185}
186
187- (IBAction) valueDidChange: (id) sender
188{
189 switch ([sender tag]) {
190 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400191 [self currentAccount]->setRegistrationExpire([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400192 break;
193 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400194 [self currentAccount]->setLocalPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400195 break;
196 case STUNURL_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400197 [self currentAccount]->setSipStunServer([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400198 break;
199 case PUBLICADDR_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400200 [self currentAccount]->setPublishedAddress([[sender stringValue] UTF8String]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400201 break;
202 case PUBLICPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400203 [self currentAccount]->setPublishedPort([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400204 break;
205 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400206 [self currentAccount]->setAudioPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400207 break;
208 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400209 [self currentAccount]->setAudioPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400210 break;
211 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400212 [self currentAccount]->setVideoPortMin([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400213 break;
214 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400215 [self currentAccount]->setVideoPortMax([sender integerValue]);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400216 break;
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400217 case TURN_SERVER_TAG:
218 [self currentAccount]->setTurnServer([[sender stringValue] UTF8String]);
219 break;
220 case TURN_USERNAME_TAG:
221 [self currentAccount]->setTurnServerUsername([[sender stringValue] UTF8String]);
222 break;
223 case TURN_PASSWORD_TAG:
224 [self currentAccount]->setTurnServerPassword([[sender stringValue] UTF8String]);
225 break;
226 case TURN_REALM_TAG:
227 [self currentAccount]->setTurnServerRealm([[sender stringValue] UTF8String]);
228 break;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400229 default:
230 break;
231 }
232 [self updateControlsWithTag:[sender tag]];
233}
234
235- (IBAction)toggleSTUN:(NSButton *)sender
236{
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400237 [self currentAccount]->setSipStunEnabled([sender state]);
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400238 [STUNserverURLField setEnabled:[self currentAccount]->isSipStunEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400239}
240
Alexandre Lision9ddfd8d2015-08-10 15:11:16 -0400241- (IBAction)toggleTURN:(id)sender {
242 [self currentAccount]->setTurnEnabled([sender state]);
243 [turnServerURL setEnabled:[sender state]];
244 [turnUsername setEnabled:[sender state]];
245 [turnPassword setEnabled:[sender state]];
246 [turnRealm setEnabled:[sender state]];
247}
248
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400249- (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix
250{
251 NSInteger row = [matrix selectedRow];
252 if(row == 0) {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400253 [self currentAccount]->setPublishedSameAsLocal(YES);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400254 } else {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400255 [self currentAccount]->setPublishedSameAsLocal(NO);
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400256 }
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400257 [publishedAddrField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
258 [publishedPortField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400259
260}
261
262- (void) updateControlsWithTag:(NSInteger) tag
263{
264 switch (tag) {
265 case REGISTRATION_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400266 [registrationStepper setIntegerValue:[self currentAccount]->registrationExpire()];
267 [registrationField setIntegerValue:[self currentAccount]->registrationExpire()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400268 break;
269 case LOCALPORT_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400270 [localPortStepper setIntegerValue:[self currentAccount]->localPort()];
271 [localPortField setIntegerValue:[self currentAccount]->localPort()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400272 break;
273 case MINAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400274 [minAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMin()];
275 [minAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400276 break;
277 case MAXAUDIO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400278 [maxAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMax()];
279 [maxAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400280 break;
281 case MINVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400282 [minVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMin()];
283 [minVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMin()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400284 break;
285 case MAXVIDEO_TAG:
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400286 [maxVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMax()];
287 [maxVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMax()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400288 break;
289 default:
290 break;
291 }
292}
293
294@end