Commit 7f3164c1 authored by Alexandre Lision's avatar Alexandre Lision

accounts: use account selection model

Refs #75626

Change-Id: If9dbd47d5463b4a17aff31eae6dd3699cf7e9883
parent d18fa275
......@@ -31,10 +31,6 @@
#import <account.h>
@interface AccAdvancedVC : NSViewController <NSTextFieldDelegate> {
}
- (void)loadAccount:(Account *)account;
@interface AccAdvancedVC : NSViewController <NSTextFieldDelegate>
@end
......@@ -39,9 +39,11 @@
#import "AccAdvancedVC.h"
#import <accountmodel.h>
#import <qitemselectionmodel.h>
@interface AccAdvancedVC ()
@property Account* privateAccount;
@property (assign) IBOutlet NSTextField *registrationField;
@property (assign) IBOutlet NSTextField *localPortField;
@property (assign) IBOutlet NSButton *isUsingSTUN;
......@@ -67,7 +69,6 @@
@end
@implementation AccAdvancedVC
@synthesize privateAccount;
@synthesize registrationField;
@synthesize localPortField;
@synthesize isUsingSTUN;
......@@ -106,12 +107,27 @@
[STUNserverURLField setTag:STUNURL_TAG];
[publishedPortField setTag:PUBLICPORT_TAG];
[publishedAddrField setTag:PUBLICADDR_TAG];
QObject::connect(AccountModel::instance()->selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if(!current.isValid())
return;
[self loadAccount];
});
}
- (void)loadAccount:(Account *)account
- (Account*) currentAccount
{
privateAccount = account;
auto accIdx = AccountModel::instance()->selectionModel()->currentIndex();
return AccountModel::instance()->getAccountByModelIndex(accIdx);
}
- (void)loadAccount
{
auto account = [self currentAccount];
[self updateControlsWithTag:REGISTRATION_TAG];
[self updateControlsWithTag:LOCALPORT_TAG];
[self updateControlsWithTag:MINAUDIO_TAG];
......@@ -119,20 +135,20 @@
[self updateControlsWithTag:MINVIDEO_TAG];
[self updateControlsWithTag:MAXVIDEO_TAG];
[STUNserverURLField setStringValue:privateAccount->sipStunServer().toNSString()];
[isUsingSTUN setState:privateAccount->isSipStunEnabled()?NSOnState:NSOffState];
[STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()];
[STUNserverURLField setStringValue:account->sipStunServer().toNSString()];
[isUsingSTUN setState:account->isSipStunEnabled()?NSOnState:NSOffState];
[STUNserverURLField setEnabled:account->isSipStunEnabled()];
if(privateAccount->isPublishedSameAsLocal())
if(account->isPublishedSameAsLocal())
[publishAddrAndPortRadioGroup selectCellAtRow:0 column:0];
else {
[publishAddrAndPortRadioGroup selectCellAtRow:1 column:0];
}
[publishedAddrField setStringValue:privateAccount->publishedAddress().toNSString()];
[publishedPortField setIntValue:privateAccount->publishedPort()];
[publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()];
[publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()];
[publishedAddrField setStringValue:account->publishedAddress().toNSString()];
[publishedPortField setIntValue:account->publishedPort()];
[publishedAddrField setEnabled:!account->isPublishedSameAsLocal()];
[publishedPortField setEnabled:!account->isPublishedSameAsLocal()];
}
#pragma mark - NSTextFieldDelegate methods
......@@ -152,31 +168,31 @@
{
switch ([sender tag]) {
case REGISTRATION_TAG:
privateAccount->setRegistrationExpire([sender integerValue]);
[self currentAccount]->setRegistrationExpire([sender integerValue]);
break;
case LOCALPORT_TAG:
privateAccount->setLocalPort([sender integerValue]);
[self currentAccount]->setLocalPort([sender integerValue]);
break;
case STUNURL_TAG:
privateAccount->setSipStunServer([[sender stringValue] UTF8String]);
[self currentAccount]->setSipStunServer([[sender stringValue] UTF8String]);
break;
case PUBLICADDR_TAG:
privateAccount->setPublishedAddress([[sender stringValue] UTF8String]);
[self currentAccount]->setPublishedAddress([[sender stringValue] UTF8String]);
break;
case PUBLICPORT_TAG:
privateAccount->setPublishedPort([sender integerValue]);
[self currentAccount]->setPublishedPort([sender integerValue]);
break;
case MINAUDIO_TAG:
privateAccount->setAudioPortMin([sender integerValue]);
[self currentAccount]->setAudioPortMin([sender integerValue]);
break;
case MAXAUDIO_TAG:
privateAccount->setAudioPortMax([sender integerValue]);
[self currentAccount]->setAudioPortMax([sender integerValue]);
break;
case MINVIDEO_TAG:
privateAccount->setVideoPortMin([sender integerValue]);
[self currentAccount]->setVideoPortMin([sender integerValue]);
break;
case MAXVIDEO_TAG:
privateAccount->setVideoPortMax([sender integerValue]);
[self currentAccount]->setVideoPortMax([sender integerValue]);
break;
default:
break;
......@@ -186,20 +202,20 @@
- (IBAction)toggleSTUN:(NSButton *)sender
{
privateAccount->setSipStunEnabled([sender state]==NSOnState);
[STUNserverURLField setEnabled:privateAccount->isSipStunEnabled()];
[self currentAccount]->setSipStunEnabled([sender state]==NSOnState);
[STUNserverURLField setEnabled:[self currentAccount]->isSipStunEnabled()];
}
- (IBAction)didSwitchPublishedAddress:(NSMatrix *)matrix
{
NSInteger row = [matrix selectedRow];
if(row == 0) {
privateAccount->setPublishedSameAsLocal(YES);
[self currentAccount]->setPublishedSameAsLocal(YES);
} else {
privateAccount->setPublishedSameAsLocal(NO);
[self currentAccount]->setPublishedSameAsLocal(NO);
}
[publishedAddrField setEnabled:!privateAccount->isPublishedSameAsLocal()];
[publishedPortField setEnabled:!privateAccount->isPublishedSameAsLocal()];
[publishedAddrField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
[publishedPortField setEnabled:![self currentAccount]->isPublishedSameAsLocal()];
}
......@@ -207,28 +223,28 @@
{
switch (tag) {
case REGISTRATION_TAG:
[registrationStepper setIntegerValue:privateAccount->registrationExpire()];
[registrationField setIntegerValue:privateAccount->registrationExpire()];
[registrationStepper setIntegerValue:[self currentAccount]->registrationExpire()];
[registrationField setIntegerValue:[self currentAccount]->registrationExpire()];
break;
case LOCALPORT_TAG:
[localPortStepper setIntegerValue:privateAccount->localPort()];
[localPortField setIntegerValue:privateAccount->localPort()];
[localPortStepper setIntegerValue:[self currentAccount]->localPort()];
[localPortField setIntegerValue:[self currentAccount]->localPort()];
break;
case MINAUDIO_TAG:
[minAudioPortStepper setIntegerValue:privateAccount->audioPortMin()];
[minAudioRTPRange setIntegerValue:privateAccount->audioPortMin()];
[minAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMin()];
[minAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMin()];
break;
case MAXAUDIO_TAG:
[maxAudioPortStepper setIntegerValue:privateAccount->audioPortMax()];
[maxAudioRTPRange setIntegerValue:privateAccount->audioPortMax()];
[maxAudioPortStepper setIntegerValue:[self currentAccount]->audioPortMax()];
[maxAudioRTPRange setIntegerValue:[self currentAccount]->audioPortMax()];
break;
case MINVIDEO_TAG:
[minVideoPortStepper setIntegerValue:privateAccount->videoPortMin()];
[minVideoRTPRange setIntegerValue:privateAccount->videoPortMin()];
[minVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMin()];
[minVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMin()];
break;
case MAXVIDEO_TAG:
[maxVideoPortStepper setIntegerValue:privateAccount->videoPortMax()];
[maxVideoRTPRange setIntegerValue:privateAccount->videoPortMax()];
[maxVideoPortStepper setIntegerValue:[self currentAccount]->videoPortMax()];
[maxVideoRTPRange setIntegerValue:[self currentAccount]->videoPortMax()];
break;
default:
break;
......
......@@ -36,11 +36,7 @@
#import "QNSTreeController.h"
@interface AccAudioVC : NSViewController <NSOutlineViewDelegate> {
}
- (void)loadAccount:(Account *)account;
@interface AccAudioVC : NSViewController <NSOutlineViewDelegate>
@end
......
......@@ -37,10 +37,10 @@
#import <QSortFilterProxyModel>
#import <audio/codecmodel.h>
#import <accountmodel.h>
#import <qitemselectionmodel.h>
@interface AccAudioVC ()
@property Account* privateAccount;
@property QNSTreeController *treeController;
@property (assign) IBOutlet NSOutlineView *codecsView;
......@@ -49,17 +49,29 @@
@implementation AccAudioVC
@synthesize treeController;
@synthesize codecsView;
@synthesize privateAccount;
- (void)awakeFromNib
{
NSLog(@"INIT Audio VC");
QObject::connect(AccountModel::instance()->selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if(!current.isValid())
return;
[self loadAccount];
});
}
- (void)loadAccount:(Account *)account
- (Account*) currentAccount
{
privateAccount = account;
treeController = [[QNSTreeController alloc] initWithQModel:privateAccount->codecModel()->audioCodecs()];
auto accIdx = AccountModel::instance()->selectionModel()->currentIndex();
return AccountModel::instance()->getAccountByModelIndex(accIdx);
}
- (void)loadAccount
{
auto account = [self currentAccount];
treeController = [[QNSTreeController alloc] initWithQModel:account->codecModel()->audioCodecs()];
[treeController setAvoidsEmptySelection:NO];
[treeController setChildrenKeyPath:@"children"];
......@@ -75,8 +87,8 @@
if(!qIdx.isValid())
return;
QMimeData* mime = privateAccount->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
privateAccount->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex());
QMimeData* mime = [self currentAccount]->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
[self currentAccount]->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex());
}
}
......@@ -86,8 +98,8 @@
if(!qIdx.isValid())
return;
QMimeData* mime = privateAccount->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
privateAccount->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex());
QMimeData* mime = [self currentAccount]->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
[self currentAccount]->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex());
}
}
......@@ -95,8 +107,8 @@
NSInteger row = [sender clickedRow];
NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE];
NSButtonCell *cell = [col dataCellForRow:row];
QModelIndex qIdx = privateAccount->codecModel()->audioCodecs()->index(row, 0, QModelIndex());
privateAccount->codecModel()->audioCodecs()->setData(qIdx, cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
QModelIndex qIdx = [self currentAccount]->codecModel()->audioCodecs()->index(row, 0, QModelIndex());
[self currentAccount]->codecModel()->audioCodecs()->setData(qIdx, cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
}
#pragma mark - NSOutlineViewDelegate methods
......@@ -157,16 +169,16 @@
if(!qIdx.isValid())
return;
if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) {
[cell setState:privateAccount->codecModel()->audioCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
[cell setState:[self currentAccount]->codecModel()->audioCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS])
{
cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString();
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString();
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ])
{
cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString();
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString();
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE])
{
cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString();
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString();
}
}
......
......@@ -38,12 +38,6 @@
}
- (IBAction)toggleUpnp:(NSButton *)sender;
- (IBAction)toggleAutoAnswer:(NSButton *)sender;
- (IBAction)toggleCustomAgent:(NSButton *)sender;
- (void)loadAccount:(Account *)account;
@end
#endif // ACCGENERALVC_H
\ No newline at end of file
......@@ -42,8 +42,6 @@
@interface AccGeneralVC ()
@property Account* privateAccount;
@property (assign) IBOutlet NSView *boxingAccount;
@property (assign) IBOutlet NSView *boxingParameters;
@property (assign) IBOutlet NSView *boxingCommon;
......@@ -79,7 +77,6 @@
@synthesize autoAnswerButton;
@synthesize userAgentButton;
@synthesize userAgentTextField;
@synthesize privateAccount;
- (void)awakeFromNib
{
......@@ -89,25 +86,38 @@
[usernameTextField setTag:USERNAME_TAG];
[passwordTextField setTag:PASSWORD_TAG];
[userAgentTextField setTag:USERAGENT_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);
}
- (IBAction)toggleUpnp:(NSButton *)sender {
privateAccount->setUpnpEnabled([sender state] == NSOnState);
[self currentAccount]->setUpnpEnabled([sender state] == NSOnState);
}
- (IBAction)toggleAutoAnswer:(NSButton *)sender {
privateAccount->setAutoAnswer([sender state] == NSOnState);
[self currentAccount]->setAutoAnswer([sender state] == NSOnState);
}
- (IBAction)toggleCustomAgent:(NSButton *)sender {
[self.userAgentTextField setEnabled:[sender state] == NSOnState];
privateAccount->setHasCustomUserAgent([sender state] == NSOnState);
[self currentAccount]->setHasCustomUserAgent([sender state] == NSOnState);
}
- (void)loadAccount:(Account *)account
- (void)loadAccount
{
privateAccount = account;
auto account = [self currentAccount];
if([account->alias().toNSString() isEqualToString:@"IP2IP"]) {
[boxingAccount.subviews setValue:@YES forKeyPath:@"hidden"];
......@@ -145,15 +155,15 @@
break;
}
[upnpButton setState:privateAccount->isUpnpEnabled()];
[userAgentButton setState:privateAccount->hasCustomUserAgent()];
[userAgentTextField setEnabled:privateAccount->hasCustomUserAgent()];
[self.autoAnswerButton setState:privateAccount->isAutoAnswer()];
[upnpButton setState:[self currentAccount]->isUpnpEnabled()];
[userAgentButton setState:[self currentAccount]->hasCustomUserAgent()];
[userAgentTextField setEnabled:[self currentAccount]->hasCustomUserAgent()];
[self.autoAnswerButton setState:[self currentAccount]->isAutoAnswer()];
[self.userAgentTextField setStringValue:account->userAgent().toNSString()];
}
- (IBAction)tryRegistration:(id)sender {
self.privateAccount << Account::EditAction::SAVE;
[self currentAccount] << Account::EditAction::SAVE;
}
- (IBAction)showPassword:(NSButton *)sender {
......@@ -195,19 +205,19 @@
switch ([textField tag]) {
case ALIAS_TAG:
privateAccount->setAlias([[textField stringValue] UTF8String]);
[self currentAccount]->setAlias([[textField stringValue] UTF8String]);
break;
case HOSTNAME_TAG:
privateAccount->setHostname([[textField stringValue] UTF8String]);
[self currentAccount]->setHostname([[textField stringValue] UTF8String]);
break;
case USERNAME_TAG:
privateAccount->setUsername([[textField stringValue] UTF8String]);
[self currentAccount]->setUsername([[textField stringValue] UTF8String]);
break;
case PASSWORD_TAG:
privateAccount->setPassword([[textField stringValue] UTF8String]);
[self currentAccount]->setPassword([[textField stringValue] UTF8String]);
break;
case USERAGENT_TAG:
privateAccount->setUserAgent([[textField stringValue] UTF8String]);
[self currentAccount]->setUserAgent([[textField stringValue] UTF8String]);
break;
default:
break;
......
......@@ -34,12 +34,7 @@
#import <account.h>
@interface AccRingVC : NSViewController <NSTextFieldDelegate> {
NSTextField *hashField;
}
- (void)loadAccount:(Account *)account;
@interface AccRingVC : NSViewController <NSTextFieldDelegate>
@end
......
......@@ -35,9 +35,10 @@
#import "AccRingVC.h"
@interface AccRingVC ()
#import <accountmodel.h>
#import <qitemselectionmodel.h>
@property Account* privateAccount;
@interface AccRingVC ()
@property (assign) IBOutlet NSTextField *aliasTextField;
@property (assign) IBOutlet NSTextField *typeLabel;
......@@ -52,7 +53,6 @@
@end
@implementation AccRingVC
@synthesize privateAccount;
@synthesize typeLabel;
@synthesize bootstrapField;
@synthesize hashField;
......@@ -68,14 +68,25 @@
[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];
});
}
- (void)loadAccount:(Account *)account
- (Account*) currentAccount
{
if(privateAccount == account)
return;
auto accIdx = AccountModel::instance()->selectionModel()->currentIndex();
return AccountModel::instance()->getAccountByModelIndex(accIdx);
}
privateAccount = account;
- (void)loadAccount
{
auto account = [self currentAccount];
[self.aliasTextField setStringValue:account->alias().toNSString()];
......@@ -94,33 +105,33 @@
break;
}
[upnpButton setState:privateAccount->isUpnpEnabled()];
[userAgentButton setState:privateAccount->hasCustomUserAgent()];
[userAgentTextField setEnabled:privateAccount->hasCustomUserAgent()];
[upnpButton setState:[self currentAccount]->isUpnpEnabled()];
[userAgentButton setState:[self currentAccount]->hasCustomUserAgent()];
[userAgentTextField setEnabled:[self currentAccount]->hasCustomUserAgent()];
[autoAnswerButton setState:privateAccount->isAutoAnswer()];
[autoAnswerButton setState:[self currentAccount]->isAutoAnswer()];
[userAgentTextField setStringValue:account->userAgent().toNSString()];
[bootstrapField setStringValue:account->hostname().toNSString()];
if([privateAccount->username().toNSString() isEqualToString:@""])
if([[self currentAccount]->username().toNSString() isEqualToString:@""])
[hashField setStringValue:@"Reopen account to see your hash"];
else
[hashField setStringValue:privateAccount->username().toNSString()];
[hashField setStringValue:[self currentAccount]->username().toNSString()];
}
- (IBAction)toggleUpnp:(NSButton *)sender {
privateAccount->setUpnpEnabled([sender state] == NSOnState);
[self currentAccount]->setUpnpEnabled([sender state] == NSOnState);
}
- (IBAction)toggleAutoAnswer:(NSButton *)sender {
privateAccount->setAutoAnswer([sender state] == NSOnState);
[self currentAccount]->setAutoAnswer([sender state] == NSOnState);
}
- (IBAction)toggleCustomAgent:(NSButton *)sender {
[self.userAgentTextField setEnabled:[sender state] == NSOnState];
privateAccount->setHasCustomUserAgent([sender state] == NSOnState);
[self currentAccount]->setHasCustomUserAgent([sender state] == NSOnState);
}
#pragma mark - NSTextFieldDelegate methods
......@@ -136,16 +147,16 @@
switch ([textField tag]) {
case ALIAS_TAG:
privateAccount->setAlias([[textField stringValue] UTF8String]);
[self currentAccount]->setAlias([[textField stringValue] UTF8String]);
break;
case HOSTNAME_TAG:
privateAccount->setHostname([[textField stringValue] UTF8String]);
[self currentAccount]->setHostname([[textField stringValue] UTF8String]);
break;
case PASSWORD_TAG:
privateAccount->setPassword([[textField stringValue] UTF8String]);
[self currentAccount]->setPassword([[textField stringValue] UTF8String]);
break;
case USERAGENT_TAG:
privateAccount->setUserAgent([[textField stringValue] UTF8String]);
[self currentAccount]->setUserAgent([[textField stringValue] UTF8String]);
break;
default:
break;
......
......@@ -32,13 +32,7 @@
#import <Cocoa/Cocoa.h>
#import <account.h>
@interface AccSecurityVC : NSViewController<NSMenuDelegate, NSPathControlDelegate, NSOpenSavePanelDelegate> {
}
- (void)loadAccount:(Account *)account;
@interface AccSecurityVC : NSViewController<NSMenuDelegate, NSPathControlDelegate, NSOpenSavePanelDelegate>
@end
......
......@@ -34,6 +34,7 @@
#import <tlsmethodmodel.h>
#import <qitemselectionmodel.h>
#import <ciphermodel.h>
#import <accountmodel.h>
#import "QNSTreeController.h"
#import "CertificateWC.h"
......@@ -48,7 +49,6 @@
@interface AccSecurityVC ()
@property Account* privateAccount;
@property NSTreeController *treeController;
@property (unsafe_unretained) IBOutlet NSOutlineView *cipherListView;
@property (unsafe_unretained) IBOutlet NSButton *useTLS;
......@@ -73,7 +73,6 @@
@end
@implementation AccSecurityVC
@synthesize privateAccount;
@synthesize treeController;
@synthesize cipherListView;
@synthesize certificateWC;
......@@ -100,21 +99,34 @@
[tlsNegotiationTimeoutStepper setTag:TLS_NEGOTIATION_TAG];
[tlsNegotiationTimeout setTag:TLS_NEGOTIATION_TAG];