blob: 88a5f6a71dcd3bfc0015981b0aa9c0c151584981 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
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#import "AccRingVC.h"
37
38@interface AccRingVC ()
39
40@property Account* privateAccount;
41
42@property (assign) IBOutlet NSTextField *aliasTextField;
43@property (assign) IBOutlet NSTextField *typeLabel;
44@property (assign) IBOutlet NSTextField *bootstrapField;
45@property (assign) IBOutlet NSTextField *hashField;
46
47@property (assign) IBOutlet NSButton *upnpButton;
48@property (assign) IBOutlet NSButton *autoAnswerButton;
49@property (assign) IBOutlet NSButton *userAgentButton;
50@property (assign) IBOutlet NSTextField *userAgentTextField;
51
52@end
53
54@implementation AccRingVC
55@synthesize privateAccount;
56@synthesize typeLabel;
57@synthesize bootstrapField;
58@synthesize hashField;
59@synthesize aliasTextField;
60@synthesize upnpButton;
61@synthesize autoAnswerButton;
62@synthesize userAgentButton;
63@synthesize userAgentTextField;
64
65- (void)awakeFromNib
66{
67 NSLog(@"INIT Ring VC");
68 [aliasTextField setTag:ALIAS_TAG];
69 [userAgentTextField setTag:USERAGENT_TAG];
70 [bootstrapField setTag:HOSTNAME_TAG];
71}
72
73- (void)loadAccount:(Account *)account
74{
75 if(privateAccount == account)
76 return;
77
78 privateAccount = account;
79
80 [self.aliasTextField setStringValue:account->alias().toNSString()];
81
82 switch (account->protocol()) {
83 case Account::Protocol::SIP:
84 [typeLabel setStringValue:@"SIP"];
85 break;
86 case Account::Protocol::IAX:
87 [typeLabel setStringValue:@"IAX"];
88 break;
89 case Account::Protocol::RING:
90 [typeLabel setStringValue:@"RING"];
91 break;
92
93 default:
94 break;
95 }
96
97 [upnpButton setState:privateAccount->isUpnpEnabled()];
98 [userAgentButton setState:privateAccount->hasCustomUserAgent()];
99 [userAgentTextField setEnabled:privateAccount->hasCustomUserAgent()];
100
101 [autoAnswerButton setState:privateAccount->isAutoAnswer()];
102 [userAgentTextField setStringValue:account->userAgent().toNSString()];
103
104 [bootstrapField setStringValue:account->hostname().toNSString()];
105
106 if([privateAccount->username().toNSString() isEqualToString:@""])
107 [hashField setStringValue:@"Reopen account to see your hash"];
108 else
109 [hashField setStringValue:privateAccount->username().toNSString()];
110
111}
112
113- (IBAction)toggleUpnp:(NSButton *)sender {
114 privateAccount->setUpnpEnabled([sender state] == NSOnState);
115}
116
117- (IBAction)toggleAutoAnswer:(NSButton *)sender {
118 privateAccount->setAutoAnswer([sender state] == NSOnState);
119}
120
121- (IBAction)toggleCustomAgent:(NSButton *)sender {
122 [self.userAgentTextField setEnabled:[sender state] == NSOnState];
123 privateAccount->setHasCustomUserAgent([sender state] == NSOnState);
124}
125
126#pragma mark - NSTextFieldDelegate methods
127
128- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
129{
130 return YES;
131}
132
133-(void)controlTextDidChange:(NSNotification *)notif
134{
135 NSTextField *textField = [notif object];
136
137 switch ([textField tag]) {
138 case ALIAS_TAG:
139 privateAccount->setAlias([[textField stringValue] UTF8String]);
140 break;
141 case HOSTNAME_TAG:
142 privateAccount->setHostname([[textField stringValue] UTF8String]);
143 break;
144 case PASSWORD_TAG:
145 privateAccount->setPassword([[textField stringValue] UTF8String]);
146 break;
147 case USERAGENT_TAG:
148 privateAccount->setUserAgent([[textField stringValue] UTF8String]);
149 break;
150 default:
151 break;
152 }
153}
154
155@end