Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 3 | * 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. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | #define ALIAS_TAG 0 |
| 31 | #define HOSTNAME_TAG 1 |
| 32 | #define USERNAME_TAG 2 |
| 33 | #define PASSWORD_TAG 3 |
| 34 | #define USERAGENT_TAG 4 |
| 35 | |
| 36 | |
| 37 | #import "AccGeneralVC.h" |
| 38 | |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 39 | #import <accountmodel.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 40 | #import <protocolmodel.h> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 41 | #import <qitemselectionmodel.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 42 | |
| 43 | @interface AccGeneralVC () |
| 44 | |
| 45 | @property Account* privateAccount; |
| 46 | |
| 47 | @property (assign) IBOutlet NSView *boxingAccount; |
| 48 | @property (assign) IBOutlet NSView *boxingParameters; |
| 49 | @property (assign) IBOutlet NSView *boxingCommon; |
| 50 | |
| 51 | @property (assign) IBOutlet NSTextField *aliasTextField; |
| 52 | @property (assign) IBOutlet NSTextField *typeLabel; |
| 53 | |
| 54 | @property (assign) IBOutlet NSTextField *serverHostTextField; |
| 55 | @property (assign) IBOutlet NSTextField *usernameTextField; |
| 56 | @property (assign) IBOutlet NSSecureTextField *passwordTextField; |
| 57 | |
| 58 | @property (assign) IBOutlet NSButton *upnpButton; |
| 59 | @property (assign) IBOutlet NSButton *autoAnswerButton; |
| 60 | @property (assign) IBOutlet NSButton *userAgentButton; |
| 61 | |
| 62 | @property (assign) IBOutlet NSTextField *userAgentTextField; |
| 63 | |
| 64 | @end |
| 65 | |
| 66 | @implementation AccGeneralVC |
| 67 | @synthesize typeLabel; |
| 68 | @synthesize boxingAccount; |
| 69 | @synthesize boxingParameters; |
| 70 | @synthesize boxingCommon; |
| 71 | @synthesize aliasTextField; |
| 72 | @synthesize serverHostTextField; |
| 73 | @synthesize usernameTextField; |
| 74 | @synthesize passwordTextField; |
| 75 | @synthesize upnpButton; |
| 76 | @synthesize autoAnswerButton; |
| 77 | @synthesize userAgentButton; |
| 78 | @synthesize userAgentTextField; |
| 79 | @synthesize privateAccount; |
| 80 | |
| 81 | - (void)awakeFromNib |
| 82 | { |
| 83 | NSLog(@"INIT General VC"); |
| 84 | [aliasTextField setTag:ALIAS_TAG]; |
| 85 | [serverHostTextField setTag:HOSTNAME_TAG]; |
| 86 | [usernameTextField setTag:USERNAME_TAG]; |
| 87 | [passwordTextField setTag:PASSWORD_TAG]; |
| 88 | [userAgentTextField setTag:USERAGENT_TAG]; |
| 89 | } |
| 90 | |
| 91 | - (IBAction)toggleUpnp:(NSButton *)sender { |
| 92 | privateAccount->setUpnpEnabled([sender state] == NSOnState); |
| 93 | } |
| 94 | |
| 95 | - (IBAction)toggleAutoAnswer:(NSButton *)sender { |
| 96 | privateAccount->setAutoAnswer([sender state] == NSOnState); |
| 97 | } |
| 98 | |
| 99 | - (IBAction)toggleCustomAgent:(NSButton *)sender { |
| 100 | [self.userAgentTextField setEnabled:[sender state] == NSOnState]; |
| 101 | privateAccount->setHasCustomUserAgent([sender state] == NSOnState); |
| 102 | } |
| 103 | |
| 104 | - (void)loadAccount:(Account *)account |
| 105 | { |
| 106 | |
| 107 | privateAccount = account; |
| 108 | |
| 109 | if([account->alias().toNSString() isEqualToString:@"IP2IP"]) { |
| 110 | [boxingAccount.subviews setValue:@YES forKeyPath:@"hidden"]; |
| 111 | [boxingParameters.subviews setValue:@YES forKeyPath:@"hidden"]; |
| 112 | |
| 113 | NSLog(@"IP@IP"); |
| 114 | // Put visible items at top of the frame |
| 115 | [boxingCommon setFrameOrigin:NSMakePoint(boxingAccount.frame.origin.x, |
| 116 | boxingAccount.frame.origin.y - 40)]; |
| 117 | [boxingCommon setNeedsDisplay:YES]; |
| 118 | |
| 119 | } else { |
| 120 | [boxingAccount.subviews setValue:@NO forKeyPath:@"hidden"]; |
| 121 | [boxingParameters.subviews setValue:@NO forKeyPath:@"hidden"]; |
| 122 | |
| 123 | [self.aliasTextField setStringValue:account->alias().toNSString()]; |
| 124 | [self.serverHostTextField setStringValue:account->hostname().toNSString()]; |
| 125 | [self.usernameTextField setStringValue:account->username().toNSString()]; |
| 126 | [self.passwordTextField setStringValue:account->password().toNSString()]; |
| 127 | } |
| 128 | |
| 129 | switch (account->protocol()) { |
| 130 | case Account::Protocol::SIP: |
| 131 | [self.typeLabel setStringValue:@"SIP"]; |
| 132 | break; |
| 133 | case Account::Protocol::IAX: |
| 134 | [self.typeLabel setStringValue:@"IAX"]; |
| 135 | break; |
| 136 | case Account::Protocol::RING: |
| 137 | [self.typeLabel setStringValue:@"RING"]; |
| 138 | break; |
| 139 | |
| 140 | default: |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | [upnpButton setState:privateAccount->isUpnpEnabled()]; |
| 145 | [userAgentButton setState:privateAccount->hasCustomUserAgent()]; |
| 146 | [userAgentTextField setEnabled:privateAccount->hasCustomUserAgent()]; |
| 147 | [self.autoAnswerButton setState:privateAccount->isAutoAnswer()]; |
| 148 | [self.userAgentTextField setStringValue:account->userAgent().toNSString()]; |
| 149 | } |
| 150 | |
| 151 | #pragma mark - NSTextFieldDelegate methods |
| 152 | |
| 153 | - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor |
| 154 | { |
| 155 | return YES; |
| 156 | } |
| 157 | |
| 158 | -(void)controlTextDidChange:(NSNotification *)notif |
| 159 | { |
| 160 | NSTextField *textField = [notif object]; |
| 161 | |
| 162 | switch ([textField tag]) { |
| 163 | case ALIAS_TAG: |
| 164 | privateAccount->setAlias([[textField stringValue] UTF8String]); |
| 165 | break; |
| 166 | case HOSTNAME_TAG: |
| 167 | privateAccount->setHostname([[textField stringValue] UTF8String]); |
| 168 | break; |
| 169 | case USERNAME_TAG: |
| 170 | privateAccount->setUsername([[textField stringValue] UTF8String]); |
| 171 | break; |
| 172 | case PASSWORD_TAG: |
| 173 | privateAccount->setPassword([[textField stringValue] UTF8String]); |
| 174 | break; |
| 175 | case USERAGENT_TAG: |
| 176 | privateAccount->setUserAgent([[textField stringValue] UTF8String]); |
| 177 | break; |
| 178 | default: |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | @end |