Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015-2018 Savoir-faire Linux Inc. |
| 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | #import "AccAdvancedRingVC.h" |
| 21 | |
| 22 | //LRC |
| 23 | #import <api/lrc.h> |
| 24 | #import <api/newaccountmodel.h> |
| 25 | #import <api/newdevicemodel.h> |
| 26 | |
| 27 | @interface AccAdvancedRingVC () { |
| 28 | __unsafe_unretained IBOutlet NSButton *allowIncoming; |
| 29 | __unsafe_unretained IBOutlet NSTextField *nameServerField; |
| 30 | __unsafe_unretained IBOutlet NSTextField *proxyServerField; |
| 31 | __unsafe_unretained IBOutlet NSTextField *bootstrapServerField; |
| 32 | __unsafe_unretained IBOutlet NSButton *enableProxyButton; |
| 33 | } |
| 34 | @end |
| 35 | |
| 36 | @implementation AccAdvancedRingVC |
| 37 | |
| 38 | //Tags for views |
| 39 | const NSInteger NAME_SERVER_TAG = 100; |
| 40 | const NSInteger PROXY_SERVER_TAG = 200; |
| 41 | const NSInteger BOOTSTRAP_SERVER_TAG = 300; |
| 42 | |
| 43 | -(void) updateView { |
| 44 | lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID); |
| 45 | [allowIncoming setState: accountProperties.allowIncoming]; |
| 46 | [nameServerField setStringValue: @(accountProperties.RingNS.uri.c_str())]; |
| 47 | [proxyServerField setStringValue:@(accountProperties.proxyServer.c_str())]; |
| 48 | [bootstrapServerField setStringValue:@(accountProperties.hostname.c_str())]; |
| 49 | [enableProxyButton setState: accountProperties.proxyEnabled]; |
| 50 | [proxyServerField setEditable:accountProperties.proxyEnabled]; |
| 51 | } |
| 52 | |
| 53 | -(void) viewDidLoad { |
| 54 | [super viewDidLoad]; |
Kateryna Kostiuk | a852594 | 2018-10-17 14:33:39 -0400 | [diff] [blame^] | 55 | [[self view] setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 56 | [self updateView]; |
| 57 | } |
| 58 | |
| 59 | - (void) setSelectedAccount:(std::string) account { |
| 60 | [super setSelectedAccount: account]; |
| 61 | [self updateView]; |
| 62 | } |
| 63 | |
| 64 | #pragma mark - Actions |
| 65 | |
| 66 | - (IBAction)allowCallFromUnknownPeer:(id)sender { |
| 67 | lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID); |
| 68 | if(accountProperties.allowIncoming != [sender state]) { |
| 69 | accountProperties.allowIncoming = [sender state]; |
| 70 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | - (IBAction)enableProxy:(id)sender { |
| 75 | lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID); |
| 76 | if(accountProperties.proxyEnabled != [sender state]) { |
| 77 | accountProperties.proxyEnabled = [sender state]; |
| 78 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 79 | } |
| 80 | [proxyServerField setEditable:[sender state]]; |
| 81 | } |
| 82 | |
| 83 | - (IBAction) valueDidChange: (id) sender |
| 84 | { |
| 85 | lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID); |
| 86 | |
| 87 | switch ([sender tag]) { |
| 88 | case NAME_SERVER_TAG: |
| 89 | if(accountProperties.RingNS.uri != [[sender stringValue] UTF8String]) { |
| 90 | accountProperties.RingNS.uri = [[sender stringValue] UTF8String]; |
| 91 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 92 | } |
| 93 | return; |
| 94 | case PROXY_SERVER_TAG: |
| 95 | if(accountProperties.proxyServer != [[sender stringValue] UTF8String]) { |
| 96 | accountProperties.proxyServer = [[sender stringValue] UTF8String]; |
| 97 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 98 | } |
| 99 | return; |
| 100 | case BOOTSTRAP_SERVER_TAG: |
| 101 | if(accountProperties.hostname != [[sender stringValue] UTF8String]) { |
| 102 | accountProperties.hostname = [[sender stringValue] UTF8String]; |
| 103 | self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties); |
| 104 | } |
| 105 | return; |
| 106 | default: |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | [super valueDidChange:sender]; |
| 111 | } |
| 112 | |
| 113 | #pragma mark - NSTextFieldDelegate methods |
| 114 | |
| 115 | -(void)controlTextDidChange:(NSNotification *)notif |
| 116 | { |
| 117 | NSTextField *textField = [notif object]; |
| 118 | NSRange test = [[textField currentEditor] selectedRange]; |
| 119 | |
| 120 | [self valueDidChange:textField]; |
| 121 | } |
| 122 | |
| 123 | @end |