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 | #import "AccRingVC.h" |
| 37 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 38 | #import <accountmodel.h> |
| 39 | #import <qitemselectionmodel.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 40 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 41 | @interface AccRingVC () |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 42 | |
| 43 | @property (assign) IBOutlet NSTextField *aliasTextField; |
| 44 | @property (assign) IBOutlet NSTextField *typeLabel; |
| 45 | @property (assign) IBOutlet NSTextField *bootstrapField; |
| 46 | @property (assign) IBOutlet NSTextField *hashField; |
| 47 | |
| 48 | @property (assign) IBOutlet NSButton *upnpButton; |
| 49 | @property (assign) IBOutlet NSButton *autoAnswerButton; |
| 50 | @property (assign) IBOutlet NSButton *userAgentButton; |
| 51 | @property (assign) IBOutlet NSTextField *userAgentTextField; |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 52 | @property (unsafe_unretained) IBOutlet NSButton *allowUnknown; |
| 53 | @property (unsafe_unretained) IBOutlet NSButton *allowHistory; |
| 54 | @property (unsafe_unretained) IBOutlet NSButton *allowContacts; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 55 | |
| 56 | @end |
| 57 | |
| 58 | @implementation AccRingVC |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 59 | @synthesize typeLabel; |
| 60 | @synthesize bootstrapField; |
| 61 | @synthesize hashField; |
| 62 | @synthesize aliasTextField; |
| 63 | @synthesize upnpButton; |
| 64 | @synthesize autoAnswerButton; |
| 65 | @synthesize userAgentButton; |
| 66 | @synthesize userAgentTextField; |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 67 | @synthesize allowContacts, allowHistory, allowUnknown; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 68 | |
| 69 | - (void)awakeFromNib |
| 70 | { |
| 71 | NSLog(@"INIT Ring VC"); |
| 72 | [aliasTextField setTag:ALIAS_TAG]; |
| 73 | [userAgentTextField setTag:USERAGENT_TAG]; |
| 74 | [bootstrapField setTag:HOSTNAME_TAG]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 75 | |
| 76 | QObject::connect(AccountModel::instance()->selectionModel(), |
| 77 | &QItemSelectionModel::currentChanged, |
| 78 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 79 | if(!current.isValid()) |
| 80 | return; |
| 81 | [self loadAccount]; |
| 82 | }); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 85 | - (Account*) currentAccount |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 86 | { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 87 | auto accIdx = AccountModel::instance()->selectionModel()->currentIndex(); |
| 88 | return AccountModel::instance()->getAccountByModelIndex(accIdx); |
| 89 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 90 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 91 | - (void)loadAccount |
| 92 | { |
| 93 | auto account = [self currentAccount]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 94 | |
| 95 | [self.aliasTextField setStringValue:account->alias().toNSString()]; |
| 96 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 97 | [typeLabel setStringValue:@"RING"]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 98 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 99 | [allowUnknown setState:account->allowIncomingFromUnknown()]; |
| 100 | [allowHistory setState:account->allowIncomingFromHistory()]; |
| 101 | [allowContacts setState:account->allowIncomingFromContact()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 102 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 103 | [allowHistory setEnabled:!account->allowIncomingFromUnknown()]; |
| 104 | [allowContacts setEnabled:!account->allowIncomingFromUnknown()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 105 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 106 | [upnpButton setState:account->isUpnpEnabled()]; |
| 107 | [userAgentButton setState:account->hasCustomUserAgent()]; |
| 108 | [userAgentTextField setEnabled:account->hasCustomUserAgent()]; |
| 109 | |
| 110 | [autoAnswerButton setState:account->isAutoAnswer()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 111 | [userAgentTextField setStringValue:account->userAgent().toNSString()]; |
| 112 | |
| 113 | [bootstrapField setStringValue:account->hostname().toNSString()]; |
| 114 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 115 | if([account->username().toNSString() isEqualToString:@""]) |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 116 | [hashField setStringValue:@"Reopen account to see your hash"]; |
| 117 | else |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 118 | [hashField setStringValue:account->username().toNSString()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 119 | |
| 120 | } |
| 121 | |
| 122 | - (IBAction)toggleUpnp:(NSButton *)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 123 | [self currentAccount]->setUpnpEnabled([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | - (IBAction)toggleAutoAnswer:(NSButton *)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 127 | [self currentAccount]->setAutoAnswer([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | - (IBAction)toggleCustomAgent:(NSButton *)sender { |
| 131 | [self.userAgentTextField setEnabled:[sender state] == NSOnState]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 132 | [self currentAccount]->setHasCustomUserAgent([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Alexandre Lision | 2866435 | 2015-07-29 14:47:42 -0400 | [diff] [blame^] | 135 | - (IBAction)toggleAllowFromUnknown:(id)sender { |
| 136 | [self currentAccount]->setAllowIncomingFromUnknown([sender state] == NSOnState); |
| 137 | [allowHistory setEnabled:![sender state] == NSOnState]; |
| 138 | [allowContacts setEnabled:![sender state] == NSOnState]; |
| 139 | } |
| 140 | - (IBAction)toggleAllowFromHistory:(id)sender { |
| 141 | [self currentAccount]->setAllowIncomingFromHistory([sender state] == NSOnState); |
| 142 | } |
| 143 | - (IBAction)toggleAllowFromContacts:(id)sender { |
| 144 | [self currentAccount]->setAllowIncomingFromContact([sender state] == NSOnState); |
| 145 | } |
| 146 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 147 | #pragma mark - NSTextFieldDelegate methods |
| 148 | |
| 149 | - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor |
| 150 | { |
| 151 | return YES; |
| 152 | } |
| 153 | |
| 154 | -(void)controlTextDidChange:(NSNotification *)notif |
| 155 | { |
| 156 | NSTextField *textField = [notif object]; |
| 157 | |
| 158 | switch ([textField tag]) { |
| 159 | case ALIAS_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 160 | [self currentAccount]->setAlias([[textField stringValue] UTF8String]); |
Alexandre Lision | a1f07bf | 2015-07-28 10:30:55 -0400 | [diff] [blame] | 161 | [self currentAccount]->setDisplayName([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 162 | break; |
| 163 | case HOSTNAME_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 164 | [self currentAccount]->setHostname([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 165 | break; |
| 166 | case PASSWORD_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 167 | [self currentAccount]->setPassword([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 168 | break; |
| 169 | case USERAGENT_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 170 | [self currentAccount]->setUserAgent([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 171 | break; |
| 172 | default: |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | @end |