accounts: use account selection model
Refs #75626
Change-Id: If9dbd47d5463b4a17aff31eae6dd3699cf7e9883
diff --git a/src/AccGeneralVC.mm b/src/AccGeneralVC.mm
index a75ad53..a2d33b1 100644
--- a/src/AccGeneralVC.mm
+++ b/src/AccGeneralVC.mm
@@ -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 ¤t, 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;