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; |
| 52 | |
| 53 | @end |
| 54 | |
| 55 | @implementation AccRingVC |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 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]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 71 | |
| 72 | QObject::connect(AccountModel::instance()->selectionModel(), |
| 73 | &QItemSelectionModel::currentChanged, |
| 74 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 75 | if(!current.isValid()) |
| 76 | return; |
| 77 | [self loadAccount]; |
| 78 | }); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 81 | - (Account*) currentAccount |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 82 | { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 83 | auto accIdx = AccountModel::instance()->selectionModel()->currentIndex(); |
| 84 | return AccountModel::instance()->getAccountByModelIndex(accIdx); |
| 85 | } |
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 | - (void)loadAccount |
| 88 | { |
| 89 | auto account = [self currentAccount]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 90 | |
| 91 | [self.aliasTextField setStringValue:account->alias().toNSString()]; |
| 92 | |
| 93 | switch (account->protocol()) { |
| 94 | case Account::Protocol::SIP: |
| 95 | [typeLabel setStringValue:@"SIP"]; |
| 96 | break; |
| 97 | case Account::Protocol::IAX: |
| 98 | [typeLabel setStringValue:@"IAX"]; |
| 99 | break; |
| 100 | case Account::Protocol::RING: |
| 101 | [typeLabel setStringValue:@"RING"]; |
| 102 | break; |
| 103 | |
| 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 108 | [upnpButton setState:[self currentAccount]->isUpnpEnabled()]; |
| 109 | [userAgentButton setState:[self currentAccount]->hasCustomUserAgent()]; |
| 110 | [userAgentTextField setEnabled:[self currentAccount]->hasCustomUserAgent()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 111 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 112 | [autoAnswerButton setState:[self currentAccount]->isAutoAnswer()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 113 | [userAgentTextField setStringValue:account->userAgent().toNSString()]; |
| 114 | |
| 115 | [bootstrapField setStringValue:account->hostname().toNSString()]; |
| 116 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 117 | if([[self currentAccount]->username().toNSString() isEqualToString:@""]) |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 118 | [hashField setStringValue:@"Reopen account to see your hash"]; |
| 119 | else |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 120 | [hashField setStringValue:[self currentAccount]->username().toNSString()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 121 | |
| 122 | } |
| 123 | |
| 124 | - (IBAction)toggleUpnp:(NSButton *)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 125 | [self currentAccount]->setUpnpEnabled([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | - (IBAction)toggleAutoAnswer:(NSButton *)sender { |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 129 | [self currentAccount]->setAutoAnswer([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | - (IBAction)toggleCustomAgent:(NSButton *)sender { |
| 133 | [self.userAgentTextField setEnabled:[sender state] == NSOnState]; |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 134 | [self currentAccount]->setHasCustomUserAgent([sender state] == NSOnState); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | #pragma mark - NSTextFieldDelegate methods |
| 138 | |
| 139 | - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor |
| 140 | { |
| 141 | return YES; |
| 142 | } |
| 143 | |
| 144 | -(void)controlTextDidChange:(NSNotification *)notif |
| 145 | { |
| 146 | NSTextField *textField = [notif object]; |
| 147 | |
| 148 | switch ([textField tag]) { |
| 149 | case ALIAS_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 150 | [self currentAccount]->setAlias([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 151 | break; |
| 152 | case HOSTNAME_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 153 | [self currentAccount]->setHostname([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 154 | break; |
| 155 | case PASSWORD_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 156 | [self currentAccount]->setPassword([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 157 | break; |
| 158 | case USERAGENT_TAG: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 159 | [self currentAccount]->setUserAgent([[textField stringValue] UTF8String]); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 160 | break; |
| 161 | default: |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | @end |