Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 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. |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 20 | #import "AccountsVC.h" |
| 21 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 22 | // Qt |
| 23 | #import <QItemSelectionModel> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 24 | #import <QSortFilterProxyModel> |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 25 | #import <QtCore/qdir.h> |
| 26 | #import <QtCore/qstandardpaths.h> |
| 27 | |
| 28 | // LRC |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 29 | #import <accountmodel.h> |
| 30 | #import <protocolmodel.h> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 31 | #import <account.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 32 | |
| 33 | #import "QNSTreeController.h" |
| 34 | #import "AccGeneralVC.h" |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 35 | #import "AccMediaVC.h" |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 36 | #import "AccAdvancedVC.h" |
| 37 | #import "AccSecurityVC.h" |
| 38 | #import "AccRingVC.h" |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 39 | #import "AccDevicesVC.h" |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 40 | #import "BackupAccountWC.h" |
| 41 | #import "RestoreAccountWC.h" |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 42 | #import "RingWizardWC.h" |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 43 | #import "AccBannedContactsVC.h" |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 44 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 45 | @interface AccountsVC () <BackupAccountDelegate, RestoreAccountDelegate> |
Alexandre Lision | c1f9666 | 2016-03-23 17:24:19 -0400 | [diff] [blame] | 46 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 47 | @property (assign) IBOutlet NSPopUpButton *protocolList; |
| 48 | |
| 49 | @property (assign) IBOutlet NSTabView *configPanels; |
| 50 | @property (retain) IBOutlet NSTabViewItem *generalTabItem; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 51 | @property (retain) IBOutlet NSTabViewItem *mediaTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 52 | @property (retain) IBOutlet NSTabViewItem *advancedTabItem; |
| 53 | @property (retain) IBOutlet NSTabViewItem *securityTabItem; |
| 54 | @property (retain) IBOutlet NSTabViewItem *ringTabItem; |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 55 | @property (retain) IBOutlet NSTabViewItem *ringDevicesTabItem; |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 56 | @property (retain) IBOutlet NSTabViewItem *bannedListTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 57 | |
| 58 | @property QNSTreeController *treeController; |
| 59 | @property (assign) IBOutlet NSOutlineView *accountsListView; |
| 60 | @property (assign) IBOutlet NSTabView *accountDetailsView; |
Alexandre Lision | c1f9666 | 2016-03-23 17:24:19 -0400 | [diff] [blame] | 61 | @property (unsafe_unretained) IBOutlet NSButton* exportAccountButton; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 62 | |
| 63 | @property AccRingVC* ringVC; |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 64 | @property AccDevicesVC* devicesVC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 65 | @property AccGeneralVC* generalVC; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 66 | @property AccMediaVC* audioVC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 67 | @property AccAdvancedVC* advancedVC; |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 68 | @property AccBannedContactsVC* bannedContactsVC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 69 | @property AccSecurityVC* securityVC; |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 70 | @property AbstractLoadingWC* accountModal; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 71 | @property RingWizardWC* wizard; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 72 | |
| 73 | @end |
| 74 | |
| 75 | @implementation AccountsVC |
| 76 | @synthesize protocolList; |
| 77 | @synthesize configPanels; |
| 78 | @synthesize generalTabItem; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 79 | @synthesize mediaTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 80 | @synthesize advancedTabItem; |
| 81 | @synthesize securityTabItem; |
| 82 | @synthesize ringTabItem; |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 83 | @synthesize ringDevicesTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 84 | @synthesize accountsListView; |
| 85 | @synthesize accountDetailsView; |
| 86 | @synthesize treeController; |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 87 | @synthesize accountModal; |
Loïc Siret | fcb4ca6 | 2016-09-21 17:12:09 -0400 | [diff] [blame] | 88 | @synthesize wizard; |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 89 | @synthesize bannedListTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 90 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 91 | NSInteger const TAG_CHECK = 100; |
| 92 | NSInteger const TAG_NAME = 200; |
| 93 | NSInteger const TAG_STATUS = 300; |
| 94 | NSInteger const TAG_TYPE = 400; |
| 95 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 96 | QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnection, accountTypeChangedConnection; |
| 97 | |
Alexandre Lision | c1f9666 | 2016-03-23 17:24:19 -0400 | [diff] [blame] | 98 | |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 99 | - (void)loadView { |
| 100 | [super loadView]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 101 | treeController = [[QNSTreeController alloc] initWithQModel:&AccountModel::instance()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 102 | [treeController setAvoidsEmptySelection:NO]; |
| 103 | [treeController setAlwaysUsesMultipleValuesMarker:YES]; |
| 104 | [treeController setChildrenKeyPath:@"children"]; |
| 105 | |
| 106 | [accountsListView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 107 | [accountsListView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 108 | [accountsListView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 109 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 110 | QObject::disconnect(accountChangedConnection); |
| 111 | QObject::disconnect(selectedAccountChangedConnection); |
| 112 | |
| 113 | accountChangedConnection = QObject::connect(&AccountModel::instance(), |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 114 | &QAbstractItemModel::dataChanged, |
| 115 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
| 116 | [accountsListView reloadDataForRowIndexes: |
| 117 | [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)] |
| 118 | columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, accountsListView.tableColumns.count)]]; |
| 119 | }); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 120 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 121 | selectedAccountChangedConnection = QObject::connect(AccountModel::instance().selectionModel(), |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 122 | &QItemSelectionModel::currentChanged, |
| 123 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 124 | [accountDetailsView setHidden:!current.isValid()]; |
| 125 | if(!current.isValid()) { |
| 126 | [accountsListView deselectAll:nil]; |
| 127 | return; |
| 128 | } |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 129 | |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 130 | [treeController setSelectionQModelIndex:current]; |
| 131 | }); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 132 | AccountModel::instance().selectionModel()->clearCurrentIndex(); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 133 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 134 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 135 | QModelIndex qProtocolIdx = AccountModel::instance().protocolModel()->selectionModel()->currentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 136 | [self.protocolList addItemWithTitle: |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 137 | AccountModel::instance().protocolModel()->data(qProtocolIdx, Qt::DisplayRole).toString().toNSString()]; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 138 | QObject::disconnect(accountTypeChangedConnection); |
| 139 | accountTypeChangedConnection = QObject::connect(AccountModel::instance().protocolModel()->selectionModel(), |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 140 | &QItemSelectionModel::currentChanged, |
| 141 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 142 | if (!current.isValid()) { |
| 143 | return; |
| 144 | } |
| 145 | [protocolList removeAllItems]; |
| 146 | [protocolList addItemWithTitle:AccountModel::instance().protocolModel()->data(current, Qt::DisplayRole).toString().toNSString()]; |
| 147 | }); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 148 | |
| 149 | self.generalVC = [[AccGeneralVC alloc] initWithNibName:@"AccGeneral" bundle:nil]; |
| 150 | [[self.generalVC view] setFrame:[self.generalTabItem.view frame]]; |
| 151 | [[self.generalVC view] setBounds:[self.generalTabItem.view bounds]]; |
| 152 | [self.generalTabItem setView:self.generalVC.view]; |
| 153 | |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 154 | self.audioVC = [[AccMediaVC alloc] initWithNibName:@"AccMedia" bundle:nil]; |
| 155 | [[self.audioVC view] setFrame:[self.mediaTabItem.view frame]]; |
| 156 | [[self.audioVC view] setBounds:[self.mediaTabItem.view bounds]]; |
| 157 | [self.mediaTabItem setView:self.audioVC.view]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 158 | |
| 159 | self.advancedVC = [[AccAdvancedVC alloc] initWithNibName:@"AccAdvanced" bundle:nil]; |
| 160 | [[self.advancedVC view] setFrame:[self.advancedTabItem.view frame]]; |
| 161 | [[self.advancedVC view] setBounds:[self.advancedTabItem.view bounds]]; |
| 162 | [self.advancedTabItem setView:self.advancedVC.view]; |
| 163 | |
| 164 | self.securityVC = [[AccSecurityVC alloc] initWithNibName:@"AccSecurity" bundle:nil]; |
| 165 | [[self.securityVC view] setFrame:[self.securityTabItem.view frame]]; |
| 166 | [[self.securityVC view] setBounds:[self.securityTabItem.view bounds]]; |
| 167 | [self.securityTabItem setView:self.securityVC.view]; |
| 168 | |
| 169 | self.ringVC = [[AccRingVC alloc] initWithNibName:@"AccRing" bundle:nil]; |
| 170 | [[self.ringVC view] setFrame:[self.ringTabItem.view frame]]; |
| 171 | [[self.ringVC view] setBounds:[self.ringTabItem.view bounds]]; |
| 172 | [self.ringTabItem setView:self.ringVC.view]; |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 173 | |
| 174 | self.devicesVC = [[AccDevicesVC alloc] initWithNibName:@"AccDevices" bundle:nil]; |
| 175 | [[self.devicesVC view] setFrame:[self.ringDevicesTabItem.view frame]]; |
| 176 | [[self.devicesVC view] setBounds:[self.ringDevicesTabItem.view bounds]]; |
| 177 | [self.ringDevicesTabItem setView:self.devicesVC.view]; |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 178 | |
| 179 | self.bannedContactsVC = [[AccBannedContactsVC alloc] initWithNibName:@"AccBannedContacts" bundle:nil]; |
| 180 | [[self.bannedContactsVC view] setFrame:[self.bannedListTabItem.view frame]]; |
| 181 | [[self.bannedContactsVC view] setBounds:[self.bannedListTabItem.view bounds]]; |
| 182 | [self.bannedListTabItem setView:self.bannedContactsVC.view]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 183 | } |
| 184 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 185 | - (void) setupSIPPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 186 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 187 | // Start by removing all tabs |
| 188 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 189 | [configPanels removeTabViewItem:item]; |
| 190 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 191 | [configPanels insertTabViewItem:generalTabItem atIndex:0]; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 192 | [configPanels insertTabViewItem:mediaTabItem atIndex:1]; |
| 193 | [configPanels insertTabViewItem:advancedTabItem atIndex:2]; |
| 194 | [configPanels insertTabViewItem:securityTabItem atIndex:3]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 197 | - (void) setupRINGPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 198 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 199 | // Start by removing all tabs |
| 200 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 201 | [configPanels removeTabViewItem:item]; |
| 202 | } |
| 203 | |
| 204 | [configPanels insertTabViewItem:ringTabItem atIndex:0]; |
Alexandre Lision | 45f1f54 | 2016-08-25 15:16:17 -0400 | [diff] [blame] | 205 | [configPanels insertTabViewItem:ringDevicesTabItem atIndex:1]; |
| 206 | [configPanels insertTabViewItem:mediaTabItem atIndex:2]; |
| 207 | [configPanels insertTabViewItem:advancedTabItem atIndex:3]; |
Kateryna Kostiuk | 77e9390 | 2017-05-30 16:38:11 -0400 | [diff] [blame] | 208 | [configPanels insertTabViewItem:bannedListTabItem atIndex:4]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 209 | } |
Loïc Siret | 31d5cc0 | 2016-09-08 14:38:24 -0400 | [diff] [blame] | 210 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 211 | - (IBAction)toggleAccount:(NSButton*)sender { |
| 212 | NSInteger row = [accountsListView rowForView:sender]; |
| 213 | auto accountToToggle = AccountModel::instance().getAccountByModelIndex(AccountModel::instance().index(row)); |
| 214 | accountToToggle->setEnabled(sender.state); |
| 215 | accountToToggle << Account::EditAction::SAVE; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | #pragma mark - NSOutlineViewDelegate methods |
| 219 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 220 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 221 | { |
| 222 | return YES; |
| 223 | } |
| 224 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 225 | - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 226 | { |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 227 | return [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 230 | - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 231 | { |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 232 | NSTableView* result = [outlineView makeViewWithIdentifier:@"AccountView" owner:self]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 233 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 234 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 235 | if(!qIdx.isValid()) |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 236 | return result; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 237 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 238 | NSTextField* nameLabel = [result viewWithTag:TAG_NAME]; |
| 239 | NSTextField* stateLabel = [result viewWithTag:TAG_STATUS]; |
| 240 | NSButton* checkButton = [result viewWithTag:TAG_CHECK]; |
| 241 | NSTextField* typeLabel = [result viewWithTag:TAG_TYPE]; |
Alexandre Lision | 0ab4608 | 2015-08-11 12:10:21 -0400 | [diff] [blame] | 242 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 243 | auto account = AccountModel::instance().getAccountByModelIndex(qIdx); |
| 244 | auto humanState = account->toHumanStateName(); |
| 245 | |
| 246 | [nameLabel setStringValue:account->alias().toNSString()]; |
| 247 | [stateLabel setStringValue:humanState.toNSString()]; |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 248 | |
| 249 | switch (account->protocol()) { |
| 250 | case Account::Protocol::SIP: |
| 251 | [typeLabel setStringValue:@"SIP"]; |
| 252 | break; |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 253 | case Account::Protocol::RING: |
| 254 | [typeLabel setStringValue:@"RING"]; |
| 255 | break; |
| 256 | default: |
| 257 | break; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 258 | } |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 259 | |
| 260 | switch (account->registrationState()) { |
| 261 | case Account::RegistrationState::READY: |
| 262 | [stateLabel setTextColor:[NSColor colorWithCalibratedRed:116/255.0 green:179/255.0 blue:93/255.0 alpha:1.0]]; |
| 263 | break; |
| 264 | case Account::RegistrationState::TRYING: |
| 265 | [stateLabel setTextColor:[NSColor redColor]]; |
| 266 | break; |
| 267 | case Account::RegistrationState::UNREGISTERED: |
| 268 | [stateLabel setTextColor:[NSColor blackColor]]; |
| 269 | break; |
| 270 | case Account::RegistrationState::ERROR: |
| 271 | [stateLabel setTextColor:[NSColor redColor]]; |
| 272 | break; |
| 273 | default: |
| 274 | [stateLabel setTextColor:[NSColor blackColor]]; |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | [checkButton setState:qIdx.data(Qt::CheckStateRole).value<BOOL>()]; |
| 279 | |
| 280 | return result; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 283 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 284 | { |
| 285 | // ask the tree controller for the current selection |
Alexandre Lision | c1f9666 | 2016-03-23 17:24:19 -0400 | [diff] [blame] | 286 | [self.exportAccountButton setEnabled:[[treeController selectedNodes] count] > 0]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 287 | if([[treeController selectedNodes] count] > 0) { |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 288 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 289 | //Update details view |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 290 | auto acc = AccountModel::instance().getAccountByModelIndex(qIdx); |
| 291 | AccountModel::instance().selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 292 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame] | 293 | switch (acc->protocol()) { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 294 | case Account::Protocol::SIP: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 295 | [self setupSIPPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 296 | break; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 297 | case Account::Protocol::RING: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 298 | [self setupRINGPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 299 | break; |
| 300 | default: |
| 301 | break; |
| 302 | } |
| 303 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 304 | [self.accountDetailsView setHidden:NO]; |
| 305 | } else { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 306 | AccountModel::instance().selectionModel()->clearCurrentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 310 | #pragma mark - Delete account |
Alexandre Lision | c1f9666 | 2016-03-23 17:24:19 -0400 | [diff] [blame] | 311 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 312 | - (IBAction)removeAccount:(id)sender |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 313 | { |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 314 | AccountModel::instance().remove(AccountModel::instance().selectedAccount()); |
| 315 | AccountModel::instance().save(); |
| 316 | } |
| 317 | |
| 318 | #pragma mark - Advanced menu methods |
| 319 | |
| 320 | - (IBAction)advancedActionsClicked:(NSButton *)sender |
| 321 | { |
| 322 | NSMenu* menu = [[NSMenu alloc] init]; |
| 323 | |
| 324 | auto backupItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Backup account", @"Contextual menu entry") |
| 325 | action:@selector(backupAccount:) |
| 326 | keyEquivalent:@""]; |
| 327 | |
| 328 | if(treeController.selectedNodes.count == 0) { |
| 329 | // Use a fake selector, to grey out the Backup entry in the menu |
| 330 | [backupItem setAction:@selector(disable:)]; |
Alexandre Lision | 274c22c | 2016-06-30 11:57:43 -0400 | [diff] [blame] | 331 | } |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 332 | |
| 333 | [menu insertItem:backupItem atIndex:0]; |
| 334 | |
| 335 | [menu insertItemWithTitle:NSLocalizedString(@"Restore account", @"Contextual menu entry") |
| 336 | action:@selector(restoreAccount:) |
| 337 | keyEquivalent:@"" |
| 338 | atIndex:0]; |
| 339 | |
| 340 | [NSMenu popUpContextMenu:menu withEvent:[self forgedEventForButton:sender] forView:(NSButton *)sender]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 343 | - (void) backupAccount:(NSMenuItem*) sender |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 344 | { |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 345 | auto passwordWC = [[BackupAccountWC alloc] initWithDelegate:self]; |
| 346 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 347 | [self.view.window beginSheet:passwordWC.window completionHandler:nil]; |
| 348 | #else |
| 349 | [NSApp beginSheet: passwordWC.window |
| 350 | modalForWindow: self.view.window |
| 351 | modalDelegate: self |
| 352 | didEndSelector: nil |
| 353 | contextInfo: nil]; |
| 354 | #endif |
| 355 | [passwordWC setAllowFileSelection:NO]; |
| 356 | if(treeController.selectedNodes.count > 0) { |
| 357 | QStringList accounts; |
| 358 | for (id item : [treeController selectedNodes]) { |
| 359 | QModelIndex accIdx = [treeController toQIdx:item]; |
| 360 | accounts << AccountModel::instance().getAccountByModelIndex(accIdx)->id(); |
| 361 | } |
| 362 | [passwordWC setAccounts:accounts]; |
| 363 | } |
| 364 | [passwordWC showWindow:self]; |
| 365 | accountModal = passwordWC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 368 | - (void) restoreAccount:(NSMenuItem*) sender |
| 369 | { |
| 370 | auto passwordWC = [[RestoreAccountWC alloc] initWithDelegate:self]; |
| 371 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 372 | [self.view.window beginSheet:passwordWC.window completionHandler:nil]; |
| 373 | #else |
| 374 | [NSApp beginSheet: passwordWC.window |
| 375 | modalForWindow: self.view.window |
| 376 | modalDelegate: self |
| 377 | didEndSelector: nil |
| 378 | contextInfo: nil]; |
| 379 | #endif |
| 380 | [passwordWC setAllowFileSelection:YES]; |
| 381 | [passwordWC showWindow:self]; |
| 382 | accountModal = passwordWC; |
| 383 | } |
| 384 | |
| 385 | - (NSEvent*) forgedEventForButton:(NSButton*) button |
| 386 | { |
| 387 | NSRect frame = [button frame]; |
| 388 | NSPoint menuOrigin = [[button superview] |
| 389 | convertPoint:NSMakePoint(frame.origin.x, frame.origin.y) |
| 390 | toView:nil]; |
| 391 | return [NSEvent mouseEventWithType:NSLeftMouseDown |
| 392 | location:menuOrigin |
| 393 | modifierFlags:NSLeftMouseDownMask // 0x100 |
| 394 | timestamp:0 |
| 395 | windowNumber:[[button window] windowNumber] |
| 396 | context:[[button window] graphicsContext] |
| 397 | eventNumber:0 |
| 398 | clickCount:1 |
| 399 | pressure:1]; |
| 400 | } |
| 401 | |
| 402 | |
| 403 | #pragma mark - Account creation methods |
| 404 | |
| 405 | - (IBAction)addAccountClicked:(NSButton *)sender |
| 406 | { |
| 407 | NSMenu* menu = [[NSMenu alloc] init]; |
| 408 | [menu insertItemWithTitle:NSLocalizedString(@"Create RING Account", @"Contextual menu entry") |
| 409 | action:@selector(createRingAccount:) |
| 410 | keyEquivalent:@"" |
| 411 | atIndex:0]; |
| 412 | [menu insertItemWithTitle:NSLocalizedString(@"Create SIP Account", @"Contextual menu entry") |
| 413 | action:@selector(createSIPAccount:) |
| 414 | keyEquivalent:@"" |
| 415 | atIndex:0]; |
| 416 | |
| 417 | [NSMenu popUpContextMenu:menu withEvent:[self forgedEventForButton:sender] forView:(NSButton *)sender]; |
| 418 | } |
| 419 | |
| 420 | - (void)createSIPAccount:(NSMenuItem*) sender |
| 421 | { |
| 422 | auto acc = AccountModel::instance().add([NSLocalizedString(@"New SIP account", @"User label") UTF8String]); |
| 423 | acc->setDisplayName(acc->alias()); |
| 424 | acc->setProtocol(Account::Protocol::SIP); |
| 425 | acc->setDTMFType(DtmfType::OverSip); |
| 426 | AccountModel::instance().save(); |
| 427 | } |
| 428 | |
| 429 | - (void)createRingAccount:(NSMenuItem*) sender |
| 430 | { |
| 431 | wizard = [[RingWizardWC alloc] initWithWindowNibName:@"RingWizard"]; |
| 432 | [wizard showChooseWithCancelButton: YES]; |
| 433 | // [wizard.window makeKeyAndOrderFront:self]; |
| 434 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 435 | [self.view.window beginSheet:wizard.window completionHandler:nil]; |
| 436 | #else |
| 437 | [NSApp beginSheet: wizard.window |
| 438 | modalForWindow: self.view.window |
| 439 | modalDelegate: self |
| 440 | didEndSelector: nil |
| 441 | contextInfo: nil]; |
| 442 | #endif |
| 443 | [wizard showWindow:self]; |
| 444 | } |
| 445 | |
| 446 | #pragma mark - BackupAccountDelegate methods |
| 447 | |
Loïc Siret | 31d5cc0 | 2016-09-08 14:38:24 -0400 | [diff] [blame] | 448 | -(void) didCompleteExportWithPath:(NSURL*) fileUrl |
| 449 | { |
| 450 | [[NSWorkspace sharedWorkspace] selectFile:fileUrl.path inFileViewerRootedAtPath:@""]; |
| 451 | } |
| 452 | |
Alexandre Lision | 886cde1 | 2016-10-25 17:39:49 -0400 | [diff] [blame] | 453 | #pragma mark - RestoreAccountDelegate methods |
| 454 | |
| 455 | -(void) didCompleteImport |
| 456 | { |
| 457 | // Nothing to do here |
| 458 | } |
| 459 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 460 | @end |