blob: 448a500bf4e671bb527b5a65ae4c0b6201244b9c [file] [log] [blame]
/*
* Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#define ALIAS_TAG 0
#define HOSTNAME_TAG 1
#define USERNAME_TAG 2
#define PASSWORD_TAG 3
#define USERAGENT_TAG 4
#import "AccRingVC.h"
#import <accountmodel.h>
#import <qitemselectionmodel.h>
@interface AccRingVC ()
@property (assign) IBOutlet NSTextField *aliasTextField;
@property (assign) IBOutlet NSTextField *typeLabel;
@property (assign) IBOutlet NSTextField *bootstrapField;
@property (assign) IBOutlet NSTextField *hashField;
@property (assign) IBOutlet NSButton *upnpButton;
@property (assign) IBOutlet NSButton *autoAnswerButton;
@property (assign) IBOutlet NSButton *userAgentButton;
@property (assign) IBOutlet NSTextField *userAgentTextField;
@property (unsafe_unretained) IBOutlet NSButton *allowUnknown;
@property (unsafe_unretained) IBOutlet NSButton *allowHistory;
@property (unsafe_unretained) IBOutlet NSButton *allowContacts;
@end
@implementation AccRingVC
@synthesize typeLabel;
@synthesize bootstrapField;
@synthesize hashField;
@synthesize aliasTextField;
@synthesize upnpButton;
@synthesize autoAnswerButton;
@synthesize userAgentButton;
@synthesize userAgentTextField;
@synthesize allowContacts, allowHistory, allowUnknown;
- (void)awakeFromNib
{
NSLog(@"INIT Ring VC");
[aliasTextField setTag:ALIAS_TAG];
[userAgentTextField setTag:USERAGENT_TAG];
[bootstrapField setTag:HOSTNAME_TAG];
QObject::connect(AccountModel::instance()->selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if(!current.isValid())
return;
[self loadAccount];
});
}
- (Account*) currentAccount
{
auto accIdx = AccountModel::instance()->selectionModel()->currentIndex();
return AccountModel::instance()->getAccountByModelIndex(accIdx);
}
- (void)loadAccount
{
auto account = [self currentAccount];
[self.aliasTextField setStringValue:account->alias().toNSString()];
[typeLabel setStringValue:@"RING"];
[allowUnknown setState:account->allowIncomingFromUnknown()];
[allowHistory setState:account->allowIncomingFromHistory()];
[allowContacts setState:account->allowIncomingFromContact()];
[allowHistory setEnabled:!account->allowIncomingFromUnknown()];
[allowContacts setEnabled:!account->allowIncomingFromUnknown()];
[upnpButton setState:account->isUpnpEnabled()];
[userAgentButton setState:account->hasCustomUserAgent()];
[userAgentTextField setEnabled:account->hasCustomUserAgent()];
[autoAnswerButton setState:account->isAutoAnswer()];
[userAgentTextField setStringValue:account->userAgent().toNSString()];
[bootstrapField setStringValue:account->hostname().toNSString()];
if([account->username().toNSString() isEqualToString:@""])
[hashField setStringValue:@"Reopen account to see your hash"];
else
[hashField setStringValue:account->username().toNSString()];
}
- (IBAction)toggleUpnp:(NSButton *)sender {
[self currentAccount]->setUpnpEnabled([sender state] == NSOnState);
}
- (IBAction)toggleAutoAnswer:(NSButton *)sender {
[self currentAccount]->setAutoAnswer([sender state] == NSOnState);
}
- (IBAction)toggleCustomAgent:(NSButton *)sender {
[self.userAgentTextField setEnabled:[sender state] == NSOnState];
[self currentAccount]->setHasCustomUserAgent([sender state] == NSOnState);
}
- (IBAction)toggleAllowFromUnknown:(id)sender {
[self currentAccount]->setAllowIncomingFromUnknown([sender state] == NSOnState);
[allowHistory setEnabled:![sender state] == NSOnState];
[allowContacts setEnabled:![sender state] == NSOnState];
}
- (IBAction)toggleAllowFromHistory:(id)sender {
[self currentAccount]->setAllowIncomingFromHistory([sender state] == NSOnState);
}
- (IBAction)toggleAllowFromContacts:(id)sender {
[self currentAccount]->setAllowIncomingFromContact([sender state] == NSOnState);
}
#pragma mark - NSTextFieldDelegate methods
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
{
return YES;
}
-(void)controlTextDidChange:(NSNotification *)notif
{
NSTextField *textField = [notif object];
switch ([textField tag]) {
case ALIAS_TAG:
[self currentAccount]->setAlias([[textField stringValue] UTF8String]);
[self currentAccount]->setDisplayName([[textField stringValue] UTF8String]);
break;
case HOSTNAME_TAG:
[self currentAccount]->setHostname([[textField stringValue] UTF8String]);
break;
case PASSWORD_TAG:
[self currentAccount]->setPassword([[textField stringValue] UTF8String]);
break;
case USERAGENT_TAG:
[self currentAccount]->setUserAgent([[textField stringValue] UTF8String]);
break;
default:
break;
}
}
@end