AccAdvancedRingVC.mm 4.68 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
/*
 *  Copyright (C) 2015-2018 Savoir-faire Linux Inc.
 *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
 *  Author: Kateryna Kostiuk <kateryna.kostiuk@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.
 */
#import "AccAdvancedRingVC.h"

//LRC
#import <api/lrc.h>
#import <api/newaccountmodel.h>
#import <api/newdevicemodel.h>

@interface AccAdvancedRingVC () {
    __unsafe_unretained IBOutlet NSButton *allowIncoming;
    __unsafe_unretained IBOutlet NSTextField *nameServerField;
    __unsafe_unretained IBOutlet NSTextField *proxyServerField;
    __unsafe_unretained IBOutlet NSTextField *bootstrapServerField;
    __unsafe_unretained IBOutlet NSButton *enableProxyButton;
}
@end

@implementation AccAdvancedRingVC

//Tags for views
const NSInteger  NAME_SERVER_TAG         = 100;
const NSInteger  PROXY_SERVER_TAG        = 200;
const NSInteger  BOOTSTRAP_SERVER_TAG    = 300;

-(void) updateView {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    [allowIncoming setState: accountProperties.allowIncoming];
    [nameServerField setStringValue: @(accountProperties.RingNS.uri.c_str())];
    [proxyServerField setStringValue:@(accountProperties.proxyServer.c_str())];
    [bootstrapServerField setStringValue:@(accountProperties.hostname.c_str())];
    [enableProxyButton setState: accountProperties.proxyEnabled];
    [proxyServerField setEditable:accountProperties.proxyEnabled];
}

-(void) viewDidLoad {
    [super viewDidLoad];
55
    [[self view] setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin];
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
    [self updateView];
}

- (void) setSelectedAccount:(std::string) account {
    [super setSelectedAccount: account];
    [self updateView];
}

#pragma mark - Actions

- (IBAction)allowCallFromUnknownPeer:(id)sender {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.allowIncoming != [sender state]) {
        accountProperties.allowIncoming = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}

- (IBAction)enableProxy:(id)sender {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.proxyEnabled != [sender state]) {
        accountProperties.proxyEnabled = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
    [proxyServerField setEditable:[sender state]];
}

- (IBAction) valueDidChange: (id) sender
{
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);

    switch ([sender tag]) {
        case NAME_SERVER_TAG:
            if(accountProperties.RingNS.uri != [[sender stringValue] UTF8String]) {
                accountProperties.RingNS.uri = [[sender stringValue] UTF8String];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
            }
            return;
        case PROXY_SERVER_TAG:
            if(accountProperties.proxyServer != [[sender stringValue] UTF8String]) {
                accountProperties.proxyServer = [[sender stringValue] UTF8String];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
            }
            return;
        case BOOTSTRAP_SERVER_TAG:
            if(accountProperties.hostname != [[sender stringValue] UTF8String]) {
                accountProperties.hostname = [[sender stringValue] UTF8String];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
            }
            return;
        default:
            break;
    }

    [super valueDidChange:sender];
}

#pragma mark - NSTextFieldDelegate methods

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

    [self valueDidChange:textField];
}

@end