AccAdvancedVC.mm 8.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
/*
 *  Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
 *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */
#define REGISTRATION_TAG 0
#define LOCALPORT_TAG 1
#define STUNURL_TAG 2
#define PUBLICADDR_TAG 3
#define PUBLICPORT_TAG 4
#define MINAUDIO_TAG 5
#define MAXAUDIO_TAG 6
#define MINVIDEO_TAG 7
#define MAXVIDEO_TAG 8

#import "AccAdvancedVC.h"

@interface AccAdvancedVC ()

@property Account* privateAccount;
@property (assign) IBOutlet NSTextField *registrationField;
@property (assign) IBOutlet NSTextField *localPortField;
@property (assign) IBOutlet NSButton *isUsingSTUN;

@property (assign) IBOutlet NSTextField *STUNserverURLField;
@property (assign) IBOutlet NSTextField *minAudioRTPRange;
@property (assign) IBOutlet NSTextField *maxAudioRTPRange;
@property (assign) IBOutlet NSTextField *minVideoRTPRange;
@property (assign) IBOutlet NSTextField *maxVideoRTPRange;


@property (assign) IBOutlet NSStepper *registrationStepper;
@property (assign) IBOutlet NSStepper *localPortStepper;
@property (assign) IBOutlet NSStepper *minAudioPortStepper;
@property (assign) IBOutlet NSStepper *maxAudioPortStepper;
@property (assign) IBOutlet NSStepper *minVideoPortStepper;
@property (assign) IBOutlet NSStepper *maxVideoPortStepper;

@property (assign) IBOutlet NSMatrix *publishAddrAndPortRadioGroup;
@property (assign) IBOutlet NSTextField *publishedAddrField;
@property (assign) IBOutlet NSTextField *publishedPortField;

@end

@implementation AccAdvancedVC
@synthesize privateAccount;
@synthesize registrationField;
@synthesize localPortField;
@synthesize isUsingSTUN;
@synthesize STUNserverURLField;
@synthesize minAudioRTPRange;
@synthesize maxAudioRTPRange;
@synthesize minVideoRTPRange;
@synthesize maxVideoRTPRange;
@synthesize registrationStepper;
@synthesize localPortStepper;
@synthesize minAudioPortStepper;
@synthesize maxAudioPortStepper;
@synthesize minVideoPortStepper;
@synthesize maxVideoPortStepper;
@synthesize publishAddrAndPortRadioGroup;
@synthesize publishedAddrField;
@synthesize publishedPortField;

- (void)awakeFromNib
{
    NSLog(@"INIT Advanced VC");
    [registrationStepper setTag:REGISTRATION_TAG];
    [localPortStepper setTag:LOCALPORT_TAG];
    [minAudioPortStepper setTag:MINAUDIO_TAG];
    [maxAudioPortStepper setTag:MAXAUDIO_TAG];
    [minVideoPortStepper setTag:MINVIDEO_TAG];
    [maxVideoPortStepper setTag:MAXVIDEO_TAG];

    [registrationField setTag:REGISTRATION_TAG];
    [localPortField setTag:LOCALPORT_TAG];
    [minAudioRTPRange setTag:MINAUDIO_TAG];
    [maxAudioRTPRange setTag:MAXAUDIO_TAG];
    [minVideoRTPRange setTag:MINVIDEO_TAG];
    [maxVideoRTPRange setTag:MAXVIDEO_TAG];

    [STUNserverURLField setTag:STUNURL_TAG];
    [publishedPortField setTag:PUBLICPORT_TAG];
    [publishedAddrField setTag:PUBLICADDR_TAG];
    
}

