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