- (void)loadAccount:(Account *)account
{
    privateAccount = account;
    [self updateControlsWithTag:REGISTRATION_TAG];
    [self updateControlsWithTag:LOCALPORT_TAG];
    [self updateControlsWithTag:MINAUDIO_TAG];
    [self updateControlsWithTag:MAXAUDIO_TAG];
    [self updateControlsWithTag:MINVIDEO_TAG];
    [self updateControlsWithTag:MAXVIDEO_TAG];

    [STUNserverURLField setStringValue:privateAccount->sipStunServer().toNSString()];
    [isUsingSTUN setState:privateAccount->isSipStunEnabled()?NSOnState:NSOffState];
    [STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()];

    if(privateAccount->isPublishedSameAsLocal())
        [publishAddrAndPortRadioGroup selectCellAtRow:0 column:0];
    else {
        [publishAddrAndPortRadioGroup selectCellAtRow:1 column:0];
    }

    [publishedAddrField setStringValue:privateAccount->publishedAddress().toNSString()];
    [publishedPortField setIntValue:privateAccount->publishedPort()];
    [publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()];
    [publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()];
}

#pragma mark - NSTextFieldDelegate methods

-(void)controlTextDidChange:(NSNotification *)notif
{
    NSTextField *textField = [notif object];
    NSRange test = [[textField currentEditor] selectedRange];

    [self valueDidChange:textField];
    //FIXME: saving account lose focus because in NSTreeController we remove and reinsert row so View selction change
    [textField.window makeFirstResponder:textField];
    [[textField currentEditor] setSelectedRange:test];
}

- (IBAction) valueDidChange: (id) sender
{
    switch ([sender tag]) {
        case REGISTRATION_TAG:
            privateAccount->setRegistrationExpire([sender integerValue]);
            break;
        case LOCALPORT_TAG:
            privateAccount->setLocalPort([sender integerValue]);
            break;
        case STUNURL_TAG:
            privateAccount->setSipStunServer([[sender stringValue] UTF8String]);
            break;
        case PUBLICADDR_TAG:
            privateAccount->setPublishedAddress([[sender stringValue] UTF8String]);
            break;
        case PUBLICPORT_TAG:
            privateAccount->setPublishedPort([sender integerValue]);
            break;
        case MINAUDIO_TAG:
            privateAccount->setAudioPortMin([sender integerValue]);
            break;
        case MAXAUDIO_TAG:
            privateAccount->setAudioPortMax([sender integerValue]);
            break;
        case MINVIDEO_TAG:
            privateAccount->setVideoPortMin([sender integerValue]);
            break;
        case MAXVIDEO_TAG:
            privateAccount->setVideoPortMax([sender integerValue]);
            break;
        default:
            break;
    }
    [self updateControlsWithTag:[sender tag]];
}

- (IBAction)toggleSTUN:(NSButton *)sender
{
    privateAccount->setSipStunEnabled([sender state]==NSOnState);
    [STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()];
}

- (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix
{
    NSInteger row = [matrix selectedRow];
    if(row == 0) {
        privateAccount->setPublishedSameAsLocal(YES);
    } else {
        privateAccount->setPublishedSameAsLocal(NO);
    }
    [publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()];
    [publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()];

}

- (void) updateControlsWithTag:(NSInteger) tag
{
    switch (tag) {
        case REGISTRATION_TAG:
            [registrationStepper setIntegerValue:privateAccount->registrationExpire()];
            [registrationField setIntegerValue:privateAccount->registrationExpire()];
            break;
        case LOCALPORT_TAG:
            [localPortStepper setIntegerValue:privateAccount->localPort()];
            [localPortField setIntegerValue:privateAccount->localPort()];
            break;
        case MINAUDIO_TAG:
            [minAudioPortStepper setIntegerValue:privateAccount->audioPortMin()];
            [minAudioRTPRange setIntegerValue:privateAccount->audioPortMin()];
            break;
        case MAXAUDIO_TAG:
            [maxAudioPortStepper setIntegerValue:privateAccount->audioPortMax()];
            [maxAudioRTPRange setIntegerValue:privateAccount->audioPortMax()];
            break;
        case MINVIDEO_TAG:
            [minVideoPortStepper setIntegerValue:privateAccount->videoPortMin()];
            [minVideoRTPRange setIntegerValue:privateAccount->videoPortMin()];
            break;
        case MAXVIDEO_TAG:
            [maxVideoPortStepper setIntegerValue:privateAccount->videoPortMax()];
            [maxVideoRTPRange setIntegerValue:privateAccount->videoPortMax()];
            break;
        default:
            break;
    }
}

@end